changeset 22573:be44a5efeaff

HotSpotMethodData must handle profile data when TypeProfileLevel is non-zero
author Tom Rodriguez <tom.rodriguez@oracle.com>
date Thu, 17 Sep 2015 12:11:28 -0700
parents c3b49e9d0f48
children 5a706439be63
files jvmci/jdk.internal.jvmci.hotspot/src/jdk/internal/jvmci/hotspot/CompilerToVM.java jvmci/jdk.internal.jvmci.hotspot/src/jdk/internal/jvmci/hotspot/HotSpotMethodData.java src/cpu/x86/vm/globals_x86.hpp src/share/vm/jvmci/jvmciCompilerToVM.cpp src/share/vm/oops/methodData.cpp src/share/vm/runtime/arguments.cpp
diffstat 6 files changed, 86 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/jvmci/jdk.internal.jvmci.hotspot/src/jdk/internal/jvmci/hotspot/CompilerToVM.java	Thu Sep 17 12:10:17 2015 -0700
+++ b/jvmci/jdk.internal.jvmci.hotspot/src/jdk/internal/jvmci/hotspot/CompilerToVM.java	Thu Sep 17 12:11:28 2015 -0700
@@ -563,4 +563,12 @@
      * @return null or the resolved method for this location
      */
     native HotSpotResolvedObjectTypeImpl getResolvedJavaType(Object base, long displacement, boolean compressed);
+
+    /**
+     * @param metaspaceMethodData
+     * @param position
+     * @return Return the size of the ProfileData item pointed at by {@code current}. Throws
+     *         {@link IllegalArgumentException} if an invalid position is given.
+     */
+    native int methodDataProfileDataSize(long metaspaceMethodData, int position);
 }
--- a/jvmci/jdk.internal.jvmci.hotspot/src/jdk/internal/jvmci/hotspot/HotSpotMethodData.java	Thu Sep 17 12:10:17 2015 -0700
+++ b/jvmci/jdk.internal.jvmci.hotspot/src/jdk/internal/jvmci/hotspot/HotSpotMethodData.java	Thu Sep 17 12:11:28 2015 -0700
@@ -61,10 +61,10 @@
         new BranchData(),
         new MultiBranchData(),
         new ArgInfoData(),
-        null, // call_type_data_tag
-        null, // virtual_call_type_data_tag
-        null, // parameters_type_data_tag
-        null, // speculative_trap_data_tag
+        new UnknownProfileData(Tag.CallTypeData),
+        new VirtualCallTypeData(),
+        new UnknownProfileData(Tag.ParametersTypeData),
+        new UnknownProfileData(Tag.SpeculativeTrapData),
     };
     // @formatter:on
 
@@ -132,7 +132,8 @@
         }
 
         HotSpotMethodDataAccessor result = getData(position);
-        assert result != null : "NO_DATA tag is not allowed";
+        final Tag tag = AbstractMethodData.readTag(this, position);
+        assert result != null : "NO_DATA tag is not allowed " + tag;
         return result;
     }
 
@@ -274,7 +275,7 @@
         private static final int EXCEPTIONS_MASK = 1 << config.bitDataExceptionSeenFlag;
 
         private final Tag tag;
-        private final int staticSize;
+        protected final int staticSize;
 
         protected AbstractMethodData(Tag tag, int staticSize) {
             this.tag = tag;
@@ -296,8 +297,12 @@
         }
 
         @Override
-        public int getSize(HotSpotMethodData data, int position) {
-            return staticSize + getDynamicSize(data, position);
+        public final int getSize(HotSpotMethodData data, int position) {
+            int size = staticSize + getDynamicSize(data, position);
+            // Sanity check against VM
+            int vmSize = HotSpotJVMCIRuntime.runtime().compilerToVm.methodDataProfileDataSize(data.metaspaceMethodData, position);
+            assert size == vmSize : size + " != " + vmSize;
+            return size;
         }
 
         @Override
@@ -609,6 +614,10 @@
             super(Tag.VirtualCallData, VIRTUAL_CALL_DATA_SIZE);
         }
 
+        protected VirtualCallData(Tag tag, int staticSize) {
+            super(tag, staticSize);
+        }
+
         @Override
         public int getExecutionCount(HotSpotMethodData data, int position) {
             final int typeProfileWidth = config.typeProfileWidth;
@@ -701,6 +710,19 @@
         }
     }
 
+    private static class VirtualCallTypeData extends VirtualCallData {
+
+        public VirtualCallTypeData() {
+            super(Tag.VirtualCallTypeData, 0);
+        }
+
+        @Override
+        protected int getDynamicSize(HotSpotMethodData data, int position) {
+            assert staticSize == 0;
+            return HotSpotJVMCIRuntime.runtime().compilerToVm.methodDataProfileDataSize(data.metaspaceMethodData, position);
+        }
+    }
+
     private static class RetData extends CounterData {
 
         private static final int RET_DATA_ROW_SIZE = cellsToBytes(3);
@@ -863,6 +885,24 @@
         }
     }
 
