/* * Copyright (c) 2017, Google and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. * */ #ifndef SHARE_VM_RUNTIME_HEAPMONITORING_HPP #define SHARE_VM_RUNTIME_HEAPMONITORING_HPP #include "gc/shared/referenceProcessor.hpp" #include "runtime/sharedRuntime.hpp" // Support class for sampling heap allocations across the VM. class HeapMonitoring : AllStatic { private: // Cheap random number generator static uint64_t _rnd; static jint _monitoring_rate; static bool _enabled; // Statics for the fast log static const int FastLogNumBits = 10; static const int FastLogMask = (1 << FastLogNumBits) - 1; static double _log_table[1<0, "bad value passed to assert"); uint64_t x = 0; memcpy(&x, &d, sizeof(uint64_t)); const uint32_t x_high = x >> 32; const uint32_t y = x_high >> (20 - FastLogNumBits) & FastLogMask; const int32_t exponent = ((x_high >> 20) & 0x7FF) - 1023; return exponent + _log_table[y]; } public: /* * General note: currently none of these methods are deemed thread-safe. */ // First method called by user to start the profiler: // - Note: the lower the monitoring rate, the higher the overhead incurred. static void initialize_profiling(jint monitoring_rate, jint max_gc_storage); // Pick the next sample for a given size_t pointer using a geometric variable // with specified mean. The specified mean is provided via the // initialize_profiling method. static void pick_next_sample(size_t* ptr); // Get live/garbage traces and provide a method to release the traces. static void get_live_traces(jvmtiStackTraces* stack_traces); static void get_garbage_traces(jvmtiStackTraces* stack_traces); static void get_frequent_garbage_traces(jvmtiStackTraces* stack_traces); static void get_cached_traces(jvmtiStackTraces* stack_traces); static void release_traces(jvmtiStackTraces* trace_info); static void get_sampling_statistics(jvmtiHeapSamplingStats* stats); static void stop_profiling(); // Called when o is to be sampled from a given thread and a given size. static void object_alloc_do_sample(Thread* t, oopDesc* o, intx size_in_bytes); // Called to clean up oops that have been saved by our sampling function, // but which no longer have other references in the heap. static void weak_oops_do(BoolObjectClosure* is_alive, OopClosure* f); static void weak_oops_do(OopClosure* oop_closure) { AlwaysTrueClosure _always_true; weak_oops_do(&_always_true, oop_closure); } static bool enabled() { return _enabled; } }; #endif // SHARE_VM_RUNTIME_HEAPMONITORING_HPP