< prev index next >

src/os/windows/vm/os_windows.cpp

Print this page




1652       lib_arch_str,running_arch_str);
1653   }
1654   else
1655   {
1656     // don't know what architecture this dll was build for
1657     ::_snprintf(ebuf, ebuflen-1,
1658       "Can't load this .dll (machine code=0x%x) on a %s-bit platform",
1659       lib_arch,running_arch_str);
1660   }
1661 
1662   return NULL;
1663 }
1664 
1665 
1666 void os::print_dll_info(outputStream *st) {
1667    int pid = os::current_process_id();
1668    st->print_cr("Dynamic libraries:");
1669    enumerate_modules(pid, _print_module, (void *)st);
1670 }
1671 












































1672 void os::print_os_info_brief(outputStream* st) {
1673   os::print_os_info(st);
1674 }
1675 
1676 void os::print_os_info(outputStream* st) {
1677   st->print("OS:");
1678 
1679   os::win32::print_windows_version(st);
1680 }
1681 
1682 void os::win32::print_windows_version(outputStream* st) {
1683   OSVERSIONINFOEX osvi;
1684   VS_FIXEDFILEINFO *file_info;
1685   TCHAR kernel32_path[MAX_PATH];
1686   UINT len, ret;
1687 
1688   // Use the GetVersionEx information to see if we're on a server or
1689   // workstation edition of Windows. Starting with Windows 8.1 we can't
1690   // trust the OS version information returned by this API.
1691   ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));


4335     oflags |= _O_EXCL;
4336   }
4337   return ::open(path, oflags, _S_IREAD | _S_IWRITE);
4338 }
4339 
4340 // return current position of file pointer
4341 jlong os::current_file_offset(int fd) {
4342   return (jlong)::_lseeki64(fd, (__int64)0L, SEEK_CUR);
4343 }
4344 
4345 // move file pointer to the specified offset
4346 jlong os::seek_to_file_offset(int fd, jlong offset) {
4347   return (jlong)::_lseeki64(fd, (__int64)offset, SEEK_SET);
4348 }
4349 
4350 
4351 jlong os::lseek(int fd, jlong offset, int whence) {
4352   return (jlong) ::_lseeki64(fd, offset, whence);
4353 }
4354 
















4355 // This method is a slightly reworked copy of JDK's sysNativePath
4356 // from src/windows/hpi/src/path_md.c
4357 
4358 /* Convert a pathname to native format.  On win32, this involves forcing all
4359    separators to be '\\' rather than '/' (both are legal inputs, but Win95
4360    sometimes rejects '/') and removing redundant separators.  The input path is
4361    assumed to have been converted into the character encoding used by the local
4362    system.  Because this might be a double-byte encoding, care is taken to
4363    treat double-byte lead characters correctly.
4364 
4365    This procedure modifies the given path in place, as the result is never
4366    longer than the original.  There is no error return; this operation always
4367    succeeds. */
4368 char * os::native_path(char *path) {
4369   char *src = path, *dst = path, *end = path;
4370   char *colon = NULL;           /* If a drive specifier is found, this will
4371                                         point to the colon following the drive
4372                                         letter */
4373 
4374   /* Assumption: '/', '\\', ':', and drive letters are never lead bytes */


4794   char filename[MAX_PATH];
4795   if (PauseAtStartupFile && PauseAtStartupFile[0]) {
4796     jio_snprintf(filename, MAX_PATH, PauseAtStartupFile);
4797   } else {
4798     jio_snprintf(filename, MAX_PATH, "./vm.paused.%d", current_process_id());
4799   }
4800 
4801   int fd = ::open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666);
4802   if (fd != -1) {
4803     struct stat buf;
4804     ::close(fd);
4805     while (::stat(filename, &buf) == 0) {
4806       Sleep(100);
4807     }
4808   } else {
4809     jio_fprintf(stderr,
4810       "Could not open pause file '%s', continuing immediately.\n", filename);
4811   }
4812 }
4813 
4814 os::WatcherThreadCrashProtection::WatcherThreadCrashProtection() {
4815   assert(Thread::current()->is_Watcher_thread(), "Must be WatcherThread");



4816 }
4817 
4818 /*
4819  * See the caveats for this class in os_windows.hpp
4820  * Protects the callback call so that raised OS EXCEPTIONS causes a jump back
4821  * into this method and returns false. If no OS EXCEPTION was raised, returns
4822  * true.
4823  * The callback is supposed to provide the method that should be protected.
4824  */
4825 bool os::WatcherThreadCrashProtection::call(os::CrashProtectionCallback& cb) {
4826   assert(Thread::current()->is_Watcher_thread(), "Only for WatcherThread");
4827   assert(!WatcherThread::watcher_thread()->has_crash_protection(),
4828       "crash_protection already set?");

4829 
4830   bool success = true;
4831   __try {
4832     WatcherThread::watcher_thread()->set_crash_protection(this);
4833     cb.call();
4834   } __except(EXCEPTION_EXECUTE_HANDLER) {
4835     // only for protection, nothing to do
4836     success = false;
4837   }
4838   WatcherThread::watcher_thread()->set_crash_protection(NULL);


4839   return success;
4840 }
4841 
4842 // An Event wraps a win32 "CreateEvent" kernel handle.
4843 //
4844 // We have a number of choices regarding "CreateEvent" win32 handle leakage:
4845 //
4846 // 1:  When a thread dies return the Event to the EventFreeList, clear the ParkHandle
4847 //     field, and call CloseHandle() on the win32 event handle.  Unpark() would
4848 //     need to be modified to tolerate finding a NULL (invalid) win32 event handle.
4849 //     In addition, an unpark() operation might fetch the handle field, but the
4850 //     event could recycle between the fetch and the SetEvent() operation.
4851 //     SetEvent() would either fail because the handle was invalid, or inadvertently work,
4852 //     as the win32 handle value had been recycled.  In an ideal world calling SetEvent()
4853 //     on an stale but recycled handle would be harmless, but in practice this might
4854 //     confuse other non-Sun code, so it's not a viable approach.
4855 //
4856 // 2:  Once a win32 event handle is associated with an Event, it remains associated
4857 //     with the Event.  The event handle is never closed.  This could be construed
4858 //     as handle leakage, but only up to the maximum # of threads that have been extant




