changeset 22657:9203f93ffeb0

Fix race condition in lazy compiler initialization.
author Roland Schatz <roland.schatz@oracle.com>
date Mon, 05 Oct 2015 13:13:21 +0200
parents d634e615b00d
children 61bb5fa12458
files jvmci/jdk.internal.jvmci.hotspot/src/jdk/internal/jvmci/hotspot/HotSpotJVMCIRuntime.java
diffstat 1 files changed, 6 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/jvmci/jdk.internal.jvmci.hotspot/src/jdk/internal/jvmci/hotspot/HotSpotJVMCIRuntime.java	Fri Oct 02 16:49:50 2015 +0200
+++ b/jvmci/jdk.internal.jvmci.hotspot/src/jdk/internal/jvmci/hotspot/HotSpotJVMCIRuntime.java	Mon Oct 05 13:13:21 2015 +0200
@@ -123,7 +123,7 @@
     protected final HotSpotVMConfig config;
     private final JVMCIBackend hostBackend;
 
-    private Compiler compiler;
+    private volatile Compiler compiler;
     protected final JVMCIMetaAccessContext metaAccessContext;
 
     private final Map<Class<? extends Architecture>, JVMCIBackend> backends = new HashMap<>();
@@ -197,7 +197,11 @@
 
     public Compiler getCompiler() {
         if (compiler == null) {
-            compiler = HotSpotJVMCICompilerConfig.getCompilerFactory().createCompiler(this);
+            synchronized (this) {
+                if (compiler == null) {
+                    compiler = HotSpotJVMCICompilerConfig.getCompilerFactory().createCompiler(this);
+                }
+            }
         }
         return compiler;
     }