Skip to content

Commit c09364f

Browse files
Return real guest version in JDWP VirtualMachine.Version
Also remove unused `VirtualMachine`/`VirtualMachineImpl`
1 parent d48dd97 commit c09364f

File tree

11 files changed

+63
-150
lines changed

11 files changed

+63
-150
lines changed

espresso-shared/src/com.oracle.truffle.espresso.classfile/src/com/oracle/truffle/espresso/classfile/JavaVersion.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,10 @@ public int classFileVersion() {
231231
return version + 44;
232232
}
233233

234+
public int featureVersion() {
235+
return version;
236+
}
237+
234238
@Override
235239
public int compareTo(JavaVersion o) {
236240
return Integer.compare(this.version, o.version);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
* JDWP. Each entity will be assigned a unique ID. Only weak references are kept for entities.
3939
*/
4040
public final class Ids<T> {
41+
public static final int ID_SIZE = 8;
42+
private static final Pattern ANON_INNER_CLASS_PATTERN = Pattern.compile(".*\\$\\d+.*");
4143

4244
private volatile long uniqueID = 1;
4345

@@ -53,8 +55,6 @@ public final class Ids<T> {
5355
*/
5456
private final T nullObject;
5557

56-
public static final Pattern ANON_INNER_CLASS_PATTERN = Pattern.compile(".*\\$\\d+.*");
57-
5858
private HashMap<String, Long> innerClassIDMap = new HashMap<>(16);
5959

6060
private List<Object> pinnedObjects = new ArrayList<>();

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,4 +506,8 @@ public interface JDWPContext {
506506
boolean isSteppingInProgress(Thread t);
507507

508508
void replaceController(DebuggerController newController);
509+
510+
int getJavaFeatureVersion();
511+
512+
String getSystemProperty(String name);
509513
}

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
@@ -236,7 +236,7 @@ private void processPacket(Packet packet) {
236236
case JDWP.VirtualMachine.ID: {
237237
switch (packet.cmd) {
238238
case JDWP.VirtualMachine.VERSION.ID:
239-
result = JDWP.VirtualMachine.VERSION.createReply(packet, controller.getVirtualMachine());
239+
result = JDWP.VirtualMachine.VERSION.createReply(packet, context);
240240
break;
241241
case JDWP.VirtualMachine.CLASSES_BY_SIGNATURE.ID:
242242
result = JDWP.VirtualMachine.CLASSES_BY_SIGNATURE.createReply(packet, controller, context);
@@ -254,7 +254,7 @@ private void processPacket(Packet packet) {
254254
result = JDWP.VirtualMachine.DISPOSE.createReply(packet, controller);
255255
break;
256256
case JDWP.VirtualMachine.IDSIZES.ID:
257-
result = JDWP.VirtualMachine.IDSIZES.createReply(packet, controller.getVirtualMachine());
257+
result = JDWP.VirtualMachine.IDSIZES.createReply(packet);
258258
break;
259259
case JDWP.VirtualMachine.SUSPEND.ID:
260260
result = JDWP.VirtualMachine.SUSPEND.createReply(packet, controller);

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ public final class DebuggerController implements ContextsListener {
9393
private JDWPOptions options;
9494
private DebuggerSession debuggerSession;
9595
private Ids<Object> ids;
96-
private final VirtualMachine vm;
9796
private Debugger debugger;
9897
private final GCPrevention gcPrevention;
9998
private final ThreadSuspension threadSuspension;
@@ -111,7 +110,6 @@ public final class DebuggerController implements ContextsListener {
111110
private volatile Throwable lateStartupError;
112111

113112
public DebuggerController(TruffleLogger logger) {
114-
this.vm = new VirtualMachineImpl();
115113
this.gcPrevention = new GCPrevention();
116114
this.threadSuspension = new ThreadSuspension();
117115
this.eventFilters = new EventFilters();
@@ -658,10 +656,6 @@ public void prepareMethodBreakpoint(MethodBreakpointEvent event) {
658656
methodBreakpointExpected.put(Thread.currentThread(), event);
659657
}
660658

661-
public VirtualMachine getVirtualMachine() {
662-
return vm;
663-
}
664-
665659
public GCPrevention getGCPrevention() {
666660
return gcPrevention;
667661
}

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

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import com.oracle.truffle.espresso.jdwp.api.ClassStatusConstants;
3737
import com.oracle.truffle.espresso.jdwp.api.ErrorCodes;
3838
import com.oracle.truffle.espresso.jdwp.api.FieldRef;
39+
import com.oracle.truffle.espresso.jdwp.api.Ids;
3940
import com.oracle.truffle.espresso.jdwp.api.JDWPConstantPool;
4041
import com.oracle.truffle.espresso.jdwp.api.JDWPContext;
4142
import com.oracle.truffle.espresso.jdwp.api.KlassRef;
@@ -65,13 +66,36 @@ static class VirtualMachine {
6566
static class VERSION {
6667
public static final int ID = 1;
6768

68-
static CommandResult createReply(Packet packet, com.oracle.truffle.espresso.jdwp.impl.VirtualMachine vm) {
69+
static CommandResult createReply(Packet packet, JDWPContext context) {
6970
PacketStream reply = new PacketStream().replyPacket().id(packet.id);
70-
reply.writeString(vm.getVmDescription());
71-
reply.writeInt(1);
72-
reply.writeInt(8);
73-
reply.writeString(vm.getVmVersion());
74-
reply.writeString(vm.getVmName());
71+
int majorVersion;
72+
int minorVersion;
73+
int featureVersion = context.getJavaFeatureVersion();
74+
if (featureVersion < 9) {
75+
majorVersion = 1;
76+
minorVersion = featureVersion;
77+
} else if (featureVersion < 11) {
78+
majorVersion = 9;
79+
minorVersion = 0;
80+
} else if (featureVersion < 13) {
81+
majorVersion = 11;
82+
minorVersion = 0;
83+
} else {
84+
majorVersion = featureVersion;
85+
minorVersion = 0;
86+
}
87+
String javaVersion = context.getSystemProperty("java.version");
88+
String vmName = context.getSystemProperty("java.vm.name");
89+
String vmInfo = context.getSystemProperty("java.vm.info");
90+
reply.writeString(String.format("""
91+
Java Debug Wire Protocol version %d.%d
92+
JVM Debug Interface version %d.%d
93+
JVM version %s (%s, %s)""", majorVersion, minorVersion, majorVersion, minorVersion,
94+
javaVersion, vmName, vmInfo));
95+
reply.writeInt(majorVersion);
96+
reply.writeInt(minorVersion);
97+
reply.writeString(javaVersion);
98+
reply.writeString(vmName);
7599
return new CommandResult(reply);
76100
}
77101
}
@@ -173,13 +197,13 @@ static CommandResult createReply(Packet packet, DebuggerController controller) {
173197
static class IDSIZES {
174198
public static final int ID = 7;
175199

176-
static CommandResult createReply(Packet packet, com.oracle.truffle.espresso.jdwp.impl.VirtualMachine vm) {
200+
static CommandResult createReply(Packet packet) {
177201
PacketStream reply = new PacketStream().replyPacket().id(packet.id);
178-
reply.writeInt(vm.getSizeOfFieldRef());
179-
reply.writeInt(vm.getSizeOfMethodRef());
180-
reply.writeInt(vm.getSizeofObjectRef());
181-
reply.writeInt(vm.getSizeOfClassRef());
182-
reply.writeInt(vm.getSizeOfFrameRef());
202+
reply.writeInt(Ids.ID_SIZE);
203+
reply.writeInt(Ids.ID_SIZE);
204+
reply.writeInt(Ids.ID_SIZE);
205+
reply.writeInt(Ids.ID_SIZE);
206+
reply.writeInt(Ids.ID_SIZE);
183207
return new CommandResult(reply);
184208
}
185209
}

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

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

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

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

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/descriptors/EspressoSymbols.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,6 +1378,7 @@ public static class Signatures {
13781378
Types.java_lang_Object);
13791379
public static final Symbol<Signature> UnknownKeyException_Object_Throwable = SYMBOLS.putSignature(Types.com_oracle_truffle_espresso_polyglot_UnknownKeyException,
13801380
Types.java_lang_Object, Types.java_lang_Throwable);
1381+
public static final Symbol<Signature> String_String = SYMBOLS.putSignature(Types.java_lang_String, Types.java_lang_String);
13811382

13821383
// JVMCI
13831384
public static final Symbol<Signature> EspressoJVMCIRuntime = SYMBOLS.putSignature(Types.com_oracle_truffle_espresso_jvmci_EspressoJVMCIRuntime);

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/meta/Meta.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,7 @@ public Meta(EspressoContext context) {
660660

661661
java_lang_System = knownKlass(Types.java_lang_System);
662662
java_lang_System_exit = java_lang_System.requireDeclaredMethod(Names.exit, Signatures._void_int);
663+
java_lang_System_getProperty = java_lang_System.requireDeclaredMethod(Names.getProperty, Signatures.String_String);
663664
java_lang_System_securityManager = diff() //
664665
.field(VERSION_21_OR_LOWER, Names.security, Types.java_lang_SecurityManager) //
665666
.notRequiredField(java_lang_System);
@@ -1784,6 +1785,7 @@ private DiffVersionLoadHelper diff() {
17841785
public final Method java_lang_System_initPhase1;
17851786
public final Method java_lang_System_initPhase2;
17861787
public final Method java_lang_System_initPhase3;
1788+
public final Method java_lang_System_getProperty;
17871789
public final Method java_lang_System_exit;
17881790
public final Field java_lang_System_securityManager;
17891791
public final Field java_lang_System_in;

0 commit comments

Comments
 (0)