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);
}
}
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);
}
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;
}
}
}
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!");
}
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;
}
Aggregations