Skip to content

Commit 274e2ce

Browse files
committed
[GR-59921] Improve jdwp connection logic.
PullRequest: graal/19368
2 parents aef6140 + 228619f commit 274e2ce

File tree

18 files changed

+265
-354
lines changed

18 files changed

+265
-354
lines changed

espresso/src/com.oracle.truffle.espresso.jdwp/src/com/oracle/truffle/espresso/jdwp/api/CallFrame.java

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
*/
2323
package com.oracle.truffle.espresso.jdwp.api;
2424

25+
import com.oracle.truffle.api.TruffleLogger;
2526
import com.oracle.truffle.api.debug.DebugScope;
2627
import com.oracle.truffle.api.debug.DebugStackFrame;
2728
import com.oracle.truffle.api.debug.DebugValue;
@@ -34,10 +35,8 @@
3435
import com.oracle.truffle.api.interop.UnsupportedMessageException;
3536
import com.oracle.truffle.api.nodes.Node;
3637
import com.oracle.truffle.api.nodes.RootNode;
37-
import com.oracle.truffle.espresso.jdwp.impl.DebuggerController;
3838

3939
public final class CallFrame {
40-
4140
private static final InteropLibrary INTEROP = InteropLibrary.getFactory().getUncached();
4241
public static final Object INVALID_VALUE = new Object();
4342

@@ -53,11 +52,11 @@ public final class CallFrame {
5352
private final DebugStackFrame debugStackFrame;
5453
private final DebugScope debugScope;
5554
private final JDWPContext context;
56-
private final DebuggerController controller;
5755
private Object scope;
56+
private final TruffleLogger logger;
5857

5958
public CallFrame(long threadId, byte typeTag, long classId, MethodRef method, long methodId, long codeIndex, Frame frame, Node currentNode, RootNode rootNode,
60-
DebugStackFrame debugStackFrame, JDWPContext context, DebuggerController controller) {
59+
DebugStackFrame debugStackFrame, JDWPContext context, TruffleLogger logger) {
6160
this.threadId = threadId;
6261
this.typeTag = typeTag;
6362
this.classId = classId;
@@ -70,11 +69,12 @@ public CallFrame(long threadId, byte typeTag, long classId, MethodRef method, lo
7069
this.debugStackFrame = debugStackFrame;
7170
this.debugScope = debugStackFrame != null ? debugStackFrame.getScope() : null;
7271
this.context = context;
73-
this.controller = controller;
72+
this.logger = logger;
7473
}
7574

76-
public CallFrame(long threadId, byte typeTag, long classId, long methodId, long codeIndex) {
77-
this(threadId, typeTag, classId, null, methodId, codeIndex, null, null, null, null, null, null);
75+
// used for tests in comparisons only
76+
public CallFrame(long threadId, byte typeTag, long classId, long methodId, long codeIndex, TruffleLogger logger) {
77+
this(threadId, typeTag, classId, null, methodId, codeIndex, null, null, null, null, null, logger);
7878
}
7979

8080
public byte getTypeTag() {
@@ -124,9 +124,7 @@ public Object getThisValue() {
124124
}
125125
return INTEROP.readMember(theScope, "0");
126126
} catch (UnsupportedMessageException | UnknownIdentifierException e) {
127-
if (controller != null) {
128-
controller.warning(() -> "Unable to read 'this' value from method: " + getMethod() + " with currentNode: " + currentNode.getClass());
129-
}
127+
logger.warning(() -> "Unable to read 'this' value from method: " + getMethod() + " with currentNode: " + currentNode.getClass());
130128
return INVALID_VALUE;
131129
}
132130
}
@@ -144,9 +142,7 @@ public void setVariable(Object value, String identifier) {
144142
try {
145143
INTEROP.writeMember(theScope, identifier, value);
146144
} catch (Exception e) {
147-
if (controller != null) {
148-
controller.warning(() -> "Unable to write member " + identifier + " from variables");
149-
}
145+
logger.warning(() -> "Unable to write member " + identifier + " from variables");
150146
}
151147
}
152148

@@ -164,14 +160,10 @@ private Object getScope() {
164160
try {
165161
scope = NodeLibrary.getUncached().getScope(node, frame, true);
166162
} catch (UnsupportedMessageException e) {
167-
if (controller != null) {
168-
controller.warning(() -> "Unable to get scope for " + currentNode.getClass());
169-
}
163+
logger.warning(() -> "Unable to get scope for " + currentNode.getClass());
170164
}
171165
} else {
172-
if (controller != null) {
173-
controller.warning(() -> "Unable to get scope for " + currentNode.getClass());
174-
}
166+
logger.warning(() -> "Unable to get scope for " + currentNode.getClass());
175167
}
176168
return scope;
177169
}

espresso/src/com.oracle.truffle.espresso.jdwp/src/com/oracle/truffle/espresso/jdwp/api/Ids.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import java.util.regex.Matcher;
3232
import java.util.regex.Pattern;
3333

34-
import com.oracle.truffle.espresso.jdwp.impl.DebuggerController;
34+
import com.oracle.truffle.api.TruffleLogger;
3535

3636
/**
3737
* Class that keeps an ID representation of all entities when communicating with a debugger through
@@ -57,11 +57,10 @@ public final class Ids<T> {
5757

5858
private HashMap<String, Long> innerClassIDMap = new HashMap<>(16);
5959

60-
private DebuggerController controller;
61-
6260
private List<Object> pinnedObjects = new ArrayList<>();
6361

6462
private volatile boolean pinningState = false;
63+
private TruffleLogger logger;
6564

6665
@SuppressWarnings({"unchecked", "rawtypes"})
6766
public Ids(T nullObject) {
@@ -202,14 +201,8 @@ public boolean checkRemoved(long refTypeId) {
202201
return innerClassIDMap.containsValue(refTypeId);
203202
}
204203

205-
public void injectController(DebuggerController control) {
206-
this.controller = control;
207-
}
208-
209204
private void log(Supplier<String> supplier) {
210-
if (controller != null) {
211-
controller.finest(supplier);
212-
}
205+
logger.finest(supplier);
213206
}
214207

215208
public synchronized void pinAll() {
@@ -226,4 +219,8 @@ public synchronized void unpinAll() {
226219
pinningState = false;
227220
pinnedObjects.clear();
228221
}
222+
223+
public void injectLogger(TruffleLogger truffleLogger) {
224+
this.logger = truffleLogger;
225+
}
229226
}

espresso/src/com.oracle.truffle.espresso.jdwp/src/com/oracle/truffle/espresso/jdwp/api/JDWPSetup.java

Lines changed: 0 additions & 44 deletions
This file was deleted.

espresso/src/com.oracle.truffle.espresso.jdwp/src/com/oracle/truffle/espresso/jdwp/impl/DebuggerConnection.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public void run() {
201201
}
202202
// Now, begin processing packets when they start to flow from the debugger
203203
try {
204-
while (!Thread.currentThread().isInterrupted()) {
204+
while (!Thread.currentThread().isInterrupted() && !controller.isClosing()) {
205205
try {
206206
processPacket(Packet.fromByteArray(debuggerConnection.connection.readPacket()));
207207
} catch (IOException e) {
@@ -242,7 +242,7 @@ private void processPacket(Packet packet) {
242242
result = JDWP.VirtualMachine.CLASSES_BY_SIGNATURE.createReply(packet, controller, context);
243243
break;
244244
case JDWP.VirtualMachine.ALL_CLASSES.ID:
245-
result = JDWP.VirtualMachine.ALL_CLASSES.createReply(packet, context);
245+
result = JDWP.VirtualMachine.ALL_CLASSES.createReply(packet, context, controller);
246246
break;
247247
case JDWP.VirtualMachine.ALL_THREADS.ID:
248248
result = JDWP.VirtualMachine.ALL_THREADS.createReply(packet, context, controller);

0 commit comments

Comments
 (0)