void init_cause(jthrowable exc_object, jthrowable exc_cause) { ASSERT_RAISE_AREA; assert(exc_cause); assert(hythread_is_suspend_enabled()); tmn_suspend_disable(); Class* exc_class = exc_object->object->vt()->clss; Method *init_cause_method = class_lookup_method_recursive(exc_class, "initCause", "(Ljava/lang/Throwable;)Ljava/lang/Throwable;"); assert(init_cause_method); jvalue args[2]; args[0].l = exc_object; args[1].l = exc_cause; jvalue ret_val; vm_execute_java_method_array((jmethodID) init_cause_method, &ret_val, args); tmn_suspend_enable(); }
/** * Runs java.lang.Thread.detach() method. */ static jint run_java_detach(jthread java_thread) { assert(hythread_is_suspend_enabled()); JNIEnv *jni_env = jthread_get_JNI_env(java_thread); Global_Env *vm_env = jni_get_vm_env(jni_env); Class *thread_class = vm_env->java_lang_Thread_Class; static Method *detach = NULL; if (detach == NULL) { const char *method_name = "detach"; const char *descriptor = "(Ljava/lang/Throwable;)V"; detach = class_lookup_method(thread_class, method_name, descriptor); if (detach == NULL) { TRACE("Failed to find thread's detach method " << descriptor << " , exception = " << exn_get()); return TM_ERROR_INTERNAL; } } // Initialize arguments. jvalue args[2]; args[0].l = java_thread; if (vm_env->IsVmShutdowning()) { args[1].l = NULL; } else { args[1].l = exn_get(); } exn_clear(); hythread_suspend_disable(); vm_execute_java_method_array((jmethodID) detach, 0, args); hythread_suspend_enable(); if (exn_raised()) { TRACE ("java.lang.Thread.detach(Throwable) method completed with an exception: " << exn_get_name()); return TM_ERROR_INTERNAL; } return TM_ERROR_NONE; }
jthrowable create_exception(Class* exc_class, Method* exc_init, jvalue* args) { ASSERT_RAISE_AREA; assert(hythread_is_suspend_enabled()); bool suspended_enabled = hythread_is_suspend_enabled(); if (suspended_enabled) { tmn_suspend_disable(); } ManagedObject *man_obj = class_alloc_new_object(exc_class); if (!man_obj) { exn_raise_object(VM_Global_State::loader_env->java_lang_OutOfMemoryError); if (suspended_enabled) { tmn_suspend_enable(); } return NULL; } jthrowable exc_object = oh_allocate_local_handle(); exc_object->object = man_obj; args[0].l = exc_object; if (exn_raised()) { //if RuntimeException or Error if (suspended_enabled) { tmn_suspend_enable(); } return NULL; } vm_execute_java_method_array((jmethodID) exc_init, 0, args); if (suspended_enabled) { tmn_suspend_enable(); } return exc_object; }