zgu@3900: /* zgu@5272: * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. zgu@3900: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. zgu@3900: * zgu@3900: * This code is free software; you can redistribute it and/or modify it zgu@3900: * under the terms of the GNU General Public License version 2 only, as zgu@3900: * published by the Free Software Foundation. zgu@3900: * zgu@3900: * This code is distributed in the hope that it will be useful, but WITHOUT zgu@3900: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or zgu@3900: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License zgu@3900: * version 2 for more details (a copy is included in the LICENSE file that zgu@3900: * accompanied this code). zgu@3900: * zgu@3900: * You should have received a copy of the GNU General Public License version zgu@3900: * 2 along with this work; if not, write to the Free Software Foundation, zgu@3900: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. zgu@3900: * zgu@3900: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA zgu@3900: * or visit www.oracle.com if you need additional information or have any zgu@3900: * questions. zgu@3900: * zgu@3900: */ zgu@3900: zgu@3900: #ifndef SHARE_VM_SERVICES_MEM_TRACKER_HPP zgu@3900: #define SHARE_VM_SERVICES_MEM_TRACKER_HPP zgu@3900: jprovino@4165: #include "utilities/macros.hpp" jprovino@4165: jprovino@4165: #if !INCLUDE_NMT jprovino@4165: jprovino@4165: #include "utilities/ostream.hpp" jprovino@4165: jprovino@4165: class BaselineOutputer : public StackObj { jprovino@4165: jprovino@4165: }; jprovino@4165: jprovino@4165: class BaselineTTYOutputer : public BaselineOutputer { jprovino@4165: public: jprovino@4165: BaselineTTYOutputer(outputStream* st) { } jprovino@4165: }; jprovino@4165: jprovino@4165: class MemTracker : AllStatic { jprovino@4165: public: jprovino@4165: enum ShutdownReason { jprovino@4165: NMT_shutdown_none, // no shutdown requested jprovino@4165: NMT_shutdown_user, // user requested shutdown jprovino@4165: NMT_normal, // normal shutdown, process exit jprovino@4165: NMT_out_of_memory, // shutdown due to out of memory jprovino@4165: NMT_initialization, // shutdown due to initialization failure jprovino@4165: NMT_use_malloc_only, // can not combine NMT with UseMallocOnly flag jprovino@4165: NMT_error_reporting, // shutdown by vmError::report_and_die() jprovino@4165: NMT_out_of_generation, // running out of generation queue jprovino@4165: NMT_sequence_overflow // overflow the sequence number jprovino@4165: }; jprovino@4165: zgu@5272: class Tracker { zgu@5272: public: zgu@5272: void discard() { } zgu@5272: zgu@5272: void record(address addr, size_t size = 0, MEMFLAGS flags = mtNone, address pc = NULL) { } zgu@5272: void record(address old_addr, address new_addr, size_t size, zgu@5272: MEMFLAGS flags, address pc = NULL) { } zgu@5272: }; zgu@5272: zgu@5272: private: zgu@5272: static Tracker _tkr; zgu@5272: jprovino@4165: jprovino@4165: public: jprovino@4165: static inline void init_tracking_options(const char* option_line) { } jprovino@4165: static inline bool is_on() { return false; } jprovino@4165: static const char* reason() { return "Native memory tracking is not implemented"; } jprovino@4165: static inline bool can_walk_stack() { return false; } jprovino@4165: jprovino@4165: static inline void bootstrap_single_thread() { } jprovino@4165: static inline void bootstrap_multi_thread() { } jprovino@4165: static inline void start() { } jprovino@4165: jprovino@4165: static inline void record_malloc(address addr, size_t size, MEMFLAGS flags, jprovino@4165: address pc = 0, Thread* thread = NULL) { } jprovino@4165: static inline void record_free(address addr, MEMFLAGS flags, Thread* thread = NULL) { } jprovino@4165: static inline void record_arena_size(address addr, size_t size) { } jprovino@4165: static inline void record_virtual_memory_reserve(address addr, size_t size, zgu@5272: MEMFLAGS flags, address pc = 0, Thread* thread = NULL) { } zgu@5272: static inline void record_virtual_memory_reserve_and_commit(address addr, size_t size, zgu@5272: MEMFLAGS flags, address pc = 0, Thread* thread = NULL) { } jprovino@4165: static inline void record_virtual_memory_commit(address addr, size_t size, jprovino@4165: address pc = 0, Thread* thread = NULL) { } jprovino@4165: static inline void record_virtual_memory_type(address base, MEMFLAGS flags, jprovino@4165: Thread* thread = NULL) { } zgu@5272: static inline Tracker get_realloc_tracker() { return _tkr; } zgu@5272: static inline Tracker get_virtual_memory_uncommit_tracker() { return _tkr; } zgu@5272: static inline Tracker get_virtual_memory_release_tracker() { return _tkr; } jprovino@4165: static inline bool baseline() { return false; } jprovino@4165: static inline bool has_baseline() { return false; } jprovino@4165: zgu@4810: static inline void set_autoShutdown(bool value) { } jprovino@4165: static void shutdown(ShutdownReason reason) { } zgu@4842: static inline bool shutdown_in_progress() { return false; } jprovino@4165: static bool print_memory_usage(BaselineOutputer& out, size_t unit, zgu@4842: bool summary_only = true) { return false; } jprovino@4165: static bool compare_memory_usage(BaselineOutputer& out, size_t unit, zgu@4842: bool summary_only = true) { return false; } jprovino@4165: zgu@4842: static bool wbtest_wait_for_data_merge() { return false; } ctornqvi@4512: jprovino@4165: static inline void sync() { } jprovino@4165: static inline void thread_exiting(JavaThread* thread) { } jprovino@4165: }; jprovino@4165: jprovino@4165: jprovino@4165: #else // !INCLUDE_NMT jprovino@4165: zgu@3900: #include "memory/allocation.hpp" zgu@3900: #include "runtime/globals.hpp" zgu@3900: #include "runtime/mutex.hpp" zgu@3900: #include "runtime/os.hpp" zgu@3900: #include "runtime/thread.hpp" zgu@3900: #include "services/memPtr.hpp" zgu@3900: #include "services/memRecorder.hpp" zgu@3900: #include "services/memSnapshot.hpp" zgu@3900: #include "services/memTrackWorker.hpp" zgu@3900: zgu@4193: extern bool NMT_track_callsite; zgu@4193: ctornqvi@4512: #ifndef MAX_UNSIGNED_LONG ctornqvi@4512: #define MAX_UNSIGNED_LONG (unsigned long)(-1) ctornqvi@4512: #endif ctornqvi@4512: zgu@4193: #ifdef ASSERT zgu@4193: #define DEBUG_CALLER_PC (NMT_track_callsite ? os::get_caller_pc(2) : 0) zgu@3900: #else zgu@3900: #define DEBUG_CALLER_PC 0 zgu@3900: #endif zgu@3900: zgu@3900: // The thread closure walks threads to collect per-thread zgu@3900: // memory recorders at NMT sync point zgu@3900: class SyncThreadRecorderClosure : public ThreadClosure { zgu@3900: private: zgu@3900: int _thread_count; zgu@3900: zgu@3900: public: zgu@3900: SyncThreadRecorderClosure() { zgu@3900: _thread_count =0; zgu@3900: } zgu@3900: zgu@3900: void do_thread(Thread* thread); zgu@3900: int get_thread_count() const { zgu@3900: return _thread_count; zgu@3900: } zgu@3900: }; zgu@3900: zgu@3900: class BaselineOutputer; zgu@3900: class MemSnapshot; zgu@3900: class MemTrackWorker; zgu@3900: class Thread; zgu@3900: /* zgu@3900: * MemTracker is the 'gate' class to native memory tracking runtime. zgu@3900: */ zgu@3900: class MemTracker : AllStatic { zgu@4400: friend class GenerationData; zgu@3900: friend class MemTrackWorker; zgu@3900: friend class MemSnapshot; zgu@3900: friend class SyncThreadRecorderClosure; zgu@3900: zgu@3900: // NMT state zgu@3900: enum NMTStates { zgu@3900: NMT_uninited, // not yet initialized zgu@3900: NMT_bootstrapping_single_thread, // bootstrapping, VM is in single thread mode zgu@3900: NMT_bootstrapping_multi_thread, // bootstrapping, VM is about to enter multi-thread mode zgu@3900: NMT_started, // NMT fully started zgu@3900: NMT_shutdown_pending, // shutdown pending zgu@3900: NMT_final_shutdown, // in final phase of shutdown zgu@3900: NMT_shutdown // shutdown zgu@3900: }; zgu@3900: zgu@4081: public: zgu@5272: class Tracker : public StackObj { zgu@5272: friend class MemTracker; zgu@5272: public: zgu@5272: enum MemoryOperation { zgu@5272: NoOp, // no op zgu@5272: Malloc, // malloc zgu@5272: Realloc, // realloc zgu@5272: Free, // free zgu@5272: Reserve, // virtual memory reserve zgu@5272: Commit, // virtual memory commit zgu@5272: ReserveAndCommit, // virtual memory reserve and commit zgu@5272: StackAlloc = ReserveAndCommit, // allocate thread stack zgu@5272: Type, // assign virtual memory type zgu@5272: Uncommit, // virtual memory uncommit zgu@5272: Release, // virtual memory release zgu@5272: ArenaSize, // set arena size zgu@5272: StackRelease // release thread stack zgu@5272: }; zgu@5272: zgu@5272: zgu@5272: protected: zgu@5272: Tracker(MemoryOperation op, Thread* thr = NULL); zgu@5272: zgu@5272: public: zgu@5272: void discard(); zgu@5272: zgu@5272: void record(address addr, size_t size = 0, MEMFLAGS flags = mtNone, address pc = NULL); zgu@5272: void record(address old_addr, address new_addr, size_t size, zgu@5272: MEMFLAGS flags, address pc = NULL); zgu@5272: zgu@5272: private: zgu@5272: bool _need_thread_critical_lock; zgu@5272: JavaThread* _java_thread; zgu@5272: MemoryOperation _op; // memory operation zgu@5272: jint _seq; // reserved sequence number zgu@5272: }; zgu@5272: zgu@5272: zgu@5272: public: zgu@3900: // native memory tracking level zgu@3900: enum NMTLevel { zgu@3900: NMT_off, // native memory tracking is off zgu@3900: NMT_summary, // don't track callsite zgu@3900: NMT_detail // track callsite also zgu@3900: }; zgu@3900: zgu@3900: enum ShutdownReason { zgu@3900: NMT_shutdown_none, // no shutdown requested zgu@3900: NMT_shutdown_user, // user requested shutdown zgu@3900: NMT_normal, // normal shutdown, process exit zgu@3900: NMT_out_of_memory, // shutdown due to out of memory zgu@3900: NMT_initialization, // shutdown due to initialization failure zgu@3900: NMT_use_malloc_only, // can not combine NMT with UseMallocOnly flag zgu@3900: NMT_error_reporting, // shutdown by vmError::report_and_die() zgu@3900: NMT_out_of_generation, // running out of generation queue zgu@3900: NMT_sequence_overflow // overflow the sequence number zgu@3900: }; zgu@3900: zgu@3900: public: zgu@3900: // initialize NMT tracking level from command line options, called zgu@3900: // from VM command line parsing code zgu@3900: static void init_tracking_options(const char* option_line); zgu@3900: zgu@3900: // if NMT is enabled to record memory activities zgu@3900: static inline bool is_on() { zgu@3900: return (_tracking_level >= NMT_summary && zgu@3900: _state >= NMT_bootstrapping_single_thread); zgu@3900: } zgu@3900: zgu@4081: static inline enum NMTLevel tracking_level() { zgu@4081: return _tracking_level; zgu@4081: } zgu@4081: zgu@3900: // user readable reason for shutting down NMT zgu@3900: static const char* reason() { zgu@3900: switch(_reason) { zgu@3900: case NMT_shutdown_none: zgu@3900: return "Native memory tracking is not enabled"; zgu@3900: case NMT_shutdown_user: zgu@3900: return "Native memory tracking has been shutdown by user"; zgu@3900: case NMT_normal: zgu@3900: return "Native memory tracking has been shutdown due to process exiting"; zgu@3936: case NMT_out_of_memory: zgu@3936: return "Native memory tracking has been shutdown due to out of native memory"; zgu@3900: case NMT_initialization: zgu@3900: return "Native memory tracking failed to initialize"; zgu@3900: case NMT_error_reporting: zgu@3900: return "Native memory tracking has been shutdown due to error reporting"; zgu@3900: case NMT_out_of_generation: zgu@3900: return "Native memory tracking has been shutdown due to running out of generation buffer"; zgu@3900: case NMT_sequence_overflow: zgu@3900: return "Native memory tracking has been shutdown due to overflow the sequence number"; zgu@3900: case NMT_use_malloc_only: zgu@3900: return "Native memory tracking is not supported when UseMallocOnly is on"; zgu@3900: default: zgu@3900: ShouldNotReachHere(); zgu@3900: return NULL; zgu@3900: } zgu@3900: } zgu@3900: zgu@3900: // test if we can walk native stack zgu@3900: static bool can_walk_stack() { zgu@3900: // native stack is not walkable during bootstrapping on sparc zgu@3900: #if defined(SPARC) zgu@3900: return (_state == NMT_started); zgu@3900: #else zgu@3900: return (_state >= NMT_bootstrapping_single_thread && _state <= NMT_started); zgu@3900: #endif zgu@3900: } zgu@3900: zgu@3900: // if native memory tracking tracks callsite zgu@3900: static inline bool track_callsite() { return _tracking_level == NMT_detail; } zgu@3900: zgu@4810: // NMT automatically shuts itself down under extreme situation by default. zgu@4810: // When the value is set to false, NMT will try its best to stay alive, zgu@4810: // even it has to slow down VM. zgu@4810: static inline void set_autoShutdown(bool value) { zgu@4810: AutoShutdownNMT = value; zgu@4810: if (AutoShutdownNMT && _slowdown_calling_thread) { zgu@4810: _slowdown_calling_thread = false; zgu@4810: } zgu@4810: } zgu@4810: zgu@3900: // shutdown native memory tracking capability. Native memory tracking zgu@3900: // can be shutdown by VM when it encounters low memory scenarios. zgu@3900: // Memory tracker should gracefully shutdown itself, and preserve the zgu@3900: // latest memory statistics for post morten diagnosis. zgu@3900: static void shutdown(ShutdownReason reason); zgu@3900: zgu@3900: // if there is shutdown requested zgu@3900: static inline bool shutdown_in_progress() { zgu@3900: return (_state >= NMT_shutdown_pending); zgu@3900: } zgu@3900: zgu@3900: // bootstrap native memory tracking, so it can start to collect raw data zgu@3900: // before worker thread can start zgu@3900: zgu@3900: // the first phase of bootstrapping, when VM still in single-threaded mode zgu@3900: static void bootstrap_single_thread(); zgu@3900: // the second phase of bootstrapping, VM is about or already in multi-threaded mode zgu@3900: static void bootstrap_multi_thread(); zgu@3900: zgu@3900: zgu@3900: // start() has to be called when VM still in single thread mode, but after zgu@3900: // command line option parsing is done. zgu@3900: static void start(); zgu@3900: zgu@3900: // record a 'malloc' call zgu@3900: static inline void record_malloc(address addr, size_t size, MEMFLAGS flags, zgu@3900: address pc = 0, Thread* thread = NULL) { zgu@5272: Tracker tkr(Tracker::Malloc, thread); zgu@5272: tkr.record(addr, size, flags, pc); zgu@3900: } zgu@3900: // record a 'free' call zgu@3900: static inline void record_free(address addr, MEMFLAGS flags, Thread* thread = NULL) { zgu@5272: Tracker tkr(Tracker::Free, thread); zgu@5272: tkr.record(addr, 0, flags, DEBUG_CALLER_PC); zgu@3900: } zgu@3900: zgu@3900: static inline void record_arena_size(address addr, size_t size) { zgu@5272: Tracker tkr(Tracker::ArenaSize); zgu@5272: tkr.record(addr, size); zgu@3900: } zgu@3900: zgu@3900: // record a virtual memory 'reserve' call zgu@3900: static inline void record_virtual_memory_reserve(address addr, size_t size, zgu@5272: MEMFLAGS flags, address pc = 0, Thread* thread = NULL) { zgu@5272: assert(size > 0, "Sanity check"); zgu@5272: Tracker tkr(Tracker::Reserve, thread); zgu@5272: tkr.record(addr, size, flags, pc); zgu@3900: } zgu@3900: zgu@4053: static inline void record_thread_stack(address addr, size_t size, Thread* thr, zgu@4053: address pc = 0) { zgu@5272: Tracker tkr(Tracker::StackAlloc, thr); zgu@5272: tkr.record(addr, size, mtThreadStack, pc); zgu@4053: } zgu@4053: zgu@4053: static inline void release_thread_stack(address addr, size_t size, Thread* thr) { zgu@5272: Tracker tkr(Tracker::StackRelease, thr); zgu@5272: tkr.record(addr, size, mtThreadStack, DEBUG_CALLER_PC); zgu@4053: } zgu@4053: zgu@3900: // record a virtual memory 'commit' call zgu@3900: static inline void record_virtual_memory_commit(address addr, size_t size, zgu@4193: address pc, Thread* thread = NULL) { zgu@5272: Tracker tkr(Tracker::Commit, thread); zgu@5272: tkr.record(addr, size, mtNone, pc); zgu@3900: } zgu@3900: zgu@5272: static inline void record_virtual_memory_reserve_and_commit(address addr, size_t size, zgu@5272: MEMFLAGS flags, address pc, Thread* thread = NULL) { zgu@5272: Tracker tkr(Tracker::ReserveAndCommit, thread); zgu@5272: tkr.record(addr, size, flags, pc); zgu@3900: } zgu@3900: zgu@3900: zgu@3900: // record memory type on virtual memory base address zgu@3900: static inline void record_virtual_memory_type(address base, MEMFLAGS flags, zgu@3900: Thread* thread = NULL) { zgu@5272: Tracker tkr(Tracker::Type); zgu@5272: tkr.record(base, 0, flags); zgu@5272: } zgu@5272: zgu@5272: // Get memory trackers for memory operations that can result race conditions. zgu@5272: // The memory tracker has to be obtained before realloc, virtual memory uncommit zgu@5272: // and virtual memory release, and call tracker.record() method if operation zgu@5272: // succeeded, or tracker.discard() to abort the tracking. zgu@5272: static inline Tracker get_realloc_tracker() { zgu@5272: return Tracker(Tracker::Realloc); zgu@5272: } zgu@5272: zgu@5272: static inline Tracker get_virtual_memory_uncommit_tracker() { zgu@5272: return Tracker(Tracker::Uncommit); zgu@5272: } zgu@5272: zgu@5272: static inline Tracker get_virtual_memory_release_tracker() { zgu@5272: return Tracker(Tracker::Release); zgu@3900: } zgu@3900: zgu@3900: zgu@3900: // create memory baseline of current memory snapshot zgu@3900: static bool baseline(); zgu@3900: // is there a memory baseline zgu@3900: static bool has_baseline() { zgu@3900: return _baseline.baselined(); zgu@3900: } zgu@3900: zgu@3900: // print memory usage from current snapshot zgu@3900: static bool print_memory_usage(BaselineOutputer& out, size_t unit, zgu@3900: bool summary_only = true); zgu@3900: // compare memory usage between current snapshot and baseline zgu@3900: static bool compare_memory_usage(BaselineOutputer& out, size_t unit, zgu@3900: bool summary_only = true); zgu@3900: ctornqvi@4512: // the version for whitebox testing support, it ensures that all memory ctornqvi@4512: // activities before this method call, are reflected in the snapshot ctornqvi@4512: // database. ctornqvi@4512: static bool wbtest_wait_for_data_merge(); ctornqvi@4512: zgu@3900: // sync is called within global safepoint to synchronize nmt data zgu@3900: static void sync(); zgu@3900: zgu@3900: // called when a thread is about to exit zgu@3900: static void thread_exiting(JavaThread* thread); zgu@3900: zgu@3900: // retrieve global snapshot zgu@3900: static MemSnapshot* get_snapshot() { zgu@3900: if (shutdown_in_progress()) { zgu@3900: return NULL; zgu@3900: } zgu@3900: return _snapshot; zgu@3900: } zgu@3900: zgu@3900: // print tracker stats zgu@3900: NOT_PRODUCT(static void print_tracker_stats(outputStream* st);) zgu@3900: NOT_PRODUCT(static void walk_stack(int toSkip, char* buf, int len);) zgu@3900: zgu@3900: private: zgu@3900: // start native memory tracking worker thread zgu@4927: static bool start_worker(MemSnapshot* snapshot); zgu@3900: zgu@3900: // called by worker thread to complete shutdown process zgu@3900: static void final_shutdown(); zgu@3900: zgu@3900: protected: zgu@3900: // retrieve per-thread recorder of the specified thread. zgu@3900: // if the recorder is full, it will be enqueued to overflow zgu@3900: // queue, a new recorder is acquired from recorder pool or a zgu@3900: // new instance is created. zgu@3900: // when thread == NULL, it means global recorder zgu@3900: static MemRecorder* get_thread_recorder(JavaThread* thread); zgu@3900: zgu@3900: // per-thread recorder pool zgu@3900: static void release_thread_recorder(MemRecorder* rec); zgu@3900: static void delete_all_pooled_recorders(); zgu@3900: zgu@3900: // pending recorder queue. Recorders are queued to pending queue zgu@3900: // when they are overflowed or collected at nmt sync point. zgu@3900: static void enqueue_pending_recorder(MemRecorder* rec); zgu@3900: static MemRecorder* get_pending_recorders(); zgu@3900: static void delete_all_pending_recorders(); zgu@3900: zgu@5272: // write a memory tracking record in recorder zgu@5272: static void write_tracking_record(address addr, MEMFLAGS type, zgu@5272: size_t size, jint seq, address pc, JavaThread* thread); zgu@5272: zgu@5272: static bool is_single_threaded_bootstrap() { zgu@5272: return _state == NMT_bootstrapping_single_thread; zgu@5272: } zgu@5272: zgu@5272: static void check_NMT_load(Thread* thr) { zgu@5272: assert(thr != NULL, "Sanity check"); zgu@5272: if (_slowdown_calling_thread && thr != _worker_thread) { zgu@5363: #ifdef _WINDOWS zgu@5363: // On Windows, os::NakedYield() does not work as well zgu@5363: // as os::yield_all() zgu@5272: os::yield_all(); zgu@5363: #else zgu@5363: // On Solaris, os::yield_all() depends on os::sleep() zgu@5363: // which requires JavaTherad in _thread_in_vm state. zgu@5363: // Transits thread to _thread_in_vm state can be dangerous zgu@5363: // if caller holds lock, as it may deadlock with Threads_lock. zgu@5363: // So use NaKedYield instead. zgu@5363: // zgu@5363: // Linux and BSD, NakedYield() and yield_all() implementations zgu@5363: // are the same. zgu@5363: os::NakedYield(); zgu@5363: #endif zgu@5272: } zgu@5272: } zgu@5272: zgu@5272: static void inc_pending_op_count() { zgu@5272: Atomic::inc(&_pending_op_count); zgu@5272: } zgu@5272: zgu@5272: static void dec_pending_op_count() { zgu@5272: Atomic::dec(&_pending_op_count); zgu@5272: assert(_pending_op_count >= 0, "Sanity check"); zgu@5272: } zgu@5272: zgu@5272: zgu@3900: private: zgu@3900: // retrieve a pooled memory record or create new one if there is not zgu@3900: // one available zgu@3900: static MemRecorder* get_new_or_pooled_instance(); zgu@3900: static void create_memory_record(address addr, MEMFLAGS type, zgu@3900: size_t size, address pc, Thread* thread); zgu@3900: static void create_record_in_recorder(address addr, MEMFLAGS type, zgu@3935: size_t size, address pc, JavaThread* thread); zgu@3900: ctornqvi@4512: static void set_current_processing_generation(unsigned long generation) { ctornqvi@4512: _worker_thread_idle = false; ctornqvi@4512: _processing_generation = generation; ctornqvi@4512: } ctornqvi@4512: ctornqvi@4512: static void report_worker_idle() { ctornqvi@4512: _worker_thread_idle = true; ctornqvi@4512: } ctornqvi@4512: zgu@3900: private: zgu@3900: // global memory snapshot zgu@3900: static MemSnapshot* _snapshot; zgu@3900: zgu@3900: // a memory baseline of snapshot zgu@3900: static MemBaseline _baseline; zgu@3900: zgu@3900: // query lock zgu@3936: static Mutex* _query_lock; zgu@3900: zgu@3900: // a thread can start to allocate memory before it is attached zgu@3900: // to VM 'Thread', those memory activities are recorded here. zgu@3900: // ThreadCritical is required to guard this global recorder. zgu@4927: static MemRecorder* volatile _global_recorder; zgu@3900: zgu@3900: // main thread id zgu@3900: debug_only(static intx _main_thread_tid;) zgu@3900: zgu@3900: // pending recorders to be merged zgu@4927: static MemRecorder* volatile _merge_pending_queue; zgu@3900: zgu@3900: NOT_PRODUCT(static volatile jint _pending_recorder_count;) zgu@3900: zgu@3900: // pooled memory recorders zgu@4927: static MemRecorder* volatile _pooled_recorders; zgu@3900: zgu@3900: // memory recorder pool management, uses following zgu@3900: // counter to determine if a released memory recorder zgu@3900: // should be pooled zgu@3900: zgu@3900: // latest thread count zgu@3900: static int _thread_count; zgu@3900: // pooled recorder count zgu@3900: static volatile jint _pooled_recorder_count; zgu@3900: zgu@3900: zgu@3900: // worker thread to merge pending recorders into snapshot zgu@3900: static MemTrackWorker* _worker_thread; zgu@3900: zgu@3900: // how many safepoints we skipped without entering sync point zgu@3900: static int _sync_point_skip_count; zgu@3900: zgu@3900: // if the tracker is properly intialized zgu@3900: static bool _is_tracker_ready; zgu@3900: // tracking level (off, summary and detail) zgu@3900: static enum NMTLevel _tracking_level; zgu@3900: zgu@3900: // current nmt state zgu@3900: static volatile enum NMTStates _state; zgu@3900: // the reason for shutting down nmt zgu@3900: static enum ShutdownReason _reason; ctornqvi@4512: // the generation that NMT is processing ctornqvi@4512: static volatile unsigned long _processing_generation; ctornqvi@4512: // although NMT is still procesing current generation, but ctornqvi@4512: // there is not more recorder to process, set idle state ctornqvi@4512: static volatile bool _worker_thread_idle; zgu@4810: zgu@4810: // if NMT should slow down calling thread to allow zgu@4810: // worker thread to catch up zgu@4810: static volatile bool _slowdown_calling_thread; zgu@5272: zgu@5272: // pending memory op count. zgu@5272: // Certain memory ops need to pre-reserve sequence number zgu@5272: // before memory operation can happen to avoid race condition. zgu@5272: // See MemTracker::Tracker for detail zgu@5272: static volatile jint _pending_op_count; zgu@3900: }; zgu@3900: jprovino@4165: #endif // !INCLUDE_NMT jprovino@4165: zgu@3900: #endif // SHARE_VM_SERVICES_MEM_TRACKER_HPP