Search in sources :

Example 66 with RVMType

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

the class JNIFunctions method GetStaticFieldID.

/**
 * GetStaticFieldID:  return a field id which can be cached in native code and reused
 * @param env A JREF index for the JNI environment object
 * @param classJREF a JREF index for the RVMClass object
 * @param fieldNameAddress a raw address to a null-terminated string in C for the field name
 * @param descriptorAddress a raw address to a null-terminated string in C for the descriptor
 * @return the offset of a static field given the class, field name
 *         and type. Return 0 if the field is not found
 * @throws NoSuchFieldError if the specified field cannot be found
 * @throws ExceptionInInitializerError if the class initializer fails
 * @throws OutOfMemoryError if the system runs out of memory
 */
private static int GetStaticFieldID(JNIEnvironment env, int classJREF, Address fieldNameAddress, Address descriptorAddress) {
    if (traceJNI)
        VM.sysWriteln("JNI called: GetStaticFieldID");
    RuntimeEntrypoints.checkJNICountDownToGC();
    try {
        Class<?> cls = (Class<?>) env.getJNIRef(classJREF);
        String fieldString = JNIGenericHelpers.createStringFromC(fieldNameAddress);
        Atom fieldName = Atom.findOrCreateAsciiAtom(fieldString);
        String descriptorString = JNIGenericHelpers.createStringFromC(descriptorAddress);
        Atom descriptor = Atom.findOrCreateAsciiAtom(descriptorString);
        RVMType rvmType = java.lang.JikesRVMSupport.getTypeForClass(cls);
        if (rvmType.isClassType()) {
            // First search for the fields in the class and its superclasses
            for (RVMClass curClass = rvmType.asClass(); curClass != null; curClass = curClass.getSuperClass()) {
                for (RVMField field : curClass.getStaticFields()) {
                    if (field.getName() == fieldName && field.getDescriptor() == descriptor) {
                        return field.getId();
                    }
                }
            }
            // Now search all implemented interfaces (includes inherited interfaces)
            for (RVMClass curClass : rvmType.asClass().getAllImplementedInterfaces()) {
                for (RVMField field : curClass.getStaticFields()) {
                    if (field.getName() == fieldName && field.getDescriptor() == descriptor) {
                        return field.getId();
                    }
                }
            }
        }
        env.recordException(new NoSuchFieldError(fieldString + ", " + descriptorString + " of " + cls));
        return 0;
    } catch (Throwable unexpected) {
        if (traceJNI)
            unexpected.printStackTrace(System.err);
        env.recordException(unexpected);
        return 0;
    }
}
Also used : RVMType(org.jikesrvm.classloader.RVMType) RVMField(org.jikesrvm.classloader.RVMField) RVMClass(org.jikesrvm.classloader.RVMClass) Atom(org.jikesrvm.classloader.Atom) RVMClass(org.jikesrvm.classloader.RVMClass)

Example 67 with RVMType

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

the class DebugUtil method boot.

@Interruptible
static void boot(BootRecord theBootRecord) {
    // get addresses of TIBs for RVMArray & RVMClass used for testing Type ptrs
    RVMType t = RVMArray.IntArray;
    tibForArrayType = ObjectModel.getTIB(t);
    tibForPrimitiveType = ObjectModel.getTIB(RVMType.IntType);
    t = Magic.getObjectType(BootRecord.the_boot_record);
    tibForClassType = ObjectModel.getTIB(t);
}
Also used : RVMType(org.jikesrvm.classloader.RVMType) Interruptible(org.vmmagic.pragma.Interruptible)

Example 68 with RVMType

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

the class JavaHeader method initializeScalarHeader.

/**
 * Perform any required initialization of the JAVA portion of the header.
 * @param bootImage The bootimage being written
 * @param ptr  The object ref to the storage to be initialized
 * @param tib  The TIB of the instance being created
 * @param size The number of bytes allocated by the GC system for this object.
 * @param needsIdentityHash needs an identity hash value
 * @param identityHashValue the value for the identity hash
 * @return the address used for a reference to this object
 */
