changeset 11420:7c4c1a7c875a

made HotSpotGraalRuntime.instance final
author Doug Simon <doug.simon@oracle.com>
date Mon, 26 Aug 2013 17:10:45 +0200
parents 2fac92eb4559
children 966d4517bf58 51dcddfa25a6
files graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotGraalRuntime.java graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotGraalRuntime.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java
diffstat 3 files changed, 29 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotGraalRuntime.java	Thu Aug 22 14:45:40 2013 +0200
+++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotGraalRuntime.java	Mon Aug 26 17:10:45 2013 +0200
@@ -44,15 +44,17 @@
      * Called from C++ code to retrieve the singleton instance, creating it first if necessary.
      */
     public static HotSpotGraalRuntime makeInstance() {
-        if (graalRuntime() == null) {
+        HotSpotGraalRuntime graalRuntime = graalRuntime();
+        if (graalRuntime == null) {
             HotSpotGraalRuntimeFactory factory = findFactory("AMD64");
             if (factory != null) {
-                setInstance(factory.createRuntime());
+                graalRuntime = factory.createRuntime();
             } else {
-                setInstance(new AMD64HotSpotGraalRuntime());
+                graalRuntime = new AMD64HotSpotGraalRuntime();
             }
+            graalRuntime.completeInitialization();
         }
-        return graalRuntime();
+        return graalRuntime;
     }
 
     protected Architecture createArchitecture() {
--- a/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotGraalRuntime.java	Thu Aug 22 14:45:40 2013 +0200
+++ b/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotGraalRuntime.java	Mon Aug 26 17:10:45 2013 +0200
@@ -41,10 +41,12 @@
      * Called from C++ code to retrieve the singleton instance, creating it first if necessary.
      */
     public static HotSpotGraalRuntime makeInstance() {
-        if (graalRuntime() == null) {
-            setInstance(new SPARCHotSpotGraalRuntime());
+        HotSpotGraalRuntime graalRuntime = graalRuntime();
+        if (graalRuntime == null) {
+            graalRuntime = new SPARCHotSpotGraalRuntime();
+            graalRuntime.completeInitialization();
         }
-        return graalRuntime();
+        return graalRuntime;
     }
 
     protected static Architecture createArchitecture() {
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java	Thu Aug 22 14:45:40 2013 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java	Mon Aug 26 17:10:45 2013 +0200
@@ -23,6 +23,7 @@
 package com.oracle.graal.hotspot;
 
 import static com.oracle.graal.graph.UnsafeAccess.*;
+import static com.oracle.graal.hotspot.HotSpotGraalRuntime.Options.*;
 
 import java.lang.reflect.*;
 import java.util.*;
@@ -49,7 +50,7 @@
  */
 public abstract class HotSpotGraalRuntime implements GraalRuntime {
 
-    private static HotSpotGraalRuntime instance;
+    private static final HotSpotGraalRuntime instance = (HotSpotGraalRuntime) Graal.getRuntime();
 
     /**
      * Gets the singleton {@link HotSpotGraalRuntime} object.
@@ -59,22 +60,18 @@
     }
 
     /**
-     * Called by the platform specific class exactly once to register the singleton instance.
+     * Do deferred initialization.
      */
-    protected static void setInstance(HotSpotGraalRuntime runtime) {
-        assert instance == null : "runtime already registered";
-        instance = runtime;
-
-        // Do deferred initialization
+    public void completeInitialization() {
 
         // Proxies for the VM/Compiler interfaces cannot be initialized
         // in the constructor as proxy creation causes static
         // initializers to be executed for all the types involved in the
         // proxied methods. Some of these static initializers (e.g. in
-        // HotSpotMethodData) rely on the above instance field being set
-        // to retrieve config details.
-        VMToCompiler toCompiler = runtime.vmToCompiler;
-        CompilerToVM toVM = runtime.compilerToVm;
+        // HotSpotMethodData) rely on the static 'instance' field being set
+        // to retrieve configuration details.
+        VMToCompiler toCompiler = this.vmToCompiler;
+        CompilerToVM toVM = this.compilerToVm;
 
         if (CountingProxy.ENABLED) {
             toCompiler = CountingProxy.getProxy(VMToCompiler.class, toCompiler);
@@ -85,14 +82,18 @@
             toVM = LoggingProxy.getProxy(CompilerToVM.class, toVM);
         }
 
-        runtime.vmToCompiler = toCompiler;
-        runtime.compilerToVm = toVM;
+        this.vmToCompiler = toCompiler;
+        this.compilerToVm = toVM;
     }
 
-    // @formatter:off
-    @Option(help = "The runtime configuration to use")
-    private static final OptionValue<String> GraalRuntime = new OptionValue<>("");
-    // @formatter:on
+    // Options must not be directly declared in HotSpotGraalRuntime - see VerifyHotSpotOptionsPhase
+    static class Options {
+
+        // @formatter:off
+        @Option(help = "The runtime configuration to use")
+        static final OptionValue<String> GraalRuntime = new OptionValue<>("");
+        // @formatter:on
+    }
 
     protected static HotSpotGraalRuntimeFactory findFactory(String architecture) {
         HotSpotGraalRuntimeFactory basic = null;