18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24 #include "precompiled.hpp"
25
26
27 #include "oops/instanceKlass.hpp"
28 #include "runtime/atomic.hpp"
29 #include "runtime/interfaceSupport.hpp"
30 #include "runtime/mutexLocker.hpp"
31 #include "runtime/safepoint.hpp"
32 #include "runtime/threadCritical.hpp"
33 #include "runtime/vm_operations.hpp"
34 #include "services/memPtr.hpp"
35 #include "services/memReporter.hpp"
36 #include "services/memTracker.hpp"
37 #include "utilities/decoder.hpp"
38 #include "utilities/globalDefinitions.hpp"
39
40
41 bool NMT_track_callsite = false;
42
43 // walk all 'known' threads at NMT sync point, and collect their recorders
44 void SyncThreadRecorderClosure::do_thread(Thread* thread) {
45 assert(SafepointSynchronize::is_at_safepoint(), "Safepoint required");
46 if (thread->is_Java_thread()) {
47 JavaThread* javaThread = (JavaThread*)thread;
48 MemRecorder* recorder = javaThread->get_recorder();
49 if (recorder != NULL) {
50 MemTracker::enqueue_pending_recorder(recorder);
51 javaThread->set_recorder(NULL);
52 }
53 }
54 _thread_count ++;
55 }
56
57
63 MemRecorder* volatile MemTracker::_pooled_recorders = NULL;
64 MemTrackWorker* MemTracker::_worker_thread = NULL;
65 int MemTracker::_sync_point_skip_count = 0;
66 MemTracker::NMTLevel MemTracker::_tracking_level = MemTracker::NMT_off;
67 volatile MemTracker::NMTStates MemTracker::_state = NMT_uninited;
68 MemTracker::ShutdownReason MemTracker::_reason = NMT_shutdown_none;
69 int MemTracker::_thread_count = 255;
70 volatile jint MemTracker::_pooled_recorder_count = 0;
71 volatile unsigned long MemTracker::_processing_generation = 0;
72 volatile bool MemTracker::_worker_thread_idle = false;
73 volatile jint MemTracker::_pending_op_count = 0;
74 volatile bool MemTracker::_slowdown_calling_thread = false;
75 debug_only(intx MemTracker::_main_thread_tid = 0;)
76 NOT_PRODUCT(volatile jint MemTracker::_pending_recorder_count = 0;)
77
78 void MemTracker::init_tracking_options(const char* option_line) {
79 _tracking_level = NMT_off;
80 if (strcmp(option_line, "=summary") == 0) {
81 _tracking_level = NMT_summary;
82 } else if (strcmp(option_line, "=detail") == 0) {
83 _tracking_level = NMT_detail;
84 } else if (strcmp(option_line, "=off") != 0) {
85 vm_exit_during_initialization("Syntax error, expecting -XX:NativeMemoryTracking=[off|summary|detail]", NULL);
86 }
87 }
88
89 // first phase of bootstrapping, when VM is still in single-threaded mode.
90 void MemTracker::bootstrap_single_thread() {
91 if (_tracking_level > NMT_off) {
92 assert(_state == NMT_uninited, "wrong state");
93
94 // NMT is not supported with UseMallocOnly is on. NMT can NOT
95 // handle the amount of malloc data without significantly impacting
96 // runtime performance when this flag is on.
97 if (UseMallocOnly) {
98 shutdown(NMT_use_malloc_only);
99 return;
100 }
101
102 _query_lock = new (std::nothrow) Mutex(Monitor::max_nonleaf, "NMT_queryLock");
103 if (_query_lock == NULL) {
|
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24 #include "precompiled.hpp"
25
26
27 #include "oops/instanceKlass.hpp"
28 #include "runtime/atomic.hpp"
29 #include "runtime/interfaceSupport.hpp"
30 #include "runtime/mutexLocker.hpp"
31 #include "runtime/safepoint.hpp"
32 #include "runtime/threadCritical.hpp"
33 #include "runtime/vm_operations.hpp"
34 #include "services/memPtr.hpp"
35 #include "services/memReporter.hpp"
36 #include "services/memTracker.hpp"
37 #include "utilities/decoder.hpp"
38 #include "utilities/defaultStream.hpp"
39 #include "utilities/globalDefinitions.hpp"
40
41
42 bool NMT_track_callsite = false;
43
44 // walk all 'known' threads at NMT sync point, and collect their recorders
45 void SyncThreadRecorderClosure::do_thread(Thread* thread) {
46 assert(SafepointSynchronize::is_at_safepoint(), "Safepoint required");
47 if (thread->is_Java_thread()) {
48 JavaThread* javaThread = (JavaThread*)thread;
49 MemRecorder* recorder = javaThread->get_recorder();
50 if (recorder != NULL) {
51 MemTracker::enqueue_pending_recorder(recorder);
52 javaThread->set_recorder(NULL);
53 }
54 }
55 _thread_count ++;
56 }
57
58
64 MemRecorder* volatile MemTracker::_pooled_recorders = NULL;
65 MemTrackWorker* MemTracker::_worker_thread = NULL;
66 int MemTracker::_sync_point_skip_count = 0;
67 MemTracker::NMTLevel MemTracker::_tracking_level = MemTracker::NMT_off;
68 volatile MemTracker::NMTStates MemTracker::_state = NMT_uninited;
69 MemTracker::ShutdownReason MemTracker::_reason = NMT_shutdown_none;
70 int MemTracker::_thread_count = 255;
71 volatile jint MemTracker::_pooled_recorder_count = 0;
72 volatile unsigned long MemTracker::_processing_generation = 0;
73 volatile bool MemTracker::_worker_thread_idle = false;
74 volatile jint MemTracker::_pending_op_count = 0;
75 volatile bool MemTracker::_slowdown_calling_thread = false;
76 debug_only(intx MemTracker::_main_thread_tid = 0;)
77 NOT_PRODUCT(volatile jint MemTracker::_pending_recorder_count = 0;)
78
79 void MemTracker::init_tracking_options(const char* option_line) {
80 _tracking_level = NMT_off;
81 if (strcmp(option_line, "=summary") == 0) {
82 _tracking_level = NMT_summary;
83 } else if (strcmp(option_line, "=detail") == 0) {
84 // detail relies on a stack-walking ability that may not
85 // be available depending on platform and/or compiler flags
86 if (PLATFORM_NMT_DETAIL_SUPPORTED) {
87 _tracking_level = NMT_detail;
88 } else {
89 jio_fprintf(defaultStream::error_stream(),
90 "NMT detail is not supported on this platform. Using NMT summary instead.\n");
91 _tracking_level = NMT_summary;
92 }
93 } else if (strcmp(option_line, "=off") != 0) {
94 vm_exit_during_initialization("Syntax error, expecting -XX:NativeMemoryTracking=[off|summary|detail]", NULL);
95 }
96 }
97
98 // first phase of bootstrapping, when VM is still in single-threaded mode.
99 void MemTracker::bootstrap_single_thread() {
100 if (_tracking_level > NMT_off) {
101 assert(_state == NMT_uninited, "wrong state");
102
103 // NMT is not supported with UseMallocOnly is on. NMT can NOT
104 // handle the amount of malloc data without significantly impacting
105 // runtime performance when this flag is on.
106 if (UseMallocOnly) {
107 shutdown(NMT_use_malloc_only);
108 return;
109 }
110
111 _query_lock = new (std::nothrow) Mutex(Monitor::max_nonleaf, "NMT_queryLock");
112 if (_query_lock == NULL) {
|