49 #include "oops/symbol.hpp"
50 #include "oops/verifyOopClosure.hpp"
51 #include "prims/jvm_misc.hpp"
52 #include "prims/jvmtiExport.hpp"
53 #include "prims/jvmtiThreadState.hpp"
54 #include "prims/privilegedStack.hpp"
55 #include "runtime/arguments.hpp"
56 #include "runtime/atomic.inline.hpp"
57 #include "runtime/biasedLocking.hpp"
58 #include "runtime/commandLineFlagConstraintList.hpp"
59 #include "runtime/commandLineFlagRangeList.hpp"
60 #include "runtime/deoptimization.hpp"
61 #include "runtime/fprofiler.hpp"
62 #include "runtime/frame.inline.hpp"
63 #include "runtime/globals.hpp"
64 #include "runtime/init.hpp"
65 #include "runtime/interfaceSupport.hpp"
66 #include "runtime/java.hpp"
67 #include "runtime/javaCalls.hpp"
68 #include "runtime/jniPeriodicChecker.hpp"
69 #include "runtime/memprofiler.hpp"
70 #include "runtime/mutexLocker.hpp"
71 #include "runtime/objectMonitor.hpp"
72 #include "runtime/orderAccess.inline.hpp"
73 #include "runtime/osThread.hpp"
74 #include "runtime/safepoint.hpp"
75 #include "runtime/sharedRuntime.hpp"
76 #include "runtime/statSampler.hpp"
77 #include "runtime/stubRoutines.hpp"
78 #include "runtime/sweeper.hpp"
79 #include "runtime/task.hpp"
80 #include "runtime/thread.inline.hpp"
81 #include "runtime/threadCritical.hpp"
82 #include "runtime/vframe.hpp"
83 #include "runtime/vframeArray.hpp"
84 #include "runtime/vframe_hp.hpp"
85 #include "runtime/vmThread.hpp"
86 #include "runtime/vm_operations.hpp"
87 #include "runtime/vm_version.hpp"
88 #include "services/attachListener.hpp"
3309 // Someday we could have a table or list of all non-JavaThreads.
3310 // For now, just manually iterate through them.
3311 tc->do_thread(VMThread::vm_thread());
3312 Universe::heap()->gc_threads_do(tc);
3313 WatcherThread *wt = WatcherThread::watcher_thread();
3314 // Strictly speaking, the following NULL check isn't sufficient to make sure
3315 // the data for WatcherThread is still valid upon being examined. However,
3316 // considering that WatchThread terminates when the VM is on the way to
3317 // exit at safepoint, the chance of the above is extremely small. The right
3318 // way to prevent termination of WatcherThread would be to acquire
3319 // Terminator_lock, but we can't do that without violating the lock rank
3320 // checking in some cases.
3321 if (wt != NULL) {
3322 tc->do_thread(wt);
3323 }
3324
3325 // If CompilerThreads ever become non-JavaThreads, add them here
3326 }
3327
3328 void Threads::initialize_java_lang_classes(JavaThread* main_thread, TRAPS) {
3329 TraceTime timer("Initialize java.lang classes", TraceStartupTime);
3330
3331 if (EagerXrunInit && Arguments::init_libraries_at_startup()) {
3332 create_vm_init_libraries();
3333 }
3334
3335 initialize_class(vmSymbols::java_lang_String(), CHECK);
3336
3337 // Inject CompactStrings value after the static initializers for String ran.
3338 java_lang_String::set_compact_strings(CompactStrings);
3339
3340 // Initialize java_lang.System (needed before creating the thread)
3341 initialize_class(vmSymbols::java_lang_System(), CHECK);
3342 // The VM creates & returns objects of this class. Make sure it's initialized.
3343 initialize_class(vmSymbols::java_lang_Class(), CHECK);
3344 initialize_class(vmSymbols::java_lang_ThreadGroup(), CHECK);
3345 Handle thread_group = create_initial_thread_group(CHECK);
3346 Universe::set_main_thread_group(thread_group());
3347 initialize_class(vmSymbols::java_lang_Thread(), CHECK);
3348 oop thread_object = create_initial_thread(thread_group, main_thread, CHECK);
3349 main_thread->set_threadObj(thread_object);
3356 initialize_class(vmSymbols::java_lang_reflect_Method(), CHECK);
3357 initialize_class(vmSymbols::java_lang_ref_Finalizer(), CHECK);
3358 call_initializeSystemClass(CHECK);
3359
3360 // get the Java runtime name after java.lang.System is initialized
3361 JDK_Version::set_runtime_name(get_java_runtime_name(THREAD));
3362 JDK_Version::set_runtime_version(get_java_runtime_version(THREAD));
3363
3364 // an instance of OutOfMemory exception has been allocated earlier
3365 initialize_class(vmSymbols::java_lang_OutOfMemoryError(), CHECK);
3366 initialize_class(vmSymbols::java_lang_NullPointerException(), CHECK);
3367 initialize_class(vmSymbols::java_lang_ClassCastException(), CHECK);
3368 initialize_class(vmSymbols::java_lang_ArrayStoreException(), CHECK);
3369 initialize_class(vmSymbols::java_lang_ArithmeticException(), CHECK);
3370 initialize_class(vmSymbols::java_lang_StackOverflowError(), CHECK);
3371 initialize_class(vmSymbols::java_lang_IllegalMonitorStateException(), CHECK);
3372 initialize_class(vmSymbols::java_lang_IllegalArgumentException(), CHECK);
3373 }
3374
3375 void Threads::initialize_jsr292_core_classes(TRAPS) {
3376 initialize_class(vmSymbols::java_lang_invoke_MethodHandle(), CHECK);
3377 initialize_class(vmSymbols::java_lang_invoke_MemberName(), CHECK);
3378 initialize_class(vmSymbols::java_lang_invoke_MethodHandleNatives(), CHECK);
3379 }
3380
3381 jint Threads::create_vm(JavaVMInitArgs* args, bool* canTryAgain) {
3382 extern void JDK_Version_init();
3383
3384 // Preinitialize version info.
3385 VM_Version::early_initialize();
3386
3387 // Check version
3388 if (!is_supported_jni_version(args->version)) return JNI_EVERSION;
3389
3390 // Initialize library-based TLS
3391 ThreadLocalStorage::init();
3392
3393 // Initialize the output stream module
3394 ostream_init();
3395
3425 if (ergo_result != JNI_OK) return ergo_result;
3426
3427 // Final check of all ranges after ergonomics which may change values.
3428 if (!CommandLineFlagRangeList::check_ranges()) {
3429 return JNI_EINVAL;
3430 }
3431
3432 // Final check of all 'AfterErgo' constraints after ergonomics which may change values.
3433 bool constraint_result = CommandLineFlagConstraintList::check_constraints(CommandLineFlagConstraint::AfterErgo);
3434 if (!constraint_result) {
3435 return JNI_EINVAL;
3436 }
3437
3438 if (PauseAtStartup) {
3439 os::pause();
3440 }
3441
3442 HOTSPOT_VM_INIT_BEGIN();
3443
3444 // Timing (must come after argument parsing)
3445 TraceTime timer("Create VM", TraceStartupTime);
3446
3447 // Initialize the os module after parsing the args
3448 jint os_init_2_result = os::init_2();
3449 if (os_init_2_result != JNI_OK) return os_init_2_result;
3450
3451 jint adjust_after_os_result = Arguments::adjust_after_os();
3452 if (adjust_after_os_result != JNI_OK) return adjust_after_os_result;
3453
3454 // Initialize output stream logging
3455 ostream_init_log();
3456
3457 // Convert -Xrun to -agentlib: if there is no JVM_OnLoad
3458 // Must be before create_vm_init_agents()
3459 if (Arguments::init_libraries_at_startup()) {
3460 convert_vm_init_libraries_to_agents();
3461 }
3462
3463 // Launch -agentlib/-agentpath and converted -Xrun agents
3464 if (Arguments::init_agents_at_startup()) {
3465 create_vm_init_agents();
3510 if (status != JNI_OK) {
3511 delete main_thread;
3512 *canTryAgain = false; // don't let caller call JNI_CreateJavaVM again
3513 return status;
3514 }
3515
3516 // Should be done after the heap is fully created
3517 main_thread->cache_global_variables();
3518
3519 HandleMark hm;
3520
3521 { MutexLocker mu(Threads_lock);
3522 Threads::add(main_thread);
3523 }
3524
3525 // Any JVMTI raw monitors entered in onload will transition into
3526 // real raw monitor. VM is setup enough here for raw monitor enter.
3527 JvmtiExport::transition_pending_onload_raw_monitors();
3528
3529 // Create the VMThread
3530 { TraceTime timer("Start VMThread", TraceStartupTime);
3531 VMThread::create();
3532 Thread* vmthread = VMThread::vm_thread();
3533
3534 if (!os::create_thread(vmthread, os::vm_thread)) {
3535 vm_exit_during_initialization("Cannot create VM thread. "
3536 "Out of system resources.");
3537 }
3538
3539 // Wait for the VM thread to become ready, and VMThread::run to initialize
3540 // Monitors can have spurious returns, must always check another state flag
3541 {
3542 MutexLocker ml(Notify_lock);
3543 os::start_thread(vmthread);
3544 while (vmthread->active_handles() == NULL) {
3545 Notify_lock->wait();
3546 }
3547 }
3548 }
3549
3550 assert(Universe::is_fully_initialized(), "not initialized");
|
49 #include "oops/symbol.hpp"
50 #include "oops/verifyOopClosure.hpp"
51 #include "prims/jvm_misc.hpp"
52 #include "prims/jvmtiExport.hpp"
53 #include "prims/jvmtiThreadState.hpp"
54 #include "prims/privilegedStack.hpp"
55 #include "runtime/arguments.hpp"
56 #include "runtime/atomic.inline.hpp"
57 #include "runtime/biasedLocking.hpp"
58 #include "runtime/commandLineFlagConstraintList.hpp"
59 #include "runtime/commandLineFlagRangeList.hpp"
60 #include "runtime/deoptimization.hpp"
61 #include "runtime/fprofiler.hpp"
62 #include "runtime/frame.inline.hpp"
63 #include "runtime/globals.hpp"
64 #include "runtime/init.hpp"
65 #include "runtime/interfaceSupport.hpp"
66 #include "runtime/java.hpp"
67 #include "runtime/javaCalls.hpp"
68 #include "runtime/jniPeriodicChecker.hpp"
69 #include "runtime/logTimer.hpp"
70 #include "runtime/memprofiler.hpp"
71 #include "runtime/mutexLocker.hpp"
72 #include "runtime/objectMonitor.hpp"
73 #include "runtime/orderAccess.inline.hpp"
74 #include "runtime/osThread.hpp"
75 #include "runtime/safepoint.hpp"
76 #include "runtime/sharedRuntime.hpp"
77 #include "runtime/statSampler.hpp"
78 #include "runtime/stubRoutines.hpp"
79 #include "runtime/sweeper.hpp"
80 #include "runtime/task.hpp"
81 #include "runtime/thread.inline.hpp"
82 #include "runtime/threadCritical.hpp"
83 #include "runtime/vframe.hpp"
84 #include "runtime/vframeArray.hpp"
85 #include "runtime/vframe_hp.hpp"
86 #include "runtime/vmThread.hpp"
87 #include "runtime/vm_operations.hpp"
88 #include "runtime/vm_version.hpp"
89 #include "services/attachListener.hpp"
3310 // Someday we could have a table or list of all non-JavaThreads.
3311 // For now, just manually iterate through them.
3312 tc->do_thread(VMThread::vm_thread());
3313 Universe::heap()->gc_threads_do(tc);
3314 WatcherThread *wt = WatcherThread::watcher_thread();
3315 // Strictly speaking, the following NULL check isn't sufficient to make sure
3316 // the data for WatcherThread is still valid upon being examined. However,
3317 // considering that WatchThread terminates when the VM is on the way to
3318 // exit at safepoint, the chance of the above is extremely small. The right
3319 // way to prevent termination of WatcherThread would be to acquire
3320 // Terminator_lock, but we can't do that without violating the lock rank
3321 // checking in some cases.
3322 if (wt != NULL) {
3323 tc->do_thread(wt);
3324 }
3325
3326 // If CompilerThreads ever become non-JavaThreads, add them here
3327 }
3328
3329 void Threads::initialize_java_lang_classes(JavaThread* main_thread, TRAPS) {
3330 TraceStartupTime timer("Initialize java.lang classes");
3331
3332 if (EagerXrunInit && Arguments::init_libraries_at_startup()) {
3333 create_vm_init_libraries();
3334 }
3335
3336 initialize_class(vmSymbols::java_lang_String(), CHECK);
3337
3338 // Inject CompactStrings value after the static initializers for String ran.
3339 java_lang_String::set_compact_strings(CompactStrings);
3340
3341 // Initialize java_lang.System (needed before creating the thread)
3342 initialize_class(vmSymbols::java_lang_System(), CHECK);
3343 // The VM creates & returns objects of this class. Make sure it's initialized.
3344 initialize_class(vmSymbols::java_lang_Class(), CHECK);
3345 initialize_class(vmSymbols::java_lang_ThreadGroup(), CHECK);
3346 Handle thread_group = create_initial_thread_group(CHECK);
3347 Universe::set_main_thread_group(thread_group());
3348 initialize_class(vmSymbols::java_lang_Thread(), CHECK);
3349 oop thread_object = create_initial_thread(thread_group, main_thread, CHECK);
3350 main_thread->set_threadObj(thread_object);
3357 initialize_class(vmSymbols::java_lang_reflect_Method(), CHECK);
3358 initialize_class(vmSymbols::java_lang_ref_Finalizer(), CHECK);
3359 call_initializeSystemClass(CHECK);
3360
3361 // get the Java runtime name after java.lang.System is initialized
3362 JDK_Version::set_runtime_name(get_java_runtime_name(THREAD));
3363 JDK_Version::set_runtime_version(get_java_runtime_version(THREAD));
3364
3365 // an instance of OutOfMemory exception has been allocated earlier
3366 initialize_class(vmSymbols::java_lang_OutOfMemoryError(), CHECK);
3367 initialize_class(vmSymbols::java_lang_NullPointerException(), CHECK);
3368 initialize_class(vmSymbols::java_lang_ClassCastException(), CHECK);
3369 initialize_class(vmSymbols::java_lang_ArrayStoreException(), CHECK);
3370 initialize_class(vmSymbols::java_lang_ArithmeticException(), CHECK);
3371 initialize_class(vmSymbols::java_lang_StackOverflowError(), CHECK);
3372 initialize_class(vmSymbols::java_lang_IllegalMonitorStateException(), CHECK);
3373 initialize_class(vmSymbols::java_lang_IllegalArgumentException(), CHECK);
3374 }
3375
3376 void Threads::initialize_jsr292_core_classes(TRAPS) {
3377 TraceStartupTime timer("Initialize java.lang.invoke classes");
3378
3379 initialize_class(vmSymbols::java_lang_invoke_MethodHandle(), CHECK);
3380 initialize_class(vmSymbols::java_lang_invoke_MemberName(), CHECK);
3381 initialize_class(vmSymbols::java_lang_invoke_MethodHandleNatives(), CHECK);
3382 }
3383
3384 jint Threads::create_vm(JavaVMInitArgs* args, bool* canTryAgain) {
3385 extern void JDK_Version_init();
3386
3387 // Preinitialize version info.
3388 VM_Version::early_initialize();
3389
3390 // Check version
3391 if (!is_supported_jni_version(args->version)) return JNI_EVERSION;
3392
3393 // Initialize library-based TLS
3394 ThreadLocalStorage::init();
3395
3396 // Initialize the output stream module
3397 ostream_init();
3398
3428 if (ergo_result != JNI_OK) return ergo_result;
3429
3430 // Final check of all ranges after ergonomics which may change values.
3431 if (!CommandLineFlagRangeList::check_ranges()) {
3432 return JNI_EINVAL;
3433 }
3434
3435 // Final check of all 'AfterErgo' constraints after ergonomics which may change values.
3436 bool constraint_result = CommandLineFlagConstraintList::check_constraints(CommandLineFlagConstraint::AfterErgo);
3437 if (!constraint_result) {
3438 return JNI_EINVAL;
3439 }
3440
3441 if (PauseAtStartup) {
3442 os::pause();
3443 }
3444
3445 HOTSPOT_VM_INIT_BEGIN();
3446
3447 // Timing (must come after argument parsing)
3448 TraceStartupTime timer("Create VM");
3449
3450 // Initialize the os module after parsing the args
3451 jint os_init_2_result = os::init_2();
3452 if (os_init_2_result != JNI_OK) return os_init_2_result;
3453
3454 jint adjust_after_os_result = Arguments::adjust_after_os();
3455 if (adjust_after_os_result != JNI_OK) return adjust_after_os_result;
3456
3457 // Initialize output stream logging
3458 ostream_init_log();
3459
3460 // Convert -Xrun to -agentlib: if there is no JVM_OnLoad
3461 // Must be before create_vm_init_agents()
3462 if (Arguments::init_libraries_at_startup()) {
3463 convert_vm_init_libraries_to_agents();
3464 }
3465
3466 // Launch -agentlib/-agentpath and converted -Xrun agents
3467 if (Arguments::init_agents_at_startup()) {
3468 create_vm_init_agents();
3513 if (status != JNI_OK) {
3514 delete main_thread;
3515 *canTryAgain = false; // don't let caller call JNI_CreateJavaVM again
3516 return status;
3517 }
3518
3519 // Should be done after the heap is fully created
3520 main_thread->cache_global_variables();
3521
3522 HandleMark hm;
3523
3524 { MutexLocker mu(Threads_lock);
3525 Threads::add(main_thread);
3526 }
3527
3528 // Any JVMTI raw monitors entered in onload will transition into
3529 // real raw monitor. VM is setup enough here for raw monitor enter.
3530 JvmtiExport::transition_pending_onload_raw_monitors();
3531
3532 // Create the VMThread
3533 { TraceStartupTime timer("Start VMThread");
3534
3535 VMThread::create();
3536 Thread* vmthread = VMThread::vm_thread();
3537
3538 if (!os::create_thread(vmthread, os::vm_thread)) {
3539 vm_exit_during_initialization("Cannot create VM thread. "
3540 "Out of system resources.");
3541 }
3542
3543 // Wait for the VM thread to become ready, and VMThread::run to initialize
3544 // Monitors can have spurious returns, must always check another state flag
3545 {
3546 MutexLocker ml(Notify_lock);
3547 os::start_thread(vmthread);
3548 while (vmthread->active_handles() == NULL) {
3549 Notify_lock->wait();
3550 }
3551 }
3552 }
3553
3554 assert(Universe::is_fully_initialized(), "not initialized");
|