9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #ifndef SHARE_SERVICES_ATTACHLISTENER_HPP 26 #define SHARE_SERVICES_ATTACHLISTENER_HPP 27 28 #include "memory/allocation.hpp" 29 #include "utilities/debug.hpp" 30 #include "utilities/globalDefinitions.hpp" 31 #include "utilities/macros.hpp" 32 #include "utilities/ostream.hpp" 33 34 // The AttachListener thread services a queue of operations that are enqueued 35 // by client tools. Each operation is identified by a name and has up to 3 36 // arguments. The operation name is mapped to a function which performs the 37 // operation. The function is called with an outputStream which is can use to 38 // write any result data (for examples the properties command serializes 39 // properties names and values to the output stream). When the function 40 // complets the result value and any result data is returned to the client 41 // tool. 42 43 class AttachOperation; 44 45 typedef jint (*AttachOperationFunction)(AttachOperation* op, outputStream* out); 46 47 struct AttachOperationFunctionInfo { 48 const char* name; 49 AttachOperationFunction func; 50 }; 51 52 class AttachListener: AllStatic { 53 public: 54 static void vm_start() NOT_SERVICES_RETURN; 55 static void init() NOT_SERVICES_RETURN; 56 static void abort() NOT_SERVICES_RETURN; 57 58 // invoke to perform clean-up tasks when all clients detach 59 static void detachall() NOT_SERVICES_RETURN; 60 61 // indicates if the Attach Listener needs to be created at startup 62 static bool init_at_startup() NOT_SERVICES_RETURN_(false); 63 64 // indicates if we have a trigger to start the Attach Listener 65 static bool is_init_trigger() NOT_SERVICES_RETURN_(false); 66 67 #if !INCLUDE_SERVICES 68 static bool is_attach_supported() { return false; } 69 #else 70 private: 71 static volatile bool _initialized; 72 73 public: 74 static bool is_initialized() { return _initialized; } 75 static void set_initialized() { _initialized = true; } 76 77 // indicates if this VM supports attach-on-demand 78 static bool is_attach_supported() { return !DisableAttachMechanism; } 79 80 // platform specific initialization 81 static int pd_init(); 82 83 // platform specific operation 84 static AttachOperationFunctionInfo* pd_find_operation(const char* name); 85 86 // platform specific flag change 87 static jint pd_set_flag(AttachOperation* op, outputStream* out); 88 89 // platform specific detachall 90 static void pd_detachall(); 91 92 // platform specific data dump 93 static void pd_data_dump(); 94 95 // dequeue the next operation | 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #ifndef SHARE_SERVICES_ATTACHLISTENER_HPP 26 #define SHARE_SERVICES_ATTACHLISTENER_HPP 27 28 #include "memory/allocation.hpp" 29 #include "metaprogramming/isRegisteredEnum.hpp" 30 #include "runtime/atomic.hpp" 31 #include "utilities/debug.hpp" 32 #include "utilities/globalDefinitions.hpp" 33 #include "utilities/macros.hpp" 34 #include "utilities/ostream.hpp" 35 36 // The AttachListener thread services a queue of operations that are enqueued 37 // by client tools. Each operation is identified by a name and has up to 3 38 // arguments. The operation name is mapped to a function which performs the 39 // operation. The function is called with an outputStream which is can use to 40 // write any result data (for examples the properties command serializes 41 // properties names and values to the output stream). When the function 42 // complets the result value and any result data is returned to the client 43 // tool. 44 45 class AttachOperation; 46 47 typedef jint (*AttachOperationFunction)(AttachOperation* op, outputStream* out); 48 49 struct AttachOperationFunctionInfo { 50 const char* name; 51 AttachOperationFunction func; 52 }; 53 54 enum AttachListenerState { 55 AL_NOT_INITIALIZED, 56 AL_INITIALIZING, 57 AL_INITIALIZED 58 }; 59 60 template<> struct IsRegisteredEnum<AttachListenerState> : public TrueType {}; 61 62 class AttachListener: AllStatic { 63 public: 64 static void vm_start() NOT_SERVICES_RETURN; 65 static void init() NOT_SERVICES_RETURN; 66 static void abort() NOT_SERVICES_RETURN; 67 68 // invoke to perform clean-up tasks when all clients detach 69 static void detachall() NOT_SERVICES_RETURN; 70 71 // check unix domain socket file on filesystem 72 static bool check_socket_file() NOT_SERVICES_RETURN_(false); 73 74 // indicates if the Attach Listener needs to be created at startup 75 static bool init_at_startup() NOT_SERVICES_RETURN_(false); 76 77 // indicates if we have a trigger to start the Attach Listener 78 static bool is_init_trigger() NOT_SERVICES_RETURN_(false); 79 80 #if !INCLUDE_SERVICES 81 static bool is_attach_supported() { return false; } 82 #else 83 84 private: 85 static volatile AttachListenerState _state; 86 87 public: 88 static void set_state(AttachListenerState new_state) { 89 Atomic::store(new_state, &_state); 90 } 91 92 static AttachListenerState get_state() { 93 return Atomic::load(&_state); 94 } 95 96 static AttachListenerState transit_state(AttachListenerState new_state, 97 AttachListenerState cmp_state) { 98 return Atomic::cmpxchg(new_state, &_state, cmp_state); 99 } 100 101 static bool is_initialized() { 102 return Atomic::load(&_state) == AL_INITIALIZED; 103 } 104 105 static void set_initialized() { 106 Atomic::store(AL_INITIALIZED, &_state); 107 } 108 109 // indicates if this VM supports attach-on-demand 110 static bool is_attach_supported() { return !DisableAttachMechanism; } 111 112 // platform specific initialization 113 static int pd_init(); 114 115 // platform specific operation 116 static AttachOperationFunctionInfo* pd_find_operation(const char* name); 117 118 // platform specific flag change 119 static jint pd_set_flag(AttachOperation* op, outputStream* out); 120 121 // platform specific detachall 122 static void pd_detachall(); 123 124 // platform specific data dump 125 static void pd_data_dump(); 126 127 // dequeue the next operation |