changeset 9807:d552919fbb05

Graal's code annotations are installed into codeBlobs and are thus included in disassembler output (in a non-PRODUCT build)
author Doug Simon <doug.simon@oracle.com>
date Thu, 23 May 2013 23:23:03 +0200
parents 21b8cd853b2b
children 097630441baf
files graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CompilationResult.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotCompiledCode.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java src/share/vm/classfile/systemDictionary.hpp src/share/vm/classfile/vmSymbols.hpp src/share/vm/graal/graalCodeInstaller.cpp src/share/vm/graal/graalCodeInstaller.hpp src/share/vm/graal/graalJavaAccess.hpp
diffstat 9 files changed, 73 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CompilationResult.java	Thu May 23 18:14:59 2013 +0200
+++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CompilationResult.java	Thu May 23 23:23:03 2013 +0200
@@ -492,6 +492,9 @@
      * @return the code annotations or {@code null} if there are none
      */
     public List<CodeAnnotation> getAnnotations() {
+        if (annotations == null) {
+            return Collections.emptyList();
+        }
         return annotations;
     }
 
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java	Thu May 23 18:14:59 2013 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java	Thu May 23 23:23:03 2013 +0200
@@ -213,6 +213,8 @@
                 if (Debug.isDumpEnabled()) {
                     Debug.dump(new Object[]{compResult, installedCode}, "After code installation");
                 }
+                // TTY.println(String.valueOf(graph));
+                // TTY.println(graalRuntime.getRuntime().disassemble(installedCode));
             }
 
         });
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotCompiledCode.java	Thu May 23 18:14:59 2013 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotCompiledCode.java	Thu May 23 23:23:03 2013 +0200
@@ -25,9 +25,9 @@
 import java.util.*;
 
 import com.oracle.graal.api.code.*;
-import com.oracle.graal.api.code.CompilationResult.ExceptionHandler;
-import com.oracle.graal.api.code.CompilationResult.Mark;
-import com.oracle.graal.api.code.CompilationResult.Site;
+import com.oracle.graal.api.code.CompilationResult.CodeComment;
+import com.oracle.graal.api.code.CompilationResult.JumpTable;
+import com.oracle.graal.api.code.CompilationResult.*;
 
 /**
  * A {@link CompilationResult} with additional HotSpot-specific information required for installing
@@ -40,6 +40,18 @@
 
     public final Site[] sites;
     public final ExceptionHandler[] exceptionHandlers;
+    public final Comment[] comments;
+
+    public static class Comment {
+
+        public final String text;
+        public final int pcOffset;
+
+        public Comment(int pcOffset, String text) {
+            this.text = text;
+            this.pcOffset = pcOffset;
+        }
+    }
 
     public HotSpotCompiledCode(CompilationResult compResult) {
         this.comp = compResult;
@@ -49,6 +61,24 @@
         } else {
             exceptionHandlers = compResult.getExceptionHandlers().toArray(new ExceptionHandler[compResult.getExceptionHandlers().size()]);
         }
+        List<CodeAnnotation> annotations = compResult.getAnnotations();
+        comments = new Comment[annotations.size()];
+        if (!annotations.isEmpty()) {
+            for (int i = 0; i < comments.length; i++) {
+                CodeAnnotation annotation = annotations.get(i);
+                String text;
+                if (annotation instanceof CodeComment) {
+                    CodeComment codeComment = (CodeComment) annotation;
+                    text = codeComment.value;
+                } else if (annotation instanceof JumpTable) {
+                    JumpTable jumpTable = (JumpTable) annotation;
+                    text = "JumpTable [" + jumpTable.low + " .. " + jumpTable.high + "]";
+                } else {
+                    text = annotation.toString();
+                }
+                comments[i] = new Comment(annotation.position, text);
+            }
+        }
     }
 
     static class SiteComparator implements Comparator<Site> {
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java	Thu May 23 18:14:59 2013 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java	Thu May 23 23:23:03 2013 +0200
@@ -129,8 +129,9 @@
     @Override
     public native long getMaxCallTargetOffset(long address);
 
+    // The HotSpot disassembler seems not to be thread safe so it's better to synchronize its usage
     @Override
-    public native String disassembleCodeBlob(long codeBlob);
+    public synchronized native String disassembleCodeBlob(long codeBlob);
 
     @Override
     public native byte[] getCode(long codeBlob);
--- a/src/share/vm/classfile/systemDictionary.hpp	Thu May 23 18:14:59 2013 +0200
+++ b/src/share/vm/classfile/systemDictionary.hpp	Thu May 23 23:23:03 2013 +0200
@@ -186,6 +186,7 @@
   do_klass(BitSet_klass,                          java_util_BitSet,                                             Opt) \
   /* graal.hotspot */                                                                                                \
   do_klass(HotSpotCompiledCode_klass,             com_oracle_graal_hotspot_HotSpotCompiledCode,                 Opt) \
