Search in sources :

Example 56 with RVMMethod

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

the class BootImageWriter method copyKnownInstanceField.

/**
 * If we can't find a field via reflection we may still determine
 * and copy a value because we know the internals of Classpath.
 * @param jdkObject the object containing the field
 * @param rvmFieldName the name of the field
 * @param rvmFieldType the type reference of the field
 * @param rvmFieldAddress the address that the field is being written to
 */
private static boolean copyKnownInstanceField(Object jdkObject, String rvmFieldName, TypeReference rvmFieldType, Address rvmFieldAddress) throws IllegalAccessException {
    // Class library independent objects
    if (jdkObject instanceof java.lang.Class) {
        Object value = null;
        String fieldName = null;
        boolean fieldIsFinal = false;
        if (rvmFieldName.equals("type")) {
            // lets go over the common ones
            if (jdkObject == java.lang.Boolean.TYPE) {
                value = RVMType.BooleanType;
            } else if (jdkObject == java.lang.Byte.TYPE) {
                value = RVMType.ByteType;
            } else if (jdkObject == java.lang.Character.TYPE) {
                value = RVMType.CharType;
            } else if (jdkObject == java.lang.Double.TYPE) {
                value = RVMType.DoubleType;
            } else if (jdkObject == java.lang.Float.TYPE) {
                value = RVMType.FloatType;
            } else if (jdkObject == java.lang.Integer.TYPE) {
                value = RVMType.IntType;
            } else if (jdkObject == java.lang.Long.TYPE) {
                value = RVMType.LongType;
            } else if (jdkObject == java.lang.Short.TYPE) {
                value = RVMType.ShortType;
            } else if (jdkObject == java.lang.Void.TYPE) {
                value = RVMType.VoidType;
            } else {
                value = TypeReference.findOrCreate((Class<?>) jdkObject).peekType();
                if (value == null) {
                    fail("Failed to populate Class.type for " + jdkObject);
                }
            }
            fieldName = "type";
            fieldIsFinal = true;
        }
        if ((fieldName != null) && (value != null)) {
            if (verbosity.isAtLeast(DETAILED))
                traceContext.push(value.getClass().getName(), "java.lang.Class", fieldName);
            Address imageAddress = BootImageMap.findOrCreateEntry(value).imageAddress;
            if (imageAddress.EQ(OBJECT_NOT_PRESENT)) {
                // object not part of bootimage: install null reference
                if (verbosity.isAtLeast(DETAILED))
                    traceContext.traceObjectNotInBootImage();
                bootImage.setNullAddressWord(rvmFieldAddress, true, true, false);
            } else if (imageAddress.EQ(OBJECT_NOT_ALLOCATED)) {
                imageAddress = copyToBootImage(value, false, Address.max(), jdkObject, false, AlignmentEncoding.ALIGN_CODE_NONE);
                if (verbosity.isAtLeast(ADDRESSES))
                    traceContext.traceObjectFoundThroughKnown();
                bootImage.setAddressWord(rvmFieldAddress, imageAddress.toWord(), true, !fieldIsFinal);
            } else {
                if (verbosity.isAtLeast(ADDRESSES))
                    traceContext.traceObjectFoundThroughKnown();
                bootImage.setAddressWord(rvmFieldAddress, imageAddress.toWord(), true, !fieldIsFinal);
            }
            if (verbosity.isAtLeast(DETAILED))
                traceContext.pop();
            return true;
        } else {
            // Unknown Class field or value for type
            return false;
        }
    } else if ((jdkObject instanceof java.lang.String) && (rvmFieldName.equals("count")) && (rvmFieldType.isIntType())) {
        // The fields "count" and "offset" are not guaranteed to be present in
        // the String implementation in the class library (case in point: IcedTea 7).
        // We don't need to do anything for "offset" (the default value of 0 is correct)
        // but we need to ensure that "count" has the correct value.
        bootImage.setFullWord(rvmFieldAddress, ((java.lang.String) jdkObject).length());
        return true;
    }
    // Class library dependent fields
    if (classLibrary == "harmony") {
        if ((jdkObject instanceof java.lang.String) && (rvmFieldName.equals("hashCode")) && (rvmFieldType.isIntType())) {
            // Populate String's hashCode value
            bootImage.setFullWord(rvmFieldAddress, jdkObject.hashCode());
            return true;
        } else if (jdkObject instanceof java.util.Locale) {
            String fieldName;
            Object value;
            if (rvmFieldName.equals("countryCode")) {
                value = ((java.util.Locale) jdkObject).getCountry();
                fieldName = "countryCode";
            } else if (rvmFieldName.equals("languageCode")) {
                value = ((java.util.Locale) jdkObject).getLanguage();
                fieldName = "languageCode";
            } else if (rvmFieldName.equals("variantCode")) {
                value = ((java.util.Locale) jdkObject).getVariant();
                fieldName = "languageCode";
            } else {
                return false;
            }
            if (verbosity.isAtLeast(DETAILED))
                traceContext.push(value.getClass().getName(), "java.util.Locale", fieldName);
            Address imageAddress = BootImageMap.findOrCreateEntry(value).imageAddress;
            if (imageAddress.EQ(OBJECT_NOT_PRESENT)) {
                // object not part of bootimage: install null reference
                if (verbosity.isAtLeast(DETAILED))
                    traceContext.traceObjectNotInBootImage();
                throw new Error("Failed to populate " + fieldName + " in Locale");
            } else if (imageAddress.EQ(OBJECT_NOT_ALLOCATED)) {
                imageAddress = copyToBootImage(value, false, Address.max(), jdkObject, false, AlignmentEncoding.ALIGN_CODE_NONE);
                if (verbosity.isAtLeast(ADDRESSES))
                    traceContext.traceObjectFoundThroughKnown();
                bootImage.setAddressWord(rvmFieldAddress, imageAddress.toWord(), true, false);
            } else {
                if (verbosity.isAtLeast(ADDRESSES))
                    traceContext.traceObjectFoundThroughKnown();
                bootImage.setAddressWord(rvmFieldAddress, imageAddress.toWord(), true, false);
            }
            if (verbosity.isAtLeast(DETAILED))
                traceContext.pop();
            return true;
        } else if ((jdkObject instanceof java.util.WeakHashMap) && (rvmFieldName.equals("referenceQueue"))) {
            Object value = new java.lang.ref.ReferenceQueue();
            if (verbosity.isAtLeast(DETAILED))
                traceContext.push(value.getClass().getName(), "java.util.WeakHashMap", "referenceQueue");
            Address imageAddress = BootImageMap.findOrCreateEntry(value).imageAddress;
            if (imageAddress.EQ(OBJECT_NOT_PRESENT)) {
                // object not part of bootimage: install null reference
                if (verbosity.isAtLeast(DETAILED))
                    traceContext.traceObjectNotInBootImage();
                throw new Error("Failed to populate referenceQueue in WeakHashMap");
            } else if (imageAddress.EQ(OBJECT_NOT_ALLOCATED)) {
                imageAddress = copyToBootImage(value, false, Address.max(), jdkObject, false, AlignmentEncoding.ALIGN_CODE_NONE);
                if (verbosity.isAtLeast(ADDRESSES))
                    traceContext.traceObjectFoundThroughKnown();
                bootImage.setAddressWord(rvmFieldAddress, imageAddress.toWord(), true, false);
            } else {
                if (verbosity.isAtLeast(ADDRESSES))
                    traceContext.traceObjectFoundThroughKnown();
                bootImage.setAddressWord(rvmFieldAddress, imageAddress.toWord(), true, false);
            }
            if (verbosity.isAtLeast(DETAILED))
                traceContext.pop();
            return true;
        } else if (jdkObject instanceof java.lang.ref.ReferenceQueue) {
            if (rvmFieldName.equals("firstReference")) {
                return false;
            } else {
                throw new Error("Unknown field " + rvmFieldName + " in java.lang.ref.ReferenceQueue");
            }
        } else if (jdkObject instanceof java.lang.reflect.Constructor) {
            Constructor<?> cons = (Constructor<?>) jdkObject;
            if (rvmFieldName.equals("vmConstructor")) {
                // fill in this RVMMethod field
                String typeName = "L" + cons.getDeclaringClass().getName().replace('.', '/') + ";";
                RVMType type = TypeReference.findOrCreate(typeName).peekType();
                if (type == null) {
                    throw new Error("Failed to find type for Constructor.constructor: " + cons + " " + typeName);
                }
                final RVMClass klass = type.asClass();
                Class<?>[] consParams = cons.getParameterTypes();
                RVMMethod constructor = null;
                loop_over_all_constructors: for (RVMMethod vmCons : klass.getConstructorMethods()) {
                    TypeReference[] vmConsParams = vmCons.getParameterTypes();
                    if (vmConsParams.length == consParams.length) {
                        for (int j = 0; j < vmConsParams.length; j++) {
                            if (!consParams[j].equals(vmConsParams[j].resolve().getClassForType())) {
                                continue loop_over_all_constructors;
                            }
                        }
                        constructor = vmCons;
                        break;
                    }
                }
                if (constructor == null) {
                    throw new Error("Failed to populate Constructor.cons for " + cons);
                }
                if (verbosity.isAtLeast(DETAILED))
                    traceContext.push("vmConstructor", "java.lang.Constructor", "cons");
                Address imageAddress = BootImageMap.findOrCreateEntry(constructor).imageAddress;
                if (imageAddress.EQ(OBJECT_NOT_PRESENT)) {
                    // object not part of bootimage: install null reference
                    if (verbosity.isAtLeast(DETAILED))
                        traceContext.traceObjectNotInBootImage();
                    bootImage.setNullAddressWord(rvmFieldAddress, true, false, false);
                } else if (imageAddress.EQ(OBJECT_NOT_ALLOCATED)) {
                    imageAddress = copyToBootImage(constructor, false, Address.max(), jdkObject, false, AlignmentEncoding.ALIGN_CODE_NONE);
                    if (verbosity.isAtLeast(ADDRESSES))
                        traceContext.traceObjectFoundThroughKnown();
                    bootImage.setAddressWord(rvmFieldAddress, imageAddress.toWord(), true, false);
                } else {
                    if (verbosity.isAtLeast(ADDRESSES))
                        traceContext.traceObjectFoundThroughKnown();
                    bootImage.setAddressWord(rvmFieldAddress, imageAddress.toWord(), true, false);
                }
                if (verbosity.isAtLeast(DETAILED))
                    traceContext.pop();
                return true;
            } else if (rvmFieldName.equals("isAccessible")) {
                // This field is inherited accesible flag is actually part of
                // AccessibleObject
                bootImage.setByte(rvmFieldAddress, cons.isAccessible() ? 1 : 0);
                return true;
            } else if (rvmFieldName.equals("invoker")) {
                // Bytecode reflection field, can only be installed in running VM
                bootImage.setNullAddressWord(rvmFieldAddress, true, false, false);
                return true;
            } else {
                // Unknown Constructor field
                throw new Error("Unknown field " + rvmFieldName + " in java.lang.reflect.Constructor");
            }
        } else {
            // unknown field
            return false;
        }
    } else if (classLibrary == "classpath") {
        if ((jdkObject instanceof java.lang.String) && (rvmFieldName.equals("cachedHashCode")) && (rvmFieldType.isIntType())) {
            // Populate String's cachedHashCode value
            bootImage.setFullWord(rvmFieldAddress, jdkObject.hashCode());
            return true;
        } else if (jdkObject instanceof java.lang.reflect.Constructor) {
            Constructor<?> cons = (Constructor<?>) jdkObject;
            if (rvmFieldName.equals("cons")) {
                // fill in this RVMMethod field
                String typeName = "L" + cons.getDeclaringClass().getName().replace('.', '/') + ";";
                RVMType type = TypeReference.findOrCreate(typeName).peekType();
                if (type == null) {
                    throw new Error("Failed to find type for Constructor.constructor: " + cons + " " + typeName);
                }
                final RVMClass klass = type.asClass();
                Class<?>[] consParams = cons.getParameterTypes();
                RVMMethod constructor = null;
                loop_over_all_constructors: for (RVMMethod vmCons : klass.getConstructorMethods()) {
                    TypeReference[] vmConsParams = vmCons.getParameterTypes();
                    if (vmConsParams.length == consParams.length) {
                        for (int j = 0; j < vmConsParams.length; j++) {
                            if (!consParams[j].equals(vmConsParams[j].resolve().getClassForType())) {
                                continue loop_over_all_constructors;
                            }
                        }
                        constructor = vmCons;
                        break;
                    }
                }
                if (constructor == null) {
                    throw new Error("Failed to populate Constructor.cons for " + cons);
                }
                if (verbosity.isAtLeast(DETAILED))
                    traceContext.push("VMConstructor", "java.lang.Constructor", "cons");
                Object vmcons = java.lang.reflect.JikesRVMSupport.createVMConstructor(constructor);
                Address imageAddress = BootImageMap.findOrCreateEntry(vmcons).imageAddress;
                if (imageAddress.EQ(OBJECT_NOT_PRESENT)) {
                    // object not part of bootimage: install null reference
                    if (verbosity.isAtLeast(DETAILED))
                        traceContext.traceObjectNotInBootImage();
                    bootImage.setNullAddressWord(rvmFieldAddress, true, false, false);
                } else if (imageAddress.EQ(OBJECT_NOT_ALLOCATED)) {
                    imageAddress = copyToBootImage(vmcons, false, Address.max(), jdkObject, false, AlignmentEncoding.ALIGN_CODE_NONE);
                    if (verbosity.isAtLeast(ADDRESSES))
                        traceContext.traceObjectFoundThroughKnown();
                    bootImage.setAddressWord(rvmFieldAddress, imageAddress.toWord(), true, false);
                } else {
                    if (verbosity.isAtLeast(ADDRESSES))
                        traceContext.traceObjectFoundThroughKnown();
                    bootImage.setAddressWord(rvmFieldAddress, imageAddress.toWord(), true, false);
                }
                if (verbosity.isAtLeast(DETAILED))
                    traceContext.pop();
                return true;
            } else if (rvmFieldName.equals("flag")) {
                // This field is inherited accesible flag is actually part of
                // AccessibleObject
                bootImage.setByte(rvmFieldAddress, cons.isAccessible() ? 1 : 0);
                return true;
            } else {
                // Unknown Constructor field
                return false;
            }
        } else if (jdkObject instanceof java.lang.ref.ReferenceQueue) {
            if (rvmFieldName.equals("lock")) {
                VM.sysWriteln("writing the lock field.");
                Object value = new org.jikesrvm.scheduler.LightMonitor();
                if (verbosity.isAtLeast(DETAILED))
                    traceContext.push(value.getClass().getName(), "java.lang.ref.ReferenceQueue", "lock");
                Address imageAddress = BootImageMap.findOrCreateEntry(value).imageAddress;
                if (imageAddress.EQ(OBJECT_NOT_PRESENT)) {
                    if (verbosity.isAtLeast(DETAILED))
                        traceContext.traceObjectNotInBootImage();
                    throw new Error("Failed to populate lock in ReferenceQueue");
                } else if (imageAddress.EQ(OBJECT_NOT_ALLOCATED)) {
                    imageAddress = copyToBootImage(value, false, Address.max(), jdkObject, false, AlignmentEncoding.ALIGN_CODE_NONE);
                    if (verbosity.isAtLeast(ADDRESSES))
                        traceContext.traceObjectFoundThroughKnown();
                    bootImage.setAddressWord(rvmFieldAddress, imageAddress.toWord(), true, false);
                } else {
                    if (verbosity.isAtLeast(ADDRESSES))
                        traceContext.traceObjectFoundThroughKnown();
                    bootImage.setAddressWord(rvmFieldAddress, imageAddress.toWord(), true, false);
                }
                if (verbosity.isAtLeast(DETAILED))
                    traceContext.pop();
                return true;
            } else if (rvmFieldName.equals("first")) {
                return false;
            } else {
                throw new Error("Unknown field " + rvmFieldName + " in java.lang.ref.ReferenceQueue");
            }
        } else if (jdkObject instanceof java.util.BitSet) {
            BitSet bs = (BitSet) jdkObject;
            if (rvmFieldName.equals("bits")) {
                // highest bit set in set
                int max = 0;
                for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i + 1)) {
                    max = i;
                }
                long[] bits = new long[(max + 63) / 64];
                for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i + 1)) {
                    bits[i / 64] |= 1L << (i & 63);
                }
                if (verbosity.isAtLeast(DETAILED))
                    traceContext.push("[J", "java.util.BitSet", "bits");
                Address imageAddress = BootImageMap.findOrCreateEntry(bits).imageAddress;
                if (imageAddress.EQ(OBJECT_NOT_PRESENT)) {
                    // object not part of bootimage: install null reference
                    if (verbosity.isAtLeast(DETAILED))
                        traceContext.traceObjectNotInBootImage();
                    bootImage.setNullAddressWord(rvmFieldAddress, true, false);
                } else if (imageAddress.EQ(OBJECT_NOT_ALLOCATED)) {
                    imageAddress = copyToBootImage(bits, false, Address.max(), jdkObject, false, AlignmentEncoding.ALIGN_CODE_NONE);
                    if (verbosity.isAtLeast(ADDRESSES))
                        traceContext.traceObjectFoundThroughKnown();
                    bootImage.setAddressWord(rvmFieldAddress, imageAddress.toWord(), false, false);
                } else {
                    if (verbosity.isAtLeast(ADDRESSES))
                        traceContext.traceObjectFoundThroughKnown();
                    bootImage.setAddressWord(rvmFieldAddress, imageAddress.toWord(), false, false);
                }
                if (verbosity.isAtLeast(DETAILED))
                    traceContext.pop();
                return true;
            } else {
                // Unknown BitSet field
                return false;
            }
        } else {
            // Unknown field
            return false;
        }
    } else {
        throw new Error("Unknown class library: \"" + classLibrary + "\"");
    }
}
Also used : Address(org.vmmagic.unboxed.Address) RVMType(org.jikesrvm.classloader.RVMType) Constructor(java.lang.reflect.Constructor) BitSet(java.util.BitSet) RVMClass(org.jikesrvm.classloader.RVMClass) RVMMethod(org.jikesrvm.classloader.RVMMethod) RVMClass(org.jikesrvm.classloader.RVMClass)

