changeset 7355:8c163cfda1e5

only @MethodSubstitution annotated methods are now considered to be method substitutions which allows for helper methods to be in the same class
author Doug Simon <doug.simon@oracle.com>
date Fri, 11 Jan 2013 18:26:32 +0100
parents 867ec7c2a9ca
children fe9f252f0d05
files graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/SystemSnippets.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/ThreadSnippets.java graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/DoubleSnippets.java graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/FloatSnippets.java graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/IntegerSnippets.java graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/LongSnippets.java graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/MathSnippetsX86.java graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/NodeClassSnippets.java graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/SnippetInstaller.java graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/UnsignedMathSnippets.java
diffstat 10 files changed, 60 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/SystemSnippets.java	Fri Jan 11 17:50:13 2013 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/SystemSnippets.java	Fri Jan 11 18:26:32 2013 +0100
@@ -30,6 +30,7 @@
 import com.oracle.graal.hotspot.nodes.*;
 import com.oracle.graal.nodes.extended.*;
 import com.oracle.graal.snippets.*;
+import com.oracle.graal.snippets.ClassSubstitution.*;
 import com.oracle.graal.word.*;
 
 /**
@@ -41,14 +42,17 @@
     public static final Descriptor JAVA_TIME_MILLIS = new Descriptor("javaTimeMillis", false, long.class);
     public static final Descriptor JAVA_TIME_NANOS = new Descriptor("javaTimeNanos", false, long.class);
 
+    @MethodSubstitution
     public static long currentTimeMillis() {
         return callLong(JAVA_TIME_MILLIS);
     }
 
+    @MethodSubstitution
     public static long nanoTime() {
         return callLong(JAVA_TIME_NANOS);
     }
 
+    @MethodSubstitution
     public static int identityHashCode(Object x) {
         if (x == null) {
             return 0;
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/ThreadSnippets.java	Fri Jan 11 17:50:13 2013 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/ThreadSnippets.java	Fri Jan 11 18:26:32 2013 +0100
@@ -32,9 +32,10 @@
 /**
  * Snippets for {@link java.lang.Thread} methods.
  */
