Ejemplo n.º 1
0
/**
 * Checkes constraint for given class and loads classes if it's needed.
 */
vf_Result vf_force_check_constraint(Class_Handle klass,
    vf_TypeConstraint* constraint)    // class constraint
{
    // get target class
    Class_Handle target = vf_resolve_class( klass, constraint->target, true );
    if( !target ) {
        return VF_ErrorLoadClass;
    }

    //no need to load the source
    if(class_is_interface(target)){
        return VF_OK;
    }


    // get stack reference class
    Class_Handle source = vf_resolve_class( klass, constraint->source, true );
    if( !source ) {
        return VF_ErrorLoadClass;
    }

    // check restriction
    if( !vf_is_extending( source, target ) ) {
        return VF_ErrorIncompatibleArgument;
    }
    return VF_OK;
} // vf_force_check_constraint
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;
    };
}