Example 57 with RVMMethod

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

the class BaselineCompilerImpl method emit_invokeinterface.

@Override
protected void emit_invokeinterface(MethodReference methodRef) {
    // +1 for "this" parameter
    int count = methodRef.getParameterWords() + 1;
    RVMMethod resolvedMethod = null;
    resolvedMethod = methodRef.peekInterfaceMethod();
    // do so inline.
    if (VM.BuildForIMTInterfaceInvocation) {
        if (methodRef.isMiranda()) {
        // TODO: It's not entirely clear that we can just assume that
        // the class actually implements the interface.
        // However, we don't know what interface we need to be checking
        // so there doesn't appear to be much else we can do here.
        } else {
            if (resolvedMethod == null) {
                // Can't successfully resolve it at compile time.
                // Call uncommon case typechecking routine to do the right thing when this code actually executes.
                asm.emitLAddrToc(T0, Entrypoints.unresolvedInvokeinterfaceImplementsTestMethod.getOffset());
                asm.emitMTCTR(T0);
                // id of method reference we are trying to call
                asm.emitLVAL(T0, methodRef.getId());
                // the "this" object
                peekAddr(T1, count - 1);
                // throw exception, if link error
                asm.emitBCCTRL();
            } else {
                RVMClass interfaceClass = resolvedMethod.getDeclaringClass();
                int interfaceIndex = interfaceClass.getDoesImplementIndex();
                int interfaceMask = interfaceClass.getDoesImplementBitMask();
                // the "this" object
                peekAddr(T0, count - 1);
                // TIB of "this" object
                asm.baselineEmitLoadTIB(T0, T0);
                // implements bit vector
                asm.emitLAddr(T0, TIB_DOES_IMPLEMENT_INDEX << LOG_BYTES_IN_ADDRESS, T0);
                if (DynamicTypeCheck.MIN_DOES_IMPLEMENT_SIZE <= interfaceIndex) {
                    // must do arraybounds check of implements bit vector
                    // T1 gets array length
                    asm.emitLIntOffset(T1, T0, ObjectModel.getArrayLengthOffset());
                    asm.emitLVAL(T2, interfaceIndex);
                    asm.emitCMPL(T2, T1);
                    // if in bounds, jump around trap.  TODO: would like to encode "y" bit that this branch is expected to be takem.
                    ForwardReference fr1 = asm.emitForwardBC(LT);
                    // encoding of TRAP_ALWAYS MUST_IMPLEMENT_INTERFACE
                    asm.emitTWI(31, GPR.R12, MUST_IMPLEMENT_TRAP);
                    fr1.resolve(asm);
                }
                // Test the appropriate bit and if set, branch around another trap imm
                asm.emitLInt(T1, interfaceIndex << LOG_BYTES_IN_INT, T0);
                if ((interfaceMask & 0xffff) == interfaceMask) {
                    asm.emitANDI(S0, T1, interfaceMask);
                } else {
                    if (VM.VerifyAssertions)
                        VM._assert((interfaceMask & 0xffff0000) == interfaceMask);
                    asm.emitANDIS(S0, T1, interfaceMask);
                }
                // TODO: encode "y" bit that branch is likely taken.
                ForwardReference fr2 = asm.emitForwardBC(NE);
                // encoding of TRAP_ALWAYS MUST_IMPLEMENT_INTERFACE
                asm.emitTWI(31, GPR.R12, MUST_IMPLEMENT_TRAP);
                fr2.resolve(asm);
            }
        }
    }
    // (2) Emit interface invocation sequence.
    if (VM.BuildForIMTInterfaceInvocation) {
        InterfaceMethodSignature sig = InterfaceMethodSignature.findOrCreate(methodRef);
        // T0 is "this"
        genMoveParametersToRegisters(true, methodRef);
        asm.baselineEmitLoadTIB(S0, T0);
        // Load the IMT base into S0
        asm.emitLAddr(S0, TIB_INTERFACE_DISPATCH_TABLE_INDEX << LOG_BYTES_IN_ADDRESS, S0);
        // the method address
        asm.emitLAddrOffset(S0, S0, sig.getIMTOffset());
        asm.emitMTCTR(S0);
        // pass "hidden" parameter in S1 scratch  register
        asm.emitLVAL(S1, sig.getId());
        asm.emitBCCTRL();
    } else {
        int itableIndex = -1;
        if (VM.BuildForITableInterfaceInvocation && resolvedMethod != null) {
            // get the index of the method in the Itable
            itableIndex = InterfaceInvocation.getITableIndex(resolvedMethod.getDeclaringClass(), methodRef.getName(), methodRef.getDescriptor());
        }
        if (itableIndex == -1) {
            // itable index is not known at compile-time.
            // call "invokeInterface" to resolve object + method id into method address
            int methodRefId = methodRef.getId();
            asm.emitLAddrToc(T0, Entrypoints.invokeInterfaceMethod.getOffset());
            asm.emitMTCTR(T0);
            // object
            peekAddr(T0, count - 1);
            // method id
            asm.emitLVAL(T1, methodRefId);
            // T0 := resolved method address
            asm.emitBCCTRL();
            asm.emitMTCTR(T0);
            genMoveParametersToRegisters(true, methodRef);
            asm.emitBCCTRL();
        } else {
            // itable index is known at compile-time.
            // call "findITable" to resolve object + interface id into
            // itable address
            asm.emitLAddrToc(T0, Entrypoints.findItableMethod.getOffset());
            asm.emitMTCTR(T0);
            // object
            peekAddr(T0, count - 1);
            asm.baselineEmitLoadTIB(T0, T0);
            // interface id
            asm.emitLVAL(T1, resolvedMethod.getDeclaringClass().getInterfaceId());
            // T0 := itable reference
            asm.emitBCCTRL();
            // T0 := the method to call
            asm.emitLAddr(T0, itableIndex << LOG_BYTES_IN_ADDRESS, T0);
            asm.emitMTCTR(T0);
            // T0 is "this"
            genMoveParametersToRegisters(true, methodRef);
            asm.emitBCCTRL();
        }
    }
    genPopParametersAndPushReturnValue(true, methodRef);
}
Also used : ForwardReference(org.jikesrvm.compilers.common.assembler.ForwardReference) InterfaceMethodSignature(org.jikesrvm.classloader.InterfaceMethodSignature) RVMMethod(org.jikesrvm.classloader.RVMMethod) RVMClass(org.jikesrvm.classloader.RVMClass)

