Search in sources :

Example 21 with RVMClass

use of org.jikesrvm.classloader.RVMClass in project JikesRVM by JikesRVM.

the class VMCommonLibrarySupport method invokeVirtual.

@Inline(value = Inline.When.ArgumentsAreConstant, arguments = { 2 })
private static Object invokeVirtual(Object receiver, Object[] args, RVMMethod method, Method jlrMethod, RVMClass accessingClass, ReflectionBase invoker) throws IllegalAccessException, IllegalArgumentException, ExceptionInInitializerError, InvocationTargetException {
    // validate "this" argument
    if (receiver == null) {
        throwNewNullPointerException();
    }
    RVMClass declaringClass = method.getDeclaringClass();
    if (!isArgumentCompatible(declaringClass, receiver)) {
        throwNewIllegalArgumentException();
    }
    // Accessibility checks
    if (!method.isPublic() && !jlrMethod.isAccessible()) {
        checkAccess(method, accessingClass);
    }
    // find the right method to call
    RVMClass C = Magic.getObjectType(receiver).asClass();
    method = C.findVirtualMethod(method.getName(), method.getDescriptor());
    // Invoke method
    try {
        return Reflection.invoke(method, invoker, receiver, args, false);
    } catch (Throwable t) {
        throw new InvocationTargetException(t);
    }
}
Also used : RVMClass(org.jikesrvm.classloader.RVMClass) Inline(org.vmmagic.pragma.Inline) NoInline(org.vmmagic.pragma.NoInline)

Example 22 with RVMClass

use of org.jikesrvm.classloader.RVMClass in project JikesRVM by JikesRVM.

the class VMCommonLibrarySupport method checkAccess.

/* ---- General Reflection Support ---- */
/**
 * Check to see if a method declared by the accessingClass
 * should be allowed to access the argument RVMMember.
 * Assumption: member is not public.  This trivial case should
 * be approved by the caller without needing to call this method.
 */
private static void checkAccess(RVMMember member, RVMClass accessingClass) throws IllegalAccessException {
    RVMClass declaringClass = member.getDeclaringClass();
    if (member.isPrivate()) {
        // access from the declaringClass is allowed
        if (accessingClass == declaringClass)
            return;
    } else if (member.isProtected()) {
        // access within the package is allowed.
        if (declaringClass.getClassLoader() == accessingClass.getClassLoader() && declaringClass.getPackageName().equals(accessingClass.getPackageName()))
            return;
        // access by subclasses is allowed.
        for (RVMClass cls = accessingClass; cls != null; cls = cls.getSuperClass()) {
            if (accessingClass == declaringClass)
                return;
        }
    } else {
        // default: access within package is allowed
        if (declaringClass.getClassLoader() == accessingClass.getClassLoader() && declaringClass.getPackageName().equals(accessingClass.getPackageName()))
            return;
    }
    throwNewIllegalAccessException(member, accessingClass);
}
Also used : RVMClass(org.jikesrvm.classloader.RVMClass)

Example 23 with RVMClass

use of org.jikesrvm.classloader.RVMClass in project JikesRVM by JikesRVM.

the class OptTestHarness method processOptionString.

