8244997: Convert the JavaThread::_threadObj oop to use OopStorage

Move the oop and handle releasing it in the service thread.  Remove Universe::oops_do from callers.

Co-authored-by: Erik Osterlund <erik.osterlund@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: dholmes, zgu, eosterlund, cjplummer
This commit is contained in:
Coleen Phillimore 2020-08-07 07:53:26 -04:00
parent 4d3baa2d37
commit 0c9e0c2e7f
46 changed files with 162 additions and 207 deletions

View file

@ -37,6 +37,8 @@
#include "gc/shared/barrierSet.hpp"
#include "gc/shared/gcId.hpp"
#include "gc/shared/gcLocker.inline.hpp"
#include "gc/shared/oopStorage.hpp"
#include "gc/shared/oopStorageSet.hpp"
#include "gc/shared/workgroup.hpp"
#include "interpreter/interpreter.hpp"
#include "interpreter/linkResolver.hpp"
@ -1055,12 +1057,12 @@ static Handle create_initial_thread_group(TRAPS) {
return main_instance;
}
// Creates the initial Thread
static oop create_initial_thread(Handle thread_group, JavaThread* thread,
// Creates the initial Thread, and sets it to running.
static void create_initial_thread(Handle thread_group, JavaThread* thread,
TRAPS) {
InstanceKlass* ik = SystemDictionary::Thread_klass();
assert(ik->is_initialized(), "must be");
instanceHandle thread_oop = ik->allocate_instance_handle(CHECK_NULL);
instanceHandle thread_oop = ik->allocate_instance_handle(CHECK);
// Cannot use JavaCalls::construct_new_instance because the java.lang.Thread
// constructor calls Thread.current(), which must be set here for the
@ -1069,7 +1071,7 @@ static oop create_initial_thread(Handle thread_group, JavaThread* thread,
java_lang_Thread::set_priority(thread_oop(), NormPriority);
thread->set_threadObj(thread_oop());
Handle string = java_lang_String::create_from_str("main", CHECK_NULL);
Handle string = java_lang_String::create_from_str("main", CHECK);
JavaValue result(T_VOID);
JavaCalls::call_special(&result, thread_oop,
@ -1078,8 +1080,12 @@ static oop create_initial_thread(Handle thread_group, JavaThread* thread,
vmSymbols::threadgroup_string_void_signature(),
thread_group,
string,
CHECK_NULL);
return thread_oop();
CHECK);
// Set thread status to running since main thread has
// been started and running.
java_lang_Thread::set_thread_status(thread_oop(),
java_lang_Thread::RUNNABLE);
}
char java_runtime_name[128] = "";
@ -1187,6 +1193,23 @@ static void call_postVMInitHook(TRAPS) {
}
}
// Initialized by VMThread at vm_global_init
static OopStorage* _thread_oop_storage = NULL;
oop JavaThread::threadObj() const {
return _threadObj.resolve();
}
void JavaThread::set_threadObj(oop p) {
assert(_thread_oop_storage != NULL, "not yet initialized");
_threadObj = OopHandle(_thread_oop_storage, p);
}
OopStorage* JavaThread::thread_oop_storage() {
assert(_thread_oop_storage != NULL, "not yet initialized");
return _thread_oop_storage;
}
void JavaThread::allocate_threadObj(Handle thread_group, const char* thread_name,
bool daemon, TRAPS) {
assert(thread_group.not_null(), "thread group should be specified");
@ -1653,7 +1676,6 @@ void JavaThread::initialize() {
// Initialize fields
set_saved_exception_pc(NULL);
set_threadObj(NULL);
_anchor.clear();
set_entry_point(NULL);
set_jni_functions(jni_functions());
@ -1758,7 +1780,7 @@ void JavaThread::interrupt() {
bool JavaThread::is_interrupted(bool clear_interrupted) {
debug_only(check_for_dangling_thread_pointer(this);)
if (threadObj() == NULL) {
if (_threadObj.peek() == NULL) {
// If there is no j.l.Thread then it is impossible to have
// been interrupted. We can find NULL during VM initialization
// or when a JNI thread is still in the process of attaching.
@ -1871,6 +1893,9 @@ JavaThread::JavaThread(ThreadFunction entry_point, size_t stack_sz) :
JavaThread::~JavaThread() {
// Ask ServiceThread to release the threadObj OopHandle
ServiceThread::add_oop_handle_release(_threadObj);
// JSR166 -- return the parker to the free list
Parker::Release(_parker);
_parker = NULL;
@ -1971,7 +1996,7 @@ void JavaThread::run() {
void JavaThread::thread_main_inner() {
assert(JavaThread::current() == this, "sanity check");
assert(this->threadObj() != NULL, "just checking");
assert(_threadObj.peek() != NULL, "just checking");
// Execute thread entry point unless this thread has a pending exception
// or has been stopped before starting.
@ -3015,7 +3040,6 @@ void JavaThread::oops_do(OopClosure* f, CodeBlobClosure* cf) {
// Traverse instance variables at the end since the GC may be moving things
// around using this function
f->do_oop((oop*) &_threadObj);
f->do_oop((oop*) &_vm_result);
f->do_oop((oop*) &_exception_oop);
f->do_oop((oop*) &_pending_async_exception);
@ -3717,13 +3741,7 @@ void Threads::initialize_java_lang_classes(JavaThread* main_thread, TRAPS) {
Handle thread_group = create_initial_thread_group(CHECK);
Universe::set_main_thread_group(thread_group());
initialize_class(vmSymbols::java_lang_Thread(), CHECK);
oop thread_object = create_initial_thread(thread_group, main_thread, CHECK);
main_thread->set_threadObj(thread_object);
// Set thread status to running since main thread has
// been started and running.
java_lang_Thread::set_thread_status(thread_object,
java_lang_Thread::RUNNABLE);
create_initial_thread(thread_group, main_thread, CHECK);
// The VM creates objects of this class.
initialize_class(vmSymbols::java_lang_Module(), CHECK);
@ -3886,6 +3904,9 @@ jint Threads::create_vm(JavaVMInitArgs* args, bool* canTryAgain) {
}
#endif // INCLUDE_JVMCI
// Initialize OopStorage for threadObj
_thread_oop_storage = OopStorageSet::create_strong("Thread OopStorage");
// Attach the main thread to this os thread
JavaThread* main_thread = new JavaThread();
main_thread->set_thread_state(_thread_in_vm);