Example 58 with RVMMethod

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

the class ClassLoaderProxy method lookupMethod.

// --------------------------------------------------------------------------
// Querry classloader data structures
// --------------------------------------------------------------------------
/**
 * Find the method of the given class that matches the given descriptor.
 *
 * @param cls the method's class
 * @param ref name and descriptor of the method
 * @return a matching method or {@code null} if none was found
 */
public static RVMMethod lookupMethod(RVMClass cls, MethodReference ref) {
    RVMMethod newmeth = null;
    if (cls.isResolved() && !cls.isInterface()) {
        Atom mn = ref.getName();
        Atom md = ref.getDescriptor();
        for (; (newmeth == null) && (cls != null); cls = cls.getSuperClass()) {
            newmeth = cls.findDeclaredMethod(mn, md);
        }
    }
    return newmeth;
}
Also used : RVMMethod(org.jikesrvm.classloader.RVMMethod) Atom(org.jikesrvm.classloader.Atom)

Example 59 with RVMMethod

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

the class CompiledMethods method spaceReport.

/**
 * Report on the space used by compiled code and associated mapping information
 */
public static void spaceReport() {
    int[] codeCount = new int[CompiledMethod.NUM_COMPILER_TYPES + 1];
    int[] codeBytes = new int[CompiledMethod.NUM_COMPILER_TYPES + 1];
    int[] mapBytes = new int[CompiledMethod.NUM_COMPILER_TYPES + 1];
    RVMArray codeArray = RVMType.CodeArrayType.asArray();
    for (int i = 0; i < numCompiledMethods(); i++) {
        CompiledMethod cm = getCompiledMethodUnchecked(i);
        if (cm == null || !cm.isCompiled())
            continue;
        int ct = cm.getCompilerType();
        codeCount[ct]++;
        int size = codeArray.getInstanceSize(cm.numberOfInstructions());
        codeBytes[ct] += Memory.alignUp(size, BYTES_IN_ADDRESS);
        mapBytes[ct] += cm.size();
    }
    VM.sysWriteln("Compiled code space report");
    VM.sysWriteln();
    VM.sysWriteln("  Baseline Compiler");
    VM.sysWriteln("    Number of compiled methods =         " + codeCount[CompiledMethod.BASELINE]);
    VM.sysWriteln("    Total size of code (bytes) =         " + codeBytes[CompiledMethod.BASELINE]);
    VM.sysWriteln("    Total size of mapping data (bytes) = " + mapBytes[CompiledMethod.BASELINE]);
    if (codeCount[CompiledMethod.OPT] > 0) {
        VM.sysWriteln("  Optimizing Compiler");
        VM.sysWriteln("    Number of compiled methods =         " + codeCount[CompiledMethod.OPT]);
        VM.sysWriteln("    Total size of code (bytes) =         " + codeBytes[CompiledMethod.OPT]);
        VM.sysWriteln("    Total size of mapping data (bytes) = " + mapBytes[CompiledMethod.OPT]);
    }
    if (codeCount[CompiledMethod.JNI] > 0) {
        VM.sysWriteln("  JNI Stub Compiler (Java->C stubs for native methods)");
        VM.sysWriteln("    Number of compiled methods =         " + codeCount[CompiledMethod.JNI]);
        VM.sysWriteln("    Total size of code (bytes) =         " + codeBytes[CompiledMethod.JNI]);
        VM.sysWriteln("    Total size of mapping data (bytes) = " + mapBytes[CompiledMethod.JNI]);
    }
    if (!VM.runningVM) {
        TreeMap<String, Integer> packageData = new TreeMap<String, Integer>(new Comparator<String>() {

            @Override
            public int compare(String a, String b) {
                return a.compareTo(b);
            }
        });
        for (int i = 0; i < numCompiledMethods(); ++i) {
            CompiledMethod compiledMethod = getCompiledMethodUnchecked(i);
            if (compiledMethod != null) {
                RVMMethod m = compiledMethod.getMethod();
                if (m != null && compiledMethod.isCompiled()) {
                    String packageName = m.getDeclaringClass().getPackageName();
                    int numInstructions = compiledMethod.numberOfInstructions();
                    Integer val = packageData.get(packageName);
                    if (val == null) {
                        val = numInstructions;
                    } else {
                        val = val + numInstructions;
                    }
                    packageData.put(packageName, val);
                }
            }
        }
        VM.sysWriteln("------------------------------------------------------------------------------------------");
        VM.sysWriteln("  Break down of code space usage by package (bytes):");
        VM.sysWriteln("------------------------------------------------------------------------------------------");
        Set<String> keys = packageData.keySet();
        int maxPackageNameSize = 0;
        for (String packageName : keys) {
            maxPackageNameSize = Math.max(maxPackageNameSize, packageName.length());
        }
        maxPackageNameSize++;
        for (String packageName : keys) {
            VM.sysWriteField(maxPackageNameSize, packageName);
            VM.sysWriteField(10, packageData.get(packageName));
            VM.sysWriteln();
        }
    }
}
Also used : RVMMethod(org.jikesrvm.classloader.RVMMethod) RVMArray(org.jikesrvm.classloader.RVMArray) TreeMap(java.util.TreeMap) JNICompiledMethod(org.jikesrvm.jni.JNICompiledMethod) OptCompiledMethod(org.jikesrvm.compilers.opt.runtimesupport.OptCompiledMethod)

