apetushkov@9858: /* apetushkov@9858: * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved. apetushkov@9858: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. apetushkov@9858: * apetushkov@9858: * This code is free software; you can redistribute it and/or modify it apetushkov@9858: * under the terms of the GNU General Public License version 2 only, as apetushkov@9858: * published by the Free Software Foundation. apetushkov@9858: * apetushkov@9858: * This code is distributed in the hope that it will be useful, but WITHOUT apetushkov@9858: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or apetushkov@9858: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License apetushkov@9858: * version 2 for more details (a copy is included in the LICENSE file that apetushkov@9858: * accompanied this code). apetushkov@9858: * apetushkov@9858: * You should have received a copy of the GNU General Public License version apetushkov@9858: * 2 along with this work; if not, write to the Free Software Foundation, apetushkov@9858: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. apetushkov@9858: * apetushkov@9858: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA apetushkov@9858: * or visit www.oracle.com if you need additional information or have any apetushkov@9858: * questions. apetushkov@9858: * apetushkov@9858: */ apetushkov@9858: apetushkov@9858: #include "precompiled.hpp" apetushkov@9858: #include "classfile/javaClasses.hpp" apetushkov@9858: #include "classfile/vmSymbols.hpp" apetushkov@9858: #include "jfr/jfr.hpp" apetushkov@9858: #include "jfr/dcmd/jfrDcmds.hpp" apetushkov@9858: #include "jfr/jni/jfrJavaSupport.hpp" apetushkov@9858: #include "jfr/recorder/jfrRecorder.hpp" apetushkov@9858: #include "jfr/recorder/service/jfrOptionSet.hpp" apetushkov@9858: #include "memory/resourceArea.hpp" apetushkov@9858: #include "oops/oop.inline.hpp" apetushkov@9858: #include "oops/symbol.hpp" apetushkov@9858: #include "runtime/handles.inline.hpp" apetushkov@9858: #include "services/diagnosticArgument.hpp" apetushkov@9858: #include "services/diagnosticFramework.hpp" apetushkov@9858: #include "utilities/globalDefinitions.hpp" apetushkov@9858: apetushkov@9858: #ifdef _WINDOWS apetushkov@9858: #define JFR_FILENAME_EXAMPLE "C:\\Users\\user\\My Recording.jfr" apetushkov@9858: #endif apetushkov@9858: apetushkov@9858: #ifdef __APPLE__ apetushkov@9858: #define JFR_FILENAME_EXAMPLE "/Users/user/My Recording.jfr" apetushkov@9858: #endif apetushkov@9858: apetushkov@9858: #ifndef JFR_FILENAME_EXAMPLE apetushkov@9858: #define JFR_FILENAME_EXAMPLE "/home/user/My Recording.jfr" apetushkov@9858: #endif apetushkov@9858: apetushkov@9858: // JNIHandle management apetushkov@9858: apetushkov@9858: // ------------------------------------------------------------------ apetushkov@9858: // push_jni_handle_block apetushkov@9858: // apetushkov@9858: // Push on a new block of JNI handles. apetushkov@9858: static void push_jni_handle_block(Thread* const thread) { apetushkov@9858: DEBUG_ONLY(JfrJavaSupport::check_java_thread_in_vm(thread)); apetushkov@9858: apetushkov@9858: // Allocate a new block for JNI handles. apetushkov@9858: // Inlined code from jni_PushLocalFrame() apetushkov@9858: JNIHandleBlock* prev_handles = thread->active_handles(); apetushkov@9858: JNIHandleBlock* entry_handles = JNIHandleBlock::allocate_block(thread); apetushkov@9858: assert(entry_handles != NULL && prev_handles != NULL, "should not be NULL"); apetushkov@9858: entry_handles->set_pop_frame_link(prev_handles); // make sure prev handles get gc'd. apetushkov@9858: thread->set_active_handles(entry_handles); apetushkov@9858: } apetushkov@9858: apetushkov@9858: // ------------------------------------------------------------------ apetushkov@9858: // pop_jni_handle_block apetushkov@9858: // apetushkov@9858: // Pop off the current block of JNI handles. apetushkov@9858: static void pop_jni_handle_block(Thread* const thread) { apetushkov@9858: DEBUG_ONLY(JfrJavaSupport::check_java_thread_in_vm(thread)); apetushkov@9858: apetushkov@9858: // Release our JNI handle block apetushkov@9858: JNIHandleBlock* entry_handles = thread->active_handles(); apetushkov@9858: JNIHandleBlock* prev_handles = entry_handles->pop_frame_link(); apetushkov@9858: // restore apetushkov@9858: thread->set_active_handles(prev_handles); apetushkov@9858: entry_handles->set_pop_frame_link(NULL); apetushkov@9858: JNIHandleBlock::release_block(entry_handles, thread); // may block apetushkov@9858: } apetushkov@9858: apetushkov@9858: class JNIHandleBlockManager : public StackObj { apetushkov@9858: private: apetushkov@9858: Thread* const _thread; apetushkov@9858: public: apetushkov@9858: JNIHandleBlockManager(Thread* thread) : _thread(thread) { apetushkov@9858: push_jni_handle_block(_thread); apetushkov@9858: } apetushkov@9858: apetushkov@9858: ~JNIHandleBlockManager() { apetushkov@9858: pop_jni_handle_block(_thread); apetushkov@9858: } apetushkov@9858: }; apetushkov@9858: apetushkov@9858: static bool is_disabled(outputStream* output) { apetushkov@9858: if (Jfr::is_disabled()) { apetushkov@9858: if (output != NULL) { apetushkov@9858: output->print_cr("Flight Recorder is disabled.\n"); apetushkov@9858: } apetushkov@9858: return true; apetushkov@9858: } apetushkov@9858: return false; apetushkov@9858: } apetushkov@9858: apetushkov@9858: static bool is_recorder_instance_created(outputStream* output) { apetushkov@9858: if (!JfrRecorder::is_created()) { apetushkov@9858: if (output != NULL) { apetushkov@9858: output->print_cr("No available recordings.\n"); apetushkov@9858: output->print_cr("Use JFR.start to start a recording.\n"); apetushkov@9858: } apetushkov@9858: return false; apetushkov@9858: } apetushkov@9858: return true; apetushkov@9858: } apetushkov@9858: apetushkov@9858: static bool invalid_state(outputStream* out, TRAPS) { apetushkov@9858: DEBUG_ONLY(JfrJavaSupport::check_java_thread_in_vm(THREAD)); apetushkov@9858: return is_disabled(out); apetushkov@9858: } apetushkov@9858: apetushkov@9858: static void print_pending_exception(outputStream* output, oop throwable) { apetushkov@9858: assert(throwable != NULL, "invariant"); apetushkov@9858: apetushkov@9858: oop msg = java_lang_Throwable::message(throwable); apetushkov@9858: apetushkov@9858: if (msg != NULL) { apetushkov@9858: char* text = java_lang_String::as_utf8_string(msg); apetushkov@9858: output->print_raw_cr(text); apetushkov@9858: } apetushkov@9858: } apetushkov@9858: apetushkov@9858: static void print_message(outputStream* output, const char* message) { apetushkov@9858: if (message != NULL) { apetushkov@9858: output->print_raw(message); apetushkov@9858: } apetushkov@9858: } apetushkov@9858: apetushkov@9858: static void handle_dcmd_result(outputStream* output, apetushkov@9858: const oop result, apetushkov@9858: const DCmdSource source, apetushkov@9858: TRAPS) { apetushkov@9858: DEBUG_ONLY(JfrJavaSupport::check_java_thread_in_vm(THREAD)); apetushkov@9858: assert(output != NULL, "invariant"); apetushkov@9858: if (HAS_PENDING_EXCEPTION) { apetushkov@9858: print_pending_exception(output, PENDING_EXCEPTION); apetushkov@9858: // Don't clear excption on startup, JVM should fail initialization. apetushkov@9858: if (DCmd_Source_Internal != source) { apetushkov@9858: CLEAR_PENDING_EXCEPTION; apetushkov@9858: } apetushkov@9858: return; apetushkov@9858: } apetushkov@9858: apetushkov@9858: assert(!HAS_PENDING_EXCEPTION, "invariant"); apetushkov@9858: apetushkov@9858: if (result != NULL) { apetushkov@9858: const char* result_chars = java_lang_String::as_utf8_string(result); apetushkov@9858: print_message(output, result_chars); apetushkov@9858: } apetushkov@9858: } apetushkov@9858: apetushkov@9858: static oop construct_dcmd_instance(JfrJavaArguments* args, TRAPS) { apetushkov@9858: assert(args != NULL, "invariant"); apetushkov@9858: DEBUG_ONLY(JfrJavaSupport::check_java_thread_in_vm(THREAD)); apetushkov@9858: assert(args->klass() != NULL, "invariant"); apetushkov@9858: args->set_name("", CHECK_NULL); apetushkov@9858: args->set_signature("()V", CHECK_NULL); apetushkov@9858: JfrJavaSupport::new_object(args, CHECK_NULL); apetushkov@9858: return (oop)args->result()->get_jobject(); apetushkov@9858: } apetushkov@9858: apetushkov@9858: JfrDumpFlightRecordingDCmd::JfrDumpFlightRecordingDCmd(outputStream* output, apetushkov@9858: bool heap) : DCmdWithParser(output, heap), apetushkov@9858: _name("name", "Recording name, e.g. \\\"My Recording\\\"", "STRING", false, NULL), apetushkov@9858: _filename("filename", "Copy recording data to file, e.g. \\\"" JFR_FILENAME_EXAMPLE "\\\"", "STRING", false), apetushkov@9858: _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"), apetushkov@9858: _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"), apetushkov@9858: _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), apetushkov@9858: _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), apetushkov@9858: _path_to_gc_roots("path-to-gc-roots", "Collect path to GC roots", "BOOLEAN", false, "false") { apetushkov@9858: _dcmdparser.add_dcmd_option(&_name); apetushkov@9858: _dcmdparser.add_dcmd_option(&_filename); apetushkov@9858: _dcmdparser.add_dcmd_option(&_maxage); apetushkov@9858: _dcmdparser.add_dcmd_option(&_maxsize); apetushkov@9858: _dcmdparser.add_dcmd_option(&_begin); apetushkov@9858: _dcmdparser.add_dcmd_option(&_end); apetushkov@9858: _dcmdparser.add_dcmd_option(&_path_to_gc_roots); apetushkov@9858: }; apetushkov@9858: apetushkov@9858: int JfrDumpFlightRecordingDCmd::num_arguments() { apetushkov@9858: ResourceMark rm; apetushkov@9858: JfrDumpFlightRecordingDCmd* dcmd = new JfrDumpFlightRecordingDCmd(NULL, false); apetushkov@9858: if (dcmd != NULL) { apetushkov@9858: DCmdMark mark(dcmd); apetushkov@9858: return dcmd->_dcmdparser.num_arguments(); apetushkov@9858: } apetushkov@9858: return 0; apetushkov@9858: } apetushkov@9858: apetushkov@9858: void JfrDumpFlightRecordingDCmd::execute(DCmdSource source, TRAPS) { apetushkov@9858: DEBUG_ONLY(JfrJavaSupport::check_java_thread_in_vm(THREAD)); apetushkov@9858: apetushkov@9858: if (invalid_state(output(), THREAD) || !is_recorder_instance_created(output())) { apetushkov@9858: return; apetushkov@9858: } apetushkov@9858: apetushkov@9858: ResourceMark rm(THREAD); apetushkov@9858: HandleMark hm(THREAD); apetushkov@9858: JNIHandleBlockManager jni_handle_management(THREAD); apetushkov@9858: apetushkov@9858: JavaValue result(T_OBJECT); apetushkov@9858: JfrJavaArguments constructor_args(&result); apetushkov@9858: constructor_args.set_klass("jdk/jfr/internal/dcmd/DCmdDump", CHECK); apetushkov@9858: const oop dcmd = construct_dcmd_instance(&constructor_args, CHECK); apetushkov@9858: Handle h_dcmd_instance(THREAD, dcmd); apetushkov@9858: assert(h_dcmd_instance.not_null(), "invariant"); apetushkov@9858: apetushkov@9858: jstring name = NULL; apetushkov@9858: if (_name.is_set() && _name.value() != NULL) { apetushkov@9858: name = JfrJavaSupport::new_string(_name.value(), CHECK); apetushkov@9858: } apetushkov@9858: apetushkov@9858: jstring filepath = NULL; apetushkov@9858: if (_filename.is_set() && _filename.value() != NULL) { apetushkov@9858: filepath = JfrJavaSupport::new_string(_filename.value(), CHECK); apetushkov@9858: } apetushkov@9858: apetushkov@9858: jobject maxage = NULL; apetushkov@9858: if (_maxage.is_set()) { apetushkov@9858: maxage = JfrJavaSupport::new_java_lang_Long(_maxage.value()._nanotime, CHECK); apetushkov@9858: } apetushkov@9858: apetushkov@9858: jobject maxsize = NULL; apetushkov@9858: if (_maxsize.is_set()) { apetushkov@9858: maxsize = JfrJavaSupport::new_java_lang_Long(_maxsize.value()._size, CHECK); apetushkov@9858: } apetushkov@9858: apetushkov@9858: jstring begin = NULL; apetushkov@9858: if (_begin.is_set() && _begin.value() != NULL) { apetushkov@9858: begin = JfrJavaSupport::new_string(_begin.value(), CHECK); apetushkov@9858: } apetushkov@9858: apetushkov@9858: jstring end = NULL; apetushkov@9858: if (_end.is_set() && _end.value() != NULL) { apetushkov@9858: end = JfrJavaSupport::new_string(_end.value(), CHECK); apetushkov@9858: } apetushkov@9858: apetushkov@9858: jobject path_to_gc_roots = NULL; apetushkov@9858: if (_path_to_gc_roots.is_set()) { apetushkov@9858: path_to_gc_roots = JfrJavaSupport::new_java_lang_Boolean(_path_to_gc_roots.value(), CHECK); apetushkov@9858: } apetushkov@9858: apetushkov@9858: static const char klass[] = "jdk/jfr/internal/dcmd/DCmdDump"; apetushkov@9858: static const char method[] = "execute"; apetushkov@9858: static 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;"; apetushkov@9858: apetushkov@9858: JfrJavaArguments execute_args(&result, klass, method, signature, CHECK); apetushkov@9858: execute_args.set_receiver(h_dcmd_instance); apetushkov@9858: apetushkov@9858: // arguments apetushkov@9858: execute_args.push_jobject(name); apetushkov@9858: execute_args.push_jobject(filepath); apetushkov@9858: execute_args.push_jobject(maxage); apetushkov@9858: execute_args.push_jobject(maxsize); apetushkov@9858: execute_args.push_jobject(begin); apetushkov@9858: execute_args.push_jobject(end); apetushkov@9858: execute_args.push_jobject(path_to_gc_roots); apetushkov@9858: apetushkov@9858: JfrJavaSupport::call_virtual(&execute_args, THREAD); apetushkov@9858: handle_dcmd_result(output(), (oop)result.get_jobject(), source, THREAD); apetushkov@9858: } apetushkov@9858: apetushkov@9858: JfrCheckFlightRecordingDCmd::JfrCheckFlightRecordingDCmd(outputStream* output, bool heap) : DCmdWithParser(output, heap), apetushkov@9858: _name("name","Recording name, e.g. \\\"My Recording\\\" or omit to see all recordings","STRING",false, NULL), apetushkov@9858: _verbose("verbose","Print event settings for the recording(s)","BOOLEAN", apetushkov@9858: false, "false") { apetushkov@9858: _dcmdparser.add_dcmd_option(&_name); apetushkov@9858: _dcmdparser.add_dcmd_option(&_verbose); apetushkov@9858: }; apetushkov@9858: apetushkov@9858: int JfrCheckFlightRecordingDCmd::num_arguments() { apetushkov@9858: ResourceMark rm; apetushkov@9858: JfrCheckFlightRecordingDCmd* dcmd = new JfrCheckFlightRecordingDCmd(NULL, false); apetushkov@9858: if (dcmd != NULL) { apetushkov@9858: DCmdMark mark(dcmd); apetushkov@9858: return dcmd->_dcmdparser.num_arguments(); apetushkov@9858: } apetushkov@9858: return 0; apetushkov@9858: } apetushkov@9858: apetushkov@9858: void JfrCheckFlightRecordingDCmd::execute(DCmdSource source, TRAPS) { apetushkov@9858: DEBUG_ONLY(JfrJavaSupport::check_java_thread_in_vm(THREAD)); apetushkov@9858: apetushkov@9858: if (invalid_state(output(), THREAD) || !is_recorder_instance_created(output())) { apetushkov@9858: return; apetushkov@9858: } apetushkov@9858: apetushkov@9858: ResourceMark rm(THREAD); apetushkov@9858: HandleMark hm(THREAD); apetushkov@9858: JNIHandleBlockManager jni_handle_management(THREAD); apetushkov@9858: apetushkov@9858: JavaValue result(T_OBJECT); apetushkov@9858: JfrJavaArguments constructor_args(&result); apetushkov@9858: constructor_args.set_klass("jdk/jfr/internal/dcmd/DCmdCheck", CHECK); apetushkov@9858: const oop dcmd = construct_dcmd_instance(&constructor_args, CHECK); apetushkov@9858: Handle h_dcmd_instance(THREAD, dcmd); apetushkov@9858: assert(h_dcmd_instance.not_null(), "invariant"); apetushkov@9858: apetushkov@9858: jstring name = NULL; apetushkov@9858: if (_name.is_set() && _name.value() != NULL) { apetushkov@9858: name = JfrJavaSupport::new_string(_name.value(), CHECK); apetushkov@9858: } apetushkov@9858: apetushkov@9858: jobject verbose = NULL; apetushkov@9858: if (_verbose.is_set()) { apetushkov@9858: verbose = JfrJavaSupport::new_java_lang_Boolean(_verbose.value(), CHECK); apetushkov@9858: } apetushkov@9858: apetushkov@9858: static const char klass[] = "jdk/jfr/internal/dcmd/DCmdCheck"; apetushkov@9858: static const char method[] = "execute"; apetushkov@9858: static const char signature[] = "(Ljava/lang/String;Ljava/lang/Boolean;)Ljava/lang/String;"; apetushkov@9858: apetushkov@9858: JfrJavaArguments execute_args(&result, klass, method, signature, CHECK); apetushkov@9858: execute_args.set_receiver(h_dcmd_instance); apetushkov@9858: apetushkov@9858: // arguments apetushkov@9858: execute_args.push_jobject(name); apetushkov@9858: execute_args.push_jobject(verbose); apetushkov@9858: apetushkov@9858: JfrJavaSupport::call_virtual(&execute_args, THREAD); apetushkov@9858: handle_dcmd_result(output(), (oop)result.get_jobject(), source, THREAD); apetushkov@9858: } apetushkov@9858: apetushkov@9858: JfrStartFlightRecordingDCmd::JfrStartFlightRecordingDCmd(outputStream* output, apetushkov@9858: bool heap) : DCmdWithParser(output, heap), apetushkov@9858: _name("name", "Name that can be used to identify recording, e.g. \\\"My Recording\\\"", "STRING", false, NULL), apetushkov@9858: _settings("settings", "Settings file(s), e.g. profile or default. See JRE_HOME/lib/jfr", "STRING SET", false), apetushkov@9858: _delay("delay", "Delay recording start with (s)econds, (m)inutes), (h)ours), or (d)ays, e.g. 5h.", "NANOTIME", false, "0"), apetushkov@9858: _duration("duration", "Duration of recording in (s)econds, (m)inutes, (h)ours, or (d)ays, e.g. 300s.", "NANOTIME", false, "0"), apetushkov@9858: _filename("filename", "Resulting recording filename, e.g. \\\"" JFR_FILENAME_EXAMPLE "\\\"", "STRING", false), apetushkov@9858: _disk("disk", "Recording should be persisted to disk", "BOOLEAN", false), apetushkov@9858: _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"), apetushkov@9858: _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"), apetushkov@9858: _dump_on_exit("dumponexit", "Dump running recording when JVM shuts down", "BOOLEAN", false), apetushkov@9858: _path_to_gc_roots("path-to-gc-roots", "Collect path to GC roots", "BOOLEAN", false, "false") { apetushkov@9858: _dcmdparser.add_dcmd_option(&_name); apetushkov@9858: _dcmdparser.add_dcmd_option(&_settings); apetushkov@9858: _dcmdparser.add_dcmd_option(&_delay); apetushkov@9858: _dcmdparser.add_dcmd_option(&_duration); apetushkov@9858: _dcmdparser.add_dcmd_option(&_disk); apetushkov@9858: _dcmdparser.add_dcmd_option(&_filename); apetushkov@9858: _dcmdparser.add_dcmd_option(&_maxage); apetushkov@9858: _dcmdparser.add_dcmd_option(&_maxsize); apetushkov@9858: _dcmdparser.add_dcmd_option(&_dump_on_exit); apetushkov@9858: _dcmdparser.add_dcmd_option(&_path_to_gc_roots); apetushkov@9858: }; apetushkov@9858: apetushkov@9858: int JfrStartFlightRecordingDCmd::num_arguments() { apetushkov@9858: ResourceMark rm; apetushkov@9858: JfrStartFlightRecordingDCmd* dcmd = new JfrStartFlightRecordingDCmd(NULL, false); apetushkov@9858: if (dcmd != NULL) { apetushkov@9858: DCmdMark mark(dcmd); apetushkov@9858: return dcmd->_dcmdparser.num_arguments(); apetushkov@9858: } apetushkov@9858: return 0; apetushkov@9858: } apetushkov@9858: apetushkov@9858: void JfrStartFlightRecordingDCmd::execute(DCmdSource source, TRAPS) { apetushkov@9858: DEBUG_ONLY(JfrJavaSupport::check_java_thread_in_vm(THREAD)); apetushkov@9858: apetushkov@9858: if (invalid_state(output(), THREAD)) { apetushkov@9858: return; apetushkov@9858: } apetushkov@9858: apetushkov@9858: ResourceMark rm(THREAD); apetushkov@9858: HandleMark hm(THREAD); apetushkov@9858: JNIHandleBlockManager jni_handle_management(THREAD); apetushkov@9858: apetushkov@9858: JavaValue result(T_OBJECT); apetushkov@9858: JfrJavaArguments constructor_args(&result); apetushkov@9858: constructor_args.set_klass("jdk/jfr/internal/dcmd/DCmdStart", THREAD); apetushkov@9858: const oop dcmd = construct_dcmd_instance(&constructor_args, CHECK); apetushkov@9858: Handle h_dcmd_instance(THREAD, dcmd); apetushkov@9858: assert(h_dcmd_instance.not_null(), "invariant"); apetushkov@9858: apetushkov@9858: jstring name = NULL; apetushkov@9858: if (_name.is_set() && _name.value() != NULL) { apetushkov@9858: name = JfrJavaSupport::new_string(_name.value(), CHECK); apetushkov@9858: } apetushkov@9858: apetushkov@9858: jstring filename = NULL; apetushkov@9858: if (_filename.is_set() && _filename.value() != NULL) { apetushkov@9858: filename = JfrJavaSupport::new_string(_filename.value(), CHECK); apetushkov@9858: } apetushkov@9858: apetushkov@9858: jobject maxage = NULL; apetushkov@9858: if (_maxage.is_set()) { apetushkov@9858: maxage = JfrJavaSupport::new_java_lang_Long(_maxage.value()._nanotime, CHECK); apetushkov@9858: } apetushkov@9858: apetushkov@9858: jobject maxsize = NULL; apetushkov@9858: if (_maxsize.is_set()) { apetushkov@9858: maxsize = JfrJavaSupport::new_java_lang_Long(_maxsize.value()._size, CHECK); apetushkov@9858: } apetushkov@9858: apetushkov@9858: jobject duration = NULL; apetushkov@9858: if (_duration.is_set()) { apetushkov@9858: duration = JfrJavaSupport::new_java_lang_Long(_duration.value()._nanotime, CHECK); apetushkov@9858: } apetushkov@9858: apetushkov@9858: jobject delay = NULL; apetushkov@9858: if (_delay.is_set()) { apetushkov@9858: delay = JfrJavaSupport::new_java_lang_Long(_delay.value()._nanotime, CHECK); apetushkov@9858: } apetushkov@9858: apetushkov@9858: jobject disk = NULL; apetushkov@9858: if (_disk.is_set()) { apetushkov@9858: disk = JfrJavaSupport::new_java_lang_Boolean(_disk.value(), CHECK); apetushkov@9858: } apetushkov@9858: apetushkov@9858: jobject dump_on_exit = NULL; apetushkov@9858: if (_dump_on_exit.is_set()) { apetushkov@9858: dump_on_exit = JfrJavaSupport::new_java_lang_Boolean(_dump_on_exit.value(), CHECK); apetushkov@9858: } apetushkov@9858: apetushkov@9858: jobject path_to_gc_roots = NULL; apetushkov@9858: if (_path_to_gc_roots.is_set()) { apetushkov@9858: path_to_gc_roots = JfrJavaSupport::new_java_lang_Boolean(_path_to_gc_roots.value(), CHECK); apetushkov@9858: } apetushkov@9858: apetushkov@9858: jobjectArray settings = NULL; apetushkov@9858: if (_settings.is_set()) { egahlin@9883: int length = _settings.value()->array()->length(); egahlin@9883: if (length == 1) { egahlin@9883: const char* c_str = _settings.value()->array()->at(0); egahlin@9883: if (strcmp(c_str, "none") == 0) { egahlin@9883: length = 0; egahlin@9883: } egahlin@9883: } apetushkov@9858: settings = JfrJavaSupport::new_string_array(length, CHECK); apetushkov@9858: assert(settings != NULL, "invariant"); apetushkov@9858: for (int i = 0; i < length; ++i) { apetushkov@9858: jobject element = JfrJavaSupport::new_string(_settings.value()->array()->at(i), CHECK); apetushkov@9858: assert(element != NULL, "invariant"); apetushkov@9858: JfrJavaSupport::set_array_element(settings, element, i, CHECK); apetushkov@9858: } egahlin@9889: } else { egahlin@9889: settings = JfrJavaSupport::new_string_array(1, CHECK); egahlin@9889: assert(settings != NULL, "invariant"); egahlin@9889: jobject element = JfrJavaSupport::new_string("default", CHECK); egahlin@9889: assert(element != NULL, "invariant"); egahlin@9889: JfrJavaSupport::set_array_element(settings, element, 0, CHECK); apetushkov@9858: } apetushkov@9858: apetushkov@9858: static const char klass[] = "jdk/jfr/internal/dcmd/DCmdStart"; apetushkov@9858: static const char method[] = "execute"; apetushkov@9858: static const char signature[] = "(Ljava/lang/String;[Ljava/lang/String;Ljava/lang/Long;" apetushkov@9858: "Ljava/lang/Long;Ljava/lang/Boolean;Ljava/lang/String;" apetushkov@9858: "Ljava/lang/Long;Ljava/lang/Long;Ljava/lang/Boolean;Ljava/lang/Boolean;)Ljava/lang/String;"; apetushkov@9858: apetushkov@9858: JfrJavaArguments execute_args(&result, klass, method, signature, CHECK); apetushkov@9858: execute_args.set_receiver(h_dcmd_instance); apetushkov@9858: apetushkov@9858: // arguments apetushkov@9858: execute_args.push_jobject(name); apetushkov@9858: execute_args.push_jobject(settings); apetushkov@9858: execute_args.push_jobject(delay); apetushkov@9858: execute_args.push_jobject(duration); apetushkov@9858: execute_args.push_jobject(disk); apetushkov@9858: execute_args.push_jobject(filename); apetushkov@9858: execute_args.push_jobject(maxage); apetushkov@9858: execute_args.push_jobject(maxsize); apetushkov@9858: execute_args.push_jobject(dump_on_exit); apetushkov@9858: execute_args.push_jobject(path_to_gc_roots); apetushkov@9858: apetushkov@9858: JfrJavaSupport::call_virtual(&execute_args, THREAD); apetushkov@9858: handle_dcmd_result(output(), (oop)result.get_jobject(), source, THREAD); apetushkov@9858: } apetushkov@9858: apetushkov@9858: JfrStopFlightRecordingDCmd::JfrStopFlightRecordingDCmd(outputStream* output, apetushkov@9858: bool heap) : DCmdWithParser(output, heap), apetushkov@9858: _name("name", "Recording text,.e.g \\\"My Recording\\\"", "STRING", true, NULL), apetushkov@9858: _filename("filename", "Copy recording data to file, e.g. \\\"" JFR_FILENAME_EXAMPLE "\\\"", "STRING", false, NULL) { apetushkov@9858: _dcmdparser.add_dcmd_option(&_name); apetushkov@9858: _dcmdparser.add_dcmd_option(&_filename); apetushkov@9858: }; apetushkov@9858: apetushkov@9858: int JfrStopFlightRecordingDCmd::num_arguments() { apetushkov@9858: ResourceMark rm; apetushkov@9858: JfrStopFlightRecordingDCmd* dcmd = new JfrStopFlightRecordingDCmd(NULL, false); apetushkov@9858: if (dcmd != NULL) { apetushkov@9858: DCmdMark mark(dcmd); apetushkov@9858: return dcmd->_dcmdparser.num_arguments(); apetushkov@9858: } apetushkov@9858: return 0; apetushkov@9858: } apetushkov@9858: apetushkov@9858: void JfrStopFlightRecordingDCmd::execute(DCmdSource source, TRAPS) { apetushkov@9858: DEBUG_ONLY(JfrJavaSupport::check_java_thread_in_vm(THREAD)); apetushkov@9858: apetushkov@9858: if (invalid_state(output(), THREAD) || !is_recorder_instance_created(output())) { apetushkov@9858: return; apetushkov@9858: } apetushkov@9858: apetushkov@9858: ResourceMark rm(THREAD); apetushkov@9858: HandleMark hm(THREAD); apetushkov@9858: JNIHandleBlockManager jni_handle_management(THREAD); apetushkov@9858: apetushkov@9858: JavaValue result(T_OBJECT); apetushkov@9858: JfrJavaArguments constructor_args(&result); apetushkov@9858: constructor_args.set_klass("jdk/jfr/internal/dcmd/DCmdStop", CHECK); apetushkov@9858: const oop dcmd = construct_dcmd_instance(&constructor_args, CHECK); apetushkov@9858: Handle h_dcmd_instance(THREAD, dcmd); apetushkov@9858: assert(h_dcmd_instance.not_null(), "invariant"); apetushkov@9858: apetushkov@9858: jstring name = NULL; apetushkov@9858: if (_name.is_set() && _name.value() != NULL) { apetushkov@9858: name = JfrJavaSupport::new_string(_name.value(), CHECK); apetushkov@9858: } apetushkov@9858: apetushkov@9858: jstring filepath = NULL; apetushkov@9858: if (_filename.is_set() && _filename.value() != NULL) { apetushkov@9858: filepath = JfrJavaSupport::new_string(_filename.value(), CHECK); apetushkov@9858: } apetushkov@9858: apetushkov@9858: static const char klass[] = "jdk/jfr/internal/dcmd/DCmdStop"; apetushkov@9858: static const char method[] = "execute"; apetushkov@9858: static const char signature[] = "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;"; apetushkov@9858: apetushkov@9858: JfrJavaArguments execute_args(&result, klass, method, signature, CHECK); apetushkov@9858: execute_args.set_receiver(h_dcmd_instance); apetushkov@9858: apetushkov@9858: // arguments apetushkov@9858: execute_args.push_jobject(name); apetushkov@9858: execute_args.push_jobject(filepath); apetushkov@9858: apetushkov@9858: JfrJavaSupport::call_virtual(&execute_args, THREAD); apetushkov@9858: handle_dcmd_result(output(), (oop)result.get_jobject(), source, THREAD); apetushkov@9858: } apetushkov@9858: apetushkov@9858: JfrConfigureFlightRecorderDCmd::JfrConfigureFlightRecorderDCmd(outputStream* output, apetushkov@9858: bool heap) : DCmdWithParser(output, heap), apetushkov@9858: _repository_path("repositorypath", "Path to repository,.e.g \\\"My Repository\\\"", "STRING", false, NULL), apetushkov@9858: _dump_path("dumppath", "Path to dump,.e.g \\\"My Dump path\\\"", "STRING", false, NULL), ysuenaga@9870: _stack_depth("stackdepth", "Stack Depth", "JULONG", false, "64"), ysuenaga@9870: _global_buffer_count("globalbuffercount", "Number of global buffers,", "JULONG", false, "20"), ysuenaga@9870: _global_buffer_size("globalbuffersize", "Size of a global buffers,", "MEMORY SIZE", false, "512k"), ysuenaga@9870: _thread_buffer_size("thread_buffer_size", "Size of a thread buffer", "MEMORY SIZE", false, "8k"), ysuenaga@9870: _memory_size("memorysize", "Overall memory size, ", "MEMORY SIZE", false, "10m"), ysuenaga@9870: _max_chunk_size("maxchunksize", "Size of an individual disk chunk", "MEMORY SIZE", false, "12m"), apetushkov@9858: _sample_threads("samplethreads", "Activate Thread sampling", "BOOLEAN", false, "true") { apetushkov@9858: _dcmdparser.add_dcmd_option(&_repository_path); apetushkov@9858: _dcmdparser.add_dcmd_option(&_dump_path); apetushkov@9858: _dcmdparser.add_dcmd_option(&_stack_depth); apetushkov@9858: _dcmdparser.add_dcmd_option(&_global_buffer_count); apetushkov@9858: _dcmdparser.add_dcmd_option(&_global_buffer_size); apetushkov@9858: _dcmdparser.add_dcmd_option(&_thread_buffer_size); apetushkov@9858: _dcmdparser.add_dcmd_option(&_memory_size); apetushkov@9858: _dcmdparser.add_dcmd_option(&_max_chunk_size); apetushkov@9858: _dcmdparser.add_dcmd_option(&_sample_threads); apetushkov@9858: }; apetushkov@9858: apetushkov@9858: int JfrConfigureFlightRecorderDCmd::num_arguments() { apetushkov@9858: ResourceMark rm; apetushkov@9858: JfrConfigureFlightRecorderDCmd* dcmd = new JfrConfigureFlightRecorderDCmd(NULL, false); apetushkov@9858: if (dcmd != NULL) { apetushkov@9858: DCmdMark mark(dcmd); apetushkov@9858: return dcmd->_dcmdparser.num_arguments(); apetushkov@9858: } apetushkov@9858: return 0; apetushkov@9858: } apetushkov@9858: apetushkov@9858: void JfrConfigureFlightRecorderDCmd::execute(DCmdSource source, TRAPS) { apetushkov@9858: DEBUG_ONLY(JfrJavaSupport::check_java_thread_in_vm(THREAD)); apetushkov@9858: apetushkov@9858: if (invalid_state(output(), THREAD)) { apetushkov@9858: return; apetushkov@9858: } apetushkov@9858: apetushkov@9858: ResourceMark rm(THREAD); apetushkov@9858: HandleMark hm(THREAD); apetushkov@9858: JNIHandleBlockManager jni_handle_management(THREAD); apetushkov@9858: apetushkov@9858: JavaValue result(T_OBJECT); apetushkov@9858: JfrJavaArguments constructor_args(&result); apetushkov@9858: constructor_args.set_klass("jdk/jfr/internal/dcmd/DCmdConfigure", CHECK); apetushkov@9858: const oop dcmd = construct_dcmd_instance(&constructor_args, CHECK); apetushkov@9858: Handle h_dcmd_instance(THREAD, dcmd); apetushkov@9858: assert(h_dcmd_instance.not_null(), "invariant"); apetushkov@9858: apetushkov@9858: jstring repository_path = NULL; apetushkov@9858: if (_repository_path.is_set() && _repository_path.value() != NULL) { apetushkov@9858: repository_path = JfrJavaSupport::new_string(_repository_path.value(), CHECK); apetushkov@9858: } apetushkov@9858: apetushkov@9858: jstring dump_path = NULL; apetushkov@9858: if (_dump_path.is_set() && _dump_path.value() != NULL) { apetushkov@9858: dump_path = JfrJavaSupport::new_string(_dump_path.value(), CHECK); apetushkov@9858: } apetushkov@9858: apetushkov@9858: jobject stack_depth = NULL; apetushkov@9858: if (_stack_depth.is_set()) { apetushkov@9858: stack_depth = JfrJavaSupport::new_java_lang_Integer((jint)_stack_depth.value(), CHECK); apetushkov@9858: } apetushkov@9858: apetushkov@9858: jobject global_buffer_count = NULL; apetushkov@9858: if (_global_buffer_count.is_set()) { apetushkov@9858: global_buffer_count = JfrJavaSupport::new_java_lang_Long(_global_buffer_count.value(), CHECK); apetushkov@9858: } apetushkov@9858: apetushkov@9858: jobject global_buffer_size = NULL; apetushkov@9858: if (_global_buffer_size.is_set()) { ysuenaga@9870: global_buffer_size = JfrJavaSupport::new_java_lang_Long(_global_buffer_size.value()._size, CHECK); apetushkov@9858: } apetushkov@9858: apetushkov@9858: jobject thread_buffer_size = NULL; apetushkov@9858: if (_thread_buffer_size.is_set()) { ysuenaga@9870: thread_buffer_size = JfrJavaSupport::new_java_lang_Long(_thread_buffer_size.value()._size, CHECK); apetushkov@9858: } apetushkov@9858: apetushkov@9858: jobject max_chunk_size = NULL; apetushkov@9858: if (_max_chunk_size.is_set()) { ysuenaga@9870: max_chunk_size = JfrJavaSupport::new_java_lang_Long(_max_chunk_size.value()._size, CHECK); apetushkov@9858: } apetushkov@9858: apetushkov@9858: jobject memory_size = NULL; apetushkov@9858: if (_memory_size.is_set()) { ysuenaga@9870: memory_size = JfrJavaSupport::new_java_lang_Long(_memory_size.value()._size, CHECK); apetushkov@9858: } apetushkov@9858: apetushkov@9858: jobject sample_threads = NULL; apetushkov@9858: if (_sample_threads.is_set()) { apetushkov@9858: sample_threads = JfrJavaSupport::new_java_lang_Boolean(_sample_threads.value(), CHECK); apetushkov@9858: } apetushkov@9858: apetushkov@9858: static const char klass[] = "jdk/jfr/internal/dcmd/DCmdConfigure"; apetushkov@9858: static const char method[] = "execute"; apetushkov@9858: static const char signature[] = "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Integer;" apetushkov@9858: "Ljava/lang/Long;Ljava/lang/Long;Ljava/lang/Long;Ljava/lang/Long;" apetushkov@9858: "Ljava/lang/Long;Ljava/lang/Boolean;)Ljava/lang/String;"; apetushkov@9858: apetushkov@9858: JfrJavaArguments execute_args(&result, klass, method, signature, CHECK); apetushkov@9858: execute_args.set_receiver(h_dcmd_instance); apetushkov@9858: apetushkov@9858: // params apetushkov@9858: execute_args.push_jobject(repository_path); apetushkov@9858: execute_args.push_jobject(dump_path); apetushkov@9858: execute_args.push_jobject(stack_depth); apetushkov@9858: execute_args.push_jobject(global_buffer_count); apetushkov@9858: execute_args.push_jobject(global_buffer_size); apetushkov@9858: execute_args.push_jobject(thread_buffer_size); apetushkov@9858: execute_args.push_jobject(memory_size); apetushkov@9858: execute_args.push_jobject(max_chunk_size); apetushkov@9858: execute_args.push_jobject(sample_threads); apetushkov@9858: apetushkov@9858: JfrJavaSupport::call_virtual(&execute_args, THREAD); apetushkov@9858: handle_dcmd_result(output(), (oop)result.get_jobject(), source, THREAD); apetushkov@9858: } apetushkov@9858: apetushkov@9858: bool register_jfr_dcmds() { apetushkov@9858: uint32_t full_export = DCmd_Source_Internal | DCmd_Source_AttachAPI | DCmd_Source_MBean; apetushkov@9858: DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl(full_export, true, false)); apetushkov@9858: DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl(full_export, true, false)); apetushkov@9858: DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl(full_export, true, false)); apetushkov@9858: DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl(full_export, true, false)); apetushkov@9858: DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl(full_export, true, false)); apetushkov@9858: apetushkov@9858: DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl(full_export, true, false)); apetushkov@9858: return true; apetushkov@9858: } apetushkov@9858: