From e99c267d0e903c7598f4c68c4afa09a6107d8a4a Mon Sep 17 00:00:00 2001 From: Jason Feng Date: Sun, 21 Apr 2019 13:53:07 -0400 Subject: [PATCH 1/2] Init system property java.vm.specification.version via native There is a need to retrieve the system property java.vm.specification.version via JVMTI API in an early phase before Java code java.lang.VersionProps.init(systemProperties) running. Removed the Java code (Java 12+) setting the property; Get the property value via JAVA_SPEC_VERSION and set it within vmprops.c:initializeSystemProperties(); Refactoring to do runtime check on JAVA_SPEC_VERSION instead of j2seVersion. Signed-off-by: Jason Feng --- .../share/classes/java/lang/System.java | 2 - runtime/include/vendor_version.h | 5 +- runtime/vm/vmprops.c | 52 +++++++++---------- 3 files changed, 26 insertions(+), 33 deletions(-) diff --git a/jcl/src/java.base/share/classes/java/lang/System.java b/jcl/src/java.base/share/classes/java/lang/System.java index 0819ccbe8b4..98811bdac02 100644 --- a/jcl/src/java.base/share/classes/java/lang/System.java +++ b/jcl/src/java.base/share/classes/java/lang/System.java @@ -398,8 +398,6 @@ private static void ensureProperties(boolean isInitialization) { /*[IF Java12]*/ java.lang.VersionProps.init(initializedProperties); - /* VersionProps.init(systemProperties) above sets java.specification.version value which is used to set java.vm.specification.version. */ - initializedProperties.put("java.vm.specification.version", initializedProperties.get("java.specification.version")); //$NON-NLS-1$ //$NON-NLS-2$ /*[ELSE] /* VersionProps.init requires systemProperties to be set */ systemProperties = initializedProperties; diff --git a/runtime/include/vendor_version.h b/runtime/include/vendor_version.h index 25cb374a18c..0d8f908d173 100644 --- a/runtime/include/vendor_version.h +++ b/runtime/include/vendor_version.h @@ -49,8 +49,8 @@ #define VENDOR_SHORT_NAME "OpenJ9" #define JAVA_VM_VENDOR "Eclipse OpenJ9" +#define JAVA_VM_NAME "Eclipse OpenJ9 VM" -#if JAVA_SPEC_VERSION < 12 /* Pre-JDK12 versions use following defines to set system properties * java.vendor and java.vendor.url within vmprop.c:initializeSystemProperties(vm). * JDK12 (assuming future versions as well) sets these properties via java.lang.VersionProps.init(systemProperties) @@ -58,8 +58,5 @@ */ #define JAVA_VENDOR "Eclipse OpenJ9" #define JAVA_VENDOR_URL "http://www.eclipse.org/openj9" -#endif /* JAVA_SPEC_VERSION < 12 */ - -#define JAVA_VM_NAME "Eclipse OpenJ9 VM" #endif /* vendor_version_h */ diff --git a/runtime/vm/vmprops.c b/runtime/vm/vmprops.c index a8d9d1f2e5b..889d2168801 100644 --- a/runtime/vm/vmprops.c +++ b/runtime/vm/vmprops.c @@ -539,6 +539,7 @@ initializeSystemProperties(J9JavaVM * vm) UDATA j2seVersion = J2SE_VERSION(vm); const char* propValue = NULL; UDATA rc = J9SYSPROP_ERROR_NONE; + const char *specificationVersion = NULL; if (omrthread_monitor_init(&(vm->systemPropertiesMutex), 0) != 0) { return J9SYSPROP_ERROR_OUT_OF_MEMORY; @@ -572,35 +573,34 @@ initializeSystemProperties(J9JavaVM * vm) } } -#if JAVA_SPEC_VERSION < 12 - /* Following system properties are defined via java.lang.VersionProps.init(systemProperties) and following settings within System.ensureProperties() */ - { - const char *classVersion = NULL; - const char *specificationVersion = NULL; - - /* Properties that always exist */ - switch (j2seVersion) { - case J2SE_18: - classVersion = "52.0"; - specificationVersion = "1.8"; - break; - case J2SE_V11: - default: - classVersion = "55.0"; - specificationVersion = "11"; - break; - } - rc = addSystemProperty(vm, "java.class.version", classVersion, 0); - if (J9SYSPROP_ERROR_NONE != rc) { - goto fail; - } - + if (JAVA_SPEC_VERSION == 8) { + specificationVersion = "1.8"; + } else { +#define J9_STR_(x) #x +#define J9_STR(x) J9_STR_(x) + specificationVersion = J9_STR(JAVA_SPEC_VERSION); + } + if (JAVA_SPEC_VERSION < 12) { + /* System property "java.specification.version" is defined via java.lang.VersionProps.init(systemProperties) within System.ensureProperties() */ rc = addSystemProperty(vm, "java.specification.version", specificationVersion, 0); if (J9SYSPROP_ERROR_NONE != rc) { goto fail; } - - rc = addSystemProperty(vm, "java.vm.specification.version", specificationVersion, 0); + } + rc = addSystemProperty(vm, "java.vm.specification.version", specificationVersion, 0); + if (J9SYSPROP_ERROR_NONE != rc) { + goto fail; + } + + if (JAVA_SPEC_VERSION < 12) { + /* Following system properties are defined via java.lang.VersionProps.init(systemProperties) within System.ensureProperties() */ + const char *classVersion = NULL; + if (JAVA_SPEC_VERSION == 8) { + classVersion = "52.0"; + } else { + classVersion = "55.0"; /* Java 11 */ + } + rc = addSystemProperty(vm, "java.class.version", classVersion, 0); if (J9SYSPROP_ERROR_NONE != rc) { goto fail; } @@ -614,9 +614,7 @@ initializeSystemProperties(J9JavaVM * vm) if (J9SYSPROP_ERROR_NONE != rc) { goto fail; } - } -#endif /* JAVA_SPEC_VERSION < 12 */ rc = addSystemProperty(vm, "java.vm.vendor", JAVA_VM_VENDOR, 0); if (J9SYSPROP_ERROR_NONE != rc) { From 93e408692f0e0ae785bad7baa81873b317ec4aa2 Mon Sep 17 00:00:00 2001 From: Dan Heidinga Date: Wed, 24 Apr 2019 00:19:55 -0400 Subject: [PATCH 2/2] Use compile time checks rather than runtime checks Modify the JAVA_SPEC_VERSION checks so they can be done at compile time and are grouped together in a single block Signed-off-by: Dan Heidinga --- runtime/include/vendor_version.h | 2 ++ runtime/vm/vmprops.c | 41 ++++++++++++++++++-------------- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/runtime/include/vendor_version.h b/runtime/include/vendor_version.h index 0d8f908d173..25655ee38e6 100644 --- a/runtime/include/vendor_version.h +++ b/runtime/include/vendor_version.h @@ -51,6 +51,7 @@ #define JAVA_VM_VENDOR "Eclipse OpenJ9" #define JAVA_VM_NAME "Eclipse OpenJ9 VM" +#if JAVA_SPEC_VERSION < 12 /* Pre-JDK12 versions use following defines to set system properties * java.vendor and java.vendor.url within vmprop.c:initializeSystemProperties(vm). * JDK12 (assuming future versions as well) sets these properties via java.lang.VersionProps.init(systemProperties) @@ -58,5 +59,6 @@ */ #define JAVA_VENDOR "Eclipse OpenJ9" #define JAVA_VENDOR_URL "http://www.eclipse.org/openj9" +#endif /* JAVA_SPEC_VERSION < 12 */ #endif /* vendor_version_h */ diff --git a/runtime/vm/vmprops.c b/runtime/vm/vmprops.c index 889d2168801..a6ad44be584 100644 --- a/runtime/vm/vmprops.c +++ b/runtime/vm/vmprops.c @@ -580,20 +580,24 @@ initializeSystemProperties(J9JavaVM * vm) #define J9_STR(x) J9_STR_(x) specificationVersion = J9_STR(JAVA_SPEC_VERSION); } - if (JAVA_SPEC_VERSION < 12) { - /* System property "java.specification.version" is defined via java.lang.VersionProps.init(systemProperties) within System.ensureProperties() */ - rc = addSystemProperty(vm, "java.specification.version", specificationVersion, 0); - if (J9SYSPROP_ERROR_NONE != rc) { - goto fail; - } - } + + /* Some properties (*.vm.*) are owned by the VM and need to be set early for all + * versions so they are available to jvmti agents. + * Other java.* properties are owned by the class libraries and setting them can be + * delayed until VersionProps.init() runs. + */ rc = addSystemProperty(vm, "java.vm.specification.version", specificationVersion, 0); if (J9SYSPROP_ERROR_NONE != rc) { goto fail; } - - if (JAVA_SPEC_VERSION < 12) { - /* Following system properties are defined via java.lang.VersionProps.init(systemProperties) within System.ensureProperties() */ + +#if JAVA_SPEC_VERSION < 12 + /* For Java 12, the following properties are defined via java.lang.VersionProps.init(systemProperties) within System.ensureProperties() */ + rc = addSystemProperty(vm, "java.specification.version", specificationVersion, 0); + if (J9SYSPROP_ERROR_NONE != rc) { + goto fail; + } + { const char *classVersion = NULL; if (JAVA_SPEC_VERSION == 8) { classVersion = "52.0"; @@ -604,17 +608,18 @@ initializeSystemProperties(J9JavaVM * vm) if (J9SYSPROP_ERROR_NONE != rc) { goto fail; } + } - rc = addSystemProperty(vm, "java.vendor", JAVA_VENDOR, 0); - if (J9SYSPROP_ERROR_NONE != rc) { - goto fail; - } + rc = addSystemProperty(vm, "java.vendor", JAVA_VENDOR, 0); + if (J9SYSPROP_ERROR_NONE != rc) { + goto fail; + } - rc = addSystemProperty(vm, "java.vendor.url", JAVA_VENDOR_URL, 0); - if (J9SYSPROP_ERROR_NONE != rc) { - goto fail; - } + rc = addSystemProperty(vm, "java.vendor.url", JAVA_VENDOR_URL, 0); + if (J9SYSPROP_ERROR_NONE != rc) { + goto fail; } +#endif /* JAVA_SPEC_VERSION < 12 */ rc = addSystemProperty(vm, "java.vm.vendor", JAVA_VM_VENDOR, 0); if (J9SYSPROP_ERROR_NONE != rc) {