2008-06-05 15:57:56 -07:00
|
|
|
/*
|
2014-07-08 08:04:06 -07:00
|
|
|
* Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
|
2008-06-05 15:57:56 -07: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.
|
|
|
|
*
|
2010-05-27 19:08:38 -07:00
|
|
|
* 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.
|
2008-06-05 15:57:56 -07:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "precompiled.hpp"
|
|
|
|
#include "classfile/systemDictionary.hpp"
|
|
|
|
#include "gc_implementation/shared/concurrentGCThread.hpp"
|
|
|
|
#include "oops/instanceRefKlass.hpp"
|
|
|
|
#include "oops/oop.inline.hpp"
|
|
|
|
#include "runtime/init.hpp"
|
|
|
|
#include "runtime/interfaceSupport.hpp"
|
|
|
|
#include "runtime/java.hpp"
|
|
|
|
#include "runtime/javaCalls.hpp"
|
2014-02-11 08:43:17 -08:00
|
|
|
#include "runtime/os.hpp"
|
2008-06-05 15:57:56 -07:00
|
|
|
|
2010-11-23 13:22:55 -08:00
|
|
|
// CopyrightVersion 1.2
|
2008-06-05 15:57:56 -07:00
|
|
|
|
|
|
|
int ConcurrentGCThread::_CGC_flag = CGC_nil;
|
|
|
|
|
2009-05-11 16:30:56 -07:00
|
|
|
ConcurrentGCThread::ConcurrentGCThread() :
|
|
|
|
_should_terminate(false), _has_terminated(false) {
|
2008-06-05 15:57:56 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
void ConcurrentGCThread::create_and_start() {
|
|
|
|
if (os::create_thread(this, os::cgc_thread)) {
|
|
|
|
// XXX: need to set this to low priority
|
2014-01-23 14:47:23 +01:00
|
|
|
// unless "aggressive mode" set; priority
|
2008-06-05 15:57:56 -07:00
|
|
|
// should be just less than that of VMThread.
|
|
|
|
os::set_priority(this, NearMaxPriority);
|
|
|
|
if (!_should_terminate && !DisableStartThread) {
|
|
|
|
os::start_thread(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConcurrentGCThread::initialize_in_thread() {
|
|
|
|
this->record_stack_base_and_size();
|
|
|
|
this->initialize_thread_local_storage();
|
|
|
|
this->set_active_handles(JNIHandleBlock::allocate_block());
|
|
|
|
// From this time Thread::current() should be working.
|
|
|
|
assert(this == Thread::current(), "just checking");
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConcurrentGCThread::wait_for_universe_init() {
|
|
|
|
MutexLockerEx x(CGC_lock, Mutex::_no_safepoint_check_flag);
|
|
|
|
while (!is_init_completed() && !_should_terminate) {
|
|
|
|
CGC_lock->wait(Mutex::_no_safepoint_check_flag, 200);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConcurrentGCThread::terminate() {
|
|
|
|
// Signal that it is terminated
|
|
|
|
{
|
|
|
|
MutexLockerEx mu(Terminator_lock,
|
|
|
|
Mutex::_no_safepoint_check_flag);
|
|
|
|
_has_terminated = true;
|
|
|
|
Terminator_lock->notify();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Thread destructor usually does this..
|
|
|
|
ThreadLocalStorage::set_thread(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void _sltLoop(JavaThread* thread, TRAPS) {
|
|
|
|
SurrogateLockerThread* slt = (SurrogateLockerThread*)thread;
|
|
|
|
slt->loop();
|
|
|
|
}
|
|
|
|
|
|
|
|
SurrogateLockerThread::SurrogateLockerThread() :
|
|
|
|
JavaThread(&_sltLoop),
|
|
|
|
_monitor(Mutex::nonleaf, "SLTMonitor"),
|
|
|
|
_buffer(empty)
|
|
|
|
{}
|
|
|
|
|
|
|
|
SurrogateLockerThread* SurrogateLockerThread::make(TRAPS) {
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
Klass* k =
|
2011-01-27 16:11:27 -08:00
|
|
|
SystemDictionary::resolve_or_fail(vmSymbols::java_lang_Thread(),
|
2008-06-05 15:57:56 -07:00
|
|
|
true, CHECK_NULL);
|
|
|
|
instanceKlassHandle klass (THREAD, k);
|
|
|
|
instanceHandle thread_oop = klass->allocate_instance_handle(CHECK_NULL);
|
|
|
|
|
2010-10-01 16:43:05 -04:00
|
|
|
const char thread_name[] = "Surrogate Locker Thread (Concurrent GC)";
|
2008-06-05 15:57:56 -07:00
|
|
|
Handle string = java_lang_String::create_from_str(thread_name, CHECK_NULL);
|
|
|
|
|
|
|
|
// Initialize thread_oop to put it into the system threadGroup
|
|
|
|
Handle thread_group (THREAD, Universe::system_thread_group());
|
|
|
|
JavaValue result(T_VOID);
|
|
|
|
JavaCalls::call_special(&result, thread_oop,
|
|
|
|
klass,
|
2011-01-27 16:11:27 -08:00
|
|
|
vmSymbols::object_initializer_name(),
|
|
|
|
vmSymbols::threadgroup_string_void_signature(),
|
2008-06-05 15:57:56 -07:00
|
|
|
thread_group,
|
|
|
|
string,
|
|
|
|
CHECK_NULL);
|
|
|
|
|
|
|
|
SurrogateLockerThread* res;
|
|
|
|
{
|
|
|
|
MutexLocker mu(Threads_lock);
|
|
|
|
res = new SurrogateLockerThread();
|
|
|
|
|
|
|
|
// At this point it may be possible that no osthread was created for the
|
|
|
|
// JavaThread due to lack of memory. We would have to throw an exception
|
|
|
|
// in that case. However, since this must work and we do not allow
|
|
|
|
// exceptions anyway, check and abort if this fails.
|
|
|
|
if (res == NULL || res->osthread() == NULL) {
|
|
|
|
vm_exit_during_initialization("java.lang.OutOfMemoryError",
|
2014-02-11 08:43:17 -08:00
|
|
|
os::native_thread_creation_failed_msg());
|
2008-06-05 15:57:56 -07:00
|
|
|
}
|
|
|
|
java_lang_Thread::set_thread(thread_oop(), res);
|
|
|
|
java_lang_Thread::set_priority(thread_oop(), NearMaxPriority);
|
|
|
|
java_lang_Thread::set_daemon(thread_oop());
|
|
|
|
|
|
|
|
res->set_threadObj(thread_oop());
|
|
|
|
Threads::add(res);
|
|
|
|
Thread::start(res);
|
|
|
|
}
|
2014-07-08 08:04:06 -07:00
|
|
|
os::naked_yield(); // This seems to help with initial start-up of SLT
|
2008-06-05 15:57:56 -07:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2014-11-11 13:39:00 -05:00
|
|
|
void SurrogateLockerThread::report_missing_slt() {
|
|
|
|
vm_exit_during_initialization(
|
|
|
|
"GC before GC support fully initialized: "
|
|
|
|
"SLT is needed but has not yet been created.");
|
|
|
|
ShouldNotReachHere();
|
|
|
|
}
|
|
|
|
|
2008-06-05 15:57:56 -07:00
|
|
|
void SurrogateLockerThread::manipulatePLL(SLT_msg_type msg) {
|
|
|
|
MutexLockerEx x(&_monitor, Mutex::_no_safepoint_check_flag);
|
|
|
|
assert(_buffer == empty, "Should be empty");
|
|
|
|
assert(msg != empty, "empty message");
|
2011-10-20 12:06:20 -07:00
|
|
|
assert(!Heap_lock->owned_by_self(), "Heap_lock owned by requesting thread");
|
|
|
|
|
2008-06-05 15:57:56 -07:00
|
|
|
_buffer = msg;
|
|
|
|
while (_buffer != empty) {
|
|
|
|
_monitor.notify();
|
|
|
|
_monitor.wait(Mutex::_no_safepoint_check_flag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ======= Surrogate Locker Thread =============
|
|
|
|
|
|
|
|
void SurrogateLockerThread::loop() {
|
|
|
|
BasicLock pll_basic_lock;
|
|
|
|
SLT_msg_type msg;
|
|
|
|
debug_only(unsigned int owned = 0;)
|
|
|
|
|
|
|
|
while (/* !isTerminated() */ 1) {
|
|
|
|
{
|
|
|
|
MutexLocker x(&_monitor);
|
|
|
|
// Since we are a JavaThread, we can't be here at a safepoint.
|
|
|
|
assert(!SafepointSynchronize::is_at_safepoint(),
|
|
|
|
"SLT is a JavaThread");
|
|
|
|
// wait for msg buffer to become non-empty
|
|
|
|
while (_buffer == empty) {
|
|
|
|
_monitor.notify();
|
|
|
|
_monitor.wait();
|
|
|
|
}
|
|
|
|
msg = _buffer;
|
|
|
|
}
|
|
|
|
switch(msg) {
|
|
|
|
case acquirePLL: {
|
2012-09-07 12:04:16 -04:00
|
|
|
InstanceRefKlass::acquire_pending_list_lock(&pll_basic_lock);
|
2008-06-05 15:57:56 -07:00
|
|
|
debug_only(owned++;)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case releaseAndNotifyPLL: {
|
|
|
|
assert(owned > 0, "Don't have PLL");
|
2012-09-07 12:04:16 -04:00
|
|
|
InstanceRefKlass::release_and_notify_pending_list_lock(&pll_basic_lock);
|
2008-06-05 15:57:56 -07:00
|
|
|
debug_only(owned--;)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case empty:
|
|
|
|
default: {
|
|
|
|
guarantee(false,"Unexpected message in _buffer");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
MutexLocker x(&_monitor);
|
|
|
|
// Since we are a JavaThread, we can't be here at a safepoint.
|
|
|
|
assert(!SafepointSynchronize::is_at_safepoint(),
|
|
|
|
"SLT is a JavaThread");
|
|
|
|
_buffer = empty;
|
|
|
|
_monitor.notify();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert(!_monitor.owned_by_self(), "Should unlock before exit.");
|
|
|
|
}
|