Mon, 19 Aug 2019 10:11:31 +0200
8229401: Fix JFR code cache test failures
8223689: Add JFR Thread Sampling Support
8223690: Add JFR BiasedLock Event Support
8223691: Add JFR G1 Region Type Change Event Support
8223692: Add JFR G1 Heap Summary Event Support
Summary: Backport JFR from JDK11, additional fixes
Reviewed-by: neugens, apetushkov
Contributed-by: denghui.ddh@alibaba-inc.com
apetushkov@9858 | 1 | /* |
apetushkov@9858 | 2 | * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved. |
apetushkov@9858 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
apetushkov@9858 | 4 | * |
apetushkov@9858 | 5 | * This code is free software; you can redistribute it and/or modify it |
apetushkov@9858 | 6 | * under the terms of the GNU General Public License version 2 only, as |
apetushkov@9858 | 7 | * published by the Free Software Foundation. |
apetushkov@9858 | 8 | * |
apetushkov@9858 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
apetushkov@9858 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
apetushkov@9858 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
apetushkov@9858 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
apetushkov@9858 | 13 | * accompanied this code). |
apetushkov@9858 | 14 | * |
apetushkov@9858 | 15 | * You should have received a copy of the GNU General Public License version |
apetushkov@9858 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
apetushkov@9858 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
apetushkov@9858 | 18 | * |
apetushkov@9858 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
apetushkov@9858 | 20 | * or visit www.oracle.com if you need additional information or have any |
apetushkov@9858 | 21 | * questions. |
apetushkov@9858 | 22 | * |
apetushkov@9858 | 23 | */ |
apetushkov@9858 | 24 | |
apetushkov@9858 | 25 | #include "precompiled.hpp" |
apetushkov@9858 | 26 | #include "jfr/jni/jfrJavaSupport.hpp" |
apetushkov@9858 | 27 | #include "jfr/periodic/jfrThreadCPULoadEvent.hpp" |
apetushkov@9858 | 28 | #include "jfr/recorder/jfrRecorder.hpp" |
apetushkov@9858 | 29 | #include "jfr/recorder/checkpoint/jfrCheckpointManager.hpp" |
apetushkov@9858 | 30 | #include "jfr/recorder/checkpoint/types/traceid/jfrTraceId.inline.hpp" |
apetushkov@9858 | 31 | #include "jfr/recorder/service/jfrOptionSet.hpp" |
apetushkov@9858 | 32 | #include "jfr/recorder/storage/jfrStorage.hpp" |
apetushkov@9858 | 33 | #include "jfr/recorder/stacktrace/jfrStackTraceRepository.hpp" |
apetushkov@9858 | 34 | #include "jfr/support/jfrThreadLocal.hpp" |
apetushkov@9858 | 35 | #include "memory/allocation.inline.hpp" |
apetushkov@9858 | 36 | #include "runtime/os.hpp" |
apetushkov@9858 | 37 | #include "runtime/thread.inline.hpp" |
apetushkov@9858 | 38 | |
apetushkov@9858 | 39 | /* This data structure is per thread and only accessed by the thread itself, no locking required */ |
apetushkov@9858 | 40 | JfrThreadLocal::JfrThreadLocal() : |
apetushkov@9858 | 41 | _java_event_writer(NULL), |
apetushkov@9858 | 42 | _java_buffer(NULL), |
apetushkov@9858 | 43 | _native_buffer(NULL), |
apetushkov@9858 | 44 | _shelved_buffer(NULL), |
apetushkov@9858 | 45 | _stackframes(NULL), |
apetushkov@9858 | 46 | _trace_id(JfrTraceId::assign_thread_id()), |
apetushkov@9858 | 47 | _thread_cp(), |
apetushkov@9858 | 48 | _data_lost(0), |
apetushkov@9858 | 49 | _stack_trace_id(max_julong), |
apetushkov@9858 | 50 | _user_time(0), |
apetushkov@9858 | 51 | _cpu_time(0), |
apetushkov@9858 | 52 | _wallclock_time(os::javaTimeNanos()), |
apetushkov@9858 | 53 | _stack_trace_hash(0), |
apetushkov@9858 | 54 | _stackdepth(0), |
apetushkov@9858 | 55 | _entering_suspend_flag(0), |
apetushkov@9858 | 56 | _dead(false) {} |
apetushkov@9858 | 57 | |
apetushkov@9858 | 58 | u8 JfrThreadLocal::add_data_lost(u8 value) { |
apetushkov@9858 | 59 | _data_lost += value; |
apetushkov@9858 | 60 | return _data_lost; |
apetushkov@9858 | 61 | } |
apetushkov@9858 | 62 | |
apetushkov@9858 | 63 | bool JfrThreadLocal::has_thread_checkpoint() const { |
apetushkov@9858 | 64 | return _thread_cp.valid(); |
apetushkov@9858 | 65 | } |
apetushkov@9858 | 66 | |
apetushkov@9858 | 67 | void JfrThreadLocal::set_thread_checkpoint(const JfrCheckpointBlobHandle& ref) { |
apetushkov@9858 | 68 | assert(!_thread_cp.valid(), "invariant"); |
apetushkov@9858 | 69 | _thread_cp = ref; |
apetushkov@9858 | 70 | } |
apetushkov@9858 | 71 | |
apetushkov@9858 | 72 | const JfrCheckpointBlobHandle& JfrThreadLocal::thread_checkpoint() const { |
apetushkov@9858 | 73 | return _thread_cp; |
apetushkov@9858 | 74 | } |
apetushkov@9858 | 75 | |
apetushkov@9858 | 76 | void JfrThreadLocal::set_dead() { |
apetushkov@9858 | 77 | assert(!is_dead(), "invariant"); |
apetushkov@9858 | 78 | _dead = true; |
apetushkov@9858 | 79 | } |
apetushkov@9858 | 80 | |
apetushkov@9858 | 81 | void JfrThreadLocal::on_exit(JavaThread* thread) { |
apetushkov@9858 | 82 | if (JfrRecorder::is_recording()) { |
apetushkov@9858 | 83 | JfrCheckpointManager::write_thread_checkpoint(thread); |
apetushkov@9858 | 84 | JfrThreadCPULoadEvent::send_event_for_thread(thread); |
apetushkov@9858 | 85 | } |
apetushkov@9858 | 86 | thread->jfr_thread_local()->set_dead(); |
apetushkov@9858 | 87 | } |
apetushkov@9858 | 88 | |
apetushkov@9858 | 89 | void JfrThreadLocal::on_destruct(Thread* thread) { |
apetushkov@9858 | 90 | JfrThreadLocal* const tl = thread->jfr_thread_local(); |
apetushkov@9858 | 91 | if (tl->has_native_buffer()) { |
apetushkov@9858 | 92 | release(tl->native_buffer(), thread); |
apetushkov@9858 | 93 | } |
apetushkov@9858 | 94 | if (tl->has_java_buffer()) { |
apetushkov@9858 | 95 | release(tl->java_buffer(), thread); |
apetushkov@9858 | 96 | } |
apetushkov@9858 | 97 | assert(tl->shelved_buffer() == NULL, "invariant"); |
apetushkov@9858 | 98 | if (thread->jfr_thread_local()->has_java_event_writer()) { |
apetushkov@9858 | 99 | JfrJavaSupport::destroy_global_jni_handle(tl->java_event_writer()); |
apetushkov@9858 | 100 | } |
apetushkov@9858 | 101 | destroy_stackframes(thread); |
apetushkov@9858 | 102 | } |
apetushkov@9858 | 103 | |
apetushkov@9858 | 104 | JfrBuffer* JfrThreadLocal::acquire(Thread* thread, size_t size) { |
apetushkov@9858 | 105 | return JfrStorage::acquire_thread_local(thread, size); |
apetushkov@9858 | 106 | } |
apetushkov@9858 | 107 | |
apetushkov@9858 | 108 | void JfrThreadLocal::release(JfrBuffer* buffer, Thread* thread) { |
apetushkov@9858 | 109 | assert(buffer != NULL, "invariant"); |
apetushkov@9858 | 110 | JfrStorage::release_thread_local(buffer, thread); |
apetushkov@9858 | 111 | } |
apetushkov@9858 | 112 | |
apetushkov@9858 | 113 | JfrBuffer* JfrThreadLocal::install_native_buffer() const { |
apetushkov@9858 | 114 | assert(!has_native_buffer(), "invariant"); |
apetushkov@9858 | 115 | _native_buffer = acquire(Thread::current()); |
apetushkov@9858 | 116 | return _native_buffer; |
apetushkov@9858 | 117 | } |
apetushkov@9858 | 118 | |
apetushkov@9858 | 119 | JfrBuffer* JfrThreadLocal::install_java_buffer() const { |
apetushkov@9858 | 120 | assert(!has_java_buffer(), "invariant"); |
apetushkov@9858 | 121 | assert(!has_java_event_writer(), "invariant"); |
apetushkov@9858 | 122 | _java_buffer = acquire(Thread::current()); |
apetushkov@9858 | 123 | return _java_buffer; |
apetushkov@9858 | 124 | } |
apetushkov@9858 | 125 | |
apetushkov@9858 | 126 | JfrStackFrame* JfrThreadLocal::install_stackframes() const { |
apetushkov@9858 | 127 | assert(_stackframes == NULL, "invariant"); |
apetushkov@9858 | 128 | _stackdepth = (u4)JfrOptionSet::stackdepth(); |
apetushkov@9858 | 129 | guarantee(_stackdepth > 0, "Stackdepth must be > 0"); |
apetushkov@9858 | 130 | _stackframes = NEW_C_HEAP_ARRAY(JfrStackFrame, _stackdepth, mtTracing); |
apetushkov@9858 | 131 | return _stackframes; |
apetushkov@9858 | 132 | } |
apetushkov@9858 | 133 | |
apetushkov@9858 | 134 | void JfrThreadLocal::destroy_stackframes(Thread* thread) { |
apetushkov@9858 | 135 | assert(thread != NULL, "invariant"); |
apetushkov@9858 | 136 | JfrStackFrame* frames = thread->jfr_thread_local()->stackframes(); |
apetushkov@9858 | 137 | if (frames != NULL) { |
apetushkov@9858 | 138 | FREE_C_HEAP_ARRAY(JfrStackFrame, frames, mtTracing); |
apetushkov@9858 | 139 | thread->jfr_thread_local()->set_stackframes(NULL); |
apetushkov@9858 | 140 | } |
apetushkov@9858 | 141 | } |