< prev index next >

src/hotspot/share/gc/shared/memAllocator.cpp

Print this page
rev 52132 : 8201655: Add thread-enabled support for the Heap Sampling
Summary:
Reviewed-by:

*** 30,39 **** --- 30,41 ---- #include "gc/shared/threadLocalAllocBuffer.inline.hpp" #include "memory/universe.hpp" #include "oops/arrayOop.hpp" #include "oops/oop.inline.hpp" #include "prims/jvmtiExport.hpp" + #include "prims/jvmtiEventController.inline.hpp" + #include "prims/jvmtiThreadState.inline.hpp" #include "runtime/sharedRuntime.hpp" #include "runtime/handles.inline.hpp" #include "runtime/thread.inline.hpp" #include "services/lowMemoryDetector.hpp" #include "utilities/align.hpp"
*** 181,199 **** --- 183,223 ---- _thread->check_for_valid_safepoint_state(true); } } #endif + static bool thread_enabled_for_one_jvmti_env() { + JavaThread *thread = JavaThread::current(); + JvmtiThreadState *state = thread->jvmti_thread_state(); + if (state == NULL) { + return false; + } + + JvmtiEnvThreadStateIterator it(state); + for (JvmtiEnvThreadState* ets = it.first(); ets != NULL; ets = it.next(ets)) { + if (ets->is_enabled(JVMTI_EVENT_SAMPLED_OBJECT_ALLOC)) { + return true; + } + } + + return false; + } + void MemAllocator::Allocation::notify_allocation_jvmti_sampler() { // support for JVMTI VMObjectAlloc event (no-op if not enabled) JvmtiExport::vm_object_alloc_event_collector(obj()); if (!JvmtiExport::should_post_sampled_object_alloc()) { // Sampling disabled return; } + // Sampling is enabled for at least one thread, is it this one? + if (!thread_enabled_for_one_jvmti_env()) { + return; + } + if (!_allocated_outside_tlab && _allocated_tlab_size == 0 && !_tlab_end_reset_for_sample) { // Sample if it's a non-TLAB allocation, or a TLAB allocation that either refills the TLAB // or expands it due to taking a sampler induced slow path. return; }
< prev index next >