changeset 10536:26c69598db3e

Fix bug in canonicalization of non-compressed object pointers.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Tue, 25 Jun 2013 19:48:16 +0200
parents ddc756cd065d
children 8b2065558490
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/bridge/CompilerToVM.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.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/FloatingReadNode.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ReadNode.java src/share/vm/graal/graalCompilerToVM.cpp
diffstat 8 files changed, 32 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/MetaAccessProvider.java	Tue Jun 25 14:59:57 2013 +0200
+++ b/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/MetaAccessProvider.java	Tue Jun 25 19:48:16 2013 +0200
@@ -90,10 +90,11 @@
      * 
      * @param base the base address from which the value is read
      * @param displacement the displacement within the object in bytes
+     * @param compressedPointer whether this is a read of a compressed or an uncompressed pointer
      * @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);
+    Constant readUnsafeConstant(Kind kind, Object base, long displacement, boolean compressedPointer);
 
     /**
      * Determines if a given foreign call is side-effect free. Deoptimization cannot return
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java	Tue Jun 25 14:59:57 2013 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java	Tue Jun 25 19:48:16 2013 +0200
@@ -222,6 +222,8 @@
 
     String getFileName(HotSpotResolvedJavaType method);
 
+    Object readUnsafeUncompressedPointer(Object o, long displacement);
+
     /**
      * Invalidates the profiling information and restarts profiling upon the next invocation.
      * 
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java	Tue Jun 25 14:59:57 2013 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java	Tue Jun 25 19:48:16 2013 +0200
@@ -173,6 +173,9 @@
     public native void invalidateInstalledCode(HotSpotInstalledCode hotspotInstalledCode);
 
     @Override
+    public native Object readUnsafeUncompressedPointer(Object o, long displacement);
+
+    @Override
     public Object executeCompiledMethod(Object arg1, Object arg2, Object arg3, HotSpotInstalledCode hotspotInstalledCode) throws InvalidInstalledCodeException {
         return executeCompiledMethodIntrinsic(arg1, arg2, arg3, hotspotInstalledCode);
     }
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaField.java	Tue Jun 25 14:59:57 2013 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaField.java	Tue Jun 25 19:48:16 2013 +0200
@@ -200,12 +200,12 @@
         if (receiver == null) {
             assert Modifier.isStatic(flags);
             if (holder.isInitialized()) {
-                return graalRuntime().getRuntime().readUnsafeConstant(getKind(), holder.mirror(), offset);
+                return graalRuntime().getRuntime().readUnsafeConstant(getKind(), holder.mirror(), offset, true);
             }
             return null;
         } else {
             assert !Modifier.isStatic(flags);
-            return graalRuntime().getRuntime().readUnsafeConstant(getKind(), receiver.asObject(), offset);
+            return graalRuntime().getRuntime().readUnsafeConstant(getKind(), receiver.asObject(), offset, true);
         }
     }
 
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java	Tue Jun 25 14:59:57 2013 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java	Tue Jun 25 19:48:16 2013 +0200
@@ -1113,7 +1113,7 @@
     }
 
     @Override
-    public Constant readUnsafeConstant(Kind kind, Object base, long displacement) {
+    public Constant readUnsafeConstant(Kind kind, Object base, long displacement, boolean compressedPointer) {
         switch (kind) {
             case Boolean:
                 return Constant.forBoolean(base == null ? unsafe.getByte(displacement) != 0 : unsafe.getBoolean(base, displacement));
@@ -1131,8 +1131,15 @@
                 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));
+            case Object: {
+                Object o = null;
+                if (compressedPointer) {
+                    o = unsafe.getObject(base, displacement);
+                } else {
+                    o = this.getGraalRuntime().getCompilerToVM().readUnsafeUncompressedPointer(base, displacement);
+                }
+                return Constant.forObject(o);
+            }
             default:
                 throw GraalInternalError.shouldNotReachHere();
         }
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/FloatingReadNode.java	Tue Jun 25 14:59:57 2013 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/FloatingReadNode.java	Tue Jun 25 19:48:16 2013 +0200
@@ -57,7 +57,7 @@
 
     @Override
     public ValueNode canonical(CanonicalizerTool tool) {
-        return ReadNode.canonicalizeRead(this, location(), object(), tool);
+        return ReadNode.canonicalizeRead(this, location(), object(), tool, compress());
     }
 
     @Override
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ReadNode.java	Tue Jun 25 14:59:57 2013 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ReadNode.java	Tue Jun 25 19:48:16 2013 +0200
@@ -62,7 +62,7 @@
 
     @Override
     public ValueNode canonical(CanonicalizerTool tool) {
-        return canonicalizeRead(this, location(), object(), tool);
+        return canonicalizeRead(this, location(), object(), tool, compress());
     }
 
     @Override
@@ -70,7 +70,7 @@
         return graph().unique(new FloatingReadNode(object(), location(), lastLocationAccess, stamp(), getGuard(), getWriteBarrierType(), compress()));
     }
 
-    public static ValueNode canonicalizeRead(ValueNode read, LocationNode location, ValueNode object, CanonicalizerTool tool) {
+    public static ValueNode canonicalizeRead(ValueNode read, LocationNode location, ValueNode object, CanonicalizerTool tool, boolean compressedPointer) {
         MetaAccessProvider runtime = tool.runtime();
         if (read.usages().count() == 0) {
             // Read without usages can be savely removed.
@@ -83,7 +83,7 @@
                 if (object.kind() == Kind.Object) {
                     Object base = object.asConstant().asObject();
                     if (base != null) {
-                        Constant constant = tool.runtime().readUnsafeConstant(kind, base, displacement);
+                        Constant constant = tool.runtime().readUnsafeConstant(kind, base, displacement, compressedPointer);
                         if (constant != null) {
                             return ConstantNode.forConstant(constant, runtime, read.graph());
                         }
@@ -91,7 +91,7 @@
                 } else if (object.kind() == Kind.Long || object.kind().getStackKind() == Kind.Int) {
                     long base = object.asConstant().asLong();
                     if (base != 0L) {
-                        Constant constant = tool.runtime().readUnsafeConstant(kind, null, base + displacement);
+                        Constant constant = tool.runtime().readUnsafeConstant(kind, null, base + displacement, compressedPointer);
                         if (constant != null) {
                             return ConstantNode.forConstant(constant, runtime, read.graph());
                         }
--- a/src/share/vm/graal/graalCompilerToVM.cpp	Tue Jun 25 14:59:57 2013 +0200
+++ b/src/share/vm/graal/graalCompilerToVM.cpp	Tue Jun 25 19:48:16 2013 +0200
@@ -1168,6 +1168,13 @@
 C2V_END
 
 
+C2V_VMENTRY(jobject, readUnsafeUncompressedPointer, (JNIEnv *env, jobject, jobject o, jlong offset))
+  oop resolved_o = JNIHandles::resolve(o);
+  jlong address = offset + (jlong)resolved_o;
+  return JNIHandles::make_local(*((oop*)address));
+C2V_END
+
+
 #define CC (char*)  /*cast a literal from (const char*)*/
 #define FN_PTR(f) CAST_FROM_FN_PTR(void*, &(c2v_ ## f))
 
@@ -1246,6 +1253,7 @@
   {CC"getFileName",                   CC"("HS_RESOLVED_JAVA_TYPE")"STRING,                              FN_PTR(getFileName)},
   {CC"reprofile",                     CC"("METASPACE_METHOD")V",                                        FN_PTR(reprofile)},
   {CC"invalidateInstalledCode",       CC"("HS_INSTALLED_CODE")V",                                       FN_PTR(invalidateInstalledCode)},
+  {CC"readUnsafeUncompressedPointer", CC"("OBJECT"J)"OBJECT,                                            FN_PTR(readUnsafeUncompressedPointer)},
 };
 
 int CompilerToVM_methods_count() {