Search in sources :

Example 1 with MemberReference

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

the class EdgeCounts method readCounts.

public static void readCounts(String fn) {
    LineNumberReader in = null;
    try {
        in = new LineNumberReader(new FileReader(fn));
    } catch (IOException e) {
        e.printStackTrace();
        VM.sysFail("Unable to open input edge counter file " + fn);
    }
    try {
        int[] cur = null;
        int curIdx = 0;
        for (String s = in.readLine(); s != null; s = in.readLine()) {
            // strip classloader cruft we can't parse
            s = s.replaceAll("\\{urls[^\\}]*\\}", "");
            StringTokenizer parser = new StringTokenizer(s, " \t\n\r\f,{}");
            String firstToken = parser.nextToken();
            if (firstToken.equals("M")) {
                int numCounts = Integer.parseInt(parser.nextToken());
                MemberReference key = MemberReference.parse(parser);
                int id = key.getId();
                allocateCounters(id, numCounts);
                cur = data[id];
                curIdx = 0;
                if (Controller.options.BULK_COMPILATION_VERBOSITY >= 1) {
                    VM.sysWrite("M");
                }
            } else {
                // discard bytecode index, we don't care.
                String type = parser.nextToken();
                if (type.equals("switch")) {
                    // discard '<'
                    parser.nextToken();
                    for (String nt = parser.nextToken(); !nt.equals(">"); nt = parser.nextToken()) {
                        cur[curIdx++] = Integer.parseInt(nt);
                    }
                    if (Controller.options.BULK_COMPILATION_VERBOSITY >= 1) {
                        VM.sysWrite("S");
                    }
                } else if (type.equals("forwbranch") || type.equals("backbranch")) {
                    // discard '<'
                    parser.nextToken();
                    cur[curIdx + TAKEN] = Integer.parseInt(parser.nextToken());
                    cur[curIdx + NOT_TAKEN] = Integer.parseInt(parser.nextToken());
                    curIdx += 2;
                    if (Controller.options.BULK_COMPILATION_VERBOSITY >= 1) {
                        VM.sysWrite("B");
                    }
                } else {
                    VM.sysFail("Format error in edge counter input file");
                }
            }
        }
        in.close();
    } catch (IOException e) {
        e.printStackTrace();
        VM.sysFail("Error parsing input edge counter file" + fn);
    }
    // Enable debug of input by dumping file as we exit the VM.
    if (false) {
        Callbacks.addExitMonitor(new EdgeCounts());
        BaselineCompiler.processCommandLineArg("-X:base:", "edge_counter_file=DebugEdgeCounters");
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) MemberReference(org.jikesrvm.classloader.MemberReference) FileReader(java.io.FileReader) IOException(java.io.IOException) Entrypoint(org.vmmagic.pragma.Entrypoint) LineNumberReader(java.io.LineNumberReader)

Example 2 with MemberReference

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

the class JNIHelpers method invokeInitializer.

/**
 * Common code shared by the JNI functions NewObjectA, NewObjectV, NewObject
 * (object creation)
 * @param cls class whose constructor is to be invoked
 * @param methodID the method ID for a constructor
 * @param argAddress where to find the arguments for the constructor
 * @param isJvalue {@code true} if parameters are passed as a jvalue array
 * @param isDotDotStyle {@code true} if the method uses varargs
 * @return a new object created by the specified constructor
 * @throws Exception when the reflective invocation of the constructor fails
 */
public static Object invokeInitializer(Class<?> cls, int methodID, Address argAddress, boolean isJvalue, boolean isDotDotStyle) throws Exception {
    // get the parameter list as Java class
    MemberReference mr = MemberReference.getMemberRef(methodID);
    TypeReference tr = java.lang.JikesRVMSupport.getTypeForClass(cls).getTypeRef();
    MethodReference methodRef = MemberReference.findOrCreate(tr, mr.getName(), mr.getDescriptor()).asMethodReference();
    RVMMethod mth = methodRef.resolve();
    Constructor<?> constMethod = java.lang.reflect.JikesRVMSupport.createConstructor(mth);
    if (!mth.isPublic()) {
        constMethod.setAccessible(true);
    }
    // Package the parameters for the constructor
    Address varargAddress;
    if (isDotDotStyle) {
        // flag is false because this JNI function has 3 args before the var args
        varargAddress = getVarArgAddress(false);
    } else {
        varargAddress = argAddress;
    }
    Object[] argObjs;
    if (isJvalue) {
        argObjs = packageParametersFromJValuePtr(methodRef, argAddress);
    } else {
        argObjs = packageParameterFromVarArg(methodRef, varargAddress);
    }
    // construct the new object
    return constMethod.newInstance(argObjs);
}
Also used : RVMMethod(org.jikesrvm.classloader.RVMMethod) Address(org.vmmagic.unboxed.Address) MemberReference(org.jikesrvm.classloader.MemberReference) MethodReference(org.jikesrvm.classloader.MethodReference) TypeReference(org.jikesrvm.classloader.TypeReference)

Example 3 with MemberReference

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

the class DynamicCallFileInfoReader method readOneCallSiteAttribute.

private static void readOneCallSiteAttribute(StringTokenizer parser, boolean boot) {
    String firstToken = parser.nextToken();
    if (firstToken.equals("CallSite")) {
        try {
            MemberReference callerKey = MemberReference.parse(parser, boot);
            if (callerKey == null)
                return;
            MethodReference callerRef = callerKey.asMethodReference();
            RVMMethod caller, callee;
            caller = getMethod(callerRef);
            // serves as doco - token skipped
            @SuppressWarnings("unused") int callerSize = Integer.parseInt(parser.nextToken());
            int bci = Integer.parseInt(parser.nextToken());
            MemberReference calleeKey = MemberReference.parse(parser, boot);
            if (calleeKey == null)
                return;
            MethodReference calleeRef = calleeKey.asMethodReference();
            callee = getMethod(calleeRef);
            // serves as doco - token skipped
            @SuppressWarnings("unused") int calleeSize = Integer.parseInt(parser.nextToken());
            // skip "weight:"
            parser.nextToken();
            float weight = Float.parseFloat(parser.nextToken());
            if ((caller == null) || (callee == null)) {
                Controller.dcg.incrementUnResolvedEdge(callerRef, bci, calleeRef, weight);
            } else {
                Controller.dcg.incrementEdge(caller, bci, callee, weight);
            }
        } catch (Exception e) {
            VM.sysWriteln("Caught exception: " + e);
        }
    } else {
        VM.sysFail("Format error in dynamic call graph file");
    }
}
Also used : RVMMethod(org.jikesrvm.classloader.RVMMethod) MemberReference(org.jikesrvm.classloader.MemberReference) MethodReference(org.jikesrvm.classloader.MethodReference) IOException(java.io.IOException)

Example 4 with MemberReference

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

the class GenerateMagic method mapToMetadata.

private static LocationOperand mapToMetadata(Operand metadata) {
    if (metadata instanceof IntConstantOperand) {
        int index = ((IntConstantOperand) metadata).value;
        if (index == 0)
            return null;
        MemberReference mr = MemberReference.getMemberRef(index);
        return new LocationOperand(mr.asFieldReference());
    }
    return null;
}
Also used : LocationOperand(org.jikesrvm.compilers.opt.ir.operand.LocationOperand) IntConstantOperand(org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand) MemberReference(org.jikesrvm.classloader.MemberReference)

Example 5 with MemberReference

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

the class JNIHelpers method invokeInitializer.

/**
 * Common code shared by the JNI functions NewObjectA, NewObjectV, NewObject
 * (object creation)
 * @param methodID the method ID for a constructor
 * @return a new object created by the specified constructor
 */
public static Object invokeInitializer(Class<?> cls, int methodID, Address argAddress, boolean isJvalue, boolean isDotDotStyle) throws Exception {
    // get the parameter list as Java class
    MemberReference mr = MemberReference.getMemberRef(methodID);
    TypeReference tr = java.lang.JikesRVMSupport.getTypeForClass(cls).getTypeRef();
    MethodReference methodRef = MemberReference.findOrCreate(tr, mr.getName(), mr.getDescriptor()).asMethodReference();
    RVMMethod mth = methodRef.resolve();
    Constructor<?> constMethod = java.lang.reflect.JikesRVMSupport.createConstructor(mth);
    if (!mth.isPublic()) {
        constMethod.setAccessible(true);
    }
    Object[] argObjs;
    if (isJvalue) {
        argObjs = packageParametersFromJValuePtr(methodRef, argAddress);
    } else if (isDotDotStyle) {
        // dot dot var arg
        if (VM.BuildForPower64ELF_ABI) {
            Address varargAddress = pushVarArgToSpillArea(methodID, false);
            argObjs = packageParameterFromVarArg(methodRef, varargAddress);
        } else {
            if (VM.VerifyAssertions)
                VM._assert(VM.BuildForSVR4ABI);
            // pass in the frame pointer of glue stack frames
            // stack frame looks as following:
            // this method ->
            // 
            // architecture.JNIHelpers.method -->
            // 
            // native to java method ->
            // 
            // glue frame ->
            // 
            // native C method ->
            Address gluefp = Magic.getCallerFramePointer(Magic.getCallerFramePointer(Magic.getCallerFramePointer(Magic.getFramePointer())));
            argObjs = packageParameterFromDotArgSVR4(methodRef, gluefp, false);
        }
    } else {
        // mormal var arg
        if (VM.BuildForPower64ELF_ABI) {
            argObjs = packageParameterFromVarArg(methodRef, argAddress);
        } else {
            if (VM.VerifyAssertions)
                VM._assert(VM.BuildForSVR4ABI);
            argObjs = packageParameterFromVarArgSVR4(methodRef, argAddress);
        }
    }
    // construct the new object
    return constMethod.newInstance(argObjs);
}
Also used : RVMMethod(org.jikesrvm.classloader.RVMMethod) Address(org.vmmagic.unboxed.Address) MemberReference(org.jikesrvm.classloader.MemberReference) MethodReference(org.jikesrvm.classloader.MethodReference) TypeReference(org.jikesrvm.classloader.TypeReference)

Aggregations

MemberReference (org.jikesrvm.classloader.MemberReference)5 MethodReference (org.jikesrvm.classloader.MethodReference)3 RVMMethod (org.jikesrvm.classloader.RVMMethod)3 IOException (java.io.IOException)2 TypeReference (org.jikesrvm.classloader.TypeReference)2 Address (org.vmmagic.unboxed.Address)2 FileReader (java.io.FileReader)1 LineNumberReader (java.io.LineNumberReader)1 StringTokenizer (java.util.StringTokenizer)1 IntConstantOperand (org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand)1 LocationOperand (org.jikesrvm.compilers.opt.ir.operand.LocationOperand)1 Entrypoint (org.vmmagic.pragma.Entrypoint)1