Search in sources :

Example 1 with RVMField

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

the class Class method getFields.

public Field[] getFields() throws SecurityException {
    checkMemberAccess(Member.PUBLIC);
    RVMField[] static_fields = type.getStaticFields();
    RVMField[] instance_fields = type.getInstanceFields();
    ArrayList<Field> coll = new ArrayList<Field>(static_fields.length + instance_fields.length);
    for (RVMField field : static_fields) {
        if (field.isPublic()) {
            coll.add(JikesRVMSupport.createField(field));
        }
    }
    for (RVMField field : instance_fields) {
        if (field.isPublic()) {
            coll.add(JikesRVMSupport.createField(field));
        }
    }
    return coll.toArray(new Field[coll.size()]);
}
Also used : RVMField(org.jikesrvm.classloader.RVMField) Field(java.lang.reflect.Field) RVMField(org.jikesrvm.classloader.RVMField) ArrayList(java.util.ArrayList)

Example 2 with RVMField

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

the class Class method getDeclaredField.

public Field getDeclaredField(String name) throws NoSuchFieldException, SecurityException {
    throwNPEWhenNameIsNull(name);
    checkMemberAccess(Member.DECLARED);
    if (!type.isClassType() || name == null)
        throwNoSuchFieldException(name);
    Atom aName = Atom.findOrCreateUnicodeAtom(name);
    RVMField answer = type.asClass().findDeclaredField(aName);
    if (answer == null) {
        throwNoSuchFieldException(name);
    }
    return JikesRVMSupport.createField(answer);
}
Also used : RVMField(org.jikesrvm.classloader.RVMField) Atom(org.jikesrvm.classloader.Atom)

Example 3 with RVMField

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

the class Class method getField.

public Field getField(String name) throws NoSuchFieldException, SecurityException {
    throwNPEWhenNameIsNull(name);
    checkMemberAccess(Member.PUBLIC);
    if (!type.isClassType())
        throw new NoSuchFieldException();
    Atom aName = Atom.findUnicodeAtom(name);
    if (aName == null)
        throwNoSuchFieldException(name);
    RVMField answer = getFieldInternal(aName);
    if (answer == null) {
        throwNoSuchFieldException(name);
    }
    return JikesRVMSupport.createField(answer);
}
Also used : RVMField(org.jikesrvm.classloader.RVMField) Atom(org.jikesrvm.classloader.Atom)

Example 4 with RVMField

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

the class BootImageWriter method writeAddressMap.

/**
 * Write method address map for use with dbx debugger.
 *
 * @param fileName name of file to write the map to
 */