private void processOptionString(String[] args) {
    for (int i = 0, n = args.length; i < n; i++) {
        try {
            String arg = args[i];
            if (arg.startsWith("-oc:") && options.processAsOption("-X:irc:", arg.substring(4))) {
            // handled in processAsOption
            } else if ("-useBootOptions".equals(arg)) {
                OptimizingCompiler.setBootOptions(options);
            } else if ("-longcommandline".equals(arg)) {
                // the -longcommandline option reads options from a file.
                String fileName = args[++i];
                String[] optionString = fileAccess.readOptionStringFromFile(fileName);
                processOptionString(optionString);
            } else if ("+baseline".equals(arg)) {
                useBaselineCompiler = true;
            } else if ("-baseline".equals(arg)) {
                useBaselineCompiler = false;
            } else if ("-load".equals(arg)) {
                loadClass(args[++i]);
            } else if ("-class".equals(arg)) {
                RVMClass klass = loadClass(args[++i]);
                processClass(klass, options);
                duplicateOptions();
            } else if ("-method".equals(arg) || "-methodOpt".equals(arg) || "-methodBase".equals(arg)) {
                // Default for this method is determined by BASELINE var
                boolean isBaseline = useBaselineCompiler;
                // Unless specified by these options
                if ("-methodOpt".equals(arg)) {
                    isBaseline = false;
                }
                if ("-methodBase".equals(arg)) {
                    isBaseline = true;
                }
                RVMClass klass = null;
                try {
                    klass = loadClass(args[++i]);
                } catch (Exception e) {
                    output.sysErrPrintln("WARNING: Skipping method from " + args[i]);
                }
                if (klass == null)
                    continue;
                String name = args[++i];
                String desc = args[++i];
                RVMMethod method = findDeclaredOrFirstMethod(klass, name, desc);
                if (method == null || method.isAbstract() || method.isNative()) {
                    output.sysErrPrintln("WARNING: Skipping method " + args[i - 2] + "." + name);
                } else {
                    processMethod(method, options, isBaseline);
                }
                duplicateOptions();
            } else if ("-performance".equals(arg)) {
                perf = new Performance(output);
            } else if ("-disableClassLoading".equals(arg)) {
                disableClassloading = true;
            } else if ("-er".equals(arg)) {
                executeWithReflection = true;
                RVMClass klass = loadClass(args[++i]);
                String name = args[++i];
                String desc = args[++i];
                NormalMethod method = (NormalMethod) findDeclaredOrFirstMethod(klass, name, desc);
                CompiledMethod cm = null;
                if (method == null) {
                    output.sysErrPrintln("Canceling further option processing to prevent assertion failures.");
                    return;
                }
                if (useBaselineCompiler) {
                    cm = BaselineCompiler.compile(method);
                } else {
                    CompilationPlan cp = new CompilationPlan(method, OptimizationPlanner.createOptimizationPlan(options), null, options);
                    try {
                        cm = OptimizingCompiler.compile(cp);
                    } catch (Throwable e) {
                        output.sysErrPrintln("SKIPPING method:" + method + "Due to exception: " + e);
                    }
                }
                if (cm != null) {
                    method.replaceCompiledMethod(cm);
                    if (printCodeAddress) {
                        output.sysOutPrintln(compiledMethodMessage(method));
                    }
                }
                TypeReference[] argDesc = method.getDescriptor().parseForParameterTypes(klass.getClassLoader());
                Object[] reflectMethodArgs = new Object[argDesc.length];
                i = parseMethodArgs(argDesc, args, i, reflectMethodArgs);
                java.lang.reflect.Method reflectoid = java.lang.reflect.JikesRVMSupport.createMethod(method);
                reflectoidVector.add(reflectoid);
                reflectMethodVector.add(method);
                reflectMethodArgsVector.add(reflectMethodArgs);
                duplicateOptions();
            } else if ("-main".equals(arg)) {
                executeMainMethod = true;
                i++;
                mainClass = loadClass(args[i]);
                i++;
                mainArgs = new String[args.length - i];
                for (int j = 0, z = mainArgs.length; j < z; j++) {
                    mainArgs[j] = args[i + j];
                }
                break;
            } else {
                output.sysErrPrintln("Unrecognized argument: " + arg + " - ignored");
            }
        } catch (ArrayIndexOutOfBoundsException e) {
            output.sysErrPrintln("Uncaught ArrayIndexOutOfBoundsException, possibly" + " not enough command-line arguments - aborting");
            printFormatString();
            e.printStackTrace(output.getSystemErr());
            break;
        } catch (Exception e) {
            output.sysErrPrintln(e.toString());
            e.printStackTrace(output.getSystemErr());
            break;
        }
    }
}
Also used : CompilationPlan(org.jikesrvm.compilers.opt.driver.CompilationPlan) InvocationTargetException(java.lang.reflect.InvocationTargetException) OptimizingCompilerException(org.jikesrvm.compilers.opt.OptimizingCompilerException) CompiledMethod(org.jikesrvm.compilers.common.CompiledMethod) RVMClass(org.jikesrvm.classloader.RVMClass) RVMMethod(org.jikesrvm.classloader.RVMMethod) NormalMethod(org.jikesrvm.classloader.NormalMethod) TypeReference(org.jikesrvm.classloader.TypeReference) Method(java.lang.reflect.Method)

