Skip to content

Commit e436163

Browse files
committed
[GR-62501] Revert refactor of Method vs. MethodVersion to fix isObsolete().
PullRequest: graal/20342
2 parents da40831 + ad4c6d4 commit e436163

File tree

11 files changed

+234
-225
lines changed

11 files changed

+234
-225
lines changed

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public final class CallFrame {
4242

4343
private final byte typeTag;
4444
private final long classId;
45-
private final MethodRef method;
45+
private final MethodVersionRef methodVersion;
4646
private final long methodId;
4747
private final long codeIndex;
4848
private final long threadId;
@@ -55,14 +55,14 @@ public final class CallFrame {
5555
private Object scope;
5656
private final TruffleLogger logger;
5757

58-
public CallFrame(long threadId, byte typeTag, long classId, MethodRef method, long methodId, long codeIndex, Frame frame, Node currentNode, RootNode rootNode,
58+
public CallFrame(long threadId, byte typeTag, long classId, MethodVersionRef methodVersion, long methodId, long codeIndex, Frame frame, Node currentNode, RootNode rootNode,
5959
DebugStackFrame debugStackFrame, JDWPContext context, TruffleLogger logger) {
6060
this.threadId = threadId;
6161
this.typeTag = typeTag;
6262
this.classId = classId;
63-
this.method = method;
63+
this.methodVersion = methodVersion;
6464
this.methodId = methodId;
65-
this.codeIndex = method != null && method.isObsolete() ? -1 : codeIndex;
65+
this.codeIndex = methodVersion != null && methodVersion.isObsolete() ? -1 : codeIndex;
6666
this.frame = frame;
6767
this.currentNode = currentNode;
6868
this.rootNode = rootNode;
@@ -85,15 +85,22 @@ public long getClassId() {
8585
return classId;
8686
}
8787

88+
public MethodVersionRef getMethodVersion() {
89+
return methodVersion;
90+
}
91+
8892
public MethodRef getMethod() {
89-
return method;
93+
if (methodVersion != null) {
94+
return methodVersion.getMethod();
95+
}
96+
return null;
9097
}
9198

9299
public long getMethodId() {
93-
if (method == null) {
100+
if (methodVersion == null) {
94101
return methodId;
95102
}
96-
return method.isObsolete() ? 0 : methodId;
103+
return methodVersion.isObsolete() ? 0 : methodId;
97104
}
98105

99106
public long getCodeIndex() {

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

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -172,31 +172,6 @@ private synchronized long generateUniqueId(T object) {
172172
return id;
173173
}
174174

175-
public void replaceObject(T original, T replacement) {
176-
int id = (int) getIdAsLong(original);
177-
objects[id] = new WeakReference<>(replacement);
178-
log(() -> "Replaced ID: " + id);
179-
}
180-
181-
@SuppressWarnings({"unchecked", "rawtypes"})
182-
public void updateId(KlassRef klass) {
183-
// remove existing ID
184-
removeId(klass);
185-
Long theId = innerClassIDMap.get(klass.getNameAsString());
186-
if (theId != null) {
187-
// then inject klass under the new ID
188-
objects[(int) (long) theId] = new WeakReference(klass);
189-
}
190-
}
191-
192-
@SuppressWarnings({"unchecked", "rawtypes"})
193-
private void removeId(KlassRef klass) {
194-
int id = (int) getId(klass);
195-
if (id > 0) {
196-
objects[id] = new WeakReference<>(null);
197-
}
198-
}
199-
200175
public boolean checkRemoved(long refTypeId) {
201176
return innerClassIDMap.containsValue(refTypeId);
202177
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public interface JDWPContext {
7373
* @param root the Truffle root node object
7474
* @return the declaring method of the root node
7575
*/
76-
MethodRef getMethodFromRootNode(RootNode root);
76+
MethodVersionRef getMethodFromRootNode(RootNode root);
7777

7878
/**
7979
* @return guest language array of all active threads

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

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -175,14 +175,6 @@ public interface MethodRef {
175175
*/
176176
boolean hasSourceFileAttribute();
177177

178-
/**
179-
* Determines if the code index is located in the source file on the last line of this method.
180-
*
181-
* @param codeIndex
182-
* @return true if last line, false otherwise
183-
*/
184-
boolean isLastLine(long codeIndex);
185-
186178
/**
187179
* Returns the klass that declares this method.
188180
*
@@ -234,16 +226,6 @@ public interface MethodRef {
234226

235227
void disposeHooks();
236228

237-
/**
238-
* Determine if this method is obsolete. A method is obsolete if it has been replaced by a
239-
* non-equivalent method using the RedefineClasses command. The original and redefined methods
240-
* are considered equivalent if their bytecodes are the same except for indices into the
241-
* constant pool and the referenced constants are equal.
242-
*
243-
* @return true if the method is obsolete
244-
*/
245-
boolean isObsolete();
246-
247229
/**
248230
* Returns the last bci of the method.
249231
*
@@ -264,4 +246,11 @@ public interface MethodRef {
264246
* @return true if the method is a static initializer
265247
*/
266248
boolean isClassInitializer();
249+
250+
/**
251+
* Determines if this method was removed by redefinition.
252+
*
253+
* @return true if removed
254+
*/
255+
boolean isRemovedByRedefinition();
267256
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (c) 2025, 2025, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
package com.oracle.truffle.espresso.jdwp.api;
24+
25+
public interface MethodVersionRef {
26+
/**
27+
* Returns the MethodRef corresponding to this method version.
28+
*
29+
* @return the MethodRef
30+
*/
31+
MethodRef getMethod();
32+
33+
/**
34+
* Determine if this method is obsolete. A method is obsolete if it has been replaced by a
35+
* non-equivalent method using the RedefineClasses command. The original and redefined methods
36+
* are considered equivalent if their bytecodes are the same except for indices into the
37+
* constant pool and the referenced constants are equal.
38+
*
39+
* @return true if the method is obsolete
40+
*/
41+
boolean isObsolete();
42+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2029, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -96,7 +96,7 @@ public interface VMListener {
9696
* This method should be called when when the monitor wait(timeout) method is invoked in the
9797
* guest VM. A monitor wait event will then be sent through JDWP, if there was a request for the
9898
* current thread.
99-
*
99+
*
100100
* @param monitor the monitor object
101101
* @param timeout the timeout in ms before the wait will time out
102102
*/

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
import com.oracle.truffle.espresso.jdwp.api.JDWPOptions;
6969
import com.oracle.truffle.espresso.jdwp.api.KlassRef;
7070
import com.oracle.truffle.espresso.jdwp.api.MethodRef;
71+
import com.oracle.truffle.espresso.jdwp.api.MethodVersionRef;
7172
import com.oracle.truffle.espresso.jdwp.api.VMEventListener;
7273

7374
public final class DebuggerController implements ContextsListener {
@@ -415,10 +416,10 @@ private void doStepOut(SuspendedInfo susp) {
415416
SteppingInfo steppingInfo = commandRequestIds.get(susp.getThread());
416417
if (steppingInfo != null && stepOutBCI != -1) {
417418
// record the location that we'll land on after the step out completes
418-
MethodRef method = context.getMethodFromRootNode(callerRoot);
419+
MethodVersionRef method = context.getMethodFromRootNode(callerRoot);
419420
if (method != null) {
420-
KlassRef klass = method.getDeclaringKlassRef();
421-
steppingInfo.setStepOutBCI(context.getIds().getIdAsLong(klass), context.getIds().getIdAsLong(method), stepOutBCI);
421+
KlassRef klass = method.getMethod().getDeclaringKlassRef();
422+
steppingInfo.setStepOutBCI(context.getIds().getIdAsLong(klass), context.getIds().getIdAsLong(method.getMethod()), stepOutBCI);
422423
}
423424
}
424425
}
@@ -869,16 +870,17 @@ public CallFrame[] getCallFrames(Object guestThread) {
869870
List<CallFrame> callFrames = new ArrayList<>();
870871
Truffle.getRuntime().iterateFrames(frameInstance -> {
871872
KlassRef klass;
872-
MethodRef method;
873+
MethodVersionRef methodVersion;
873874
RootNode root = getRootNode(frameInstance);
874875
if (root == null) {
875876
return null;
876877
}
877-
method = getContext().getMethodFromRootNode(root);
878-
if (method == null) {
878+
methodVersion = getContext().getMethodFromRootNode(root);
879+
if (methodVersion == null) {
879880
return null;
880881
}
881882

883+
MethodRef method = methodVersion.getMethod();
882884
klass = method.getDeclaringKlassRef();
883885
long klassId = ids.getIdAsLong(klass);
884886
long methodId = ids.getIdAsLong(method);
@@ -914,7 +916,7 @@ public CallFrame[] getCallFrames(Object guestThread) {
914916
if (currentNode instanceof RootNode) {
915917
currentNode = context.getInstrumentableNode((RootNode) currentNode);
916918
}
917-
callFrames.add(new CallFrame(context.getIds().getIdAsLong(guestThread), typeTag, klassId, method, methodId, codeIndex, frame, currentNode, root, null, context, jdwpLogger));
919+
callFrames.add(new CallFrame(context.getIds().getIdAsLong(guestThread), typeTag, klassId, methodVersion, methodId, codeIndex, frame, currentNode, root, null, context, jdwpLogger));
918920
return null;
919921
});
920922
return callFrames.toArray(new CallFrame[0]);
@@ -1227,11 +1229,11 @@ private CallFrame[] createCallFrames(long threadId, Iterable<DebugStackFrame> st
12271229
}
12281230

12291231
Frame rawFrame = frame.getRawFrame(context.getLanguageClass(), FrameInstance.FrameAccess.READ_WRITE);
1230-
MethodRef method = context.getMethodFromRootNode(root);
1231-
KlassRef klass = method.getDeclaringKlassRef();
1232+
MethodVersionRef methodVersion = context.getMethodFromRootNode(root);
1233+
KlassRef klass = methodVersion.getMethod().getDeclaringKlassRef();
12321234

12331235
klassId = ids.getIdAsLong(klass);
1234-
methodId = ids.getIdAsLong(method);
1236+
methodId = ids.getIdAsLong(methodVersion.getMethod());
12351237
typeTag = TypeTag.getKind(klass);
12361238

12371239
// check if we have a dedicated step out code index on the top frame
@@ -1241,7 +1243,7 @@ private CallFrame[] createCallFrames(long threadId, Iterable<DebugStackFrame> st
12411243
codeIndex = context.getBCI(rawNode, rawFrame);
12421244
}
12431245

1244-
list.addLast(new CallFrame(threadId, typeTag, klassId, method, methodId, codeIndex, rawFrame, rawNode, root, frame, context, jdwpLogger));
1246+
list.addLast(new CallFrame(threadId, typeTag, klassId, methodVersion, methodId, codeIndex, rawFrame, rawNode, root, frame, context, jdwpLogger));
12451247
frameCount++;
12461248
if (frameLimit != -1 && frameCount >= frameLimit) {
12471249
return list.toArray(new CallFrame[0]);

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -1518,7 +1518,8 @@ static CommandResult createReply(Packet packet, JDWPContext context) {
15181518
if (method == null) {
15191519
return new CommandResult(reply);
15201520
}
1521-
reply.writeBoolean(method.isObsolete());
1521+
// only condition to check here is if removed by redefinition
1522+
reply.writeBoolean(method.isRemovedByRedefinition());
15221523
}
15231524
return new CommandResult(reply);
15241525
}
@@ -2154,7 +2155,7 @@ static CommandResult createReply(Packet packet, DebuggerController controller) {
21542155
reply.writeLong(controller.getContext().getIds().getIdAsLong(frame));
21552156
reply.writeByte(frame.getTypeTag());
21562157
reply.writeLong(frame.getClassId());
2157-
reply.writeLong(frame.getMethod().isObsolete() ? 0 : controller.getContext().getIds().getIdAsLong(frame.getMethod()));
2158+
reply.writeLong(frame.getMethodVersion().isObsolete() ? 0 : controller.getContext().getIds().getIdAsLong(frame.getMethod()));
21582159
reply.writeLong(frame.getCodeIndex());
21592160
}
21602161
return new CommandResult(reply);

0 commit comments

Comments
 (0)