+    private static class UnknownProfileData extends AbstractMethodData {
+        public UnknownProfileData(Tag tag) {
+            super(tag, 0);
+        }
+
+        @Override
+        protected int getDynamicSize(HotSpotMethodData data, int position) {
+            assert staticSize == 0;
+            return HotSpotJVMCIRuntime.runtime().compilerToVm.methodDataProfileDataSize(data.metaspaceMethodData, position);
+        }
+
+        @Override
+        public StringBuilder appendTo(StringBuilder sb, HotSpotMethodData data, int pos) {
+            // TODO Auto-generated method stub
+            return null;
+        }
+    }
+
     public void setCompiledIRSize(int size) {
         UNSAFE.putInt(metaspaceMethodData + config.methodDataIRSizeOffset, size);
     }
--- a/src/cpu/x86/vm/globals_x86.hpp	Thu Sep 17 12:10:17 2015 -0700
+++ b/src/cpu/x86/vm/globals_x86.hpp	Thu Sep 17 12:11:28 2015 -0700
@@ -80,8 +80,12 @@
 // GC Ergo Flags
 define_pd_global(uintx, CMSYoungGenPerWorker, 64*M);  // default max size of CMS young gen, per GC worker thread
 
-// Disabled in JVMCI until HotSpotMethodData is updated to be aware of the new profiling tags
-define_pd_global(uintx, TypeProfileLevel, JVMCI_ONLY(0) NOT_JVMCI(111));
+#ifdef COMPILER_JVMCI
+// Don't bother enabling type profiling since JVMCI doesn't currently expose it
+define_pd_global(uintx, TypeProfileLevel, 0);
+#else
+define_pd_global(uintx, TypeProfileLevel, 111);
+#endif
 
 #define ARCH_FLAGS(develop, product, diagnostic, experimental, notproduct) \
                                                                             \
--- a/src/share/vm/jvmci/jvmciCompilerToVM.cpp	Thu Sep 17 12:10:17 2015 -0700
+++ b/src/share/vm/jvmci/jvmciCompilerToVM.cpp	Thu Sep 17 12:11:28 2015 -0700
@@ -1122,6 +1122,26 @@
   tty->flush();
 C2V_END
 
+C2V_VMENTRY(int, methodDataProfileDataSize, (JNIEnv*, jobject, jlong metaspace_method_data, jint position))
+  ResourceMark rm;
+  MethodData* mdo = CompilerToVM::asMethodData(metaspace_method_data);
+  ProfileData* profile_data = mdo->data_at(position);
+  if (mdo->is_valid(profile_data)) {
+    return profile_data->size_in_bytes();
+  }
+  DataLayout* data    = mdo->extra_data_base();
+  DataLayout* end   = mdo->extra_data_limit();
+  for (;; data = mdo->next_extra(data)) {
+    assert(data < end, "moved past end of extra data");
+    profile_data = data->data_in();
+    if (mdo->dp_to_di(profile_data->dp()) == position) {
+      return profile_data->size_in_bytes();
+    }
+  }
+  mdo->print();
+  THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), err_msg("Invalid profile data position %d", position));
+C2V_END
+
 
 #define CC (char*)  /*cast a literal from (const char*)*/
 #define FN_PTR(f) CAST_FROM_FN_PTR(void*, &(c2v_ ## f))
@@ -1200,6 +1220,7 @@
   {CC"shouldDebugNonSafepoints",                     CC"()Z",                                                                          FN_PTR(shouldDebugNonSafepoints)},
   {CC"writeDebugOutput",                             CC"([BII)V",                                                                      FN_PTR(writeDebugOutput)},
   {CC"flushDebugOutput",                             CC"()V",                                                                          FN_PTR(flushDebugOutput)},
+  {CC"methodDataProfileDataSize",                    CC"(JI)I",                                                                        FN_PTR(methodDataProfileDataSize)},
 };
 
 int CompilerToVM::methods_count() {
--- a/src/share/vm/oops/methodData.cpp	Thu Sep 17 12:10:17 2015 -0700
+++ b/src/share/vm/oops/methodData.cpp	Thu Sep 17 12:11:28 2015 -0700
@@ -1124,7 +1124,9 @@
     return new VirtualCallTypeData(this);
   case DataLayout::parameters_type_data_tag:
     return new ParametersTypeData(this);
-  };
+  case DataLayout::speculative_trap_data_tag:
+    return new SpeculativeTrapData(this);
+  }
 }
 
 // Iteration over data.
--- a/src/share/vm/runtime/arguments.cpp	Thu Sep 17 12:10:17 2015 -0700
+++ b/src/share/vm/runtime/arguments.cpp	Thu Sep 17 12:11:28 2015 -0700
@@ -2442,10 +2442,6 @@
       warning("forcing ScavengeRootsInCode non-zero because JVMCI is enabled");
       ScavengeRootsInCode = 1;
   }
-  if (TypeProfileLevel != 0) {
-      warning("forcing TypeProfileLevel to 0 as HotSpotMethodData can not yet handle the new type profile info");
-      TypeProfileLevel = 0;
-  }
 #endif
 
   // Need to limit the extent of the padding to reasonable size.