提交 ef11a27e 编写于 作者: J jcbeyler

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
上级 d70f256d
......@@ -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 @@ public class HeapMonitor {
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 @@ public class HeapMonitor {
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 @@ public class HeapMonitor {
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 class HeapMonitor {
}
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;
......
......@@ -26,11 +26,13 @@ package MyPackage;
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
......
......@@ -208,6 +208,7 @@ static jboolean check_sample_content(JNIEnv* env,
ObjectTrace* trace,
ExpectedContentFrame *expected,
size_t expected_count,
jboolean check_lines,
int print_out_comparisons) {
jvmtiFrameInfo* frames;
size_t i;
......@@ -224,6 +225,7 @@ static jboolean check_sample_content(JNIEnv* env,
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 @@ static jboolean check_sample_content(JNIEnv* env,
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 double event_storage_get_average_rate(EventStorage* storage) {
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_contains(JNIEnv* env,
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 @@ static jboolean event_storage_garbage_contains(JNIEnv* env,
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 @@ Java_MyPackage_HeapMonitor_disableSamplingEvents(JNIEnv* env, jclass cls) {
}
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 @@ Java_MyPackage_HeapMonitor_obtainedEvents(JNIEnv* env, jclass cls, jobjectArray
}
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 @@ Java_MyPackage_HeapMonitor_garbageContains(JNIEnv* env, jclass cls, jobjectArray
}
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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册