Mercurial > hg > graal-jvmci-8
diff src/share/vm/runtime/thread.cpp @ 2181:d25d4ca69222
Merge.
author | Thomas Wuerthinger <wuerthinger@ssw.jku.at> |
---|---|
date | Wed, 16 Feb 2011 13:47:20 +0100 |
parents | 91fe28b03d6a 3582bf76420e |
children | 0cd39a385a72 |
line wrap: on
line diff
--- a/src/share/vm/runtime/thread.cpp Wed Feb 16 13:38:33 2011 +0100 +++ b/src/share/vm/runtime/thread.cpp Wed Feb 16 13:47:20 2011 +0100 @@ -31,12 +31,13 @@ #include "compiler/compileBroker.hpp" #include "interpreter/interpreter.hpp" #include "interpreter/linkResolver.hpp" +#include "jvmtifiles/jvmtiEnv.hpp" #include "memory/oopFactory.hpp" #include "memory/universe.inline.hpp" #include "oops/instanceKlass.hpp" #include "oops/objArrayOop.hpp" #include "oops/oop.inline.hpp" -#include "oops/symbolOop.hpp" +#include "oops/symbol.hpp" #include "prims/jvm_misc.hpp" #include "prims/jvmtiExport.hpp" #include "prims/jvmtiThreadState.hpp" @@ -890,7 +891,7 @@ return os::create_main_thread((JavaThread*)this); } -static void initialize_class(symbolHandle class_name, TRAPS) { +static void initialize_class(Symbol* class_name, TRAPS) { klassOop klass = SystemDictionary::resolve_or_fail(class_name, true, CHECK); instanceKlass::cast(klass)->initialize(CHECK); } @@ -898,7 +899,7 @@ // Creates the initial ThreadGroup static Handle create_initial_thread_group(TRAPS) { - klassOop k = SystemDictionary::resolve_or_fail(vmSymbolHandles::java_lang_ThreadGroup(), true, CHECK_NH); + klassOop k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_ThreadGroup(), true, CHECK_NH); instanceKlassHandle klass (THREAD, k); Handle system_instance = klass->allocate_instance_handle(CHECK_NH); @@ -907,8 +908,8 @@ JavaCalls::call_special(&result, system_instance, klass, - vmSymbolHandles::object_initializer_name(), - vmSymbolHandles::void_method_signature(), + vmSymbols::object_initializer_name(), + vmSymbols::void_method_signature(), CHECK_NH); } Universe::set_system_thread_group(system_instance()); @@ -920,8 +921,8 @@ JavaCalls::call_special(&result, main_instance, klass, - vmSymbolHandles::object_initializer_name(), - vmSymbolHandles::threadgroup_string_void_signature(), + vmSymbols::object_initializer_name(), + vmSymbols::threadgroup_string_void_signature(), system_instance, string, CHECK_NH); @@ -931,7 +932,7 @@ // Creates the initial Thread static oop create_initial_thread(Handle thread_group, JavaThread* thread, TRAPS) { - klassOop k = SystemDictionary::resolve_or_fail(vmSymbolHandles::java_lang_Thread(), true, CHECK_NULL); + klassOop k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_Thread(), true, CHECK_NULL); instanceKlassHandle klass (THREAD, k); instanceHandle thread_oop = klass->allocate_instance_handle(CHECK_NULL); @@ -944,8 +945,8 @@ JavaValue result(T_VOID); JavaCalls::call_special(&result, thread_oop, klass, - vmSymbolHandles::object_initializer_name(), - vmSymbolHandles::threadgroup_string_void_signature(), + vmSymbols::object_initializer_name(), + vmSymbols::threadgroup_string_void_signature(), thread_group, string, CHECK_NULL); @@ -953,12 +954,12 @@ } static void call_initializeSystemClass(TRAPS) { - klassOop k = SystemDictionary::resolve_or_fail(vmSymbolHandles::java_lang_System(), true, CHECK); + klassOop k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_System(), true, CHECK); instanceKlassHandle klass (THREAD, k); JavaValue result(T_VOID); - JavaCalls::call_static(&result, klass, vmSymbolHandles::initializeSystemClass_name(), - vmSymbolHandles::void_method_signature(), CHECK); + JavaCalls::call_static(&result, klass, vmSymbols::initializeSystemClass_name(), + vmSymbols::void_method_signature(), CHECK); } #ifdef KERNEL @@ -972,18 +973,31 @@ } JavaValue result(T_VOID); - JavaCalls::call_static(&result, klass, vmSymbolHandles::setBootClassLoaderHook_name(), - vmSymbolHandles::void_method_signature(), CHECK); + JavaCalls::call_static(&result, klass, vmSymbols::setBootClassLoaderHook_name(), + vmSymbols::void_method_signature(), CHECK); } #endif // KERNEL +// General purpose hook into Java code, run once when the VM is initialized. +// The Java library method itself may be changed independently from the VM. +static void call_postVMInitHook(TRAPS) { + klassOop k = SystemDictionary::sun_misc_PostVMInitHook_klass(); + instanceKlassHandle klass (THREAD, k); + if (klass.not_null()) { + JavaValue result(T_VOID); + JavaCalls::call_static(&result, klass, vmSymbols::run_method_name(), + vmSymbols::void_method_signature(), + CHECK); + } +} + static void reset_vm_info_property(TRAPS) { // the vm info string ResourceMark rm(THREAD); const char *vm_info = VM_Version::vm_info_string(); // java.lang.System class - klassOop k = SystemDictionary::resolve_or_fail(vmSymbolHandles::java_lang_System(), true, CHECK); + klassOop k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_System(), true, CHECK); instanceKlassHandle klass (THREAD, k); // setProperty arguments @@ -996,8 +1010,8 @@ // public static String setProperty(String key, String value); JavaCalls::call_static(&r, klass, - vmSymbolHandles::setProperty_name(), - vmSymbolHandles::string_string_string_signature(), + vmSymbols::setProperty_name(), + vmSymbols::string_string_string_signature(), key_str, value_str, CHECK); @@ -1008,7 +1022,7 @@ assert(thread_group.not_null(), "thread group should be specified"); assert(threadObj() == NULL, "should only create Java thread object once"); - klassOop k = SystemDictionary::resolve_or_fail(vmSymbolHandles::java_lang_Thread(), true, CHECK); + klassOop k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_Thread(), true, CHECK); instanceKlassHandle klass (THREAD, k); instanceHandle thread_oop = klass->allocate_instance_handle(CHECK); @@ -1023,8 +1037,8 @@ JavaCalls::call_special(&result, thread_oop, klass, - vmSymbolHandles::object_initializer_name(), - vmSymbolHandles::threadgroup_string_void_signature(), + vmSymbols::object_initializer_name(), + vmSymbols::threadgroup_string_void_signature(), thread_group, // Argument 1 name, // Argument 2 THREAD); @@ -1034,8 +1048,8 @@ JavaCalls::call_special(&result, thread_oop, klass, - vmSymbolHandles::object_initializer_name(), - vmSymbolHandles::threadgroup_runnable_void_signature(), + vmSymbols::object_initializer_name(), + vmSymbols::threadgroup_runnable_void_signature(), thread_group, // Argument 1 Handle(), // Argument 2 THREAD); @@ -1056,8 +1070,8 @@ JavaCalls::call_special(&result, thread_group, group, - vmSymbolHandles::add_method_name(), - vmSymbolHandles::thread_void_signature(), + vmSymbols::add_method_name(), + vmSymbols::thread_void_signature(), threadObj, // Arg 1 THREAD); @@ -1496,11 +1510,11 @@ assert(JavaThread::current() == this, "sanity check"); assert(this->threadObj() != NULL, "just checking"); - // Execute thread entry point. If this thread is being asked to restart, - // or has been stopped before starting, do not reexecute entry point. + // Execute thread entry point unless this thread has a pending exception + // or has been stopped before starting. // Note: Due to JVM_StopThread we can have pending exceptions already! - if (!this->has_pending_exception() && !java_lang_Thread::is_stillborn(this->threadObj())) { - // enter the thread's entry point only if we have no pending exceptions + if (!this->has_pending_exception() && + !java_lang_Thread::is_stillborn(this->threadObj())) { HandleMark hm(this); this->entry_point()(this, this); } @@ -1519,13 +1533,10 @@ ObjectLocker lock(threadObj, thread); // Ignore pending exception (ThreadDeath), since we are exiting anyway thread->clear_pending_exception(); - // It is of profound importance that we set the stillborn bit and reset the thread object, - // before we do the notify. Since, changing these two variable will make JVM_IsAlive return - // false. So in case another thread is doing a join on this thread , it will detect that the thread - // is dead when it gets notified. - java_lang_Thread::set_stillborn(threadObj()); // Thread is exiting. So set thread_status field in java.lang.Thread class to TERMINATED. java_lang_Thread::set_thread_status(threadObj(), java_lang_Thread::TERMINATED); + // Clear the native thread instance - this makes isAlive return false and allows the join() + // to complete once we've done the notify_all below java_lang_Thread::set_thread(threadObj(), NULL); lock.notify_all(thread); // Ignore pending exception (ThreadDeath), since we are exiting anyway @@ -1576,8 +1587,8 @@ CallInfo callinfo; KlassHandle thread_klass(THREAD, SystemDictionary::Thread_klass()); LinkResolver::resolve_virtual_call(callinfo, threadObj, recvrKlass, thread_klass, - vmSymbolHandles::dispatchUncaughtException_name(), - vmSymbolHandles::throwable_void_signature(), + vmSymbols::dispatchUncaughtException_name(), + vmSymbols::throwable_void_signature(), KlassHandle(), false, false, THREAD); CLEAR_PENDING_EXCEPTION; methodHandle method = callinfo.selected_method(); @@ -1585,8 +1596,8 @@ JavaValue result(T_VOID); JavaCalls::call_virtual(&result, threadObj, thread_klass, - vmSymbolHandles::dispatchUncaughtException_name(), - vmSymbolHandles::throwable_void_signature(), + vmSymbols::dispatchUncaughtException_name(), + vmSymbols::throwable_void_signature(), uncaught_exception, THREAD); } else { @@ -1594,8 +1605,8 @@ JavaValue result(T_VOID); JavaCalls::call_virtual(&result, group, thread_group, - vmSymbolHandles::uncaughtException_name(), - vmSymbolHandles::thread_throwable_void_signature(), + vmSymbols::uncaughtException_name(), + vmSymbols::thread_throwable_void_signature(), threadObj, // Arg 1 uncaught_exception, // Arg 2 THREAD); @@ -1614,8 +1625,8 @@ KlassHandle thread_klass(THREAD, SystemDictionary::Thread_klass()); JavaCalls::call_virtual(&result, threadObj, thread_klass, - vmSymbolHandles::exit_method_name(), - vmSymbolHandles::void_method_signature(), + vmSymbols::exit_method_name(), + vmSymbols::void_method_signature(), THREAD); CLEAR_PENDING_EXCEPTION; } @@ -1699,7 +1710,7 @@ tlab().make_parsable(true); // retire TLAB } - if (jvmti_thread_state() != NULL) { + if (JvmtiEnv::environments_might_exist()) { JvmtiExport::cleanup_thread(this); } @@ -1984,11 +1995,6 @@ // (tw) May we do this? //if (is_Compiler_thread()) return; - // This is a change from JDK 1.1, but JDK 1.2 will also do it: - if (java_throwable->is_a(SystemDictionary::ThreadDeath_klass())) { - java_lang_Thread::set_stillborn(threadObj()); - } - { // Actually throw the Throwable against the target Thread - however // only if there is no thread death exception installed already. @@ -3150,7 +3156,7 @@ } if (InitializeJavaLangString) { - initialize_class(vmSymbolHandles::java_lang_String(), CHECK_0); + initialize_class(vmSymbols::java_lang_String(), CHECK_0); } else { warning("java.lang.String not initialized"); } @@ -3160,10 +3166,10 @@ // Forcibly initialize java/util/HashMap and mutate the private // static final "frontCacheEnabled" field before we start creating instances #ifdef ASSERT - klassOop tmp_k = SystemDictionary::find(vmSymbolHandles::java_util_HashMap(), Handle(), Handle(), CHECK_0); + klassOop tmp_k = SystemDictionary::find(vmSymbols::java_util_HashMap(), Handle(), Handle(), CHECK_0); assert(tmp_k == NULL, "java/util/HashMap should not be loaded yet"); #endif - klassOop k_o = SystemDictionary::resolve_or_null(vmSymbolHandles::java_util_HashMap(), Handle(), Handle(), CHECK_0); + klassOop k_o = SystemDictionary::resolve_or_null(vmSymbols::java_util_HashMap(), Handle(), Handle(), CHECK_0); KlassHandle k = KlassHandle(THREAD, k_o); guarantee(k.not_null(), "Must find java/util/HashMap"); instanceKlassHandle ik = instanceKlassHandle(THREAD, k()); @@ -3178,7 +3184,7 @@ if (UseStringCache) { // Forcibly initialize java/lang/StringValue and mutate the private // static final "stringCacheEnabled" field before we start creating instances - klassOop k_o = SystemDictionary::resolve_or_null(vmSymbolHandles::java_lang_StringValue(), Handle(), Handle(), CHECK_0); + klassOop k_o = SystemDictionary::resolve_or_null(vmSymbols::java_lang_StringValue(), Handle(), Handle(), CHECK_0); // Possible that StringValue isn't present: if so, silently don't break if (k_o != NULL) { KlassHandle k = KlassHandle(THREAD, k_o); @@ -3195,11 +3201,11 @@ // Initialize java_lang.System (needed before creating the thread) if (InitializeJavaLangSystem) { - initialize_class(vmSymbolHandles::java_lang_System(), CHECK_0); - initialize_class(vmSymbolHandles::java_lang_ThreadGroup(), CHECK_0); + initialize_class(vmSymbols::java_lang_System(), CHECK_0); + initialize_class(vmSymbols::java_lang_ThreadGroup(), CHECK_0); Handle thread_group = create_initial_thread_group(CHECK_0); Universe::set_main_thread_group(thread_group()); - initialize_class(vmSymbolHandles::java_lang_Thread(), CHECK_0); + initialize_class(vmSymbols::java_lang_Thread(), CHECK_0); oop thread_object = create_initial_thread(thread_group, main_thread, CHECK_0); main_thread->set_threadObj(thread_object); // Set thread status to running since main thread has @@ -3208,10 +3214,10 @@ java_lang_Thread::RUNNABLE); // The VM preresolve methods to these classes. Make sure that get initialized - initialize_class(vmSymbolHandles::java_lang_reflect_Method(), CHECK_0); - initialize_class(vmSymbolHandles::java_lang_ref_Finalizer(), CHECK_0); + initialize_class(vmSymbols::java_lang_reflect_Method(), CHECK_0); + initialize_class(vmSymbols::java_lang_ref_Finalizer(), CHECK_0); // The VM creates & returns objects of this class. Make sure it's initialized. - initialize_class(vmSymbolHandles::java_lang_Class(), CHECK_0); + initialize_class(vmSymbols::java_lang_Class(), CHECK_0); call_initializeSystemClass(CHECK_0); } else { warning("java.lang.System not initialized"); @@ -3219,13 +3225,13 @@ // an instance of OutOfMemory exception has been allocated earlier if (InitializeJavaLangExceptionsErrors) { - initialize_class(vmSymbolHandles::java_lang_OutOfMemoryError(), CHECK_0); - initialize_class(vmSymbolHandles::java_lang_NullPointerException(), CHECK_0); - initialize_class(vmSymbolHandles::java_lang_ClassCastException(), CHECK_0); - initialize_class(vmSymbolHandles::java_lang_ArrayStoreException(), CHECK_0); - initialize_class(vmSymbolHandles::java_lang_ArithmeticException(), CHECK_0); - initialize_class(vmSymbolHandles::java_lang_StackOverflowError(), CHECK_0); - initialize_class(vmSymbolHandles::java_lang_IllegalMonitorStateException(), CHECK_0); + initialize_class(vmSymbols::java_lang_OutOfMemoryError(), CHECK_0); + initialize_class(vmSymbols::java_lang_NullPointerException(), CHECK_0); + initialize_class(vmSymbols::java_lang_ClassCastException(), CHECK_0); + initialize_class(vmSymbols::java_lang_ArrayStoreException(), CHECK_0); + initialize_class(vmSymbols::java_lang_ArithmeticException(), CHECK_0); + initialize_class(vmSymbols::java_lang_StackOverflowError(), CHECK_0); + initialize_class(vmSymbols::java_lang_IllegalMonitorStateException(), CHECK_0); } else { warning("java.lang.OutOfMemoryError has not been initialized"); warning("java.lang.NullPointerException has not been initialized"); @@ -3251,7 +3257,7 @@ // Future Fix : the best fix is to grant everyone permissions to read "java.compiler" and // read and write"java.vm.info" in the default policy file. See bugid 4211383 // Once that is done, we should remove this hack. - initialize_class(vmSymbolHandles::java_lang_Compiler(), CHECK_0); + initialize_class(vmSymbols::java_lang_Compiler(), CHECK_0); // More hackery - the static initializer of java.lang.Compiler adds the string "nojit" to // the java.vm.info property if no jit gets loaded through java.lang.Compiler (the hotspot @@ -3348,6 +3354,14 @@ BiasedLocking::init(); + if (JDK_Version::current().post_vm_init_hook_enabled()) { + call_postVMInitHook(THREAD); + // The Java side of PostVMInitHook.run must deal with all + // exceptions and provide means of diagnosis. + if (HAS_PENDING_EXCEPTION) { + CLEAR_PENDING_EXCEPTION; + } + } // Start up the WatcherThread if there are any periodic tasks // NOTE: All PeriodicTasks should be registered by now. If they @@ -3569,7 +3583,7 @@ EXCEPTION_MARK; klassOop k = - SystemDictionary::resolve_or_null(vmSymbolHandles::java_lang_Shutdown(), + SystemDictionary::resolve_or_null(vmSymbols::java_lang_Shutdown(), THREAD); if (k != NULL) { // SystemDictionary::resolve_or_null will return null if there was @@ -3583,8 +3597,8 @@ JavaValue result(T_VOID); JavaCalls::call_static(&result, shutdown_klass, - vmSymbolHandles::shutdown_method_name(), - vmSymbolHandles::void_method_signature(), + vmSymbols::shutdown_method_name(), + vmSymbols::void_method_signature(), THREAD); } CLEAR_PENDING_EXCEPTION;