< prev index next >

test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/libHeapMonitorTest.cpp

Print this page

   1 /*
   2  * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright (c) 2018, Google and/or its affiliates. All rights reserved.
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   6  * This code is free software; you can redistribute it and/or modify it
   7  * under the terms of the GNU General Public License version 2 only, as
   8  * published by the Free Software Foundation.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.

 516 
 517   int current_count = storage->live_object_count;
 518   if (storage->live_objects != nullptr) {
 519     memcpy(new_objects, storage->live_objects, current_count * sizeof(*new_objects));
 520   }
 521   free(storage->live_objects);
 522   storage->live_objects = new_objects;
 523   storage->live_object_size = new_max;
 524 }
 525 
 526 static void event_storage_add(EventStorage* storage,
 527                               JNIEnv* jni,
 528                               jthread thread,
 529                               jobject object,
 530                               jclass klass,
 531                               jlong size) {
 532   jvmtiFrameInfo frames[64];
 533   jint count;
 534   jvmtiError err;
 535 





 536   err = jvmti->GetStackTrace(thread, 0, 64, frames, &count);
 537   if (err == JVMTI_ERROR_NONE && count >= 1) {
 538     ObjectTrace* live_object;
 539     jvmtiFrameInfo* allocated_frames = (jvmtiFrameInfo*) malloc(count * sizeof(*allocated_frames));
 540     memcpy(allocated_frames, frames, count * sizeof(*allocated_frames));
 541 
 542     live_object = (ObjectTrace*) malloc(sizeof(*live_object));
 543     live_object->frames = allocated_frames;
 544     live_object->frame_count = count;
 545     live_object->size = size;
 546     live_object->thread = thread;
 547     live_object->object = jni->NewWeakGlobalRef(object);
 548 
 549     if (jni->ExceptionOccurred()) {
 550       jni->FatalError("Error in event_storage_add: Exception in jni NewWeakGlobalRef");
 551     }
 552 
 553     // Only now lock and get things done quickly.
 554     event_storage_lock(storage);
 555 

   1 /*
   2  * Copyright (c) 2018, 2026, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright (c) 2018, Google and/or its affiliates. All rights reserved.
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   6  * This code is free software; you can redistribute it and/or modify it
   7  * under the terms of the GNU General Public License version 2 only, as
   8  * published by the Free Software Foundation.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.

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