2014-03-18 19:07:22 +01:00
|
|
|
/*
|
2019-04-25 10:56:31 -04:00
|
|
|
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
|
2014-03-18 19:07:22 +01:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "precompiled.hpp"
|
2015-02-13 14:37:35 +01:00
|
|
|
#include "classfile/javaClasses.inline.hpp"
|
2015-05-13 15:16:06 +02:00
|
|
|
#include "gc/g1/g1CollectedHeap.hpp"
|
|
|
|
#include "gc/g1/g1StringDedup.hpp"
|
|
|
|
#include "gc/g1/g1StringDedupQueue.hpp"
|
2015-12-10 14:57:55 +01:00
|
|
|
#include "logging/log.hpp"
|
2015-02-13 14:37:35 +01:00
|
|
|
#include "oops/oop.inline.hpp"
|
2016-08-21 20:56:37 -04:00
|
|
|
#include "runtime/atomic.hpp"
|
2014-03-18 19:07:22 +01:00
|
|
|
#include "runtime/mutexLocker.hpp"
|
2018-03-23 18:54:12 +01:00
|
|
|
#include "runtime/safepointVerifiers.hpp"
|
2014-03-18 19:07:22 +01:00
|
|
|
#include "utilities/stack.inline.hpp"
|
|
|
|
|
|
|
|
const size_t G1StringDedupQueue::_max_size = 1000000; // Max number of elements per queue
|
|
|
|
const size_t G1StringDedupQueue::_max_cache_size = 0; // Max cache size per queue
|
|
|
|
|
|
|
|
G1StringDedupQueue::G1StringDedupQueue() :
|
|
|
|
_cursor(0),
|
2014-04-11 11:00:12 +02:00
|
|
|
_cancel(false),
|
2014-03-18 19:07:22 +01:00
|
|
|
_empty(true),
|
|
|
|
_dropped(0) {
|
2015-05-22 10:58:16 +02:00
|
|
|
_nqueues = ParallelGCThreads;
|
2014-03-18 19:07:22 +01:00
|
|
|
_queues = NEW_C_HEAP_ARRAY(G1StringDedupWorkerQueue, _nqueues, mtGC);
|
|
|
|
for (size_t i = 0; i < _nqueues; i++) {
|
|
|
|
new (_queues + i) G1StringDedupWorkerQueue(G1StringDedupWorkerQueue::default_segment_size(), _max_cache_size, _max_size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
G1StringDedupQueue::~G1StringDedupQueue() {
|
|
|
|
ShouldNotReachHere();
|
|
|
|
}
|
|
|
|
|
2018-06-14 09:59:21 -04:00
|
|
|
void G1StringDedupQueue::wait_impl() {
|
2019-04-25 10:56:31 -04:00
|
|
|
MonitorLocker ml(StringDedupQueue_lock, Mutex::_no_safepoint_check_flag);
|
2018-06-14 09:59:21 -04:00
|
|
|
while (_empty && !_cancel) {
|
2019-04-25 10:56:31 -04:00
|
|
|
ml.wait();
|
2014-03-18 19:07:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-14 09:59:21 -04:00
|
|
|
void G1StringDedupQueue::cancel_wait_impl() {
|
2019-04-25 10:56:31 -04:00
|
|
|
MonitorLocker ml(StringDedupQueue_lock, Mutex::_no_safepoint_check_flag);
|
2018-06-14 09:59:21 -04:00
|
|
|
_cancel = true;
|
2014-04-11 11:00:12 +02:00
|
|
|
ml.notify();
|
|
|
|
}
|
|
|
|
|
2018-06-14 09:59:21 -04:00
|
|
|
void G1StringDedupQueue::push_impl(uint worker_id, oop java_string) {
|
2014-03-18 19:07:22 +01:00
|
|
|
assert(SafepointSynchronize::is_at_safepoint(), "Must be at safepoint");
|
2018-06-14 09:59:21 -04:00
|
|
|
assert(worker_id < _nqueues, "Invalid queue");
|
2014-03-18 19:07:22 +01:00
|
|
|
|
|
|
|
// Push and notify waiter
|
2018-06-14 09:59:21 -04:00
|
|
|
G1StringDedupWorkerQueue& worker_queue = _queues[worker_id];
|
2014-03-18 19:07:22 +01:00
|
|
|
if (!worker_queue.is_full()) {
|
|
|
|
worker_queue.push(java_string);
|
2018-06-14 09:59:21 -04:00
|
|
|
if (_empty) {
|
2019-04-25 10:56:31 -04:00
|
|
|
MonitorLocker ml(StringDedupQueue_lock, Mutex::_no_safepoint_check_flag);
|
2018-06-14 09:59:21 -04:00
|
|
|
if (_empty) {
|
2014-03-18 19:07:22 +01:00
|
|
|
// Mark non-empty and notify waiter
|
2018-06-14 09:59:21 -04:00
|
|
|
_empty = false;
|
2014-03-18 19:07:22 +01:00
|
|
|
ml.notify();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Queue is full, drop the string and update the statistics
|
2018-06-14 09:59:21 -04:00
|
|
|
Atomic::inc(&_dropped);
|
2014-03-18 19:07:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-14 09:59:21 -04:00
|
|
|
oop G1StringDedupQueue::pop_impl() {
|
2014-03-18 19:07:22 +01:00
|
|
|
assert(!SafepointSynchronize::is_at_safepoint(), "Must not be at safepoint");
|
2016-01-14 13:26:19 +01:00
|
|
|
NoSafepointVerifier nsv;
|
2014-03-18 19:07:22 +01:00
|
|
|
|
|
|
|
// Try all queues before giving up
|
2018-06-14 09:59:21 -04:00
|
|
|
for (size_t tries = 0; tries < _nqueues; tries++) {
|
2014-03-18 19:07:22 +01:00
|
|
|
// The cursor indicates where we left of last time
|
2018-06-14 09:59:21 -04:00
|
|
|
G1StringDedupWorkerQueue* queue = &_queues[_cursor];
|
2014-03-18 19:07:22 +01:00
|
|
|
while (!queue->is_empty()) {
|
|
|
|
oop obj = queue->pop();
|
|
|
|
// The oop we pop can be NULL if it was marked
|
|
|
|
// dead. Just ignore those and pop the next oop.
|
|
|
|
if (obj != NULL) {
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try next queue
|
2018-06-14 09:59:21 -04:00
|
|
|
_cursor = (_cursor + 1) % _nqueues;
|
2014-03-18 19:07:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Mark empty
|
2018-06-14 09:59:21 -04:00
|
|
|
_empty = true;
|
2014-03-18 19:07:22 +01:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-06-14 09:59:21 -04:00
|
|
|
void G1StringDedupQueue::unlink_or_oops_do_impl(StringDedupUnlinkOrOopsDoClosure* cl, size_t queue) {
|
|
|
|
assert(queue < _nqueues, "Invalid queue");
|
|
|
|
StackIterator<oop, mtGC> iter(_queues[queue]);
|
2014-03-18 19:07:22 +01:00
|
|
|
while (!iter.is_empty()) {
|
|
|
|
oop* p = iter.next_addr();
|
|
|
|
if (*p != NULL) {
|
|
|
|
if (cl->is_alive(*p)) {
|
|
|
|
cl->keep_alive(p);
|
|
|
|
} else {
|
|
|
|
// Clear dead reference
|
|
|
|
*p = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-14 09:59:21 -04:00
|
|
|
void G1StringDedupQueue::print_statistics_impl() {
|
2016-07-04 11:27:11 +02:00
|
|
|
log_debug(gc, stringdedup)(" Queue");
|
2018-06-14 09:59:21 -04:00
|
|
|
log_debug(gc, stringdedup)(" Dropped: " UINTX_FORMAT, _dropped);
|
2014-03-18 19:07:22 +01:00
|
|
|
}
|
|
|
|
|
2018-06-14 09:59:21 -04:00
|
|
|
void G1StringDedupQueue::verify_impl() {
|
|
|
|
for (size_t i = 0; i < _nqueues; i++) {
|
|
|
|
StackIterator<oop, mtGC> iter(_queues[i]);
|
2014-03-18 19:07:22 +01:00
|
|
|
while (!iter.is_empty()) {
|
|
|
|
oop obj = iter.next();
|
|
|
|
if (obj != NULL) {
|
2015-04-13 15:47:48 +02:00
|
|
|
guarantee(G1CollectedHeap::heap()->is_in_reserved(obj), "Object must be on the heap");
|
2014-03-18 19:07:22 +01:00
|
|
|
guarantee(!obj->is_forwarded(), "Object must not be forwarded");
|
|
|
|
guarantee(java_lang_String::is_instance(obj), "Object must be a String");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|