Example 60 with RVMMethod

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

the class Class method getMethod.

public Method getMethod(String name, Class<?>... parameterTypes) throws NoSuchMethodException, SecurityException {
    throwNPEWhenNameIsNull(name);
    checkMemberAccess(Member.PUBLIC);
    if (!type.isClassType())
        throwNoSuchMethodException(name, parameterTypes);
    Atom aName = Atom.findOrCreateUnicodeAtom(name);
    if (aName == RVMClassLoader.StandardClassInitializerMethodName || aName == RVMClassLoader.StandardObjectInitializerMethodName) {
        // <init> and <clinit> are not methods.
        throwNoSuchMethodException(name, parameterTypes);
    }
    // (1) Scan the declared public methods of this class and each of its superclasses
    RVMMethod answer = getMethodInternal1(aName, parameterTypes);
    if (answer == null) {
        // (2) Now we need to consider methods inherited from interfaces.
        // Because we inject the requisite Miranda methods, we can do this simply
        // by looking at this class's virtual methods instead of searching interface hierarchies.
        answer = getMethodInternal2(aName, parameterTypes);
    }
    if (answer == null) {
        throwNoSuchMethodException(name, parameterTypes);
    }
    return JikesRVMSupport.createMethod(answer);
}
Also used : RVMMethod(org.jikesrvm.classloader.RVMMethod) Atom(org.jikesrvm.classloader.Atom)

