changeset 51074:bf686c47c109

8206960: HeapMonitor tests fail with Graal Summary: Remove checking lines and disable VMEventsTest when using Graal Reviewed-by: amenkov, sspitsyn Contributed-by: jcbeyler@google.com
author jcbeyler
date Thu, 12 Jul 2018 12:00:52 -0700
parents 34696f3aa22b
children e6ee7cf448f0
files test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitor.java test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorVMEventsTest.java test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/libHeapMonitorTest.c
diffstat 3 files changed, 66 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitor.java	Thu Jul 12 11:57:06 2018 -0700
+++ b/test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitor.java	Thu Jul 12 12:00:52 2018 -0700
@@ -23,9 +23,13 @@
 
 package MyPackage;
 
+import java.lang.management.ManagementFactory;
 import java.util.ArrayList;
 import java.util.List;
 
+import com.sun.management.HotSpotDiagnosticMXBean;
+import com.sun.management.VMOption;
+
 /** API for handling the underlying heap sampling monitoring system. */
 public class HeapMonitor {
   private static int[][] arrays;
@@ -56,7 +60,7 @@
     int sum = 0;
     List<Frame> frames = new ArrayList<Frame>();
     allocate(frames);
-    frames.add(new Frame("allocate", "()Ljava/util/List;", "HeapMonitor.java", 58));
+    frames.add(new Frame("allocate", "()Ljava/util/List;", "HeapMonitor.java", 62));
     return frames;
   }
 
@@ -65,8 +69,8 @@
     for (int j = 0; j < allocationIterations; j++) {
       sum += actuallyAllocate();
     }
-    frames.add(new Frame("actuallyAllocate", "()I", "HeapMonitor.java", 93));
-    frames.add(new Frame("allocate", "(Ljava/util/List;)V", "HeapMonitor.java", 66));
+    frames.add(new Frame("actuallyAllocate", "()I", "HeapMonitor.java", 97));
+    frames.add(new Frame("allocate", "(Ljava/util/List;)V", "HeapMonitor.java", 70));
   }
 
   public static List<Frame> repeatAllocate(int max) {
@@ -74,7 +78,7 @@
     for (int i = 0; i < max; i++) {
       frames = allocate();
     }
-    frames.add(new Frame("repeatAllocate", "(I)Ljava/util/List;", "HeapMonitor.java", 75));
+    frames.add(new Frame("repeatAllocate", "(I)Ljava/util/List;", "HeapMonitor.java", 79));
     return frames;
   }
 
@@ -152,14 +156,42 @@
   }
 
   public native static int sampledEvents();
-  public native static boolean obtainedEvents(Frame[] frames);
-  public native static boolean garbageContains(Frame[] frames);
+  public native static boolean obtainedEvents(Frame[] frames, boolean checkLines);
+  public native static boolean garbageContains(Frame[] frames, boolean checkLines);
   public native static boolean eventStorageIsEmpty();
   public native static void resetEventStorage();
   public native static int getEventStorageElementCount();
   public native static void forceGarbageCollection();
   public native static boolean enableVMEvents();
 
