1 /*
  2  * Copyright (c) 2019, 2021, 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  *
 23  */
 24 
 25 #include "precompiled.hpp"
 26 #include "jfr/jfr.hpp"
 27 #include "jfr/jni/jfrJavaSupport.hpp"
 28 #include "jfr/leakprofiler/leakProfiler.hpp"
 29 #include "jfr/recorder/checkpoint/types/traceid/jfrTraceIdLoadBarrier.inline.hpp"
 30 #include "jfr/recorder/jfrRecorder.hpp"
 31 #include "jfr/recorder/checkpoint/jfrCheckpointManager.hpp"
 32 #include "jfr/recorder/repository/jfrEmergencyDump.hpp"
 33 #include "jfr/recorder/service/jfrOptionSet.hpp"
 34 #include "jfr/recorder/repository/jfrRepository.hpp"
 35 #include "jfr/support/jfrThreadLocal.hpp"
 36 #include "runtime/interfaceSupport.inline.hpp"
 37 #include "runtime/java.hpp"
 38 #include "runtime/thread.hpp"
 39 
 40 bool Jfr::is_enabled() {
 41   return JfrRecorder::is_enabled();
 42 }
 43 
 44 bool Jfr::is_disabled() {
 45   return JfrRecorder::is_disabled();
 46 }
 47 
 48 bool Jfr::is_recording() {
 49   return JfrRecorder::is_recording();
 50 }
 51 
 52 void Jfr::on_create_vm_1() {
 53   if (!JfrRecorder::on_create_vm_1()) {
 54     vm_exit_during_initialization("Failure when starting JFR on_create_vm_1");
 55   }
 56 }
 57 
 58 void Jfr::on_create_vm_2() {
 59   if (!JfrRecorder::on_create_vm_2()) {
 60     vm_exit_during_initialization("Failure when starting JFR on_create_vm_2");
 61   }
 62 }
 63 
 64 void Jfr::on_create_vm_3() {
 65   if (!JfrRecorder::on_create_vm_3()) {
 66     vm_exit_during_initialization("Failure when starting JFR on_create_vm_3");
 67   }
 68 }
 69 
 70 void Jfr::on_unloading_classes() {
 71   if (JfrRecorder::is_created()) {
 72     JfrCheckpointManager::on_unloading_classes();
 73   }
 74 }
 75 
 76 void Jfr::on_thread_start(Thread* t) {
 77   JfrThreadLocal::on_start(t);
 78 }
 79 
 80 void Jfr::on_thread_start(jobject carrier_thread, jobject vthread) {
 81   JfrThreadLocal::on_vthread_start(JfrJavaSupport::get_native(carrier_thread), vthread);
 82 }
 83 
 84 void Jfr::on_thread_exit(Thread* t) {
 85   JfrThreadLocal::on_exit(t);
 86 }
 87 
 88 void Jfr::on_thread_exit(jobject carrier_thread, jobject vthread) {
 89   JfrThreadLocal::on_vthread_exit(JfrJavaSupport::get_native(carrier_thread), vthread);
 90 }
 91 
 92 void Jfr::exclude_thread(Thread* t) {
 93   JfrThreadLocal::exclude(t);
 94 }
 95 
 96 void Jfr::include_thread(Thread* t) {
 97   JfrThreadLocal::include(t);
 98 }
 99 
100 bool Jfr::is_excluded(Thread* t) {
101   return t != NULL && t->jfr_thread_local()->is_excluded();
102 }
103 
104 void Jfr::on_vm_shutdown(bool exception_handler) {
105   if (JfrRecorder::is_recording()) {
106     JfrEmergencyDump::on_vm_shutdown(exception_handler);
107   }
108 }
109 
110 void Jfr::on_vm_error_report(outputStream* st) {
111   if (JfrRecorder::is_recording()) {
112     JfrRepository::on_vm_error_report(st);
113   }
114 }
115 
116 bool Jfr::on_flight_recorder_option(const JavaVMOption** option, char* delimiter) {
117   return JfrOptionSet::parse_flight_recorder_option(option, delimiter);
118 }
119 
120 bool Jfr::on_start_flight_recording_option(const JavaVMOption** option, char* delimiter) {
121   return JfrOptionSet::parse_start_flight_recording_option(option, delimiter);
122 }
123 
124 JRT_LEAF(void, Jfr::get_class_id_intrinsic(const Klass* klass))
125   assert(klass != NULL, "sanity");
126   JfrTraceIdLoadBarrier::load_barrier(klass);
127 JRT_END
128 
129 address Jfr::epoch_address() {
130   return JfrTraceIdEpoch::epoch_address();
131 }
132 
133 address Jfr::signal_address() {
134   return JfrTraceIdEpoch::signal_address();
135 }