comparison src/os/solaris/vm/attachListener_solaris.cpp @ 1675:a81afd9c293c

6649594: Intermittent IOExceptions during dynamic attach on linux and solaris Reviewed-by: dcubed, dholmes
author alanb
date Fri, 16 Jul 2010 13:14:03 +0100
parents c18cbe5936b8
children f95d63e2154a
comparison
equal deleted inserted replaced
1642:0e7d2a08b605 1675:a81afd9c293c
362 } 362 }
363 363
364 // Create the door 364 // Create the door
365 int SolarisAttachListener::create_door() { 365 int SolarisAttachListener::create_door() {
366 char door_path[PATH_MAX+1]; 366 char door_path[PATH_MAX+1];
367 char initial_path[PATH_MAX+1];
367 int fd, res; 368 int fd, res;
368 369
369 // register exit function 370 // register exit function
370 ::atexit(listener_cleanup); 371 ::atexit(listener_cleanup);
371 372
373 int dd = ::door_create(enqueue_proc, NULL, 0); 374 int dd = ::door_create(enqueue_proc, NULL, 0);
374 if (dd < 0) { 375 if (dd < 0) {
375 return -1; 376 return -1;
376 } 377 }
377 378
379 // create initial file to attach door descriptor
378 snprintf(door_path, sizeof(door_path), "%s/.java_pid%d", 380 snprintf(door_path, sizeof(door_path), "%s/.java_pid%d",
379 os::get_temp_directory(), os::current_process_id()); 381 os::get_temp_directory(), os::current_process_id());
380 RESTARTABLE(::creat(door_path, S_IRUSR | S_IWUSR), fd); 382 snprintf(initial_path, sizeof(initial_path), "%s.tmp", door_path);
381 383 RESTARTABLE(::creat(initial_path, S_IRUSR | S_IWUSR), fd);
382 if (fd == -1) { 384 if (fd == -1) {
383 debug_only(warning("attempt to create %s failed", door_path)); 385 debug_only(warning("attempt to create %s failed", initial_path));
386 ::door_revoke(dd);
384 return -1; 387 return -1;
385 } 388 }
386 assert(fd >= 0, "bad file descriptor"); 389 assert(fd >= 0, "bad file descriptor");
387 set_door_path(door_path);
388 RESTARTABLE(::close(fd), res); 390 RESTARTABLE(::close(fd), res);
389 391
390 // attach the door descriptor to the file 392 // attach the door descriptor to the file
391 if ((res = ::fattach(dd, door_path)) == -1) { 393 if ((res = ::fattach(dd, initial_path)) == -1) {
392 // if busy then detach and try again 394 // if busy then detach and try again
393 if (errno == EBUSY) { 395 if (errno == EBUSY) {
394 ::fdetach(door_path); 396 ::fdetach(initial_path);
395 res = ::fattach(dd, door_path); 397 res = ::fattach(dd, initial_path);
396 } 398 }
397 if (res == -1) { 399 if (res == -1) {
398 ::door_revoke(dd); 400 ::door_revoke(dd);
399 dd = -1; 401 dd = -1;
400 } 402 }
401 } 403 }
404
405 // rename file so that clients can attach
406 if (dd >= 0) {
407 if (::rename(initial_path, door_path) == -1) {
408 RESTARTABLE(::close(dd), res);
409 ::fdetach(initial_path);
410 dd = -1;
411 }
412 }
402 if (dd >= 0) { 413 if (dd >= 0) {
403 set_door_descriptor(dd); 414 set_door_descriptor(dd);
415 set_door_path(door_path);
404 } else { 416 } else {
405 // unable to create door or attach it to the file 417 // unable to create door, attach it to file, or rename file into place
406 ::unlink(door_path); 418 ::unlink(initial_path);
407 set_door_path(NULL);
408 return -1; 419 return -1;
409 } 420 }
410 421
411 return 0; 422 return 0;
412 } 423 }