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;
}
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));
}
}
}
}
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;
}
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);
}
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);
}
});
}
Aggregations