Example 24 with RVMClass

use of org.jikesrvm.classloader.RVMClass in project JikesRVM by JikesRVM.

the class TestingTools method getNoArgumentConstructor.

public static NormalMethod getNoArgumentConstructor(Class<?> declaringClass) throws Exception {
    RVMType type = java.lang.JikesRVMSupport.getTypeForClass(declaringClass);
    RVMClass clazz = type.asClass();
    RVMMethod[] constructors = clazz.getConstructorMethods();
    for (RVMMethod method : constructors) {
        if (method.getParameterTypes().length == 0) {
            return (NormalMethod) method;
        }
    }
    throw new NoSuchMethodException("Did not find a no-argument constructor!");
}
Also used : RVMMethod(org.jikesrvm.classloader.RVMMethod) RVMType(org.jikesrvm.classloader.RVMType) NormalMethod(org.jikesrvm.classloader.NormalMethod) RVMClass(org.jikesrvm.classloader.RVMClass)

Example 25 with RVMClass

use of org.jikesrvm.classloader.RVMClass in project JikesRVM by JikesRVM.

the class DynamicTypeCheckExpansion method mustImplementInterface.

/**
 * Expand a checkcastInterface instruction into the LIR sequence that
 * implements the dynamic type check, raising an IncompataibleClassChangeError
 * if the type check fails.
 * Ref is known to never contain a null ptr at runtime.
 *
 * @param s a MUST_IMPLEMENT_INTERFACE instruction to expand
 * @param ir the enclosing IR
 * @return the last Instruction in the generated LIR sequence.
 */