1652       lib_arch_str,running_arch_str);
1653   }
1654   else
1655   {
1656     // don't know what architecture this dll was build for
1657     ::_snprintf(ebuf, ebuflen-1,
1658       "Can't load this .dll (machine code=0x%x) on a %s-bit platform",
1659       lib_arch,running_arch_str);
1660   }
1661 
1662   return NULL;
1663 }
1664 
1665 
1666 void os::print_dll_info(outputStream *st) {
1667    int pid = os::current_process_id();
1668    st->print_cr("Dynamic libraries:");
1669    enumerate_modules(pid, _print_module, (void *)st);
1670 }
1671 
1672 int os::get_loaded_modules_info(os::LoadedModulesCallbackFunc callback, void *param) {
1673   HANDLE   hProcess;
1674 
1675 # define MAX_NUM_MODULES 128
1676   HMODULE     modules[MAX_NUM_MODULES];
1677   static char filename[MAX_PATH];
1678   int         result = 0;
1679 
1680   int pid = os::current_process_id();
1681   hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,
1682                          FALSE, pid);
1683   if (hProcess == NULL) return 0;
1684 
1685   DWORD size_needed;
1686   if (!EnumProcessModules(hProcess, modules, sizeof(modules), &size_needed)) {
1687     CloseHandle(hProcess);
1688     return 0;
1689   }
1690 
1691   // number of modules that are currently loaded
1692   int num_modules = size_needed / sizeof(HMODULE);
1693 
1694   for (int i = 0; i < MIN2(num_modules, MAX_NUM_MODULES); i++) {
1695     // Get Full pathname:
1696     if (!GetModuleFileNameEx(hProcess, modules[i], filename, sizeof(filename))) {
1697       filename[0] = '\0';
1698     }
1699 
1700     MODULEINFO modinfo;
1701     if (!GetModuleInformation(hProcess, modules[i], &modinfo, sizeof(modinfo))) {
1702       modinfo.lpBaseOfDll = NULL;
1703       modinfo.SizeOfImage = 0;
1704     }
1705 
1706     // Invoke callback function
1707     result = callback(filename, (address)modinfo.lpBaseOfDll,
1708                       (address)((u8)modinfo.lpBaseOfDll + (u8)modinfo.SizeOfImage), param);
1709     if (result) break;
1710   }
1711 
1712   CloseHandle(hProcess);
1713   return result;
1714 }
1715 
1716 void os::print_os_info_brief(outputStream* st) {
1717   os::print_os_info(st);
1718 }
1719 
1720 void os::print_os_info(outputStream* st) {
1721   st->print("OS:");
1722 
1723   os::win32::print_windows_version(st);
1724 }
1725 
1726 void os::win32::print_windows_version(outputStream* st) {
1727   OSVERSIONINFOEX osvi;
1728   VS_FIXEDFILEINFO *file_info;
1729   TCHAR kernel32_path[MAX_PATH];
1730   UINT len, ret;
1731 
1732   // Use the GetVersionEx information to see if we're on a server or
1733   // workstation edition of Windows. Starting with Windows 8.1 we can't
1734   // trust the OS version information returned by this API.
1735   ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));


