src/hotspot/share/jfr/jni/jfrJniMethodRegistration.cpp
author mgronlun
Wed, 30 Oct 2019 19:43:52 +0100
changeset 58863 c16ac7a2eba4
parent 53014 339d2fbe8675
child 59226 a0f39cc47387
permissions -rw-r--r--
8226511: Implement JFR Event Streaming Reviewed-by: egahlin, mseledtsov, mgronlun Contributed-by: erik.gahlin@oracle.com, mikhailo.seledtsov@oracle.com, markus.gronlund@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     1
/*
58863
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents: 53014
diff changeset
     2
 * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     4
 *
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     7
 * published by the Free Software Foundation.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     8
 *
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    13
 * accompanied this code).
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    14
 *
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    18
 *
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    21
 * questions.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    22
 *
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    23
 */
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    24
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    25
#include "precompiled.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    26
#include "jfr/jni/jfrJniMethod.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    27
#include "jfr/jni/jfrJniMethodRegistration.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    28
#include "logging/log.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    29
#include "runtime/interfaceSupport.inline.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    30
#include "runtime/thread.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    31
#include "utilities/exceptions.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    32
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    33
JfrJniMethodRegistration::JfrJniMethodRegistration(JNIEnv* env) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    34
  assert(env != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    35
  jclass jfr_clz = env->FindClass("jdk/jfr/internal/JVM");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    36
  if (jfr_clz != NULL) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    37
    JNINativeMethod method[] = {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    38
      (char*)"beginRecording", (char*)"()V", (void*)jfr_begin_recording,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    39
      (char*)"endRecording", (char*)"()V", (void*)jfr_end_recording,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    40
      (char*)"counterTime", (char*)"()J", (void*)jfr_elapsed_counter,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    41
      (char*)"createJFR", (char*)"(Z)Z", (void*)jfr_create_jfr,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    42
      (char*)"destroyJFR", (char*)"()Z", (void*)jfr_destroy_jfr,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    43
      (char*)"emitEvent", (char*)"(JJJ)Z", (void*)jfr_emit_event,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    44
      (char*)"getAllEventClasses", (char*)"()Ljava/util/List;", (void*)jfr_get_all_event_classes,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    45
      (char*)"getClassIdNonIntrinsic", (char*)"(Ljava/lang/Class;)J", (void*)jfr_class_id,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    46
      (char*)"getPid", (char*)"()Ljava/lang/String;", (void*)jfr_get_pid,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    47
      (char*)"getStackTraceId", (char*)"(I)J", (void*)jfr_stacktrace_id,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    48
      (char*)"getThreadId", (char*)"(Ljava/lang/Thread;)J", (void*)jfr_id_for_thread,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    49
      (char*)"getTicksFrequency", (char*)"()J", (void*)jfr_elapsed_frequency,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    50
      (char*)"subscribeLogLevel", (char*)"(Ljdk/jfr/internal/LogTag;I)V", (void*)jfr_subscribe_log_level,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    51
      (char*)"log", (char*)"(IILjava/lang/String;)V", (void*)jfr_log,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    52
      (char*)"retransformClasses", (char*)"([Ljava/lang/Class;)V", (void*)jfr_retransform_classes,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    53
      (char*)"setEnabled", (char*)"(JZ)V", (void*)jfr_set_enabled,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    54
      (char*)"setFileNotification", (char*)"(J)V", (void*)jfr_set_file_notification,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    55
      (char*)"setGlobalBufferCount", (char*)"(J)V", (void*)jfr_set_global_buffer_count,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    56
      (char*)"setGlobalBufferSize", (char*)"(J)V", (void*)jfr_set_global_buffer_size,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    57
      (char*)"setMethodSamplingInterval", (char*)"(JJ)V", (void*)jfr_set_method_sampling_interval,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    58
      (char*)"setOutput", (char*)"(Ljava/lang/String;)V", (void*)jfr_set_output,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    59
      (char*)"setSampleThreads", (char*)"(Z)V", (void*)jfr_set_sample_threads,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    60
      (char*)"setStackDepth", (char*)"(I)V", (void*)jfr_set_stack_depth,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    61
      (char*)"setStackTraceEnabled", (char*)"(JZ)V", (void*)jfr_set_stacktrace_enabled,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    62
      (char*)"setThreadBufferSize", (char*)"(J)V", (void*)jfr_set_thread_buffer_size,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    63
      (char*)"setMemorySize", (char*)"(J)V", (void*)jfr_set_memory_size,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    64
      (char*)"setThreshold", (char*)"(JJ)Z", (void*)jfr_set_threshold,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    65
      (char*)"storeMetadataDescriptor", (char*)"([B)V", (void*)jfr_store_metadata_descriptor,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    66
      (char*)"getAllowedToDoEventRetransforms", (char*)"()Z", (void*)jfr_allow_event_retransforms,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    67
      (char*)"isAvailable", (char*)"()Z", (void*)jfr_is_available,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    68
      (char*)"getTimeConversionFactor", (char*)"()D", (void*)jfr_time_conv_factor,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    69
      (char*)"getTypeId", (char*)"(Ljava/lang/Class;)J", (void*)jfr_type_id,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    70
      (char*)"getEventWriter", (char*)"()Ljava/lang/Object;", (void*)jfr_get_event_writer,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    71
      (char*)"newEventWriter", (char*)"()Ljdk/jfr/internal/EventWriter;", (void*)jfr_new_event_writer,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    72
      (char*)"flush", (char*)"(Ljdk/jfr/internal/EventWriter;II)Z", (void*)jfr_event_writer_flush,
58863
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents: 53014
diff changeset
    73
      (char*)"flush", (char*)"()V", (void*)jfr_flush,
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    74
      (char*)"setRepositoryLocation", (char*)"(Ljava/lang/String;)V", (void*)jfr_set_repository_location,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    75
      (char*)"abort", (char*)"(Ljava/lang/String;)V", (void*)jfr_abort,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    76
      (char*)"getEpochAddress", (char*)"()J",(void*)jfr_get_epoch_address,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    77
      (char*)"addStringConstant", (char*)"(ZJLjava/lang/String;)Z", (void*)jfr_add_string_constant,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    78
      (char*)"uncaughtException", (char*)"(Ljava/lang/Thread;Ljava/lang/Throwable;)V", (void*)jfr_uncaught_exception,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    79
      (char*)"setForceInstrumentation", (char*)"(Z)V", (void*)jfr_set_force_instrumentation,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    80
      (char*)"getUnloadedEventClassCount", (char*)"()J", (void*)jfr_get_unloaded_event_classes_count,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    81
      (char*)"setCutoff", (char*)"(JJ)Z", (void*)jfr_set_cutoff,
53014
339d2fbe8675 8215284: Reduce noise induced by periodic task getFileSize()
mgronlun
parents: 50113
diff changeset
    82
      (char*)"emitOldObjectSamples", (char*)"(JZ)V", (void*)jfr_emit_old_object_samples,
58863
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents: 53014
diff changeset
    83
      (char*)"shouldRotateDisk", (char*)"()Z", (void*)jfr_should_rotate_disk,
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents: 53014
diff changeset
    84
      (char*)"exclude", (char*)"(Ljava/lang/Thread;)V", (void*)jfr_exclude_thread,
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents: 53014
diff changeset
    85
      (char*)"include", (char*)"(Ljava/lang/Thread;)V", (void*)jfr_include_thread,
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents: 53014
diff changeset
    86
      (char*)"isExcluded", (char*)"(Ljava/lang/Thread;)Z", (void*)jfr_is_thread_excluded,
c16ac7a2eba4 8226511: Implement JFR Event Streaming
mgronlun
parents: 53014
diff changeset
    87
      (char*)"getChunkStartNanos", (char*)"()J", (void*)jfr_chunk_start_nanos
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    88
    };
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    89
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    90
    const size_t method_array_length = sizeof(method) / sizeof(JNINativeMethod);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    91
    if (env->RegisterNatives(jfr_clz, method, (jint)method_array_length) != JNI_OK) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    92
      JavaThread* jt = JavaThread::thread_from_jni_environment(env);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    93
      assert(jt != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    94
      assert(jt->thread_state() == _thread_in_native, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    95
      ThreadInVMfromNative transition(jt);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    96
      log_error(jfr, system)("RegisterNatives for JVM class failed!");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    97
    }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    98
    env->DeleteLocalRef(jfr_clz);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    99
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   100
}