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