use of org.jikesrvm.classloader.RVMType in project JikesRVM by JikesRVM.
the class BC2IR method do_CheckStore.
/**
* Generate a storecheck for the given array and elem
* @param ref the array reference
* @param elem the element to be written to the array
* @param elemType the type of the array references elements
* @return {@code true} if an unconditional throw is generated, {@code false} otherwise
*/
private boolean do_CheckStore(Operand ref, Operand elem, TypeReference elemType) {
if (gc.noCheckStoreChecks())
return false;
if (CF_CHECKSTORE) {
// ARRAY SUBTYPING IS SUBTLE (see JLS 10.10) --dave
if (elem.isDefinitelyNull()) {
if (DBG_TYPE)
db("skipping checkstore of null constant");
return false;
}
if (elemType.isArrayType()) {
TypeReference elemType2 = elemType;
do {
elemType2 = elemType2.getArrayElementType();
} while (elemType2.isArrayType());
RVMType et2 = elemType2.peekType();
if (et2 != null) {
if (et2.isPrimitiveType() || et2.isUnboxedType() || ((RVMClass) et2).isFinal()) {
TypeReference myElemType = getRefTypeOf(elem);
if (myElemType == elemType) {
if (DBG_TYPE) {
db("eliminating checkstore to an array with a final element type " + elemType);
}
return false;
} else {
// run time check is still necessary
}
}
}
} else {
// elemType is class
RVMType et = elemType.peekType();
if (et != null && ((RVMClass) et).isFinal()) {
if (getRefTypeOf(elem) == elemType) {
if (DBG_TYPE) {
db("eliminating checkstore to an array with a final element type " + elemType);
}
return false;
} else {
// run time check is still necessary
}
}
}
}
RegisterOperand guard = gc.getTemps().makeTempValidation();
if (isNonNull(elem)) {
RegisterOperand newGuard = gc.getTemps().makeTempValidation();
appendInstruction(Binary.create(GUARD_COMBINE, newGuard, copyGuardFromOperand(elem), getCurrentGuard()));
appendInstruction(StoreCheck.create(OBJARRAY_STORE_CHECK_NOTNULL, guard, ref.copy(), elem.copy(), newGuard.copy()));
} else {
appendInstruction(StoreCheck.create(OBJARRAY_STORE_CHECK, guard, ref.copy(), elem.copy(), getCurrentGuard()));
}
setCurrentGuard(guard);
rectifyStateWithArrayStoreExceptionHandler();
return false;
}
use of org.jikesrvm.classloader.RVMType in project JikesRVM by JikesRVM.
the class BC2IR method generateAnewarray.
// pops the length off the stack
//
public Instruction generateAnewarray(TypeReference arrayTypeRef, TypeReference elementTypeRef) {
if (arrayTypeRef == null) {
if (VM.VerifyAssertions)
opt_assert(elementTypeRef != null);
arrayTypeRef = elementTypeRef.getArrayTypeForElementType();
}
if (elementTypeRef == null) {
elementTypeRef = arrayTypeRef.getArrayElementType();
}
RegisterOperand t = gc.getTemps().makeTemp(arrayTypeRef);
t.setPreciseType();
markGuardlessNonNull(t);
// We can do early resolution of the array type if the element type
// is already initialized.
RVMType arrayType = arrayTypeRef.peekType();
Operator op;
TypeOperand arrayOp;
if ((arrayType != null) && (arrayType.isInitialized() || arrayType.isInBootImage())) {
op = NEWARRAY;
arrayOp = makeTypeOperand(arrayType);
t.setExtant();
} else {
RVMType elementType = elementTypeRef.peekType();
if ((elementType != null) && (elementType.isInitialized() || elementType.isInBootImage())) {
arrayType = arrayTypeRef.resolve();
arrayType.prepareForFirstUse();
op = NEWARRAY;
arrayOp = makeTypeOperand(arrayType);
t.setExtant();
} else {
op = NEWARRAY_UNRESOLVED;
arrayOp = makeTypeOperand(arrayTypeRef);
}
}
Instruction s = NewArray.create(op, t, arrayOp, popInt());
push(t.copyD2U());
rectifyStateWithErrorHandler();
rectifyStateWithExceptionHandler(TypeReference.JavaLangNegativeArraySizeException);
return s;
}
use of org.jikesrvm.classloader.RVMType in project JikesRVM by JikesRVM.
the class Class method forNameInternal.
private static Class<?> forNameInternal(String className, boolean initialize, ClassLoader classLoader) throws ClassNotFoundException, LinkageError, ExceptionInInitializerError {
if (className == null) {
throw new ClassNotFoundException("Cannot load a class with a name of null");
}
try {
if (className.startsWith("[")) {
if (!validArrayDescriptor(className)) {
throw new ClassNotFoundException(className);
}
}
Atom descriptor = Atom.findOrCreateAsciiAtom(className.replace('.', '/')).descriptorFromClassName();
TypeReference tRef = TypeReference.findOrCreate(classLoader, descriptor);
RVMType ans = tRef.resolve();
Callbacks.notifyForName(ans);
if (initialize && !ans.isInitialized()) {
ans.prepareForFirstUse();
}
return ans.getClassForType();
} catch (NoClassDefFoundError ncdfe) {
Throwable cause2 = ncdfe.getCause();
ClassNotFoundException cnf;
// If we get a NCDFE that was caused by a CNFE, throw the original CNFE.
if (cause2 instanceof ClassNotFoundException)
cnf = (ClassNotFoundException) cause2;
else
cnf = new ClassNotFoundException(className, ncdfe);
throw cnf;
}
}
use of org.jikesrvm.classloader.RVMType in project JikesRVM by JikesRVM.
the class VMStackWalker method getClassContext.
/**
* Classpath's Javadoc for this method says:
* <blockquote>
* Get a list of all the classes currently executing methods on the
* Java stack. <code>getClassContext()[0]</code> is the class associated
* with the currently executing method, i.e., the method that called
* <code>VMStackWalker.getClassContext()</code> (possibly through
* reflection). So you may need to pop off these stack frames from
* the top of the stack:
* <ul>
* <li><code>VMStackWalker.getClassContext()</code>
* <li><code>Method.invoke()</code>
* </ul>
*
* @return an array of the declaring classes of each stack frame
* </blockquote>
*/
public static Class<?>[] getClassContext() {
StackBrowser b = new StackBrowser();
int frames = 0;
VM.disableGC();
b.init();
// skip VMStackWalker.getClassContext (this call)
b.up();
// Were we invoked by reflection?
boolean reflected;
if (b.getMethod() == Entrypoints.java_lang_reflect_Method_invokeMethod) {
reflected = true;
// Skip Method.invoke, (if we were called by reflection)
b.up();
} else {
reflected = false;
}
/* Count # of frames. */
while (b.hasMoreFrames()) {
frames++;
b.up();
}
VM.enableGC();
RVMType[] iclasses = new RVMType[frames];
int i = 0;
b = new StackBrowser();
VM.disableGC();
b.init();
// skip this method
b.up();
if (reflected)
// Skip Method.invoke if we were called by reflection
b.up();
while (b.hasMoreFrames()) {
iclasses[i++] = b.getCurrentClass();
b.up();
}
VM.enableGC();
Class<?>[] classes = new Class[frames];
for (int j = 0; j < iclasses.length; j++) {
classes[j] = iclasses[j].getClassForType();
}
return classes;
}
use of org.jikesrvm.classloader.RVMType in project JikesRVM by JikesRVM.
the class VMClassLoader method defineClass.
static Class<?> defineClass(ClassLoader cl, String name, byte[] data, int offset, int len, ProtectionDomain pd) throws ClassFormatError {
RVMType vmType = RVMClassLoader.defineClassInternal(name, data, offset, len, cl);
Class<?> ans = vmType.getClassForType();
JikesRVMSupport.setClassProtectionDomain(ans, pd);
ImmutableEntryHashMapRVM<String, Class<?>> mapForCL;
if (cl == null || cl == BootstrapClassLoader.getBootstrapClassLoader()) {
mapForCL = bootStrapLoadedClasses;
} else {
mapForCL = loadedClasses.get(cl);
if (mapForCL == null) {
mapForCL = new ImmutableEntryHashMapRVM<String, Class<?>>();
loadedClasses.put(cl, mapForCL);
}
}
mapForCL.put(ans.getName(), ans);
return ans;
}
Aggregations