Search in sources :

Example 1 with TIB

use of org.jikesrvm.objectmodel.TIB in project JikesRVM by JikesRVM.

the class InterfaceInvocation method installITable.

private static void installITable(RVMClass C, RVMClass I) {
    TIB tib = C.getTypeInformationBlock();
    ITableArray iTables = tib.getITableArray();
    if (iTables == null) {
        iTables = MemoryManager.newITableArray(2);
        tib.setITableArray(iTables);
    } else {
        for (int i = 0; i < iTables.length(); i++) {
            if (iTables.get(i).isFor(I)) {
                // some other thread just built the iTable
                return;
            }
        }
        ITableArray tmp = MemoryManager.newITableArray(iTables.length() + 1);
        for (int i = 0; i < iTables.length(); i++) {
            tmp.set(i, iTables.get(i));
        }
        iTables = tmp;
        tib.setITableArray(iTables);
    }
    if (VM.VerifyAssertions)
        VM._assert(iTables.get(iTables.length() - 1) == null);
    ITable iTable = buildITable(C, I);
    iTables.set(iTables.length() - 1, iTable);
    // iTables[0] is a move to front cache; fill it here so we can
    // assume it always contains some iTable.
    iTables.set(0, iTable);
}
Also used : ITableArray(org.jikesrvm.objectmodel.ITableArray) ITable(org.jikesrvm.objectmodel.ITable) TIB(org.jikesrvm.objectmodel.TIB) Entrypoint(org.vmmagic.pragma.Entrypoint)

Example 2 with TIB

use of org.jikesrvm.objectmodel.TIB in project JikesRVM by JikesRVM.

the class InterfaceInvocation method unresolvedInvokeinterfaceImplementsTest.

/**
 * <code>mid</code> is the dictionary id of an interface method we are trying to invoke
 * <code>RHStib</code> is the TIB of an object on which we are attempting to invoke it.
 *
 * We were unable to resolve the member reference at compile time.
 * Therefore we must resolve it now and then call invokeinterfaceImplementsTest
 * with the right LHSclass.
 *
 * @param mid     Dictionary id of the {@link MemberReference} for the target interface method.
 * @param rhsObject  The object on which we are attempting to invoke the interface method
 */
@Entrypoint
public static void unresolvedInvokeinterfaceImplementsTest(int mid, Object rhsObject) throws IncompatibleClassChangeError {
    RVMMethod sought = MemberReference.getMemberRef(mid).asMethodReference().resolveInterfaceMethod();
    RVMClass LHSclass = sought.getDeclaringClass();
    if (!LHSclass.isResolved()) {
        LHSclass.resolve();
    }
    /* If the object is not null, ensure that it implements the interface.
     * If it is null, then we return to our caller and let them raise the
     * null pointer exception when they attempt to get the object's TIB so
     * they can actually make the interface call.
     */
    if (rhsObject != null) {
        TIB RHStib = ObjectModel.getTIB(rhsObject);
        if (LHSclass.isInterface() && DynamicTypeCheck.instanceOfInterface(LHSclass, RHStib))
            return;
        // Raise an IncompatibleClassChangeError.
        throw new IncompatibleClassChangeError();
    }
}
Also used : TIB(org.jikesrvm.objectmodel.TIB) Entrypoint(org.vmmagic.pragma.Entrypoint)

Example 3 with TIB

use of org.jikesrvm.objectmodel.TIB in project JikesRVM by JikesRVM.

the class InterfaceInvocation method updateTIBEntry.

/**
 * If there is an an IMT or ITable entry that contains
 * compiled code for the argument method, then update it to
 * contain the current compiled code for the method.
 *
 * @param klass the RVMClass who's IMT/ITable is being reset
 * @param m the method that needs to be updated.
 */
public static void updateTIBEntry(RVMClass klass, RVMMethod m) {
    TIB tib = klass.getTypeInformationBlock();
    if (VM.BuildForIMTInterfaceInvocation) {
        RVMMethod[] map = klass.noIMTConflictMap;
        if (map != null) {
            for (int i = 0; i < IMT_METHOD_SLOTS; i++) {
                if (map[i] == m) {
                    IMT imt = tib.getImt();
                    imt.set(i, m.getCurrentEntryCodeArray());
                    // all done -- a method is in at most 1 IMT slot
                    return;
                }
            }
        }
    } else if (VM.BuildForITableInterfaceInvocation) {
        if (tib.getITableArray() != null) {
            ITableArray iTables = tib.getITableArray();
            Atom name = m.getName();
            Atom desc = m.getDescriptor();
            for (int i = 0; i < iTables.length(); i++) {
                ITable iTable = iTables.get(i);
                if (iTable != null) {
                    RVMClass I = iTable.getInterfaceClass();
                    RVMMethod[] interfaceMethods = I.getDeclaredMethods();
                    for (RVMMethod im : interfaceMethods) {
                        if (im.getName() == name && im.getDescriptor() == desc) {
                            iTable.set(getITableIndex(I, name, desc), m.getCurrentEntryCodeArray());
                        }
                    }
                }
            }
        }
    }
}
Also used : IMT(org.jikesrvm.objectmodel.IMT) ITableArray(org.jikesrvm.objectmodel.ITableArray) ITable(org.jikesrvm.objectmodel.ITable) TIB(org.jikesrvm.objectmodel.TIB) Entrypoint(org.vmmagic.pragma.Entrypoint)

Example 4 with TIB

use of org.jikesrvm.objectmodel.TIB in project JikesRVM by JikesRVM.

the class InterfaceInvocation method populateIMT.

private static void populateIMT(RVMClass klass, IMTDict d) {
    TIB tib = klass.getTypeInformationBlock();
    IMT IMT = MemoryManager.newIMT();
    klass.setIMT(IMT);
    d.populateIMT(klass, tib, IMT);
    tib.setImt(IMT);
}
Also used : IMT(org.jikesrvm.objectmodel.IMT) TIB(org.jikesrvm.objectmodel.TIB)

Example 5 with TIB

use of org.jikesrvm.objectmodel.TIB 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)

Aggregations

TIB (org.jikesrvm.objectmodel.TIB)36 Entrypoint (org.vmmagic.pragma.Entrypoint)16 RVMArray (org.jikesrvm.classloader.RVMArray)14 RVMType (org.jikesrvm.classloader.RVMType)13 NoInline (org.vmmagic.pragma.NoInline)9 Interruptible (org.vmmagic.pragma.Interruptible)8 Address (org.vmmagic.unboxed.Address)7 Test (org.junit.Test)5 CodeArray (org.jikesrvm.compilers.common.CodeArray)4 ITable (org.jikesrvm.objectmodel.ITable)4 RVMClass (org.jikesrvm.classloader.RVMClass)3 RVMMethod (org.jikesrvm.classloader.RVMMethod)3 Offset (org.vmmagic.unboxed.Offset)3 CompiledMethod (org.jikesrvm.compilers.common.CompiledMethod)2 IMT (org.jikesrvm.objectmodel.IMT)2 ITableArray (org.jikesrvm.objectmodel.ITableArray)2 Inline (org.vmmagic.pragma.Inline)2 BufferedOutputStream (java.io.BufferedOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 PrintStream (java.io.PrintStream)1