57 #include "runtime/osThread.hpp"
58 #include "runtime/perfMemory.hpp"
59 #include "runtime/sharedRuntime.hpp"
60 #include "runtime/statSampler.hpp"
61 #include "runtime/stubRoutines.hpp"
62 #include "runtime/thread.inline.hpp"
63 #include "runtime/threadCritical.hpp"
64 #include "runtime/timer.hpp"
65 #include "runtime/vm_version.hpp"
66 #include "semaphore_windows.hpp"
67 #include "services/attachListener.hpp"
68 #include "services/memTracker.hpp"
69 #include "services/runtimeService.hpp"
70 #include "utilities/align.hpp"
71 #include "utilities/decoder.hpp"
72 #include "utilities/defaultStream.hpp"
73 #include "utilities/events.hpp"
74 #include "utilities/growableArray.hpp"
75 #include "utilities/macros.hpp"
76 #include "utilities/vmError.hpp"
77 #include "windbghelp.hpp"
78
79
80 #ifdef _DEBUG
81 #include <crtdbg.h>
82 #endif
83
84
85 #include <windows.h>
86 #include <sys/types.h>
87 #include <sys/stat.h>
88 #include <sys/timeb.h>
89 #include <objidl.h>
90 #include <shlobj.h>
91
92 #include <malloc.h>
93 #include <signal.h>
94 #include <direct.h>
95 #include <errno.h>
96 #include <fcntl.h>
117 static FILETIME process_user_time;
118 static FILETIME process_kernel_time;
119
120 #ifdef _M_AMD64
121 #define __CPU__ amd64
122 #else
123 #define __CPU__ i486
124 #endif
125
126 // save DLL module handle, used by GetModuleFileName
127
128 HINSTANCE vm_lib_handle;
129
130 BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, LPVOID reserved) {
131 switch (reason) {
132 case DLL_PROCESS_ATTACH:
133 vm_lib_handle = hinst;
134 if (ForceTimeHighResolution) {
135 timeBeginPeriod(1L);
136 }
137 break;
138 case DLL_PROCESS_DETACH:
139 if (ForceTimeHighResolution) {
140 timeEndPeriod(1L);
141 }
142 break;
143 default:
144 break;
145 }
146 return true;
147 }
148
149 static inline double fileTimeAsDouble(FILETIME* time) {
150 const double high = (double) ((unsigned int) ~0);
151 const double split = 10000000.0;
152 double result = (time->dwLowDateTime / split) +
153 time->dwHighDateTime * (high/split);
154 return result;
155 }
156
1302 return (vm_lib_location[0] <= addr) && (addr < vm_lib_location[1]);
1303 }
1304
1305 // print module info; param is outputStream*
1306 static int _print_module(const char* fname, address base_address,
1307 address top_address, void* param) {
1308 if (!param) return -1;
1309
1310 outputStream* st = (outputStream*)param;
1311
1312 st->print(PTR_FORMAT " - " PTR_FORMAT " \t%s\n", base_address, top_address, fname);
1313 return 0;
1314 }
1315
1316 // Loads .dll/.so and
1317 // in case of error it checks if .dll/.so was built for the
1318 // same architecture as Hotspot is running on
1319 void * os::dll_load(const char *name, char *ebuf, int ebuflen) {
1320 void * result = LoadLibrary(name);
1321 if (result != NULL) {
1322 return result;
1323 }
1324
1325 DWORD errcode = GetLastError();
1326 if (errcode == ERROR_MOD_NOT_FOUND) {
1327 strncpy(ebuf, "Can't find dependent libraries", ebuflen - 1);
1328 ebuf[ebuflen - 1] = '\0';
1329 return NULL;
1330 }
1331
1332 // Parsing dll below
1333 // If we can read dll-info and find that dll was built
1334 // for an architecture other than Hotspot is running in
1335 // - then print to buffer "DLL was built for a different architecture"
1336 // else call os::lasterror to obtain system error message
1337
1338 // Read system error message into ebuf
1339 // It may or may not be overwritten below (in the for loop and just above)
1340 lasterror(ebuf, (size_t) ebuflen);
1341 ebuf[ebuflen - 1] = '\0';
4029 #ifndef _WIN64
4030 // Print something if NX is enabled (win32 on AMD64)
4031 NOT_PRODUCT(if (PrintMiscellaneous && Verbose) nx_check_protection());
4032 #endif
4033
4034 // initialize thread priority policy
4035 prio_init();
4036
4037 if (UseNUMA && !ForceNUMA) {
4038 UseNUMA = false; // We don't fully support this yet
4039 }
4040
4041 if (UseNUMAInterleaving) {
4042 // first check whether this Windows OS supports VirtualAllocExNuma, if not ignore this flag
4043 bool success = numa_interleaving_init();
4044 if (!success) UseNUMAInterleaving = false;
4045 }
4046
4047 if (initSock() != JNI_OK) {
4048 return JNI_ERR;
4049 }
4050
4051 return JNI_OK;
4052 }
4053
4054 // Mark the polling page as unreadable
4055 void os::make_polling_page_unreadable(void) {
4056 DWORD old_status;
4057 if (!VirtualProtect((char *)_polling_page, os::vm_page_size(),
4058 PAGE_NOACCESS, &old_status)) {
4059 fatal("Could not disable polling page");
4060 }
4061 }
4062
4063 // Mark the polling page as readable
4064 void os::make_polling_page_readable(void) {
4065 DWORD old_status;
4066 if (!VirtualProtect((char *)_polling_page, os::vm_page_size(),
4067 PAGE_READONLY, &old_status)) {
4068 fatal("Could not enable polling page");
|
57 #include "runtime/osThread.hpp"
58 #include "runtime/perfMemory.hpp"
59 #include "runtime/sharedRuntime.hpp"
60 #include "runtime/statSampler.hpp"
61 #include "runtime/stubRoutines.hpp"
62 #include "runtime/thread.inline.hpp"
63 #include "runtime/threadCritical.hpp"
64 #include "runtime/timer.hpp"
65 #include "runtime/vm_version.hpp"
66 #include "semaphore_windows.hpp"
67 #include "services/attachListener.hpp"
68 #include "services/memTracker.hpp"
69 #include "services/runtimeService.hpp"
70 #include "utilities/align.hpp"
71 #include "utilities/decoder.hpp"
72 #include "utilities/defaultStream.hpp"
73 #include "utilities/events.hpp"
74 #include "utilities/growableArray.hpp"
75 #include "utilities/macros.hpp"
76 #include "utilities/vmError.hpp"
77 #include "symbolengine.hpp"
78 #include "windbghelp.hpp"
79
80
81 #ifdef _DEBUG
82 #include <crtdbg.h>
83 #endif
84
85
86 #include <windows.h>
87 #include <sys/types.h>
88 #include <sys/stat.h>
89 #include <sys/timeb.h>
90 #include <objidl.h>
91 #include <shlobj.h>
92
93 #include <malloc.h>
94 #include <signal.h>
95 #include <direct.h>
96 #include <errno.h>
97 #include <fcntl.h>
118 static FILETIME process_user_time;
119 static FILETIME process_kernel_time;
120
121 #ifdef _M_AMD64
122 #define __CPU__ amd64
123 #else
124 #define __CPU__ i486
125 #endif
126
127 // save DLL module handle, used by GetModuleFileName
128
129 HINSTANCE vm_lib_handle;
130
131 BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, LPVOID reserved) {
132 switch (reason) {
133 case DLL_PROCESS_ATTACH:
134 vm_lib_handle = hinst;
135 if (ForceTimeHighResolution) {
136 timeBeginPeriod(1L);
137 }
138 WindowsDbgHelp::pre_initialize();
139 SymbolEngine::pre_initialize();
140 break;
141 case DLL_PROCESS_DETACH:
142 if (ForceTimeHighResolution) {
143 timeEndPeriod(1L);
144 }
145 break;
146 default:
147 break;
148 }
149 return true;
150 }
151
152 static inline double fileTimeAsDouble(FILETIME* time) {
153 const double high = (double) ((unsigned int) ~0);
154 const double split = 10000000.0;
155 double result = (time->dwLowDateTime / split) +
156 time->dwHighDateTime * (high/split);
157 return result;
158 }
159
1305 return (vm_lib_location[0] <= addr) && (addr < vm_lib_location[1]);
1306 }
1307
1308 // print module info; param is outputStream*
1309 static int _print_module(const char* fname, address base_address,
1310 address top_address, void* param) {
1311 if (!param) return -1;
1312
1313 outputStream* st = (outputStream*)param;
1314
1315 st->print(PTR_FORMAT " - " PTR_FORMAT " \t%s\n", base_address, top_address, fname);
1316 return 0;
1317 }
1318
1319 // Loads .dll/.so and
1320 // in case of error it checks if .dll/.so was built for the
1321 // same architecture as Hotspot is running on
1322 void * os::dll_load(const char *name, char *ebuf, int ebuflen) {
1323 void * result = LoadLibrary(name);
1324 if (result != NULL) {
1325 if (InitializeDbgHelpEarly) {
1326 // Recalculate pdb search path if a DLL was loaded successfully.
1327 SymbolEngine::recalc_search_path();
1328 }
1329 return result;
1330 }
1331
1332 DWORD errcode = GetLastError();
1333 if (errcode == ERROR_MOD_NOT_FOUND) {
1334 strncpy(ebuf, "Can't find dependent libraries", ebuflen - 1);
1335 ebuf[ebuflen - 1] = '\0';
1336 return NULL;
1337 }
1338
1339 // Parsing dll below
1340 // If we can read dll-info and find that dll was built
1341 // for an architecture other than Hotspot is running in
1342 // - then print to buffer "DLL was built for a different architecture"
1343 // else call os::lasterror to obtain system error message
1344
1345 // Read system error message into ebuf
1346 // It may or may not be overwritten below (in the for loop and just above)
1347 lasterror(ebuf, (size_t) ebuflen);
1348 ebuf[ebuflen - 1] = '\0';
4036 #ifndef _WIN64
4037 // Print something if NX is enabled (win32 on AMD64)
4038 NOT_PRODUCT(if (PrintMiscellaneous && Verbose) nx_check_protection());
4039 #endif
4040
4041 // initialize thread priority policy
4042 prio_init();
4043
4044 if (UseNUMA && !ForceNUMA) {
4045 UseNUMA = false; // We don't fully support this yet
4046 }
4047
4048 if (UseNUMAInterleaving) {
4049 // first check whether this Windows OS supports VirtualAllocExNuma, if not ignore this flag
4050 bool success = numa_interleaving_init();
4051 if (!success) UseNUMAInterleaving = false;
4052 }
4053
4054 if (initSock() != JNI_OK) {
4055 return JNI_ERR;
4056 }
4057
4058 if (InitializeDbgHelpEarly) {
4059 SymbolEngine::recalc_search_path();
4060 }
4061
4062 return JNI_OK;
4063 }
4064
4065 // Mark the polling page as unreadable
4066 void os::make_polling_page_unreadable(void) {
4067 DWORD old_status;
4068 if (!VirtualProtect((char *)_polling_page, os::vm_page_size(),
4069 PAGE_NOACCESS, &old_status)) {
4070 fatal("Could not disable polling page");
4071 }
4072 }
4073
4074 // Mark the polling page as readable
4075 void os::make_polling_page_readable(void) {
4076 DWORD old_status;
4077 if (!VirtualProtect((char *)_polling_page, os::vm_page_size(),
4078 PAGE_READONLY, &old_status)) {
4079 fatal("Could not enable polling page");
|