1 /*
2 * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
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 *
100 event.commit();
101 JfrThreadCPULoadEvent::send_event_for_thread(jt);
102 }
103
104 void JfrThreadLocal::release(JfrThreadLocal* tl, Thread* t) {
105 assert(tl != NULL, "invariant");
106 assert(t != NULL, "invariant");
107 assert(Thread::current() == t, "invariant");
108 assert(!tl->is_dead(), "invariant");
109 assert(tl->shelved_buffer() == NULL, "invariant");
110 if (tl->has_native_buffer()) {
111 JfrStorage::release_thread_local(tl->native_buffer(), t);
112 }
113 if (tl->has_java_buffer()) {
114 JfrStorage::release_thread_local(tl->java_buffer(), t);
115 }
116 if (tl->has_java_event_writer()) {
117 assert(t->is_Java_thread(), "invariant");
118 JfrJavaSupport::destroy_global_jni_handle(tl->java_event_writer());
119 }
120 if (tl->_stackframes != NULL) {
121 FREE_C_HEAP_ARRAY(JfrStackFrame, tl->_stackframes);
122 }
123 tl->_dead = true;
124 }
125
126 void JfrThreadLocal::on_exit(Thread* t) {
127 assert(t != NULL, "invariant");
128 JfrThreadLocal * const tl = t->jfr_thread_local();
129 assert(!tl->is_dead(), "invariant");
130 if (JfrRecorder::is_recording()) {
131 if (t->is_Java_thread()) {
132 send_java_thread_end_events(tl->thread_id(), (JavaThread*)t);
133 }
134 }
135 release(tl, Thread::current()); // because it could be that Thread::current() != t
136 }
137
138 JfrBuffer* JfrThreadLocal::install_native_buffer() const {
139 assert(!has_native_buffer(), "invariant");
140 _native_buffer = JfrStorage::acquire_thread_local(Thread::current());
141 return _native_buffer;
142 }
|
1 /*
2 * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
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 *
100 event.commit();
101 JfrThreadCPULoadEvent::send_event_for_thread(jt);
102 }
103
104 void JfrThreadLocal::release(JfrThreadLocal* tl, Thread* t) {
105 assert(tl != NULL, "invariant");
106 assert(t != NULL, "invariant");
107 assert(Thread::current() == t, "invariant");
108 assert(!tl->is_dead(), "invariant");
109 assert(tl->shelved_buffer() == NULL, "invariant");
110 if (tl->has_native_buffer()) {
111 JfrStorage::release_thread_local(tl->native_buffer(), t);
112 }
113 if (tl->has_java_buffer()) {
114 JfrStorage::release_thread_local(tl->java_buffer(), t);
115 }
116 if (tl->has_java_event_writer()) {
117 assert(t->is_Java_thread(), "invariant");
118 JfrJavaSupport::destroy_global_jni_handle(tl->java_event_writer());
119 }
120 FREE_C_HEAP_ARRAY(JfrStackFrame, tl->_stackframes);
121 tl->_dead = true;
122 }
123
124 void JfrThreadLocal::on_exit(Thread* t) {
125 assert(t != NULL, "invariant");
126 JfrThreadLocal * const tl = t->jfr_thread_local();
127 assert(!tl->is_dead(), "invariant");
128 if (JfrRecorder::is_recording()) {
129 if (t->is_Java_thread()) {
130 send_java_thread_end_events(tl->thread_id(), (JavaThread*)t);
131 }
132 }
133 release(tl, Thread::current()); // because it could be that Thread::current() != t
134 }
135
136 JfrBuffer* JfrThreadLocal::install_native_buffer() const {
137 assert(!has_native_buffer(), "invariant");
138 _native_buffer = JfrStorage::acquire_thread_local(Thread::current());
139 return _native_buffer;
140 }
|