author | herrick |
Fri, 18 Oct 2019 14:14:37 -0400 | |
branch | JDK-8200758-branch |
changeset 58696 | 61c44899b4eb |
parent 55682 | 70fab3a8ff02 |
child 59248 | e92153ed8bdc |
permissions | -rw-r--r-- |
1 | 1 |
/* |
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
49406
diff
changeset
|
2 |
* Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved. |
1 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
49406
diff
changeset
|
25 |
#ifndef SHARE_SERVICES_ATTACHLISTENER_HPP |
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
49406
diff
changeset
|
26 |
#define SHARE_SERVICES_ATTACHLISTENER_HPP |
7397 | 27 |
|
28 |
#include "memory/allocation.hpp" |
|
55682
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
54851
diff
changeset
|
29 |
#include "metaprogramming/isRegisteredEnum.hpp" |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
54851
diff
changeset
|
30 |
#include "runtime/atomic.hpp" |
7397 | 31 |
#include "utilities/debug.hpp" |
49406
f654b37c58a1
8199010: attachListener.hpp: Fix potential null termination issue found by coverity scans
clanger
parents:
47216
diff
changeset
|
32 |
#include "utilities/globalDefinitions.hpp" |
15482
470d0b0c09f1
8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents:
13977
diff
changeset
|
33 |
#include "utilities/macros.hpp" |
49406
f654b37c58a1
8199010: attachListener.hpp: Fix potential null termination issue found by coverity scans
clanger
parents:
47216
diff
changeset
|
34 |
#include "utilities/ostream.hpp" |
7397 | 35 |
|
1 | 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 |
||
55682
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
54851
diff
changeset
|
54 |
enum AttachListenerState { |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
54851
diff
changeset
|
55 |
AL_NOT_INITIALIZED, |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
54851
diff
changeset
|
56 |
AL_INITIALIZING, |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
54851
diff
changeset
|
57 |
AL_INITIALIZED |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
54851
diff
changeset
|
58 |
}; |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
54851
diff
changeset
|
59 |
|
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
54851
diff
changeset
|
60 |
template<> struct IsRegisteredEnum<AttachListenerState> : public TrueType {}; |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
54851
diff
changeset
|
61 |
|
1 | 62 |
class AttachListener: AllStatic { |
63 |
public: |
|
18931
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
15484
diff
changeset
|
64 |
static void vm_start() NOT_SERVICES_RETURN; |
13975
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13195
diff
changeset
|
65 |
static void init() NOT_SERVICES_RETURN; |
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13195
diff
changeset
|
66 |
static void abort() NOT_SERVICES_RETURN; |
1 | 67 |
|
68 |
// invoke to perform clean-up tasks when all clients detach |
|
13975
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13195
diff
changeset
|
69 |
static void detachall() NOT_SERVICES_RETURN; |
1 | 70 |
|
55682
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
54851
diff
changeset
|
71 |
// check unix domain socket file on filesystem |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
54851
diff
changeset
|
72 |
static bool check_socket_file() NOT_SERVICES_RETURN_(false); |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
54851
diff
changeset
|
73 |
|
1 | 74 |
// indicates if the Attach Listener needs to be created at startup |
13975
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13195
diff
changeset
|
75 |
static bool init_at_startup() NOT_SERVICES_RETURN_(false); |
1 | 76 |
|
77 |
// indicates if we have a trigger to start the Attach Listener |
|
13975
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13195
diff
changeset
|
78 |
static bool is_init_trigger() NOT_SERVICES_RETURN_(false); |
1 | 79 |
|
13975
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13195
diff
changeset
|
80 |
#if !INCLUDE_SERVICES |
1 | 81 |
static bool is_attach_supported() { return false; } |
13975
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13195
diff
changeset
|
82 |
#else |
55682
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
54851
diff
changeset
|
83 |
|
1 | 84 |
private: |
55682
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
54851
diff
changeset
|
85 |
static volatile AttachListenerState _state; |
1 | 86 |
|
87 |
public: |
|
55682
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
54851
diff
changeset
|
88 |
static void set_state(AttachListenerState new_state) { |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
54851
diff
changeset
|
89 |
Atomic::store(new_state, &_state); |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
54851
diff
changeset
|
90 |
} |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
54851
diff
changeset
|
91 |
|
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
54851
diff
changeset
|
92 |
static AttachListenerState get_state() { |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
54851
diff
changeset
|
93 |
return Atomic::load(&_state); |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
54851
diff
changeset
|
94 |
} |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
54851
diff
changeset
|
95 |
|
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
54851
diff
changeset
|
96 |
static AttachListenerState transit_state(AttachListenerState new_state, |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
54851
diff
changeset
|
97 |
AttachListenerState cmp_state) { |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
54851
diff
changeset
|
98 |
return Atomic::cmpxchg(new_state, &_state, cmp_state); |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
54851
diff
changeset
|
99 |
} |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
54851
diff
changeset
|
100 |
|
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
54851
diff
changeset
|
101 |
static bool is_initialized() { |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
54851
diff
changeset
|
102 |
return Atomic::load(&_state) == AL_INITIALIZED; |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
54851
diff
changeset
|
103 |
} |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
54851
diff
changeset
|
104 |
|
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
54851
diff
changeset
|
105 |
static void set_initialized() { |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
54851
diff
changeset
|
106 |
Atomic::store(AL_INITIALIZED, &_state); |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
54851
diff
changeset
|
107 |
} |
1 | 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 |
|
128 |
static AttachOperation* dequeue(); |
|
13975
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13195
diff
changeset
|
129 |
#endif // !INCLUDE_SERVICES |
22197
41ea552a447d
6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents:
18931
diff
changeset
|
130 |
|
41ea552a447d
6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents:
18931
diff
changeset
|
131 |
private: |
41ea552a447d
6730115: Fastdebug VM crashes with "ExceptionMark destructor expects no pending exceptions" error
zgu
parents:
18931
diff
changeset
|
132 |
static bool has_init_error(TRAPS); |
1 | 133 |
}; |
134 |
||
13975
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13195
diff
changeset
|
135 |
#if INCLUDE_SERVICES |
13195 | 136 |
class AttachOperation: public CHeapObj<mtInternal> { |
1 | 137 |
public: |
138 |
enum { |
|
139 |
name_length_max = 16, // maximum length of name |
|
140 |
arg_length_max = 1024, // maximum length of argument |
|
54065
f984aca565c1
8219721: jcmd from earlier release will hang attaching to VM with JDK-8215622 applied
dholmes
parents:
53858
diff
changeset
|
141 |
arg_count_max = 3 // maximum number of arguments |
1 | 142 |
}; |
143 |
||
144 |
// name of special operation that can be enqueued when all |
|
145 |
// clients detach |
|
146 |
static char* detachall_operation_name() { return (char*)"detachall"; } |
|
147 |
||
148 |
private: |
|
149 |
char _name[name_length_max+1]; |
|
150 |
char _arg[arg_count_max][arg_length_max+1]; |
|
151 |
||
152 |
public: |
|
153 |
const char* name() const { return _name; } |
|
154 |
||
155 |
// set the operation name |
|
54851 | 156 |
void set_name(const char* name) { |
49406
f654b37c58a1
8199010: attachListener.hpp: Fix potential null termination issue found by coverity scans
clanger
parents:
47216
diff
changeset
|
157 |
assert(strlen(name) <= name_length_max, "exceeds maximum name length"); |
f654b37c58a1
8199010: attachListener.hpp: Fix potential null termination issue found by coverity scans
clanger
parents:
47216
diff
changeset
|
158 |
size_t len = MIN2(strlen(name), (size_t)name_length_max); |
f654b37c58a1
8199010: attachListener.hpp: Fix potential null termination issue found by coverity scans
clanger
parents:
47216
diff
changeset
|
159 |
memcpy(_name, name, len); |
f654b37c58a1
8199010: attachListener.hpp: Fix potential null termination issue found by coverity scans
clanger
parents:
47216
diff
changeset
|
160 |
_name[len] = '\0'; |
1 | 161 |
} |
162 |
||
163 |
// get an argument value |
|
164 |
const char* arg(int i) const { |
|
165 |
assert(i>=0 && i<arg_count_max, "invalid argument index"); |
|
166 |
return _arg[i]; |
|
167 |
} |
|
168 |
||
169 |
// set an argument value |
|
170 |
void set_arg(int i, char* arg) { |
|
171 |
assert(i>=0 && i<arg_count_max, "invalid argument index"); |
|
172 |
if (arg == NULL) { |
|
173 |
_arg[i][0] = '\0'; |
|
174 |
} else { |
|
49406
f654b37c58a1
8199010: attachListener.hpp: Fix potential null termination issue found by coverity scans
clanger
parents:
47216
diff
changeset
|
175 |
assert(strlen(arg) <= arg_length_max, "exceeds maximum argument length"); |
f654b37c58a1
8199010: attachListener.hpp: Fix potential null termination issue found by coverity scans
clanger
parents:
47216
diff
changeset
|
176 |
size_t len = MIN2(strlen(arg), (size_t)arg_length_max); |
f654b37c58a1
8199010: attachListener.hpp: Fix potential null termination issue found by coverity scans
clanger
parents:
47216
diff
changeset
|
177 |
memcpy(_arg[i], arg, len); |
f654b37c58a1
8199010: attachListener.hpp: Fix potential null termination issue found by coverity scans
clanger
parents:
47216
diff
changeset
|
178 |
_arg[i][len] = '\0'; |
1 | 179 |
} |
180 |
} |
|
181 |
||
182 |
// create an operation of a given name |
|
54851 | 183 |
AttachOperation(const char* name) { |
1 | 184 |
set_name(name); |
185 |
for (int i=0; i<arg_count_max; i++) { |
|
186 |
set_arg(i, NULL); |
|
187 |
} |
|
188 |
} |
|
189 |
||
190 |
// complete operation by sending result code and any result data to the client |
|
191 |
virtual void complete(jint result, bufferedStream* result_stream) = 0; |
|
192 |
}; |
|
13975
2f7431485cfa
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
13195
diff
changeset
|
193 |
#endif // INCLUDE_SERVICES |
7397 | 194 |
|
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
49406
diff
changeset
|
195 |
#endif // SHARE_SERVICES_ATTACHLISTENER_HPP |