private static void writeAddressMap(String mapFileName) throws IOException {
    if (verbosity.isAtLeast(SUMMARY))
        say("writing ", mapFileName);
    // Restore previously unnecessary Statics data structures
    Statics.bootImageReportGeneration(staticsJunk);
    FileOutputStream fos = new FileOutputStream(mapFileName);
    BufferedOutputStream bos = new BufferedOutputStream(fos, 128);
    PrintStream out = new PrintStream(bos, false);
    out.println("#! /bin/bash");
    out.println("# This is a method address map, for use with the ``dbx'' debugger.");
    out.println("# To sort by \"code\" address, type \"bash <name-of-this-file>\".");
    out.println("# Bootimage data: " + Integer.toHexString(BOOT_IMAGE_DATA_START.toInt()) + "..." + Integer.toHexString(BOOT_IMAGE_DATA_START.toInt() + bootImage.getDataSize()));
    out.println("# Bootimage code: " + Integer.toHexString(BOOT_IMAGE_CODE_START.toInt()) + "..." + Integer.toHexString(BOOT_IMAGE_CODE_START.toInt() + bootImage.getCodeSize()));
    out.println("# Bootimage refs: " + Integer.toHexString(BOOT_IMAGE_RMAP_START.toInt()) + "..." + Integer.toHexString(BOOT_IMAGE_RMAP_START.toInt() + bootImage.getRMapSize()));
    out.println();
    out.println("(/bin/grep 'code     0x' | /bin/sort -k 4.3,4) << EOF-EOF-EOF");
    out.println();
    out.println("JTOC Map");
    out.println("--------");
    out.println("slot  offset     category contents            details");
    out.println("----  ------     -------- --------            -------");
    String pad = "        ";
    // Numeric JTOC fields
    for (int jtocSlot = Statics.getLowestInUseSlot(); jtocSlot < Statics.middleOfTable; jtocSlot++) {
        Offset jtocOff = Statics.slotAsOffset(jtocSlot);
        String category;
        String contents;
        String details;
        RVMField field = getRvmStaticField(jtocOff);
        RVMField field2 = getRvmStaticField(jtocOff.plus(4));
        boolean couldBeLongLiteral = Statics.isLongSizeLiteral(jtocSlot);
        boolean couldBeIntLiteral = Statics.isIntSizeLiteral(jtocSlot);
        if (couldBeLongLiteral && ((field == null) || (field2 == null))) {
            if ((field == null) && (field2 == null)) {
                category = "literal      ";
                long lval = Statics.getSlotContentsAsLong(jtocOff);
                contents = Services.intAsHexString((int) (lval >> 32)) + Services.intAsHexString((int) (lval & 0xffffffffL)).substring(2);
                details = lval + "L";
            } else if ((field == null) && (field2 != null)) {
                category = "literal/field";
                long lval = Statics.getSlotContentsAsLong(jtocOff);
                contents = Services.intAsHexString((int) (lval >> 32)) + Services.intAsHexString((int) (lval & 0xffffffffL)).substring(2);
                details = lval + "L / " + field2.toString();
            } else if ((field != null) && (field2 == null)) {
                category = "literal/field";
                long lval = Statics.getSlotContentsAsLong(jtocOff);
                contents = Services.intAsHexString((int) (lval >> 32)) + Services.intAsHexString((int) (lval & 0xffffffffL)).substring(2);
                details = lval + "L / " + field.toString();
            } else {
                throw new Error("Unreachable");
            }
            jtocSlot++;
        } else if (couldBeIntLiteral) {
            if (field != null) {
                category = "literal/field";
                int ival = Statics.getSlotContentsAsInt(jtocOff);
                contents = Services.intAsHexString(ival) + pad;
                details = Integer.toString(ival) + " / " + field.toString();
            } else {
                category = "literal      ";
                int ival = Statics.getSlotContentsAsInt(jtocOff);
                contents = Services.intAsHexString(ival) + pad;
                details = Integer.toString(ival);
            }
        } else {
            if (field != null) {
                category = "field        ";
                details = field.toString();
                TypeReference type = field.getType();
                if (type.isIntLikeType()) {
                    int ival = Statics.getSlotContentsAsInt(jtocOff);
                    contents = Services.intAsHexString(ival) + pad;
                } else if (type.isLongType()) {
                    long lval = Statics.getSlotContentsAsLong(jtocOff);
                    contents = Services.intAsHexString((int) (lval >> 32)) + Services.intAsHexString((int) (lval & 0xffffffffL)).substring(2);
                    jtocSlot++;
                } else if (type.isFloatType()) {
                    int ival = Statics.getSlotContentsAsInt(jtocOff);
                    contents = Float.toString(Float.intBitsToFloat(ival)) + pad;
                } else if (type.isDoubleType()) {
                    long lval = Statics.getSlotContentsAsLong(jtocOff);
                    contents = Double.toString(Double.longBitsToDouble(lval)) + pad;
                    jtocSlot++;
                } else if (type.isWordLikeType()) {
                    if (VM.BuildFor32Addr) {
                        int ival = Statics.getSlotContentsAsInt(jtocOff);
                        contents = Services.intAsHexString(ival) + pad;
                    } else {
                        long lval = Statics.getSlotContentsAsLong(jtocOff);
                        contents = Services.intAsHexString((int) (lval >> 32)) + Services.intAsHexString((int) (lval & 0xffffffffL)).substring(2);
                        jtocSlot++;
                    }
                } else {
                    // Unknown?
                    int ival = Statics.getSlotContentsAsInt(jtocOff);
                    category = "<? - field>  ";
                    details = "<? - " + field.toString() + ">";
                    contents = Services.intAsHexString(ival) + pad;
                }
            } else {
                // Unknown?
                int ival = Statics.getSlotContentsAsInt(jtocOff);
                category = "<?>        ";
                details = "<?>";
                contents = Services.intAsHexString(ival) + pad;
            }
        }
        out.println((jtocSlot + "        ").substring(0, 8) + Services.addressAsHexString(jtocOff.toWord().toAddress()) + " " + category + "  " + contents + "  " + details);
    }
    // Reference JTOC fields
    for (int jtocSlot = Statics.middleOfTable, n = Statics.getHighestInUseSlot(); jtocSlot <= n; jtocSlot += Statics.getReferenceSlotSize()) {
        Offset jtocOff = Statics.slotAsOffset(jtocSlot);
        Object obj = BootImageMap.getObject(getIVal(jtocOff));
        String category;
        String details;
        String contents = Services.addressAsHexString(getReferenceAddr(jtocOff, false)) + pad;
        RVMField field = getRvmStaticField(jtocOff);
        if (Statics.isReferenceLiteral(jtocSlot)) {
            if (field != null) {
                category = "literal/field";
            } else {
                category = "literal      ";
            }
            if (obj == null) {
                details = "(null)";
            } else if (obj instanceof String) {
                details = "\"" + obj + "\"";
            } else if (obj instanceof Class) {
                details = obj.toString();
                ;
            } else if (obj instanceof TIB) {
                category = "literal tib  ";
                RVMType type = ((TIB) obj).getType();
                details = (type == null) ? "?" : type.toString();
            } else {
                details = "object " + obj.getClass();
            }
            if (field != null) {
                details += " / " + field.toString();
            }
        } else if (field != null) {
            category = "field        ";
            details = field.toString();
        } else if (obj instanceof TIB) {
            // TIBs confuse the statics as their backing is written into the boot image
            category = "tib          ";
            RVMType type = ((TIB) obj).getType();
            details = (type == null) ? "?" : type.toString();
        } else {
            category = "unknown      ";
            if (obj instanceof String) {
                details = "\"" + obj + "\"";
            } else if (obj instanceof Class) {
                details = obj.toString();
            } else {
                CompiledMethod m = findMethodOfCode(obj);
                if (m != null) {
                    category = "code         ";
                    details = m.getMethod().toString();
                } else if (obj != null) {
                    details = "<?> - unrecognized field or literal of type " + obj.getClass();
                } else {
                    details = "<?>";
                }
            }
        }
        out.println((jtocSlot + "        ").substring(0, 8) + Services.addressAsHexString(jtocOff.toWord().toAddress()) + " " + category + "  " + contents + "  " + details);
    }
    out.println();
    out.println("Method Map");
    out.println("----------");
    out.println("                          address             method");
    out.println("                          -------             ------");
    out.println();
    for (int i = 0; i < CompiledMethods.numCompiledMethods(); ++i) {
        CompiledMethod compiledMethod = CompiledMethods.getCompiledMethodUnchecked(i);
        if (compiledMethod != null) {
            RVMMethod m = compiledMethod.getMethod();
            if (m != null && compiledMethod.isCompiled()) {
                CodeArray instructions = compiledMethod.getEntryCodeArray();
                Address code = BootImageMap.getImageAddress(instructions.getBacking(), true);
                out.println(".     .          code     " + Services.addressAsHexString(code) + "          " + compiledMethod.getMethod());
            }
        }
    }
    // Extra information on the layout of objects in the boot image
    if (false) {
        out.println();
        out.println("Object Map");
        out.println("----------");
        out.println("                          address             type");
        out.println("                          -------             ------");
        out.println();
        SortedSet<BootImageMap.Entry> set = new TreeSet<BootImageMap.Entry>(new Comparator<BootImageMap.Entry>() {

            @Override
            public int compare(BootImageMap.Entry a, BootImageMap.Entry b) {
                return Integer.valueOf(a.imageAddress.toInt()).compareTo(b.imageAddress.toInt());
            }
        });
        for (Enumeration<BootImageMap.Entry> e = BootImageMap.elements(); e.hasMoreElements(); ) {
            BootImageMap.Entry entry = e.nextElement();
            set.add(entry);
        }
        for (Iterator<BootImageMap.Entry> i = set.iterator(); i.hasNext(); ) {
            BootImageMap.Entry entry = i.next();
            Address data = entry.imageAddress;
            out.println(".     .          data     " + Services.addressAsHexString(data) + "          " + entry.jdkObject.getClass());
        }
    }
    out.println();
    out.println("EOF-EOF-EOF");
    out.flush();
    out.close();
}
Also used : Address(org.vmmagic.unboxed.Address) RVMType(org.jikesrvm.classloader.RVMType) CompiledMethod(org.jikesrvm.compilers.common.CompiledMethod) CodeArray(org.jikesrvm.compilers.common.CodeArray) TreeSet(java.util.TreeSet) RVMField(org.jikesrvm.classloader.RVMField) TypeReference(org.jikesrvm.classloader.TypeReference) BufferedOutputStream(java.io.BufferedOutputStream) PrintStream(java.io.PrintStream) TIB(org.jikesrvm.objectmodel.TIB) Offset(org.vmmagic.unboxed.Offset) RVMMethod(org.jikesrvm.classloader.RVMMethod) FileOutputStream(java.io.FileOutputStream) RVMClass(org.jikesrvm.classloader.RVMClass)

