示例#1
0
文件: compile.cpp 项目: dacut/juliet
static JIT_Result compile_do_compilation(Method* method)
{
    ASSERT_RAISE_AREA;
    assert(hythread_is_suspend_enabled());
    tmn_suspend_disable();
    class_initialize(method->get_class());
    tmn_suspend_enable();
   
    method->lock();
    if (exn_raised()) {
        method->unlock();
        return JIT_FAILURE;
    } else if (method->get_state() == Method::ST_Compiled) {
        method->unlock();
        return JIT_SUCCESS;
    } else if (method->get_state()==Method::ST_NotCompiled && exn_raised()) {
        method->unlock();
        return JIT_FAILURE;
    } else if(!check_available_stack_size(0x8000)) {
        method->unlock();
        return JIT_FAILURE;
    }

    if (method->is_native()) {
        JIT_Result res = compile_prepare_native_method(method);            
        if (res == JIT_SUCCESS) {
            compile_flush_generated_code();
            method->set_state(Method::ST_Compiled);
            method->do_jit_recompiled_method_callbacks();
            method->apply_vtable_patches();
        } else {
            method->set_state(Method::ST_NotCompiled);
            compile_raise_exception("java/lang/UnsatisfiedLinkError", "Cannot load native ", method);
        }
        method->unlock();
        return res;
    } else {
        // Call an execution manager to compile the method.
        // An execution manager is safe to call from multiple threads.
        method->unlock();
        return VM_Global_State::loader_env->em_interface->CompileMethod(method);
    }
}
Class *get_exc_class(const char *exception_name)
{
    ASSERT_RAISE_AREA;
    assert(hythread_is_suspend_enabled());
    Global_Env *env = VM_Global_State::loader_env;
    String *exc_str = env->string_pool.lookup(exception_name);
    Class *exc_class =
        env->bootstrap_class_loader->LoadVerifyAndPrepareClass(env, exc_str);

    if (exc_class == NULL) {
        return NULL;
    }

    tmn_suspend_disable();
    class_initialize(exc_class);
    tmn_suspend_enable();

    if (exn_raised()) {
        return NULL;
    }

    return exc_class;
}