Example #1
0
	bool class_lookup_method(ClassConstPtr cls, Symbol name, MethodQueryResult* out_method) {
		Method m;
		if (class_lookup_method(cls, name, &m)) {
			out_method->type = m.type;
			out_method->result = m.type == MethodTypeFunction ? m.function : m.property->getter;
			return true;
		}
		
		if (class_lookup_method(cls, sym("method_missing"), &m)) {
			out_method->type = MethodTypeMissing;
			out_method->result = m.function;
			return true;
		}
		
		TRAP(); // method_missing not defined in Object.
		return false;
	}
Example #2
0
	bool class_lookup_property_setter(ClassConstPtr cls, Symbol name, MethodQueryResult* out_method) {
		Method m;
		if (class_lookup_method(cls, name, &m)) {
			if (m.type == MethodTypeProperty) {
				out_method->type = m.type;
				out_method->result = m.property->setter;
				return true;
			}
		}
		return false;
	}
Example #3
0
/**
 * 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;
}