@Interruptible
public static Address initializeScalarHeader(BootImageInterface bootImage, Address ptr, TIB tib, int size, boolean needsIdentityHash, int identityHashValue) {
    Address ref = ptr.plus(OBJECT_REF_OFFSET);
    if (needsIdentityHash) {
        bootImage.setFullWord(ref.plus(STATUS_OFFSET), HASH_STATE_HASHED_AND_MOVED.toInt());
        if (DYNAMIC_HASH_OFFSET) {
            // Read the size of this object.
            RVMType t = tib.getType();
            bootImage.setFullWord(ptr.plus(t.asClass().getInstanceSize()), identityHashValue);
        } else {
            ref = ref.plus(HASHCODE_BYTES);
            bootImage.setFullWord(ref.plus(HASHCODE_OFFSET), (identityHashValue << 1) | ALIGNMENT_MASK);
        }
    } else {
        // As boot image objects can't move there is no benefit in lazily setting them to hashed
        bootImage.setFullWord(ref.plus(STATUS_OFFSET), HASH_STATE_HASHED.toInt());
    }
    return ref;
}
Also used : Address(org.vmmagic.unboxed.Address) RVMType(org.jikesrvm.classloader.RVMType) Interruptible(org.vmmagic.pragma.Interruptible)

Example 69 with RVMType

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

the class JavaHeader method initializeArrayHeader.

/**
 * Perform any required initialization of the JAVA portion of the header.
 *
 * @param bootImage the bootimage being written
 * @param ptr  the object ref to the storage to be initialized
 * @param tib the TIB of the instance being created
 * @param size the number of bytes allocated by the GC system for this object.
 * @param numElements the number of elements in the array
 * @param needsIdentityHash needs an identity hash value
 * @param identityHashValue the value for the identity hash
 * @return the address used for a reference to this object
 */
@Interruptible
public static Address initializeArrayHeader(BootImageInterface bootImage, Address ptr, TIB tib, int size, int numElements, boolean needsIdentityHash, int identityHashValue) {
    Address ref = ptr.plus(OBJECT_REF_OFFSET);
    // (TIB set by BootImageWriter; array length set by ObjectModel)
    if (needsIdentityHash) {
        bootImage.setFullWord(ref.plus(STATUS_OFFSET), HASH_STATE_HASHED_AND_MOVED.toInt());
        if (DYNAMIC_HASH_OFFSET) {
            // Read the size of this object.
            RVMType t = tib.getType();
            bootImage.setFullWord(ptr.plus(t.asArray().getInstanceSize(numElements)), identityHashValue);
        } else {
            ref = ref.plus(HASHCODE_BYTES);
            bootImage.setFullWord(ref.plus(HASHCODE_OFFSET), (identityHashValue << 1) | ALIGNMENT_MASK);
        }
    } else {
        // As boot image objects can't move there is no benefit in lazily setting them to hashed
        bootImage.setFullWord(ref.plus(STATUS_OFFSET), HASH_STATE_HASHED.toInt());
    }
    return ref;
}
Also used : Address(org.vmmagic.unboxed.Address) RVMType(org.jikesrvm.classloader.RVMType) Interruptible(org.vmmagic.pragma.Interruptible)

Example 70 with RVMType

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

the class ObjectModel method getObjectEndAddress.

/**
 * Get the pointer just past an object.
 *
 * @param obj the object in question
 * @return first word after the object
 */
public static Address getObjectEndAddress(Object obj) {
    TIB tib = getTIB(obj);
    RVMType type = tib.getType();
    if (type.isClassType()) {
        return getObjectEndAddress(obj, type.asClass());
    } else {
        int numElements = Magic.getArrayLength(obj);
        return getObjectEndAddress(obj, type.asArray(), numElements);
    }
}
Also used : RVMType(org.jikesrvm.classloader.RVMType) Entrypoint(org.vmmagic.pragma.Entrypoint)

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