Search in sources :

Example 46 with RVMType

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;
}
Also used : RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) RVMType(org.jikesrvm.classloader.RVMType) TypeReference(org.jikesrvm.classloader.TypeReference)

Example 47 with RVMType

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;
}
Also used : Operator(org.jikesrvm.compilers.opt.ir.Operator) RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) RVMType(org.jikesrvm.classloader.RVMType) TypeOperand(org.jikesrvm.compilers.opt.ir.operand.TypeOperand) Instruction(org.jikesrvm.compilers.opt.ir.Instruction)

Example 48 with RVMType

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;
    }
}
Also used : RVMType(org.jikesrvm.classloader.RVMType) TypeReference(org.jikesrvm.classloader.TypeReference) Atom(org.jikesrvm.classloader.Atom)

Example 49 with RVMType

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;
}
Also used : RVMType(org.jikesrvm.classloader.RVMType) StackBrowser(org.jikesrvm.runtime.StackBrowser)

Example 50 with RVMType

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;
}
Also used : RVMType(org.jikesrvm.classloader.RVMType)

Aggregations

RVMType (org.jikesrvm.classloader.RVMType)77 RVMClass (org.jikesrvm.classloader.RVMClass)23 TypeReference (org.jikesrvm.classloader.TypeReference)18 Address (org.vmmagic.unboxed.Address)16 RVMMethod (org.jikesrvm.classloader.RVMMethod)15 RegisterOperand (org.jikesrvm.compilers.opt.ir.operand.RegisterOperand)15 TIB (org.jikesrvm.objectmodel.TIB)13 Entrypoint (org.vmmagic.pragma.Entrypoint)13 IntConstantOperand (org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand)12 Operand (org.jikesrvm.compilers.opt.ir.operand.Operand)12 RVMArray (org.jikesrvm.classloader.RVMArray)11 ConditionOperand (org.jikesrvm.compilers.opt.ir.operand.ConditionOperand)11 MethodOperand (org.jikesrvm.compilers.opt.ir.operand.MethodOperand)11 BranchProfileOperand (org.jikesrvm.compilers.opt.ir.operand.BranchProfileOperand)10 NullConstantOperand (org.jikesrvm.compilers.opt.ir.operand.NullConstantOperand)10 TrapCodeOperand (org.jikesrvm.compilers.opt.ir.operand.TrapCodeOperand)10 TrueGuardOperand (org.jikesrvm.compilers.opt.ir.operand.TrueGuardOperand)10 Instruction (org.jikesrvm.compilers.opt.ir.Instruction)9 TypeOperand (org.jikesrvm.compilers.opt.ir.operand.TypeOperand)9 Offset (org.vmmagic.unboxed.Offset)8