--- old/src/hotspot/share/services/attachListener.hpp 2019-07-11 08:48:53.123153857 +0900 +++ new/src/hotspot/share/services/attachListener.hpp 2019-07-11 08:48:53.034153760 +0900 @@ -26,6 +26,8 @@ #define SHARE_SERVICES_ATTACHLISTENER_HPP #include "memory/allocation.hpp" +#include "metaprogramming/isRegisteredEnum.hpp" +#include "runtime/atomic.hpp" #include "utilities/debug.hpp" #include "utilities/globalDefinitions.hpp" #include "utilities/macros.hpp" @@ -49,6 +51,14 @@ AttachOperationFunction func; }; +enum AttachListenerState { + AL_NOT_INITIALIZED, + AL_INITIALIZING, + AL_INITIALIZED +}; + +template<> struct IsRegisteredEnum : public TrueType {}; + class AttachListener: AllStatic { public: static void vm_start() NOT_SERVICES_RETURN; @@ -58,6 +68,9 @@ // invoke to perform clean-up tasks when all clients detach static void detachall() NOT_SERVICES_RETURN; + // check unix domain socket file on filesystem + static bool check_socket_file() NOT_SERVICES_RETURN_(false); + // indicates if the Attach Listener needs to be created at startup static bool init_at_startup() NOT_SERVICES_RETURN_(false); @@ -67,12 +80,31 @@ #if !INCLUDE_SERVICES static bool is_attach_supported() { return false; } #else + private: - static volatile bool _initialized; + static volatile AttachListenerState _state; public: - static bool is_initialized() { return _initialized; } - static void set_initialized() { _initialized = true; } + static void set_state(AttachListenerState new_state) { + Atomic::store(new_state, &_state); + } + + static AttachListenerState get_state() { + return Atomic::load(&_state); + } + + static AttachListenerState transit_state(AttachListenerState new_state, + AttachListenerState cmp_state) { + return Atomic::cmpxchg(new_state, &_state, cmp_state); + } + + static bool is_initialized() { + return Atomic::load(&_state) == AL_INITIALIZED; + } + + static void set_initialized() { + Atomic::store(AL_INITIALIZED, &_state); + } // indicates if this VM supports attach-on-demand static bool is_attach_supported() { return !DisableAttachMechanism; }