/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* 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.
*
*/
#include "memory/allocation.hpp"
#include "runtime/globals.hpp"
#include "runtime/thread.hpp"
#include "services/memPtr.hpp"
#include "services/memRecorder.hpp"
#include "services/memSnapshot.hpp"
#include "services/memTrackWorker.hpp"
#ifdef SOLARIS
#include "thread_solaris.inline.hpp"
#endif
extern bool NMT_track_callsite;
#ifndef MAX_UNSIGNED_LONG
#endif
#ifdef ASSERT
#else
#define DEBUG_CALLER_PC 0
#endif
// The thread closure walks threads to collect per-thread
// memory recorders at NMT sync point
private:
int _thread_count;
public:
_thread_count =0;
}
int get_thread_count() const {
return _thread_count;
}
};
class BaselineOutputer;
class MemSnapshot;
class MemTrackWorker;
class Thread;
/*
* MemTracker is the 'gate' class to native memory tracking runtime.
*/
friend class GenerationData;
friend class MemTrackWorker;
friend class MemSnapshot;
friend class SyncThreadRecorderClosure;
// NMT state
enum NMTStates {
};
public:
friend class MemTracker;
public:
enum MemoryOperation {
};
protected:
public:
void discard();
private:
};
public:
// native memory tracking level
enum NMTLevel {
};
enum ShutdownReason {
};
public:
// initialize NMT tracking level from command line options, called
// from VM command line parsing code
static void init_tracking_options(const char* option_line);
// if NMT is enabled to record memory activities
static inline bool is_on() {
return (_tracking_level >= NMT_summary &&
}
return _tracking_level;
}
// user readable reason for shutting down NMT
static const char* reason() {
switch(_reason) {
case NMT_shutdown_none:
return "Native memory tracking is not enabled";
case NMT_shutdown_user:
return "Native memory tracking has been shutdown by user";
case NMT_normal:
return "Native memory tracking has been shutdown due to process exiting";
case NMT_out_of_memory:
return "Native memory tracking has been shutdown due to out of native memory";
case NMT_initialization:
return "Native memory tracking failed to initialize";
case NMT_error_reporting:
return "Native memory tracking has been shutdown due to error reporting";
case NMT_out_of_generation:
return "Native memory tracking has been shutdown due to running out of generation buffer";
case NMT_sequence_overflow:
return "Native memory tracking has been shutdown due to overflow the sequence number";
case NMT_use_malloc_only:
return "Native memory tracking is not supported when UseMallocOnly is on";
default:
return NULL;
}
}
// test if we can walk native stack
static bool can_walk_stack() {
// native stack is not walkable during bootstrapping on sparc
#if defined(SPARC)
return (_state == NMT_started);
#else
#endif
}
// if native memory tracking tracks callsite
// NMT automatically shuts itself down under extreme situation by default.
// When the value is set to false, NMT will try its best to stay alive,
// even it has to slow down VM.
if (AutoShutdownNMT && _slowdown_calling_thread) {
_slowdown_calling_thread = false;
}
}
// shutdown native memory tracking capability. Native memory tracking
// can be shutdown by VM when it encounters low memory scenarios.
// Memory tracker should gracefully shutdown itself, and preserve the
// latest memory statistics for post morten diagnosis.
// if there is shutdown requested
static inline bool shutdown_in_progress() {
return (_state >= NMT_shutdown_pending);
}
// bootstrap native memory tracking, so it can start to collect raw data
// before worker thread can start
// the first phase of bootstrapping, when VM still in single-threaded mode
static void bootstrap_single_thread();
// the second phase of bootstrapping, VM is about or already in multi-threaded mode
static void bootstrap_multi_thread();
private:
public:
// start() has to be called when VM still in single thread mode, but after
// command line option parsing is done.
static void start();
// record a 'malloc' call
}
// record a 'free' call
}
}
// record a virtual memory 'reserve' call
if (is_on()) {
}
}
if (is_on()) {
}
}
if (is_on()) {
}
}
// record a virtual memory 'commit' call
if (is_on()) {
}
}
if (is_on()) {
}
}
// record memory type on virtual memory base address
if (is_on()) {
}
}
// Get memory trackers for memory operations that can result race conditions.
// The memory tracker has to be obtained before realloc, virtual memory uncommit
// and virtual memory release, and call tracker.record() method if operation
// succeeded, or tracker.discard() to abort the tracking.
}
}
}
// create memory baseline of current memory snapshot
static bool baseline();
// is there a memory baseline
static bool has_baseline() {
}
// print memory usage from current snapshot
bool summary_only = true);
// compare memory usage between current snapshot and baseline
bool summary_only = true);
// the version for whitebox testing support, it ensures that all memory
// activities before this method call, are reflected in the snapshot
// database.
static bool wbtest_wait_for_data_merge();
// sync is called within global safepoint to synchronize nmt data
static void sync();
// called when a thread is about to exit
// retrieve global snapshot
if (shutdown_in_progress()) {
return NULL;
}
return _snapshot;
}
// print tracker stats
private:
// start native memory tracking worker thread
// called by worker thread to complete shutdown process
static void final_shutdown();
protected:
// retrieve per-thread recorder of the specified thread.
// if the recorder is full, it will be enqueued to overflow
// queue, a new recorder is acquired from recorder pool or a
// new instance is created.
// when thread == NULL, it means global recorder
// per-thread recorder pool
static void delete_all_pooled_recorders();
// pending recorder queue. Recorders are queued to pending queue
// when they are overflowed or collected at nmt sync point.
static MemRecorder* get_pending_recorders();
static void delete_all_pending_recorders();
// write a memory tracking record in recorder
static bool is_single_threaded_bootstrap() {
return _state == NMT_bootstrapping_single_thread;
}
}
}
static void inc_pending_op_count() {
}
static void dec_pending_op_count() {
}
private:
// retrieve a pooled memory record or create new one if there is not
// one available
static MemRecorder* get_new_or_pooled_instance();
_worker_thread_idle = false;
}
static void report_worker_idle() {
_worker_thread_idle = true;
}
private:
// global memory snapshot
// a memory baseline of snapshot
// query lock
// a thread can start to allocate memory before it is attached
// to VM 'Thread', those memory activities are recorded here.
// ThreadCritical is required to guard this global recorder.
// main thread id
// pending recorders to be merged
// pooled memory recorders
// memory recorder pool management, uses following
// counter to determine if a released memory recorder
// should be pooled
// latest thread count
static int _thread_count;
// pooled recorder count
// worker thread to merge pending recorders into snapshot
// how many safepoints we skipped without entering sync point
static int _sync_point_skip_count;
// if the tracker is properly intialized
static bool _is_tracker_ready;
// tracking level (off, summary and detail)
// current nmt state
// the reason for shutting down nmt
// the generation that NMT is processing
static volatile unsigned long _processing_generation;
// although NMT is still procesing current generation, but
// there is not more recorder to process, set idle state
static volatile bool _worker_thread_idle;
// if NMT should slow down calling thread to allow
// worker thread to catch up
static volatile bool _slowdown_calling_thread;
// pending memory op count.
// Certain memory ops need to pre-reserve sequence number
// before memory operation can happen to avoid race condition.
// See MemTracker::Tracker for detail
};
#endif // SHARE_VM_SERVICES_MEM_TRACKER_HPP