Search in sources :

Example 1 with KlassRef

use of com.oracle.truffle.espresso.jdwp.api.KlassRef in project graal by oracle.

the class DebuggerController method captureCallFramesBeforeBlocking.

public CallFrame[] captureCallFramesBeforeBlocking(Object guestThread) {
    List<CallFrame> callFrames = new ArrayList<>();
    Truffle.getRuntime().iterateFrames(new FrameInstanceVisitor<>() {

        @Override
        public Object visitFrame(FrameInstance frameInstance) {
            KlassRef klass;
            MethodRef method;
            RootNode root = getRootNode(frameInstance);
            if (root == null) {
                return null;
            }
            method = getContext().getMethodFromRootNode(root);
            if (method == null) {
                return null;
            }
            klass = method.getDeclaringKlassRef();
            long klassId = ids.getIdAsLong(klass);
            long methodId = ids.getIdAsLong(method);
            byte typeTag = TypeTag.getKind(klass);
            Frame frame = frameInstance.getFrame(FrameInstance.FrameAccess.READ_WRITE);
            // for bytecode-based languages (Espresso) we can read the precise bci from the
            // frame
            long codeIndex = -1;
            try {
                codeIndex = context.readBCIFromFrame(root, frame);
            } catch (Throwable t) {
                JDWP.LOGGER.fine(() -> "Unable to read current BCI from frame in method: " + klass.getNameAsString() + "." + method.getNameAsString());
            }
            if (codeIndex == -1) {
                // fall back to start of the method then
                codeIndex = 0;
            }
            // check if current bci is higher than the first index on the last line,
            // in which case we must report the last line index instead
            long lastLineBCI = method.getBCIFromLine(method.getLastLine());
            if (codeIndex > lastLineBCI) {
                codeIndex = lastLineBCI;
            }
            Node currentNode = frameInstance.getCallNode();
            if (currentNode == null) {
                CallTarget callTarget = frameInstance.getCallTarget();
                if (callTarget instanceof RootCallTarget) {
                    currentNode = ((RootCallTarget) callTarget).getRootNode();
                }
            }
            if (currentNode instanceof RootNode) {
                currentNode = context.getInstrumentableNode((RootNode) currentNode);
            }
            callFrames.add(new CallFrame(context.getIds().getIdAsLong(guestThread), typeTag, klassId, method, methodId, codeIndex, frame, currentNode, root, null, context));
            return null;
        }
    });
    CallFrame[] result = callFrames.toArray(new CallFrame[callFrames.size()]);
    // collect monitor info
    MonitorStackInfo[] ownedMonitorInfos = context.getOwnedMonitors(result);
    HashMap<Object, Integer> entryCounts = new HashMap<>(ownedMonitorInfos.length);
    for (MonitorStackInfo ownedMonitorInfo : ownedMonitorInfos) {
        Object monitor = ownedMonitorInfo.getMonitor();
        entryCounts.put(monitor, context.getMonitorEntryCount(monitor));
    }
    suspendedInfos.put(guestThread, new SuspendedInfo(context, result, guestThread, entryCounts));
    return result;
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode) DebugStackFrame(com.oracle.truffle.api.debug.DebugStackFrame) CallFrame(com.oracle.truffle.espresso.jdwp.api.CallFrame) Frame(com.oracle.truffle.api.frame.Frame) HashMap(java.util.HashMap) RootCallTarget(com.oracle.truffle.api.RootCallTarget) CallTarget(com.oracle.truffle.api.CallTarget) RootNode(com.oracle.truffle.api.nodes.RootNode) Node(com.oracle.truffle.api.nodes.Node) ArrayList(java.util.ArrayList) MonitorStackInfo(com.oracle.truffle.espresso.jdwp.api.MonitorStackInfo) FrameInstance(com.oracle.truffle.api.frame.FrameInstance) MethodRef(com.oracle.truffle.espresso.jdwp.api.MethodRef) CallFrame(com.oracle.truffle.espresso.jdwp.api.CallFrame) KlassRef(com.oracle.truffle.espresso.jdwp.api.KlassRef) RootCallTarget(com.oracle.truffle.api.RootCallTarget)

Example 2 with KlassRef

use of com.oracle.truffle.espresso.jdwp.api.KlassRef in project graal by oracle.

the class JDKProxyRedefinitionPlugin method collectExtraClassesToReload.

@Override
@TruffleBoundary
public synchronized void collectExtraClassesToReload(List<RedefineInfo> redefineInfos, List<RedefineInfo> additional) {
    for (RedefineInfo redefineInfo : redefineInfos) {
        KlassRef klass = redefineInfo.getKlass();
        if (klass != null) {
            List<ProxyCache> list = cache.getOrDefault(klass, Collections.emptyList());
            for (ProxyCache proxyCache : list) {
                StaticObject result = (StaticObject) proxyGeneratorMethodCallNode.call(proxyCache.proxyName, proxyCache.interfaces, proxyCache.classModifier);
                byte[] proxyBytes = (byte[]) getContext().getMeta().toHostBoxed(result);
                additional.add(new RedefineInfo(proxyCache.klass, proxyBytes));
            }
        }
    }
}
Also used : RedefineInfo(com.oracle.truffle.espresso.jdwp.api.RedefineInfo) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) KlassRef(com.oracle.truffle.espresso.jdwp.api.KlassRef) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 3 with KlassRef

