aboutsummaryrefslogtreecommitdiff
path: root/src/java.base/share/classes/java/lang/System.java
diff options
context:
space:
mode:
authorClaes Redestad <redestad@openjdk.org>2020-05-15 12:25:37 +0200
committerClaes Redestad <redestad@openjdk.org>2020-05-15 12:25:37 +0200
commit82f2a0e2e4f45335badf0df4edb51523e2729fba (patch)
treecaf67d3ed51121e3c12374cacc75edb5a762afa2 /src/java.base/share/classes/java/lang/System.java
parentb76a215ff6088d59012bda82fa26a6c0ce8a8463 (diff)
downloadopenjdk-82f2a0e2e4f45335badf0df4edb51523e2729fba.tar.gz
openjdk-82f2a0e2e4f45335badf0df4edb51523e2729fba.zip
8245024: Simplify and eagerly initialize StringConcatFactory
Reviewed-by: psandoz
Diffstat (limited to 'src/java.base/share/classes/java/lang/System.java')
-rw-r--r--src/java.base/share/classes/java/lang/System.java17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/java.base/share/classes/java/lang/System.java b/src/java.base/share/classes/java/lang/System.java
index 630e9a2dbd5..7fc959ae1be 100644
--- a/src/java.base/share/classes/java/lang/System.java
+++ b/src/java.base/share/classes/java/lang/System.java
@@ -37,6 +37,7 @@ import java.io.UnsupportedEncodingException;
import java.lang.annotation.Annotation;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodType;
+import java.lang.invoke.StringConcatFactory;
import java.lang.module.ModuleDescriptor;
import java.lang.reflect.Constructor;
import java.lang.reflect.Executable;
@@ -62,6 +63,7 @@ import java.util.function.Supplier;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Stream;
+import jdk.internal.misc.Unsafe;
import jdk.internal.util.StaticProperty;
import jdk.internal.module.ModuleBootstrap;
import jdk.internal.module.ServicesCatalog;
@@ -2049,6 +2051,7 @@ public final class System {
* @return JNI_OK for success, JNI_ERR for failure
*/
private static int initPhase2(boolean printToStderr, boolean printStackTrace) {
+
try {
bootLayer = ModuleBootstrap.boot();
} catch (Exception | Error e) {
@@ -2065,15 +2068,23 @@ public final class System {
/*
* Invoked by VM. Phase 3 is the final system initialization:
- * 1. set security manager
- * 2. set system class loader
- * 3. set TCCL
+ * 1. eagerly initialize bootstrap method factories that might interact
+ * negatively with custom security managers and custom class loaders
+ * 2. set security manager
+ * 3. set system class loader
+ * 4. set TCCL
*
* This method must be called after the module system initialization.
* The security manager and system class loader may be a custom class from
* the application classpath or modulepath.
*/
private static void initPhase3() {
+
+ // Initialize the StringConcatFactory eagerly to avoid potential
+ // bootstrap circularity issues that could be caused by a custom
+ // SecurityManager
+ Unsafe.getUnsafe().ensureClassInitialized(StringConcatFactory.class);
+
String smProp = System.getProperty("java.security.manager");
if (smProp != null) {
switch (smProp) {