Ejemplo n.º 1
0
Method* interp_resolve_virtual_method(Class* clazz, int methodId) {
    assert(!hythread_is_suspend_enabled());
    Compilation_Handle handle;
    handle.env = VM_Global_State::loader_env;
    handle.jit = 0;

    hythread_suspend_enable();
    assert(hythread_is_suspend_enabled());
    Method *method = resolve_virtual_method(
            (Compile_Handle*)&handle, clazz, methodId);
    hythread_suspend_disable();
    if (!method) {
        if (!exn_raised())
            class_throw_linking_error_for_interpreter(clazz, methodId, OPCODE_INVOKEVIRTUAL);
    }
    return method;
}
Ejemplo n.º 2
0
void Compiler::handle_ik_meth(const JInst& jinst) {
    if (jinst.opcode == OPCODE_INVOKESTATIC || 
        jinst.opcode == OPCODE_INVOKESPECIAL ||
        jinst.opcode == OPCODE_INVOKEVIRTUAL || 
        jinst.opcode == OPCODE_INVOKEINTERFACE) {
        
       
        JavaByteCodes opkod = jinst.opcode;
        ::std::vector<jtype> args;
        jtype retType;
        bool is_static = opkod == OPCODE_INVOKESTATIC;
        get_args_info(is_static, jinst.op0, args, &retType);
        
        Method_Handle meth = NULL;
        unsigned short cpIndex = (unsigned short)jinst.op0;
        bool lazy = m_lazy_resolution;
        bool resolve = !lazy || class_cp_is_entry_resolved(m_klass, cpIndex);
        if (!resolve) {
            assert(lazy);
            gen_invoke(opkod, NULL, cpIndex, args, retType);
            return;
        }
        if (opkod == OPCODE_INVOKESTATIC) {
            meth = resolve_static_method(m_compileHandle, m_klass,
                                            jinst.op0);
            if (meth != NULL) {
                Class_Handle klass = method_get_class(meth);
                if (!class_is_initialized(klass)) {
                    gen_call_vm(ci_helper_o, rt_helper_init_class, 0, klass);
                }
            }
        }
        else if (opkod == OPCODE_INVOKEVIRTUAL) {
            meth = resolve_virtual_method(m_compileHandle, m_klass,
                                            jinst.op0);
        }
        else if (opkod == OPCODE_INVOKEINTERFACE) {
            // BUG and HACK - all in one:
            // An 'org/eclipse/ui/keys/KeyStroke::hashCode' (e3.0) does
            // invokeinterface on java/util/SortedSet::hashCode(), but the
            // entry get resolved into the 'java/lang/Object::hashCode' !
            // later: for eclipse 3.1.1 the same problem happens with 
            // org/eclipse/jdt/internal/core/JavaProject::equals
            // which tries to resolve 
            //  'org/eclipse/core/resources/IProject::equals (Ljava/lang/Object;)Z'
            meth = resolve_interface_method(m_compileHandle, m_klass, jinst.op0);
            //
            //*** workaround here:
            if (meth != NULL && 
                !class_is_interface(method_get_class(meth))) {
                opkod = OPCODE_INVOKEVIRTUAL;
            }
        }
        else {
            assert(opkod == OPCODE_INVOKESPECIAL);
            meth = resolve_special_method(m_compileHandle, m_klass, jinst.op0);
        }
        // if class to call to is available, but method is not found in the class
        // meth here will be equal to NULL and lazy resolution call will be
        // generated in gen_invoke
        gen_invoke(opkod, meth, cpIndex, args, retType);
        return;
    }
    switch(jinst.opcode) {
    case OPCODE_IRETURN: {
        SYNC_FIRST(static const CallSig cs(CCONV_MANAGED, i32));
        gen_return(cs);
        break;
    }
    case OPCODE_LRETURN: {
        SYNC_FIRST(static const CallSig cs(CCONV_MANAGED, i64));
        gen_return(cs);
        break;
    }
    case OPCODE_FRETURN: {
        SYNC_FIRST(static const CallSig cs(CCONV_MANAGED, flt32));
        gen_return(cs);
        break;
    }
    case OPCODE_DRETURN: {
        SYNC_FIRST(static const CallSig cs(CCONV_MANAGED, dbl64));
        gen_return(cs);
        break;
    }
    case OPCODE_ARETURN: {
        SYNC_FIRST(static const CallSig cs(CCONV_MANAGED, jobj));
        gen_return(cs);
        break;
    }
    case OPCODE_RETURN: {
        SYNC_FIRST(static const CallSig cs(CCONV_MANAGED, jvoid));
        gen_return(cs);   
        break;
    }
    default: assert(false);   break;
    };
}