4325 if (on_load_entry != NULL) { 4326 // Invoke the JVM_OnLoad function 4327 JavaThread* thread = JavaThread::current(); 4328 ThreadToNativeFromVM ttn(thread); 4329 HandleMark hm(thread); 4330 jint err = (*on_load_entry)(&main_vm, agent->options(), NULL); 4331 if (err != JNI_OK) { 4332 vm_exit_during_initialization("-Xrun library failed to init", agent->name()); 4333 } 4334 } else { 4335 vm_exit_during_initialization("Could not find JVM_OnLoad function in -Xrun library", agent->name()); 4336 } 4337 } 4338 } 4339 4340 4341 // Last thread running calls java.lang.Shutdown.shutdown() 4342 void JavaThread::invoke_shutdown_hooks() { 4343 HandleMark hm(this); 4344 4345 // We could get here with a pending exception, if so clear it now. 4346 if (this->has_pending_exception()) { 4347 this->clear_pending_exception(); 4348 } 4349 4350 EXCEPTION_MARK; 4351 Klass* shutdown_klass = 4352 SystemDictionary::resolve_or_null(vmSymbols::java_lang_Shutdown(), 4353 THREAD); 4354 if (shutdown_klass != NULL) { 4355 // SystemDictionary::resolve_or_null will return null if there was 4356 // an exception. If we cannot load the Shutdown class, just don't 4357 // call Shutdown.shutdown() at all. This will mean the shutdown hooks 4358 // won't be run. Note that if a shutdown hook was registered, 4359 // the Shutdown class would have already been loaded 4360 // (Runtime.addShutdownHook will load it). 4361 JavaValue result(T_VOID); 4362 JavaCalls::call_static(&result, 4363 shutdown_klass, 4364 vmSymbols::shutdown_name(), | 4325 if (on_load_entry != NULL) { 4326 // Invoke the JVM_OnLoad function 4327 JavaThread* thread = JavaThread::current(); 4328 ThreadToNativeFromVM ttn(thread); 4329 HandleMark hm(thread); 4330 jint err = (*on_load_entry)(&main_vm, agent->options(), NULL); 4331 if (err != JNI_OK) { 4332 vm_exit_during_initialization("-Xrun library failed to init", agent->name()); 4333 } 4334 } else { 4335 vm_exit_during_initialization("Could not find JVM_OnLoad function in -Xrun library", agent->name()); 4336 } 4337 } 4338 } 4339 4340 4341 // Last thread running calls java.lang.Shutdown.shutdown() 4342 void JavaThread::invoke_shutdown_hooks() { 4343 HandleMark hm(this); 4344 4345 // Link all classes for dynamic CDS dumping before vm exit. 4346 // Same operation is being done in JVM_BeforeHalt for handling the 4347 // case where the application calls System.exit(). 4348 if (DynamicDumpSharedSpaces) { 4349 MetaspaceShared::link_and_cleanup_shared_classes(false, this); 4350 } 4351 4352 // We could get here with a pending exception, if so clear it now. 4353 if (this->has_pending_exception()) { 4354 this->clear_pending_exception(); 4355 } 4356 4357 EXCEPTION_MARK; 4358 Klass* shutdown_klass = 4359 SystemDictionary::resolve_or_null(vmSymbols::java_lang_Shutdown(), 4360 THREAD); 4361 if (shutdown_klass != NULL) { 4362 // SystemDictionary::resolve_or_null will return null if there was 4363 // an exception. If we cannot load the Shutdown class, just don't 4364 // call Shutdown.shutdown() at all. This will mean the shutdown hooks 4365 // won't be run. Note that if a shutdown hook was registered, 4366 // the Shutdown class would have already been loaded 4367 // (Runtime.addShutdownHook will load it). 4368 JavaValue result(T_VOID); 4369 JavaCalls::call_static(&result, 4370 shutdown_klass, 4371 vmSymbols::shutdown_name(), |