Mercurial > hg > graal-compiler
comparison src/share/vm/runtime/thread.cpp @ 14909:4ca6dc0799b6
Backout jdk9 merge
author | Gilles Duboscq <duboscq@ssw.jku.at> |
---|---|
date | Tue, 01 Apr 2014 13:57:07 +0200 |
parents | 3e9a960f0da1 |
children | b68a693a7ad4 |
comparison
equal
deleted
inserted
replaced
14908:8db6e76cb658 | 14909:4ca6dc0799b6 |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. | 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | 4 * |
5 * This code is free software; you can redistribute it and/or modify it | 5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as | 6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
114 | 114 |
115 #ifdef DTRACE_ENABLED | 115 #ifdef DTRACE_ENABLED |
116 | 116 |
117 // Only bother with this argument setup if dtrace is available | 117 // Only bother with this argument setup if dtrace is available |
118 | 118 |
119 #define HOTSPOT_THREAD_PROBE_start HOTSPOT_THREAD_START | 119 #ifndef USDT2 |
120 #define HOTSPOT_THREAD_PROBE_stop HOTSPOT_THREAD_STOP | 120 HS_DTRACE_PROBE_DECL(hotspot, vm__init__begin); |
121 HS_DTRACE_PROBE_DECL(hotspot, vm__init__end); | |
122 HS_DTRACE_PROBE_DECL5(hotspot, thread__start, char*, intptr_t, | |
123 intptr_t, intptr_t, bool); | |
124 HS_DTRACE_PROBE_DECL5(hotspot, thread__stop, char*, intptr_t, | |
125 intptr_t, intptr_t, bool); | |
126 | |
127 #define DTRACE_THREAD_PROBE(probe, javathread) \ | |
128 { \ | |
129 ResourceMark rm(this); \ | |
130 int len = 0; \ | |
131 const char* name = (javathread)->get_thread_name(); \ | |
132 len = strlen(name); \ | |
133 HS_DTRACE_PROBE5(hotspot, thread__##probe, \ | |
134 name, len, \ | |
135 java_lang_Thread::thread_id((javathread)->threadObj()), \ | |
136 (javathread)->osthread()->thread_id(), \ | |
137 java_lang_Thread::is_daemon((javathread)->threadObj())); \ | |
138 } | |
139 | |
140 #else /* USDT2 */ | |
141 | |
142 #define HOTSPOT_THREAD_PROBE_start HOTSPOT_THREAD_PROBE_START | |
143 #define HOTSPOT_THREAD_PROBE_stop HOTSPOT_THREAD_PROBE_STOP | |
121 | 144 |
122 #define DTRACE_THREAD_PROBE(probe, javathread) \ | 145 #define DTRACE_THREAD_PROBE(probe, javathread) \ |
123 { \ | 146 { \ |
124 ResourceMark rm(this); \ | 147 ResourceMark rm(this); \ |
125 int len = 0; \ | 148 int len = 0; \ |
129 (char *) name, len, \ | 152 (char *) name, len, \ |
130 java_lang_Thread::thread_id((javathread)->threadObj()), \ | 153 java_lang_Thread::thread_id((javathread)->threadObj()), \ |
131 (uintptr_t) (javathread)->osthread()->thread_id(), \ | 154 (uintptr_t) (javathread)->osthread()->thread_id(), \ |
132 java_lang_Thread::is_daemon((javathread)->threadObj())); \ | 155 java_lang_Thread::is_daemon((javathread)->threadObj())); \ |
133 } | 156 } |
157 | |
158 #endif /* USDT2 */ | |
134 | 159 |
135 #else // ndef DTRACE_ENABLED | 160 #else // ndef DTRACE_ENABLED |
136 | 161 |
137 #define DTRACE_THREAD_PROBE(probe, javathread) | 162 #define DTRACE_THREAD_PROBE(probe, javathread) |
138 | 163 |
289 } | 314 } |
290 | 315 |
291 void Thread::record_stack_base_and_size() { | 316 void Thread::record_stack_base_and_size() { |
292 set_stack_base(os::current_stack_base()); | 317 set_stack_base(os::current_stack_base()); |
293 set_stack_size(os::current_stack_size()); | 318 set_stack_size(os::current_stack_size()); |
294 if (is_Java_thread()) { | |
295 ((JavaThread*) this)->set_stack_overflow_limit(); | |
296 } | |
297 // CR 7190089: on Solaris, primordial thread's stack is adjusted | 319 // CR 7190089: on Solaris, primordial thread's stack is adjusted |
298 // in initialize_thread(). Without the adjustment, stack size is | 320 // in initialize_thread(). Without the adjustment, stack size is |
299 // incorrect if stack is set to unlimited (ulimit -s unlimited). | 321 // incorrect if stack is set to unlimited (ulimit -s unlimited). |
300 // So far, only Solaris has real implementation of initialize_thread(). | 322 // So far, only Solaris has real implementation of initialize_thread(). |
301 // | 323 // |
747 | 769 |
748 #ifndef PRODUCT | 770 #ifndef PRODUCT |
749 void JavaThread::record_jump(address target, address instr, const char* file, int line) { | 771 void JavaThread::record_jump(address target, address instr, const char* file, int line) { |
750 | 772 |
751 // This should not need to be atomic as the only way for simultaneous | 773 // This should not need to be atomic as the only way for simultaneous |
752 // updates is via interrupts. Even then this should be rare or non-existent | 774 // updates is via interrupts. Even then this should be rare or non-existant |
753 // and we don't care that much anyway. | 775 // and we don't care that much anyway. |
754 | 776 |
755 int index = _jmp_ring_index; | 777 int index = _jmp_ring_index; |
756 _jmp_ring_index = (index + 1 ) & (jump_ring_buffer_size - 1); | 778 _jmp_ring_index = (index + 1 ) & (jump_ring_buffer_size - 1); |
757 _jmp_ring[index]._target = (intptr_t) target; | 779 _jmp_ring[index]._target = (intptr_t) target; |
806 assert(SharedHeap::heap()->workers()->active_workers() > 0, | 828 assert(SharedHeap::heap()->workers()->active_workers() > 0, |
807 "Should only fail when parallel."); | 829 "Should only fail when parallel."); |
808 return false; | 830 return false; |
809 } | 831 } |
810 | 832 |
811 void Thread::oops_do(OopClosure* f, CLDClosure* cld_f, CodeBlobClosure* cf) { | 833 void Thread::oops_do(OopClosure* f, CLDToOopClosure* cld_f, CodeBlobClosure* cf) { |
812 active_handles()->oops_do(f); | 834 active_handles()->oops_do(f); |
813 // Do oop for ThreadShadow | 835 // Do oop for ThreadShadow |
814 f->do_oop((oop*)&_pending_exception); | 836 f->do_oop((oop*)&_pending_exception); |
815 #ifdef GRAAL | 837 #ifdef GRAAL |
816 f->do_oop((oop*)&_pending_failed_speculation); | 838 f->do_oop((oop*)&_pending_failed_speculation); |
908 // This could potentially lead to deadlocks | 930 // This could potentially lead to deadlocks |
909 for(Monitor *cur = _owned_locks; cur; cur = cur->next()) { | 931 for(Monitor *cur = _owned_locks; cur; cur = cur->next()) { |
910 // Threads_lock is special, since the safepoint synchronization will not start before this is | 932 // Threads_lock is special, since the safepoint synchronization will not start before this is |
911 // acquired. Hence, a JavaThread cannot be holding it at a safepoint. So is VMOperationRequest_lock, | 933 // acquired. Hence, a JavaThread cannot be holding it at a safepoint. So is VMOperationRequest_lock, |
912 // since it is used to transfer control between JavaThreads and the VMThread | 934 // since it is used to transfer control between JavaThreads and the VMThread |
913 // Do not *exclude* any locks unless you are absolutely sure it is correct. Ask someone else first! | 935 // Do not *exclude* any locks unless you are absolutly sure it is correct. Ask someone else first! |
914 if ( (cur->allow_vm_block() && | 936 if ( (cur->allow_vm_block() && |
915 cur != Threads_lock && | 937 cur != Threads_lock && |
916 cur != Compile_lock && // Temporary: should not be necessary when we get separate compilation | 938 cur != Compile_lock && // Temporary: should not be necessary when we get spearate compilation |
917 cur != VMOperationRequest_lock && | 939 cur != VMOperationRequest_lock && |
918 cur != VMOperationQueue_lock) || | 940 cur != VMOperationQueue_lock) || |
919 cur->rank() == Mutex::special) { | 941 cur->rank() == Mutex::special) { |
920 warning("Thread holding lock at safepoint that vm can block on: %s", cur->name()); | 942 warning("Thread holding lock at safepoint that vm can block on: %s", cur->name()); |
921 } | 943 } |
1254 // if we didn't have any tasks we could have waited for a long time | 1276 // if we didn't have any tasks we could have waited for a long time |
1255 // consider the time_slept zero and reset time_before_loop | 1277 // consider the time_slept zero and reset time_before_loop |
1256 time_slept = 0; | 1278 time_slept = 0; |
1257 time_before_loop = now; | 1279 time_before_loop = now; |
1258 } else { | 1280 } else { |
1259 // need to recalculate since we might have new tasks in _tasks | 1281 // need to recalulate since we might have new tasks in _tasks |
1260 time_slept = (int) ((now - time_before_loop) / 1000000); | 1282 time_slept = (int) ((now - time_before_loop) / 1000000); |
1261 } | 1283 } |
1262 | 1284 |
1263 // Change to task list or spurious wakeup of some kind | 1285 // Change to task list or spurious wakeup of some kind |
1264 if (timedout || _should_terminate) { | 1286 if (timedout || _should_terminate) { |
1671 // The first routine called by a new Java thread | 1693 // The first routine called by a new Java thread |
1672 void JavaThread::run() { | 1694 void JavaThread::run() { |
1673 // initialize thread-local alloc buffer related fields | 1695 // initialize thread-local alloc buffer related fields |
1674 this->initialize_tlab(); | 1696 this->initialize_tlab(); |
1675 | 1697 |
1676 // used to test validity of stack trace backs | 1698 // used to test validitity of stack trace backs |
1677 this->record_base_of_stack_pointer(); | 1699 this->record_base_of_stack_pointer(); |
1678 | 1700 |
1679 // Record real stack base and size. | 1701 // Record real stack base and size. |
1680 this->record_stack_base_and_size(); | 1702 this->record_stack_base_and_size(); |
1681 | 1703 |
2755 _cur_thr->set_processed_thread(NULL); | 2777 _cur_thr->set_processed_thread(NULL); |
2756 } | 2778 } |
2757 } | 2779 } |
2758 }; | 2780 }; |
2759 | 2781 |
2760 void JavaThread::oops_do(OopClosure* f, CLDClosure* cld_f, CodeBlobClosure* cf) { | 2782 void JavaThread::oops_do(OopClosure* f, CLDToOopClosure* cld_f, CodeBlobClosure* cf) { |
2761 // Verify that the deferred card marks have been flushed. | 2783 // Verify that the deferred card marks have been flushed. |
2762 assert(deferred_card_mark().is_empty(), "Should be empty during GC"); | 2784 assert(deferred_card_mark().is_empty(), "Should be empty during GC"); |
2763 | 2785 |
2764 // The ThreadProfiler oops_do is done from FlatProfiler::oops_do | 2786 // The ThreadProfiler oops_do is done from FlatProfiler::oops_do |
2765 // since there may be more than one thread using each ThreadProfiler. | 2787 // since there may be more than one thread using each ThreadProfiler. |
3285 #ifndef PRODUCT | 3307 #ifndef PRODUCT |
3286 _ideal_graph_printer = NULL; | 3308 _ideal_graph_printer = NULL; |
3287 #endif | 3309 #endif |
3288 } | 3310 } |
3289 | 3311 |
3290 void CompilerThread::oops_do(OopClosure* f, CLDClosure* cld_f, CodeBlobClosure* cf) { | 3312 void CompilerThread::oops_do(OopClosure* f, CLDToOopClosure* cld_f, CodeBlobClosure* cf) { |
3291 JavaThread::oops_do(f, cld_f, cf); | 3313 JavaThread::oops_do(f, cld_f, cf); |
3292 if (_scanned_nmethod != NULL && cf != NULL) { | 3314 if (_scanned_nmethod != NULL && cf != NULL) { |
3293 // Safepoints can occur when the sweeper is scanning an nmethod so | 3315 // Safepoints can occur when the sweeper is scanning an nmethod so |
3294 // process it here to make sure it isn't unloaded in the middle of | 3316 // process it here to make sure it isn't unloaded in the middle of |
3295 // a scan. | 3317 // a scan. |
3341 tc->do_thread(wt); | 3363 tc->do_thread(wt); |
3342 | 3364 |
3343 // If CompilerThreads ever become non-JavaThreads, add them here | 3365 // If CompilerThreads ever become non-JavaThreads, add them here |
3344 } | 3366 } |
3345 | 3367 |
3346 | |
3347 void Threads::initialize_java_lang_classes(JavaThread* main_thread, TRAPS) { | |
3348 TraceTime timer("Initialize java.lang classes", TraceStartupTime); | |
3349 | |
3350 if (EagerXrunInit && Arguments::init_libraries_at_startup()) { | |
3351 create_vm_init_libraries(); | |
3352 } | |
3353 | |
3354 initialize_class(vmSymbols::java_lang_String(), CHECK); | |
3355 | |
3356 // Initialize java_lang.System (needed before creating the thread) | |
3357 initialize_class(vmSymbols::java_lang_System(), CHECK); | |
3358 initialize_class(vmSymbols::java_lang_ThreadGroup(), CHECK); | |
3359 Handle thread_group = create_initial_thread_group(CHECK); | |
3360 Universe::set_main_thread_group(thread_group()); | |
3361 initialize_class(vmSymbols::java_lang_Thread(), CHECK); | |
3362 oop thread_object = create_initial_thread(thread_group, main_thread, CHECK); | |
3363 main_thread->set_threadObj(thread_object); | |
3364 // Set thread status to running since main thread has | |
3365 // been started and running. | |
3366 java_lang_Thread::set_thread_status(thread_object, | |
3367 java_lang_Thread::RUNNABLE); | |
3368 | |
3369 // The VM creates & returns objects of this class. Make sure it's initialized. | |
3370 initialize_class(vmSymbols::java_lang_Class(), CHECK); | |
3371 | |
3372 // The VM preresolves methods to these classes. Make sure that they get initialized | |
3373 initialize_class(vmSymbols::java_lang_reflect_Method(), CHECK); | |
3374 initialize_class(vmSymbols::java_lang_ref_Finalizer(), CHECK); | |
3375 call_initializeSystemClass(CHECK); | |
3376 | |
3377 // get the Java runtime name after java.lang.System is initialized | |
3378 JDK_Version::set_runtime_name(get_java_runtime_name(THREAD)); | |
3379 JDK_Version::set_runtime_version(get_java_runtime_version(THREAD)); | |
3380 | |
3381 // an instance of OutOfMemory exception has been allocated earlier | |
3382 initialize_class(vmSymbols::java_lang_OutOfMemoryError(), CHECK); | |
3383 initialize_class(vmSymbols::java_lang_NullPointerException(), CHECK); | |
3384 initialize_class(vmSymbols::java_lang_ClassCastException(), CHECK); | |
3385 initialize_class(vmSymbols::java_lang_ArrayStoreException(), CHECK); | |
3386 initialize_class(vmSymbols::java_lang_ArithmeticException(), CHECK); | |
3387 initialize_class(vmSymbols::java_lang_StackOverflowError(), CHECK); | |
3388 initialize_class(vmSymbols::java_lang_IllegalMonitorStateException(), CHECK); | |
3389 initialize_class(vmSymbols::java_lang_IllegalArgumentException(), CHECK); | |
3390 } | |
3391 | |
3392 void Threads::initialize_jsr292_core_classes(TRAPS) { | |
3393 initialize_class(vmSymbols::java_lang_invoke_MethodHandle(), CHECK); | |
3394 initialize_class(vmSymbols::java_lang_invoke_MemberName(), CHECK); | |
3395 initialize_class(vmSymbols::java_lang_invoke_MethodHandleNatives(), CHECK); | |
3396 } | |
3397 | |
3398 jint Threads::create_vm(JavaVMInitArgs* args, bool* canTryAgain) { | 3368 jint Threads::create_vm(JavaVMInitArgs* args, bool* canTryAgain) { |
3399 | 3369 |
3400 extern void JDK_Version_init(); | 3370 extern void JDK_Version_init(); |
3401 | 3371 |
3402 // Check version | 3372 // Check version |
3412 os::init(); | 3382 os::init(); |
3413 | 3383 |
3414 // Initialize system properties. | 3384 // Initialize system properties. |
3415 Arguments::init_system_properties(); | 3385 Arguments::init_system_properties(); |
3416 | 3386 |
3417 // So that JDK version can be used as a discriminator when parsing arguments | 3387 // So that JDK version can be used as a discrimintor when parsing arguments |
3418 JDK_Version_init(); | 3388 JDK_Version_init(); |
3419 | 3389 |
3420 // Update/Initialize System properties after JDK version number is known | 3390 // Update/Initialize System properties after JDK version number is known |
3421 Arguments::init_version_specific_system_properties(); | 3391 Arguments::init_version_specific_system_properties(); |
3422 | 3392 |
3431 | 3401 |
3432 if (PauseAtStartup) { | 3402 if (PauseAtStartup) { |
3433 os::pause(); | 3403 os::pause(); |
3434 } | 3404 } |
3435 | 3405 |
3406 #ifndef USDT2 | |
3407 HS_DTRACE_PROBE(hotspot, vm__init__begin); | |
3408 #else /* USDT2 */ | |
3436 HOTSPOT_VM_INIT_BEGIN(); | 3409 HOTSPOT_VM_INIT_BEGIN(); |
3410 #endif /* USDT2 */ | |
3437 | 3411 |
3438 // Record VM creation timing statistics | 3412 // Record VM creation timing statistics |
3439 TraceVmCreationTime create_vm_timer; | 3413 TraceVmCreationTime create_vm_timer; |
3440 create_vm_timer.start(); | 3414 create_vm_timer.start(); |
3441 | 3415 |
3447 if (os_init_2_result != JNI_OK) return os_init_2_result; | 3421 if (os_init_2_result != JNI_OK) return os_init_2_result; |
3448 | 3422 |
3449 jint adjust_after_os_result = Arguments::adjust_after_os(); | 3423 jint adjust_after_os_result = Arguments::adjust_after_os(); |
3450 if (adjust_after_os_result != JNI_OK) return adjust_after_os_result; | 3424 if (adjust_after_os_result != JNI_OK) return adjust_after_os_result; |
3451 | 3425 |
3452 // initialize TLS | 3426 // intialize TLS |
3453 ThreadLocalStorage::init(); | 3427 ThreadLocalStorage::init(); |
3454 | 3428 |
3455 // Bootstrap native memory tracking, so it can start recording memory | 3429 // Bootstrap native memory tracking, so it can start recording memory |
3456 // activities before worker thread is started. This is the first phase | 3430 // activities before worker thread is started. This is the first phase |
3457 // of bootstrapping, VM is currently running in single-thread mode. | 3431 // of bootstrapping, VM is currently running in single-thread mode. |
3567 // Make sure we're starting with a clean slate. | 3541 // Make sure we're starting with a clean slate. |
3568 VM_Verify verify_op; | 3542 VM_Verify verify_op; |
3569 VMThread::execute(&verify_op); | 3543 VMThread::execute(&verify_op); |
3570 } | 3544 } |
3571 | 3545 |
3572 Thread* THREAD = Thread::current(); | 3546 EXCEPTION_MARK; |
3573 | 3547 |
3574 // At this point, the Universe is initialized, but we have not executed | 3548 // At this point, the Universe is initialized, but we have not executed |
3575 // any byte code. Now is a good time (the only time) to dump out the | 3549 // any byte code. Now is a good time (the only time) to dump out the |
3576 // internal state of the JVM for sharing. | 3550 // internal state of the JVM for sharing. |
3577 if (DumpSharedSpaces) { | 3551 if (DumpSharedSpaces) { |
3578 MetaspaceShared::preload_and_dump(CHECK_JNI_ERR); | 3552 MetaspaceShared::preload_and_dump(CHECK_0); |
3579 ShouldNotReachHere(); | 3553 ShouldNotReachHere(); |
3580 } | 3554 } |
3581 | 3555 |
3582 // Always call even when there are not JVMTI environments yet, since environments | 3556 // Always call even when there are not JVMTI environments yet, since environments |
3583 // may be attached late and JVMTI must track phases of VM execution | 3557 // may be attached late and JVMTI must track phases of VM execution |
3584 JvmtiExport::enter_start_phase(); | 3558 JvmtiExport::enter_start_phase(); |
3585 | 3559 |
3586 // Notify JVMTI agents that VM has started (JNI is up) - nop if no agents. | 3560 // Notify JVMTI agents that VM has started (JNI is up) - nop if no agents. |
3587 JvmtiExport::post_vm_start(); | 3561 JvmtiExport::post_vm_start(); |
3588 | 3562 |
3589 initialize_java_lang_classes(main_thread, CHECK_JNI_ERR); | 3563 { |
3590 | 3564 TraceTime timer("Initialize java.lang classes", TraceStartupTime); |
3591 // We need this for ClassDataSharing - the initial vm.info property is set | 3565 |
3592 // with the default value of CDS "sharing" which may be reset through | 3566 if (EagerXrunInit && Arguments::init_libraries_at_startup()) { |
3593 // command line options. | 3567 create_vm_init_libraries(); |
3594 reset_vm_info_property(CHECK_JNI_ERR); | 3568 } |
3569 | |
3570 initialize_class(vmSymbols::java_lang_String(), CHECK_0); | |
3571 | |
3572 // Initialize java_lang.System (needed before creating the thread) | |
3573 initialize_class(vmSymbols::java_lang_System(), CHECK_0); | |
3574 initialize_class(vmSymbols::java_lang_ThreadGroup(), CHECK_0); | |
3575 Handle thread_group = create_initial_thread_group(CHECK_0); | |
3576 Universe::set_main_thread_group(thread_group()); | |
3577 initialize_class(vmSymbols::java_lang_Thread(), CHECK_0); | |
3578 oop thread_object = create_initial_thread(thread_group, main_thread, CHECK_0); | |
3579 main_thread->set_threadObj(thread_object); | |
3580 // Set thread status to running since main thread has | |
3581 // been started and running. | |
3582 java_lang_Thread::set_thread_status(thread_object, | |
3583 java_lang_Thread::RUNNABLE); | |
3584 | |
3585 // The VM creates & returns objects of this class. Make sure it's initialized. | |
3586 initialize_class(vmSymbols::java_lang_Class(), CHECK_0); | |
3587 | |
3588 // The VM preresolves methods to these classes. Make sure that they get initialized | |
3589 initialize_class(vmSymbols::java_lang_reflect_Method(), CHECK_0); | |
3590 initialize_class(vmSymbols::java_lang_ref_Finalizer(), CHECK_0); | |
3591 call_initializeSystemClass(CHECK_0); | |
3592 | |
3593 // get the Java runtime name after java.lang.System is initialized | |
3594 JDK_Version::set_runtime_name(get_java_runtime_name(THREAD)); | |
3595 JDK_Version::set_runtime_version(get_java_runtime_version(THREAD)); | |
3596 | |
3597 // an instance of OutOfMemory exception has been allocated earlier | |
3598 initialize_class(vmSymbols::java_lang_OutOfMemoryError(), CHECK_0); | |
3599 initialize_class(vmSymbols::java_lang_NullPointerException(), CHECK_0); | |
3600 initialize_class(vmSymbols::java_lang_ClassCastException(), CHECK_0); | |
3601 initialize_class(vmSymbols::java_lang_ArrayStoreException(), CHECK_0); | |
3602 initialize_class(vmSymbols::java_lang_ArithmeticException(), CHECK_0); | |
3603 initialize_class(vmSymbols::java_lang_StackOverflowError(), CHECK_0); | |
3604 initialize_class(vmSymbols::java_lang_IllegalMonitorStateException(), CHECK_0); | |
3605 initialize_class(vmSymbols::java_lang_IllegalArgumentException(), CHECK_0); | |
3606 } | |
3607 | |
3608 // See : bugid 4211085. | |
3609 // Background : the static initializer of java.lang.Compiler tries to read | |
3610 // property"java.compiler" and read & write property "java.vm.info". | |
3611 // When a security manager is installed through the command line | |
3612 // option "-Djava.security.manager", the above properties are not | |
3613 // readable and the static initializer for java.lang.Compiler fails | |
3614 // resulting in a NoClassDefFoundError. This can happen in any | |
3615 // user code which calls methods in java.lang.Compiler. | |
3616 // Hack : the hack is to pre-load and initialize this class, so that only | |
3617 // system domains are on the stack when the properties are read. | |
3618 // Currently even the AWT code has calls to methods in java.lang.Compiler. | |
3619 // On the classic VM, java.lang.Compiler is loaded very early to load the JIT. | |
3620 // Future Fix : the best fix is to grant everyone permissions to read "java.compiler" and | |
3621 // read and write"java.vm.info" in the default policy file. See bugid 4211383 | |
3622 // Once that is done, we should remove this hack. | |
3623 initialize_class(vmSymbols::java_lang_Compiler(), CHECK_0); | |
3624 | |
3625 // More hackery - the static initializer of java.lang.Compiler adds the string "nojit" to | |
3626 // the java.vm.info property if no jit gets loaded through java.lang.Compiler (the hotspot | |
3627 // compiler does not get loaded through java.lang.Compiler). "java -version" with the | |
3628 // hotspot vm says "nojit" all the time which is confusing. So, we reset it here. | |
3629 // This should also be taken out as soon as 4211383 gets fixed. | |
3630 reset_vm_info_property(CHECK_0); | |
3595 | 3631 |
3596 quicken_jni_functions(); | 3632 quicken_jni_functions(); |
3597 | 3633 |
3598 // Must be run after init_ft which initializes ft_enabled | 3634 // Must be run after init_ft which initializes ft_enabled |
3599 if (TRACE_INITIALIZE() != JNI_OK) { | 3635 if (TRACE_INITIALIZE() != JNI_OK) { |
3602 | 3638 |
3603 // Set flag that basic initialization has completed. Used by exceptions and various | 3639 // Set flag that basic initialization has completed. Used by exceptions and various |
3604 // debug stuff, that does not work until all basic classes have been initialized. | 3640 // debug stuff, that does not work until all basic classes have been initialized. |
3605 set_init_completed(); | 3641 set_init_completed(); |
3606 | 3642 |
3643 #ifndef USDT2 | |
3644 HS_DTRACE_PROBE(hotspot, vm__init__end); | |
3645 #else /* USDT2 */ | |
3607 HOTSPOT_VM_INIT_END(); | 3646 HOTSPOT_VM_INIT_END(); |
3647 #endif /* USDT2 */ | |
3608 | 3648 |
3609 // record VM initialization completion time | 3649 // record VM initialization completion time |
3610 #if INCLUDE_MANAGEMENT | 3650 #if INCLUDE_MANAGEMENT |
3611 Management::record_vm_init_completed(); | 3651 Management::record_vm_init_completed(); |
3612 #endif // INCLUDE_MANAGEMENT | 3652 #endif // INCLUDE_MANAGEMENT |
3614 // Compute system loader. Note that this has to occur after set_init_completed, since | 3654 // Compute system loader. Note that this has to occur after set_init_completed, since |
3615 // valid exceptions may be thrown in the process. | 3655 // valid exceptions may be thrown in the process. |
3616 // Note that we do not use CHECK_0 here since we are inside an EXCEPTION_MARK and | 3656 // Note that we do not use CHECK_0 here since we are inside an EXCEPTION_MARK and |
3617 // set_init_completed has just been called, causing exceptions not to be shortcut | 3657 // set_init_completed has just been called, causing exceptions not to be shortcut |
3618 // anymore. We call vm_exit_during_initialization directly instead. | 3658 // anymore. We call vm_exit_during_initialization directly instead. |
3619 SystemDictionary::compute_java_system_loader(CHECK_JNI_ERR); | 3659 SystemDictionary::compute_java_system_loader(THREAD); |
3660 if (HAS_PENDING_EXCEPTION) { | |
3661 vm_exit_during_initialization(Handle(THREAD, PENDING_EXCEPTION)); | |
3662 } | |
3620 | 3663 |
3621 #if INCLUDE_ALL_GCS | 3664 #if INCLUDE_ALL_GCS |
3622 // Support for ConcurrentMarkSweep. This should be cleaned up | 3665 // Support for ConcurrentMarkSweep. This should be cleaned up |
3623 // and better encapsulated. The ugly nested if test would go away | 3666 // and better encapsulated. The ugly nested if test would go away |
3624 // once things are properly refactored. XXX YSR | 3667 // once things are properly refactored. XXX YSR |
3625 if (UseConcMarkSweepGC || UseG1GC) { | 3668 if (UseConcMarkSweepGC || UseG1GC) { |
3626 if (UseConcMarkSweepGC) { | 3669 if (UseConcMarkSweepGC) { |
3627 ConcurrentMarkSweepThread::makeSurrogateLockerThread(CHECK_JNI_ERR); | 3670 ConcurrentMarkSweepThread::makeSurrogateLockerThread(THREAD); |
3628 } else { | 3671 } else { |
3629 ConcurrentMarkThread::makeSurrogateLockerThread(CHECK_JNI_ERR); | 3672 ConcurrentMarkThread::makeSurrogateLockerThread(THREAD); |
3673 } | |
3674 if (HAS_PENDING_EXCEPTION) { | |
3675 vm_exit_during_initialization(Handle(THREAD, PENDING_EXCEPTION)); | |
3630 } | 3676 } |
3631 } | 3677 } |
3632 #endif // INCLUDE_ALL_GCS | 3678 #endif // INCLUDE_ALL_GCS |
3633 | 3679 |
3634 // Always call even when there are not JVMTI environments yet, since environments | 3680 // Always call even when there are not JVMTI environments yet, since environments |
3667 // initialize compiler(s) | 3713 // initialize compiler(s) |
3668 #if defined(COMPILER1) || defined(COMPILER2) || defined(SHARK) || defined(COMPILERGRAAL) | 3714 #if defined(COMPILER1) || defined(COMPILER2) || defined(SHARK) || defined(COMPILERGRAAL) |
3669 CompileBroker::compilation_init(); | 3715 CompileBroker::compilation_init(); |
3670 #endif | 3716 #endif |
3671 | 3717 |
3672 // Pre-initialize some JSR292 core classes to avoid deadlock during class loading. | |
3673 // It is done after compilers are initialized, because otherwise compilations of | |
3674 // signature polymorphic MH intrinsics can be missed | |
3675 // (see SystemDictionary::find_method_handle_intrinsic). | |
3676 if (EnableInvokeDynamic) { | 3718 if (EnableInvokeDynamic) { |
3677 initialize_jsr292_core_classes(CHECK_JNI_ERR); | 3719 // Pre-initialize some JSR292 core classes to avoid deadlock during class loading. |
3720 // It is done after compilers are initialized, because otherwise compilations of | |
3721 // signature polymorphic MH intrinsics can be missed | |
3722 // (see SystemDictionary::find_method_handle_intrinsic). | |
3723 initialize_class(vmSymbols::java_lang_invoke_MethodHandle(), CHECK_0); | |
3724 initialize_class(vmSymbols::java_lang_invoke_MemberName(), CHECK_0); | |
3725 initialize_class(vmSymbols::java_lang_invoke_MethodHandleNatives(), CHECK_0); | |
3678 } | 3726 } |
3679 | 3727 |
3680 #if INCLUDE_MANAGEMENT | 3728 #if INCLUDE_MANAGEMENT |
3681 Management::initialize(THREAD); | 3729 Management::initialize(THREAD); |
3730 #endif // INCLUDE_MANAGEMENT | |
3682 | 3731 |
3683 if (HAS_PENDING_EXCEPTION) { | 3732 if (HAS_PENDING_EXCEPTION) { |
3684 // management agent fails to start possibly due to | 3733 // management agent fails to start possibly due to |
3685 // configuration problem and is responsible for printing | 3734 // configuration problem and is responsible for printing |
3686 // stack trace if appropriate. Simply exit VM. | 3735 // stack trace if appropriate. Simply exit VM. |
3687 vm_exit(1); | 3736 vm_exit(1); |
3688 } | 3737 } |
3689 #endif // INCLUDE_MANAGEMENT | |
3690 | 3738 |
3691 if (Arguments::has_profile()) FlatProfiler::engage(main_thread, true); | 3739 if (Arguments::has_profile()) FlatProfiler::engage(main_thread, true); |
3692 if (MemProfiling) MemProfiler::engage(); | 3740 if (MemProfiling) MemProfiler::engage(); |
3693 StatSampler::engage(); | 3741 StatSampler::engage(); |
3694 if (CheckJNICalls) JniPeriodicChecker::engage(); | 3742 if (CheckJNICalls) JniPeriodicChecker::engage(); |
4185 | 4233 |
4186 // Operations on the Threads list for GC. These are not explicitly locked, | 4234 // Operations on the Threads list for GC. These are not explicitly locked, |
4187 // but the garbage collector must provide a safe context for them to run. | 4235 // but the garbage collector must provide a safe context for them to run. |
4188 // In particular, these things should never be called when the Threads_lock | 4236 // In particular, these things should never be called when the Threads_lock |
4189 // is held by some other thread. (Note: the Safepoint abstraction also | 4237 // is held by some other thread. (Note: the Safepoint abstraction also |
4190 // uses the Threads_lock to guarantee this property. It also makes sure that | 4238 // uses the Threads_lock to gurantee this property. It also makes sure that |
4191 // all threads gets blocked when exiting or starting). | 4239 // all threads gets blocked when exiting or starting). |
4192 | 4240 |
4193 void Threads::oops_do(OopClosure* f, CLDClosure* cld_f, CodeBlobClosure* cf) { | 4241 void Threads::oops_do(OopClosure* f, CLDToOopClosure* cld_f, CodeBlobClosure* cf) { |
4194 ALL_JAVA_THREADS(p) { | 4242 ALL_JAVA_THREADS(p) { |
4195 p->oops_do(f, cld_f, cf); | 4243 p->oops_do(f, cld_f, cf); |
4196 } | 4244 } |
4197 VMThread::vm_thread()->oops_do(f, cld_f, cf); | 4245 VMThread::vm_thread()->oops_do(f, cld_f, cf); |
4198 } | 4246 } |
4199 | 4247 |
4200 void Threads::possibly_parallel_oops_do(OopClosure* f, CLDClosure* cld_f, CodeBlobClosure* cf) { | 4248 void Threads::possibly_parallel_oops_do(OopClosure* f, CLDToOopClosure* cld_f, CodeBlobClosure* cf) { |
4201 // Introduce a mechanism allowing parallel threads to claim threads as | 4249 // Introduce a mechanism allowing parallel threads to claim threads as |
4202 // root groups. Overhead should be small enough to use all the time, | 4250 // root groups. Overhead should be small enough to use all the time, |
4203 // even in sequential code. | 4251 // even in sequential code. |
4204 SharedHeap* sh = SharedHeap::heap(); | 4252 SharedHeap* sh = SharedHeap::heap(); |
4205 // Cannot yet substitute active_workers for n_par_threads | 4253 // Cannot yet substitute active_workers for n_par_threads |
4475 for (;;) { | 4523 for (;;) { |
4476 while (*adr != 0) { | 4524 while (*adr != 0) { |
4477 ++ctr ; | 4525 ++ctr ; |
4478 if ((ctr & 0xFFF) == 0 || !os::is_MP()) { | 4526 if ((ctr & 0xFFF) == 0 || !os::is_MP()) { |
4479 if (Yields > 5) { | 4527 if (Yields > 5) { |
4480 os::naked_short_sleep(1); | 4528 // Consider using a simple NakedSleep() instead. |
4529 // Then SpinAcquire could be called by non-JVM threads | |
4530 Thread::current()->_ParkEvent->park(1) ; | |
4481 } else { | 4531 } else { |
4482 os::NakedYield() ; | 4532 os::NakedYield() ; |
4483 ++Yields ; | 4533 ++Yields ; |
4484 } | 4534 } |
4485 } else { | 4535 } else { |