src/share/vm/services/attachListener.hpp

Mon, 12 Aug 2019 18:30:40 +0300

author
apetushkov
date
Mon, 12 Aug 2019 18:30:40 +0300
changeset 9858
b985cbb00e68
parent 9313
fd0ca2c1433b
child 9448
73d689add964
permissions
-rw-r--r--

8223147: JFR Backport
8199712: Flight Recorder
8203346: JFR: Inconsistent signature of jfr_add_string_constant
8195817: JFR.stop should require name of recording
8195818: JFR.start should increase autogenerated name by one
8195819: Remove recording=x from jcmd JFR.check output
8203921: JFR thread sampling is missing fixes from JDK-8194552
8203929: Limit amount of data for JFR.dump
8203664: JFR start failure after AppCDS archive created with JFR StartFlightRecording
8003209: JFR events for network utilization
8207392: [PPC64] Implement JFR profiling
8202835: jfr/event/os/TestSystemProcess.java fails on missing events
Summary: Backport JFR from JDK11. Initial integration
Reviewed-by: neugens

duke@435 1 /*
zgu@4492 2 * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #ifndef SHARE_VM_SERVICES_ATTACHLISTENER_HPP
stefank@2314 26 #define SHARE_VM_SERVICES_ATTACHLISTENER_HPP
stefank@2314 27
stefank@2314 28 #include "memory/allocation.hpp"
stefank@2314 29 #include "utilities/debug.hpp"
stefank@2314 30 #include "utilities/ostream.hpp"
jprovino@4542 31 #include "utilities/macros.hpp"
stefank@2314 32
duke@435 33 // The AttachListener thread services a queue of operations that are enqueued
duke@435 34 // by client tools. Each operation is identified by a name and has up to 3
duke@435 35 // arguments. The operation name is mapped to a function which performs the
duke@435 36 // operation. The function is called with an outputStream which is can use to
duke@435 37 // write any result data (for examples the properties command serializes
duke@435 38 // properties names and values to the output stream). When the function
duke@435 39 // complets the result value and any result data is returned to the client
duke@435 40 // tool.
duke@435 41
duke@435 42 class AttachOperation;
duke@435 43
duke@435 44 typedef jint (*AttachOperationFunction)(AttachOperation* op, outputStream* out);
duke@435 45
duke@435 46 struct AttachOperationFunctionInfo {
duke@435 47 const char* name;
duke@435 48 AttachOperationFunction func;
duke@435 49 };
duke@435 50
duke@435 51 class AttachListener: AllStatic {
duke@435 52 public:
allwin@5412 53 static void vm_start() NOT_SERVICES_RETURN;
jprovino@4165 54 static void init() NOT_SERVICES_RETURN;
jprovino@4165 55 static void abort() NOT_SERVICES_RETURN;
duke@435 56
duke@435 57 // invoke to perform clean-up tasks when all clients detach
jprovino@4165 58 static void detachall() NOT_SERVICES_RETURN;
duke@435 59
duke@435 60 // indicates if the Attach Listener needs to be created at startup
jprovino@4165 61 static bool init_at_startup() NOT_SERVICES_RETURN_(false);
duke@435 62
duke@435 63 // indicates if we have a trigger to start the Attach Listener
jprovino@4165 64 static bool is_init_trigger() NOT_SERVICES_RETURN_(false);
duke@435 65
jprovino@4165 66 #if !INCLUDE_SERVICES
duke@435 67 static bool is_attach_supported() { return false; }
jprovino@4165 68 #else
duke@435 69 private:
duke@435 70 static volatile bool _initialized;
duke@435 71
duke@435 72 public:
duke@435 73 static bool is_initialized() { return _initialized; }
duke@435 74 static void set_initialized() { _initialized = true; }
duke@435 75
duke@435 76 // indicates if this VM supports attach-on-demand
duke@435 77 static bool is_attach_supported() { return !DisableAttachMechanism; }
duke@435 78
duke@435 79 // platform specific initialization
duke@435 80 static int pd_init();
duke@435 81
duke@435 82 // platform specific operation
duke@435 83 static AttachOperationFunctionInfo* pd_find_operation(const char* name);
duke@435 84
duke@435 85 // platform specific flag change
duke@435 86 static jint pd_set_flag(AttachOperation* op, outputStream* out);
duke@435 87
duke@435 88 // platform specific detachall
duke@435 89 static void pd_detachall();
duke@435 90
duke@435 91 // platform specific data dump
duke@435 92 static void pd_data_dump();
duke@435 93
duke@435 94 // dequeue the next operation
duke@435 95 static AttachOperation* dequeue();
jprovino@4165 96 #endif // !INCLUDE_SERVICES
zgu@9313 97
zgu@9313 98 private:
zgu@9313 99 static bool has_init_error(TRAPS);
duke@435 100 };
duke@435 101
jprovino@4165 102 #if INCLUDE_SERVICES
zgu@3900 103 class AttachOperation: public CHeapObj<mtInternal> {
duke@435 104 public:
duke@435 105 enum {
duke@435 106 name_length_max = 16, // maximum length of name
duke@435 107 arg_length_max = 1024, // maximum length of argument
duke@435 108 arg_count_max = 3 // maximum number of arguments
duke@435 109 };
duke@435 110
duke@435 111 // name of special operation that can be enqueued when all
duke@435 112 // clients detach
duke@435 113 static char* detachall_operation_name() { return (char*)"detachall"; }
duke@435 114
duke@435 115 private:
duke@435 116 char _name[name_length_max+1];
duke@435 117 char _arg[arg_count_max][arg_length_max+1];
duke@435 118
duke@435 119 public:
duke@435 120 const char* name() const { return _name; }
duke@435 121
duke@435 122 // set the operation name
duke@435 123 void set_name(char* name) {
duke@435 124 assert(strlen(name) <= name_length_max, "exceeds maximum name length");
duke@435 125 strcpy(_name, name);
duke@435 126 }
duke@435 127
duke@435 128 // get an argument value
duke@435 129 const char* arg(int i) const {
duke@435 130 assert(i>=0 && i<arg_count_max, "invalid argument index");
duke@435 131 return _arg[i];
duke@435 132 }
duke@435 133
duke@435 134 // set an argument value
duke@435 135 void set_arg(int i, char* arg) {
duke@435 136 assert(i>=0 && i<arg_count_max, "invalid argument index");
duke@435 137 if (arg == NULL) {
duke@435 138 _arg[i][0] = '\0';
duke@435 139 } else {
duke@435 140 assert(strlen(arg) <= arg_length_max, "exceeds maximum argument length");
duke@435 141 strcpy(_arg[i], arg);
duke@435 142 }
duke@435 143 }
duke@435 144
duke@435 145 // create an operation of a given name
duke@435 146 AttachOperation(char* name) {
duke@435 147 set_name(name);
duke@435 148 for (int i=0; i<arg_count_max; i++) {
duke@435 149 set_arg(i, NULL);
duke@435 150 }
duke@435 151 }
duke@435 152
duke@435 153 // complete operation by sending result code and any result data to the client
duke@435 154 virtual void complete(jint result, bufferedStream* result_stream) = 0;
duke@435 155 };
jprovino@4165 156 #endif // INCLUDE_SERVICES
stefank@2314 157
stefank@2314 158 #endif // SHARE_VM_SERVICES_ATTACHLISTENER_HPP

mercurial