changeset 10798:7d3e74190a09

Code refactoring and cleanup
author Christos Kotselidis <christos.kotselidis@oracle.com>
date Wed, 17 Jul 2013 19:30:36 +0200
parents bb3cfaa7897c
children a84634196540
files graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/WriteBarrierAdditionTest.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/HotSpotReplacementsUtil.java
diffstat 3 files changed, 24 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/WriteBarrierAdditionTest.java	Wed Jul 17 18:02:19 2013 +0200
+++ b/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/WriteBarrierAdditionTest.java	Wed Jul 17 19:30:36 2013 +0200
@@ -41,6 +41,7 @@
 import com.oracle.graal.phases.*;
 import com.oracle.graal.phases.common.*;
 import com.oracle.graal.phases.tiers.*;
+import static com.oracle.graal.hotspot.replacements.HotSpotReplacementsUtil.*;
 
 /**
  * The following unit tests assert the presence of write barriers for both Serial and G1 GCs.
@@ -71,7 +72,7 @@
      */
     @Test
     public void test1() throws Exception {
-        test("test1Snippet", ((HotSpotRuntime) runtime()).config.useG1GC ? 4 : 2);
+        test("test1Snippet", useG1GC() ? 4 : 2);
     }
 
     public static void test1Snippet() {
@@ -87,7 +88,7 @@
      */
     @Test
     public void test2() throws Exception {
-        test("test2Snippet", ((HotSpotRuntime) runtime()).config.useG1GC ? 8 : 4);
+        test("test2Snippet", useG1GC() ? 8 : 4);
     }
 
     public static void test2Snippet(boolean test) {
@@ -110,7 +111,7 @@
      */
     @Test
     public void test3() throws Exception {
-        test("test3Snippet", ((HotSpotRuntime) runtime()).config.useG1GC ? 8 : 4);
+        test("test3Snippet", useG1GC() ? 8 : 4);
     }
 
     public static void test3Snippet() {
@@ -133,7 +134,7 @@
      */
     @Test
     public void test4() throws Exception {
-        test("test4Snippet", ((HotSpotRuntime) runtime()).config.useG1GC ? 5 : 2);
+        test("test4Snippet", useG1GC() ? 5 : 2);
     }
 
     public static Object test4Snippet() {
@@ -151,7 +152,7 @@
      */
     @Test
     public void test5() throws Exception {
-        test("test5Snippet", ((HotSpotRuntime) runtime()).config.useG1GC ? 9 : 4);
+        test("test5Snippet", useG1GC() ? 9 : 4);
     }
 
     public static Object test5Snippet() throws Exception {
@@ -164,7 +165,7 @@
      */
     @Test
     public void test6() throws Exception {
-        test2("test6Snippet", wr, new Long(HotSpotRuntime.referentOffset()), null);
+        test2("test6Snippet", wr, new Long(referentOffset()), null);
     }
 
     /**
@@ -173,7 +174,7 @@
      */
     @Test
     public void test7() throws Exception {
-        test2("test6Snippet", con, new Long(HotSpotRuntime.referentOffset()), null);
+        test2("test6Snippet", con, new Long(referentOffset()), null);
     }
 
     /**
@@ -210,14 +211,14 @@
                 Debug.dump(graph, "After Write Barrier Addition");
 
                 int barriers = 0;
-                if (((HotSpotRuntime) runtime()).config.useG1GC) {
+                if (useG1GC()) {
                     barriers = graph.getNodes(G1PreWriteBarrier.class).count() + graph.getNodes(G1PostWriteBarrier.class).count();
                 } else {
                     barriers = graph.getNodes(SerialWriteBarrier.class).count();
                 }
                 Assert.assertTrue(barriers == expectedBarriers);
                 for (WriteNode write : graph.getNodes(WriteNode.class)) {
-                    if (((HotSpotRuntime) runtime()).config.useG1GC) {
+                    if (useG1GC()) {
                         if (write.getWriteBarrierType() != WriteBarrierType.NONE) {
                             Assert.assertTrue(write.successors().count() == 1);
                             Assert.assertTrue(write.next() instanceof G1PostWriteBarrier);
@@ -234,11 +235,11 @@
                 for (ReadNode read : graph.getNodes(ReadNode.class)) {
                     if (read.getWriteBarrierType() != WriteBarrierType.NONE) {
                         if (read.location() instanceof ConstantLocationNode) {
-                            Assert.assertTrue(((ConstantLocationNode) (read.location())).getDisplacement() == HotSpotRuntime.referentOffset());
+                            Assert.assertTrue(((ConstantLocationNode) (read.location())).getDisplacement() == referentOffset());
                         } else {
-                            Assert.assertTrue(((IndexedLocationNode) (read.location())).getDisplacement() == HotSpotRuntime.referentOffset());
+                            Assert.assertTrue(((IndexedLocationNode) (read.location())).getDisplacement() == referentOffset());
                         }
-                        Assert.assertTrue(((HotSpotRuntime) runtime()).config.useG1GC);
+                        Assert.assertTrue(useG1GC());
                         Assert.assertTrue(read.getWriteBarrierType() == WriteBarrierType.PRECISE);
                         Assert.assertTrue(read.next() instanceof G1PreWriteBarrier);
                     }
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java	Wed Jul 17 18:02:19 2013 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java	Wed Jul 17 19:30:36 2013 +0200
@@ -849,14 +849,6 @@
         return graph.add(new WriteNode(object, value, location, WriteBarrierType.NONE, config.useCompressedKlassPointers));
     }
 
-    public static long referentOffset() {
-        try {
-            return unsafe.objectFieldOffset(java.lang.ref.Reference.class.getDeclaredField("referent"));
-        } catch (Exception e) {
-            throw new GraalInternalError(e);
-        }
-    }
-
     /**
      * The following method lowers the unsafe load node. If any GC besides G1 is used, the unsafe
      * load is lowered normally to a read node. However, if the G1 is used and the unsafe load could
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/HotSpotReplacementsUtil.java	Wed Jul 17 18:02:19 2013 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/HotSpotReplacementsUtil.java	Wed Jul 17 19:30:36 2013 +0200
@@ -22,6 +22,7 @@
  */
 package com.oracle.graal.hotspot.replacements;
 
+import static com.oracle.graal.graph.UnsafeAccess.*;
 import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*;
 import static com.oracle.graal.hotspot.meta.HotSpotRuntime.*;
 import static com.oracle.graal.nodes.extended.BranchProbabilityNode.*;
@@ -29,6 +30,7 @@
 
 import com.oracle.graal.api.code.*;
 import com.oracle.graal.api.meta.*;
+import com.oracle.graal.graph.*;
 import com.oracle.graal.graph.Node.ConstantNodeParameter;
 import com.oracle.graal.graph.Node.NodeIntrinsic;
 import com.oracle.graal.hotspot.*;
@@ -699,4 +701,13 @@
     public static long gcTotalCollectionsAddress() {
         return config().gcTotalCollectionsAddress;
     }
+
+    @Fold
+    public static long referentOffset() {
+        try {
+            return unsafe.objectFieldOffset(java.lang.ref.Reference.class.getDeclaredField("referent"));
+        } catch (Exception e) {
+            throw new GraalInternalError(e);
+        }
+    }
 }