Skip to content

Commit 3898afd

Browse files
committed
make logging methods static
1 parent 0e81c54 commit 3898afd

File tree

16 files changed

+132
-164
lines changed

16 files changed

+132
-164
lines changed

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

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import com.oracle.truffle.api.nodes.Node;
3636
import com.oracle.truffle.api.nodes.RootNode;
3737
import com.oracle.truffle.espresso.jdwp.impl.DebuggerController;
38-
import com.oracle.truffle.espresso.jdwp.impl.JDWP;
3938

4039
public final class CallFrame {
4140

@@ -54,11 +53,10 @@ public final class CallFrame {
5453
private final DebugStackFrame debugStackFrame;
5554
private final DebugScope debugScope;
5655
private final JDWPContext context;
57-
private final DebuggerController controller;
5856
private Object scope;
5957

6058
public CallFrame(long threadId, byte typeTag, long classId, MethodRef method, long methodId, long codeIndex, Frame frame, Node currentNode, RootNode rootNode,
61-
DebugStackFrame debugStackFrame, JDWPContext context, DebuggerController controller) {
59+
DebugStackFrame debugStackFrame, JDWPContext context) {
6260
this.threadId = threadId;
6361
this.typeTag = typeTag;
6462
this.classId = classId;
@@ -71,11 +69,10 @@ public CallFrame(long threadId, byte typeTag, long classId, MethodRef method, lo
7169
this.debugStackFrame = debugStackFrame;
7270
this.debugScope = debugStackFrame != null ? debugStackFrame.getScope() : null;
7371
this.context = context;
74-
this.controller = controller;
7572
}
7673

7774
public CallFrame(long threadId, byte typeTag, long classId, long methodId, long codeIndex) {
78-
this(threadId, typeTag, classId, null, methodId, codeIndex, null, null, null, null, null, null);
75+
this(threadId, typeTag, classId, null, methodId, codeIndex, null, null, null, null, null);
7976
}
8077

8178
public byte getTypeTag() {
@@ -118,9 +115,7 @@ public Object getThisValue() {
118115
try {
119116
return theScope != null ? INTEROP.readMember(theScope, "this") : null;
120117
} catch (UnsupportedMessageException | UnknownIdentifierException e) {
121-
if (controller != null) {
122-
controller.warning(() -> "Unable to read 'this' value from method: " + getMethod() + " with currentNode: " + currentNode.getClass());
123-
}
118+
DebuggerController.warning(() -> "Unable to read 'this' value from method: " + getMethod() + " with currentNode: " + currentNode.getClass());
124119
return INVALID_VALUE;
125120
}
126121
}
@@ -138,9 +133,7 @@ public void setVariable(Object value, String identifier) {
138133
try {
139134
INTEROP.writeMember(theScope, identifier, value);
140135
} catch (Exception e) {
141-
if (controller != null) {
142-
controller.warning(() -> "Unable to write member " + identifier + " from variables");
143-
}
136+
DebuggerController.warning(() -> "Unable to write member " + identifier + " from variables");
144137
}
145138
}
146139

@@ -158,14 +151,10 @@ private Object getScope() {
158151
try {
159152
scope = NodeLibrary.getUncached().getScope(node, frame, true);
160153
} catch (UnsupportedMessageException e) {
161-
if (controller != null) {
162-
controller.warning(() -> "Unable to get scope for " + currentNode.getClass());
163-
}
154+
DebuggerController.warning(() -> "Unable to get scope for " + currentNode.getClass());
164155
}
165156
} else {
166-
if (controller != null) {
167-
controller.warning(() -> "Unable to get scope for " + currentNode.getClass());
168-
}
157+
DebuggerController.warning(() -> "Unable to get scope for " + currentNode.getClass());
169158
}
170159
return scope;
171160
}

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

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import java.lang.ref.WeakReference;
2828
import java.util.Arrays;
2929
import java.util.HashMap;
30-
import java.util.function.Supplier;
3130
import java.util.regex.Matcher;
3231
import java.util.regex.Pattern;
3332

@@ -55,8 +54,6 @@ public final class Ids<T> {
5554

5655
private HashMap<String, Long> innerClassIDMap = new HashMap<>(16);
5756

58-
private DebuggerController controller;
59-
6057
@SuppressWarnings({"unchecked", "rawtypes"})
6158
public Ids(T nullObject) {
6259
this.nullObject = nullObject;
@@ -71,15 +68,15 @@ public Ids(T nullObject) {
7168
*/
7269
public long getIdAsLong(T object) {
7370
if (object == null) {
74-
log(() -> "Null object when getting ID");
71+
DebuggerController.fine(() -> "Null object when getting ID");
7572
return 0;
7673
}
7774
// lookup in cache
7875
for (int i = 1; i < objects.length; i++) {
7976
// really slow lookup path
8077
if (objects[i].get() == object) {
8178
final int index = i;
82-
log(() -> "ID cache hit for object: " + object + " with ID: " + index);
79+
DebuggerController.fine(() -> "ID cache hit for object: " + object + " with ID: " + index);
8380
return i;
8481
}
8582
}
@@ -110,7 +107,7 @@ public long getId(Object object) {
110107
// really slow lookup path
111108
if (objects[i].get() == object) {
112109
final int index = i;
113-
log(() -> "ID cache hit for object: " + object + " with ID: " + index);
110+
DebuggerController.fine(() -> "ID cache hit for object: " + object + " with ID: " + index);
114111
return i;
115112
}
116113
}
@@ -125,16 +122,16 @@ public long getId(Object object) {
125122
*/
126123
public T fromId(int id) {
127124
if (id == 0) {
128-
log(() -> "Null object from ID: " + id);
125+
DebuggerController.fine(() -> "Null object from ID: " + id);
129126
return nullObject;
130127
}
131128
WeakReference<T> ref = objects[id];
132129
T o = ref.get();
133130
if (o == null) {
134-
log(() -> "object with ID: " + id + " was garbage collected");
131+
DebuggerController.fine(() -> "object with ID: " + id + " was garbage collected");
135132
return null;
136133
} else {
137-
log(() -> "returning object: " + o + " for ID: " + id);
134+
DebuggerController.fine(() -> "returning object: " + o + " for ID: " + id);
138135
return o;
139136
}
140137
}
@@ -150,7 +147,7 @@ private synchronized long generateUniqueId(T object) {
150147
WeakReference<T>[] expandedArray = Arrays.copyOf(objects, objects.length + 1);
151148
expandedArray[objects.length] = new WeakReference<>(object);
152149
objects = expandedArray;
153-
log(() -> "Generating new ID: " + id + " for object: " + object);
150+
DebuggerController.fine(() -> "Generating new ID: " + id + " for object: " + object);
154151
if (object instanceof KlassRef) {
155152
KlassRef klass = (KlassRef) object;
156153
Matcher matcher = ANON_INNER_CLASS_PATTERN.matcher(klass.getNameAsString());
@@ -164,7 +161,7 @@ private synchronized long generateUniqueId(T object) {
164161
public void replaceObject(T original, T replacement) {
165162
int id = (int) getIdAsLong(original);
166163
objects[id] = new WeakReference<>(replacement);
167-
log(() -> "Replaced ID: " + id);
164+
DebuggerController.fine(() -> "Replaced ID: " + id);
168165
}
169166

170167
@SuppressWarnings({"unchecked", "rawtypes"})
@@ -189,14 +186,4 @@ private void removeId(KlassRef klass) {
189186
public boolean checkRemoved(long refTypeId) {
190187
return innerClassIDMap.containsValue(refTypeId);
191188
}
192-
193-
public void injectController(DebuggerController control) {
194-
this.controller = control;
195-
}
196-
197-
private void log(Supplier<String> supplier) {
198-
if (controller != null) {
199-
controller.finest(supplier);
200-
}
201-
}
202189
}

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ public Void call() {
279279
if (holdEvents) {
280280
heldEvents.add(stream);
281281
} else {
282-
debuggerController.fine(() -> "SENDING CLASS PREPARE EVENT FOR KLASS: " + klass.getNameAsString() + " WITH THREAD " + context.getThreadName(prepareThread));
282+
DebuggerController.fine(() -> "SENDING CLASS PREPARE EVENT FOR KLASS: " + klass.getNameAsString() + " WITH THREAD " + context.getThreadName(prepareThread));
283283
connection.queuePacket(stream);
284284
}
285285
return null;
@@ -320,7 +320,7 @@ public void breakpointHit(BreakpointInfo info, CallFrame frame, Object currentTh
320320
stream.writeLong(frame.getClassId());
321321
stream.writeLong(frame.getMethodId());
322322
stream.writeLong(frame.getCodeIndex());
323-
debuggerController.fine(() -> "Sending breakpoint hit event in thread: " + context.getThreadName(currentThread) + " with suspension policy: " + info.getSuspendPolicy());
323+
DebuggerController.fine(() -> "Sending breakpoint hit event in thread: " + context.getThreadName(currentThread) + " with suspension policy: " + info.getSuspendPolicy());
324324
if (holdEvents) {
325325
heldEvents.add(stream);
326326
} else {
@@ -492,7 +492,7 @@ public void stepCompleted(SteppingInfo info, CallFrame currentFrame) {
492492
if (info.isPopFrames()) {
493493
// send reply packet when "step" is completed
494494
PacketStream reply = new PacketStream().replyPacket().id(info.getRequestId());
495-
debuggerController.fine(() -> "Sending pop frames reply packet");
495+
DebuggerController.fine(() -> "Sending pop frames reply packet");
496496
if (holdEvents) {
497497
heldEvents.add(reply);
498498
} else {
@@ -515,7 +515,7 @@ public void stepCompleted(SteppingInfo info, CallFrame currentFrame) {
515515
stream.writeLong(currentFrame.getMethodId());
516516
long codeIndex = info.getStepOutBCI() != -1 ? info.getStepOutBCI() : currentFrame.getCodeIndex();
517517
stream.writeLong(codeIndex);
518-
debuggerController.fine(() -> "Sending step completed event");
518+
DebuggerController.fine(() -> "Sending step completed event");
519519

520520
if (holdEvents) {
521521
heldEvents.add(stream);
@@ -548,7 +548,7 @@ private void sendMonitorContendedEnterEvent(MonitorEvent monitorEvent, CallFrame
548548
stream.writeLong(currentFrame.getMethodId());
549549
long codeIndex = currentFrame.getCodeIndex();
550550
stream.writeLong(codeIndex);
551-
debuggerController.fine(() -> "Sending monitor contended event");
551+
DebuggerController.fine(() -> "Sending monitor contended event");
552552

553553
if (holdEvents) {
554554
heldEvents.add(stream);
@@ -590,7 +590,7 @@ private void sendMonitorContendedEnteredEvent(MonitorEvent monitorEvent, CallFra
590590
stream.writeLong(currentFrame.getMethodId());
591591
long codeIndex = currentFrame.getCodeIndex();
592592
stream.writeLong(codeIndex);
593-
debuggerController.fine(() -> "Sending monitor contended entered event");
593+
DebuggerController.fine(() -> "Sending monitor contended entered event");
594594

595595
if (holdEvents) {
596596
heldEvents.add(stream);
@@ -634,7 +634,7 @@ public void sendMonitorWaitEvent(Object monitor, long timeout, RequestFilter fil
634634

635635
// timeout
636636
stream.writeLong(timeout);
637-
debuggerController.fine(() -> "Sending monitor wait event");
637+
DebuggerController.fine(() -> "Sending monitor wait event");
638638

639639
if (holdEvents) {
640640
heldEvents.add(stream);
@@ -711,7 +711,7 @@ private void sendMonitorWaitedEvent(Object monitor, boolean timedOut, RequestFil
711711

712712
// timeout
713713
stream.writeBoolean(timedOut);
714-
debuggerController.fine(() -> "Sending monitor wait event");
714+
DebuggerController.fine(() -> "Sending monitor wait event");
715715

716716
if (holdEvents) {
717717
heldEvents.add(stream);
@@ -852,7 +852,7 @@ public void threadStarted(Object thread) {
852852
stream.writeByte(RequestedJDWPEvents.THREAD_START);
853853
stream.writeInt(threadStartedRequestId);
854854
stream.writeLong(ids.getIdAsLong(thread));
855-
debuggerController.fine(() -> "sending thread started event for thread: " + context.getThreadName(thread));
855+
DebuggerController.fine(() -> "sending thread started event for thread: " + context.getThreadName(thread));
856856
if (holdEvents) {
857857
heldEvents.add(stream);
858858
} else {
@@ -909,26 +909,26 @@ public boolean vmDied() {
909909
stream.writeByte(RequestedJDWPEvents.VM_DEATH);
910910
stream.writeInt(0);
911911
// don't queue this packet, send immediately
912-
connection.sendVMDied(stream, debuggerController);
912+
connection.sendVMDied(stream);
913913
return vmDeathSuspendPolicy != SuspendStrategy.NONE;
914914
}
915915

916916
@Override
917917
public void addClassUnloadRequestId(int id) {
918918
// not implemented yet
919-
debuggerController.fine(() -> "class unload events not yet implemented!");
919+
DebuggerController.fine(() -> "class unload events not yet implemented!");
920920
}
921921

922922
@Override
923923
public void addThreadStartedRequestId(int id, byte suspendPolicy) {
924-
debuggerController.fine(() -> "Adding thread start listener");
924+
DebuggerController.fine(() -> "Adding thread start listener");
925925
this.threadStartedRequestId = id;
926926
this.threadStartSuspendPolicy = suspendPolicy;
927927
}
928928

929929
@Override
930930
public void addThreadDiedRequestId(int id, byte suspendPolicy) {
931-
debuggerController.fine(() -> "Adding thread death listener");
931+
DebuggerController.fine(() -> "Adding thread death listener");
932932
this.threadDeathRequestId = id;
933933
this.threadDeathSuspendPolicy = suspendPolicy;
934934
}

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public void doProcessCommands(boolean suspend, Collection<Thread> activeThreads,
7474

7575
public void close() {
7676
try {
77-
connection.close(controller);
77+
connection.close();
7878
controller.getEventListener().setConnection(null);
7979
} catch (IOException e) {
8080
throw new RuntimeException("Closing socket connection failed", e);
@@ -112,7 +112,7 @@ private void addBlocking(DebuggerCommand command) {
112112
try {
113113
command.wait();
114114
} catch (InterruptedException e) {
115-
controller.warning(() -> "could not submit debugger command due to " + e.getMessage());
115+
DebuggerController.warning(() -> "could not submit debugger command due to " + e.getMessage());
116116
}
117117
}
118118
}
@@ -198,7 +198,7 @@ public void run() {
198198
processPacket(Packet.fromByteArray(connection.readPacket()));
199199
} catch (IOException e) {
200200
if (!Thread.currentThread().isInterrupted()) {
201-
controller.warning(() -> "Failed to process jdwp packet with message: " + e.getMessage());
201+
DebuggerController.warning(() -> "Failed to process jdwp packet with message: " + e.getMessage());
202202
}
203203
} catch (ConnectionClosedException e) {
204204
// we closed the session, so let the thread run dry
@@ -213,10 +213,10 @@ private void processPacket(Packet packet) {
213213
try {
214214
if (packet.flags == Packet.Reply) {
215215
// result packet from debugger!
216-
controller.warning(() -> "Should not get any reply packet from debugger");
216+
DebuggerController.warning(() -> "Should not get any reply packet from debugger");
217217
} else {
218218
// process a command packet from debugger
219-
controller.fine(() -> "received command(" + packet.cmdSet + "." + packet.cmd + ")");
219+
DebuggerController.fine(() -> "received command(" + packet.cmdSet + "." + packet.cmd + ")");
220220

221221
switch (packet.cmdSet) {
222222
case JDWP.VirtualMachine.ID: {
@@ -225,7 +225,7 @@ private void processPacket(Packet packet) {
225225
result = JDWP.VirtualMachine.VERSION.createReply(packet, controller.getVirtualMachine());
226226
break;
227227
case JDWP.VirtualMachine.CLASSES_BY_SIGNATURE.ID:
228-
result = JDWP.VirtualMachine.CLASSES_BY_SIGNATURE.createReply(packet, controller, context);
228+
result = JDWP.VirtualMachine.CLASSES_BY_SIGNATURE.createReply(packet, context);
229229
break;
230230
case JDWP.VirtualMachine.ALL_CLASSES.ID:
231231
result = JDWP.VirtualMachine.ALL_CLASSES.createReply(packet, context);
@@ -450,7 +450,7 @@ private void processPacket(Packet packet) {
450450
case JDWP.ThreadReference.ID:
451451
switch (packet.cmd) {
452452
case JDWP.ThreadReference.NAME.ID:
453-
result = JDWP.ThreadReference.NAME.createReply(packet, controller, context);
453+
result = JDWP.ThreadReference.NAME.createReply(packet, context);
454454
break;
455455
case JDWP.ThreadReference.SUSPEND.ID:
456456
result = JDWP.ThreadReference.SUSPEND.createReply(packet, controller);
@@ -628,14 +628,14 @@ void handleReply(Packet packet, CommandResult result) {
628628
}
629629
}
630630
} catch (Exception e) {
631-
controller.warning(() -> "Failed to run future for command(" + packet.cmdSet + "." + packet.cmd + ")");
631+
DebuggerController.warning(() -> "Failed to run future for command(" + packet.cmdSet + "." + packet.cmd + ")");
632632
}
633633
}
634634
if (result.getReply() != null) {
635-
controller.fine(() -> "replying to command(" + packet.cmdSet + "." + packet.cmd + ")");
635+
DebuggerController.fine(() -> "replying to command(" + packet.cmdSet + "." + packet.cmd + ")");
636636
connection.queuePacket(result.getReply());
637637
} else {
638-
controller.warning(() -> "no result for command(" + packet.cmdSet + "." + packet.cmd + ")");
638+
DebuggerController.warning(() -> "no result for command(" + packet.cmdSet + "." + packet.cmd + ")");
639639
}
640640
// run post futures after sending the reply
641641
if (result.getPostFutures() != null) {
@@ -646,7 +646,7 @@ void handleReply(Packet packet, CommandResult result) {
646646
}
647647
}
648648
} catch (Exception e) {
649-
controller.severe(() -> "Failed to run future for command(" + packet.cmdSet + "." + packet.cmd + ")");
649+
DebuggerController.severe(() -> "Failed to run future for command(" + packet.cmdSet + "." + packet.cmd + ")");
650650
}
651651
}
652652
}

0 commit comments

Comments
 (0)