Path: blob/master/src/hotspot/share/jfr/dcmd/jfrDcmds.cpp
41152 views
/*1* Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "classfile/javaClasses.hpp"26#include "classfile/vmSymbols.hpp"27#include "jfr/jfr.hpp"28#include "jfr/dcmd/jfrDcmds.hpp"29#include "jfr/jni/jfrJavaSupport.hpp"30#include "jfr/recorder/jfrRecorder.hpp"31#include "jfr/recorder/service/jfrOptionSet.hpp"32#include "logging/log.hpp"33#include "logging/logConfiguration.hpp"34#include "logging/logMessage.hpp"35#include "memory/resourceArea.hpp"36#include "oops/objArrayOop.inline.hpp"37#include "oops/oop.inline.hpp"38#include "oops/symbol.hpp"39#include "runtime/handles.inline.hpp"40#include "runtime/jniHandles.hpp"41#include "services/diagnosticArgument.hpp"42#include "services/diagnosticFramework.hpp"43#include "utilities/globalDefinitions.hpp"4445#ifdef _WINDOWS46#define JFR_FILENAME_EXAMPLE "C:\\Users\\user\\My Recording.jfr"47#endif4849#ifdef __APPLE__50#define JFR_FILENAME_EXAMPLE "/Users/user/My Recording.jfr"51#endif5253#ifndef JFR_FILENAME_EXAMPLE54#define JFR_FILENAME_EXAMPLE "/home/user/My Recording.jfr"55#endif5657// JNIHandle management5859// ------------------------------------------------------------------60// push_jni_handle_block61//62// Push on a new block of JNI handles.63static void push_jni_handle_block(JavaThread* const thread) {64DEBUG_ONLY(JfrJavaSupport::check_java_thread_in_vm(thread));6566// Allocate a new block for JNI handles.67// Inlined code from jni_PushLocalFrame()68JNIHandleBlock* prev_handles = thread->active_handles();69JNIHandleBlock* entry_handles = JNIHandleBlock::allocate_block(thread);70assert(entry_handles != NULL && prev_handles != NULL, "should not be NULL");71entry_handles->set_pop_frame_link(prev_handles); // make sure prev handles get gc'd.72thread->set_active_handles(entry_handles);73}7475// ------------------------------------------------------------------76// pop_jni_handle_block77//78// Pop off the current block of JNI handles.79static void pop_jni_handle_block(JavaThread* const thread) {80DEBUG_ONLY(JfrJavaSupport::check_java_thread_in_vm(thread));8182// Release our JNI handle block83JNIHandleBlock* entry_handles = thread->active_handles();84JNIHandleBlock* prev_handles = entry_handles->pop_frame_link();85// restore86thread->set_active_handles(prev_handles);87entry_handles->set_pop_frame_link(NULL);88JNIHandleBlock::release_block(entry_handles, thread); // may block89}9091class JNIHandleBlockManager : public StackObj {92private:93JavaThread* const _thread;94public:95JNIHandleBlockManager(JavaThread* thread) : _thread(thread) {96push_jni_handle_block(_thread);97}9899~JNIHandleBlockManager() {100pop_jni_handle_block(_thread);101}102};103104static bool is_module_available(outputStream* output, TRAPS) {105return JfrJavaSupport::is_jdk_jfr_module_available(output, THREAD);106}107108static bool is_disabled(outputStream* output) {109if (Jfr::is_disabled()) {110if (output != NULL) {111output->print_cr("Flight Recorder is disabled.\n");112}113return true;114}115return false;116}117118static bool is_recorder_instance_created(outputStream* output) {119if (!JfrRecorder::is_created()) {120if (output != NULL) {121output->print_cr("No available recordings.\n");122output->print_cr("Use JFR.start to start a recording.\n");123}124return false;125}126return true;127}128129static bool invalid_state(outputStream* out, TRAPS) {130DEBUG_ONLY(JfrJavaSupport::check_java_thread_in_vm(THREAD));131return is_disabled(out) || !is_module_available(out, THREAD);132}133134static void handle_pending_exception(outputStream* output, bool startup, oop throwable) {135assert(throwable != NULL, "invariant");136137oop msg = java_lang_Throwable::message(throwable);138if (msg == NULL) {139return;140}141char* text = java_lang_String::as_utf8_string(msg);142if (text != NULL) {143if (startup) {144log_error(jfr,startup)("%s", text);145} else {146output->print_cr("%s", text);147}148}149}150151static void print_message(outputStream* output, oop content, TRAPS) {152objArrayOop lines = objArrayOop(content);153assert(lines != NULL, "invariant");154assert(lines->is_array(), "must be array");155const int length = lines->length();156for (int i = 0; i < length; ++i) {157const char* text = JfrJavaSupport::c_str(lines->obj_at(i), THREAD);158if (text == NULL) {159// An oome has been thrown and is pending.160break;161}162output->print_cr("%s", text);163}164}165166static void log(oop content, TRAPS) {167LogMessage(jfr,startup) msg;168objArrayOop lines = objArrayOop(content);169assert(lines != NULL, "invariant");170assert(lines->is_array(), "must be array");171const int length = lines->length();172for (int i = 0; i < length; ++i) {173const char* text = JfrJavaSupport::c_str(lines->obj_at(i), THREAD);174if (text == NULL) {175// An oome has been thrown and is pending.176break;177}178msg.info("%s", text);179}180}181182static void handle_dcmd_result(outputStream* output,183const oop result,184const DCmdSource source,185TRAPS) {186DEBUG_ONLY(JfrJavaSupport::check_java_thread_in_vm(THREAD));187assert(output != NULL, "invariant");188const bool startup = DCmd_Source_Internal == source;189if (HAS_PENDING_EXCEPTION) {190handle_pending_exception(output, startup, PENDING_EXCEPTION);191// Don't clear excption on startup, JVM should fail initialization.192if (!startup) {193CLEAR_PENDING_EXCEPTION;194}195return;196}197198assert(!HAS_PENDING_EXCEPTION, "invariant");199200if (startup) {201if (log_is_enabled(Warning, jfr, startup)) {202// if warning is set, assume user hasn't configured log level203// Log to Info and reset to Warning. This way user can disable204// default output by setting -Xlog:jfr+startup=error/off205LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(jfr, startup));206log(result, THREAD);207LogConfiguration::configure_stdout(LogLevel::Warning, true, LOG_TAGS(jfr, startup));208} else {209log(result, THREAD);210}211} else {212// Print output for jcmd or MXBean213print_message(output, result, THREAD);214}215}216217static oop construct_dcmd_instance(JfrJavaArguments* args, TRAPS) {218assert(args != NULL, "invariant");219DEBUG_ONLY(JfrJavaSupport::check_java_thread_in_vm(THREAD));220assert(args->klass() != NULL, "invariant");221args->set_name("<init>");222args->set_signature("()V");223JfrJavaSupport::new_object(args, CHECK_NULL);224return args->result()->get_oop();225}226227JfrDumpFlightRecordingDCmd::JfrDumpFlightRecordingDCmd(outputStream* output,228bool heap) : DCmdWithParser(output, heap),229_name("name", "Recording name, e.g. \\\"My Recording\\\"", "STRING", false, NULL),230_filename("filename", "Copy recording data to file, e.g. \\\"" JFR_FILENAME_EXAMPLE "\\\"", "STRING", false),231_maxage("maxage", "Maximum duration to dump, in (s)econds, (m)inutes, (h)ours, or (d)ays, e.g. 60m, or 0 for no limit", "NANOTIME", false, "0"),232_maxsize("maxsize", "Maximum amount of bytes to dump, in (M)B or (G)B, e.g. 500M, or 0 for no limit", "MEMORY SIZE", false, "0"),233_begin("begin", "Point in time to dump data from, e.g. 09:00, 21:35:00, 2018-06-03T18:12:56.827Z, 2018-06-03T20:13:46.832, -10m, -3h, or -1d", "STRING", false),234_end("end", "Point in time to dump data to, e.g. 09:00, 21:35:00, 2018-06-03T18:12:56.827Z, 2018-06-03T20:13:46.832, -10m, -3h, or -1d", "STRING", false),235_path_to_gc_roots("path-to-gc-roots", "Collect path to GC roots", "BOOLEAN", false, "false") {236_dcmdparser.add_dcmd_option(&_name);237_dcmdparser.add_dcmd_option(&_filename);238_dcmdparser.add_dcmd_option(&_maxage);239_dcmdparser.add_dcmd_option(&_maxsize);240_dcmdparser.add_dcmd_option(&_begin);241_dcmdparser.add_dcmd_option(&_end);242_dcmdparser.add_dcmd_option(&_path_to_gc_roots);243};244245int JfrDumpFlightRecordingDCmd::num_arguments() {246ResourceMark rm;247JfrDumpFlightRecordingDCmd* dcmd = new JfrDumpFlightRecordingDCmd(NULL, false);248if (dcmd != NULL) {249DCmdMark mark(dcmd);250return dcmd->_dcmdparser.num_arguments();251}252return 0;253}254255void JfrDumpFlightRecordingDCmd::execute(DCmdSource source, TRAPS) {256DEBUG_ONLY(JfrJavaSupport::check_java_thread_in_vm(THREAD));257258if (invalid_state(output(), THREAD) || !is_recorder_instance_created(output())) {259return;260}261262ResourceMark rm(THREAD);263HandleMark hm(THREAD);264JNIHandleBlockManager jni_handle_management(THREAD);265266JavaValue result(T_OBJECT);267JfrJavaArguments constructor_args(&result);268constructor_args.set_klass("jdk/jfr/internal/dcmd/DCmdDump", CHECK);269const oop dcmd = construct_dcmd_instance(&constructor_args, CHECK);270Handle h_dcmd_instance(THREAD, dcmd);271assert(h_dcmd_instance.not_null(), "invariant");272273jstring name = NULL;274if (_name.is_set() && _name.value() != NULL) {275name = JfrJavaSupport::new_string(_name.value(), CHECK);276}277278jstring filepath = NULL;279if (_filename.is_set() && _filename.value() != NULL) {280filepath = JfrJavaSupport::new_string(_filename.value(), CHECK);281}282283jobject maxage = NULL;284if (_maxage.is_set()) {285maxage = JfrJavaSupport::new_java_lang_Long(_maxage.value()._nanotime, CHECK);286}287288jobject maxsize = NULL;289if (_maxsize.is_set()) {290maxsize = JfrJavaSupport::new_java_lang_Long(_maxsize.value()._size, CHECK);291}292293jstring begin = NULL;294if (_begin.is_set() && _begin.value() != NULL) {295begin = JfrJavaSupport::new_string(_begin.value(), CHECK);296}297298jstring end = NULL;299if (_end.is_set() && _end.value() != NULL) {300end = JfrJavaSupport::new_string(_end.value(), CHECK);301}302303jobject path_to_gc_roots = NULL;304if (_path_to_gc_roots.is_set()) {305path_to_gc_roots = JfrJavaSupport::new_java_lang_Boolean(_path_to_gc_roots.value(), CHECK);306}307308static const char klass[] = "jdk/jfr/internal/dcmd/DCmdDump";309static const char method[] = "execute";310static const char signature[] = "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Long;Ljava/lang/Long;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Boolean;)[Ljava/lang/String;";311312JfrJavaArguments execute_args(&result, klass, method, signature, CHECK);313execute_args.set_receiver(h_dcmd_instance);314315// arguments316execute_args.push_jobject(name);317execute_args.push_jobject(filepath);318execute_args.push_jobject(maxage);319execute_args.push_jobject(maxsize);320execute_args.push_jobject(begin);321execute_args.push_jobject(end);322execute_args.push_jobject(path_to_gc_roots);323324JfrJavaSupport::call_virtual(&execute_args, THREAD);325handle_dcmd_result(output(), result.get_oop(), source, THREAD);326}327328JfrCheckFlightRecordingDCmd::JfrCheckFlightRecordingDCmd(outputStream* output, bool heap) : DCmdWithParser(output, heap),329_name("name","Recording name, e.g. \\\"My Recording\\\" or omit to see all recordings","STRING",false, NULL),330_verbose("verbose","Print event settings for the recording(s)","BOOLEAN",331false, "false") {332_dcmdparser.add_dcmd_option(&_name);333_dcmdparser.add_dcmd_option(&_verbose);334};335336int JfrCheckFlightRecordingDCmd::num_arguments() {337ResourceMark rm;338JfrCheckFlightRecordingDCmd* dcmd = new JfrCheckFlightRecordingDCmd(NULL, false);339if (dcmd != NULL) {340DCmdMark mark(dcmd);341return dcmd->_dcmdparser.num_arguments();342}343return 0;344}345346void JfrCheckFlightRecordingDCmd::execute(DCmdSource source, TRAPS) {347DEBUG_ONLY(JfrJavaSupport::check_java_thread_in_vm(THREAD));348349if (invalid_state(output(), THREAD) || !is_recorder_instance_created(output())) {350return;351}352353ResourceMark rm(THREAD);354HandleMark hm(THREAD);355JNIHandleBlockManager jni_handle_management(THREAD);356357JavaValue result(T_OBJECT);358JfrJavaArguments constructor_args(&result);359constructor_args.set_klass("jdk/jfr/internal/dcmd/DCmdCheck", CHECK);360const oop dcmd = construct_dcmd_instance(&constructor_args, CHECK);361Handle h_dcmd_instance(THREAD, dcmd);362assert(h_dcmd_instance.not_null(), "invariant");363364jstring name = NULL;365if (_name.is_set() && _name.value() != NULL) {366name = JfrJavaSupport::new_string(_name.value(), CHECK);367}368369jobject verbose = NULL;370if (_verbose.is_set()) {371verbose = JfrJavaSupport::new_java_lang_Boolean(_verbose.value(), CHECK);372}373374static const char klass[] = "jdk/jfr/internal/dcmd/DCmdCheck";375static const char method[] = "execute";376static const char signature[] = "(Ljava/lang/String;Ljava/lang/Boolean;)[Ljava/lang/String;";377378JfrJavaArguments execute_args(&result, klass, method, signature, CHECK);379execute_args.set_receiver(h_dcmd_instance);380381// arguments382execute_args.push_jobject(name);383execute_args.push_jobject(verbose);384385JfrJavaSupport::call_virtual(&execute_args, THREAD);386handle_dcmd_result(output(), result.get_oop(), source, THREAD);387}388389JfrStartFlightRecordingDCmd::JfrStartFlightRecordingDCmd(outputStream* output,390bool heap) : DCmdWithParser(output, heap),391_name("name", "Name that can be used to identify recording, e.g. \\\"My Recording\\\"", "STRING", false, NULL),392_settings("settings", "Settings file(s), e.g. profile or default. See JAVA_HOME/lib/jfr", "STRING SET", false),393_delay("delay", "Delay recording start with (s)econds, (m)inutes), (h)ours), or (d)ays, e.g. 5h.", "NANOTIME", false, "0"),394_duration("duration", "Duration of recording in (s)econds, (m)inutes, (h)ours, or (d)ays, e.g. 300s.", "NANOTIME", false, "0"),395_disk("disk", "Recording should be persisted to disk", "BOOLEAN", false),396_filename("filename", "Resulting recording filename, e.g. \\\"" JFR_FILENAME_EXAMPLE "\\\"", "STRING", false),397_maxage("maxage", "Maximum time to keep recorded data (on disk) in (s)econds, (m)inutes, (h)ours, or (d)ays, e.g. 60m, or 0 for no limit", "NANOTIME", false, "0"),398_maxsize("maxsize", "Maximum amount of bytes to keep (on disk) in (k)B, (M)B or (G)B, e.g. 500M, or 0 for no limit", "MEMORY SIZE", false, "0"),399_flush_interval("flush-interval", "Minimum time before flushing buffers, measured in (s)econds, e.g. 4 s, or 0 for flushing when a recording ends", "NANOTIME", false, "1s"),400_dump_on_exit("dumponexit", "Dump running recording when JVM shuts down", "BOOLEAN", false),401_path_to_gc_roots("path-to-gc-roots", "Collect path to GC roots", "BOOLEAN", false, "false") {402_dcmdparser.add_dcmd_option(&_name);403_dcmdparser.add_dcmd_option(&_settings);404_dcmdparser.add_dcmd_option(&_delay);405_dcmdparser.add_dcmd_option(&_duration);406_dcmdparser.add_dcmd_option(&_disk);407_dcmdparser.add_dcmd_option(&_filename);408_dcmdparser.add_dcmd_option(&_maxage);409_dcmdparser.add_dcmd_option(&_maxsize);410_dcmdparser.add_dcmd_option(&_flush_interval);411_dcmdparser.add_dcmd_option(&_dump_on_exit);412_dcmdparser.add_dcmd_option(&_path_to_gc_roots);413};414415int JfrStartFlightRecordingDCmd::num_arguments() {416ResourceMark rm;417JfrStartFlightRecordingDCmd* dcmd = new JfrStartFlightRecordingDCmd(NULL, false);418if (dcmd != NULL) {419DCmdMark mark(dcmd);420return dcmd->_dcmdparser.num_arguments();421}422return 0;423}424425void JfrStartFlightRecordingDCmd::execute(DCmdSource source, TRAPS) {426DEBUG_ONLY(JfrJavaSupport::check_java_thread_in_vm(THREAD));427428if (invalid_state(output(), THREAD)) {429return;430}431432ResourceMark rm(THREAD);433HandleMark hm(THREAD);434JNIHandleBlockManager jni_handle_management(THREAD);435436JavaValue result(T_OBJECT);437JfrJavaArguments constructor_args(&result);438constructor_args.set_klass("jdk/jfr/internal/dcmd/DCmdStart", THREAD);439const oop dcmd = construct_dcmd_instance(&constructor_args, CHECK);440Handle h_dcmd_instance(THREAD, dcmd);441assert(h_dcmd_instance.not_null(), "invariant");442443jstring name = NULL;444if (_name.is_set() && _name.value() != NULL) {445name = JfrJavaSupport::new_string(_name.value(), CHECK);446}447448jstring filename = NULL;449if (_filename.is_set() && _filename.value() != NULL) {450filename = JfrJavaSupport::new_string(_filename.value(), CHECK);451}452453jobject maxage = NULL;454if (_maxage.is_set()) {455maxage = JfrJavaSupport::new_java_lang_Long(_maxage.value()._nanotime, CHECK);456}457458jobject maxsize = NULL;459if (_maxsize.is_set()) {460maxsize = JfrJavaSupport::new_java_lang_Long(_maxsize.value()._size, CHECK);461}462463jobject flush_interval = NULL;464if (_flush_interval.is_set()) {465flush_interval = JfrJavaSupport::new_java_lang_Long(_flush_interval.value()._nanotime, CHECK);466}467jobject duration = NULL;468if (_duration.is_set()) {469duration = JfrJavaSupport::new_java_lang_Long(_duration.value()._nanotime, CHECK);470}471472jobject delay = NULL;473if (_delay.is_set()) {474delay = JfrJavaSupport::new_java_lang_Long(_delay.value()._nanotime, CHECK);475}476477jobject disk = NULL;478if (_disk.is_set()) {479disk = JfrJavaSupport::new_java_lang_Boolean(_disk.value(), CHECK);480}481482jobject dump_on_exit = NULL;483if (_dump_on_exit.is_set()) {484dump_on_exit = JfrJavaSupport::new_java_lang_Boolean(_dump_on_exit.value(), CHECK);485}486487jobject path_to_gc_roots = NULL;488if (_path_to_gc_roots.is_set()) {489path_to_gc_roots = JfrJavaSupport::new_java_lang_Boolean(_path_to_gc_roots.value(), CHECK);490}491492jobjectArray settings = NULL;493if (_settings.is_set()) {494int length = _settings.value()->array()->length();495if (length == 1) {496const char* c_str = _settings.value()->array()->at(0);497if (strcmp(c_str, "none") == 0) {498length = 0;499}500}501settings = JfrJavaSupport::new_string_array(length, CHECK);502assert(settings != NULL, "invariant");503for (int i = 0; i < length; ++i) {504jobject element = JfrJavaSupport::new_string(_settings.value()->array()->at(i), CHECK);505assert(element != NULL, "invariant");506JfrJavaSupport::set_array_element(settings, element, i, CHECK);507}508} else {509settings = JfrJavaSupport::new_string_array(1, CHECK);510assert(settings != NULL, "invariant");511jobject element = JfrJavaSupport::new_string("default", CHECK);512assert(element != NULL, "invariant");513JfrJavaSupport::set_array_element(settings, element, 0, CHECK);514}515516static const char klass[] = "jdk/jfr/internal/dcmd/DCmdStart";517static const char method[] = "execute";518static const char signature[] = "(Ljava/lang/String;[Ljava/lang/String;Ljava/lang/Long;"519"Ljava/lang/Long;Ljava/lang/Boolean;Ljava/lang/String;"520"Ljava/lang/Long;Ljava/lang/Long;Ljava/lang/Long;Ljava/lang/Boolean;Ljava/lang/Boolean;)[Ljava/lang/String;";521522JfrJavaArguments execute_args(&result, klass, method, signature, CHECK);523execute_args.set_receiver(h_dcmd_instance);524525// arguments526execute_args.push_jobject(name);527execute_args.push_jobject(settings);528execute_args.push_jobject(delay);529execute_args.push_jobject(duration);530execute_args.push_jobject(disk);531execute_args.push_jobject(filename);532execute_args.push_jobject(maxage);533execute_args.push_jobject(maxsize);534execute_args.push_jobject(flush_interval);535execute_args.push_jobject(dump_on_exit);536execute_args.push_jobject(path_to_gc_roots);537538JfrJavaSupport::call_virtual(&execute_args, THREAD);539handle_dcmd_result(output(), result.get_oop(), source, THREAD);540}541542JfrStopFlightRecordingDCmd::JfrStopFlightRecordingDCmd(outputStream* output,543bool heap) : DCmdWithParser(output, heap),544_name("name", "Recording text,.e.g \\\"My Recording\\\"", "STRING", true, NULL),545_filename("filename", "Copy recording data to file, e.g. \\\"" JFR_FILENAME_EXAMPLE "\\\"", "STRING", false, NULL) {546_dcmdparser.add_dcmd_option(&_name);547_dcmdparser.add_dcmd_option(&_filename);548};549550int JfrStopFlightRecordingDCmd::num_arguments() {551ResourceMark rm;552JfrStopFlightRecordingDCmd* dcmd = new JfrStopFlightRecordingDCmd(NULL, false);553if (dcmd != NULL) {554DCmdMark mark(dcmd);555return dcmd->_dcmdparser.num_arguments();556}557return 0;558}559560void JfrStopFlightRecordingDCmd::execute(DCmdSource source, TRAPS) {561DEBUG_ONLY(JfrJavaSupport::check_java_thread_in_vm(THREAD));562563if (invalid_state(output(), THREAD) || !is_recorder_instance_created(output())) {564return;565}566567ResourceMark rm(THREAD);568HandleMark hm(THREAD);569JNIHandleBlockManager jni_handle_management(THREAD);570571JavaValue result(T_OBJECT);572JfrJavaArguments constructor_args(&result);573constructor_args.set_klass("jdk/jfr/internal/dcmd/DCmdStop", CHECK);574const oop dcmd = construct_dcmd_instance(&constructor_args, CHECK);575Handle h_dcmd_instance(THREAD, dcmd);576assert(h_dcmd_instance.not_null(), "invariant");577578jstring name = NULL;579if (_name.is_set() && _name.value() != NULL) {580name = JfrJavaSupport::new_string(_name.value(), CHECK);581}582583jstring filepath = NULL;584if (_filename.is_set() && _filename.value() != NULL) {585filepath = JfrJavaSupport::new_string(_filename.value(), CHECK);586}587588static const char klass[] = "jdk/jfr/internal/dcmd/DCmdStop";589static const char method[] = "execute";590static const char signature[] = "(Ljava/lang/String;Ljava/lang/String;)[Ljava/lang/String;";591592JfrJavaArguments execute_args(&result, klass, method, signature, CHECK);593execute_args.set_receiver(h_dcmd_instance);594595// arguments596execute_args.push_jobject(name);597execute_args.push_jobject(filepath);598599JfrJavaSupport::call_virtual(&execute_args, THREAD);600handle_dcmd_result(output(), result.get_oop(), source, THREAD);601}602603JfrConfigureFlightRecorderDCmd::JfrConfigureFlightRecorderDCmd(outputStream* output,604bool heap) : DCmdWithParser(output, heap),605_repository_path("repositorypath", "Path to repository,.e.g \\\"My Repository\\\"", "STRING", false, NULL),606_dump_path("dumppath", "Path to dump,.e.g \\\"My Dump path\\\"", "STRING", false, NULL),607_stack_depth("stackdepth", "Stack Depth", "JULONG", false, "64"),608_global_buffer_count("globalbuffercount", "Number of global buffers,", "JULONG", false, "20"),609_global_buffer_size("globalbuffersize", "Size of a global buffers,", "MEMORY SIZE", false, "512k"),610_thread_buffer_size("thread_buffer_size", "Size of a thread buffer", "MEMORY SIZE", false, "8k"),611_memory_size("memorysize", "Overall memory size, ", "MEMORY SIZE", false, "10m"),612_max_chunk_size("maxchunksize", "Size of an individual disk chunk", "MEMORY SIZE", false, "12m"),613_sample_threads("samplethreads", "Activate Thread sampling", "BOOLEAN", false, "true"),614_verbose(true) {615_dcmdparser.add_dcmd_option(&_repository_path);616_dcmdparser.add_dcmd_option(&_dump_path);617_dcmdparser.add_dcmd_option(&_stack_depth);618_dcmdparser.add_dcmd_option(&_global_buffer_count);619_dcmdparser.add_dcmd_option(&_global_buffer_size);620_dcmdparser.add_dcmd_option(&_thread_buffer_size);621_dcmdparser.add_dcmd_option(&_memory_size);622_dcmdparser.add_dcmd_option(&_max_chunk_size);623_dcmdparser.add_dcmd_option(&_sample_threads);624};625626int JfrConfigureFlightRecorderDCmd::num_arguments() {627ResourceMark rm;628JfrConfigureFlightRecorderDCmd* dcmd = new JfrConfigureFlightRecorderDCmd(NULL, false);629if (dcmd != NULL) {630DCmdMark mark(dcmd);631return dcmd->_dcmdparser.num_arguments();632}633return 0;634}635636void JfrConfigureFlightRecorderDCmd::execute(DCmdSource source, TRAPS) {637DEBUG_ONLY(JfrJavaSupport::check_java_thread_in_vm(THREAD));638639if (invalid_state(output(), THREAD)) {640return;641}642643ResourceMark rm(THREAD);644HandleMark hm(THREAD);645JNIHandleBlockManager jni_handle_management(THREAD);646647JavaValue result(T_OBJECT);648JfrJavaArguments constructor_args(&result);649constructor_args.set_klass("jdk/jfr/internal/dcmd/DCmdConfigure", CHECK);650const oop dcmd = construct_dcmd_instance(&constructor_args, CHECK);651Handle h_dcmd_instance(THREAD, dcmd);652assert(h_dcmd_instance.not_null(), "invariant");653654jstring repository_path = NULL;655if (_repository_path.is_set() && _repository_path.value() != NULL) {656repository_path = JfrJavaSupport::new_string(_repository_path.value(), CHECK);657}658659jstring dump_path = NULL;660if (_dump_path.is_set() && _dump_path.value() != NULL) {661dump_path = JfrJavaSupport::new_string(_dump_path.value(), CHECK);662}663664jobject stack_depth = NULL;665if (_stack_depth.is_set()) {666stack_depth = JfrJavaSupport::new_java_lang_Integer((jint)_stack_depth.value(), CHECK);667}668669jobject global_buffer_count = NULL;670if (_global_buffer_count.is_set()) {671global_buffer_count = JfrJavaSupport::new_java_lang_Long(_global_buffer_count.value(), CHECK);672}673674jobject global_buffer_size = NULL;675if (_global_buffer_size.is_set()) {676global_buffer_size = JfrJavaSupport::new_java_lang_Long(_global_buffer_size.value()._size, CHECK);677}678679jobject thread_buffer_size = NULL;680if (_thread_buffer_size.is_set()) {681thread_buffer_size = JfrJavaSupport::new_java_lang_Long(_thread_buffer_size.value()._size, CHECK);682}683684jobject max_chunk_size = NULL;685if (_max_chunk_size.is_set()) {686max_chunk_size = JfrJavaSupport::new_java_lang_Long(_max_chunk_size.value()._size, CHECK);687}688689jobject memory_size = NULL;690if (_memory_size.is_set()) {691memory_size = JfrJavaSupport::new_java_lang_Long(_memory_size.value()._size, CHECK);692}693694jobject sample_threads = NULL;695if (_sample_threads.is_set()) {696sample_threads = JfrJavaSupport::new_java_lang_Boolean(_sample_threads.value(), CHECK);697}698699static const char klass[] = "jdk/jfr/internal/dcmd/DCmdConfigure";700static const char method[] = "execute";701static const char signature[] = "(ZLjava/lang/String;Ljava/lang/String;Ljava/lang/Integer;"702"Ljava/lang/Long;Ljava/lang/Long;Ljava/lang/Long;Ljava/lang/Long;"703"Ljava/lang/Long;Ljava/lang/Boolean;)[Ljava/lang/String;";704705JfrJavaArguments execute_args(&result, klass, method, signature, CHECK);706execute_args.set_receiver(h_dcmd_instance);707708// params709execute_args.push_int(_verbose ? 1 : 0);710execute_args.push_jobject(repository_path);711execute_args.push_jobject(dump_path);712execute_args.push_jobject(stack_depth);713execute_args.push_jobject(global_buffer_count);714execute_args.push_jobject(global_buffer_size);715execute_args.push_jobject(thread_buffer_size);716execute_args.push_jobject(memory_size);717execute_args.push_jobject(max_chunk_size);718execute_args.push_jobject(sample_threads);719720JfrJavaSupport::call_virtual(&execute_args, THREAD);721handle_dcmd_result(output(), result.get_oop(), source, THREAD);722}723724bool register_jfr_dcmds() {725uint32_t full_export = DCmd_Source_Internal | DCmd_Source_AttachAPI | DCmd_Source_MBean;726DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JfrCheckFlightRecordingDCmd>(full_export, true, false));727DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JfrDumpFlightRecordingDCmd>(full_export, true, false));728DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JfrStartFlightRecordingDCmd>(full_export, true, false));729DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JfrStopFlightRecordingDCmd>(full_export, true, false));730DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JfrConfigureFlightRecorderDCmd>(full_export, true, false));731return true;732}733734735