src/os/linux/vm/attachListener_linux.cpp

Print this page
rev 4897 : 7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
Reviewed-by: duke


 415 
 416 
 417 // AttachListener functions
 418 
 419 AttachOperation* AttachListener::dequeue() {
 420   JavaThread* thread = JavaThread::current();
 421   ThreadBlockInVM tbivm(thread);
 422 
 423   thread->set_suspend_equivalent();
 424   // cleared by handle_special_suspend_equivalent_condition() or
 425   // java_suspend_self() via check_and_wait_while_suspended()
 426 
 427   AttachOperation* op = LinuxAttachListener::dequeue();
 428 
 429   // were we externally suspended while we were waiting?
 430   thread->check_and_wait_while_suspended();
 431 
 432   return op;
 433 }
 434 






















 435 int AttachListener::pd_init() {
 436   JavaThread* thread = JavaThread::current();
 437   ThreadBlockInVM tbivm(thread);
 438 
 439   thread->set_suspend_equivalent();
 440   // cleared by handle_special_suspend_equivalent_condition() or
 441   // java_suspend_self() via check_and_wait_while_suspended()
 442 
 443   int ret_code = LinuxAttachListener::init();
 444 
 445   // were we externally suspended while we were waiting?
 446   thread->check_and_wait_while_suspended();
 447 
 448   return ret_code;
 449 }
 450 
 451 // Attach Listener is started lazily except in the case when
 452 // +ReduseSignalUsage is used
 453 bool AttachListener::init_at_startup() {
 454   if (ReduceSignalUsage) {
 455     return true;
 456   } else {
 457     return false;
 458   }
 459 }
 460 
 461 // If the file .attach_pid<pid> exists in the working directory
 462 // or /tmp then this is the trigger to start the attach mechanism
 463 bool AttachListener::is_init_trigger() {
 464   if (init_at_startup() || is_initialized()) {
 465     return false;               // initialized at startup or already initialized
 466   }
 467   char fn[PATH_MAX+1];
 468   sprintf(fn, ".attach_pid%d", os::current_process_id());
 469   int ret;
 470   struct stat64 st;
 471   RESTARTABLE(::stat64(fn, &st), ret);
 472   if (ret == -1) {
 473     snprintf(fn, sizeof(fn), "%s/.attach_pid%d",
 474              os::get_temp_directory(), os::current_process_id());
 475     RESTARTABLE(::stat64(fn, &st), ret);
 476   }
 477   if (ret == 0) {
 478     // simple check to avoid starting the attach mechanism when
 479     // a bogus user creates the file
 480     if (st.st_uid == geteuid()) {
 481       init();
 482       return true;
 483     }
 484   }
 485   return false;
 486 }
 487 
 488 // if VM aborts then remove listener
 489 void AttachListener::abort() {
 490   listener_cleanup();
 491 }
 492 
 493 void AttachListener::pd_data_dump() {


 415 
 416 
 417 // AttachListener functions
 418 
 419 AttachOperation* AttachListener::dequeue() {
 420   JavaThread* thread = JavaThread::current();
 421   ThreadBlockInVM tbivm(thread);
 422 
 423   thread->set_suspend_equivalent();
 424   // cleared by handle_special_suspend_equivalent_condition() or
 425   // java_suspend_self() via check_and_wait_while_suspended()
 426 
 427   AttachOperation* op = LinuxAttachListener::dequeue();
 428 
 429   // were we externally suspended while we were waiting?
 430   thread->check_and_wait_while_suspended();
 431 
 432   return op;
 433 }
 434 
 435 
 436 // Performs initialization at vm startup
 437 // For Linux we remove any stale .java_pid file which could cause
 438 // an attaching process to think we are ready to recieve on the
 439 // domain socket before we are properly initialized
 440 
 441 void AttachListener::vm_start() {
 442   char fn[UNIX_PATH_MAX];
 443   struct stat64 st;
 444   int ret;
 445 
 446   snprintf(fn, UNIX_PATH_MAX, "%s/.java_pid%d",
 447            os::get_temp_directory(), os::current_process_id());
 448   RESTARTABLE(::stat64(fn, &st), ret);
 449   if (ret == 0) {
 450     ret = ::unlink(fn);
 451     if(ret == -1) {
 452       debug_only(warning("failed to remove stale attach pid file at %s", fn));
 453     }
 454   }
 455 }
 456 
 457 int AttachListener::pd_init() {
 458   JavaThread* thread = JavaThread::current();
 459   ThreadBlockInVM tbivm(thread);
 460 
 461   thread->set_suspend_equivalent();
 462   // cleared by handle_special_suspend_equivalent_condition() or
 463   // java_suspend_self() via check_and_wait_while_suspended()
 464 
 465   int ret_code = LinuxAttachListener::init();
 466 
 467   // were we externally suspended while we were waiting?
 468   thread->check_and_wait_while_suspended();
 469 
 470   return ret_code;
 471 }
 472 
 473 // Attach Listener is started lazily except in the case when
 474 // +ReduseSignalUsage is used
 475 bool AttachListener::init_at_startup() {
 476   if (ReduceSignalUsage) {
 477     return true;
 478   } else {
 479     return false;
 480   }
 481 }
 482 
 483 // If the file .attach_pid<pid> exists in the working directory
 484 // or /tmp then this is the trigger to start the attach mechanism
 485 bool AttachListener::is_init_trigger() {
 486   if (init_at_startup() || is_initialized()) {
 487     return false;               // initialized at startup or already initialized
 488   }
 489   char fn[UNIX_PATH_MAX];
 490   snprintf(fn, UNIX_PATH_MAX, ".attach_pid%d", os::current_process_id());
 491   int ret;
 492   struct stat64 st;
 493   RESTARTABLE(::stat64(fn, &st), ret);
 494   if (ret == -1) {
 495     snprintf(fn, UNIX_PATH_MAX, "%s/.attach_pid%d",
 496              os::get_temp_directory(), os::current_process_id());
 497     RESTARTABLE(::stat64(fn, &st), ret);
 498   }
 499   if (ret == 0) {
 500     // simple check to avoid starting the attach mechanism when
 501     // a bogus user creates the file
 502     if (st.st_uid == geteuid()) {
 503       init();
 504       return true;
 505     }
 506   }
 507   return false;
 508 }
 509 
 510 // if VM aborts then remove listener
 511 void AttachListener::abort() {
 512   listener_cleanup();
 513 }
 514 
 515 void AttachListener::pd_data_dump() {