1 /*
   2  * Copyright (c) 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  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "jfr/jfr.hpp"
  27 #include "jfr/recorder/access/jfrThreadData.hpp"
  28 #include "jfr/recorder/jfrRecorder.hpp"
  29 #include "jfr/recorder/checkpoint/jfrCheckpointManager.hpp"
  30 #include "jfr/recorder/repository/jfrEmergencyDump.hpp"
  31 
  32 bool Jfr::is_enabled() {
  33   return JfrRecorder::is_enabled();
  34 }
  35 
  36 bool Jfr::is_disabled() {
  37   return JfrRecorder::is_disabled();
  38 }
  39 
  40 bool Jfr::is_recording() {
  41   return JfrRecorder::is_recording();
  42 }
  43 
  44 jint Jfr::on_vm_init() {
  45   return JfrRecorder::on_vm_init() ? JNI_OK : JNI_ERR;
  46 }
  47 
  48 jint Jfr::on_vm_start() {
  49   return JfrRecorder::on_vm_start() ? JNI_OK : JNI_ERR;
  50 }
  51 
  52 void Jfr::on_unloading_classes() {
  53   if (JfrRecorder::is_created()) {
  54     JfrCheckpointManager::write_constant_tag_set_for_unloaded_classes();
  55   }
  56 }
  57 
  58 void Jfr::on_thread_exit(JavaThread* thread) {
  59   if (JfrRecorder::is_recording()) {
  60     JfrThreadData::on_exit(thread);
  61   }
  62 }
  63 
  64 void Jfr::on_thread_destruct(Thread* thread) {
  65   if (JfrRecorder::is_created()) {
  66     JfrThreadData::on_destruct(thread);
  67   }
  68 }
  69 
  70 void Jfr::on_vm_shutdown(bool exception_handler) {
  71   if (JfrRecorder::is_recording()) {
  72     JfrEmergencyDump::on_vm_shutdown(exception_handler);
  73   }
  74 }