use of com.oracle.truffle.espresso.jdwp.api.KlassRef in project graal by oracle.

the class JDWPContextImpl method getNestedTypes.

@Override
public KlassRef[] getNestedTypes(KlassRef klass) {
    if (klass instanceof ObjectKlass) {
        ArrayList<KlassRef> result = new ArrayList<>();
        ObjectKlass objectKlass = (ObjectKlass) klass;
        List<Symbol<Symbol.Name>> nestedTypeNames = objectKlass.getNestedTypeNames();
        StaticObject classLoader = objectKlass.getDefiningClassLoader();
        for (Symbol<Symbol.Name> nestedType : nestedTypeNames) {
            Symbol<Symbol.Type> type = context.getTypes().fromClassGetName(nestedType.toString());
            KlassRef loadedKlass = context.getRegistries().findLoadedClass(type, classLoader);
            if (loadedKlass != null && loadedKlass != klass) {
                result.add(loadedKlass);
            }
        }
        return result.toArray(new KlassRef[0]);
    }
    return null;
}
Also used : Symbol(com.oracle.truffle.espresso.descriptors.Symbol) ArrayList(java.util.ArrayList) ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass) KlassRef(com.oracle.truffle.espresso.jdwp.api.KlassRef)

Example 4 with KlassRef

use of com.oracle.truffle.espresso.jdwp.api.KlassRef in project graal by oracle.

the class JDWPContextImpl method locateObjectWaitFrame.

@Override
public CallFrame locateObjectWaitFrame() {
    Object currentThread = asGuestThread(Thread.currentThread());
    KlassRef klass = context.getMeta().java_lang_Object;
    MethodRef method = context.getMeta().java_lang_Object_wait.getMethodVersion();
    return new CallFrame(ids.getIdAsLong(currentThread), TypeTag.CLASS, ids.getIdAsLong(klass), method, ids.getIdAsLong(method), 0, null, null, null, null, null);
}
Also used : MethodRef(com.oracle.truffle.espresso.jdwp.api.MethodRef) CallFrame(com.oracle.truffle.espresso.jdwp.api.CallFrame) KlassRef(com.oracle.truffle.espresso.jdwp.api.KlassRef)

Example 5 with KlassRef

use of com.oracle.truffle.espresso.jdwp.api.KlassRef in project graal by oracle.

the class JDKProxyRedefinitionPlugin method collectProxyArguments.

public synchronized void collectProxyArguments(@JavaType(String.class) StaticObject proxyName, @JavaType(Class[].class) StaticObject interfaces, int classModifier, DirectCallNode generatorMethodCallNode) {
    if (proxyGeneratorMethodCallNode == null) {
        proxyGeneratorMethodCallNode = generatorMethodCallNode;
    }
    // register onLoad action that will give us
    // the klass object for the generated proxy
    registerClassLoadAction(getContext().getMeta().toHostString(proxyName), klass -> {
        // store guest-world arguments that we can use when
        // invoking the call node later on re-generation
        ProxyCache proxyCache = new ProxyCache(klass, proxyName, interfaces, classModifier);
        Klass[] proxyInterfaces = new Klass[interfaces.length()];
        for (int i = 0; i < proxyInterfaces.length; i++) {
            proxyInterfaces[i] = (Klass) getContext().getMeta().HIDDEN_MIRROR_KLASS.getHiddenObject(interfaces.get(i));
        }
        // when they change we can re-generate the proxy bytes
        for (KlassRef proxyInterface : proxyInterfaces) {
            addCacheEntry(proxyCache, proxyInterface);
        }
    });
}
Also used : Klass(com.oracle.truffle.espresso.impl.Klass) ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass) KlassRef(com.oracle.truffle.espresso.jdwp.api.KlassRef)

Aggregations

KlassRef (com.oracle.truffle.espresso.jdwp.api.KlassRef)9 MethodRef (com.oracle.truffle.espresso.jdwp.api.MethodRef)6 ArrayList (java.util.ArrayList)4 Breakpoint (com.oracle.truffle.api.debug.Breakpoint)2 RootNode (com.oracle.truffle.api.nodes.RootNode)2 ObjectKlass (com.oracle.truffle.espresso.impl.ObjectKlass)2 CallFrame (com.oracle.truffle.espresso.jdwp.api.CallFrame)2 CallTarget (com.oracle.truffle.api.CallTarget)1 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)1 RootCallTarget (com.oracle.truffle.api.RootCallTarget)1 DebugStackFrame (com.oracle.truffle.api.debug.DebugStackFrame)1 Frame (com.oracle.truffle.api.frame.Frame)1 FrameInstance (com.oracle.truffle.api.frame.FrameInstance)1 Node (com.oracle.truffle.api.nodes.Node)1 Symbol (com.oracle.truffle.espresso.descriptors.Symbol)1 Klass (com.oracle.truffle.espresso.impl.Klass)1 FieldRef (com.oracle.truffle.espresso.jdwp.api.FieldRef)1 JDWPContext (com.oracle.truffle.espresso.jdwp.api.JDWPContext)1 MonitorStackInfo (com.oracle.truffle.espresso.jdwp.api.MonitorStackInfo)1 RedefineInfo (com.oracle.truffle.espresso.jdwp.api.RedefineInfo)1