annotate src/os/solaris/dtrace/jvm_dtrace.c @ 0:a61af66fc99e

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