+  private static boolean getCheckLines() {
+    boolean checkLines = true;
+
+    // Do not check lines for Graal since it is not always "precise" with BCIs at uncommon traps.
+    try {
+      HotSpotDiagnosticMXBean bean = ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class);
+
+      VMOption enableJVMCI = bean.getVMOption("EnableJVMCI");
+      VMOption useJVMCICompiler = bean.getVMOption("UseJVMCICompiler");
+      String compiler = System.getProperty("jvmci.Compiler");
+
+      checkLines = !(enableJVMCI.getValue().equals("true")
+          && useJVMCICompiler.getValue().equals("true") && compiler.equals("graal"));
+    } catch (Exception e) {
+      // NOP.
+    }
+
+    return checkLines;
+  }
+
+  public static boolean obtainedEvents(Frame[] frames) {
+    return obtainedEvents(frames, getCheckLines());
+  }
+
+  public static boolean garbageContains(Frame[] frames) {
+    return garbageContains(frames, getCheckLines());
+  }
+
   public static boolean statsHaveExpectedNumberSamples(int expected, int acceptedErrorPercentage) {
     double actual = getEventStorageElementCount();
     double diffPercentage = Math.abs(actual - expected) / expected;
--- a/test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorVMEventsTest.java	Thu Jul 12 11:57:06 2018 -0700
+++ b/test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorVMEventsTest.java	Thu Jul 12 12:00:52 2018 -0700
@@ -26,11 +26,13 @@
 import java.util.ArrayList;
 import java.util.List;
 
+// Graal is not tested here due to Graal not supporting DisableIntrinsic.
 /**
  * @test
  * @summary Verifies that when the VM event is sent, sampled events are also collected.
  * @build Frame HeapMonitor
  * @compile HeapMonitorVMEventsTest.java
+ * @requires !vm.graal.enabled
  * @run main/othervm/native -XX:+UnlockDiagnosticVMOptions
  *                          -XX:DisableIntrinsic=_clone
  *                          -agentlib:HeapMonitorTest MyPackage.HeapMonitorVMEventsTest
--- a/test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/libHeapMonitorTest.c	Thu Jul 12 11:57:06 2018 -0700
+++ b/test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/libHeapMonitorTest.c	Thu Jul 12 12:00:52 2018 -0700
@@ -208,6 +208,7 @@
                                      ObjectTrace* trace,
                                      ExpectedContentFrame *expected,
                                      size_t expected_count,
+                                     jboolean check_lines,
                                      int print_out_comparisons) {
   jvmtiFrameInfo* frames;
   size_t i;
@@ -224,6 +225,7 @@
     char *name = NULL, *signature = NULL, *file_name = NULL;
     jclass declaring_class;
     int line_number;
+    jboolean differ;
     jvmtiError err;
 
     if (bci < 0 && expected[i].line_number != -1) {
@@ -258,23 +260,21 @@
       return FALSE;
     }
 
+    differ = (strcmp(name, expected[i].name) ||
+              strcmp(signature, expected[i].signature) ||
+              strcmp(file_name, expected[i].file_name) ||
+              (check_lines && line_number != expected[i].line_number));
+
     if (print_out_comparisons) {
-      fprintf(stderr, "\tComparing:\n");
+      fprintf(stderr, "\tComparing: (check_lines: %d)\n", check_lines);
       fprintf(stderr, "\t\tNames: %s and %s\n", name, expected[i].name);
       fprintf(stderr, "\t\tSignatures: %s and %s\n", signature, expected[i].signature);
       fprintf(stderr, "\t\tFile name: %s and %s\n", file_name, expected[i].file_name);
       fprintf(stderr, "\t\tLines: %d and %d\n", line_number, expected[i].line_number);
-      fprintf(stderr, "\t\tResult is %d\n",
-              (strcmp(name, expected[i].name) ||
-               strcmp(signature, expected[i].signature) ||
-               strcmp(file_name, expected[i].file_name) ||
-               line_number != expected[i].line_number));
+      fprintf(stderr, "\t\tResult is %d\n", differ);
     }
 
-    if (strcmp(name, expected[i].name) ||
-        strcmp(signature, expected[i].signature) ||
-        strcmp(file_name, expected[i].file_name) ||
-        line_number != expected[i].line_number) {
+    if (differ) {
       return FALSE;
     }
   }
@@ -388,14 +388,15 @@
 static jboolean event_storage_contains(JNIEnv* env,
                                        EventStorage* storage,
                                        ExpectedContentFrame* frames,
-                                       size_t size) {
+                                       size_t size,
+                                       jboolean check_lines) {
   int i;
   event_storage_lock(storage);
   fprintf(stderr, "Checking storage count %d\n", storage->live_object_count);
   for (i = 0; i < storage->live_object_count; i++) {
     ObjectTrace* trace = storage->live_objects[i];
 
-    if (check_sample_content(env, trace, frames, size, PRINT_OUT)) {
+    if (check_sample_content(env, trace, frames, size, check_lines, PRINT_OUT)) {
       event_storage_unlock(storage);
       return TRUE;
     }
@@ -407,7 +408,8 @@
 static jboolean event_storage_garbage_contains(JNIEnv* env,
                                                EventStorage* storage,
                                                ExpectedContentFrame* frames,
-                                               size_t size) {
+                                               size_t size,
+                                               jboolean check_lines) {
   int i;
   event_storage_lock(storage);
   fprintf(stderr, "Checking garbage storage count %d\n",
@@ -419,7 +421,7 @@
       continue;
     }
 
-    if (check_sample_content(env, trace, frames, size, PRINT_OUT)) {
+    if (check_sample_content(env, trace, frames, size, check_lines, PRINT_OUT)) {
       event_storage_unlock(storage);
       return TRUE;
     }
@@ -876,7 +878,9 @@
 }
 
 JNIEXPORT jboolean JNICALL
-Java_MyPackage_HeapMonitor_obtainedEvents(JNIEnv* env, jclass cls, jobjectArray frames) {
+Java_MyPackage_HeapMonitor_obtainedEvents(JNIEnv* env, jclass cls,
+                                          jobjectArray frames,
+                                          jboolean check_lines) {
   jboolean result;
   jsize size = (*env)->GetArrayLength(env, frames);
   ExpectedContentFrame *native_frames = malloc(size * sizeof(*native_frames));
@@ -886,14 +890,17 @@
   }
 
   fill_native_frames(env, frames, native_frames, size);
-  result = event_storage_contains(env, &global_event_storage, native_frames, size);
+  result = event_storage_contains(env, &global_event_storage, native_frames,
+                                  size, check_lines);
 
   free(native_frames), native_frames = NULL;
   return result;
 }
 
 JNIEXPORT jboolean JNICALL
-Java_MyPackage_HeapMonitor_garbageContains(JNIEnv* env, jclass cls, jobjectArray frames) {
+Java_MyPackage_HeapMonitor_garbageContains(JNIEnv* env, jclass cls,
+                                           jobjectArray frames,
+                                           jboolean check_lines) {
   jboolean result;
   jsize size = (*env)->GetArrayLength(env, frames);
   ExpectedContentFrame *native_frames = malloc(size * sizeof(*native_frames));
@@ -903,7 +910,8 @@
   }
 
   fill_native_frames(env, frames, native_frames, size);
-  result = event_storage_garbage_contains(env, &global_event_storage, native_frames, size);
+  result = event_storage_garbage_contains(env, &global_event_storage,
+                                          native_frames, size, check_lines);
 
   free(native_frames), native_frames = NULL;
   return result;