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';
4014 // Print something if NX is enabled (win32 on AMD64)
4015 NOT_PRODUCT(if (PrintMiscellaneous && Verbose) nx_check_protection());
4016 #endif
4017
4018 // initialize thread priority policy
4019 prio_init();
4020
4021 if (UseNUMA && !ForceNUMA) {
4022 UseNUMA = false; // We don't fully support this yet
4023 }
4024
4025 if (UseNUMAInterleaving) {
4026 // first check whether this Windows OS supports VirtualAllocExNuma, if not ignore this flag
4027 bool success = numa_interleaving_init();
4028 if (!success) UseNUMAInterleaving = false;
4029 }
4030
4031 if (initSock() != JNI_OK) {
4032 return JNI_ERR;
4033 }
4034
4035 return JNI_OK;
4036 }
4037
4038 // Mark the polling page as unreadable
4039 void os::make_polling_page_unreadable(void) {
4040 DWORD old_status;
4041 if (!VirtualProtect((char *)_polling_page, os::vm_page_size(),
4042 PAGE_NOACCESS, &old_status)) {
4043 fatal("Could not disable polling page");
4044 }
4045 }
4046
4047 // Mark the polling page as readable
4048 void os::make_polling_page_readable(void) {
4049 DWORD old_status;
4050 if (!VirtualProtect((char *)_polling_page, os::vm_page_size(),
4051 PAGE_READONLY, &old_status)) {
4052 fatal("Could not enable polling page");
4053 }
|
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 // Recalculate pdb search path if a DLL was loaded successfully.
1326 SymbolEngine::recalc_search_path();
1327 return result;
1328 }
1329
1330 DWORD errcode = GetLastError();
1331 if (errcode == ERROR_MOD_NOT_FOUND) {
1332 strncpy(ebuf, "Can't find dependent libraries", ebuflen - 1);
1333 ebuf[ebuflen - 1] = '\0';
1334 return NULL;
1335 }
1336
1337 // Parsing dll below
1338 // If we can read dll-info and find that dll was built
1339 // for an architecture other than Hotspot is running in
1340 // - then print to buffer "DLL was built for a different architecture"
1341 // else call os::lasterror to obtain system error message
1342
1343 // Read system error message into ebuf
1344 // It may or may not be overwritten below (in the for loop and just above)
1345 lasterror(ebuf, (size_t) ebuflen);
1346 ebuf[ebuflen - 1] = '\0';
4019 // Print something if NX is enabled (win32 on AMD64)
4020 NOT_PRODUCT(if (PrintMiscellaneous && Verbose) nx_check_protection());
4021 #endif
4022
4023 // initialize thread priority policy
4024 prio_init();
4025
4026 if (UseNUMA && !ForceNUMA) {
4027 UseNUMA = false; // We don't fully support this yet
4028 }
4029
4030 if (UseNUMAInterleaving) {
4031 // first check whether this Windows OS supports VirtualAllocExNuma, if not ignore this flag
4032 bool success = numa_interleaving_init();
4033 if (!success) UseNUMAInterleaving = false;
4034 }
4035
4036 if (initSock() != JNI_OK) {
4037 return JNI_ERR;
4038 }
4039
4040 SymbolEngine::recalc_search_path();
4041
4042 return JNI_OK;
4043 }
4044
4045 // Mark the polling page as unreadable
4046 void os::make_polling_page_unreadable(void) {
4047 DWORD old_status;
4048 if (!VirtualProtect((char *)_polling_page, os::vm_page_size(),
4049 PAGE_NOACCESS, &old_status)) {
4050 fatal("Could not disable polling page");
4051 }
4052 }
4053
4054 // Mark the polling page as readable
4055 void os::make_polling_page_readable(void) {
4056 DWORD old_status;
4057 if (!VirtualProtect((char *)_polling_page, os::vm_page_size(),
4058 PAGE_READONLY, &old_status)) {
4059 fatal("Could not enable polling page");
4060 }
|