author | ysuenaga |
Tue, 16 Jul 2019 07:29:12 +0900 | |
changeset 55682 | 70fab3a8ff02 |
parent 51584 | d395677d99f3 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
55682
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
51584
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:
5410
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5410
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:
5410
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
49593
4dd58ecc9912
8200105: Remove cyclic dependency between oop.inline.hpp and collectedHeap.inline.hpp
stefank
parents:
49449
diff
changeset
|
26 |
#include "logging/log.hpp" |
49449
ef5d5d343e2a
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents:
47216
diff
changeset
|
27 |
#include "runtime/interfaceSupport.inline.hpp" |
25468
5331df506290
8048241: Introduce umbrella header os.inline.hpp and clean up includes
goetz
parents:
23870
diff
changeset
|
28 |
#include "runtime/os.inline.hpp" |
7397 | 29 |
#include "services/attachListener.hpp" |
30 |
#include "services/dtraceAttacher.hpp" |
|
46589 | 31 |
#include "utilities/vmError.hpp" |
1 | 32 |
|
33 |
#include <door.h> |
|
23870
2c9e85bccffb
8038296: sun/tools/jinfo/Basic.sh: java.io.IOException: Command failed in target VM
sla
parents:
18931
diff
changeset
|
34 |
#include <limits.h> |
1 | 35 |
#include <string.h> |
36 |
#include <signal.h> |
|
37 |
#include <sys/types.h> |
|
38 |
#include <sys/socket.h> |
|
39 |
#include <sys/stat.h> |
|
40 |
||
41 |
// stropts.h uses STR in stream ioctl defines |
|
42 |
#undef STR |
|
43 |
#include <stropts.h> |
|
44 |
#undef STR |
|
45 |
#define STR(a) #a |
|
46 |
||
47 |
// The attach mechanism on Solaris is implemented using the Doors IPC |
|
48 |
// mechanism. The first tool to attempt to attach causes the attach |
|
49 |
// listener thread to startup. This thread creats a door that is |
|
50 |
// associated with a function that enqueues an operation to the attach |
|
51 |
// listener. The door is attached to a file in the file system so that |
|
52 |
// client (tools) can locate it. To enqueue an operation to the VM the |
|
53 |
// client calls through the door which invokes the enqueue function in |
|
54 |
// this process. The credentials of the client are checked and if the |
|
55 |
// effective uid matches this process then the operation is enqueued. |
|
56 |
// When an operation completes the attach listener is required to send the |
|
57 |
// operation result and any result data to the client. In this implementation |
|
58 |
// the result is returned via a UNIX domain socket. A pair of connected |
|
59 |
// sockets (socketpair) is created in the enqueue function and the file |
|
60 |
// descriptor for one of the sockets is returned to the client as the |
|
61 |
// return from the door call. The other end is retained in this process. |
|
62 |
// When the operation completes the result is sent to the client and |
|
63 |
// the socket is closed. |
|
64 |
||
65 |
// forward reference |
|
66 |
class SolarisAttachOperation; |
|
67 |
||
68 |
class SolarisAttachListener: AllStatic { |
|
69 |
private: |
|
70 |
||
71 |
// the path to which we attach the door file descriptor |
|
72 |
static char _door_path[PATH_MAX+1]; |
|
73 |
static volatile bool _has_door_path; |
|
74 |
||
75 |
// door descriptor returned by door_create |
|
76 |
static int _door_descriptor; |
|
77 |
||
55682
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
51584
diff
changeset
|
78 |
static bool _atexit_registered; |
1 | 79 |
|
80 |
// mutex to protect operation list |
|
81 |
static mutex_t _mutex; |
|
82 |
||
83 |
// semaphore to wakeup listener thread |
|
84 |
static sema_t _wakeup; |
|
85 |
||
86 |
static mutex_t* mutex() { return &_mutex; } |
|
87 |
static sema_t* wakeup() { return &_wakeup; } |
|
88 |
||
89 |
// enqueued operation list |
|
90 |
static SolarisAttachOperation* _head; |
|
91 |
static SolarisAttachOperation* _tail; |
|
92 |
||
93 |
static SolarisAttachOperation* head() { return _head; } |
|
94 |
static void set_head(SolarisAttachOperation* head) { _head = head; } |
|
95 |
||
96 |
static SolarisAttachOperation* tail() { return _tail; } |
|
97 |
static void set_tail(SolarisAttachOperation* tail) { _tail = tail; } |
|
98 |
||
99 |
// create the door |
|
100 |
static int create_door(); |
|
101 |
||
102 |
public: |
|
103 |
enum { |
|
104 |
ATTACH_PROTOCOL_VER = 1 // protocol version |
|
105 |
}; |
|
106 |
enum { |
|
107 |
ATTACH_ERROR_BADREQUEST = 100, // error code returned by |
|
108 |
ATTACH_ERROR_BADVERSION = 101, // the door call |
|
109 |
ATTACH_ERROR_RESOURCE = 102, |
|
110 |
ATTACH_ERROR_INTERNAL = 103, |
|
111 |
ATTACH_ERROR_DENIED = 104 |
|
112 |
}; |
|
113 |
||
55682
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
51584
diff
changeset
|
114 |
static void set_door_path(char* path) { |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
51584
diff
changeset
|
115 |
if (path == NULL) { |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
51584
diff
changeset
|
116 |
_door_path[0] = '\0'; |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
51584
diff
changeset
|
117 |
_has_door_path = false; |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
51584
diff
changeset
|
118 |
} else { |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
51584
diff
changeset
|
119 |
strncpy(_door_path, path, PATH_MAX); |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
51584
diff
changeset
|
120 |
_door_path[PATH_MAX] = '\0'; // ensure it's nul terminated |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
51584
diff
changeset
|
121 |
_has_door_path = true; |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
51584
diff
changeset
|
122 |
} |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
51584
diff
changeset
|
123 |
} |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
51584
diff
changeset
|
124 |
|
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
51584
diff
changeset
|
125 |
static void set_door_descriptor(int dd) { _door_descriptor = dd; } |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
51584
diff
changeset
|
126 |
|
1 | 127 |
// initialize the listener |
128 |
static int init(); |
|
129 |
||
130 |
static bool has_door_path() { return _has_door_path; } |
|
131 |
static char* door_path() { return _door_path; } |
|
132 |
static int door_descriptor() { return _door_descriptor; } |
|
133 |
||
134 |
// enqueue an operation |
|
135 |
static void enqueue(SolarisAttachOperation* op); |
|
136 |
||
137 |
// dequeue an operation |
|
138 |
static SolarisAttachOperation* dequeue(); |
|
139 |
}; |
|
140 |
||
141 |
||
142 |
// SolarisAttachOperation is an AttachOperation that additionally encapsulates |
|
143 |
// a socket connection to the requesting client/tool. SolarisAttachOperation |
|
144 |
// can additionally be held in a linked list. |
|
145 |
||
146 |
class SolarisAttachOperation: public AttachOperation { |
|
147 |
private: |
|
148 |
friend class SolarisAttachListener; |
|
149 |
||
150 |
// connection to client |
|
151 |
int _socket; |
|
152 |
||
153 |
// linked list support |
|
154 |
SolarisAttachOperation* _next; |
|
155 |
||
156 |
SolarisAttachOperation* next() { return _next; } |
|
157 |
void set_next(SolarisAttachOperation* next) { _next = next; } |
|
158 |
||
159 |
public: |
|
160 |
void complete(jint res, bufferedStream* st); |
|
161 |
||
162 |
int socket() const { return _socket; } |
|
163 |
void set_socket(int s) { _socket = s; } |
|
164 |
||
165 |
SolarisAttachOperation(char* name) : AttachOperation(name) { |
|
166 |
set_socket(-1); |
|
167 |
set_next(NULL); |
|
168 |
} |
|
169 |
}; |
|
170 |
||
171 |
// statics |
|
172 |
char SolarisAttachListener::_door_path[PATH_MAX+1]; |
|
173 |
volatile bool SolarisAttachListener::_has_door_path; |
|
174 |
int SolarisAttachListener::_door_descriptor = -1; |
|
55682
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
51584
diff
changeset
|
175 |
bool SolarisAttachListener::_atexit_registered = false; |
1 | 176 |
mutex_t SolarisAttachListener::_mutex; |
177 |
sema_t SolarisAttachListener::_wakeup; |
|
178 |
SolarisAttachOperation* SolarisAttachListener::_head = NULL; |
|
179 |
SolarisAttachOperation* SolarisAttachListener::_tail = NULL; |
|
180 |
||
181 |
// Supporting class to help split a buffer into individual components |
|
182 |
class ArgumentIterator : public StackObj { |
|
183 |
private: |
|
184 |
char* _pos; |
|
185 |
char* _end; |
|
186 |
public: |
|
187 |
ArgumentIterator(char* arg_buffer, size_t arg_size) { |
|
188 |
_pos = arg_buffer; |
|
189 |
_end = _pos + arg_size - 1; |
|
190 |
} |
|
191 |
char* next() { |
|
192 |
if (*_pos == '\0') { |
|
49742
1196aa0be8be
8201247: Various cleanups in the attach framework
clanger
parents:
49593
diff
changeset
|
193 |
// advance the iterator if possible (null arguments) |
1196aa0be8be
8201247: Various cleanups in the attach framework
clanger
parents:
49593
diff
changeset
|
194 |
if (_pos < _end) { |
1196aa0be8be
8201247: Various cleanups in the attach framework
clanger
parents:
49593
diff
changeset
|
195 |
_pos += 1; |
1196aa0be8be
8201247: Various cleanups in the attach framework
clanger
parents:
49593
diff
changeset
|
196 |
} |
1 | 197 |
return NULL; |
198 |
} |
|
199 |
char* res = _pos; |
|
200 |
char* next_pos = strchr(_pos, '\0'); |
|
201 |
if (next_pos < _end) { |
|
202 |
next_pos++; |
|
203 |
} |
|
204 |
_pos = next_pos; |
|
205 |
return res; |
|
206 |
} |
|
207 |
}; |
|
208 |
||
209 |
// Calls from the door function to check that the client credentials |
|
210 |
// match this process. Returns 0 if credentials okay, otherwise -1. |
|
211 |
static int check_credentials() { |
|
25891
103846690fc2
8049046: Deprecated Function in hotspot/src/os/solaris/vm/attachListener_solaris.cpp
dsamersoff
parents:
25468
diff
changeset
|
212 |
ucred_t *cred_info = NULL; |
103846690fc2
8049046: Deprecated Function in hotspot/src/os/solaris/vm/attachListener_solaris.cpp
dsamersoff
parents:
25468
diff
changeset
|
213 |
int ret = -1; // deny by default |
1 | 214 |
|
215 |
// get client credentials |
|
25891
103846690fc2
8049046: Deprecated Function in hotspot/src/os/solaris/vm/attachListener_solaris.cpp
dsamersoff
parents:
25468
diff
changeset
|
216 |
if (door_ucred(&cred_info) == -1) { |
103846690fc2
8049046: Deprecated Function in hotspot/src/os/solaris/vm/attachListener_solaris.cpp
dsamersoff
parents:
25468
diff
changeset
|
217 |
return -1; // unable to get them, deny |
1 | 218 |
} |
219 |
||
25891
103846690fc2
8049046: Deprecated Function in hotspot/src/os/solaris/vm/attachListener_solaris.cpp
dsamersoff
parents:
25468
diff
changeset
|
220 |
// get euid/egid from ucred_free |
103846690fc2
8049046: Deprecated Function in hotspot/src/os/solaris/vm/attachListener_solaris.cpp
dsamersoff
parents:
25468
diff
changeset
|
221 |
uid_t ucred_euid = ucred_geteuid(cred_info); |
103846690fc2
8049046: Deprecated Function in hotspot/src/os/solaris/vm/attachListener_solaris.cpp
dsamersoff
parents:
25468
diff
changeset
|
222 |
gid_t ucred_egid = ucred_getegid(cred_info); |
103846690fc2
8049046: Deprecated Function in hotspot/src/os/solaris/vm/attachListener_solaris.cpp
dsamersoff
parents:
25468
diff
changeset
|
223 |
|
103846690fc2
8049046: Deprecated Function in hotspot/src/os/solaris/vm/attachListener_solaris.cpp
dsamersoff
parents:
25468
diff
changeset
|
224 |
// check that the effective uid/gid matches |
50333
7cea35f78b50
8197387: jcmd started by "root" must be allowed to access all VM processes
dtitov
parents:
49742
diff
changeset
|
225 |
if (os::Posix::matches_effective_uid_and_gid_or_root(ucred_euid, ucred_egid)) { |
25891
103846690fc2
8049046: Deprecated Function in hotspot/src/os/solaris/vm/attachListener_solaris.cpp
dsamersoff
parents:
25468
diff
changeset
|
226 |
ret = 0; // allow |
1 | 227 |
} |
25891
103846690fc2
8049046: Deprecated Function in hotspot/src/os/solaris/vm/attachListener_solaris.cpp
dsamersoff
parents:
25468
diff
changeset
|
228 |
|
103846690fc2
8049046: Deprecated Function in hotspot/src/os/solaris/vm/attachListener_solaris.cpp
dsamersoff
parents:
25468
diff
changeset
|
229 |
ucred_free(cred_info); |
103846690fc2
8049046: Deprecated Function in hotspot/src/os/solaris/vm/attachListener_solaris.cpp
dsamersoff
parents:
25468
diff
changeset
|
230 |
return ret; |
1 | 231 |
} |
232 |
||
233 |
||
234 |
// Parses the argument buffer to create an AttachOperation that we should |
|
235 |
// enqueue to the attach listener. |
|
236 |
// The buffer is expected to be formatted as follows: |
|
237 |
// <ver>0<cmd>0<arg>0<arg>0<arg>0 |
|
238 |
// where <ver> is the version number (must be "1"), <cmd> is the command |
|
239 |
// name ("load, "datadump", ...) and <arg> is an argument. |
|
240 |
// |
|
241 |
static SolarisAttachOperation* create_operation(char* argp, size_t arg_size, int* err) { |
|
242 |
// assume bad request until parsed |
|
243 |
*err = SolarisAttachListener::ATTACH_ERROR_BADREQUEST; |
|
244 |
||
245 |
if (arg_size < 2 || argp[arg_size-1] != '\0') { |
|
246 |
return NULL; // no ver or not null terminated |
|
247 |
} |
|
248 |
||
249 |
// Use supporting class to iterate over the buffer |
|
250 |
ArgumentIterator args(argp, arg_size); |
|
251 |
||
252 |
// First check the protocol version |
|
253 |
char* ver = args.next(); |
|
254 |
if (ver == NULL) { |
|
255 |
return NULL; |
|
256 |
} |
|
257 |
if (atoi(ver) != SolarisAttachListener::ATTACH_PROTOCOL_VER) { |
|
258 |
*err = SolarisAttachListener::ATTACH_ERROR_BADVERSION; |
|
259 |
return NULL; |
|
260 |
} |
|
261 |
||
262 |
// Get command name and create the operation |
|
263 |
char* name = args.next(); |
|
264 |
if (name == NULL || strlen(name) > AttachOperation::name_length_max) { |
|
265 |
return NULL; |
|
266 |
} |
|
267 |
SolarisAttachOperation* op = new SolarisAttachOperation(name); |
|
268 |
||
269 |
// Iterate over the arguments |
|
270 |
for (int i=0; i<AttachOperation::arg_count_max; i++) { |
|
271 |
char* arg = args.next(); |
|
272 |
if (arg == NULL) { |
|
273 |
op->set_arg(i, NULL); |
|
274 |
} else { |
|
275 |
if (strlen(arg) > AttachOperation::arg_length_max) { |
|
276 |
delete op; |
|
277 |
return NULL; |
|
278 |
} |
|
279 |
op->set_arg(i, arg); |
|
280 |
} |
|
281 |
} |
|
282 |
||
283 |
// return operation |
|
284 |
*err = 0; |
|
285 |
return op; |
|
286 |
} |
|
287 |
||
288 |
// create special operation to indicate all clients have detached |
|
289 |
static SolarisAttachOperation* create_detachall_operation() { |
|
290 |
return new SolarisAttachOperation(AttachOperation::detachall_operation_name()); |
|
291 |
} |
|
292 |
||
293 |
// This is door function which the client executes via a door_call. |
|
294 |
extern "C" { |
|
295 |
static void enqueue_proc(void* cookie, char* argp, size_t arg_size, |
|
296 |
door_desc_t* dt, uint_t n_desc) |
|
297 |
{ |
|
298 |
int return_fd = -1; |
|
299 |
SolarisAttachOperation* op = NULL; |
|
300 |
||
51584
d395677d99f3
8199811: com/sun/jdi/ProcessAttachTest.java fails intermittently: Remote thread failed for unknown reason
cjplummer
parents:
50333
diff
changeset
|
301 |
// wait up to 10 seconds for listener to be up and running |
1 | 302 |
jint res = 0; |
51584
d395677d99f3
8199811: com/sun/jdi/ProcessAttachTest.java fails intermittently: Remote thread failed for unknown reason
cjplummer
parents:
50333
diff
changeset
|
303 |
int sleep_count = 0; |
d395677d99f3
8199811: com/sun/jdi/ProcessAttachTest.java fails intermittently: Remote thread failed for unknown reason
cjplummer
parents:
50333
diff
changeset
|
304 |
while (!AttachListener::is_initialized()) { |
d395677d99f3
8199811: com/sun/jdi/ProcessAttachTest.java fails intermittently: Remote thread failed for unknown reason
cjplummer
parents:
50333
diff
changeset
|
305 |
sleep(1); // 1 second |
d395677d99f3
8199811: com/sun/jdi/ProcessAttachTest.java fails intermittently: Remote thread failed for unknown reason
cjplummer
parents:
50333
diff
changeset
|
306 |
sleep_count++; |
d395677d99f3
8199811: com/sun/jdi/ProcessAttachTest.java fails intermittently: Remote thread failed for unknown reason
cjplummer
parents:
50333
diff
changeset
|
307 |
if (sleep_count > 10) { // try for 10 seconds |
d395677d99f3
8199811: com/sun/jdi/ProcessAttachTest.java fails intermittently: Remote thread failed for unknown reason
cjplummer
parents:
50333
diff
changeset
|
308 |
debug_only(warning("door_call when not enabled")); |
d395677d99f3
8199811: com/sun/jdi/ProcessAttachTest.java fails intermittently: Remote thread failed for unknown reason
cjplummer
parents:
50333
diff
changeset
|
309 |
res = (jint)SolarisAttachListener::ATTACH_ERROR_INTERNAL; |
d395677d99f3
8199811: com/sun/jdi/ProcessAttachTest.java fails intermittently: Remote thread failed for unknown reason
cjplummer
parents:
50333
diff
changeset
|
310 |
break; |
d395677d99f3
8199811: com/sun/jdi/ProcessAttachTest.java fails intermittently: Remote thread failed for unknown reason
cjplummer
parents:
50333
diff
changeset
|
311 |
} |
1 | 312 |
} |
313 |
||
314 |
// check client credentials |
|
315 |
if (res == 0) { |
|
316 |
if (check_credentials() != 0) { |
|
317 |
res = (jint)SolarisAttachListener::ATTACH_ERROR_DENIED; |
|
318 |
} |
|
319 |
} |
|
320 |
||
321 |
// if we are stopped at ShowMessageBoxOnError then maybe we can |
|
322 |
// load a diagnostic library |
|
46589 | 323 |
if (res == 0 && VMError::is_error_reported()) { |
1 | 324 |
if (ShowMessageBoxOnError) { |
325 |
// TBD - support loading of diagnostic library here |
|
326 |
} |
|
327 |
||
328 |
// can't enqueue operation after fatal error |
|
329 |
res = (jint)SolarisAttachListener::ATTACH_ERROR_RESOURCE; |
|
330 |
} |
|
331 |
||
332 |
// create the operation |
|
333 |
if (res == 0) { |
|
334 |
int err; |
|
335 |
op = create_operation(argp, arg_size, &err); |
|
336 |
res = (op == NULL) ? (jint)err : 0; |
|
337 |
} |
|
338 |
||
339 |
// create a pair of connected sockets. Store the file descriptor |
|
340 |
// for one end in the operation and enqueue the operation. The |
|
341 |
// file descriptor for the other end wil be returned to the client. |
|
342 |
if (res == 0) { |
|
343 |
int s[2]; |
|
344 |
if (socketpair(PF_UNIX, SOCK_STREAM, 0, s) < 0) { |
|
345 |
delete op; |
|
346 |
res = (jint)SolarisAttachListener::ATTACH_ERROR_RESOURCE; |
|
347 |
} else { |
|
348 |
op->set_socket(s[0]); |
|
349 |
return_fd = s[1]; |
|
350 |
SolarisAttachListener::enqueue(op); |
|
351 |
} |
|
352 |
} |
|
353 |
||
354 |
// Return 0 (success) + file descriptor, or non-0 (error) |
|
355 |
if (res == 0) { |
|
356 |
door_desc_t desc; |
|
12505 | 357 |
// DOOR_RELEASE flag makes sure fd is closed after passing it to |
358 |
// the client. See door_return(3DOOR) man page. |
|
359 |
desc.d_attributes = DOOR_DESCRIPTOR | DOOR_RELEASE; |
|
1 | 360 |
desc.d_data.d_desc.d_descriptor = return_fd; |
361 |
door_return((char*)&res, sizeof(res), &desc, 1); |
|
362 |
} else { |
|
363 |
door_return((char*)&res, sizeof(res), NULL, 0); |
|
364 |
} |
|
365 |
} |
|
366 |
} |
|
367 |
||
368 |
// atexit hook to detach the door and remove the file |
|
369 |
extern "C" { |
|
370 |
static void listener_cleanup() { |
|
55682
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
51584
diff
changeset
|
371 |
int dd = SolarisAttachListener::door_descriptor(); |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
51584
diff
changeset
|
372 |
if (dd >= 0) { |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
51584
diff
changeset
|
373 |
SolarisAttachListener::set_door_descriptor(-1); |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
51584
diff
changeset
|
374 |
::close(dd); |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
51584
diff
changeset
|
375 |
} |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
51584
diff
changeset
|
376 |
if (SolarisAttachListener::has_door_path()) { |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
51584
diff
changeset
|
377 |
char* path = SolarisAttachListener::door_path(); |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
51584
diff
changeset
|
378 |
::fdetach(path); |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
51584
diff
changeset
|
379 |
::unlink(path); |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
51584
diff
changeset
|
380 |
SolarisAttachListener::set_door_path(NULL); |
1 | 381 |
} |
382 |
} |
|
383 |
} |
|
384 |
||
385 |
// Create the door |
|
386 |
int SolarisAttachListener::create_door() { |
|
387 |
char door_path[PATH_MAX+1]; |
|
6170
82aea418ab2d
6649594: Intermittent IOExceptions during dynamic attach on linux and solaris
alanb
parents:
5547
diff
changeset
|
388 |
char initial_path[PATH_MAX+1]; |
1 | 389 |
int fd, res; |
390 |
||
391 |
// register exit function |
|
55682
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
51584
diff
changeset
|
392 |
if (!_atexit_registered) { |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
51584
diff
changeset
|
393 |
_atexit_registered = true; |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
51584
diff
changeset
|
394 |
::atexit(listener_cleanup); |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
51584
diff
changeset
|
395 |
} |
1 | 396 |
|
397 |
// create the door descriptor |
|
398 |
int dd = ::door_create(enqueue_proc, NULL, 0); |
|
399 |
if (dd < 0) { |
|
400 |
return -1; |
|
401 |
} |
|
402 |
||
6170
82aea418ab2d
6649594: Intermittent IOExceptions during dynamic attach on linux and solaris
alanb
parents:
5547
diff
changeset
|
403 |
// create initial file to attach door descriptor |
5237
aab592fd4f44
6938627: Make temporary directory use property java.io.tmpdir when specified
coleenp
parents:
5089
diff
changeset
|
404 |
snprintf(door_path, sizeof(door_path), "%s/.java_pid%d", |
aab592fd4f44
6938627: Make temporary directory use property java.io.tmpdir when specified
coleenp
parents:
5089
diff
changeset
|
405 |
os::get_temp_directory(), os::current_process_id()); |
6170
82aea418ab2d
6649594: Intermittent IOExceptions during dynamic attach on linux and solaris
alanb
parents:
5547
diff
changeset
|
406 |
snprintf(initial_path, sizeof(initial_path), "%s.tmp", door_path); |
82aea418ab2d
6649594: Intermittent IOExceptions during dynamic attach on linux and solaris
alanb
parents:
5547
diff
changeset
|
407 |
RESTARTABLE(::creat(initial_path, S_IRUSR | S_IWUSR), fd); |
1 | 408 |
if (fd == -1) { |
40625
6b45fb9188f9
8157236: attach on ARMv7 fails with com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file
dsamersoff
parents:
37113
diff
changeset
|
409 |
log_debug(attach)("attempt to create door file %s failed (%d)", initial_path, errno); |
6170
82aea418ab2d
6649594: Intermittent IOExceptions during dynamic attach on linux and solaris
alanb
parents:
5547
diff
changeset
|
410 |
::door_revoke(dd); |
1 | 411 |
return -1; |
412 |
} |
|
413 |
assert(fd >= 0, "bad file descriptor"); |
|
18078
10417cf9967d
7178026: os::close can restart ::close but that is not a restartable syscall
rdurbin
parents:
13963
diff
changeset
|
414 |
::close(fd); |
1 | 415 |
|
416 |
// attach the door descriptor to the file |
|
6170
82aea418ab2d
6649594: Intermittent IOExceptions during dynamic attach on linux and solaris
alanb
parents:
5547
diff
changeset
|
417 |
if ((res = ::fattach(dd, initial_path)) == -1) { |
1 | 418 |
// if busy then detach and try again |
419 |
if (errno == EBUSY) { |
|
6170
82aea418ab2d
6649594: Intermittent IOExceptions during dynamic attach on linux and solaris
alanb
parents:
5547
diff
changeset
|
420 |
::fdetach(initial_path); |
82aea418ab2d
6649594: Intermittent IOExceptions during dynamic attach on linux and solaris
alanb
parents:
5547
diff
changeset
|
421 |
res = ::fattach(dd, initial_path); |
1 | 422 |
} |
423 |
if (res == -1) { |
|
40625
6b45fb9188f9
8157236: attach on ARMv7 fails with com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file
dsamersoff
parents:
37113
diff
changeset
|
424 |
log_debug(attach)("unable to create door - fattach failed (%d)", errno); |
1 | 425 |
::door_revoke(dd); |
426 |
dd = -1; |
|
427 |
} |
|
428 |
} |
|
6170
82aea418ab2d
6649594: Intermittent IOExceptions during dynamic attach on linux and solaris
alanb
parents:
5547
diff
changeset
|
429 |
|
82aea418ab2d
6649594: Intermittent IOExceptions during dynamic attach on linux and solaris
alanb
parents:
5547
diff
changeset
|
430 |
// rename file so that clients can attach |
82aea418ab2d
6649594: Intermittent IOExceptions during dynamic attach on linux and solaris
alanb
parents:
5547
diff
changeset
|
431 |
if (dd >= 0) { |
82aea418ab2d
6649594: Intermittent IOExceptions during dynamic attach on linux and solaris
alanb
parents:
5547
diff
changeset
|
432 |
if (::rename(initial_path, door_path) == -1) { |
18078
10417cf9967d
7178026: os::close can restart ::close but that is not a restartable syscall
rdurbin
parents:
13963
diff
changeset
|
433 |
::close(dd); |
6170
82aea418ab2d
6649594: Intermittent IOExceptions during dynamic attach on linux and solaris
alanb
parents:
5547
diff
changeset
|
434 |
::fdetach(initial_path); |
40625
6b45fb9188f9
8157236: attach on ARMv7 fails with com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file
dsamersoff
parents:
37113
diff
changeset
|
435 |
log_debug(attach)("unable to create door - rename %s to %s failed (%d)", errno); |
6170
82aea418ab2d
6649594: Intermittent IOExceptions during dynamic attach on linux and solaris
alanb
parents:
5547
diff
changeset
|
436 |
dd = -1; |
82aea418ab2d
6649594: Intermittent IOExceptions during dynamic attach on linux and solaris
alanb
parents:
5547
diff
changeset
|
437 |
} |
82aea418ab2d
6649594: Intermittent IOExceptions during dynamic attach on linux and solaris
alanb
parents:
5547
diff
changeset
|
438 |
} |
1 | 439 |
if (dd >= 0) { |
440 |
set_door_descriptor(dd); |
|
6170
82aea418ab2d
6649594: Intermittent IOExceptions during dynamic attach on linux and solaris
alanb
parents:
5547
diff
changeset
|
441 |
set_door_path(door_path); |
40625
6b45fb9188f9
8157236: attach on ARMv7 fails with com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file
dsamersoff
parents:
37113
diff
changeset
|
442 |
log_trace(attach)("door file %s created succesfully", door_path); |
1 | 443 |
} else { |
6170
82aea418ab2d
6649594: Intermittent IOExceptions during dynamic attach on linux and solaris
alanb
parents:
5547
diff
changeset
|
444 |
// unable to create door, attach it to file, or rename file into place |
82aea418ab2d
6649594: Intermittent IOExceptions during dynamic attach on linux and solaris
alanb
parents:
5547
diff
changeset
|
445 |
::unlink(initial_path); |
1 | 446 |
return -1; |
447 |
} |
|
448 |
||
449 |
return 0; |
|
450 |
} |
|
451 |
||
452 |
// Initialization - create the door, locks, and other initialization |
|
453 |
int SolarisAttachListener::init() { |
|
454 |
if (create_door()) { |
|
455 |
return -1; |
|
456 |
} |
|
457 |
||
458 |
int status = os::Solaris::mutex_init(&_mutex); |
|
459 |
assert_status(status==0, status, "mutex_init"); |
|
460 |
||
461 |
status = ::sema_init(&_wakeup, 0, NULL, NULL); |
|
462 |
assert_status(status==0, status, "sema_init"); |
|
463 |
||
464 |
set_head(NULL); |
|
465 |
set_tail(NULL); |
|
466 |
||
467 |
return 0; |
|
468 |
} |
|
469 |
||
470 |
// Dequeue an operation |
|
471 |
SolarisAttachOperation* SolarisAttachListener::dequeue() { |
|
472 |
for (;;) { |
|
473 |
int res; |
|
474 |
||
475 |
// wait for somebody to enqueue something |
|
476 |
while ((res = ::sema_wait(wakeup())) == EINTR) |
|
477 |
; |
|
478 |
if (res) { |
|
37113 | 479 |
warning("sema_wait failed: %s", os::strerror(res)); |
1 | 480 |
return NULL; |
481 |
} |
|
482 |
||
483 |
// lock the list |
|
484 |
res = os::Solaris::mutex_lock(mutex()); |
|
485 |
assert(res == 0, "mutex_lock failed"); |
|
486 |
||
487 |
// remove the head of the list |
|
488 |
SolarisAttachOperation* op = head(); |
|
489 |
if (op != NULL) { |
|
490 |
set_head(op->next()); |
|
491 |
if (head() == NULL) { |
|
492 |
set_tail(NULL); |
|
493 |
} |
|
494 |
} |
|
495 |
||
496 |
// unlock |
|
497 |
os::Solaris::mutex_unlock(mutex()); |
|
498 |
||
499 |
// if we got an operation when return it. |
|
500 |
if (op != NULL) { |
|
501 |
return op; |
|
502 |
} |
|
503 |
} |
|
504 |
} |
|
505 |
||
506 |
// Enqueue an operation |
|
507 |
void SolarisAttachListener::enqueue(SolarisAttachOperation* op) { |
|
508 |
// lock list |
|
509 |
int res = os::Solaris::mutex_lock(mutex()); |
|
510 |
assert(res == 0, "mutex_lock failed"); |
|
511 |
||
512 |
// enqueue at tail |
|
513 |
op->set_next(NULL); |
|
514 |
if (head() == NULL) { |
|
515 |
set_head(op); |
|
516 |
} else { |
|
517 |
tail()->set_next(op); |
|
518 |
} |
|
519 |
set_tail(op); |
|
520 |
||
521 |
// wakeup the attach listener |
|
522 |
RESTARTABLE(::sema_post(wakeup()), res); |
|
523 |
assert(res == 0, "sema_post failed"); |
|
524 |
||
525 |
// unlock |
|
526 |
os::Solaris::mutex_unlock(mutex()); |
|
527 |
} |
|
528 |
||
529 |
||
530 |
// support function - writes the (entire) buffer to a socket |
|
531 |
static int write_fully(int s, char* buf, int len) { |
|
532 |
do { |
|
533 |
int n = ::write(s, buf, len); |
|
534 |
if (n == -1) { |
|
535 |
if (errno != EINTR) return -1; |
|
536 |
} else { |
|
537 |
buf += n; |
|
538 |
len -= n; |
|
539 |
} |
|
540 |
} |
|
541 |
while (len > 0); |
|
542 |
return 0; |
|
543 |
} |
|
544 |
||
545 |
// Complete an operation by sending the operation result and any result |
|
546 |
// output to the client. At this time the socket is in blocking mode so |
|
547 |
// potentially we can block if there is a lot of data and the client is |
|
548 |
// non-responsive. For most operations this is a non-issue because the |
|
549 |
// default send buffer is sufficient to buffer everything. In the future |
|
550 |
// if there are operations that involves a very big reply then it the |
|
551 |
// socket could be made non-blocking and a timeout could be used. |
|
552 |
||
553 |
void SolarisAttachOperation::complete(jint res, bufferedStream* st) { |
|
554 |
if (this->socket() >= 0) { |
|
555 |
JavaThread* thread = JavaThread::current(); |
|
556 |
ThreadBlockInVM tbivm(thread); |
|
557 |
||
558 |
thread->set_suspend_equivalent(); |
|
559 |
// cleared by handle_special_suspend_equivalent_condition() or |
|
560 |
// java_suspend_self() via check_and_wait_while_suspended() |
|
561 |
||
562 |
// write operation result |
|
563 |
char msg[32]; |
|
564 |
sprintf(msg, "%d\n", res); |
|
565 |
int rc = write_fully(this->socket(), msg, strlen(msg)); |
|
566 |
||
567 |
// write any result data |
|
568 |
if (rc == 0) { |
|
569 |
write_fully(this->socket(), (char*) st->base(), st->size()); |
|
570 |
::shutdown(this->socket(), 2); |
|
571 |
} |
|
572 |
||
573 |
// close socket and we're done |
|
18078
10417cf9967d
7178026: os::close can restart ::close but that is not a restartable syscall
rdurbin
parents:
13963
diff
changeset
|
574 |
::close(this->socket()); |
1 | 575 |
|
576 |
// were we externally suspended while we were waiting? |
|
577 |
thread->check_and_wait_while_suspended(); |
|
578 |
} |
|
579 |
delete this; |
|
580 |
} |
|
581 |
||
582 |
||
583 |
// AttachListener functions |
|
584 |
||
585 |
AttachOperation* AttachListener::dequeue() { |
|
586 |
JavaThread* thread = JavaThread::current(); |
|
587 |
ThreadBlockInVM tbivm(thread); |
|
588 |
||
589 |
thread->set_suspend_equivalent(); |
|
590 |
// cleared by handle_special_suspend_equivalent_condition() or |
|
591 |
// java_suspend_self() via check_and_wait_while_suspended() |
|
592 |
||
593 |
AttachOperation* op = SolarisAttachListener::dequeue(); |
|
594 |
||
595 |
// were we externally suspended while we were waiting? |
|
596 |
thread->check_and_wait_while_suspended(); |
|
597 |
||
598 |
return op; |
|
599 |
} |
|
600 |
||
18931
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
18078
diff
changeset
|
601 |
|
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
18078
diff
changeset
|
602 |
// Performs initialization at vm startup |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
18078
diff
changeset
|
603 |
// For Solaris we remove any stale .java_pid file which could cause |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
18078
diff
changeset
|
604 |
// an attaching process to think we are ready to receive a door_call |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
18078
diff
changeset
|
605 |
// before we are properly initialized |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
18078
diff
changeset
|
606 |
|
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
18078
diff
changeset
|
607 |
void AttachListener::vm_start() { |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
18078
diff
changeset
|
608 |
char fn[PATH_MAX+1]; |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
18078
diff
changeset
|
609 |
struct stat64 st; |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
18078
diff
changeset
|
610 |
int ret; |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
18078
diff
changeset
|
611 |
|
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
18078
diff
changeset
|
612 |
int n = snprintf(fn, sizeof(fn), "%s/.java_pid%d", |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
18078
diff
changeset
|
613 |
os::get_temp_directory(), os::current_process_id()); |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
18078
diff
changeset
|
614 |
assert(n < sizeof(fn), "java_pid file name buffer overflow"); |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
18078
diff
changeset
|
615 |
|
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
18078
diff
changeset
|
616 |
RESTARTABLE(::stat64(fn, &st), ret); |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
18078
diff
changeset
|
617 |
if (ret == 0) { |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
18078
diff
changeset
|
618 |
ret = ::unlink(fn); |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
18078
diff
changeset
|
619 |
if (ret == -1) { |
40625
6b45fb9188f9
8157236: attach on ARMv7 fails with com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file
dsamersoff
parents:
37113
diff
changeset
|
620 |
log_debug(attach)("Failed to remove stale attach pid file at %s", fn); |
18931
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
18078
diff
changeset
|
621 |
} |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
18078
diff
changeset
|
622 |
} |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
18078
diff
changeset
|
623 |
} |
5de3638104b4
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
18078
diff
changeset
|
624 |
|
1 | 625 |
int AttachListener::pd_init() { |
626 |
JavaThread* thread = JavaThread::current(); |
|
627 |
ThreadBlockInVM tbivm(thread); |
|
628 |
||
629 |
thread->set_suspend_equivalent(); |
|
630 |
// cleared by handle_special_suspend_equivalent_condition() or |
|
631 |
// java_suspend_self() |
|
632 |
||
633 |
int ret_code = SolarisAttachListener::init(); |
|
634 |
||
635 |
// were we externally suspended while we were waiting? |
|
636 |
thread->check_and_wait_while_suspended(); |
|
637 |
||
638 |
return ret_code; |
|
639 |
} |
|
640 |
||
641 |
// Attach Listener is started lazily except in the case when |
|
642 |
// +ReduseSignalUsage is used |
|
643 |
bool AttachListener::init_at_startup() { |
|
644 |
if (ReduceSignalUsage) { |
|
645 |
return true; |
|
646 |
} else { |
|
647 |
return false; |
|
648 |
} |
|
649 |
} |
|
650 |
||
55682
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
51584
diff
changeset
|
651 |
bool AttachListener::check_socket_file() { |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
51584
diff
changeset
|
652 |
int ret; |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
51584
diff
changeset
|
653 |
struct stat64 st; |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
51584
diff
changeset
|
654 |
ret = stat64(SolarisAttachListener::door_path(), &st); |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
51584
diff
changeset
|
655 |
if (ret == -1) { // need to restart attach listener. |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
51584
diff
changeset
|
656 |
log_debug(attach)("Door file %s does not exist - Restart Attach Listener", |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
51584
diff
changeset
|
657 |
SolarisAttachListener::door_path()); |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
51584
diff
changeset
|
658 |
|
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
51584
diff
changeset
|
659 |
listener_cleanup(); |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
51584
diff
changeset
|
660 |
|
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
51584
diff
changeset
|
661 |
// wait to terminate current attach listener instance... |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
51584
diff
changeset
|
662 |
while (AttachListener::transit_state(AL_INITIALIZING, |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
51584
diff
changeset
|
663 |
AL_NOT_INITIALIZED) != AL_NOT_INITIALIZED) { |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
51584
diff
changeset
|
664 |
os::naked_yield(); |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
51584
diff
changeset
|
665 |
} |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
51584
diff
changeset
|
666 |
return is_init_trigger(); |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
51584
diff
changeset
|
667 |
} |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
51584
diff
changeset
|
668 |
return false; |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
51584
diff
changeset
|
669 |
} |
70fab3a8ff02
8225690: Multiple AttachListener threads can be created
ysuenaga
parents:
51584
diff
changeset
|
670 |
|
1 | 671 |
// If the file .attach_pid<pid> exists in the working directory |
672 |
// or /tmp then this is the trigger to start the attach mechanism |
|
673 |
bool AttachListener::is_init_trigger() { |
|
674 |
if (init_at_startup() || is_initialized()) { |
|
675 |
return false; // initialized at startup or already initialized |
|
676 |
} |
|
49742
1196aa0be8be
8201247: Various cleanups in the attach framework
clanger
parents:
49593
diff
changeset
|
677 |
char fn[PATH_MAX + 1]; |
1 | 678 |
int ret; |
679 |
struct stat64 st; |
|
49742
1196aa0be8be
8201247: Various cleanups in the attach framework
clanger
parents:
49593
diff
changeset
|
680 |
sprintf(fn, ".attach_pid%d", os::current_process_id()); |
1 | 681 |
RESTARTABLE(::stat64(fn, &st), ret); |
682 |
if (ret == -1) { |
|
40625
6b45fb9188f9
8157236: attach on ARMv7 fails with com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file
dsamersoff
parents:
37113
diff
changeset
|
683 |
log_trace(attach)("Failed to find attach file: %s, trying alternate", fn); |
5237
aab592fd4f44
6938627: Make temporary directory use property java.io.tmpdir when specified
coleenp
parents:
5089
diff
changeset
|
684 |
snprintf(fn, sizeof(fn), "%s/.attach_pid%d", |
aab592fd4f44
6938627: Make temporary directory use property java.io.tmpdir when specified
coleenp
parents:
5089
diff
changeset
|
685 |
os::get_temp_directory(), os::current_process_id()); |
1 | 686 |
RESTARTABLE(::stat64(fn, &st), ret); |
40625
6b45fb9188f9
8157236: attach on ARMv7 fails with com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file
dsamersoff
parents:
37113
diff
changeset
|
687 |
if (ret == -1) { |
6b45fb9188f9
8157236: attach on ARMv7 fails with com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file
dsamersoff
parents:
37113
diff
changeset
|
688 |
log_debug(attach)("Failed to find attach file: %s", fn); |
6b45fb9188f9
8157236: attach on ARMv7 fails with com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file
dsamersoff
parents:
37113
diff
changeset
|
689 |
} |
1 | 690 |
} |
691 |
if (ret == 0) { |
|
692 |
// simple check to avoid starting the attach mechanism when |
|
50333
7cea35f78b50
8197387: jcmd started by "root" must be allowed to access all VM processes
dtitov
parents:
49742
diff
changeset
|
693 |
// a bogus non-root user creates the file |
7cea35f78b50
8197387: jcmd started by "root" must be allowed to access all VM processes
dtitov
parents:
49742
diff
changeset
|
694 |
if (os::Posix::matches_effective_uid_or_root(st.st_uid)) { |
1 | 695 |
init(); |
49742
1196aa0be8be
8201247: Various cleanups in the attach framework
clanger
parents:
49593
diff
changeset
|
696 |
log_trace(attach)("Attach triggered by %s", fn); |
1 | 697 |
return true; |
49742
1196aa0be8be
8201247: Various cleanups in the attach framework
clanger
parents:
49593
diff
changeset
|
698 |
} else { |
1196aa0be8be
8201247: Various cleanups in the attach framework
clanger
parents:
49593
diff
changeset
|
699 |
log_debug(attach)("File %s has wrong user id %d (vs %d). Attach is not triggered", fn, st.st_uid, geteuid()); |
1 | 700 |
} |
701 |
} |
|
702 |
return false; |
|
703 |
} |
|
704 |
||
705 |
// if VM aborts then detach/cleanup |
|
706 |
void AttachListener::abort() { |
|
707 |
listener_cleanup(); |
|
708 |
} |
|
709 |
||
710 |
void AttachListener::pd_data_dump() { |
|
711 |
os::signal_notify(SIGQUIT); |
|
712 |
} |
|
713 |
||
714 |
static jint enable_dprobes(AttachOperation* op, outputStream* out) { |
|
715 |
const char* probe = op->arg(0); |
|
716 |
if (probe == NULL || probe[0] == '\0') { |
|
717 |
out->print_cr("No probe specified"); |
|
718 |
return JNI_ERR; |
|
719 |
} else { |
|
23870
2c9e85bccffb
8038296: sun/tools/jinfo/Basic.sh: java.io.IOException: Command failed in target VM
sla
parents:
18931
diff
changeset
|
720 |
char *end; |
2c9e85bccffb
8038296: sun/tools/jinfo/Basic.sh: java.io.IOException: Command failed in target VM
sla
parents:
18931
diff
changeset
|
721 |
long val = strtol(probe, &end, 10); |
2c9e85bccffb
8038296: sun/tools/jinfo/Basic.sh: java.io.IOException: Command failed in target VM
sla
parents:
18931
diff
changeset
|
722 |
if (end == probe || val < 0 || val > INT_MAX) { |
1 | 723 |
out->print_cr("invalid probe type"); |
724 |
return JNI_ERR; |
|
725 |
} else { |
|
23870
2c9e85bccffb
8038296: sun/tools/jinfo/Basic.sh: java.io.IOException: Command failed in target VM
sla
parents:
18931
diff
changeset
|
726 |
int probe_typess = (int) val; |
1 | 727 |
DTrace::enable_dprobes(probe_typess); |
728 |
return JNI_OK; |
|
729 |
} |
|
730 |
} |
|
731 |
} |
|
732 |
||
733 |
// platform specific operations table |
|
734 |
static AttachOperationFunctionInfo funcs[] = { |
|
735 |
{ "enabledprobes", enable_dprobes }, |
|
736 |
{ NULL, NULL } |
|
737 |
}; |
|
738 |
||
739 |
AttachOperationFunctionInfo* AttachListener::pd_find_operation(const char* name) { |
|
740 |
int i; |
|
741 |
for (i = 0; funcs[i].name != NULL; i++) { |
|
742 |
if (strcmp(funcs[i].name, name) == 0) { |
|
743 |
return &funcs[i]; |
|
744 |
} |
|
745 |
} |
|
746 |
return NULL; |
|
747 |
} |
|
748 |
||
749 |
// Solaris specific global flag set. Currently, we support only |
|
750 |
// changing ExtendedDTraceProbes flag. |
|
751 |
jint AttachListener::pd_set_flag(AttachOperation* op, outputStream* out) { |
|
752 |
const char* name = op->arg(0); |
|
753 |
assert(name != NULL, "flag name should not be null"); |
|
754 |
bool flag = true; |
|
755 |
const char* arg1; |
|
756 |
if ((arg1 = op->arg(1)) != NULL) { |
|
23870
2c9e85bccffb
8038296: sun/tools/jinfo/Basic.sh: java.io.IOException: Command failed in target VM
sla
parents:
18931
diff
changeset
|
757 |
char *end; |
2c9e85bccffb
8038296: sun/tools/jinfo/Basic.sh: java.io.IOException: Command failed in target VM
sla
parents:
18931
diff
changeset
|
758 |
flag = (strtol(arg1, &end, 10) != 0); |
2c9e85bccffb
8038296: sun/tools/jinfo/Basic.sh: java.io.IOException: Command failed in target VM
sla
parents:
18931
diff
changeset
|
759 |
if (arg1 == end) { |
1 | 760 |
out->print_cr("flag value has to be an integer"); |
761 |
return JNI_ERR; |
|
762 |
} |
|
763 |
} |
|
764 |
||
5089
0cce506a0158
6935224: Adding new DTrace probes to work with Palantir
fparain
parents:
1
diff
changeset
|
765 |
if (strcmp(name, "ExtendedDTraceProbes") == 0) { |
0cce506a0158
6935224: Adding new DTrace probes to work with Palantir
fparain
parents:
1
diff
changeset
|
766 |
DTrace::set_extended_dprobes(flag); |
0cce506a0158
6935224: Adding new DTrace probes to work with Palantir
fparain
parents:
1
diff
changeset
|
767 |
return JNI_OK; |
1 | 768 |
} |
769 |
||
5089
0cce506a0158
6935224: Adding new DTrace probes to work with Palantir
fparain
parents:
1
diff
changeset
|
770 |
if (strcmp(name, "DTraceMonitorProbes") == 0) { |
0cce506a0158
6935224: Adding new DTrace probes to work with Palantir
fparain
parents:
1
diff
changeset
|
771 |
DTrace::set_monitor_dprobes(flag); |
0cce506a0158
6935224: Adding new DTrace probes to work with Palantir
fparain
parents:
1
diff
changeset
|
772 |
return JNI_OK; |
0cce506a0158
6935224: Adding new DTrace probes to work with Palantir
fparain
parents:
1
diff
changeset
|
773 |
} |
0cce506a0158
6935224: Adding new DTrace probes to work with Palantir
fparain
parents:
1
diff
changeset
|
774 |
|
0cce506a0158
6935224: Adding new DTrace probes to work with Palantir
fparain
parents:
1
diff
changeset
|
775 |
out->print_cr("flag '%s' cannot be changed", name); |
0cce506a0158
6935224: Adding new DTrace probes to work with Palantir
fparain
parents:
1
diff
changeset
|
776 |
return JNI_ERR; |
1 | 777 |
} |
778 |
||
779 |
void AttachListener::pd_detachall() { |
|
780 |
DTrace::detach_all_clients(); |
|
781 |
} |