changeset 7373:6b2c55fc9ba8

reworked mechanism for omitting intrinsics if the underlying hardware support is not available and used it to make intrinsification of Integer.bitCount() dependent on whether the POPCNT instruction is available
author Doug Simon <doug.simon@oracle.com>
date Mon, 14 Jan 2013 18:41:26 +0100
parents 6d65e368bb81
children deac35fb97a2
files graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotSnippetInstaller.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotVMConfig.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/SnippetInstaller.java src/share/vm/graal/graalCompilerToVM.cpp
diffstat 6 files changed, 83 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotSnippetInstaller.java	Mon Jan 14 18:41:26 2013 +0100
@@ -0,0 +1,61 @@
+/*
+ * 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 java.lang.reflect.*;
+
+import com.oracle.graal.api.code.*;
+import com.oracle.graal.hotspot.meta.*;
+import com.oracle.graal.hotspot.snippets.*;
+import com.oracle.graal.snippets.*;
+
+/**
+ * Filters certain intrinsifications based on whether there is underlying hardware support for them.
+ */
+public class HotSpotSnippetInstaller extends SnippetInstaller {
+
+    private final HotSpotVMConfig config;
+
+    public HotSpotSnippetInstaller(HotSpotRuntime runtime, Assumptions assumptions, TargetDescription target) {
+        super(runtime, assumptions, target);
+        this.config = runtime.config;
+    }
+
+    @Override
+    protected void installSubstitution(Method originalMethod, Method substituteMethod) {
+        if (substituteMethod.getDeclaringClass() == IntegerSubstitutions.class) {
+            if (substituteMethod.getName().equals("bitCount")) {
+                if (!config.usePopCountInstruction) {
+                    return;
+                }
+            }
+        } else if (substituteMethod.getDeclaringClass() == AESCryptSubstitutions.class) {
+            if (!config.useAESIntrinsics) {
+                return;
+            }
+            assert config.aescryptEncryptBlockStub != 0L;
+            assert config.aescryptDecryptBlockStub != 0L;
+        }
+        super.installSubstitution(originalMethod, substituteMethod);
+    }
+}
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotVMConfig.java	Mon Jan 14 16:56:54 2013 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotVMConfig.java	Mon Jan 14 18:41:26 2013 +0100
@@ -40,6 +40,8 @@
     public boolean useFastLocking;
     public boolean useTLAB;
     public boolean useBiasedLocking;
+    public boolean usePopCountInstruction;
+    public boolean useAESIntrinsics;
 
     // offsets, ...
     public int vmPageSize;
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java	Mon Jan 14 16:56:54 2013 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java	Mon Jan 14 18:41:26 2013 +0100
@@ -142,7 +142,7 @@
                     // Snippets cannot have speculative optimizations since they have to be valid for the entire run of the VM.
                     Assumptions assumptions = new Assumptions(false);
                     VMToCompilerImpl.this.intrinsifyArrayCopy = new IntrinsifyArrayCopyPhase(runtime, assumptions);
-                    SnippetInstaller installer = new SnippetInstaller(runtime, assumptions, runtime.getGraalRuntime().getTarget());
+                    SnippetInstaller installer = new HotSpotSnippetInstaller(runtime, assumptions, runtime.getGraalRuntime().getTarget());
                     GraalIntrinsics.installIntrinsics(installer);
                     runtime.installSnippets(installer, assumptions);
                 }
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java	Mon Jan 14 16:56:54 2013 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java	Mon Jan 14 18:41:26 2013 +0100
@@ -323,12 +323,7 @@
             installer.installSubstitutions(ClassSubstitutions.class);
         }
         if (GraalOptions.IntrinsifyAESCryptMethods) {
-            if (graalRuntime.getConfig().aescryptEncryptBlockStub != 0L) {
-                installer.installSubstitutions(AESCryptSubstitutions.class);
-            } else {
-                // AES not supported on this CPU
-                assert graalRuntime.getConfig().aescryptDecryptBlockStub == 0L;
-            }
+            installer.installSubstitutions(AESCryptSubstitutions.class);
         }
         if (GraalOptions.IntrinsifyArrayCopy) {
             installer.installSnippets(ArrayCopySnippets.class);
--- a/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/SnippetInstaller.java	Mon Jan 14 16:56:54 2013 +0100
+++ b/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/SnippetInstaller.java	Mon Jan 14 18:41:26 2013 +0100
@@ -117,16 +117,26 @@
 
             String originalName = originalName(substituteMethod, methodSubstitution);
             Class[] originalParameters = originalParameters(substituteMethod, methodSubstitution);
-            ResolvedJavaMethod substitute = runtime.lookupJavaMethod(substituteMethod);
             Method originalMethod = originalMethod(classSubstitution, originalName, originalParameters);
-            ResolvedJavaMethod substituted = runtime.lookupJavaMethod(originalMethod);
-            //System.out.println("substitution: " + MetaUtil.format("%H.%n(%p)", substituted) + " --> " + MetaUtil.format("%H.%n(%p)", substitute));
-            StructuredGraph graph = makeGraph(substitute, inliningPolicy(substitute), true);
-            Object oldValue = substituted.getCompilerStorage().put(Graph.class, graph);
-            assert oldValue == null;
+            installSubstitution(originalMethod, substituteMethod);
         }
     }
 
+    /**
+     * Installs a method substitution.
+     *
+     * @param originalMethod a method being substituted
+     * @param substituteMethod the substitute method
+     */
+    protected void installSubstitution(Method originalMethod, Method substituteMethod) {
+        ResolvedJavaMethod substitute = runtime.lookupJavaMethod(substituteMethod);
+        ResolvedJavaMethod original = runtime.lookupJavaMethod(originalMethod);
+        //System.out.println("substitution: " + MetaUtil.format("%H.%n(%p)", original) + " --> " + MetaUtil.format("%H.%n(%p)", substitute));
+        StructuredGraph graph = makeGraph(substitute, inliningPolicy(substitute), true);
+        Object oldValue = original.getCompilerStorage().put(Graph.class, graph);
+        assert oldValue == null;
+    }
+
     private SnippetInliningPolicy inliningPolicy(ResolvedJavaMethod method) {
         Class<? extends SnippetInliningPolicy> policyClass = SnippetInliningPolicy.class;
         Snippet snippet = method.getAnnotation(Snippet.class);
--- a/src/share/vm/graal/graalCompilerToVM.cpp	Mon Jan 14 16:56:54 2013 +0100
+++ b/src/share/vm/graal/graalCompilerToVM.cpp	Mon Jan 14 18:41:26 2013 +0100
@@ -609,6 +609,8 @@
   set_boolean("verifyOops", VerifyOops);
   set_boolean("useFastLocking", GraalUseFastLocking);
   set_boolean("useBiasedLocking", UseBiasedLocking);
+  set_boolean("usePopCountInstruction", UsePopCountInstruction);
+  set_boolean("useAESIntrinsics", UseAESIntrinsics);
   set_boolean("useTLAB", UseTLAB);
   set_int("codeEntryAlignment", CodeEntryAlignment);
   set_int("vmPageSize", os::vm_page_size());