changeset 7672:1a4a00390113

Make the access of raw memory via Unsafe specific to HotSpot.
author Christian Wimmer <christian.wimmer@oracle.com>
date Mon, 04 Feb 2013 05:51:50 -0800
parents 8beb61af377a
children d8e0dd401142
files graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/MetaAccessProvider.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaField.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ReadNode.java
diffstat 4 files changed, 47 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/MetaAccessProvider.java	Mon Feb 04 05:47:35 2013 -0800
+++ b/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/MetaAccessProvider.java	Mon Feb 04 05:51:50 2013 -0800
@@ -84,4 +84,13 @@
      * @throws IllegalArgumentException if {@code array} is not an array
      */
     int lookupArrayLength(Constant array);
+
+    /**
+     * Reads a value of this kind using a base address and a displacement.
+     *
+     * @param base the base address from which the value is read
+     * @param displacement the displacement within the object in bytes
+     * @return the read value encapsulated in a {@link Constant} object, or {@code null} if the value cannot be read.
+     */
+    Constant readUnsafeConstant(Kind kind, Object base, long displacement);
 }
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaField.java	Mon Feb 04 05:47:35 2013 -0800
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaField.java	Mon Feb 04 05:51:50 2013 -0800
@@ -28,7 +28,6 @@
 
 import com.oracle.graal.api.meta.*;
 import com.oracle.graal.hotspot.*;
-import com.oracle.graal.nodes.extended.*;
 import com.oracle.graal.phases.*;
 
 /**
@@ -101,12 +100,12 @@
         if (receiver == null) {
             assert Modifier.isStatic(flags);
             if (holder.isInitialized()) {
-                return ReadNode.readUnsafeConstant(getKind(), holder.mirror(), offset);
+                return HotSpotGraalRuntime.getInstance().getRuntime().readUnsafeConstant(getKind(), holder.mirror(), offset);
             }
             return null;
         } else {
             assert !Modifier.isStatic(flags);
-            return ReadNode.readUnsafeConstant(getKind(), receiver.asObject(), offset);
+            return HotSpotGraalRuntime.getInstance().getRuntime().readUnsafeConstant(getKind(), receiver.asObject(), offset);
         }
     }
 
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java	Mon Feb 04 05:47:35 2013 -0800
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java	Mon Feb 04 05:51:50 2013 -0800
@@ -28,6 +28,7 @@
 import static com.oracle.graal.api.code.Register.RegisterFlag.*;
 import static com.oracle.graal.api.meta.DeoptimizationReason.*;
 import static com.oracle.graal.api.meta.Value.*;
+import static com.oracle.graal.graph.UnsafeAccess.*;
 import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*;
 import static com.oracle.graal.hotspot.snippets.SystemSubstitutions.*;
 import static com.oracle.graal.java.GraphBuilderPhase.RuntimeCalls.*;
@@ -916,4 +917,30 @@
         gcRoots.put(object, object);
         return object;
     }
+
+    @Override
+    public Constant readUnsafeConstant(Kind kind, Object base, long displacement) {
+        switch (kind) {
+            case Boolean:
+                return Constant.forBoolean(base == null ? unsafe.getByte(displacement) != 0 : unsafe.getBoolean(base, displacement));
+            case Byte:
+                return Constant.forByte(base == null ? unsafe.getByte(displacement) : unsafe.getByte(base, displacement));
+            case Char:
+                return Constant.forChar(base == null ? unsafe.getChar(displacement) : unsafe.getChar(base, displacement));
+            case Short:
+                return Constant.forShort(base == null ? unsafe.getShort(displacement) : unsafe.getShort(base, displacement));
+            case Int:
+                return Constant.forInt(base == null ? unsafe.getInt(displacement) : unsafe.getInt(base, displacement));
+            case Long:
+                return Constant.forLong(base == null ? unsafe.getLong(displacement) : unsafe.getLong(base, displacement));
+            case Float:
+                return Constant.forFloat(base == null ? unsafe.getFloat(displacement) : unsafe.getFloat(base, displacement));
+            case Double:
+                return Constant.forDouble(base == null ? unsafe.getDouble(displacement) : unsafe.getDouble(base, displacement));
+            case Object:
+                return Constant.forObject(unsafe.getObject(base, displacement));
+            default:
+                throw GraalInternalError.shouldNotReachHere();
+        }
+    }
 }
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ReadNode.java	Mon Feb 04 05:47:35 2013 -0800
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ReadNode.java	Mon Feb 04 05:51:50 2013 -0800
@@ -22,7 +22,6 @@
  */
 package com.oracle.graal.nodes.extended;
 
