duke@435: /* zgu@4492: * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #ifndef SHARE_VM_SERVICES_ATTACHLISTENER_HPP stefank@2314: #define SHARE_VM_SERVICES_ATTACHLISTENER_HPP stefank@2314: stefank@2314: #include "memory/allocation.hpp" stefank@2314: #include "utilities/debug.hpp" stefank@2314: #include "utilities/ostream.hpp" stefank@2314: duke@435: // The AttachListener thread services a queue of operations that are enqueued duke@435: // by client tools. Each operation is identified by a name and has up to 3 duke@435: // arguments. The operation name is mapped to a function which performs the duke@435: // operation. The function is called with an outputStream which is can use to duke@435: // write any result data (for examples the properties command serializes duke@435: // properties names and values to the output stream). When the function duke@435: // complets the result value and any result data is returned to the client duke@435: // tool. duke@435: duke@435: class AttachOperation; duke@435: duke@435: typedef jint (*AttachOperationFunction)(AttachOperation* op, outputStream* out); duke@435: duke@435: struct AttachOperationFunctionInfo { duke@435: const char* name; duke@435: AttachOperationFunction func; duke@435: }; duke@435: duke@435: class AttachListener: AllStatic { duke@435: public: jprovino@4165: static void init() NOT_SERVICES_RETURN; jprovino@4165: static void abort() NOT_SERVICES_RETURN; duke@435: duke@435: // invoke to perform clean-up tasks when all clients detach jprovino@4165: static void detachall() NOT_SERVICES_RETURN; duke@435: duke@435: // indicates if the Attach Listener needs to be created at startup jprovino@4165: static bool init_at_startup() NOT_SERVICES_RETURN_(false); duke@435: duke@435: // indicates if we have a trigger to start the Attach Listener jprovino@4165: static bool is_init_trigger() NOT_SERVICES_RETURN_(false); duke@435: jprovino@4165: #if !INCLUDE_SERVICES duke@435: static bool is_attach_supported() { return false; } jprovino@4165: #else duke@435: private: duke@435: static volatile bool _initialized; duke@435: duke@435: public: duke@435: static bool is_initialized() { return _initialized; } duke@435: static void set_initialized() { _initialized = true; } duke@435: duke@435: // indicates if this VM supports attach-on-demand duke@435: static bool is_attach_supported() { return !DisableAttachMechanism; } duke@435: duke@435: // platform specific initialization duke@435: static int pd_init(); duke@435: duke@435: // platform specific operation duke@435: static AttachOperationFunctionInfo* pd_find_operation(const char* name); duke@435: duke@435: // platform specific flag change duke@435: static jint pd_set_flag(AttachOperation* op, outputStream* out); duke@435: duke@435: // platform specific detachall duke@435: static void pd_detachall(); duke@435: duke@435: // platform specific data dump duke@435: static void pd_data_dump(); duke@435: duke@435: // dequeue the next operation duke@435: static AttachOperation* dequeue(); jprovino@4165: #endif // !INCLUDE_SERVICES duke@435: }; duke@435: jprovino@4165: #if INCLUDE_SERVICES zgu@3900: class AttachOperation: public CHeapObj { duke@435: public: duke@435: enum { duke@435: name_length_max = 16, // maximum length of name duke@435: arg_length_max = 1024, // maximum length of argument duke@435: arg_count_max = 3 // maximum number of arguments duke@435: }; duke@435: duke@435: // name of special operation that can be enqueued when all duke@435: // clients detach duke@435: static char* detachall_operation_name() { return (char*)"detachall"; } duke@435: duke@435: private: duke@435: char _name[name_length_max+1]; duke@435: char _arg[arg_count_max][arg_length_max+1]; duke@435: duke@435: public: duke@435: const char* name() const { return _name; } duke@435: duke@435: // set the operation name duke@435: void set_name(char* name) { duke@435: assert(strlen(name) <= name_length_max, "exceeds maximum name length"); duke@435: strcpy(_name, name); duke@435: } duke@435: duke@435: // get an argument value duke@435: const char* arg(int i) const { duke@435: assert(i>=0 && i=0 && i