static Instruction mustImplementInterface(Instruction s, IR ir) {
    Operand ref = TypeCheck.getClearRef(s);
    RVMClass LHSClass = (RVMClass) TypeCheck.getType(s).getVMType();
    if (VM.VerifyAssertions)
        VM._assert(LHSClass != null, "Should be resolvable...");
    int interfaceIndex = LHSClass.getDoesImplementIndex();
    int interfaceMask = LHSClass.getDoesImplementBitMask();
    Operand guard = TypeCheck.getClearGuard(s);
    BasicBlock myBlock = s.getBasicBlock();
    BasicBlock failBlock = myBlock.createSubBlock(s.getBytecodeIndex(), ir, .0001f);
    BasicBlock succBlock = myBlock.splitNodeAt(s, ir);
    succBlock.firstInstruction().insertAfter(Move.create(REF_MOVE, TypeCheck.getClearResult(s), ref.copy()));
    myBlock.insertOut(failBlock);
    myBlock.insertOut(succBlock);
    ir.cfg.linkInCodeOrder(myBlock, succBlock);
    ir.cfg.addLastInCodeOrder(failBlock);
    Instruction raiseError = Trap.create(TRAP, null, TrapCodeOperand.MustImplement());
    raiseError.copyPosition(s);
    failBlock.appendInstruction(raiseError);
    Operand RHStib = getTIB(s, ir, ref, guard);
    RegisterOperand doesImpl = InsertUnary(s, ir, GET_DOES_IMPLEMENT_FROM_TIB, TypeReference.IntArray, RHStib);
    if (DynamicTypeCheck.MIN_DOES_IMPLEMENT_SIZE <= interfaceIndex) {
        RegisterOperand doesImplLength = InsertGuardedUnary(s, ir, ARRAYLENGTH, TypeReference.Int, doesImpl.copyD2U(), TG());
        Instruction lengthCheck = IfCmp.create(INT_IFCMP, ir.regpool.makeTempValidation(), doesImplLength, IC(interfaceIndex), ConditionOperand.LESS_EQUAL(), failBlock.makeJumpTarget(), BranchProfileOperand.never());
        s.insertBefore(lengthCheck);
        myBlock.splitNodeWithLinksAt(lengthCheck, ir);
        // required due to splitNode!
        myBlock.insertOut(failBlock);
    }
    RegisterOperand entry = InsertLoadOffset(s, ir, INT_LOAD, TypeReference.Int, doesImpl, Offset.fromIntZeroExtend(interfaceIndex << 2), new LocationOperand(TypeReference.Int), TG());
    RegisterOperand bit = insertBinary(s, ir, INT_AND, TypeReference.Int, entry, IC(interfaceMask));
    IfCmp.mutate(s, INT_IFCMP, ir.regpool.makeTempValidation(), bit, IC(0), ConditionOperand.EQUAL(), failBlock.makeJumpTarget(), BranchProfileOperand.never());
    return s;
}
Also used : LocationOperand(org.jikesrvm.compilers.opt.ir.operand.LocationOperand) RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) MethodOperand(org.jikesrvm.compilers.opt.ir.operand.MethodOperand) RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) TrueGuardOperand(org.jikesrvm.compilers.opt.ir.operand.TrueGuardOperand) ConditionOperand(org.jikesrvm.compilers.opt.ir.operand.ConditionOperand) Operand(org.jikesrvm.compilers.opt.ir.operand.Operand) NullConstantOperand(org.jikesrvm.compilers.opt.ir.operand.NullConstantOperand) BranchProfileOperand(org.jikesrvm.compilers.opt.ir.operand.BranchProfileOperand) TrapCodeOperand(org.jikesrvm.compilers.opt.ir.operand.TrapCodeOperand) LocationOperand(org.jikesrvm.compilers.opt.ir.operand.LocationOperand) IntConstantOperand(org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand) BasicBlock(org.jikesrvm.compilers.opt.ir.BasicBlock) Instruction(org.jikesrvm.compilers.opt.ir.Instruction) RVMClass(org.jikesrvm.classloader.RVMClass)

Aggregations

RVMClass (org.jikesrvm.classloader.RVMClass)69 RVMMethod (org.jikesrvm.classloader.RVMMethod)28 TypeReference (org.jikesrvm.classloader.TypeReference)22 RVMType (org.jikesrvm.classloader.RVMType)20 Atom (org.jikesrvm.classloader.Atom)14 RVMField (org.jikesrvm.classloader.RVMField)11 RVMArray (org.jikesrvm.classloader.RVMArray)8 Instruction (org.jikesrvm.compilers.opt.ir.Instruction)8 IntConstantOperand (org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand)8 MethodOperand (org.jikesrvm.compilers.opt.ir.operand.MethodOperand)8 Operand (org.jikesrvm.compilers.opt.ir.operand.Operand)8 RegisterOperand (org.jikesrvm.compilers.opt.ir.operand.RegisterOperand)8 BranchProfileOperand (org.jikesrvm.compilers.opt.ir.operand.BranchProfileOperand)7 ConditionOperand (org.jikesrvm.compilers.opt.ir.operand.ConditionOperand)7 LocationOperand (org.jikesrvm.compilers.opt.ir.operand.LocationOperand)7 Address (org.vmmagic.unboxed.Address)7 NormalMethod (org.jikesrvm.classloader.NormalMethod)6 CompiledMethod (org.jikesrvm.compilers.common.CompiledMethod)6 TrapCodeOperand (org.jikesrvm.compilers.opt.ir.operand.TrapCodeOperand)6 BasicBlock (org.jikesrvm.compilers.opt.ir.BasicBlock)5