Example 5 with RVMField

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

the class JNIFunctions method SetStaticDoubleField.

/**
 * SetStaticDoubleField:  set a static field of type float
 * @param env A JREF index for the JNI environment object
 * @param classJREF a JREF index for the RVMClass object
 * @param fieldID the id for the RVMField that describes this field
 * @param fieldValue  The value to assign
 */
private static void SetStaticDoubleField(JNIEnvironment env, int classJREF, int fieldID, double fieldValue) {
    if (traceJNI)
        VM.sysWriteln("JNI called: SetStaticDoubleField");
    RuntimeEntrypoints.checkJNICountDownToGC();
    try {
        RVMField field = MemberReference.getFieldRef(fieldID).resolve();
        field.setDoubleValueUnchecked(null, fieldValue);
    } catch (Throwable unexpected) {
        if (traceJNI)
            unexpected.printStackTrace(System.err);
        env.recordException(unexpected);
    }
}
Also used : RVMField(org.jikesrvm.classloader.RVMField)

Aggregations

RVMField (org.jikesrvm.classloader.RVMField)80 TypeReference (org.jikesrvm.classloader.TypeReference)21 Offset (org.vmmagic.unboxed.Offset)14 RVMClass (org.jikesrvm.classloader.RVMClass)12 Operand (org.jikesrvm.compilers.opt.ir.operand.Operand)9 Field (java.lang.reflect.Field)8 Instruction (org.jikesrvm.compilers.opt.ir.Instruction)8 RegisterOperand (org.jikesrvm.compilers.opt.ir.operand.RegisterOperand)8 Atom (org.jikesrvm.classloader.Atom)7 IntConstantOperand (org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand)6 LocationOperand (org.jikesrvm.compilers.opt.ir.operand.LocationOperand)6 RVMType (org.jikesrvm.classloader.RVMType)5 AddressConstantOperand (org.jikesrvm.compilers.opt.ir.operand.AddressConstantOperand)5 MethodOperand (org.jikesrvm.compilers.opt.ir.operand.MethodOperand)5 Address (org.vmmagic.unboxed.Address)5 FieldReference (org.jikesrvm.classloader.FieldReference)4 RVMMethod (org.jikesrvm.classloader.RVMMethod)4 BranchProfileOperand (org.jikesrvm.compilers.opt.ir.operand.BranchProfileOperand)4 ConditionOperand (org.jikesrvm.compilers.opt.ir.operand.ConditionOperand)4 TIBConstantOperand (org.jikesrvm.compilers.opt.ir.operand.TIBConstantOperand)4