Aggregations

RVMMethod (org.jikesrvm.classloader.RVMMethod)86 RVMClass (org.jikesrvm.classloader.RVMClass)29 TypeReference (org.jikesrvm.classloader.TypeReference)17 RVMType (org.jikesrvm.classloader.RVMType)15 CompiledMethod (org.jikesrvm.compilers.common.CompiledMethod)14 MethodOperand (org.jikesrvm.compilers.opt.ir.operand.MethodOperand)13 Atom (org.jikesrvm.classloader.Atom)11 RegisterOperand (org.jikesrvm.compilers.opt.ir.operand.RegisterOperand)11 Offset (org.vmmagic.unboxed.Offset)11 Instruction (org.jikesrvm.compilers.opt.ir.Instruction)10 Operand (org.jikesrvm.compilers.opt.ir.operand.Operand)10 Address (org.vmmagic.unboxed.Address)9 MethodReference (org.jikesrvm.classloader.MethodReference)8 NormalMethod (org.jikesrvm.classloader.NormalMethod)8 BranchProfileOperand (org.jikesrvm.compilers.opt.ir.operand.BranchProfileOperand)8 IntConstantOperand (org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand)8 Method (java.lang.reflect.Method)7 ConditionOperand (org.jikesrvm.compilers.opt.ir.operand.ConditionOperand)7 TrapCodeOperand (org.jikesrvm.compilers.opt.ir.operand.TrapCodeOperand)7 OptCompiledMethod (org.jikesrvm.compilers.opt.runtimesupport.OptCompiledMethod)7