-@SuppressWarnings("unused")
 @ClassSubstitution(java.lang.Thread.class)
 public class ThreadSnippets implements SnippetsInterface {
+
+    @MethodSubstitution
     public static Thread currentThread() {
         return CurrentThread.get();
     }
--- a/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/DoubleSnippets.java	Fri Jan 11 17:50:13 2013 +0100
+++ b/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/DoubleSnippets.java	Fri Jan 11 18:26:32 2013 +0100
@@ -23,6 +23,7 @@
 package com.oracle.graal.snippets;
 
 import com.oracle.graal.nodes.calc.*;
+import com.oracle.graal.snippets.ClassSubstitution.*;
 
 /**
  * Snippets for {@link java.lang.Double} methods.
@@ -32,6 +33,7 @@
 
     private static final long NAN_RAW_LONG_BITS = Double.doubleToRawLongBits(Double.NaN);
 
+    @MethodSubstitution
     public static long doubleToRawLongBits(double value) {
         @JavacBug(id = 6995200)
         Long result = ConvertNode.convert(ConvertNode.Op.MOV_D2L, value);
@@ -39,6 +41,7 @@
     }
 
     // TODO This method is not necessary, since the JDK method does exactly this
+    @MethodSubstitution
     public static long doubleToLongBits(double value) {
         if (value != value) {
             return NAN_RAW_LONG_BITS;
@@ -47,6 +50,7 @@
         }
     }
 
+    @MethodSubstitution
     public static double longBitsToDouble(long bits) {
         @JavacBug(id = 6995200)
         Double result = ConvertNode.convert(ConvertNode.Op.MOV_L2D, bits);
--- a/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/FloatSnippets.java	Fri Jan 11 17:50:13 2013 +0100
+++ b/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/FloatSnippets.java	Fri Jan 11 18:26:32 2013 +0100
@@ -23,6 +23,7 @@
 package com.oracle.graal.snippets;
 
 import com.oracle.graal.nodes.calc.*;
+import com.oracle.graal.snippets.ClassSubstitution.*;
 
 /**
  * Snippets for {@link java.lang.Float} methods.
@@ -32,6 +33,7 @@
 
     private static final int NAN_RAW_INT_BITS = Float.floatToRawIntBits(Float.NaN);
 
+    @MethodSubstitution
     public static int floatToRawIntBits(float value) {
         @JavacBug(id = 6995200)
         Integer result = ConvertNode.convert(ConvertNode.Op.MOV_F2I, value);
@@ -39,6 +41,7 @@
     }
 
     // TODO This method is not necessary, since the JDK method does exactly this
+    @MethodSubstitution
     public static int floatToIntBits(float value) {
         if (value != value) {
             return NAN_RAW_INT_BITS;
@@ -47,6 +50,7 @@
         }
     }
 
+    @MethodSubstitution
     public static float intBitsToFloat(int bits) {
         @JavacBug(id = 6995200)
         Float result = ConvertNode.convert(ConvertNode.Op.MOV_I2F, bits);
--- a/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/IntegerSnippets.java	Fri Jan 11 17:50:13 2013 +0100
+++ b/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/IntegerSnippets.java	Fri Jan 11 18:26:32 2013 +0100
@@ -22,15 +22,18 @@
  */
 package com.oracle.graal.snippets;
 
+import com.oracle.graal.snippets.ClassSubstitution.*;
 import com.oracle.graal.snippets.nodes.*;
 
 @ClassSubstitution(Integer.class)
 public class IntegerSnippets implements SnippetsInterface{
 
+    @MethodSubstitution
     public static int reverseBytes(int i) {
         return ReverseBytesNode.reverse(i);
     }
 
+    @MethodSubstitution
     public static int numberOfLeadingZeros(int i) {
         if (i == 0) {
             return 32;
@@ -38,6 +41,7 @@
         return 31 - BitScanReverseNode.scan(i);
     }
 
+    @MethodSubstitution
     public static int numberOfTrailingZeros(int i) {
         if (i == 0) {
             return 32;
@@ -45,6 +49,7 @@
         return BitScanForwardNode.scan(i);
     }
 
+    @MethodSubstitution
     public static int bitCount(int i) {
         return BitCountNode.bitCount(i);
     }
--- a/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/LongSnippets.java	Fri Jan 11 17:50:13 2013 +0100
+++ b/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/LongSnippets.java	Fri Jan 11 18:26:32 2013 +0100
@@ -22,15 +22,18 @@
  */
 package com.oracle.graal.snippets;
 
+import com.oracle.graal.snippets.ClassSubstitution.*;
 import com.oracle.graal.snippets.nodes.*;
 
 @ClassSubstitution(Long.class)
 public class LongSnippets implements SnippetsInterface{
 
+    @MethodSubstitution
     public static long reverseBytes(long i) {
         return ReverseBytesNode.reverse(i);
     }
 
+    @MethodSubstitution
     public static int numberOfLeadingZeros(long i) {
         if (i == 0) {
             return 64;
@@ -38,6 +41,7 @@
         return 63 - BitScanReverseNode.scan(i);
     }
 
+    @MethodSubstitution
     public static int numberOfTrailingZeros(long i) {
         if (i == 0) {
             return 64;
@@ -45,6 +49,7 @@
         return BitScanForwardNode.scan(i);
     }
 
+    @MethodSubstitution
     public static int bitCount(long i) {
         return BitCountNode.bitCount(i);
     }
--- a/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/MathSnippetsX86.java	Fri Jan 11 17:50:13 2013 +0100
+++ b/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/MathSnippetsX86.java	Fri Jan 11 18:26:32 2013 +0100
@@ -26,6 +26,7 @@
 import com.oracle.graal.graph.Node.ConstantNodeParameter;
 import com.oracle.graal.graph.Node.NodeIntrinsic;
 import com.oracle.graal.nodes.extended.*;
+import com.oracle.graal.snippets.ClassSubstitution.MethodSubstitution;
 import com.oracle.graal.snippets.nodes.*;
 import com.oracle.graal.snippets.nodes.MathIntrinsicNode.Operation;
 
@@ -37,18 +38,22 @@
 
     private static final double PI_4 = 0.7853981633974483;
 
+    @MethodSubstitution
     public static double abs(double x) {
         return MathIntrinsicNode.compute(x, Operation.ABS);
     }
 
+    @MethodSubstitution
     public static double sqrt(double x) {
         return MathIntrinsicNode.compute(x, Operation.SQRT);
     }
 
+    @MethodSubstitution
     public static double log(double x) {
         return MathIntrinsicNode.compute(x, Operation.LOG);
     }
 
+    @MethodSubstitution
     public static double log10(double x) {
         return MathIntrinsicNode.compute(x, Operation.LOG10);
     }
@@ -59,6 +64,7 @@
     //   accurate within [-pi/4, pi/4]. Examine the passed value and provide
     //   a slow path for inputs outside of that interval.
 
+    @MethodSubstitution
     public static double sin(double x) {
         if (abs(x) < PI_4) {
             return MathIntrinsicNode.compute(x, Operation.SIN);
@@ -67,6 +73,7 @@
         }
     }
 
+    @MethodSubstitution
     public static double cos(double x) {
         if (abs(x) < PI_4) {
             return MathIntrinsicNode.compute(x, Operation.COS);
@@ -75,6 +82,7 @@
         }
     }
 
+    @MethodSubstitution
     public static double tan(double x) {
         if (abs(x) < PI_4) {
             return MathIntrinsicNode.compute(x, Operation.TAN);
--- a/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/NodeClassSnippets.java	Fri Jan 11 17:50:13 2013 +0100
+++ b/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/NodeClassSnippets.java	Fri Jan 11 18:26:32 2013 +0100
@@ -25,6 +25,7 @@
 import com.oracle.graal.api.meta.*;
 import com.oracle.graal.graph.*;
 import com.oracle.graal.nodes.extended.*;
+import com.oracle.graal.snippets.ClassSubstitution.*;
 
 /**
  * Snippets for improving the performance of some critical methods in {@link NodeClass} methods.
@@ -33,22 +34,25 @@
  * The latter cannot be done directly in Java code as {@link UnsafeCastNode}
  * is not available to the project containing {@link NodeClass}.
  */
-@SuppressWarnings("unused")
 @ClassSubstitution(NodeClass.class)
 public class NodeClassSnippets implements SnippetsInterface {
 
+    @MethodSubstitution
     private static Node getNode(Node node, long offset) {
         return UnsafeCastNode.unsafeCast(UnsafeLoadNode.load(node, 0, offset, Kind.Object), Node.class, false, false);
     }
 
+    @MethodSubstitution
     private static NodeList getNodeList(Node node, long offset) {
         return UnsafeCastNode.unsafeCast(UnsafeLoadNode.load(node, 0, offset, Kind.Object), NodeList.class, false, false);
     }
 
+    @MethodSubstitution
     private static void putNode(Node node, long offset, Node value) {
         UnsafeStoreNode.store(node, 0, offset, value, Kind.Object);
     }
 
+    @MethodSubstitution
     private static void putNodeList(Node node, long offset, NodeList value) {
         UnsafeStoreNode.store(node, 0, offset, value, Kind.Object);
     }
--- a/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/SnippetInstaller.java	Fri Jan 11 17:50:13 2013 +0100
+++ b/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/SnippetInstaller.java	Fri Jan 11 18:26:32 2013 +0100
@@ -30,7 +30,6 @@
 import com.oracle.graal.api.meta.*;
 import com.oracle.graal.debug.*;
 import com.oracle.graal.graph.*;
-import com.oracle.graal.graph.Node.NodeIntrinsic;
 import com.oracle.graal.java.*;
 import com.oracle.graal.nodes.*;
 import com.oracle.graal.nodes.extended.*;
@@ -121,23 +120,21 @@
 
     private void installSubstitutions(Class< ? extends SnippetsInterface> clazz, Class<?> originalClazz) {
         for (Method method : clazz.getDeclaredMethods()) {
-            if (method.getAnnotation(NodeIntrinsic.class) != null) {
+            MethodSubstitution methodSubstitution = method.getAnnotation(MethodSubstitution.class);
+            if (methodSubstitution == null) {
                 continue;
             }
             try {
-                MethodSubstitution methodSubstitution = method.getAnnotation(MethodSubstitution.class);
                 String originalName = method.getName();
                 Class<?>[] originalParameters = method.getParameterTypes();
-                if (methodSubstitution != null) {
-                    if (!methodSubstitution.value().isEmpty()) {
-                        originalName = methodSubstitution.value();
-                    }
-                    if (!methodSubstitution.isStatic()) {
-                        assert originalParameters.length >= 1 : "must be a static method with the this object as its first parameter";
-                        Class<?>[] newParameters = new Class<?>[originalParameters.length - 1];
-                        System.arraycopy(originalParameters, 1, newParameters, 0, newParameters.length);
-                        originalParameters = newParameters;
-                    }
+                if (!methodSubstitution.value().isEmpty()) {
+                    originalName = methodSubstitution.value();
+                }
+                if (!methodSubstitution.isStatic()) {
+                    assert originalParameters.length >= 1 : "must be a static method with the this object as its first parameter";
+                    Class<?>[] newParameters = new Class<?>[originalParameters.length - 1];
+                    System.arraycopy(originalParameters, 1, newParameters, 0, newParameters.length);
+                    originalParameters = newParameters;
                 }
                 Method originalMethod = originalClazz.getDeclaredMethod(originalName, originalParameters);
                 if (!originalMethod.getReturnType().isAssignableFrom(method.getReturnType())) {
--- a/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/UnsignedMathSnippets.java	Fri Jan 11 17:50:13 2013 +0100
+++ b/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/UnsignedMathSnippets.java	Fri Jan 11 18:26:32 2013 +0100
@@ -28,6 +28,7 @@
 import com.oracle.graal.api.code.*;
 import com.oracle.graal.api.meta.*;
 import com.oracle.graal.nodes.calc.*;
+import com.oracle.graal.snippets.ClassSubstitution.*;
 
 /**
  * Snippets for {@link UnsignedMath}.
@@ -35,10 +36,12 @@
 @ClassSubstitution(UnsignedMath.class)
 public class UnsignedMathSnippets implements SnippetsInterface {
 
+    @MethodSubstitution
     public static boolean aboveThan(int a, int b) {
         return materialize(BT, b, a);
     }
 
+    @MethodSubstitution
     public static boolean aboveOrEqual(int a, int b) {
         return !materialize(BT, a, b);
     }
@@ -46,6 +49,7 @@
     /**
      * Unsigned comparison belowThan for two numbers.
      */
+    @MethodSubstitution
     public static boolean belowThan(int a, int b) {
         return materialize(BT, a, b);
     }
@@ -53,6 +57,7 @@
     /**
      * Unsigned comparison belowOrEqual for two numbers.
      */
+    @MethodSubstitution
     public static boolean belowOrEqual(int a, int b) {
         return !materialize(BT, b, a);
     }
@@ -60,6 +65,7 @@
     /**
      * Unsigned comparison aboveThan for two numbers.
      */
+    @MethodSubstitution
     public static boolean aboveThan(long a, long b) {
         return materialize(BT, b, a);
     }
@@ -67,6 +73,7 @@
     /**
      * Unsigned comparison aboveOrEqual for two numbers.
      */
+    @MethodSubstitution
     public static boolean aboveOrEqual(long a, long b) {
         return !materialize(BT, a, b);
     }
@@ -74,6 +81,7 @@
     /**
      * Unsigned comparison belowThan for two numbers.
      */
+    @MethodSubstitution
     public static boolean belowThan(long a, long b) {
         return materialize(BT, a, b);
     }
@@ -81,6 +89,7 @@
     /**
      * Unsigned comparison belowOrEqual for two numbers.
      */
+    @MethodSubstitution
     public static boolean belowOrEqual(long a, long b) {
         return !materialize(BT, b, a);
     }
@@ -88,6 +97,7 @@
     /**
      * Unsigned division for two numbers.
      */
+    @MethodSubstitution
     public static int divide(int a, int b) {
         return unsignedDivide(Kind.Int, a, b);
     }
@@ -95,6 +105,7 @@
     /**
      * Unsigned remainder for two numbers.
      */
+    @MethodSubstitution
     public static int remainder(int a, int b) {
         return unsignedRemainder(Kind.Int, a, b);
     }
@@ -102,6 +113,7 @@
     /**
      * Unsigned division for two numbers.
      */
+    @MethodSubstitution
     public static long divide(long a, long b) {
         return unsignedDivide(Kind.Long, a, b);
     }
@@ -109,6 +121,7 @@
     /**
      * Unsigned remainder for two numbers.
      */
+    @MethodSubstitution
     public static long remainder(long a, long b) {
         return unsignedRemainder(Kind.Long, a, b);
     }