+  do_klass(HotSpotCompiledCode_Comment_klass,     com_oracle_graal_hotspot_HotSpotCompiledCode_Comment,         Opt) \
   do_klass(HotSpotCompiledNmethod_klass,          com_oracle_graal_hotspot_HotSpotCompiledNmethod,              Opt) \
   do_klass(HotSpotCompiledRuntimeStub_klass,      com_oracle_graal_hotspot_HotSpotCompiledRuntimeStub,          Opt) \
   do_klass(HotSpotForeignCallLinkage_klass,       com_oracle_graal_hotspot_HotSpotForeignCallLinkage,           Opt) \
--- a/src/share/vm/classfile/vmSymbols.hpp	Thu May 23 18:14:59 2013 +0200
+++ b/src/share/vm/classfile/vmSymbols.hpp	Thu May 23 23:23:03 2013 +0200
@@ -297,6 +297,7 @@
   template(com_oracle_graal_hotspot_HotSpotKlassOop,                 "com/oracle/graal/hotspot/HotSpotKlassOop")                      \
   template(com_oracle_graal_hotspot_HotSpotOptions,                  "com/oracle/graal/hotspot/HotSpotOptions")                       \
   template(com_oracle_graal_hotspot_HotSpotCompiledCode,             "com/oracle/graal/hotspot/HotSpotCompiledCode")                  \
+  template(com_oracle_graal_hotspot_HotSpotCompiledCode_Comment,     "com/oracle/graal/hotspot/HotSpotCompiledCode$Comment")          \
   template(com_oracle_graal_hotspot_HotSpotCompiledNmethod,          "com/oracle/graal/hotspot/HotSpotCompiledNmethod")               \
   template(com_oracle_graal_hotspot_HotSpotCompiledRuntimeStub,      "com/oracle/graal/hotspot/HotSpotCompiledRuntimeStub")           \
   template(com_oracle_graal_hotspot_HotSpotForeignCallLinkage,       "com/oracle/graal/hotspot/HotSpotForeignCallLinkage")            \
--- a/src/share/vm/graal/graalCodeInstaller.cpp	Thu May 23 18:14:59 2013 +0200
+++ b/src/share/vm/graal/graalCodeInstaller.cpp	Thu May 23 23:23:03 2013 +0200
@@ -410,6 +410,9 @@
 
   // (very) conservative estimate: each site needs a constant section entry
   _constants_size = _sites->length() * (BytesPerLong*2);
+#ifndef PRODUCT
+  _comments = (arrayOop) HotSpotCompiledCode::comments(compiled_code);
+#endif
 
   _next_call_type = MARK_INVOKE_INVALID;
 }
@@ -463,6 +466,19 @@
       fatal("unexpected Site subclass");
     }
   }
