1699 Handle threadObj(thread, thread->threadObj());
1700 assert(threadObj.not_null(), "java thread object must exist");
1701 ObjectLocker lock(threadObj, thread);
1702 // Ignore pending exception (ThreadDeath), since we are exiting anyway
1703 thread->clear_pending_exception();
1704 // Thread is exiting. So set thread_status field in java.lang.Thread class to TERMINATED.
1705 java_lang_Thread::set_thread_status(threadObj(), java_lang_Thread::TERMINATED);
1706 // Clear the native thread instance - this makes isAlive return false and allows the join()
1707 // to complete once we've done the notify_all below
1708 java_lang_Thread::set_thread(threadObj(), NULL);
1709 lock.notify_all(thread);
1710 // Ignore pending exception (ThreadDeath), since we are exiting anyway
1711 thread->clear_pending_exception();
1712 }
1713
1714
1715 // For any new cleanup additions, please check to see if they need to be applied to
1716 // cleanup_failed_attach_current_thread as well.
1717 void JavaThread::exit(bool destroy_vm, ExitType exit_type) {
1718 assert(this == JavaThread::current(), "thread consistency check");
1719 if (!InitializeJavaLangSystem) return;
1720
1721 HandleMark hm(this);
1722 Handle uncaught_exception(this, this->pending_exception());
1723 this->clear_pending_exception();
1724 Handle threadObj(this, this->threadObj());
1725 assert(threadObj.not_null(), "Java thread object should be created");
1726
1727 if (get_thread_profiler() != NULL) {
1728 get_thread_profiler()->disengage();
1729 ResourceMark rm;
1730 get_thread_profiler()->print(get_thread_name());
1731 }
1732
1733
1734 // FIXIT: This code should be moved into else part, when reliable 1.2/1.3 check is in place
1735 {
1736 EXCEPTION_MARK;
1737
1738 CLEAR_PENDING_EXCEPTION;
1739 }
3452 // internal state of the JVM for sharing.
3453 if (DumpSharedSpaces) {
3454 MetaspaceShared::preload_and_dump(CHECK_0);
3455 ShouldNotReachHere();
3456 }
3457
3458 // Always call even when there are not JVMTI environments yet, since environments
3459 // may be attached late and JVMTI must track phases of VM execution
3460 JvmtiExport::enter_start_phase();
3461
3462 // Notify JVMTI agents that VM has started (JNI is up) - nop if no agents.
3463 JvmtiExport::post_vm_start();
3464
3465 {
3466 TraceTime timer("Initialize java.lang classes", TraceStartupTime);
3467
3468 if (EagerXrunInit && Arguments::init_libraries_at_startup()) {
3469 create_vm_init_libraries();
3470 }
3471
3472 if (InitializeJavaLangString) {
3473 initialize_class(vmSymbols::java_lang_String(), CHECK_0);
3474 } else {
3475 warning("java.lang.String not initialized");
3476 }
3477
3478 if (AggressiveOpts) {
3479 {
3480 // Forcibly initialize java/util/HashMap and mutate the private
3481 // static final "frontCacheEnabled" field before we start creating instances
3482 #ifdef ASSERT
3483 Klass* tmp_k = SystemDictionary::find(vmSymbols::java_util_HashMap(), Handle(), Handle(), CHECK_0);
3484 assert(tmp_k == NULL, "java/util/HashMap should not be loaded yet");
3485 #endif
3486 Klass* k_o = SystemDictionary::resolve_or_null(vmSymbols::java_util_HashMap(), Handle(), Handle(), CHECK_0);
3487 KlassHandle k = KlassHandle(THREAD, k_o);
3488 guarantee(k.not_null(), "Must find java/util/HashMap");
3489 instanceKlassHandle ik = instanceKlassHandle(THREAD, k());
3490 ik->initialize(CHECK_0);
3491 fieldDescriptor fd;
3492 // Possible we might not find this field; if so, don't break
3493 if (ik->find_local_field(vmSymbols::frontCacheEnabled_name(), vmSymbols::bool_signature(), &fd)) {
3494 k()->java_mirror()->bool_field_put(fd.offset(), true);
3495 }
3496 }
3497
3498 if (UseStringCache) {
3499 // Forcibly initialize java/lang/StringValue and mutate the private
3500 // static final "stringCacheEnabled" field before we start creating instances
3501 Klass* k_o = SystemDictionary::resolve_or_null(vmSymbols::java_lang_StringValue(), Handle(), Handle(), CHECK_0);
3502 // Possible that StringValue isn't present: if so, silently don't break
3503 if (k_o != NULL) {
3504 KlassHandle k = KlassHandle(THREAD, k_o);
3505 instanceKlassHandle ik = instanceKlassHandle(THREAD, k());
3506 ik->initialize(CHECK_0);
3507 fieldDescriptor fd;
3508 // Possible we might not find this field: if so, silently don't break
3509 if (ik->find_local_field(vmSymbols::stringCacheEnabled_name(), vmSymbols::bool_signature(), &fd)) {
3510 k()->java_mirror()->bool_field_put(fd.offset(), true);
3511 }
3512 }
3513 }
3514 }
3515
3516 // Initialize java_lang.System (needed before creating the thread)
3517 if (InitializeJavaLangSystem) {
3518 initialize_class(vmSymbols::java_lang_System(), CHECK_0);
3519 initialize_class(vmSymbols::java_lang_ThreadGroup(), CHECK_0);
3520 Handle thread_group = create_initial_thread_group(CHECK_0);
3521 Universe::set_main_thread_group(thread_group());
3522 initialize_class(vmSymbols::java_lang_Thread(), CHECK_0);
3523 oop thread_object = create_initial_thread(thread_group, main_thread, CHECK_0);
3524 main_thread->set_threadObj(thread_object);
3525 // Set thread status to running since main thread has
3526 // been started and running.
3527 java_lang_Thread::set_thread_status(thread_object,
3528 java_lang_Thread::RUNNABLE);
3529
3530 // The VM creates & returns objects of this class. Make sure it's initialized.
3531 initialize_class(vmSymbols::java_lang_Class(), CHECK_0);
3532
3533 // The VM preresolves methods to these classes. Make sure that they get initialized
3534 initialize_class(vmSymbols::java_lang_reflect_Method(), CHECK_0);
3535 initialize_class(vmSymbols::java_lang_ref_Finalizer(), CHECK_0);
3536 call_initializeSystemClass(CHECK_0);
3537
3538 // get the Java runtime name after java.lang.System is initialized
3539 JDK_Version::set_runtime_name(get_java_runtime_name(THREAD));
3540 JDK_Version::set_runtime_version(get_java_runtime_version(THREAD));
3541 } else {
3542 warning("java.lang.System not initialized");
3543 }
3544
3545 // an instance of OutOfMemory exception has been allocated earlier
3546 if (InitializeJavaLangExceptionsErrors) {
3547 initialize_class(vmSymbols::java_lang_OutOfMemoryError(), CHECK_0);
3548 initialize_class(vmSymbols::java_lang_NullPointerException(), CHECK_0);
3549 initialize_class(vmSymbols::java_lang_ClassCastException(), CHECK_0);
3550 initialize_class(vmSymbols::java_lang_ArrayStoreException(), CHECK_0);
3551 initialize_class(vmSymbols::java_lang_ArithmeticException(), CHECK_0);
3552 initialize_class(vmSymbols::java_lang_StackOverflowError(), CHECK_0);
3553 initialize_class(vmSymbols::java_lang_IllegalMonitorStateException(), CHECK_0);
3554 initialize_class(vmSymbols::java_lang_IllegalArgumentException(), CHECK_0);
3555 } else {
3556 warning("java.lang.OutOfMemoryError has not been initialized");
3557 warning("java.lang.NullPointerException has not been initialized");
3558 warning("java.lang.ClassCastException has not been initialized");
3559 warning("java.lang.ArrayStoreException has not been initialized");
3560 warning("java.lang.ArithmeticException has not been initialized");
3561 warning("java.lang.StackOverflowError has not been initialized");
3562 warning("java.lang.IllegalArgumentException has not been initialized");
3563 }
3564 }
3565
3566 // See : bugid 4211085.
3567 // Background : the static initializer of java.lang.Compiler tries to read
3568 // property"java.compiler" and read & write property "java.vm.info".
3569 // When a security manager is installed through the command line
3570 // option "-Djava.security.manager", the above properties are not
3571 // readable and the static initializer for java.lang.Compiler fails
3572 // resulting in a NoClassDefFoundError. This can happen in any
3573 // user code which calls methods in java.lang.Compiler.
3574 // Hack : the hack is to pre-load and initialize this class, so that only
3575 // system domains are on the stack when the properties are read.
3576 // Currently even the AWT code has calls to methods in java.lang.Compiler.
3577 // On the classic VM, java.lang.Compiler is loaded very early to load the JIT.
3578 // Future Fix : the best fix is to grant everyone permissions to read "java.compiler" and
3579 // read and write"java.vm.info" in the default policy file. See bugid 4211383
3580 // Once that is done, we should remove this hack.
3581 initialize_class(vmSymbols::java_lang_Compiler(), CHECK_0);
3582
3583 // More hackery - the static initializer of java.lang.Compiler adds the string "nojit" to
|
1699 Handle threadObj(thread, thread->threadObj());
1700 assert(threadObj.not_null(), "java thread object must exist");
1701 ObjectLocker lock(threadObj, thread);
1702 // Ignore pending exception (ThreadDeath), since we are exiting anyway
1703 thread->clear_pending_exception();
1704 // Thread is exiting. So set thread_status field in java.lang.Thread class to TERMINATED.
1705 java_lang_Thread::set_thread_status(threadObj(), java_lang_Thread::TERMINATED);
1706 // Clear the native thread instance - this makes isAlive return false and allows the join()
1707 // to complete once we've done the notify_all below
1708 java_lang_Thread::set_thread(threadObj(), NULL);
1709 lock.notify_all(thread);
1710 // Ignore pending exception (ThreadDeath), since we are exiting anyway
1711 thread->clear_pending_exception();
1712 }
1713
1714
1715 // For any new cleanup additions, please check to see if they need to be applied to
1716 // cleanup_failed_attach_current_thread as well.
1717 void JavaThread::exit(bool destroy_vm, ExitType exit_type) {
1718 assert(this == JavaThread::current(), "thread consistency check");
1719
1720 HandleMark hm(this);
1721 Handle uncaught_exception(this, this->pending_exception());
1722 this->clear_pending_exception();
1723 Handle threadObj(this, this->threadObj());
1724 assert(threadObj.not_null(), "Java thread object should be created");
1725
1726 if (get_thread_profiler() != NULL) {
1727 get_thread_profiler()->disengage();
1728 ResourceMark rm;
1729 get_thread_profiler()->print(get_thread_name());
1730 }
1731
1732
1733 // FIXIT: This code should be moved into else part, when reliable 1.2/1.3 check is in place
1734 {
1735 EXCEPTION_MARK;
1736
1737 CLEAR_PENDING_EXCEPTION;
1738 }
3451 // internal state of the JVM for sharing.
3452 if (DumpSharedSpaces) {
3453 MetaspaceShared::preload_and_dump(CHECK_0);
3454 ShouldNotReachHere();
3455 }
3456
3457 // Always call even when there are not JVMTI environments yet, since environments
3458 // may be attached late and JVMTI must track phases of VM execution
3459 JvmtiExport::enter_start_phase();
3460
3461 // Notify JVMTI agents that VM has started (JNI is up) - nop if no agents.
3462 JvmtiExport::post_vm_start();
3463
3464 {
3465 TraceTime timer("Initialize java.lang classes", TraceStartupTime);
3466
3467 if (EagerXrunInit && Arguments::init_libraries_at_startup()) {
3468 create_vm_init_libraries();
3469 }
3470
3471 initialize_class(vmSymbols::java_lang_String(), CHECK_0);
3472
3473 if (AggressiveOpts) {
3474 {
3475 // Forcibly initialize java/util/HashMap and mutate the private
3476 // static final "frontCacheEnabled" field before we start creating instances
3477 #ifdef ASSERT
3478 Klass* tmp_k = SystemDictionary::find(vmSymbols::java_util_HashMap(), Handle(), Handle(), CHECK_0);
3479 assert(tmp_k == NULL, "java/util/HashMap should not be loaded yet");
3480 #endif
3481 Klass* k_o = SystemDictionary::resolve_or_null(vmSymbols::java_util_HashMap(), Handle(), Handle(), CHECK_0);
3482 KlassHandle k = KlassHandle(THREAD, k_o);
3483 guarantee(k.not_null(), "Must find java/util/HashMap");
3484 instanceKlassHandle ik = instanceKlassHandle(THREAD, k());
3485 ik->initialize(CHECK_0);
3486 fieldDescriptor fd;
3487 // Possible we might not find this field; if so, don't break
3488 if (ik->find_local_field(vmSymbols::frontCacheEnabled_name(), vmSymbols::bool_signature(), &fd)) {
3489 k()->java_mirror()->bool_field_put(fd.offset(), true);
3490 }
3491 }
3492
3493 if (UseStringCache) {
3494 // Forcibly initialize java/lang/StringValue and mutate the private
3495 // static final "stringCacheEnabled" field before we start creating instances
3496 Klass* k_o = SystemDictionary::resolve_or_null(vmSymbols::java_lang_StringValue(), Handle(), Handle(), CHECK_0);
3497 // Possible that StringValue isn't present: if so, silently don't break
3498 if (k_o != NULL) {
3499 KlassHandle k = KlassHandle(THREAD, k_o);
3500 instanceKlassHandle ik = instanceKlassHandle(THREAD, k());
3501 ik->initialize(CHECK_0);
3502 fieldDescriptor fd;
3503 // Possible we might not find this field: if so, silently don't break
3504 if (ik->find_local_field(vmSymbols::stringCacheEnabled_name(), vmSymbols::bool_signature(), &fd)) {
3505 k()->java_mirror()->bool_field_put(fd.offset(), true);
3506 }
3507 }
3508 }
3509 }
3510
3511 // Initialize java_lang.System (needed before creating the thread)
3512 initialize_class(vmSymbols::java_lang_System(), CHECK_0);
3513 initialize_class(vmSymbols::java_lang_ThreadGroup(), CHECK_0);
3514 Handle thread_group = create_initial_thread_group(CHECK_0);
3515 Universe::set_main_thread_group(thread_group());
3516 initialize_class(vmSymbols::java_lang_Thread(), CHECK_0);
3517 oop thread_object = create_initial_thread(thread_group, main_thread, CHECK_0);
3518 main_thread->set_threadObj(thread_object);
3519 // Set thread status to running since main thread has
3520 // been started and running.
3521 java_lang_Thread::set_thread_status(thread_object,
3522 java_lang_Thread::RUNNABLE);
3523
3524 // The VM creates & returns objects of this class. Make sure it's initialized.
3525 initialize_class(vmSymbols::java_lang_Class(), CHECK_0);
3526
3527 // The VM preresolves methods to these classes. Make sure that they get initialized
3528 initialize_class(vmSymbols::java_lang_reflect_Method(), CHECK_0);
3529 initialize_class(vmSymbols::java_lang_ref_Finalizer(), CHECK_0);
3530 call_initializeSystemClass(CHECK_0);
3531
3532 // get the Java runtime name after java.lang.System is initialized
3533 JDK_Version::set_runtime_name(get_java_runtime_name(THREAD));
3534 JDK_Version::set_runtime_version(get_java_runtime_version(THREAD));
3535
3536 // an instance of OutOfMemory exception has been allocated earlier
3537 initialize_class(vmSymbols::java_lang_OutOfMemoryError(), CHECK_0);
3538 initialize_class(vmSymbols::java_lang_NullPointerException(), CHECK_0);
3539 initialize_class(vmSymbols::java_lang_ClassCastException(), CHECK_0);
3540 initialize_class(vmSymbols::java_lang_ArrayStoreException(), CHECK_0);
3541 initialize_class(vmSymbols::java_lang_ArithmeticException(), CHECK_0);
3542 initialize_class(vmSymbols::java_lang_StackOverflowError(), CHECK_0);
3543 initialize_class(vmSymbols::java_lang_IllegalMonitorStateException(), CHECK_0);
3544 initialize_class(vmSymbols::java_lang_IllegalArgumentException(), CHECK_0);
3545 }
3546
3547 // See : bugid 4211085.
3548 // Background : the static initializer of java.lang.Compiler tries to read
3549 // property"java.compiler" and read & write property "java.vm.info".
3550 // When a security manager is installed through the command line
3551 // option "-Djava.security.manager", the above properties are not
3552 // readable and the static initializer for java.lang.Compiler fails
3553 // resulting in a NoClassDefFoundError. This can happen in any
3554 // user code which calls methods in java.lang.Compiler.
3555 // Hack : the hack is to pre-load and initialize this class, so that only
3556 // system domains are on the stack when the properties are read.
3557 // Currently even the AWT code has calls to methods in java.lang.Compiler.
3558 // On the classic VM, java.lang.Compiler is loaded very early to load the JIT.
3559 // Future Fix : the best fix is to grant everyone permissions to read "java.compiler" and
3560 // read and write"java.vm.info" in the default policy file. See bugid 4211383
3561 // Once that is done, we should remove this hack.
3562 initialize_class(vmSymbols::java_lang_Compiler(), CHECK_0);
3563
3564 // More hackery - the static initializer of java.lang.Compiler adds the string "nojit" to
|