4379     oflags |= _O_EXCL;
4380   }
4381   return ::open(path, oflags, _S_IREAD | _S_IWRITE);
4382 }
4383 
4384 // return current position of file pointer
4385 jlong os::current_file_offset(int fd) {
4386   return (jlong)::_lseeki64(fd, (__int64)0L, SEEK_CUR);
4387 }
4388 
4389 // move file pointer to the specified offset
4390 jlong os::seek_to_file_offset(int fd, jlong offset) {
4391   return (jlong)::_lseeki64(fd, (__int64)offset, SEEK_SET);
4392 }
4393 
4394 
4395 jlong os::lseek(int fd, jlong offset, int whence) {
4396   return (jlong) ::_lseeki64(fd, offset, whence);
4397 }
4398 
4399 size_t os::read_at(int fd, void *buf, unsigned int nBytes, jlong offset) {
4400   OVERLAPPED ov;
4401   DWORD nread;
4402   BOOL result;
4403 
4404   ZeroMemory(&ov, sizeof(ov));
4405   ov.Offset = (DWORD)offset;
4406   ov.OffsetHigh = (DWORD)(offset >> 32);
4407 
4408   HANDLE h = (HANDLE)::_get_osfhandle(fd);
4409 
4410   result = ReadFile(h, (LPVOID)buf, nBytes, &nread, &ov);
4411 
4412   return result ? nread : 0;
4413 }
4414 
4415 // This method is a slightly reworked copy of JDK's sysNativePath
4416 // from src/windows/hpi/src/path_md.c
4417 
4418 /* Convert a pathname to native format.  On win32, this involves forcing all
4419    separators to be '\\' rather than '/' (both are legal inputs, but Win95
4420    sometimes rejects '/') and removing redundant separators.  The input path is
4421    assumed to have been converted into the character encoding used by the local
4422    system.  Because this might be a double-byte encoding, care is taken to
4423    treat double-byte lead characters correctly.
4424 
4425    This procedure modifies the given path in place, as the result is never
4426    longer than the original.  There is no error return; this operation always
4427    succeeds. */
4428 char * os::native_path(char *path) {
4429   char *src = path, *dst = path, *end = path;
4430   char *colon = NULL;           /* If a drive specifier is found, this will
4431                                         point to the colon following the drive
4432                                         letter */
4433 
4434   /* Assumption: '/', '\\', ':', and drive letters are never lead bytes */


4854   char filename[MAX_PATH];
4855   if (PauseAtStartupFile && PauseAtStartupFile[0]) {
4856     jio_snprintf(filename, MAX_PATH, PauseAtStartupFile);
4857   } else {
4858     jio_snprintf(filename, MAX_PATH, "./vm.paused.%d", current_process_id());
4859   }
4860 
4861   int fd = ::open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666);
4862   if (fd != -1) {
4863     struct stat buf;
4864     ::close(fd);
4865     while (::stat(filename, &buf) == 0) {
4866       Sleep(100);
4867     }
4868   } else {
4869     jio_fprintf(stderr,
4870       "Could not open pause file '%s', continuing immediately.\n", filename);
4871   }
4872 }
4873 
4874 Thread* os::ThreadCrashProtection::_protected_thread = NULL;
4875 os::ThreadCrashProtection* os::ThreadCrashProtection::_crash_protection = NULL;
4876 volatile intptr_t os::ThreadCrashProtection::_crash_mux = 0;
4877 
4878 os::ThreadCrashProtection::ThreadCrashProtection() {
4879 }
4880 
4881 // See the caveats for this class in os_windows.hpp
4882 // Protects the callback call so that raised OS EXCEPTIONS causes a jump back
4883 // into this method and returns false. If no OS EXCEPTION was raised, returns
4884 // true.
4885 // The callback is supposed to provide the method that should be protected.
4886 //
4887 bool os::ThreadCrashProtection::call(os::CrashProtectionCallback& cb) {
4888 
4889   Thread::muxAcquire(&_crash_mux, "CrashProtection");
4890 
4891   _protected_thread = ThreadLocalStorage::thread();
4892   assert(_protected_thread != NULL, "Cannot crash protect a NULL thread");
4893 
4894   bool success = true;
4895   __try {
4896     _crash_protection = this;
4897     cb.call();
4898   } __except(EXCEPTION_EXECUTE_HANDLER) {
4899     // only for protection, nothing to do
4900     success = false;
4901   }
4902   _crash_protection = NULL;
4903   _protected_thread = NULL;
4904   Thread::muxRelease(&_crash_mux);
4905   return success;
4906 }
4907 
4908 // An Event wraps a win32 "CreateEvent" kernel handle.
4909 //
4910 // We have a number of choices regarding "CreateEvent" win32 handle leakage:
4911 //
4912 // 1:  When a thread dies return the Event to the EventFreeList, clear the ParkHandle
4913 //     field, and call CloseHandle() on the win32 event handle.  Unpark() would
4914 //     need to be modified to tolerate finding a NULL (invalid) win32 event handle.
4915 //     In addition, an unpark() operation might fetch the handle field, but the
4916 //     event could recycle between the fetch and the SetEvent() operation.
4917 //     SetEvent() would either fail because the handle was invalid, or inadvertently work,
4918 //     as the win32 handle value had been recycled.  In an ideal world calling SetEvent()
4919 //     on an stale but recycled handle would be harmless, but in practice this might
4920 //     confuse other non-Sun code, so it's not a viable approach.
4921 //
4922 // 2:  Once a win32 event handle is associated with an Event, it remains associated
4923 //     with the Event.  The event handle is never closed.  This could be construed
4924 //     as handle leakage, but only up to the maximum # of threads that have been extant


< prev index next >