--- old/test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/libHeapMonitor.c 2018-02-12 20:05:16.399722786 -0800 +++ new/test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/libHeapMonitor.c 2018-02-12 20:05:16.175723648 -0800 @@ -178,20 +178,24 @@ } ExpectedContentFrame; static jboolean check_sample_content(JNIEnv *env, - jvmtiStackTrace *trace, + jvmtiAllocTraceInfo* trace, ExpectedContentFrame *expected, int expected_count, int print_out_comparisons) { int i; - if (expected_count > trace->frame_count) { + jvmtiStackInfo* stack_info = trace->stack_info; + + if (expected_count > stack_info->frame_count) { return FALSE; } + jvmtiFrameInfo* frames = stack_info->frame_buffer; + for (i = 0; i < expected_count; i++) { // Get basic information out of the trace. - int bci = trace->frames[i].location; - jmethodID methodid = trace->frames[i].method; + int bci = frames[i].location; + jmethodID methodid = frames[i].method; char *name = NULL, *signature = NULL, *file_name = NULL; if (bci < 0) { @@ -228,12 +232,12 @@ } if (print_out_comparisons) { - fprintf(stderr, "Comparing:\n"); - fprintf(stderr, "\tNames: %s and %s\n", name, expected[i].name); - fprintf(stderr, "\tSignatures: %s and %s\n", signature, expected[i].signature); - fprintf(stderr, "\tFile name: %s and %s\n", file_name, expected[i].file_name); - fprintf(stderr, "\tLines: %d and %d\n", line_number, expected[i].line_number); - fprintf(stderr, "\tResult is %d\n", + fprintf(stderr, "\tComparing:\n"); + 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) || @@ -251,7 +255,7 @@ return TRUE; } -static jboolean compare_samples(JNIEnv* env, jvmtiStackTrace* traces, +static jboolean compare_samples(JNIEnv* env, jvmtiAllocTraceInfo* traces, int trace_count, ExpectedContentFrame* expected_content, size_t size, @@ -259,8 +263,12 @@ // We expect the code to record correctly the bci, retrieve the line // number, have the right method and the class name of the first frames. int i; + if (print_out_comparisons) { + fprintf(stderr, "\tNumber of traces: %d\n", print_out_comparisons); + } + for (i = 0; i < trace_count; i++) { - jvmtiStackTrace *trace = traces + i; + jvmtiAllocTraceInfo* trace = traces + i; if (check_sample_content(env, trace, expected_content, size, print_out_comparisons)) { // At least one frame matched what we were looking for. @@ -275,18 +283,23 @@ check_samples(JNIEnv* env, ExpectedContentFrame* expected, size_t size, - jvmtiError (*const get_traces)(jvmtiEnv*, jvmtiStackTraces*), + jvmtiError (*const get_traces)(jvmtiEnv*, jvmtiAllocTraceInfo**, jint*), int print_out_comparisons) { - jvmtiStackTraces traces; - jvmtiError error = get_traces(jvmti, &traces); + jvmtiAllocTraceInfo *traces; + jint trace_counter; + jvmtiError error = get_traces(jvmti, &traces, &trace_counter); if (error != JVMTI_ERROR_NONE) { return FALSE; } - int result = compare_samples(env, traces.stack_traces, traces.trace_count, + int result = compare_samples(env, traces, trace_counter, expected, size, print_out_comparisons); - (*jvmti)->ReleaseTraces(jvmti, &traces); + + if ((*jvmti)->Deallocate(jvmti, (unsigned char*) traces) != JVMTI_ERROR_NONE) { + return FALSE; + } + return result; } @@ -294,7 +307,7 @@ ExpectedContentFrame* expected, size_t size, int print_out_comparisons) { - return check_samples(env, expected, size, (*jvmti)->GetLiveTraces, + return check_samples(env, expected, size, (*jvmti)->GetObjectAllocTraces, print_out_comparisons); } @@ -538,28 +551,28 @@ return FALSE; } - if (check_capability_error((*jvmti)->ReleaseTraces(jvmti, NULL), - "Release Traces")) { - return FALSE; - } - if (check_capability_error((*jvmti)->GetHeapSamplingStats(jvmti, NULL), "Get Heap Sampling Stats")) { return FALSE; } - if (check_capability_error((*jvmti)->GetGarbageTraces(jvmti, NULL), + if (check_capability_error((*jvmti)->GetGarbageTraces(jvmti, NULL, NULL), "Get Garbage Traces")) { return FALSE; } - if (check_capability_error((*jvmti)->GetFrequentGarbageTraces(jvmti, NULL), + if (check_capability_error((*jvmti)->GetFrequentGarbageTraces(jvmti, NULL, NULL), "Get Frequent Garbage Traces")) { return FALSE; } - if (check_capability_error((*jvmti)->GetLiveTraces(jvmti, NULL), - "Get Live Traces")) { + if (check_capability_error((*jvmti)->GetObjectAllocTraces(jvmti, NULL, NULL), + "Get Object Allocated Traces")) { + return FALSE; + } + + if (check_capability_error((*jvmti)->GetObjectAllocTraces(jvmti, NULL, NULL), + "Get Cached Object Allocated Traces")) { return FALSE; } return TRUE; @@ -594,30 +607,29 @@ } static double calculate_average_stack_depth( - jvmtiError (*const get_traces)(jvmtiEnv*, jvmtiStackTraces*)) { - jvmtiStackTraces traces; + jvmtiError (*const get_traces)(jvmtiEnv*, jvmtiAllocTraceInfo**, jint*)) { + jvmtiAllocTraceInfo* traces = NULL; + jint trace_counter; - jvmtiError error = get_traces(jvmti, &traces);; + jvmtiError error = get_traces(jvmti, &traces, &trace_counter);; if (error != JVMTI_ERROR_NONE) { return 0; } - int trace_count = traces.trace_count; - - if (trace_count == 0) { + if (trace_counter == 0) { return 0; } int i; - jvmtiStackTrace* stack_traces = traces.stack_traces; double sum = 0; - for (i = 0; i < trace_count; i++) { - jvmtiStackTrace *stack_trace = stack_traces + i; - sum += stack_trace->frame_count; + for (i = 0; i < trace_counter; i++) { + jvmtiAllocTraceInfo* trace = traces + i; + jvmtiStackInfo* stack_info = trace->stack_info; + sum += stack_info->frame_count; } - if ((*jvmti)->ReleaseTraces(jvmti, &traces) != JVMTI_ERROR_NONE) { + if ((*jvmti)->Deallocate(jvmti, (unsigned char*) traces) != JVMTI_ERROR_NONE) { return 0; } @@ -627,7 +639,7 @@ JNIEXPORT jdouble JNICALL Java_MyPackage_HeapMonitorStackDepthTest_getAverageStackDepth(JNIEnv *env, jclass cls) { - double result = calculate_average_stack_depth((*jvmti)->GetLiveTraces); + double result = calculate_average_stack_depth((*jvmti)->GetObjectAllocTraces); if (result != 0) { return result; @@ -639,26 +651,29 @@ } typedef struct sThreadsFound { - jint *threads; + jint* threads; int num_threads; } ThreadsFound; -static void find_threads_in_traces(jvmtiStackTraces* traces, +static void find_threads_in_traces(jvmtiAllocTraceInfo* traces, + jint trace_counter, ThreadsFound* thread_data) { int i; - jvmtiStackTrace* stack_traces = traces->stack_traces; - int trace_count = traces->trace_count; - - jint *threads = thread_data->threads; + jint* threads = thread_data->threads; int num_threads = thread_data->num_threads; // We are looking for at last expected_num_threads different traces. - for (i = 0; i < trace_count; i++) { - jvmtiStackTrace *stack_trace = stack_traces + i; - jlong thread_id = stack_trace->thread_id; + for (i = 0; i < trace_counter; i++) { + jvmtiAllocTraceInfo* trace = traces + i; + jvmtiStackInfo* stack_info = trace->stack_info; + jint thread_id = trace->thread_id; // Check it is the right frame: only accept helper top framed traces. - jmethodID methodid = stack_trace->frames[0].method; + if (stack_info->frame_count == 0) { + continue; + } + + jmethodID methodid = stack_info->frame_buffer[0].method; char *name = NULL, *signature = NULL, *file_name = NULL; (*jvmti)->GetMethodName(jvmti, methodid, &name, &signature, 0); @@ -687,30 +702,32 @@ JNIEXPORT jboolean JNICALL Java_MyPackage_HeapMonitorThreadTest_checkSamples(JNIEnv* env, jclass cls, jintArray threads) { - jvmtiStackTraces traces; + jvmtiAllocTraceInfo* traces; + jint trace_counter; + ThreadsFound thread_data; thread_data.threads = (*env)->GetIntArrayElements(env, threads, 0); thread_data.num_threads = 0; // Get live and garbage traces to ensure we capture all the threads that have // been sampled. - if ((*jvmti)->GetLiveTraces(jvmti, &traces) != JVMTI_ERROR_NONE) { + if ((*jvmti)->GetObjectAllocTraces(jvmti, &traces, &trace_counter) != JVMTI_ERROR_NONE) { return FALSE; } - find_threads_in_traces(&traces, &thread_data); + find_threads_in_traces(traces, trace_counter, &thread_data); - if ((*jvmti)->ReleaseTraces(jvmti, &traces) != JVMTI_ERROR_NONE) { + if ((*jvmti)->Deallocate(jvmti, (unsigned char*) traces) != JVMTI_ERROR_NONE) { return FALSE; } - if ((*jvmti)->GetGarbageTraces(jvmti, &traces) != JVMTI_ERROR_NONE) { + if ((*jvmti)->GetGarbageTraces(jvmti, &traces, &trace_counter) != JVMTI_ERROR_NONE) { return FALSE; } - find_threads_in_traces(&traces, &thread_data); + find_threads_in_traces(traces, trace_counter, &thread_data); - if ((*jvmti)->ReleaseTraces(jvmti, &traces) != JVMTI_ERROR_NONE) { + if ((*jvmti)->Deallocate(jvmti, (unsigned char*) traces) != JVMTI_ERROR_NONE) { return FALSE; } @@ -721,30 +738,37 @@ JNIEXPORT void JNICALL Java_MyPackage_HeapMonitorCachedTest_getLiveTracesToForceGc(JNIEnv *env, jclass cls) { - jvmtiStackTraces live_traces; - jvmtiError error = (*jvmti)->GetLiveTraces(jvmti, &live_traces); + jvmtiAllocTraceInfo* traces; + jint trace_counter; + + jvmtiError error = (*jvmti)->GetObjectAllocTraces(jvmti, &traces, + &trace_counter); if (error != JVMTI_ERROR_NONE) { return; } - (*jvmti)->ReleaseTraces(jvmti, &live_traces); + (*jvmti)->Deallocate(jvmti, (unsigned char*) traces); } -static jboolean compare_traces(jvmtiStackTraces* traces, - jvmtiStackTraces* other_traces, +static jboolean compare_traces(jvmtiAllocTraceInfo* traces, + int trace_count, + jvmtiAllocTraceInfo* other_traces, + int other_trace_count, int print_out_comparisons) { - int trace_count = traces->trace_count; - if (trace_count != other_traces->trace_count) { + if (trace_count != other_trace_count) { return FALSE; } int i; for (i = 0; i < trace_count; i++) { - jvmtiStackTrace* trace = traces->stack_traces + i; - jvmtiStackTrace* other_trace = other_traces->stack_traces + i; + jvmtiAllocTraceInfo* trace = traces + i; + jvmtiAllocTraceInfo* other_trace = other_traces + i; - if (trace->frame_count != other_trace->frame_count) { + jvmtiStackInfo* stack_info = trace->stack_info; + jvmtiStackInfo* other_stack_info = trace->stack_info; + + if (stack_info->frame_count != other_stack_info->frame_count) { return FALSE; } @@ -756,9 +780,9 @@ return FALSE; } - jvmtiFrameInfo* frames = trace->frames; - jvmtiFrameInfo* other_frames = other_trace->frames; - if (memcmp(frames, other_frames, sizeof(*frames) * trace->frame_count)) { + jvmtiFrameInfo* frames = stack_info->frame_buffer; + jvmtiFrameInfo* other_frames = other_stack_info->frame_buffer; + if (memcmp(frames, other_frames, sizeof(*frames) * stack_info->frame_count)) { return FALSE; } } @@ -770,24 +794,34 @@ Java_MyPackage_HeapMonitorCachedTest_cachedAndLiveAreSame(JNIEnv *env, jclass cls) { // Get cached first, then get live (since live performs a GC). - jvmtiStackTraces cached_traces; - jvmtiError error = (*jvmti)->GetCachedTraces(jvmti, &cached_traces); + jvmtiAllocTraceInfo* cached_traces; + jint cached_trace_counter; + jvmtiError error = (*jvmti)->GetCachedObjectAllocTraces(jvmti, &cached_traces, + &cached_trace_counter); if (error != JVMTI_ERROR_NONE) { return FALSE; } - jvmtiStackTraces live_traces; - error = (*jvmti)->GetLiveTraces(jvmti, &live_traces); + jvmtiAllocTraceInfo* live_traces; + jint live_trace_counter; + error = (*jvmti)->GetObjectAllocTraces(jvmti, &live_traces, + &live_trace_counter); if (error != JVMTI_ERROR_NONE) { return FALSE; } - int result = compare_traces(&cached_traces, &live_traces, PRINT_OUT); + int result = compare_traces(cached_traces, cached_trace_counter, + live_traces, live_trace_counter, + PRINT_OUT); - (*jvmti)->ReleaseTraces(jvmti, &cached_traces); - (*jvmti)->ReleaseTraces(jvmti, &live_traces); + if ((*jvmti)->Deallocate(jvmti, (unsigned char*) cached_traces) != JVMTI_ERROR_NONE) { + return FALSE; + } + if ((*jvmti)->Deallocate(jvmti, (unsigned char*) live_traces) != JVMTI_ERROR_NONE) { + return FALSE; + } return result; } @@ -795,21 +829,22 @@ return hash_code * 31 + value; } -static long get_hash_code(jvmtiStackTraces* traces) { - int trace_count = traces->trace_count; +static long get_hash_code(jvmtiAllocTraceInfo* traces, jint trace_counter) { int hash_code = 17; + int i, j; + + hash_code = hash(hash_code, trace_counter); + for (i = 0; i < trace_counter; i++) { + jvmtiAllocTraceInfo* trace = traces + i; - int i; - hash_code = hash(hash_code, trace_count); - for (i = 0; i < trace_count; i++) { - jvmtiStackTrace* trace = traces->stack_traces + i; - hash_code = hash(hash_code, trace->frame_count); hash_code = hash(hash_code, trace->size); hash_code = hash(hash_code, trace->thread_id); - int j; - int frame_count = trace->frame_count; - jvmtiFrameInfo* frames = trace->frames; + jvmtiStackInfo* stack_info = trace->stack_info; + hash_code = hash(hash_code, stack_info->frame_count); + + int frame_count = stack_info->frame_count; + jvmtiFrameInfo* frames = stack_info->frame_buffer; hash_code = hash(hash_code, frame_count); for (j = 0; j < frame_count; j++) { hash_code = hash(hash_code, (long) frames[i].method); @@ -824,15 +859,20 @@ Java_MyPackage_HeapMonitorCachedTest_getCachedHashCode(JNIEnv *env, jclass cls) { // Get cached first, then get live. - jvmtiStackTraces cached_traces; - jvmtiError error = (*jvmti)->GetCachedTraces(jvmti, &cached_traces); + jvmtiAllocTraceInfo* cached_traces; + jint cached_trace_counter; + jvmtiError error = (*jvmti)->GetCachedObjectAllocTraces(jvmti, &cached_traces, + &cached_trace_counter); if (error != JVMTI_ERROR_NONE) { return 0; } - long hash_code = get_hash_code(&cached_traces); - (*jvmti)->ReleaseTraces(jvmti, &cached_traces); + long hash_code = get_hash_code(cached_traces, cached_trace_counter); + + if ((*jvmti)->Deallocate(jvmti, (unsigned char*) cached_traces) != JVMTI_ERROR_NONE) { + return FALSE; + } return hash_code; }