-import static com.oracle.graal.graph.FieldIntrospection.*;
 import com.oracle.graal.api.meta.*;
 import com.oracle.graal.graph.*;
 import com.oracle.graal.nodes.*;
@@ -59,60 +58,27 @@
         return canonicalizeRead(this, tool);
     }
 
-    /**
-     * Utility function for reading a value of this kind using a base address and a displacement.
-     * 
-     * @param base the base address from which the value is read
-     * @param displacement the displacement within the object in bytes
-     * @return the read value encapsulated in a {@link Constant} object
-     */
-    public static Constant readUnsafeConstant(Kind kind, Object base, long displacement) {
-        switch (kind) {
-            case Boolean:
-                return Constant.forBoolean(base == null ? unsafe.getByte(displacement) != 0 : unsafe.getBoolean(base, displacement));
-            case Byte:
-                return Constant.forByte(base == null ? unsafe.getByte(displacement) : unsafe.getByte(base, displacement));
-            case Char:
-                return Constant.forChar(base == null ? unsafe.getChar(displacement) : unsafe.getChar(base, displacement));
-            case Short:
-                return Constant.forShort(base == null ? unsafe.getShort(displacement) : unsafe.getShort(base, displacement));
-            case Int:
-                return Constant.forInt(base == null ? unsafe.getInt(displacement) : unsafe.getInt(base, displacement));
-            case Long:
-                return Constant.forLong(base == null ? unsafe.getLong(displacement) : unsafe.getLong(base, displacement));
-            case Float:
-                return Constant.forFloat(base == null ? unsafe.getFloat(displacement) : unsafe.getFloat(base, displacement));
-            case Double:
-                return Constant.forDouble(base == null ? unsafe.getDouble(displacement) : unsafe.getDouble(base, displacement));
-            case Object:
-                return Constant.forObject(unsafe.getObject(base, displacement));
-            default:
-                throw GraalInternalError.shouldNotReachHere();
-        }
-    }
-
     public static ValueNode canonicalizeRead(Access read, CanonicalizerTool tool) {
         MetaAccessProvider runtime = tool.runtime();
-        if (runtime != null && read.object() != null && read.object().isConstant()/*
-                                                                                   * &&
-                                                                                   * read.object()
-                                                                                   * .kind() ==
-                                                                                   * Kind.Object
-                                                                                   */) {
+        if (runtime != null && read.object() != null && read.object().isConstant()) {
             if (read.location().locationIdentity() == LocationNode.FINAL_LOCATION && read.location().getClass() == LocationNode.class) {
                 long displacement = read.location().displacement();
                 Kind kind = read.location().getValueKind();
                 if (read.object().kind() == Kind.Object) {
                     Object base = read.object().asConstant().asObject();
                     if (base != null) {
-                        Constant constant = readUnsafeConstant(kind, base, displacement);
-                        return ConstantNode.forConstant(constant, runtime, read.node().graph());
+                        Constant constant = tool.runtime().readUnsafeConstant(kind, base, displacement);
+                        if (constant != null) {
+                            return ConstantNode.forConstant(constant, runtime, read.node().graph());
+                        }
                     }
                 } else if (read.object().kind() == Kind.Long || read.object().kind().getStackKind() == Kind.Int) {
                     long base = read.object().asConstant().asLong();
                     if (base != 0L) {
-                        Constant constant = readUnsafeConstant(kind, null, base + displacement);
-                        return ConstantNode.forConstant(constant, runtime, read.node().graph());
+                        Constant constant = tool.runtime().readUnsafeConstant(kind, null, base + displacement);
+                        if (constant != null) {
+                            return ConstantNode.forConstant(constant, runtime, read.node().graph());
+                        }
                     }
                 }
             }