Search in sources :

Example 1 with Utf8ConstantTable

use of com.oracle.truffle.espresso.descriptors.Utf8ConstantTable in project graal by oracle.

the class EspressoInstrumentableNode method getScope.

@ExportMessage
@TruffleBoundary
@SuppressWarnings("static-method")
public final Object getScope(Frame frame, @SuppressWarnings("unused") boolean nodeEnter) {
    // construct the current scope with valid local variables information
    Method method = getMethod();
    Local[] liveLocals = method.getLocalVariableTable().getLocalsAt(getBci(frame));
    if (liveLocals.length == 0) {
        // class was compiled without a local variable table
        // include "this" in method arguments throughout the method
        boolean hasReceiver = !method.isStatic();
        int localCount = hasReceiver ? 1 : 0;
        localCount += method.getParameterCount();
        liveLocals = new Local[localCount];
        Klass[] parameters = (Klass[]) method.getParameters();
        Utf8ConstantTable utf8Constants = getContext().getLanguage().getUtf8ConstantTable();
        int startslot = 0;
        if (hasReceiver) {
            // include 'this' and method arguments
            liveLocals[0] = new Local(utf8Constants.getOrCreate(Symbol.Name.thiz), utf8Constants.getOrCreate(method.getDeclaringKlass().getType()), 0, 65536, 0);
            startslot++;
        }
        // include method parameters
        for (int i = startslot; i < localCount; i++) {
            Klass param = hasReceiver ? parameters[i - 1] : parameters[i];
            liveLocals[i] = new Local(utf8Constants.getOrCreate(ByteSequence.create("param_" + (i))), utf8Constants.getOrCreate(param.getType()), 0, 65536, i);
        }
    }
    return EspressoScope.createVariables(liveLocals, frame, method.getName());
}
Also used : Klass(com.oracle.truffle.espresso.impl.Klass) Local(com.oracle.truffle.espresso.classfile.attributes.Local) Method(com.oracle.truffle.espresso.impl.Method) Utf8ConstantTable(com.oracle.truffle.espresso.descriptors.Utf8ConstantTable) ExportMessage(com.oracle.truffle.api.library.ExportMessage) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Aggregations

TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)1 ExportMessage (com.oracle.truffle.api.library.ExportMessage)1 Local (com.oracle.truffle.espresso.classfile.attributes.Local)1 Utf8ConstantTable (com.oracle.truffle.espresso.descriptors.Utf8ConstantTable)1 Klass (com.oracle.truffle.espresso.impl.Klass)1 Method (com.oracle.truffle.espresso.impl.Method)1