+
+#ifndef PRODUCT
+  if (_comments != NULL) {
+    oop* comments = (oop*) _comments->base(T_OBJECT);
+    for (int i = 0; i < _comments->length(); i++) {
+      oop comment = comments[i];
+      assert(comment->is_a(HotSpotCompiledCode_Comment::klass()), "cce");
+      jint offset = HotSpotCompiledCode_Comment::pcOffset(comment);
+      char* text = java_lang_String::as_utf8_string(HotSpotCompiledCode_Comment::text(comment));
+      buffer.block_comment(offset, text);
+    }
+  }
+#endif
 }
 
 void CodeInstaller::assumption_MethodContents(Handle assumption) {
--- a/src/share/vm/graal/graalCodeInstaller.hpp	Thu May 23 18:14:59 2013 +0200
+++ b/src/share/vm/graal/graalCodeInstaller.hpp	Thu May 23 23:23:03 2013 +0200
@@ -60,6 +60,9 @@
   jint          _custom_stack_area_offset;
   jint          _parameter_count;
   jint          _constants_size;
+#ifndef PRODUCT
+  arrayOop      _comments;
+#endif
 
   MarkId        _next_call_type;
   address       _invoke_mark_pc;
--- a/src/share/vm/graal/graalJavaAccess.hpp	Thu May 23 18:14:59 2013 +0200
+++ b/src/share/vm/graal/graalJavaAccess.hpp	Thu May 23 23:23:03 2013 +0200
@@ -87,6 +87,11 @@
     oop_field(HotSpotCompiledCode, comp, "Lcom/oracle/graal/api/code/CompilationResult;")                                                                      \
     oop_field(HotSpotCompiledCode, sites, "[Lcom/oracle/graal/api/code/CompilationResult$Site;")                                                               \
     oop_field(HotSpotCompiledCode, exceptionHandlers, "[Lcom/oracle/graal/api/code/CompilationResult$ExceptionHandler;")                                       \
+    oop_field(HotSpotCompiledCode, comments, "[Lcom/oracle/graal/hotspot/HotSpotCompiledCode$Comment;")                                                        \
+  end_class                                                                                                                                                    \
+  start_class(HotSpotCompiledCode_Comment)                                                                                                                     \
+    oop_field(HotSpotCompiledCode_Comment, text, "Ljava/lang/String;")                                                                                         \
+    int_field(HotSpotCompiledCode_Comment, pcOffset)                                                                                                           \
   end_class                                                                                                                                                    \
   start_class(HotSpotCompiledNmethod)                                                                                                                          \
     oop_field(HotSpotCompiledNmethod, method, "Lcom/oracle/graal/hotspot/meta/HotSpotResolvedJavaMethod;")                                                     \
@@ -95,8 +100,8 @@
   start_class(HotSpotCompiledRuntimeStub)                                                                                                                      \
     oop_field(HotSpotCompiledRuntimeStub, stubName, "Ljava/lang/String;")                                                                                      \
   end_class                                                                                                                                                    \
-  start_class(HotSpotForeignCallLinkage)                                                                                                                        \
-    long_field(HotSpotForeignCallLinkage, address)                                                                                                              \
+  start_class(HotSpotForeignCallLinkage)                                                                                                                       \
+    long_field(HotSpotForeignCallLinkage, address)                                                                                                             \
   end_class                                                                                                                                                    \
   start_class(ExceptionHandler)                                                                                                                                \
     int_field(ExceptionHandler, startBCI)                                                                                                                      \
@@ -139,7 +144,7 @@
     int_field(CompilationResult_Site, pcOffset)                                                                                                                \
   end_class                                                                                                                                                    \
   start_class(CompilationResult_Call)                                                                                                                          \
-    oop_field(CompilationResult_Call, target, "Lcom/oracle/graal/api/meta/InvokeTarget;")                                                                                            \
+    oop_field(CompilationResult_Call, target, "Lcom/oracle/graal/api/meta/InvokeTarget;")                                                                      \
     oop_field(CompilationResult_Call, debugInfo, "Lcom/oracle/graal/api/code/DebugInfo;")                                                                      \
   end_class                                                                                                                                                    \
   start_class(CompilationResult_DataPatch)                                                                                                                     \
@@ -228,10 +233,10 @@
     oop_field(VirtualObject, type, "Lcom/oracle/graal/api/meta/ResolvedJavaType;")                                                                             \
     oop_field(VirtualObject, values, "[Lcom/oracle/graal/api/meta/Value;")                                                                                     \
   end_class                                                                                                                                                    \
-  start_class(HotSpotMonitorValue)                                                                                                                               \
-    oop_field(HotSpotMonitorValue, owner, "Lcom/oracle/graal/api/meta/Value;")                                                                                   \
-    oop_field(HotSpotMonitorValue, slot, "Lcom/oracle/graal/api/code/StackSlot;")                                                                                \
-    boolean_field(HotSpotMonitorValue, eliminated)                                                                                                               \
+  start_class(HotSpotMonitorValue)                                                                                                                             \
+    oop_field(HotSpotMonitorValue, owner, "Lcom/oracle/graal/api/meta/Value;")                                                                                 \
+    oop_field(HotSpotMonitorValue, slot, "Lcom/oracle/graal/api/code/StackSlot;")                                                                              \
+    boolean_field(HotSpotMonitorValue, eliminated)                                                                                                             \
   end_class                                                                                                                                                    \
   /* end*/