76 }
77
78 ObjectSampler* ObjectSampler::sampler() {
79 assert(is_created(), "invariant");
80 return _instance;
81 }
82
83 void ObjectSampler::destroy() {
84 assert(SafepointSynchronize::is_at_safepoint(), "invariant");
85 if (_instance != NULL) {
86 ObjectSampler* const sampler = _instance;
87 _instance = NULL;
88 delete sampler;
89 }
90 }
91
92 static volatile int _lock = 0;
93
94 ObjectSampler* ObjectSampler::acquire() {
95 assert(is_created(), "invariant");
96 while (Atomic::cmpxchg(1, &_lock, 0) == 1) {}
97 return _instance;
98 }
99
100 void ObjectSampler::release() {
101 assert(is_created(), "invariant");
102 OrderAccess::fence();
103 _lock = 0;
104 }
105
106 static traceid get_thread_id(JavaThread* thread) {
107 assert(thread != NULL, "invariant");
108 if (thread->threadObj() == NULL) {
109 return 0;
110 }
111 const JfrThreadLocal* const tl = thread->jfr_thread_local();
112 assert(tl != NULL, "invariant");
113 if (tl->is_excluded()) {
114 return 0;
115 }
116 if (!tl->has_thread_blob()) {
|
76 }
77
78 ObjectSampler* ObjectSampler::sampler() {
79 assert(is_created(), "invariant");
80 return _instance;
81 }
82
83 void ObjectSampler::destroy() {
84 assert(SafepointSynchronize::is_at_safepoint(), "invariant");
85 if (_instance != NULL) {
86 ObjectSampler* const sampler = _instance;
87 _instance = NULL;
88 delete sampler;
89 }
90 }
91
92 static volatile int _lock = 0;
93
94 ObjectSampler* ObjectSampler::acquire() {
95 assert(is_created(), "invariant");
96 while (Atomic::cmpxchg(&_lock, 0, 1) == 1) {}
97 return _instance;
98 }
99
100 void ObjectSampler::release() {
101 assert(is_created(), "invariant");
102 OrderAccess::fence();
103 _lock = 0;
104 }
105
106 static traceid get_thread_id(JavaThread* thread) {
107 assert(thread != NULL, "invariant");
108 if (thread->threadObj() == NULL) {
109 return 0;
110 }
111 const JfrThreadLocal* const tl = thread->jfr_thread_local();
112 assert(tl != NULL, "invariant");
113 if (tl->is_excluded()) {
114 return 0;
115 }
116 if (!tl->has_thread_blob()) {
|