changeset 12580:7876c59a7a2f

refactored all deferred initialization of backends into HotSpotBackend
author Doug Simon <doug.simon@oracle.com>
date Fri, 25 Oct 2013 01:24:19 +0200
parents 1d369998229a
children 8fde330c11cd
files graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotBackend.java graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotBackendFactory.java graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILCompilationResult.java graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotBackend.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotBackend.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotForeignCallLinkage.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotHostBackend.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java
diffstat 8 files changed, 99 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotBackend.java	Fri Oct 25 00:31:00 2013 +0200
+++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotBackend.java	Fri Oct 25 01:24:19 2013 +0200
@@ -55,7 +55,7 @@
 /**
  * HotSpot AMD64 specific backend.
  */
-public class AMD64HotSpotBackend extends HotSpotBackend {
+public class AMD64HotSpotBackend extends HotSpotHostBackend {
 
     private static final Unsafe unsafe = Unsafe.getUnsafe();
 
--- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotBackendFactory.java	Fri Oct 25 00:31:00 2013 +0200
+++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotBackendFactory.java	Fri Oct 25 01:24:19 2013 +0200
@@ -56,8 +56,8 @@
         HotSpotCodeCacheProvider codeCache = createCodeCache(runtime, target);
         HotSpotConstantReflectionProvider constantReflection = createConstantReflection(runtime);
         Value[] nativeABICallerSaveRegisters = createNativeABICallerSaveRegisters(runtime.getConfig(), codeCache.getRegisterConfig());
-        HotSpotForeignCallsProvider foreignCalls = createForeignCalls(runtime, metaAccess, codeCache, nativeABICallerSaveRegisters);
-        LoweringProvider lowerer = createLowerer(runtime, metaAccess, foreignCalls);
+        HotSpotHostForeignCallsProvider foreignCalls = createForeignCalls(runtime, metaAccess, codeCache, nativeABICallerSaveRegisters);
+        HotSpotHostLoweringProvider lowerer = createLowerer(runtime, metaAccess, foreignCalls);
         // Replacements cannot have speculative optimizations since they have
         // to be valid for the entire run of the VM.
         Assumptions assumptions = new Assumptions(false);
--- a/graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILCompilationResult.java	Fri Oct 25 00:31:00 2013 +0200
+++ b/graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILCompilationResult.java	Fri Oct 25 01:24:19 2013 +0200
@@ -85,6 +85,7 @@
         if (b == null) {
             // Fall back to a new instance
             b = new HSAILHotSpotBackendFactory().createBackend(runtime(), runtime().getHostBackend());
+            b.completeInitialization();
         }
         backend = b;
     }
--- a/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotBackend.java	Fri Oct 25 00:31:00 2013 +0200
+++ b/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotBackend.java	Fri Oct 25 01:24:19 2013 +0200
@@ -51,7 +51,7 @@
 /**
  * HotSpot SPARC specific backend.
  */
-public class SPARCHotSpotBackend extends HotSpotBackend {
+public class SPARCHotSpotBackend extends HotSpotHostBackend {
 
     private static final Unsafe unsafe = Unsafe.getUnsafe();
 
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotBackend.java	Fri Oct 25 00:31:00 2013 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotBackend.java	Fri Oct 25 01:24:19 2013 +0200
@@ -80,6 +80,13 @@
         return runtime;
     }
 
+    /**
+     * Performs any remaining initialization that was deferred until the {@linkplain #getRuntime()
+     * runtime} object was initialized and this backend was registered with it.
+     */
+    public void completeInitialization() {
+    }
+
     @Override
     public HotSpotProviders getProviders() {
         return (HotSpotProviders) super.getProviders();
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotForeignCallLinkage.java	Fri Oct 25 00:31:00 2013 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotForeignCallLinkage.java	Fri Oct 25 01:24:19 2013 +0200
@@ -139,17 +139,17 @@
         Class<?>[] argumentTypes = descriptor.getArgumentTypes();
         JavaType[] parameterTypes = new JavaType[argumentTypes.length];
         for (int i = 0; i < parameterTypes.length; ++i) {
-            parameterTypes[i] = asJavaType(argumentTypes[i], metaAccess);
+            parameterTypes[i] = asJavaType(argumentTypes[i], metaAccess, codeCache);
         }
         TargetDescription target = codeCache.getTarget();
-        JavaType returnType = asJavaType(descriptor.getResultType(), metaAccess);
+        JavaType returnType = asJavaType(descriptor.getResultType(), metaAccess, codeCache);
         RegisterConfig regConfig = codeCache.getRegisterConfig();
         return regConfig.getCallingConvention(ccType, returnType, parameterTypes, target, false);
     }
 
-    private static JavaType asJavaType(Class type, MetaAccessProvider metaAccess) {
+    private static JavaType asJavaType(Class type, MetaAccessProvider metaAccess, CodeCacheProvider codeCache) {
         if (WordBase.class.isAssignableFrom(type)) {
-            return metaAccess.lookupJavaType(getHostWordKind().toJavaClass());
+            return metaAccess.lookupJavaType(codeCache.getTarget().wordKind.toJavaClass());
         } else {
             return metaAccess.lookupJavaType(type);
         }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotHostBackend.java	Fri Oct 25 01:24:19 2013 +0200
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.oracle.graal.hotspot;
+
+import static com.oracle.graal.phases.GraalOptions.*;
+
+import java.util.*;
+
+import com.oracle.graal.api.meta.*;
+import com.oracle.graal.debug.*;
+import com.oracle.graal.hotspot.meta.*;
+import com.oracle.graal.nodes.spi.*;
+
+/**
+ * Common functionality of HotSpot host backends.
+ */
+public abstract class HotSpotHostBackend extends HotSpotBackend {
+
+    public HotSpotHostBackend(HotSpotGraalRuntime runtime, HotSpotProviders providers) {
+        super(runtime, providers);
+    }
+
+    @Override
+    public void completeInitialization() {
+        final HotSpotProviders providers = getProviders();
+        HotSpotVMConfig config = getRuntime().getConfig();
+        HotSpotHostForeignCallsProvider foreignCalls = (HotSpotHostForeignCallsProvider) providers.getForeignCalls();
+        final HotSpotHostLoweringProvider lowerer = (HotSpotHostLoweringProvider) providers.getLowerer();
+        foreignCalls.initialize(providers, config);
+        lowerer.initialize(providers, config);
+
+        // Install intrinsics.
+        if (Intrinsify.getValue()) {
+            Debug.scope("RegisterReplacements", new Object[]{new DebugDumpScope("RegisterReplacements")}, new Runnable() {
+
+                @Override
+                public void run() {
+
+                    Replacements replacements = providers.getReplacements();
+                    ServiceLoader<ReplacementsProvider> sl = ServiceLoader.loadInstalled(ReplacementsProvider.class);
+                    for (ReplacementsProvider replacementsProvider : sl) {
+                        replacementsProvider.registerReplacements(providers.getMetaAccess(), lowerer, replacements, providers.getCodeCache().getTarget());
+                    }
+                    if (BootstrapReplacements.getValue()) {
+                        for (ResolvedJavaMethod method : replacements.getAllReplacements()) {
+                            replacements.getMacroSubstitution(method);
+                            replacements.getMethodSubstitution(method);
+                        }
+                    }
+                }
+            });
+        }
+    }
+}
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java	Fri Oct 25 00:31:00 2013 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java	Fri Oct 25 01:24:19 2013 +0200
@@ -48,7 +48,6 @@
 import com.oracle.graal.hotspot.phases.*;
 import com.oracle.graal.java.*;
 import com.oracle.graal.nodes.*;
-import com.oracle.graal.nodes.spi.*;
 import com.oracle.graal.options.*;
 import com.oracle.graal.phases.*;
 import com.oracle.graal.phases.PhasePlan.PhasePosition;
@@ -180,42 +179,18 @@
             }
         }
 
-        final HotSpotProviders hostProviders = runtime.getHostProviders();
-        HotSpotHostForeignCallsProvider hostForeignCalls = (HotSpotHostForeignCallsProvider) hostProviders.getForeignCalls();
-        assert VerifyOptionsPhase.checkOptions(hostProviders.getMetaAccess(), hostForeignCalls);
-
-        // Initialize host ForeignCallsProvider
-        hostForeignCalls.initialize(hostProviders, config);
-
-        // Install intrinsics.
-        if (Intrinsify.getValue()) {
-            Debug.scope("RegisterReplacements", new Object[]{new DebugDumpScope("RegisterReplacements")}, new Runnable() {
-
-                @Override
-                public void run() {
+        HotSpotBackend hostBackend = runtime.getHostBackend();
+        final HotSpotProviders hostProviders = hostBackend.getProviders();
+        assert VerifyOptionsPhase.checkOptions(hostProviders.getMetaAccess(), hostProviders.getForeignCalls());
 
-                    HotSpotMetaAccessProvider hostMetaAccess = hostProviders.getMetaAccess();
-                    Replacements hostReplacements = hostProviders.getReplacements();
-                    LoweringProvider hostLowerer = hostProviders.getLowerer();
-                    ServiceLoader<ReplacementsProvider> sl = ServiceLoader.loadInstalled(ReplacementsProvider.class);
-                    TargetDescription hostTarget = hostProviders.getCodeCache().getTarget();
-                    for (ReplacementsProvider replacementsProvider : sl) {
-                        replacementsProvider.registerReplacements(hostMetaAccess, hostLowerer, hostReplacements, hostTarget);
-                    }
-                    if (BootstrapReplacements.getValue()) {
-                        for (ResolvedJavaMethod method : hostReplacements.getAllReplacements()) {
-                            hostReplacements.getMacroSubstitution(method);
-                            hostReplacements.getMethodSubstitution(method);
-                        }
-                    }
-                }
-            });
+        // Complete initialization of backends
+        hostBackend.completeInitialization();
+        for (HotSpotBackend backend : runtime.getBackends().values()) {
+            if (backend != hostBackend) {
+                backend.completeInitialization();
+            }
         }
 
-        // Initialize host LoweringProvider
-        HotSpotHostLoweringProvider hostLowerer = (HotSpotHostLoweringProvider) hostProviders.getLowerer();
-        hostLowerer.initialize(hostProviders, config);
-
         // Create compilation queue.
         compileQueue = new ThreadPoolExecutor(Threads.getValue(), Threads.getValue(), 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(), CompilerThread.FACTORY);