src/os/solaris/dtrace/jvm_dtrace.c

Wed, 25 Aug 2010 05:27:54 -0700

author
twisti
date
Wed, 25 Aug 2010 05:27:54 -0700
changeset 2103
3e8fbc61cee8
parent 1907
c18cbe5936b8
child 2314
f95d63e2154a
permissions
-rw-r--r--

6978355: renaming for 6961697
Summary: This is the renaming part of 6961697 to keep the actual changes small for review.
Reviewed-by: kvn, never

duke@435 1 /*
trims@1907 2 * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 #include <door.h>
duke@435 26 #include <errno.h>
duke@435 27 #include <fcntl.h>
duke@435 28 #include <limits.h>
duke@435 29 #include <poll.h>
duke@435 30 #include <signal.h>
duke@435 31 #include <stdarg.h>
duke@435 32 #include <stdio.h>
duke@435 33 #include <stdlib.h>
duke@435 34 #include <string.h>
duke@435 35 #include <sys/types.h>
duke@435 36 #include <sys/stat.h>
duke@435 37 #include <thread.h>
duke@435 38 #include <unistd.h>
duke@435 39 #include "jvm_dtrace.h"
duke@435 40
duke@435 41 // NOTE: These constants are used in JVM code as well.
duke@435 42 // KEEP JVM CODE IN SYNC if you are going to change these...
duke@435 43
duke@435 44 #define DTRACE_ALLOC_PROBES 0x1
duke@435 45 #define DTRACE_METHOD_PROBES 0x2
duke@435 46 #define DTRACE_MONITOR_PROBES 0x4
duke@435 47 #define DTRACE_ALL_PROBES -1
duke@435 48
duke@435 49 // generic error messages
duke@435 50 #define JVM_ERR_OUT_OF_MEMORY "out of memory (native heap)"
duke@435 51 #define JVM_ERR_INVALID_PARAM "invalid input parameter(s)"
duke@435 52 #define JVM_ERR_NULL_PARAM "input paramater is NULL"
duke@435 53
duke@435 54 // error messages for attach
duke@435 55 #define JVM_ERR_CANT_OPEN_DOOR "cannot open door file"
duke@435 56 #define JVM_ERR_CANT_CREATE_ATTACH_FILE "cannot create attach file"
duke@435 57 #define JVM_ERR_DOOR_FILE_PERMISSION "door file is not secure"
duke@435 58 #define JVM_ERR_CANT_SIGNAL "cannot send SIGQUIT to target"
duke@435 59
duke@435 60 // error messages for enable probe
duke@435 61 #define JVM_ERR_DOOR_CMD_SEND "door command send failed"
duke@435 62 #define JVM_ERR_DOOR_CANT_READ_STATUS "cannot read door command status"
duke@435 63 #define JVM_ERR_DOOR_CMD_STATUS "door command error status"
duke@435 64
duke@435 65 // error message for detach
duke@435 66 #define JVM_ERR_CANT_CLOSE_DOOR "cannot close door file"
duke@435 67
duke@435 68 #define RESTARTABLE(_cmd, _result) do { \
duke@435 69 do { \
duke@435 70 _result = _cmd; \
duke@435 71 } while((_result == -1) && (errno == EINTR)); \
duke@435 72 } while(0)
duke@435 73
duke@435 74 struct _jvm_t {
duke@435 75 pid_t pid;
duke@435 76 int door_fd;
duke@435 77 };
duke@435 78
duke@435 79 static int libjvm_dtrace_debug;
duke@435 80 static void print_debug(const char* fmt,...) {
duke@435 81 if (libjvm_dtrace_debug) {
duke@435 82 va_list alist;
duke@435 83 va_start(alist, fmt);
duke@435 84 fputs("libjvm_dtrace DEBUG: ", stderr);
duke@435 85 vfprintf(stderr, fmt, alist);
duke@435 86 va_end(alist);
duke@435 87 }
duke@435 88 }
duke@435 89
duke@435 90 /* Key for thread local error message */
duke@435 91 static thread_key_t jvm_error_key;
duke@435 92
duke@435 93 /* init function for this library */
duke@435 94 static void init_jvm_dtrace() {
duke@435 95 /* check for env. var for debug mode */
duke@435 96 libjvm_dtrace_debug = getenv("LIBJVM_DTRACE_DEBUG") != NULL;
duke@435 97 /* create key for thread local error message */
duke@435 98 if (thr_keycreate(&jvm_error_key, NULL) != 0) {
duke@435 99 print_debug("can't create thread_key_t for jvm error key\n");
duke@435 100 // exit(1); ?
duke@435 101 }
duke@435 102 }
duke@435 103
duke@435 104 #pragma init(init_jvm_dtrace)
duke@435 105
duke@435 106 /* set thread local error message */
duke@435 107 static void set_jvm_error(const char* msg) {
duke@435 108 thr_setspecific(jvm_error_key, (void*)msg);
duke@435 109 }
duke@435 110
duke@435 111 /* clear thread local error message */
duke@435 112 static void clear_jvm_error() {
duke@435 113 thr_setspecific(jvm_error_key, NULL);
duke@435 114 }
duke@435 115
duke@435 116 /* file handling functions that can handle interrupt */
duke@435 117
duke@435 118 static int file_open(const char* path, int flag) {
duke@435 119 int ret;
duke@435 120 RESTARTABLE(open(path, flag), ret);
duke@435 121 return ret;
duke@435 122 }
duke@435 123
duke@435 124 static int file_close(int fd) {
duke@435 125 int ret;
duke@435 126 RESTARTABLE(close(fd), ret);
duke@435 127 return ret;
duke@435 128 }
duke@435 129
duke@435 130 static int file_read(int fd, char* buf, int len) {
duke@435 131 int ret;
duke@435 132 RESTARTABLE(read(fd, buf, len), ret);
duke@435 133 return ret;
duke@435 134 }
duke@435 135
duke@435 136 /* send SIGQUIT signal to given process */
duke@435 137 static int send_sigquit(pid_t pid) {
duke@435 138 int ret;
duke@435 139 RESTARTABLE(kill(pid, SIGQUIT), ret);
duke@435 140 return ret;
duke@435 141 }
duke@435 142
duke@435 143 /* called to check permissions on attach file */
duke@435 144 static int check_permission(const char* path) {
duke@435 145 struct stat64 sb;
duke@435 146 uid_t uid, gid;
duke@435 147 int res;
duke@435 148
duke@435 149 /*
duke@435 150 * Check that the path is owned by the effective uid/gid of this
duke@435 151 * process. Also check that group/other access is not allowed.
duke@435 152 */
duke@435 153 uid = geteuid();
duke@435 154 gid = getegid();
duke@435 155
duke@435 156 res = stat64(path, &sb);
duke@435 157 if (res != 0) {
duke@435 158 print_debug("stat failed for %s\n", path);
duke@435 159 return -1;
duke@435 160 }
duke@435 161
duke@435 162 if ((sb.st_uid != uid) || (sb.st_gid != gid) ||
duke@435 163 ((sb.st_mode & (S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) != 0)) {
duke@435 164 print_debug("well-known file %s is not secure\n", path);
duke@435 165 return -1;
duke@435 166 }
duke@435 167 return 0;
duke@435 168 }
duke@435 169
duke@435 170 #define ATTACH_FILE_PATTERN "/tmp/.attach_pid%d"
duke@435 171
duke@435 172 /* fill-in the name of attach file name in given buffer */
duke@435 173 static void fill_attach_file_name(char* path, int len, pid_t pid) {
duke@435 174 memset(path, 0, len);
duke@435 175 sprintf(path, ATTACH_FILE_PATTERN, pid);
duke@435 176 }
duke@435 177
duke@435 178 #define DOOR_FILE_PATTERN "/tmp/.java_pid%d"
duke@435 179
duke@435 180 /* open door file for the given JVM */
duke@435 181 static int open_door(pid_t pid) {
duke@435 182 char path[PATH_MAX + 1];
duke@435 183 int fd;
duke@435 184
duke@435 185 sprintf(path, DOOR_FILE_PATTERN, pid);
duke@435 186 fd = file_open(path, O_RDONLY);
duke@435 187 if (fd < 0) {
duke@435 188 set_jvm_error(JVM_ERR_CANT_OPEN_DOOR);
duke@435 189 print_debug("cannot open door file %s\n", path);
duke@435 190 return -1;
duke@435 191 }
duke@435 192 print_debug("opened door file %s\n", path);
duke@435 193 if (check_permission(path) != 0) {
duke@435 194 set_jvm_error(JVM_ERR_DOOR_FILE_PERMISSION);
duke@435 195 print_debug("check permission failed for %s\n", path);
duke@435 196 file_close(fd);
duke@435 197 fd = -1;
duke@435 198 }
duke@435 199 return fd;
duke@435 200 }
duke@435 201
duke@435 202 /* create attach file for given process */
duke@435 203 static int create_attach_file(pid_t pid) {
duke@435 204 char path[PATH_MAX + 1];
duke@435 205 int fd;
duke@435 206 fill_attach_file_name(path, sizeof(path), pid);
duke@435 207 fd = file_open(path, O_CREAT | O_RDWR);
duke@435 208 if (fd < 0) {
duke@435 209 set_jvm_error(JVM_ERR_CANT_CREATE_ATTACH_FILE);
duke@435 210 print_debug("cannot create file %s\n", path);
duke@435 211 } else {
duke@435 212 print_debug("created attach file %s\n", path);
duke@435 213 }
duke@435 214 return fd;
duke@435 215 }
duke@435 216
duke@435 217 /* delete attach file for given process */
duke@435 218 static void delete_attach_file(pid_t pid) {
duke@435 219 char path[PATH_MAX + 1];
duke@435 220 fill_attach_file_name(path, sizeof(path), pid);
duke@435 221 int res = unlink(path);
duke@435 222 if (res) {
duke@435 223 print_debug("cannot delete attach file %s\n", path);
duke@435 224 } else {
duke@435 225 print_debug("deleted attach file %s\n", path);
duke@435 226 }
duke@435 227 }
duke@435 228
duke@435 229 /* attach to given JVM */
duke@435 230 jvm_t* jvm_attach(pid_t pid) {
duke@435 231 jvm_t* jvm;
duke@435 232 int door_fd, attach_fd, i;
duke@435 233
duke@435 234 jvm = (jvm_t*) calloc(1, sizeof(jvm_t));
duke@435 235 if (jvm == NULL) {
duke@435 236 set_jvm_error(JVM_ERR_OUT_OF_MEMORY);
duke@435 237 print_debug("calloc failed in %s at %d\n", __FILE__, __LINE__);
duke@435 238 return NULL;
duke@435 239 }
duke@435 240 jvm->pid = pid;
duke@435 241 attach_fd = -1;
duke@435 242
duke@435 243 door_fd = open_door(pid);
duke@435 244 if (door_fd < 0) {
duke@435 245 print_debug("trying to create attach file\n");
duke@435 246 if ((attach_fd = create_attach_file(pid)) < 0) {
duke@435 247 goto quit;
duke@435 248 }
duke@435 249
duke@435 250 /* send QUIT signal to the target so that it will
duke@435 251 * check for the attach file.
duke@435 252 */
duke@435 253 if (send_sigquit(pid) != 0) {
duke@435 254 set_jvm_error(JVM_ERR_CANT_SIGNAL);
duke@435 255 print_debug("sending SIGQUIT failed\n");
duke@435 256 goto quit;
duke@435 257 }
duke@435 258
duke@435 259 /* give the target VM time to start the attach mechanism */
duke@435 260 do {
duke@435 261 int res;
duke@435 262 RESTARTABLE(poll(0, 0, 200), res);
duke@435 263 door_fd = open_door(pid);
duke@435 264 i++;
duke@435 265 } while (i <= 50 && door_fd == -1);
duke@435 266 if (door_fd < 0) {
duke@435 267 print_debug("Unable to open door to process %d\n", pid);
duke@435 268 goto quit;
duke@435 269 }
duke@435 270 }
duke@435 271
duke@435 272 quit:
duke@435 273 if (attach_fd >= 0) {
duke@435 274 file_close(attach_fd);
duke@435 275 delete_attach_file(jvm->pid);
duke@435 276 }
duke@435 277 if (door_fd >= 0) {
duke@435 278 jvm->door_fd = door_fd;
duke@435 279 clear_jvm_error();
duke@435 280 } else {
duke@435 281 free(jvm);
duke@435 282 jvm = NULL;
duke@435 283 }
duke@435 284 return jvm;
duke@435 285 }
duke@435 286
duke@435 287 /* return the last thread local error message */
duke@435 288 const char* jvm_get_last_error() {
duke@435 289 const char* res = NULL;
duke@435 290 thr_getspecific(jvm_error_key, (void**)&res);
duke@435 291 return res;
duke@435 292 }
duke@435 293
duke@435 294 /* detach the givenb JVM */
duke@435 295 int jvm_detach(jvm_t* jvm) {
duke@435 296 if (jvm) {
duke@435 297 int res;
duke@435 298 if (jvm->door_fd != -1) {
duke@435 299 if (file_close(jvm->door_fd) != 0) {
duke@435 300 set_jvm_error(JVM_ERR_CANT_CLOSE_DOOR);
duke@435 301 res = -1;
duke@435 302 } else {
duke@435 303 clear_jvm_error();
duke@435 304 res = 0;
duke@435 305 }
duke@435 306 }
duke@435 307 free(jvm);
duke@435 308 return res;
duke@435 309 } else {
duke@435 310 set_jvm_error(JVM_ERR_NULL_PARAM);
duke@435 311 print_debug("jvm_t* is NULL\n");
duke@435 312 return -1;
duke@435 313 }
duke@435 314 }
duke@435 315
duke@435 316 /*
duke@435 317 * A simple table to translate some known errors into reasonable
duke@435 318 * error messages
duke@435 319 */
duke@435 320 static struct {
duke@435 321 int err;
duke@435 322 const char* msg;
duke@435 323 } const error_messages[] = {
duke@435 324 { 100, "Bad request" },
duke@435 325 { 101, "Protocol mismatch" },
duke@435 326 { 102, "Resource failure" },
duke@435 327 { 103, "Internal error" },
duke@435 328 { 104, "Permission denied" },
duke@435 329 };
duke@435 330
duke@435 331 /*
duke@435 332 * Lookup the given error code and return the appropriate
duke@435 333 * message. If not found return NULL.
duke@435 334 */
duke@435 335 static const char* translate_error(int err) {
duke@435 336 int table_size = sizeof(error_messages) / sizeof(error_messages[0]);
duke@435 337 int i;
duke@435 338
duke@435 339 for (i=0; i<table_size; i++) {
duke@435 340 if (err == error_messages[i].err) {
duke@435 341 return error_messages[i].msg;
duke@435 342 }
duke@435 343 }
duke@435 344 return NULL;
duke@435 345 }
duke@435 346
duke@435 347 /*
duke@435 348 * Current protocol version
duke@435 349 */
duke@435 350 static const char* PROTOCOL_VERSION = "1";
duke@435 351
duke@435 352 #define RES_BUF_SIZE 128
duke@435 353
duke@435 354 /*
duke@435 355 * Enqueue attach-on-demand command to the given JVM
duke@435 356 */
duke@435 357 static
duke@435 358 int enqueue_command(jvm_t* jvm, const char* cstr, int arg_count, const char** args) {
duke@435 359 size_t size;
duke@435 360 door_arg_t door_args;
duke@435 361 char res_buffer[RES_BUF_SIZE];
duke@435 362 int rc, i;
duke@435 363 char* buf = NULL;
duke@435 364 int result = -1;
duke@435 365
duke@435 366 /*
duke@435 367 * First we get the command string and create the start of the
duke@435 368 * argument string to send to the target VM:
duke@435 369 * <ver>\0<cmd>\0
duke@435 370 */
duke@435 371 if (cstr == NULL) {
duke@435 372 print_debug("command name is NULL\n");
duke@435 373 goto quit;
duke@435 374 }
duke@435 375 size = strlen(PROTOCOL_VERSION) + strlen(cstr) + 2;
duke@435 376 buf = (char*)malloc(size);
duke@435 377 if (buf != NULL) {
duke@435 378 char* pos = buf;
duke@435 379 strcpy(buf, PROTOCOL_VERSION);
duke@435 380 pos += strlen(PROTOCOL_VERSION)+1;
duke@435 381 strcpy(pos, cstr);
duke@435 382 } else {
duke@435 383 set_jvm_error(JVM_ERR_OUT_OF_MEMORY);
duke@435 384 print_debug("malloc failed at %d in %s\n", __LINE__, __FILE__);
duke@435 385 goto quit;
duke@435 386 }
duke@435 387
duke@435 388 /*
duke@435 389 * Next we iterate over the arguments and extend the buffer
duke@435 390 * to include them.
duke@435 391 */
duke@435 392 for (i=0; i<arg_count; i++) {
duke@435 393 cstr = args[i];
duke@435 394 if (cstr != NULL) {
duke@435 395 size_t len = strlen(cstr);
duke@435 396 char* newbuf = (char*)realloc(buf, size+len+1);
duke@435 397 if (newbuf == NULL) {
duke@435 398 set_jvm_error(JVM_ERR_OUT_OF_MEMORY);
duke@435 399 print_debug("realloc failed in %s at %d\n", __FILE__, __LINE__);
duke@435 400 goto quit;
duke@435 401 }
duke@435 402 buf = newbuf;
duke@435 403 strcpy(buf+size, cstr);
duke@435 404 size += len+1;
duke@435 405 }
duke@435 406 }
duke@435 407
duke@435 408 /*
duke@435 409 * The arguments to the door function are in 'buf' so we now
duke@435 410 * do the door call
duke@435 411 */
duke@435 412 door_args.data_ptr = buf;
duke@435 413 door_args.data_size = size;
duke@435 414 door_args.desc_ptr = NULL;
duke@435 415 door_args.desc_num = 0;
duke@435 416 door_args.rbuf = (char*)&res_buffer;
duke@435 417 door_args.rsize = sizeof(res_buffer);
duke@435 418
duke@435 419 RESTARTABLE(door_call(jvm->door_fd, &door_args), rc);
duke@435 420
duke@435 421 /*
duke@435 422 * door_call failed
duke@435 423 */
duke@435 424 if (rc == -1) {
duke@435 425 print_debug("door_call failed\n");
duke@435 426 } else {
duke@435 427 /*
duke@435 428 * door_call succeeded but the call didn't return the the expected jint.
duke@435 429 */
duke@435 430 if (door_args.data_size < sizeof(int)) {
duke@435 431 print_debug("Enqueue error - reason unknown as result is truncated!");
duke@435 432 } else {
duke@435 433 int* res = (int*)(door_args.data_ptr);
duke@435 434 if (*res != 0) {
duke@435 435 const char* msg = translate_error(*res);
duke@435 436 if (msg == NULL) {
duke@435 437 print_debug("Unable to enqueue command to target VM: %d\n", *res);
duke@435 438 } else {
duke@435 439 print_debug("Unable to enqueue command to target VM: %s\n", msg);
duke@435 440 }
duke@435 441 } else {
duke@435 442 /*
duke@435 443 * The door call should return a file descriptor to one end of
duke@435 444 * a socket pair
duke@435 445 */
duke@435 446 if ((door_args.desc_ptr != NULL) &&
duke@435 447 (door_args.desc_num == 1) &&
duke@435 448 (door_args.desc_ptr->d_attributes & DOOR_DESCRIPTOR)) {
duke@435 449 result = door_args.desc_ptr->d_data.d_desc.d_descriptor;
duke@435 450 } else {
duke@435 451 print_debug("Reply from enqueue missing descriptor!\n");
duke@435 452 }
duke@435 453 }
duke@435 454 }
duke@435 455 }
duke@435 456
duke@435 457 quit:
duke@435 458 if (buf) free(buf);
duke@435 459 return result;
duke@435 460 }
duke@435 461
duke@435 462 /* read status code for a door command */
duke@435 463 static int read_status(int fd) {
duke@435 464 char ch, buf[16];
duke@435 465 int index = 0;
duke@435 466
duke@435 467 while (1) {
duke@435 468 if (file_read(fd, &ch, sizeof(ch)) != sizeof(ch)) {
duke@435 469 set_jvm_error(JVM_ERR_DOOR_CANT_READ_STATUS);
duke@435 470 print_debug("door cmd status: read status failed\n");
duke@435 471 return -1;
duke@435 472 }
duke@435 473 buf[index++] = ch;
duke@435 474 if (ch == '\n') {
duke@435 475 buf[index - 1] = '\0';
duke@435 476 return atoi(buf);
duke@435 477 }
duke@435 478 if (index == sizeof(buf)) {
duke@435 479 set_jvm_error(JVM_ERR_DOOR_CANT_READ_STATUS);
duke@435 480 print_debug("door cmd status: read status overflow\n");
duke@435 481 return -1;
duke@435 482 }
duke@435 483 }
duke@435 484 }
duke@435 485
duke@435 486 static const char* ENABLE_DPROBES_CMD = "enabledprobes";
duke@435 487
duke@435 488 /* enable one or more DTrace probes for a given JVM */
duke@435 489 int jvm_enable_dtprobes(jvm_t* jvm, int num_probe_types, const char** probe_types) {
duke@435 490 int fd, status = 0;
duke@435 491 char ch;
duke@435 492 const char* args[1];
duke@435 493 char buf[16];
duke@435 494 int probe_type = 0, index;
duke@435 495 int count = 0;
duke@435 496
duke@435 497 if (jvm == NULL) {
duke@435 498 set_jvm_error(JVM_ERR_NULL_PARAM);
duke@435 499 print_debug("jvm_t* is NULL\n");
duke@435 500 return -1;
duke@435 501 }
duke@435 502
duke@435 503 if (num_probe_types == 0 || probe_types == NULL ||
duke@435 504 probe_types[0] == NULL) {
duke@435 505 set_jvm_error(JVM_ERR_INVALID_PARAM);
duke@435 506 print_debug("invalid probe type argument(s)\n");
duke@435 507 return -1;
duke@435 508 }
duke@435 509
duke@435 510 for (index = 0; index < num_probe_types; index++) {
duke@435 511 const char* p = probe_types[index];
duke@435 512 if (strcmp(p, JVM_DTPROBE_OBJECT_ALLOC) == 0) {
duke@435 513 probe_type |= DTRACE_ALLOC_PROBES;
duke@435 514 count++;
duke@435 515 } else if (strcmp(p, JVM_DTPROBE_METHOD_ENTRY) == 0 ||
duke@435 516 strcmp(p, JVM_DTPROBE_METHOD_RETURN) == 0) {
duke@435 517 probe_type |= DTRACE_METHOD_PROBES;
duke@435 518 count++;
duke@435 519 } else if (strcmp(p, JVM_DTPROBE_MONITOR_ENTER) == 0 ||
duke@435 520 strcmp(p, JVM_DTPROBE_MONITOR_ENTERED) == 0 ||
duke@435 521 strcmp(p, JVM_DTPROBE_MONITOR_EXIT) == 0 ||
duke@435 522 strcmp(p, JVM_DTPROBE_MONITOR_WAIT) == 0 ||
duke@435 523 strcmp(p, JVM_DTPROBE_MONITOR_WAITED) == 0 ||
duke@435 524 strcmp(p, JVM_DTPROBE_MONITOR_NOTIFY) == 0 ||
duke@435 525 strcmp(p, JVM_DTPROBE_MONITOR_NOTIFYALL) == 0) {
duke@435 526 probe_type |= DTRACE_MONITOR_PROBES;
duke@435 527 count++;
duke@435 528 } else if (strcmp(p, JVM_DTPROBE_ALL) == 0) {
duke@435 529 probe_type |= DTRACE_ALL_PROBES;
duke@435 530 count++;
duke@435 531 }
duke@435 532 }
duke@435 533
duke@435 534 if (count == 0) {
duke@435 535 return count;
duke@435 536 }
duke@435 537 sprintf(buf, "%d", probe_type);
duke@435 538 args[0] = buf;
duke@435 539
duke@435 540 fd = enqueue_command(jvm, ENABLE_DPROBES_CMD, 1, args);
duke@435 541 if (fd < 0) {
duke@435 542 set_jvm_error(JVM_ERR_DOOR_CMD_SEND);
duke@435 543 return -1;
duke@435 544 }
duke@435 545
duke@435 546 status = read_status(fd);
duke@435 547 // non-zero status is error
duke@435 548 if (status) {
duke@435 549 set_jvm_error(JVM_ERR_DOOR_CMD_STATUS);
duke@435 550 print_debug("%s command failed (status: %d) in target JVM\n",
duke@435 551 ENABLE_DPROBES_CMD, status);
duke@435 552 file_close(fd);
duke@435 553 return -1;
duke@435 554 }
duke@435 555 // read from stream until EOF
duke@435 556 while (file_read(fd, &ch, sizeof(ch)) == sizeof(ch)) {
duke@435 557 if (libjvm_dtrace_debug) {
duke@435 558 printf("%c", ch);
duke@435 559 }
duke@435 560 }
duke@435 561
duke@435 562 file_close(fd);
duke@435 563 clear_jvm_error();
duke@435 564 return count;
duke@435 565 }

mercurial