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