< prev index next >

src/os/windows/vm/os_windows.cpp

Print this page




5233     WaitForSingleObject(_ParkEvent, time);
5234     ResetEvent(_ParkEvent);
5235 
5236     // If externally suspended while waiting, re-suspend
5237     if (thread->handle_special_suspend_equivalent_condition()) {
5238       thread->java_suspend_self();
5239     }
5240   }
5241 }
5242 
5243 void Parker::unpark() {
5244   guarantee(_ParkEvent != NULL, "invariant");
5245   SetEvent(_ParkEvent);
5246 }
5247 
5248 // Run the specified command in a separate process. Return its exit value,
5249 // or -1 on failure (e.g. can't create a new process).
5250 int os::fork_and_exec(char* cmd) {
5251   STARTUPINFO si;
5252   PROCESS_INFORMATION pi;












5253 






5254   memset(&si, 0, sizeof(si));
5255   si.cb = sizeof(si);
5256   memset(&pi, 0, sizeof(pi));
5257   BOOL rslt = CreateProcess(NULL,   // executable name - use command line
5258                             cmd,    // command line
5259                             NULL,   // process security attribute
5260                             NULL,   // thread security attribute
5261                             TRUE,   // inherits system handles
5262                             0,      // no creation flags
5263                             NULL,   // use parent's environment block
5264                             NULL,   // use parent's starting directory
5265                             &si,    // (in) startup information
5266                             &pi);   // (out) process information
5267 
5268   if (rslt) {
5269     // Wait until child process exits.
5270     WaitForSingleObject(pi.hProcess, INFINITE);
5271 
5272     DWORD exit_code;
5273     GetExitCodeProcess(pi.hProcess, &exit_code);
5274 
5275     // Close process and thread handles.
5276     CloseHandle(pi.hProcess);
5277     CloseHandle(pi.hThread);
5278 
5279     return (int)exit_code;
5280   } else {
5281     return -1;
5282   }



5283 }
5284 
5285 bool os::find(address addr, outputStream* st) {
5286   int offset = -1;
5287   bool result = false;
5288   char buf[256];
5289   if (os::dll_address_to_library_name(addr, buf, sizeof(buf), &offset)) {
5290     st->print(PTR_FORMAT " ", addr);
5291     if (strlen(buf) < sizeof(buf) - 1) {
5292       char* p = strrchr(buf, '\\');
5293       if (p) {
5294         st->print("%s", p + 1);
5295       } else {
5296         st->print("%s", buf);
5297       }
5298     } else {
5299         // The library name is probably truncated. Let's omit the library name.
5300         // See also JDK-8147512.
5301     }
5302     if (os::dll_address_to_function_name(addr, buf, sizeof(buf), &offset)) {




5233     WaitForSingleObject(_ParkEvent, time);
5234     ResetEvent(_ParkEvent);
5235 
5236     // If externally suspended while waiting, re-suspend
5237     if (thread->handle_special_suspend_equivalent_condition()) {
5238       thread->java_suspend_self();
5239     }
5240   }
5241 }
5242 
5243 void Parker::unpark() {
5244   guarantee(_ParkEvent != NULL, "invariant");
5245   SetEvent(_ParkEvent);
5246 }
5247 
5248 // Run the specified command in a separate process. Return its exit value,
5249 // or -1 on failure (e.g. can't create a new process).
5250 int os::fork_and_exec(char* cmd) {
5251   STARTUPINFO si;
5252   PROCESS_INFORMATION pi;
5253   DWORD exit_code;
5254 
5255   char * cmd_string;
5256   char * cmd_prefix = "cmd /C ";
5257   size_t len = strlen(cmd) + strlen(cmd_prefix) + 1;
5258   cmd_string = NEW_C_HEAP_ARRAY_RETURN_NULL(char, len, mtInternal);
5259   if (cmd_string == NULL) {
5260     return -1;
5261   }
5262   cmd_string[0] = '\0';
5263   strcat(cmd_string, cmd_prefix);
5264   strcat(cmd_string, cmd);
5265 
5266 // now replace all '\n' with '&'
5267   char * substring = cmd_string;
5268   while ((substring = strchr (substring, '\n')) != NULL) {
5269     substring[0] = '&';
5270     substring++;
5271   }
5272   memset(&si, 0, sizeof(si));
5273   si.cb = sizeof(si);
5274   memset(&pi, 0, sizeof(pi));
5275   BOOL rslt = CreateProcess(NULL,   // executable name - use command line
5276                             cmd_string,    // command line
5277                             NULL,   // process security attribute
5278                             NULL,   // thread security attribute
5279                             TRUE,   // inherits system handles
5280                             0,      // no creation flags
5281                             NULL,   // use parent's environment block
5282                             NULL,   // use parent's starting directory
5283                             &si,    // (in) startup information
5284                             &pi);   // (out) process information
5285 
5286   if (rslt) {
5287     // Wait until child process exits.
5288     WaitForSingleObject(pi.hProcess, INFINITE);
5289 

5290     GetExitCodeProcess(pi.hProcess, &exit_code);
5291 
5292     // Close process and thread handles.
5293     CloseHandle(pi.hProcess);
5294     CloseHandle(pi.hThread);


5295   } else {
5296     exit_code = -1;
5297   }
5298 
5299   FREE_C_HEAP_ARRAY(char, cmd_string);
5300   return (int)exit_code;
5301 }
5302 
5303 bool os::find(address addr, outputStream* st) {
5304   int offset = -1;
5305   bool result = false;
5306   char buf[256];
5307   if (os::dll_address_to_library_name(addr, buf, sizeof(buf), &offset)) {
5308     st->print(PTR_FORMAT " ", addr);
5309     if (strlen(buf) < sizeof(buf) - 1) {
5310       char* p = strrchr(buf, '\\');
5311       if (p) {
5312         st->print("%s", p + 1);
5313       } else {
5314         st->print("%s", buf);
5315       }
5316     } else {
5317         // The library name is probably truncated. Let's omit the library name.
5318         // See also JDK-8147512.
5319     }
5320     if (os::dll_address_to_function_name(addr, buf, sizeof(buf), &offset)) {


< prev index next >