< prev index next >
test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/libHeapMonitor.c
Print this page
rev 48551 : [mq]: heap8
rev 48552 : [mq]: heap10a
rev 48553 : [mq]: heap14_rebased
rev 48556 : [mq]: heap17
rev 48557 : [mq]: heap17
rev 48560 : [mq]: heap21
rev 48561 : [mq]: heap22
rev 48562 : [mq]: heap23
*** 176,199 ****
const char *file_name;
int line_number;
} ExpectedContentFrame;
static jboolean check_sample_content(JNIEnv *env,
! jvmtiStackTrace *trace,
ExpectedContentFrame *expected,
int expected_count,
int print_out_comparisons) {
int i;
! if (expected_count > trace->frame_count) {
return FALSE;
}
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;
char *name = NULL, *signature = NULL, *file_name = NULL;
if (bci < 0) {
return FALSE;
}
--- 176,203 ----
const char *file_name;
int line_number;
} ExpectedContentFrame;
static jboolean check_sample_content(JNIEnv *env,
! jvmtiAllocTraceInfo* trace,
ExpectedContentFrame *expected,
int expected_count,
int print_out_comparisons) {
int i;
! 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 = frames[i].location;
! jmethodID methodid = frames[i].method;
char *name = NULL, *signature = NULL, *file_name = NULL;
if (bci < 0) {
return FALSE;
}
*** 226,241 ****
if (signature == NULL) {
return FALSE;
}
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",
(strcmp(name, expected[i].name) ||
strcmp(signature, expected[i].signature) ||
strcmp(file_name, expected[i].file_name) ||
line_number != expected[i].line_number));
}
--- 230,245 ----
if (signature == NULL) {
return FALSE;
}
if (print_out_comparisons) {
! 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) ||
line_number != expected[i].line_number));
}
*** 249,268 ****
}
return TRUE;
}
! static jboolean compare_samples(JNIEnv* env, jvmtiStackTrace* traces,
int trace_count,
ExpectedContentFrame* expected_content,
size_t size,
int print_out_comparisons) {
// 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;
for (i = 0; i < trace_count; i++) {
! jvmtiStackTrace *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.
return TRUE;
}
--- 253,276 ----
}
return TRUE;
}
! static jboolean compare_samples(JNIEnv* env, jvmtiAllocTraceInfo* traces,
int trace_count,
ExpectedContentFrame* expected_content,
size_t size,
int print_out_comparisons) {
// 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++) {
! 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.
return TRUE;
}
*** 273,302 ****
static jboolean
check_samples(JNIEnv* env,
ExpectedContentFrame* expected,
size_t size,
! jvmtiError (*const get_traces)(jvmtiEnv*, jvmtiStackTraces*),
int print_out_comparisons) {
! jvmtiStackTraces traces;
! jvmtiError error = get_traces(jvmti, &traces);
if (error != JVMTI_ERROR_NONE) {
return FALSE;
}
! int result = compare_samples(env, traces.stack_traces, traces.trace_count,
expected, size, print_out_comparisons);
! (*jvmti)->ReleaseTraces(jvmti, &traces);
return result;
}
static jboolean frames_exist_live(JNIEnv* env,
ExpectedContentFrame* expected,
size_t size,
int print_out_comparisons) {
! return check_samples(env, expected, size, (*jvmti)->GetLiveTraces,
print_out_comparisons);
}
static jboolean frames_exist_recent(JNIEnv* env,
ExpectedContentFrame* expected,
--- 281,315 ----
static jboolean
check_samples(JNIEnv* env,
ExpectedContentFrame* expected,
size_t size,
! jvmtiError (*const get_traces)(jvmtiEnv*, jvmtiAllocTraceInfo**, jint*),
int print_out_comparisons) {
! 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, trace_counter,
expected, size, print_out_comparisons);
!
! if ((*jvmti)->Deallocate(jvmti, (unsigned char*) traces) != JVMTI_ERROR_NONE) {
! return FALSE;
! }
!
return result;
}
static jboolean frames_exist_live(JNIEnv* env,
ExpectedContentFrame* expected,
size_t size,
int print_out_comparisons) {
! return check_samples(env, expected, size, (*jvmti)->GetObjectAllocTraces,
print_out_comparisons);
}
static jboolean frames_exist_recent(JNIEnv* env,
ExpectedContentFrame* expected,
*** 536,567 ****
if (check_capability_error((*jvmti)->StopHeapSampling(jvmti),
"Stop Heap Sampling")) {
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),
"Get Garbage Traces")) {
return FALSE;
}
! if (check_capability_error((*jvmti)->GetFrequentGarbageTraces(jvmti, NULL),
"Get Frequent Garbage Traces")) {
return FALSE;
}
! if (check_capability_error((*jvmti)->GetLiveTraces(jvmti, NULL),
! "Get Live Traces")) {
return FALSE;
}
return TRUE;
}
--- 549,580 ----
if (check_capability_error((*jvmti)->StopHeapSampling(jvmti),
"Stop Heap Sampling")) {
return FALSE;
}
if (check_capability_error((*jvmti)->GetHeapSamplingStats(jvmti, NULL),
"Get Heap Sampling Stats")) {
return FALSE;
}
! if (check_capability_error((*jvmti)->GetGarbageTraces(jvmti, NULL, NULL),
"Get Garbage Traces")) {
return FALSE;
}
! if (check_capability_error((*jvmti)->GetFrequentGarbageTraces(jvmti, NULL, NULL),
"Get Frequent Garbage Traces")) {
return FALSE;
}
! 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;
}
*** 592,635 ****
"Heap Sampling Statistics");
return ((double) stats.sample_rate_accumulation) / stats.sample_rate_count;
}
static double calculate_average_stack_depth(
! jvmtiError (*const get_traces)(jvmtiEnv*, jvmtiStackTraces*)) {
! jvmtiStackTraces traces;
! jvmtiError error = get_traces(jvmti, &traces);;
if (error != JVMTI_ERROR_NONE) {
return 0;
}
! int trace_count = traces.trace_count;
!
! if (trace_count == 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;
}
! if ((*jvmti)->ReleaseTraces(jvmti, &traces) != JVMTI_ERROR_NONE) {
return 0;
}
return sum / i;
}
JNIEXPORT jdouble JNICALL
Java_MyPackage_HeapMonitorStackDepthTest_getAverageStackDepth(JNIEnv *env,
jclass cls) {
! double result = calculate_average_stack_depth((*jvmti)->GetLiveTraces);
if (result != 0) {
return result;
}
--- 605,647 ----
"Heap Sampling Statistics");
return ((double) stats.sample_rate_accumulation) / stats.sample_rate_count;
}
static double calculate_average_stack_depth(
! jvmtiError (*const get_traces)(jvmtiEnv*, jvmtiAllocTraceInfo**, jint*)) {
! jvmtiAllocTraceInfo* traces = NULL;
! jint trace_counter;
! jvmtiError error = get_traces(jvmti, &traces, &trace_counter);;
if (error != JVMTI_ERROR_NONE) {
return 0;
}
! if (trace_counter == 0) {
return 0;
}
int i;
double sum = 0;
! for (i = 0; i < trace_counter; i++) {
! jvmtiAllocTraceInfo* trace = traces + i;
! jvmtiStackInfo* stack_info = trace->stack_info;
! sum += stack_info->frame_count;
}
! if ((*jvmti)->Deallocate(jvmti, (unsigned char*) traces) != JVMTI_ERROR_NONE) {
return 0;
}
return sum / i;
}
JNIEXPORT jdouble JNICALL
Java_MyPackage_HeapMonitorStackDepthTest_getAverageStackDepth(JNIEnv *env,
jclass cls) {
! double result = calculate_average_stack_depth((*jvmti)->GetObjectAllocTraces);
if (result != 0) {
return result;
}
*** 637,666 ****
// in case.
return calculate_average_stack_depth((*jvmti)->GetGarbageTraces);
}
typedef struct sThreadsFound {
! jint *threads;
int num_threads;
} ThreadsFound;
! static void find_threads_in_traces(jvmtiStackTraces* traces,
ThreadsFound* thread_data) {
int i;
! jvmtiStackTrace* stack_traces = traces->stack_traces;
! int trace_count = traces->trace_count;
!
! 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;
// Check it is the right frame: only accept helper top framed traces.
! jmethodID methodid = stack_trace->frames[0].method;
char *name = NULL, *signature = NULL, *file_name = NULL;
(*jvmti)->GetMethodName(jvmti, methodid, &name, &signature, 0);
if (strcmp(name, "helper")) {
continue;
--- 649,681 ----
// in case.
return calculate_average_stack_depth((*jvmti)->GetGarbageTraces);
}
typedef struct sThreadsFound {
! jint* threads;
int num_threads;
} ThreadsFound;
! static void find_threads_in_traces(jvmtiAllocTraceInfo* traces,
! jint trace_counter,
ThreadsFound* thread_data) {
int i;
! 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_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.
! 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);
if (strcmp(name, "helper")) {
continue;
*** 685,752 ****
}
JNIEXPORT jboolean JNICALL
Java_MyPackage_HeapMonitorThreadTest_checkSamples(JNIEnv* env, jclass cls,
jintArray threads) {
! jvmtiStackTraces traces;
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) {
return FALSE;
}
! find_threads_in_traces(&traces, &thread_data);
! if ((*jvmti)->ReleaseTraces(jvmti, &traces) != JVMTI_ERROR_NONE) {
return FALSE;
}
! if ((*jvmti)->GetGarbageTraces(jvmti, &traces) != JVMTI_ERROR_NONE) {
return FALSE;
}
! find_threads_in_traces(&traces, &thread_data);
! if ((*jvmti)->ReleaseTraces(jvmti, &traces) != JVMTI_ERROR_NONE) {
return FALSE;
}
(*env)->ReleaseIntArrayElements(env, threads, thread_data.threads, 0);
return TRUE;
}
JNIEXPORT void JNICALL
Java_MyPackage_HeapMonitorCachedTest_getLiveTracesToForceGc(JNIEnv *env,
jclass cls) {
! jvmtiStackTraces live_traces;
! jvmtiError error = (*jvmti)->GetLiveTraces(jvmti, &live_traces);
if (error != JVMTI_ERROR_NONE) {
return;
}
! (*jvmti)->ReleaseTraces(jvmti, &live_traces);
}
! static jboolean compare_traces(jvmtiStackTraces* traces,
! jvmtiStackTraces* other_traces,
int print_out_comparisons) {
! int trace_count = traces->trace_count;
! if (trace_count != other_traces->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;
! if (trace->frame_count != other_trace->frame_count) {
return FALSE;
}
if (trace->size != other_trace->size) {
return FALSE;
--- 700,776 ----
}
JNIEXPORT jboolean JNICALL
Java_MyPackage_HeapMonitorThreadTest_checkSamples(JNIEnv* env, jclass cls,
jintArray threads) {
! 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)->GetObjectAllocTraces(jvmti, &traces, &trace_counter) != JVMTI_ERROR_NONE) {
return FALSE;
}
! find_threads_in_traces(traces, trace_counter, &thread_data);
! if ((*jvmti)->Deallocate(jvmti, (unsigned char*) traces) != JVMTI_ERROR_NONE) {
return FALSE;
}
! if ((*jvmti)->GetGarbageTraces(jvmti, &traces, &trace_counter) != JVMTI_ERROR_NONE) {
return FALSE;
}
! find_threads_in_traces(traces, trace_counter, &thread_data);
! if ((*jvmti)->Deallocate(jvmti, (unsigned char*) traces) != JVMTI_ERROR_NONE) {
return FALSE;
}
(*env)->ReleaseIntArrayElements(env, threads, thread_data.threads, 0);
return TRUE;
}
JNIEXPORT void JNICALL
Java_MyPackage_HeapMonitorCachedTest_getLiveTracesToForceGc(JNIEnv *env,
jclass cls) {
! jvmtiAllocTraceInfo* traces;
! jint trace_counter;
!
! jvmtiError error = (*jvmti)->GetObjectAllocTraces(jvmti, &traces,
! &trace_counter);
if (error != JVMTI_ERROR_NONE) {
return;
}
! (*jvmti)->Deallocate(jvmti, (unsigned char*) traces);
}
! static jboolean compare_traces(jvmtiAllocTraceInfo* traces,
! int trace_count,
! jvmtiAllocTraceInfo* other_traces,
! int other_trace_count,
int print_out_comparisons) {
! if (trace_count != other_trace_count) {
return FALSE;
}
int i;
for (i = 0; i < trace_count; i++) {
! jvmtiAllocTraceInfo* trace = traces + i;
! jvmtiAllocTraceInfo* other_trace = other_traces + i;
!
! 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;
}
if (trace->size != other_trace->size) {
return FALSE;
*** 754,766 ****
if (trace->thread_id != other_trace->thread_id) {
return FALSE;
}
! jvmtiFrameInfo* frames = trace->frames;
! jvmtiFrameInfo* other_frames = other_trace->frames;
! if (memcmp(frames, other_frames, sizeof(*frames) * trace->frame_count)) {
return FALSE;
}
}
return TRUE;
--- 778,790 ----
if (trace->thread_id != other_trace->thread_id) {
return FALSE;
}
! 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;
}
}
return TRUE;
*** 768,817 ****
JNIEXPORT jboolean JNICALL
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);
if (error != JVMTI_ERROR_NONE) {
return FALSE;
}
! jvmtiStackTraces live_traces;
! error = (*jvmti)->GetLiveTraces(jvmti, &live_traces);
if (error != JVMTI_ERROR_NONE) {
return FALSE;
}
! int result = compare_traces(&cached_traces, &live_traces, PRINT_OUT);
! (*jvmti)->ReleaseTraces(jvmti, &cached_traces);
! (*jvmti)->ReleaseTraces(jvmti, &live_traces);
return result;
}
static long hash(long hash_code, long value) {
return hash_code * 31 + value;
}
! static long get_hash_code(jvmtiStackTraces* traces) {
! int trace_count = traces->trace_count;
int hash_code = 17;
- 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;
hash_code = hash(hash_code, frame_count);
for (j = 0; j < frame_count; j++) {
hash_code = hash(hash_code, (long) frames[i].method);
hash_code = hash(hash_code, frames[i].location);
}
--- 792,852 ----
JNIEXPORT jboolean JNICALL
Java_MyPackage_HeapMonitorCachedTest_cachedAndLiveAreSame(JNIEnv *env,
jclass cls) {
// Get cached first, then get live (since live performs a GC).
! jvmtiAllocTraceInfo* cached_traces;
! jint cached_trace_counter;
! jvmtiError error = (*jvmti)->GetCachedObjectAllocTraces(jvmti, &cached_traces,
! &cached_trace_counter);
if (error != JVMTI_ERROR_NONE) {
return FALSE;
}
! 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, cached_trace_counter,
! live_traces, live_trace_counter,
! PRINT_OUT);
! 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;
}
static long hash(long hash_code, long value) {
return hash_code * 31 + value;
}
! 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;
hash_code = hash(hash_code, trace->size);
hash_code = hash(hash_code, trace->thread_id);
! 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);
hash_code = hash(hash_code, frames[i].location);
}
*** 822,840 ****
JNIEXPORT jlong JNICALL
Java_MyPackage_HeapMonitorCachedTest_getCachedHashCode(JNIEnv *env,
jclass cls) {
// Get cached first, then get live.
! jvmtiStackTraces cached_traces;
! jvmtiError error = (*jvmti)->GetCachedTraces(jvmti, &cached_traces);
if (error != JVMTI_ERROR_NONE) {
return 0;
}
! long hash_code = get_hash_code(&cached_traces);
! (*jvmti)->ReleaseTraces(jvmti, &cached_traces);
return hash_code;
}
JNIEXPORT jboolean JNICALL
--- 857,880 ----
JNIEXPORT jlong JNICALL
Java_MyPackage_HeapMonitorCachedTest_getCachedHashCode(JNIEnv *env,
jclass cls) {
// Get cached first, then get live.
! 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, cached_trace_counter);
!
! if ((*jvmti)->Deallocate(jvmti, (unsigned char*) cached_traces) != JVMTI_ERROR_NONE) {
! return FALSE;
! }
return hash_code;
}
JNIEXPORT jboolean JNICALL
< prev index next >