< 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,24 +176,28 @@
   const char *file_name;
   int line_number;
 } 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) {
       return FALSE;
     }

@@ -226,16 +230,16 @@
     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",
+      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,20 +253,24 @@
   }
 
   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,
                                 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++) {
-    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.
       return TRUE;
     }

@@ -273,30 +281,35 @@
 
 static jboolean
 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;
 }
 
 static jboolean frames_exist_live(JNIEnv* env,
                                   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);
 }
 
 static jboolean frames_exist_recent(JNIEnv* env,
                                     ExpectedContentFrame* expected,

@@ -536,32 +549,32 @@
   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),
+  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;
 }
 

@@ -592,44 +605,43 @@
               "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 (*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;
   }
 
   return sum / i;
 }
 
 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;
   }
 

@@ -637,30 +649,33 @@
   // in case.
   return calculate_average_stack_depth((*jvmti)->GetGarbageTraces);
 }
 
 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);
 
     if (strcmp(name, "helper")) {
       continue;

@@ -685,68 +700,77 @@
 }
 
 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;
   }
 
   (*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);
+  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;
+
+    jvmtiStackInfo* stack_info = trace->stack_info;
+    jvmtiStackInfo* other_stack_info = trace->stack_info;
 
-    if (trace->frame_count != other_trace->frame_count) {
+    if (stack_info->frame_count != other_stack_info->frame_count) {
       return FALSE;
     }
 
     if (trace->size != other_trace->size) {
       return FALSE;

@@ -754,13 +778,13 @@
 
     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)) {
+    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,50 +792,61 @@
 
 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);
+  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;
 }
 
 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;
+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);
       hash_code = hash(hash_code, frames[i].location);
     }

@@ -822,19 +857,24 @@
 
 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);
+  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;
 }
 
 JNIEXPORT jboolean JNICALL
< prev index next >