512
513 int current_count = storage->live_object_count;
514 if (storage->live_objects != nullptr) {
515 memcpy(new_objects, storage->live_objects, current_count * sizeof(*new_objects));
516 }
517 free(storage->live_objects);
518 storage->live_objects = new_objects;
519 storage->live_object_size = new_max;
520 }
521
522 static void event_storage_add(EventStorage* storage,
523 JNIEnv* jni,
524 jthread thread,
525 jobject object,
526 jclass klass,
527 jlong size) {
528 jvmtiFrameInfo frames[64];
529 jint count;
530 jvmtiError err;
531
532 err = jvmti->GetStackTrace(thread, 0, 64, frames, &count);
533 if (err == JVMTI_ERROR_NONE && count >= 1) {
534 ObjectTrace* live_object;
535 jvmtiFrameInfo* allocated_frames = (jvmtiFrameInfo*) malloc(count * sizeof(*allocated_frames));
536 memcpy(allocated_frames, frames, count * sizeof(*allocated_frames));
537
538 live_object = (ObjectTrace*) malloc(sizeof(*live_object));
539 live_object->frames = allocated_frames;
540 live_object->frame_count = count;
541 live_object->size = size;
542 live_object->thread = thread;
543 live_object->object = jni->NewWeakGlobalRef(object);
544
545 if (jni->ExceptionOccurred()) {
546 jni->FatalError("Error in event_storage_add: Exception in jni NewWeakGlobalRef");
547 }
548
549 // Only now lock and get things done quickly.
550 event_storage_lock(storage);
551
|
512
513 int current_count = storage->live_object_count;
514 if (storage->live_objects != nullptr) {
515 memcpy(new_objects, storage->live_objects, current_count * sizeof(*new_objects));
516 }
517 free(storage->live_objects);
518 storage->live_objects = new_objects;
519 storage->live_object_size = new_max;
520 }
521
522 static void event_storage_add(EventStorage* storage,
523 JNIEnv* jni,
524 jthread thread,
525 jobject object,
526 jclass klass,
527 jlong size) {
528 jvmtiFrameInfo frames[64];
529 jint count;
530 jvmtiError err;
531
532 if (!jni->HasIdentity(object)) {
533 // weak references are prohibited for non-identity objects, skip them
534 return;
535 }
536
537 err = jvmti->GetStackTrace(thread, 0, 64, frames, &count);
538 if (err == JVMTI_ERROR_NONE && count >= 1) {
539 ObjectTrace* live_object;
540 jvmtiFrameInfo* allocated_frames = (jvmtiFrameInfo*) malloc(count * sizeof(*allocated_frames));
541 memcpy(allocated_frames, frames, count * sizeof(*allocated_frames));
542
543 live_object = (ObjectTrace*) malloc(sizeof(*live_object));
544 live_object->frames = allocated_frames;
545 live_object->frame_count = count;
546 live_object->size = size;
547 live_object->thread = thread;
548 live_object->object = jni->NewWeakGlobalRef(object);
549
550 if (jni->ExceptionOccurred()) {
551 jni->FatalError("Error in event_storage_add: Exception in jni NewWeakGlobalRef");
552 }
553
554 // Only now lock and get things done quickly.
555 event_storage_lock(storage);
556
|