Skip to content

Commit 4d85c30

Browse files
Add option -XX:+PrintVMInfoAndExit.
1 parent eec397f commit 4d85c30

File tree

5 files changed

+25
-3
lines changed

5 files changed

+25
-3
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/JavaMainWrapper.java

+13-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import java.util.List;
3636
import java.util.function.BooleanSupplier;
3737

38-
import jdk.graal.compiler.word.Word;
3938
import org.graalvm.nativeimage.CurrentIsolate;
4039
import org.graalvm.nativeimage.ImageSingletons;
4140
import org.graalvm.nativeimage.Isolate;
@@ -80,6 +79,8 @@
8079
import com.oracle.svm.util.ClassUtil;
8180
import com.oracle.svm.util.ReflectionUtil;
8281

82+
import jdk.graal.compiler.word.Word;
83+
8384
@InternalVMMethod
8485
public class JavaMainWrapper {
8586
/*
@@ -218,6 +219,11 @@ private static int runCore0() {
218219
VMRuntime.initialize();
219220
}
220221

222+
if (SubstrateOptions.PrintVMInfoAndExit.getValue()) {
223+
printVmInfo();
224+
return 0;
225+
}
226+
221227
if (SubstrateOptions.DumpHeapAndExit.getValue()) {
222228
return VMInspectionOptions.dumpImageHeap() ? 0 : 1;
223229
}
@@ -438,6 +444,12 @@ public static String getCRuntimeArgument0() {
438444
return CTypeConversion.toJavaString(MAIN_ISOLATE_PARAMETERS.get().getArgv().read(0));
439445
}
440446

447+
private static void printVmInfo() {
448+
VM vm = ImageSingletons.lookup(VM.class);
449+
System.out.println(vm.formattedVmVersion);
450+
System.out.println(vm.formattedJdkVersion);
451+
}
452+
441453
private static final class EnterCreateIsolateWithCArgumentsPrologue implements CEntryPointOptions.Prologue {
442454
private static final CGlobalData<CCharPointer> errorMessage = CGlobalDataFactory.createCString(
443455
"Failed to create the main Isolate.");

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateDiagnostics.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ public void printDiagnostics(Log log, ErrorContext context, int maxDiagnosticLev
860860
log.string("Build time information:").indent(true);
861861

862862
VM vm = ImageSingletons.lookup(VM.class);
863-
log.string("Version: ").string(vm.vendorVersion).string(" (").string(vm.info).string("), JDK ").string(vm.version).newline();
863+
log.string("Version: ").string(vm.formattedVmVersion).string(", ").string(vm.formattedJdkVersion).newline();
864864

865865
Platform platform = ImageSingletons.lookup(Platform.class);
866866
log.string("Platform: ").string(platform.getOS()).string("/").string(platform.getArchitecture()).newline();

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java

+3
Original file line numberDiff line numberDiff line change
@@ -1172,6 +1172,9 @@ public Boolean getValue(OptionValues values) {
11721172
@Option(help = "Create a heap dump and exit.")//
11731173
public static final RuntimeOptionKey<Boolean> DumpHeapAndExit = new RuntimeOptionKey<>(false, Immutable);
11741174

1175+
@Option(help = "Print some VM information and exit.")//
1176+
public static final RuntimeOptionKey<Boolean> PrintVMInfoAndExit = new RuntimeOptionKey<>(false, Immutable);
1177+
11751178
@Option(help = "Enable Java Flight Recorder.")//
11761179
public static final RuntimeOptionKey<Boolean> FlightRecorder = new RuntimeOptionKey<>(false, Immutable);
11771180

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/VM.java

+7
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,20 @@ public final class VM {
3535
public final String vendorUrl;
3636
public final String vendorVersion;
3737

38+
/* Preformatted version strings based on the values above. */
39+
public final String formattedVmVersion;
40+
public final String formattedJdkVersion;
41+
3842
@Platforms(Platform.HOSTED_ONLY.class)
3943
public VM(String vmInfo) {
4044
info = vmInfo;
4145
version = getVersion();
4246
vendor = getVendor();
4347
vendorUrl = getVendorUrl();
4448
vendorVersion = getVendorVersion();
49+
50+
formattedVmVersion = vendorVersion + " (" + info + ")";
51+
formattedJdkVersion = "JDK " + version;
4552
}
4653

4754
@Platforms(Platform.HOSTED_ONLY.class)

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/dcmd/VMVersionDmd.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ public VMVersionDmd() {
4343
@BasedOnJDKFile("https://github.com/openjdk/jdk/blob/jdk-24+18/src/hotspot/share/services/diagnosticCommand.cpp#L234-L246")
4444
public String execute(DCmdArguments args) throws Throwable {
4545
VM vm = ImageSingletons.lookup(VM.class);
46-
return vm.vendorVersion + " (" + vm.info + ")" + System.lineSeparator() + "JDK " + vm.version;
46+
return vm.formattedVmVersion + System.lineSeparator() + vm.formattedJdkVersion;
4747
}
4848
}

0 commit comments

Comments
 (0)