4185 } 4186 4187 4188 // Last thread running calls java.lang.Shutdown.shutdown() 4189 void JavaThread::invoke_shutdown_hooks() { 4190 HandleMark hm(this); 4191 4192 // We could get here with a pending exception, if so clear it now. 4193 if (this->has_pending_exception()) { 4194 this->clear_pending_exception(); 4195 } 4196 4197 EXCEPTION_MARK; 4198 Klass* shutdown_klass = 4199 SystemDictionary::resolve_or_null(vmSymbols::java_lang_Shutdown(), 4200 THREAD); 4201 if (shutdown_klass != NULL) { 4202 // SystemDictionary::resolve_or_null will return null if there was 4203 // an exception. If we cannot load the Shutdown class, just don't 4204 // call Shutdown.shutdown() at all. This will mean the shutdown hooks 4205 // and finalizers (if runFinalizersOnExit is set) won't be run. 4206 // Note that if a shutdown hook was registered or runFinalizersOnExit 4207 // was called, the Shutdown class would have already been loaded 4208 // (Runtime.addShutdownHook and runFinalizersOnExit will load it). 4209 JavaValue result(T_VOID); 4210 JavaCalls::call_static(&result, 4211 shutdown_klass, 4212 vmSymbols::shutdown_method_name(), 4213 vmSymbols::void_method_signature(), 4214 THREAD); 4215 } 4216 CLEAR_PENDING_EXCEPTION; 4217 } 4218 4219 // Threads::destroy_vm() is normally called from jni_DestroyJavaVM() when 4220 // the program falls off the end of main(). Another VM exit path is through 4221 // vm_exit() when the program calls System.exit() to return a value or when 4222 // there is a serious error in VM. The two shutdown paths are not exactly 4223 // the same, but they share Shutdown.shutdown() at Java level and before_exit() 4224 // and VM_Exit op at VM level. 4225 // 4226 // Shutdown sequence: 4227 // + Shutdown native memory tracking if it is on 4228 // + Wait until we are the last non-daemon thread to execute | 4185 } 4186 4187 4188 // Last thread running calls java.lang.Shutdown.shutdown() 4189 void JavaThread::invoke_shutdown_hooks() { 4190 HandleMark hm(this); 4191 4192 // We could get here with a pending exception, if so clear it now. 4193 if (this->has_pending_exception()) { 4194 this->clear_pending_exception(); 4195 } 4196 4197 EXCEPTION_MARK; 4198 Klass* shutdown_klass = 4199 SystemDictionary::resolve_or_null(vmSymbols::java_lang_Shutdown(), 4200 THREAD); 4201 if (shutdown_klass != NULL) { 4202 // SystemDictionary::resolve_or_null will return null if there was 4203 // an exception. If we cannot load the Shutdown class, just don't 4204 // call Shutdown.shutdown() at all. This will mean the shutdown hooks 4205 // won't be run. Note that if a shutdown hook was registered 4206 // was called, the Shutdown class would have already been loaded 4207 // (Runtime.addShutdownHook will load it). 4208 JavaValue result(T_VOID); 4209 JavaCalls::call_static(&result, 4210 shutdown_klass, 4211 vmSymbols::shutdown_method_name(), 4212 vmSymbols::void_method_signature(), 4213 THREAD); 4214 } 4215 CLEAR_PENDING_EXCEPTION; 4216 } 4217 4218 // Threads::destroy_vm() is normally called from jni_DestroyJavaVM() when 4219 // the program falls off the end of main(). Another VM exit path is through 4220 // vm_exit() when the program calls System.exit() to return a value or when 4221 // there is a serious error in VM. The two shutdown paths are not exactly 4222 // the same, but they share Shutdown.shutdown() at Java level and before_exit() 4223 // and VM_Exit op at VM level. 4224 // 4225 // Shutdown sequence: 4226 // + Shutdown native memory tracking if it is on 4227 // + Wait until we are the last non-daemon thread to execute |