Mercurial > hg > truffle
annotate src/os/windows/vm/os_windows.cpp @ 6720:b62581e29024
disabled scaladacapo apparat benchmark
author | Lukas Stadler <lukas.stadler@jku.at> |
---|---|
date | Thu, 15 Nov 2012 17:18:16 +0100 |
parents | 957c266d8bc5 |
children | e522a00b91aa |
rev | line source |
---|---|
0 | 1 /* |
4872
aa3d708d67c4
7141200: log some interesting information in ring buffers for crashes
never
parents:
4803
diff
changeset
|
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
0 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1490
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1490
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1490
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
2306
5584e20db481
7023323: Build failure on VS2003: IsDebuggerPresent not found
sla
parents:
2302
diff
changeset
|
25 // Must be at least Windows 2000 or XP to use VectoredExceptions and IsDebuggerPresent |
0 | 26 #define _WIN32_WINNT 0x500 |
27 | |
1972 | 28 // no precompiled headers |
29 #include "classfile/classLoader.hpp" | |
30 #include "classfile/systemDictionary.hpp" | |
31 #include "classfile/vmSymbols.hpp" | |
32 #include "code/icBuffer.hpp" | |
33 #include "code/vtableStubs.hpp" | |
34 #include "compiler/compileBroker.hpp" | |
35 #include "interpreter/interpreter.hpp" | |
36 #include "jvm_windows.h" | |
37 #include "memory/allocation.inline.hpp" | |
38 #include "memory/filemap.hpp" | |
39 #include "mutex_windows.inline.hpp" | |
40 #include "oops/oop.inline.hpp" | |
41 #include "os_share_windows.hpp" | |
42 #include "prims/jniFastGetField.hpp" | |
43 #include "prims/jvm.h" | |
44 #include "prims/jvm_misc.hpp" | |
45 #include "runtime/arguments.hpp" | |
46 #include "runtime/extendedPC.hpp" | |
47 #include "runtime/globals.hpp" | |
48 #include "runtime/interfaceSupport.hpp" | |
49 #include "runtime/java.hpp" | |
50 #include "runtime/javaCalls.hpp" | |
51 #include "runtime/mutexLocker.hpp" | |
52 #include "runtime/objectMonitor.hpp" | |
53 #include "runtime/osThread.hpp" | |
54 #include "runtime/perfMemory.hpp" | |
55 #include "runtime/sharedRuntime.hpp" | |
56 #include "runtime/statSampler.hpp" | |
57 #include "runtime/stubRoutines.hpp" | |
58 #include "runtime/threadCritical.hpp" | |
59 #include "runtime/timer.hpp" | |
60 #include "services/attachListener.hpp" | |
61 #include "services/runtimeService.hpp" | |
62 #include "thread_windows.inline.hpp" | |
2022
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
1972
diff
changeset
|
63 #include "utilities/decoder.hpp" |
1972 | 64 #include "utilities/defaultStream.hpp" |
65 #include "utilities/events.hpp" | |
66 #include "utilities/growableArray.hpp" | |
67 #include "utilities/vmError.hpp" | |
68 #ifdef TARGET_ARCH_x86 | |
69 # include "assembler_x86.inline.hpp" | |
70 # include "nativeInst_x86.hpp" | |
71 #endif | |
72 #ifdef COMPILER1 | |
73 #include "c1/c1_Runtime1.hpp" | |
74 #endif | |
75 #ifdef COMPILER2 | |
76 #include "opto/runtime.hpp" | |
77 #endif | |
0 | 78 |
79 #ifdef _DEBUG | |
80 #include <crtdbg.h> | |
81 #endif | |
82 | |
83 | |
84 #include <windows.h> | |
85 #include <sys/types.h> | |
86 #include <sys/stat.h> | |
87 #include <sys/timeb.h> | |
88 #include <objidl.h> | |
89 #include <shlobj.h> | |
90 | |
91 #include <malloc.h> | |
92 #include <signal.h> | |
93 #include <direct.h> | |
94 #include <errno.h> | |
95 #include <fcntl.h> | |
96 #include <io.h> | |
97 #include <process.h> // For _beginthreadex(), _endthreadex() | |
98 #include <imagehlp.h> // For os::dll_address_to_function_name | |
99 /* for enumerating dll libraries */ | |
100 #include <vdmdbg.h> | |
101 | |
102 // for timer info max values which include all bits | |
103 #define ALL_64_BITS CONST64(0xFFFFFFFFFFFFFFFF) | |
104 | |
105 // For DLL loading/load error detection | |
106 // Values of PE COFF | |
107 #define IMAGE_FILE_PTR_TO_SIGNATURE 0x3c | |
108 #define IMAGE_FILE_SIGNATURE_LENGTH 4 | |
109 | |
110 static HANDLE main_process; | |
111 static HANDLE main_thread; | |
112 static int main_thread_id; | |
113 | |
114 static FILETIME process_creation_time; | |
115 static FILETIME process_exit_time; | |
116 static FILETIME process_user_time; | |
117 static FILETIME process_kernel_time; | |
118 | |
119 #ifdef _WIN64 | |
120 PVOID topLevelVectoredExceptionHandler = NULL; | |
121 #endif | |
122 | |
123 #ifdef _M_IA64 | |
124 #define __CPU__ ia64 | |
125 #elif _M_AMD64 | |
126 #define __CPU__ amd64 | |
127 #else | |
128 #define __CPU__ i486 | |
129 #endif | |
130 | |
131 // save DLL module handle, used by GetModuleFileName | |
132 | |
133 HINSTANCE vm_lib_handle; | |
134 | |
135 BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, LPVOID reserved) { | |
136 switch (reason) { | |
137 case DLL_PROCESS_ATTACH: | |
138 vm_lib_handle = hinst; | |
139 if(ForceTimeHighResolution) | |
140 timeBeginPeriod(1L); | |
141 break; | |
142 case DLL_PROCESS_DETACH: | |
143 if(ForceTimeHighResolution) | |
144 timeEndPeriod(1L); | |
145 #ifdef _WIN64 | |
146 if (topLevelVectoredExceptionHandler != NULL) { | |
147 RemoveVectoredExceptionHandler(topLevelVectoredExceptionHandler); | |
148 topLevelVectoredExceptionHandler = NULL; | |
149 } | |
150 #endif | |
151 break; | |
152 default: | |
153 break; | |
154 } | |
155 return true; | |
156 } | |
157 | |
158 static inline double fileTimeAsDouble(FILETIME* time) { | |
159 const double high = (double) ((unsigned int) ~0); | |
160 const double split = 10000000.0; | |
161 double result = (time->dwLowDateTime / split) + | |
162 time->dwHighDateTime * (high/split); | |
163 return result; | |
164 } | |
165 | |
166 // Implementation of os | |
167 | |
168 bool os::getenv(const char* name, char* buffer, int len) { | |
169 int result = GetEnvironmentVariable(name, buffer, len); | |
170 return result > 0 && result < len; | |
171 } | |
172 | |
173 | |
174 // No setuid programs under Windows. | |
175 bool os::have_special_privileges() { | |
176 return false; | |
177 } | |
178 | |
179 | |
180 // This method is a periodic task to check for misbehaving JNI applications | |
181 // under CheckJNI, we can add any periodic checks here. | |
182 // For Windows at the moment does nothing | |
183 void os::run_periodic_checks() { | |
184 return; | |
185 } | |
186 | |
187 #ifndef _WIN64 | |
1214
0fc941df6fb7
6918421: 1/1 in-process JVM now ignores preset Windows unhandled exception filter
dcubed
parents:
477
diff
changeset
|
188 // previous UnhandledExceptionFilter, if there is one |
0fc941df6fb7
6918421: 1/1 in-process JVM now ignores preset Windows unhandled exception filter
dcubed
parents:
477
diff
changeset
|
189 static LPTOP_LEVEL_EXCEPTION_FILTER prev_uef_handler = NULL; |
0fc941df6fb7
6918421: 1/1 in-process JVM now ignores preset Windows unhandled exception filter
dcubed
parents:
477
diff
changeset
|
190 |
0 | 191 LONG WINAPI Handle_FLT_Exception(struct _EXCEPTION_POINTERS* exceptionInfo); |
192 #endif | |
193 void os::init_system_properties_values() { | |
194 /* sysclasspath, java_home, dll_dir */ | |
195 { | |
196 char *home_path; | |
197 char *dll_path; | |
198 char *pslash; | |
199 char *bin = "\\bin"; | |
200 char home_dir[MAX_PATH]; | |
201 | |
202 if (!getenv("_ALT_JAVA_HOME_DIR", home_dir, MAX_PATH)) { | |
203 os::jvm_path(home_dir, sizeof(home_dir)); | |
204 // Found the full path to jvm[_g].dll. | |
205 // Now cut the path to <java_home>/jre if we can. | |
206 *(strrchr(home_dir, '\\')) = '\0'; /* get rid of \jvm.dll */ | |
207 pslash = strrchr(home_dir, '\\'); | |
208 if (pslash != NULL) { | |
209 *pslash = '\0'; /* get rid of \{client|server} */ | |
210 pslash = strrchr(home_dir, '\\'); | |
211 if (pslash != NULL) | |
212 *pslash = '\0'; /* get rid of \bin */ | |
213 } | |
214 } | |
215 | |
6197 | 216 home_path = NEW_C_HEAP_ARRAY(char, strlen(home_dir) + 1, mtInternal); |
0 | 217 if (home_path == NULL) |
218 return; | |
219 strcpy(home_path, home_dir); | |
220 Arguments::set_java_home(home_path); | |
221 | |
6197 | 222 dll_path = NEW_C_HEAP_ARRAY(char, strlen(home_dir) + strlen(bin) + 1, mtInternal); |
0 | 223 if (dll_path == NULL) |
224 return; | |
225 strcpy(dll_path, home_dir); | |
226 strcat(dll_path, bin); | |
227 Arguments::set_dll_dir(dll_path); | |
228 | |
229 if (!set_boot_path('\\', ';')) | |
230 return; | |
231 } | |
232 | |
233 /* library_path */ | |
234 #define EXT_DIR "\\lib\\ext" | |
235 #define BIN_DIR "\\bin" | |
236 #define PACKAGE_DIR "\\Sun\\Java" | |
237 { | |
238 /* Win32 library search order (See the documentation for LoadLibrary): | |
239 * | |
240 * 1. The directory from which application is loaded. | |
3833
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
241 * 2. The system wide Java Extensions directory (Java only) |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
242 * 3. System directory (GetSystemDirectory) |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
243 * 4. Windows directory (GetWindowsDirectory) |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
244 * 5. The PATH environment variable |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
245 * 6. The current directory |
0 | 246 */ |
247 | |
248 char *library_path; | |
249 char tmp[MAX_PATH]; | |
250 char *path_str = ::getenv("PATH"); | |
251 | |
252 library_path = NEW_C_HEAP_ARRAY(char, MAX_PATH * 5 + sizeof(PACKAGE_DIR) + | |
6197 | 253 sizeof(BIN_DIR) + (path_str ? strlen(path_str) : 0) + 10, mtInternal); |
0 | 254 |
255 library_path[0] = '\0'; | |
256 | |
257 GetModuleFileName(NULL, tmp, sizeof(tmp)); | |
258 *(strrchr(tmp, '\\')) = '\0'; | |
259 strcat(library_path, tmp); | |
260 | |
261 GetWindowsDirectory(tmp, sizeof(tmp)); | |
262 strcat(library_path, ";"); | |
263 strcat(library_path, tmp); | |
264 strcat(library_path, PACKAGE_DIR BIN_DIR); | |
265 | |
266 GetSystemDirectory(tmp, sizeof(tmp)); | |
267 strcat(library_path, ";"); | |
268 strcat(library_path, tmp); | |
269 | |
270 GetWindowsDirectory(tmp, sizeof(tmp)); | |
271 strcat(library_path, ";"); | |
272 strcat(library_path, tmp); | |
273 | |
274 if (path_str) { | |
275 strcat(library_path, ";"); | |
276 strcat(library_path, path_str); | |
277 } | |
278 | |
3833
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
279 strcat(library_path, ";."); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
280 |
0 | 281 Arguments::set_library_path(library_path); |
6197 | 282 FREE_C_HEAP_ARRAY(char, library_path, mtInternal); |
0 | 283 } |
284 | |
285 /* Default extensions directory */ | |
286 { | |
287 char path[MAX_PATH]; | |
288 char buf[2 * MAX_PATH + 2 * sizeof(EXT_DIR) + sizeof(PACKAGE_DIR) + 1]; | |
289 GetWindowsDirectory(path, MAX_PATH); | |
290 sprintf(buf, "%s%s;%s%s%s", Arguments::get_java_home(), EXT_DIR, | |
291 path, PACKAGE_DIR, EXT_DIR); | |
292 Arguments::set_ext_dirs(buf); | |
293 } | |
294 #undef EXT_DIR | |
295 #undef BIN_DIR | |
296 #undef PACKAGE_DIR | |
297 | |
298 /* Default endorsed standards directory. */ | |
299 { | |
300 #define ENDORSED_DIR "\\lib\\endorsed" | |
301 size_t len = strlen(Arguments::get_java_home()) + sizeof(ENDORSED_DIR); | |
6197 | 302 char * buf = NEW_C_HEAP_ARRAY(char, len, mtInternal); |
0 | 303 sprintf(buf, "%s%s", Arguments::get_java_home(), ENDORSED_DIR); |
304 Arguments::set_endorsed_dirs(buf); | |
305 #undef ENDORSED_DIR | |
306 } | |
307 | |
308 #ifndef _WIN64 | |
1214
0fc941df6fb7
6918421: 1/1 in-process JVM now ignores preset Windows unhandled exception filter
dcubed
parents:
477
diff
changeset
|
309 // set our UnhandledExceptionFilter and save any previous one |
0fc941df6fb7
6918421: 1/1 in-process JVM now ignores preset Windows unhandled exception filter
dcubed
parents:
477
diff
changeset
|
310 prev_uef_handler = SetUnhandledExceptionFilter(Handle_FLT_Exception); |
0 | 311 #endif |
312 | |
313 // Done | |
314 return; | |
315 } | |
316 | |
317 void os::breakpoint() { | |
318 DebugBreak(); | |
319 } | |
320 | |
321 // Invoked from the BREAKPOINT Macro | |
322 extern "C" void breakpoint() { | |
323 os::breakpoint(); | |
324 } | |
325 | |
6197 | 326 /* |
327 * RtlCaptureStackBackTrace Windows API may not exist prior to Windows XP. | |
328 * So far, this method is only used by Native Memory Tracking, which is | |
329 * only supported on Windows XP or later. | |
330 */ | |
331 address os::get_caller_pc(int n) { | |
332 #ifdef _NMT_NOINLINE_ | |
333 n ++; | |
334 #endif | |
335 address pc; | |
336 if (os::Kernel32Dll::RtlCaptureStackBackTrace(n + 1, 1, (PVOID*)&pc, NULL) == 1) { | |
337 return pc; | |
338 } | |
339 return NULL; | |
340 } | |
341 | |
342 | |
0 | 343 // os::current_stack_base() |
344 // | |
345 // Returns the base of the stack, which is the stack's | |
346 // starting address. This function must be called | |
347 // while running on the stack of the thread being queried. | |
348 | |
349 address os::current_stack_base() { | |
350 MEMORY_BASIC_INFORMATION minfo; | |
351 address stack_bottom; | |
352 size_t stack_size; | |
353 | |
354 VirtualQuery(&minfo, &minfo, sizeof(minfo)); | |
355 stack_bottom = (address)minfo.AllocationBase; | |
356 stack_size = minfo.RegionSize; | |
357 | |
358 // Add up the sizes of all the regions with the same | |
359 // AllocationBase. | |
360 while( 1 ) | |
361 { | |
362 VirtualQuery(stack_bottom+stack_size, &minfo, sizeof(minfo)); | |
363 if ( stack_bottom == (address)minfo.AllocationBase ) | |
364 stack_size += minfo.RegionSize; | |
365 else | |
366 break; | |
367 } | |
368 | |
369 #ifdef _M_IA64 | |
370 // IA64 has memory and register stacks | |
371 stack_size = stack_size / 2; | |
372 #endif | |
373 return stack_bottom + stack_size; | |
374 } | |
375 | |
376 size_t os::current_stack_size() { | |
377 size_t sz; | |
378 MEMORY_BASIC_INFORMATION minfo; | |
379 VirtualQuery(&minfo, &minfo, sizeof(minfo)); | |
380 sz = (size_t)os::current_stack_base() - (size_t)minfo.AllocationBase; | |
381 return sz; | |
382 } | |
383 | |
548
773234c55e8c
6800586: -XX:+PrintGCDateStamps is using mt-unsafe localtime function
ysr
parents:
477
diff
changeset
|
384 struct tm* os::localtime_pd(const time_t* clock, struct tm* res) { |
773234c55e8c
6800586: -XX:+PrintGCDateStamps is using mt-unsafe localtime function
ysr
parents:
477
diff
changeset
|
385 const struct tm* time_struct_ptr = localtime(clock); |
773234c55e8c
6800586: -XX:+PrintGCDateStamps is using mt-unsafe localtime function
ysr
parents:
477
diff
changeset
|
386 if (time_struct_ptr != NULL) { |
773234c55e8c
6800586: -XX:+PrintGCDateStamps is using mt-unsafe localtime function
ysr
parents:
477
diff
changeset
|
387 *res = *time_struct_ptr; |
773234c55e8c
6800586: -XX:+PrintGCDateStamps is using mt-unsafe localtime function
ysr
parents:
477
diff
changeset
|
388 return res; |
773234c55e8c
6800586: -XX:+PrintGCDateStamps is using mt-unsafe localtime function
ysr
parents:
477
diff
changeset
|
389 } |
773234c55e8c
6800586: -XX:+PrintGCDateStamps is using mt-unsafe localtime function
ysr
parents:
477
diff
changeset
|
390 return NULL; |
773234c55e8c
6800586: -XX:+PrintGCDateStamps is using mt-unsafe localtime function
ysr
parents:
477
diff
changeset
|
391 } |
0 | 392 |
393 LONG WINAPI topLevelExceptionFilter(struct _EXCEPTION_POINTERS* exceptionInfo); | |
394 | |
395 // Thread start routine for all new Java threads | |
396 static unsigned __stdcall java_start(Thread* thread) { | |
397 // Try to randomize the cache line index of hot stack frames. | |
398 // This helps when threads of the same stack traces evict each other's | |
399 // cache lines. The threads can be either from the same JVM instance, or | |
400 // from different JVM instances. The benefit is especially true for | |
401 // processors with hyperthreading technology. | |
402 static int counter = 0; | |
403 int pid = os::current_process_id(); | |
404 _alloca(((pid ^ counter++) & 7) * 128); | |
405 | |
406 OSThread* osthr = thread->osthread(); | |
407 assert(osthr->get_state() == RUNNABLE, "invalid os thread state"); | |
408 | |
409 if (UseNUMA) { | |
410 int lgrp_id = os::numa_get_group_id(); | |
411 if (lgrp_id != -1) { | |
412 thread->set_lgrp_id(lgrp_id); | |
413 } | |
414 } | |
415 | |
416 | |
417 if (UseVectoredExceptions) { | |
418 // If we are using vectored exception we don't need to set a SEH | |
419 thread->run(); | |
420 } | |
421 else { | |
422 // Install a win32 structured exception handler around every thread created | |
423 // by VM, so VM can genrate error dump when an exception occurred in non- | |
424 // Java thread (e.g. VM thread). | |
425 __try { | |
426 thread->run(); | |
427 } __except(topLevelExceptionFilter( | |
428 (_EXCEPTION_POINTERS*)_exception_info())) { | |
429 // Nothing to do. | |
430 } | |
431 } | |
432 | |
433 // One less thread is executing | |
434 // When the VMThread gets here, the main thread may have already exited | |
435 // which frees the CodeHeap containing the Atomic::add code | |
436 if (thread != VMThread::vm_thread() && VMThread::vm_thread() != NULL) { | |
437 Atomic::dec_ptr((intptr_t*)&os::win32::_os_thread_count); | |
438 } | |
439 | |
440 return 0; | |
441 } | |
442 | |
443 static OSThread* create_os_thread(Thread* thread, HANDLE thread_handle, int thread_id) { | |
444 // Allocate the OSThread object | |
445 OSThread* osthread = new OSThread(NULL, NULL); | |
446 if (osthread == NULL) return NULL; | |
447 | |
448 // Initialize support for Java interrupts | |
449 HANDLE interrupt_event = CreateEvent(NULL, true, false, NULL); | |
450 if (interrupt_event == NULL) { | |
451 delete osthread; | |
452 return NULL; | |
453 } | |
454 osthread->set_interrupt_event(interrupt_event); | |
455 | |
456 // Store info on the Win32 thread into the OSThread | |
457 osthread->set_thread_handle(thread_handle); | |
458 osthread->set_thread_id(thread_id); | |
459 | |
460 if (UseNUMA) { | |
461 int lgrp_id = os::numa_get_group_id(); | |
462 if (lgrp_id != -1) { | |
463 thread->set_lgrp_id(lgrp_id); | |
464 } | |
465 } | |
466 | |
467 // Initial thread state is INITIALIZED, not SUSPENDED | |
468 osthread->set_state(INITIALIZED); | |
469 | |
470 return osthread; | |
471 } | |
472 | |
473 | |
474 bool os::create_attached_thread(JavaThread* thread) { | |
475 #ifdef ASSERT | |
476 thread->verify_not_published(); | |
477 #endif | |
478 HANDLE thread_h; | |
479 if (!DuplicateHandle(main_process, GetCurrentThread(), GetCurrentProcess(), | |
480 &thread_h, THREAD_ALL_ACCESS, false, 0)) { | |
481 fatal("DuplicateHandle failed\n"); | |
482 } | |
483 OSThread* osthread = create_os_thread(thread, thread_h, | |
484 (int)current_thread_id()); | |
485 if (osthread == NULL) { | |
486 return false; | |
487 } | |
488 | |
489 // Initial thread state is RUNNABLE | |
490 osthread->set_state(RUNNABLE); | |
491 | |
492 thread->set_osthread(osthread); | |
493 return true; | |
494 } | |
495 | |
496 bool os::create_main_thread(JavaThread* thread) { | |
497 #ifdef ASSERT | |
498 thread->verify_not_published(); | |
499 #endif | |
500 if (_starting_thread == NULL) { | |
501 _starting_thread = create_os_thread(thread, main_thread, main_thread_id); | |
502 if (_starting_thread == NULL) { | |
503 return false; | |
504 } | |
505 } | |
506 | |
507 // The primordial thread is runnable from the start) | |
508 _starting_thread->set_state(RUNNABLE); | |
509 | |
510 thread->set_osthread(_starting_thread); | |
511 return true; | |
512 } | |
513 | |
514 // Allocate and initialize a new OSThread | |
515 bool os::create_thread(Thread* thread, ThreadType thr_type, size_t stack_size) { | |
516 unsigned thread_id; | |
517 | |
518 // Allocate the OSThread object | |
519 OSThread* osthread = new OSThread(NULL, NULL); | |
520 if (osthread == NULL) { | |
521 return false; | |
522 } | |
523 | |
524 // Initialize support for Java interrupts | |
525 HANDLE interrupt_event = CreateEvent(NULL, true, false, NULL); | |
526 if (interrupt_event == NULL) { | |
527 delete osthread; | |
528 return NULL; | |
529 } | |
530 osthread->set_interrupt_event(interrupt_event); | |
531 osthread->set_interrupted(false); | |
532 | |
533 thread->set_osthread(osthread); | |
534 | |
535 if (stack_size == 0) { | |
536 switch (thr_type) { | |
537 case os::java_thread: | |
538 // Java threads use ThreadStackSize which default value can be changed with the flag -Xss | |
539 if (JavaThread::stack_size_at_create() > 0) | |
540 stack_size = JavaThread::stack_size_at_create(); | |
541 break; | |
542 case os::compiler_thread: | |
543 if (CompilerThreadStackSize > 0) { | |
544 stack_size = (size_t)(CompilerThreadStackSize * K); | |
545 break; | |
546 } // else fall through: | |
547 // use VMThreadStackSize if CompilerThreadStackSize is not defined | |
548 case os::vm_thread: | |
549 case os::pgc_thread: | |
550 case os::cgc_thread: | |
551 case os::watcher_thread: | |
552 if (VMThreadStackSize > 0) stack_size = (size_t)(VMThreadStackSize * K); | |
553 break; | |
554 } | |
555 } | |
556 | |
557 // Create the Win32 thread | |
558 // | |
559 // Contrary to what MSDN document says, "stack_size" in _beginthreadex() | |
560 // does not specify stack size. Instead, it specifies the size of | |
561 // initially committed space. The stack size is determined by | |
562 // PE header in the executable. If the committed "stack_size" is larger | |
563 // than default value in the PE header, the stack is rounded up to the | |
564 // nearest multiple of 1MB. For example if the launcher has default | |
565 // stack size of 320k, specifying any size less than 320k does not | |
566 // affect the actual stack size at all, it only affects the initial | |
567 // commitment. On the other hand, specifying 'stack_size' larger than | |
568 // default value may cause significant increase in memory usage, because | |
569 // not only the stack space will be rounded up to MB, but also the | |
570 // entire space is committed upfront. | |
571 // | |
572 // Finally Windows XP added a new flag 'STACK_SIZE_PARAM_IS_A_RESERVATION' | |
573 // for CreateThread() that can treat 'stack_size' as stack size. However we | |
574 // are not supposed to call CreateThread() directly according to MSDN | |
575 // document because JVM uses C runtime library. The good news is that the | |
576 // flag appears to work with _beginthredex() as well. | |
577 | |
578 #ifndef STACK_SIZE_PARAM_IS_A_RESERVATION | |
579 #define STACK_SIZE_PARAM_IS_A_RESERVATION (0x10000) | |
580 #endif | |
581 | |
582 HANDLE thread_handle = | |
583 (HANDLE)_beginthreadex(NULL, | |
584 (unsigned)stack_size, | |
585 (unsigned (__stdcall *)(void*)) java_start, | |
586 thread, | |
587 CREATE_SUSPENDED | STACK_SIZE_PARAM_IS_A_RESERVATION, | |
588 &thread_id); | |
589 if (thread_handle == NULL) { | |
590 // perhaps STACK_SIZE_PARAM_IS_A_RESERVATION is not supported, try again | |
591 // without the flag. | |
592 thread_handle = | |
593 (HANDLE)_beginthreadex(NULL, | |
594 (unsigned)stack_size, | |
595 (unsigned (__stdcall *)(void*)) java_start, | |
596 thread, | |
597 CREATE_SUSPENDED, | |
598 &thread_id); | |
599 } | |
600 if (thread_handle == NULL) { | |
601 // Need to clean up stuff we've allocated so far | |
602 CloseHandle(osthread->interrupt_event()); | |
603 thread->set_osthread(NULL); | |
604 delete osthread; | |
605 return NULL; | |
606 } | |
607 | |
608 Atomic::inc_ptr((intptr_t*)&os::win32::_os_thread_count); | |
609 | |
610 // Store info on the Win32 thread into the OSThread | |
611 osthread->set_thread_handle(thread_handle); | |
612 osthread->set_thread_id(thread_id); | |
613 | |
614 // Initial thread state is INITIALIZED, not SUSPENDED | |
615 osthread->set_state(INITIALIZED); | |
616 | |
617 // The thread is returned suspended (in state INITIALIZED), and is started higher up in the call chain | |
618 return true; | |
619 } | |
620 | |
621 | |
622 // Free Win32 resources related to the OSThread | |
623 void os::free_thread(OSThread* osthread) { | |
624 assert(osthread != NULL, "osthread not set"); | |
625 CloseHandle(osthread->thread_handle()); | |
626 CloseHandle(osthread->interrupt_event()); | |
627 delete osthread; | |
628 } | |
629 | |
630 | |
631 static int has_performance_count = 0; | |
632 static jlong first_filetime; | |
633 static jlong initial_performance_count; | |
634 static jlong performance_frequency; | |
635 | |
636 | |
637 jlong as_long(LARGE_INTEGER x) { | |
638 jlong result = 0; // initialization to avoid warning | |
639 set_high(&result, x.HighPart); | |
640 set_low(&result, x.LowPart); | |
641 return result; | |
642 } | |
643 | |
644 | |
645 jlong os::elapsed_counter() { | |
646 LARGE_INTEGER count; | |
647 if (has_performance_count) { | |
648 QueryPerformanceCounter(&count); | |
649 return as_long(count) - initial_performance_count; | |
650 } else { | |
651 FILETIME wt; | |
652 GetSystemTimeAsFileTime(&wt); | |
653 return (jlong_from(wt.dwHighDateTime, wt.dwLowDateTime) - first_filetime); | |
654 } | |
655 } | |
656 | |
657 | |
658 jlong os::elapsed_frequency() { | |
659 if (has_performance_count) { | |
660 return performance_frequency; | |
661 } else { | |
662 // the FILETIME time is the number of 100-nanosecond intervals since January 1,1601. | |
663 return 10000000; | |
664 } | |
665 } | |
666 | |
667 | |
668 julong os::available_memory() { | |
669 return win32::available_memory(); | |
670 } | |
671 | |
672 julong os::win32::available_memory() { | |
877
8c79517a9300
6840305: Discrepancy in system memory details (when 4G or greater) reported by JVM and Windows OS
poonam
parents:
717
diff
changeset
|
673 // Use GlobalMemoryStatusEx() because GlobalMemoryStatus() may return incorrect |
8c79517a9300
6840305: Discrepancy in system memory details (when 4G or greater) reported by JVM and Windows OS
poonam
parents:
717
diff
changeset
|
674 // value if total memory is larger than 4GB |
8c79517a9300
6840305: Discrepancy in system memory details (when 4G or greater) reported by JVM and Windows OS
poonam
parents:
717
diff
changeset
|
675 MEMORYSTATUSEX ms; |
8c79517a9300
6840305: Discrepancy in system memory details (when 4G or greater) reported by JVM and Windows OS
poonam
parents:
717
diff
changeset
|
676 ms.dwLength = sizeof(ms); |
8c79517a9300
6840305: Discrepancy in system memory details (when 4G or greater) reported by JVM and Windows OS
poonam
parents:
717
diff
changeset
|
677 GlobalMemoryStatusEx(&ms); |
8c79517a9300
6840305: Discrepancy in system memory details (when 4G or greater) reported by JVM and Windows OS
poonam
parents:
717
diff
changeset
|
678 |
8c79517a9300
6840305: Discrepancy in system memory details (when 4G or greater) reported by JVM and Windows OS
poonam
parents:
717
diff
changeset
|
679 return (julong)ms.ullAvailPhys; |
0 | 680 } |
681 | |
682 julong os::physical_memory() { | |
683 return win32::physical_memory(); | |
684 } | |
685 | |
686 julong os::allocatable_physical_memory(julong size) { | |
20
e195fe4c40c7
6629887: 64-bit windows should not restrict default heap size to 1400m
phh
parents:
0
diff
changeset
|
687 #ifdef _LP64 |
e195fe4c40c7
6629887: 64-bit windows should not restrict default heap size to 1400m
phh
parents:
0
diff
changeset
|
688 return size; |
e195fe4c40c7
6629887: 64-bit windows should not restrict default heap size to 1400m
phh
parents:
0
diff
changeset
|
689 #else |
e195fe4c40c7
6629887: 64-bit windows should not restrict default heap size to 1400m
phh
parents:
0
diff
changeset
|
690 // Limit to 1400m because of the 2gb address space wall |
0 | 691 return MIN2(size, (julong)1400*M); |
20
e195fe4c40c7
6629887: 64-bit windows should not restrict default heap size to 1400m
phh
parents:
0
diff
changeset
|
692 #endif |
0 | 693 } |
694 | |
695 // VC6 lacks DWORD_PTR | |
696 #if _MSC_VER < 1300 | |
697 typedef UINT_PTR DWORD_PTR; | |
698 #endif | |
699 | |
700 int os::active_processor_count() { | |
701 DWORD_PTR lpProcessAffinityMask = 0; | |
702 DWORD_PTR lpSystemAffinityMask = 0; | |
703 int proc_count = processor_count(); | |
704 if (proc_count <= sizeof(UINT_PTR) * BitsPerByte && | |
705 GetProcessAffinityMask(GetCurrentProcess(), &lpProcessAffinityMask, &lpSystemAffinityMask)) { | |
706 // Nof active processors is number of bits in process affinity mask | |
707 int bitcount = 0; | |
708 while (lpProcessAffinityMask != 0) { | |
709 lpProcessAffinityMask = lpProcessAffinityMask & (lpProcessAffinityMask-1); | |
710 bitcount++; | |
711 } | |
712 return bitcount; | |
713 } else { | |
714 return proc_count; | |
715 } | |
716 } | |
717 | |
4006 | 718 void os::set_native_thread_name(const char *name) { |
719 // Not yet implemented. | |
720 return; | |
721 } | |
722 | |
0 | 723 bool os::distribute_processes(uint length, uint* distribution) { |
724 // Not yet implemented. | |
725 return false; | |
726 } | |
727 | |
728 bool os::bind_to_processor(uint processor_id) { | |
729 // Not yet implemented. | |
730 return false; | |
731 } | |
732 | |
733 static void initialize_performance_counter() { | |
734 LARGE_INTEGER count; | |
735 if (QueryPerformanceFrequency(&count)) { | |
736 has_performance_count = 1; | |
737 performance_frequency = as_long(count); | |
738 QueryPerformanceCounter(&count); | |
739 initial_performance_count = as_long(count); | |
740 } else { | |
741 has_performance_count = 0; | |
742 FILETIME wt; | |
743 GetSystemTimeAsFileTime(&wt); | |
744 first_filetime = jlong_from(wt.dwHighDateTime, wt.dwLowDateTime); | |
745 } | |
746 } | |
747 | |
748 | |
749 double os::elapsedTime() { | |
750 return (double) elapsed_counter() / (double) elapsed_frequency(); | |
751 } | |
752 | |
753 | |
754 // Windows format: | |
755 // The FILETIME structure is a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601. | |
756 // Java format: | |
757 // Java standards require the number of milliseconds since 1/1/1970 | |
758 | |
759 // Constant offset - calculated using offset() | |
760 static jlong _offset = 116444736000000000; | |
761 // Fake time counter for reproducible results when debugging | |
762 static jlong fake_time = 0; | |
763 | |
764 #ifdef ASSERT | |
765 // Just to be safe, recalculate the offset in debug mode | |
766 static jlong _calculated_offset = 0; | |
767 static int _has_calculated_offset = 0; | |
768 | |
769 jlong offset() { | |
770 if (_has_calculated_offset) return _calculated_offset; | |
771 SYSTEMTIME java_origin; | |
772 java_origin.wYear = 1970; | |
773 java_origin.wMonth = 1; | |
774 java_origin.wDayOfWeek = 0; // ignored | |
775 java_origin.wDay = 1; | |
776 java_origin.wHour = 0; | |
777 java_origin.wMinute = 0; | |
778 java_origin.wSecond = 0; | |
779 java_origin.wMilliseconds = 0; | |
780 FILETIME jot; | |
781 if (!SystemTimeToFileTime(&java_origin, &jot)) { | |
1490
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1353
diff
changeset
|
782 fatal(err_msg("Error = %d\nWindows error", GetLastError())); |
0 | 783 } |
784 _calculated_offset = jlong_from(jot.dwHighDateTime, jot.dwLowDateTime); | |
785 _has_calculated_offset = 1; | |
786 assert(_calculated_offset == _offset, "Calculated and constant time offsets must be equal"); | |
787 return _calculated_offset; | |
788 } | |
789 #else | |
790 jlong offset() { | |
791 return _offset; | |
792 } | |
793 #endif | |
794 | |
795 jlong windows_to_java_time(FILETIME wt) { | |
796 jlong a = jlong_from(wt.dwHighDateTime, wt.dwLowDateTime); | |
797 return (a - offset()) / 10000; | |
798 } | |
799 | |
800 FILETIME java_to_windows_time(jlong l) { | |
801 jlong a = (l * 10000) + offset(); | |
802 FILETIME result; | |
803 result.dwHighDateTime = high(a); | |
804 result.dwLowDateTime = low(a); | |
805 return result; | |
806 } | |
807 | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
142
diff
changeset
|
808 // For now, we say that Windows does not support vtime. I have no idea |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
142
diff
changeset
|
809 // whether it can actually be made to (DLD, 9/13/05). |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
142
diff
changeset
|
810 |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
142
diff
changeset
|
811 bool os::supports_vtime() { return false; } |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
142
diff
changeset
|
812 bool os::enable_vtime() { return false; } |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
142
diff
changeset
|
813 bool os::vtime_enabled() { return false; } |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
142
diff
changeset
|
814 double os::elapsedVTime() { |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
142
diff
changeset
|
815 // better than nothing, but not much |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
142
diff
changeset
|
816 return elapsedTime(); |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
142
diff
changeset
|
817 } |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
142
diff
changeset
|
818 |
0 | 819 jlong os::javaTimeMillis() { |
820 if (UseFakeTimers) { | |
821 return fake_time++; | |
822 } else { | |
61 | 823 FILETIME wt; |
824 GetSystemTimeAsFileTime(&wt); | |
825 return windows_to_java_time(wt); | |
0 | 826 } |
827 } | |
828 | |
829 jlong os::javaTimeNanos() { | |
830 if (!has_performance_count) { | |
4712
e7dead7e90af
7117303: VM uses non-monotonic time source and complains that it is non-monotonic
johnc
parents:
4006
diff
changeset
|
831 return javaTimeMillis() * NANOSECS_PER_MILLISEC; // the best we can do. |
0 | 832 } else { |
833 LARGE_INTEGER current_count; | |
834 QueryPerformanceCounter(¤t_count); | |
835 double current = as_long(current_count); | |
836 double freq = performance_frequency; | |
4712
e7dead7e90af
7117303: VM uses non-monotonic time source and complains that it is non-monotonic
johnc
parents:
4006
diff
changeset
|
837 jlong time = (jlong)((current/freq) * NANOSECS_PER_SEC); |
0 | 838 return time; |
839 } | |
840 } | |
841 | |
842 void os::javaTimeNanos_info(jvmtiTimerInfo *info_ptr) { | |
843 if (!has_performance_count) { | |
844 // javaTimeMillis() doesn't have much percision, | |
845 // but it is not going to wrap -- so all 64 bits | |
846 info_ptr->max_value = ALL_64_BITS; | |
847 | |
848 // this is a wall clock timer, so may skip | |
849 info_ptr->may_skip_backward = true; | |
850 info_ptr->may_skip_forward = true; | |
851 } else { | |
852 jlong freq = performance_frequency; | |
4712
e7dead7e90af
7117303: VM uses non-monotonic time source and complains that it is non-monotonic
johnc
parents:
4006
diff
changeset
|
853 if (freq < NANOSECS_PER_SEC) { |
0 | 854 // the performance counter is 64 bits and we will |
855 // be multiplying it -- so no wrap in 64 bits | |
856 info_ptr->max_value = ALL_64_BITS; | |
4712
e7dead7e90af
7117303: VM uses non-monotonic time source and complains that it is non-monotonic
johnc
parents:
4006
diff
changeset
|
857 } else if (freq > NANOSECS_PER_SEC) { |
0 | 858 // use the max value the counter can reach to |
859 // determine the max value which could be returned | |
860 julong max_counter = (julong)ALL_64_BITS; | |
4712
e7dead7e90af
7117303: VM uses non-monotonic time source and complains that it is non-monotonic
johnc
parents:
4006
diff
changeset
|
861 info_ptr->max_value = (jlong)(max_counter / (freq / NANOSECS_PER_SEC)); |
0 | 862 } else { |
863 // the performance counter is 64 bits and we will | |
864 // be using it directly -- so no wrap in 64 bits | |
865 info_ptr->max_value = ALL_64_BITS; | |
866 } | |
867 | |
868 // using a counter, so no skipping | |
869 info_ptr->may_skip_backward = false; | |
870 info_ptr->may_skip_forward = false; | |
871 } | |
872 info_ptr->kind = JVMTI_TIMER_ELAPSED; // elapsed not CPU time | |
873 } | |
874 | |
875 char* os::local_time_string(char *buf, size_t buflen) { | |
876 SYSTEMTIME st; | |
877 GetLocalTime(&st); | |
878 jio_snprintf(buf, buflen, "%d-%02d-%02d %02d:%02d:%02d", | |
879 st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond); | |
880 return buf; | |
881 } | |
882 | |
883 bool os::getTimesSecs(double* process_real_time, | |
884 double* process_user_time, | |
885 double* process_system_time) { | |
886 HANDLE h_process = GetCurrentProcess(); | |
887 FILETIME create_time, exit_time, kernel_time, user_time; | |
888 BOOL result = GetProcessTimes(h_process, | |
889 &create_time, | |
890 &exit_time, | |
891 &kernel_time, | |
892 &user_time); | |
893 if (result != 0) { | |
894 FILETIME wt; | |
895 GetSystemTimeAsFileTime(&wt); | |
896 jlong rtc_millis = windows_to_java_time(wt); | |
897 jlong user_millis = windows_to_java_time(user_time); | |
898 jlong system_millis = windows_to_java_time(kernel_time); | |
899 *process_real_time = ((double) rtc_millis) / ((double) MILLIUNITS); | |
900 *process_user_time = ((double) user_millis) / ((double) MILLIUNITS); | |
901 *process_system_time = ((double) system_millis) / ((double) MILLIUNITS); | |
902 return true; | |
903 } else { | |
904 return false; | |
905 } | |
906 } | |
907 | |
908 void os::shutdown() { | |
909 | |
910 // allow PerfMemory to attempt cleanup of any persistent resources | |
911 perfMemory_exit(); | |
912 | |
913 // flush buffered output, finish log files | |
914 ostream_abort(); | |
915 | |
916 // Check for abort hook | |
917 abort_hook_t abort_hook = Arguments::abort_hook(); | |
918 if (abort_hook != NULL) { | |
919 abort_hook(); | |
920 } | |
921 } | |
922 | |
2204
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
923 |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
924 static BOOL (WINAPI *_MiniDumpWriteDump) ( HANDLE, DWORD, HANDLE, MINIDUMP_TYPE, PMINIDUMP_EXCEPTION_INFORMATION, |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
925 PMINIDUMP_USER_STREAM_INFORMATION, PMINIDUMP_CALLBACK_INFORMATION); |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
926 |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
927 void os::check_or_create_dump(void* exceptionRecord, void* contextRecord, char* buffer, size_t bufferSize) { |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
928 HINSTANCE dbghelp; |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
929 EXCEPTION_POINTERS ep; |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
930 MINIDUMP_EXCEPTION_INFORMATION mei; |
3240
5504afd15955
7033100: CreateMinidumpOnCrash does not work for failed asserts
zgu
parents:
2386
diff
changeset
|
931 MINIDUMP_EXCEPTION_INFORMATION* pmei; |
5504afd15955
7033100: CreateMinidumpOnCrash does not work for failed asserts
zgu
parents:
2386
diff
changeset
|
932 |
2204
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
933 HANDLE hProcess = GetCurrentProcess(); |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
934 DWORD processId = GetCurrentProcessId(); |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
935 HANDLE dumpFile; |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
936 MINIDUMP_TYPE dumpType; |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
937 static const char* cwd; |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
938 |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
939 // If running on a client version of Windows and user has not explicitly enabled dumping |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
940 if (!os::win32::is_windows_server() && !CreateMinidumpOnCrash) { |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
941 VMError::report_coredump_status("Minidumps are not enabled by default on client versions of Windows", false); |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
942 return; |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
943 // If running on a server version of Windows and user has explictly disabled dumping |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
944 } else if (os::win32::is_windows_server() && !FLAG_IS_DEFAULT(CreateMinidumpOnCrash) && !CreateMinidumpOnCrash) { |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
945 VMError::report_coredump_status("Minidump has been disabled from the command line", false); |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
946 return; |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
947 } |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
948 |
3833
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
949 dbghelp = os::win32::load_Windows_dll("DBGHELP.DLL", NULL, 0); |
2204
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
950 |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
951 if (dbghelp == NULL) { |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
952 VMError::report_coredump_status("Failed to load dbghelp.dll", false); |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
953 return; |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
954 } |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
955 |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
956 _MiniDumpWriteDump = CAST_TO_FN_PTR( |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
957 BOOL(WINAPI *)( HANDLE, DWORD, HANDLE, MINIDUMP_TYPE, PMINIDUMP_EXCEPTION_INFORMATION, |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
958 PMINIDUMP_USER_STREAM_INFORMATION, PMINIDUMP_CALLBACK_INFORMATION), |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
959 GetProcAddress(dbghelp, "MiniDumpWriteDump")); |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
960 |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
961 if (_MiniDumpWriteDump == NULL) { |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
962 VMError::report_coredump_status("Failed to find MiniDumpWriteDump() in module dbghelp.dll", false); |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
963 return; |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
964 } |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
965 |
2205
b83527d0482d
7018366: hotspot/runtime_erro Fix for 7014918 does not build using MVC 2003
ctornqvi
parents:
2204
diff
changeset
|
966 dumpType = (MINIDUMP_TYPE)(MiniDumpWithFullMemory | MiniDumpWithHandleData); |
b83527d0482d
7018366: hotspot/runtime_erro Fix for 7014918 does not build using MVC 2003
ctornqvi
parents:
2204
diff
changeset
|
967 |
b83527d0482d
7018366: hotspot/runtime_erro Fix for 7014918 does not build using MVC 2003
ctornqvi
parents:
2204
diff
changeset
|
968 // Older versions of dbghelp.h doesn't contain all the dumptypes we want, dbghelp.h with |
b83527d0482d
7018366: hotspot/runtime_erro Fix for 7014918 does not build using MVC 2003
ctornqvi
parents:
2204
diff
changeset
|
969 // API_VERSION_NUMBER 11 or higher contains the ones we want though |
b83527d0482d
7018366: hotspot/runtime_erro Fix for 7014918 does not build using MVC 2003
ctornqvi
parents:
2204
diff
changeset
|
970 #if API_VERSION_NUMBER >= 11 |
b83527d0482d
7018366: hotspot/runtime_erro Fix for 7014918 does not build using MVC 2003
ctornqvi
parents:
2204
diff
changeset
|
971 dumpType = (MINIDUMP_TYPE)(dumpType | MiniDumpWithFullMemoryInfo | MiniDumpWithThreadInfo | |
b83527d0482d
7018366: hotspot/runtime_erro Fix for 7014918 does not build using MVC 2003
ctornqvi
parents:
2204
diff
changeset
|
972 MiniDumpWithUnloadedModules); |
b83527d0482d
7018366: hotspot/runtime_erro Fix for 7014918 does not build using MVC 2003
ctornqvi
parents:
2204
diff
changeset
|
973 #endif |
2204
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
974 |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
975 cwd = get_current_directory(NULL, 0); |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
976 jio_snprintf(buffer, bufferSize, "%s\\hs_err_pid%u.mdmp",cwd, current_process_id()); |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
977 dumpFile = CreateFile(buffer, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
978 |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
979 if (dumpFile == INVALID_HANDLE_VALUE) { |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
980 VMError::report_coredump_status("Failed to create file for dumping", false); |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
981 return; |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
982 } |
3240
5504afd15955
7033100: CreateMinidumpOnCrash does not work for failed asserts
zgu
parents:
2386
diff
changeset
|
983 if (exceptionRecord != NULL && contextRecord != NULL) { |
5504afd15955
7033100: CreateMinidumpOnCrash does not work for failed asserts
zgu
parents:
2386
diff
changeset
|
984 ep.ContextRecord = (PCONTEXT) contextRecord; |
5504afd15955
7033100: CreateMinidumpOnCrash does not work for failed asserts
zgu
parents:
2386
diff
changeset
|
985 ep.ExceptionRecord = (PEXCEPTION_RECORD) exceptionRecord; |
5504afd15955
7033100: CreateMinidumpOnCrash does not work for failed asserts
zgu
parents:
2386
diff
changeset
|
986 |
5504afd15955
7033100: CreateMinidumpOnCrash does not work for failed asserts
zgu
parents:
2386
diff
changeset
|
987 mei.ThreadId = GetCurrentThreadId(); |
5504afd15955
7033100: CreateMinidumpOnCrash does not work for failed asserts
zgu
parents:
2386
diff
changeset
|
988 mei.ExceptionPointers = &ep; |
5504afd15955
7033100: CreateMinidumpOnCrash does not work for failed asserts
zgu
parents:
2386
diff
changeset
|
989 pmei = &mei; |
5504afd15955
7033100: CreateMinidumpOnCrash does not work for failed asserts
zgu
parents:
2386
diff
changeset
|
990 } else { |
5504afd15955
7033100: CreateMinidumpOnCrash does not work for failed asserts
zgu
parents:
2386
diff
changeset
|
991 pmei = NULL; |
5504afd15955
7033100: CreateMinidumpOnCrash does not work for failed asserts
zgu
parents:
2386
diff
changeset
|
992 } |
5504afd15955
7033100: CreateMinidumpOnCrash does not work for failed asserts
zgu
parents:
2386
diff
changeset
|
993 |
2204
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
994 |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
995 // Older versions of dbghelp.dll (the one shipped with Win2003 for example) may not support all |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
996 // the dump types we really want. If first call fails, lets fall back to just use MiniDumpWithFullMemory then. |
3240
5504afd15955
7033100: CreateMinidumpOnCrash does not work for failed asserts
zgu
parents:
2386
diff
changeset
|
997 if (_MiniDumpWriteDump(hProcess, processId, dumpFile, dumpType, pmei, NULL, NULL) == false && |
5504afd15955
7033100: CreateMinidumpOnCrash does not work for failed asserts
zgu
parents:
2386
diff
changeset
|
998 _MiniDumpWriteDump(hProcess, processId, dumpFile, (MINIDUMP_TYPE)MiniDumpWithFullMemory, pmei, NULL, NULL) == false) { |
2204
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
999 VMError::report_coredump_status("Call to MiniDumpWriteDump() failed", false); |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
1000 } else { |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
1001 VMError::report_coredump_status(buffer, true); |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
1002 } |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
1003 |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
1004 CloseHandle(dumpFile); |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
1005 } |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
1006 |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
1007 |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
1008 |
0 | 1009 void os::abort(bool dump_core) |
1010 { | |
1011 os::shutdown(); | |
1012 // no core dump on Windows | |
1013 ::exit(1); | |
1014 } | |
1015 | |
1016 // Die immediately, no exit hook, no abort hook, no cleanup. | |
1017 void os::die() { | |
1018 _exit(-1); | |
1019 } | |
1020 | |
1021 // Directory routines copied from src/win32/native/java/io/dirent_md.c | |
1022 // * dirent_md.c 1.15 00/02/02 | |
1023 // | |
1024 // The declarations for DIR and struct dirent are in jvm_win32.h. | |
1025 | |
1026 /* Caller must have already run dirname through JVM_NativePath, which removes | |
1027 duplicate slashes and converts all instances of '/' into '\\'. */ | |
1028 | |
1029 DIR * | |
1030 os::opendir(const char *dirname) | |
1031 { | |
1032 assert(dirname != NULL, "just checking"); // hotspot change | |
6197 | 1033 DIR *dirp = (DIR *)malloc(sizeof(DIR), mtInternal); |
0 | 1034 DWORD fattr; // hotspot change |
1035 char alt_dirname[4] = { 0, 0, 0, 0 }; | |
1036 | |
1037 if (dirp == 0) { | |
1038 errno = ENOMEM; | |
1039 return 0; | |
1040 } | |
1041 | |
1042 /* | |
1043 * Win32 accepts "\" in its POSIX stat(), but refuses to treat it | |
1044 * as a directory in FindFirstFile(). We detect this case here and | |
1045 * prepend the current drive name. | |
1046 */ | |
1047 if (dirname[1] == '\0' && dirname[0] == '\\') { | |
1048 alt_dirname[0] = _getdrive() + 'A' - 1; | |
1049 alt_dirname[1] = ':'; | |
1050 alt_dirname[2] = '\\'; | |
1051 alt_dirname[3] = '\0'; | |
1052 dirname = alt_dirname; | |
1053 } | |
1054 | |
6197 | 1055 dirp->path = (char *)malloc(strlen(dirname) + 5, mtInternal); |
0 | 1056 if (dirp->path == 0) { |
6197 | 1057 free(dirp, mtInternal); |
0 | 1058 errno = ENOMEM; |
1059 return 0; | |
1060 } | |
1061 strcpy(dirp->path, dirname); | |
1062 | |
1063 fattr = GetFileAttributes(dirp->path); | |
1064 if (fattr == 0xffffffff) { | |
6197 | 1065 free(dirp->path, mtInternal); |
1066 free(dirp, mtInternal); | |
0 | 1067 errno = ENOENT; |
1068 return 0; | |
1069 } else if ((fattr & FILE_ATTRIBUTE_DIRECTORY) == 0) { | |
6197 | 1070 free(dirp->path, mtInternal); |
1071 free(dirp, mtInternal); | |
0 | 1072 errno = ENOTDIR; |
1073 return 0; | |
1074 } | |
1075 | |
1076 /* Append "*.*", or possibly "\\*.*", to path */ | |
1077 if (dirp->path[1] == ':' | |
1078 && (dirp->path[2] == '\0' | |
1079 || (dirp->path[2] == '\\' && dirp->path[3] == '\0'))) { | |
1080 /* No '\\' needed for cases like "Z:" or "Z:\" */ | |
1081 strcat(dirp->path, "*.*"); | |
1082 } else { | |
1083 strcat(dirp->path, "\\*.*"); | |
1084 } | |
1085 | |
1086 dirp->handle = FindFirstFile(dirp->path, &dirp->find_data); | |
1087 if (dirp->handle == INVALID_HANDLE_VALUE) { | |
1088 if (GetLastError() != ERROR_FILE_NOT_FOUND) { | |
6197 | 1089 free(dirp->path, mtInternal); |
1090 free(dirp, mtInternal); | |
0 | 1091 errno = EACCES; |
1092 return 0; | |
1093 } | |
1094 } | |
1095 return dirp; | |
1096 } | |
1097 | |
1098 /* parameter dbuf unused on Windows */ | |
1099 | |
1100 struct dirent * | |
1101 os::readdir(DIR *dirp, dirent *dbuf) | |
1102 { | |
1103 assert(dirp != NULL, "just checking"); // hotspot change | |
1104 if (dirp->handle == INVALID_HANDLE_VALUE) { | |
1105 return 0; | |
1106 } | |
1107 | |
1108 strcpy(dirp->dirent.d_name, dirp->find_data.cFileName); | |
1109 | |
1110 if (!FindNextFile(dirp->handle, &dirp->find_data)) { | |
1111 if (GetLastError() == ERROR_INVALID_HANDLE) { | |
1112 errno = EBADF; | |
1113 return 0; | |
1114 } | |
1115 FindClose(dirp->handle); | |
1116 dirp->handle = INVALID_HANDLE_VALUE; | |
1117 } | |
1118 | |
1119 return &dirp->dirent; | |
1120 } | |
1121 | |
1122 int | |
1123 os::closedir(DIR *dirp) | |
1124 { | |
1125 assert(dirp != NULL, "just checking"); // hotspot change | |
1126 if (dirp->handle != INVALID_HANDLE_VALUE) { | |
1127 if (!FindClose(dirp->handle)) { | |
1128 errno = EBADF; | |
1129 return -1; | |
1130 } | |
1131 dirp->handle = INVALID_HANDLE_VALUE; | |
1132 } | |
6197 | 1133 free(dirp->path, mtInternal); |
1134 free(dirp, mtInternal); | |
0 | 1135 return 0; |
1136 } | |
1137 | |
2130
34d64ad817f4
7009828: Fix for 6938627 breaks visualvm monitoring when -Djava.io.tmpdir is defined
coleenp
parents:
2069
diff
changeset
|
1138 // This must be hard coded because it's the system's temporary |
34d64ad817f4
7009828: Fix for 6938627 breaks visualvm monitoring when -Djava.io.tmpdir is defined
coleenp
parents:
2069
diff
changeset
|
1139 // directory not the java application's temp directory, ala java.io.tmpdir. |
1353
a2ea687fdc7c
6938627: Make temporary directory use property java.io.tmpdir when specified
coleenp
parents:
1320
diff
changeset
|
1140 const char* os::get_temp_directory() { |
a2ea687fdc7c
6938627: Make temporary directory use property java.io.tmpdir when specified
coleenp
parents:
1320
diff
changeset
|
1141 static char path_buf[MAX_PATH]; |
a2ea687fdc7c
6938627: Make temporary directory use property java.io.tmpdir when specified
coleenp
parents:
1320
diff
changeset
|
1142 if (GetTempPath(MAX_PATH, path_buf)>0) |
a2ea687fdc7c
6938627: Make temporary directory use property java.io.tmpdir when specified
coleenp
parents:
1320
diff
changeset
|
1143 return path_buf; |
a2ea687fdc7c
6938627: Make temporary directory use property java.io.tmpdir when specified
coleenp
parents:
1320
diff
changeset
|
1144 else{ |
a2ea687fdc7c
6938627: Make temporary directory use property java.io.tmpdir when specified
coleenp
parents:
1320
diff
changeset
|
1145 path_buf[0]='\0'; |
a2ea687fdc7c
6938627: Make temporary directory use property java.io.tmpdir when specified
coleenp
parents:
1320
diff
changeset
|
1146 return path_buf; |
a2ea687fdc7c
6938627: Make temporary directory use property java.io.tmpdir when specified
coleenp
parents:
1320
diff
changeset
|
1147 } |
0 | 1148 } |
1149 | |
691 | 1150 static bool file_exists(const char* filename) { |
1151 if (filename == NULL || strlen(filename) == 0) { | |
1152 return false; | |
1153 } | |
1154 return GetFileAttributes(filename) != INVALID_FILE_ATTRIBUTES; | |
1155 } | |
1156 | |
1157 void os::dll_build_name(char *buffer, size_t buflen, | |
1158 const char* pname, const char* fname) { | |
1159 const size_t pnamelen = pname ? strlen(pname) : 0; | |
1160 const char c = (pnamelen > 0) ? pname[pnamelen-1] : 0; | |
1161 | |
1162 // Quietly truncates on buffer overflow. Should be an error. | |
1163 if (pnamelen + strlen(fname) + 10 > buflen) { | |
1164 *buffer = '\0'; | |
1165 return; | |
1166 } | |
1167 | |
1168 if (pnamelen == 0) { | |
1169 jio_snprintf(buffer, buflen, "%s.dll", fname); | |
1170 } else if (c == ':' || c == '\\') { | |
1171 jio_snprintf(buffer, buflen, "%s%s.dll", pname, fname); | |
1172 } else if (strchr(pname, *os::path_separator()) != NULL) { | |
1173 int n; | |
1174 char** pelements = split_path(pname, &n); | |
1175 for (int i = 0 ; i < n ; i++) { | |
1176 char* path = pelements[i]; | |
1177 // Really shouldn't be NULL, but check can't hurt | |
1178 size_t plen = (path == NULL) ? 0 : strlen(path); | |
1179 if (plen == 0) { | |
1180 continue; // skip the empty path values | |
1181 } | |
1182 const char lastchar = path[plen - 1]; | |
1183 if (lastchar == ':' || lastchar == '\\') { | |
1184 jio_snprintf(buffer, buflen, "%s%s.dll", path, fname); | |
1185 } else { | |
1186 jio_snprintf(buffer, buflen, "%s\\%s.dll", path, fname); | |
1187 } | |
1188 if (file_exists(buffer)) { | |
1189 break; | |
1190 } | |
242 | 1191 } |
691 | 1192 // release the storage |
1193 for (int i = 0 ; i < n ; i++) { | |
1194 if (pelements[i] != NULL) { | |
6197 | 1195 FREE_C_HEAP_ARRAY(char, pelements[i], mtInternal); |
691 | 1196 } |
242 | 1197 } |
691 | 1198 if (pelements != NULL) { |
6197 | 1199 FREE_C_HEAP_ARRAY(char*, pelements, mtInternal); |
691 | 1200 } |
1201 } else { | |
1202 jio_snprintf(buffer, buflen, "%s\\%s.dll", pname, fname); | |
1203 } | |
242 | 1204 } |
1205 | |
0 | 1206 // Needs to be in os specific directory because windows requires another |
1207 // header file <direct.h> | |
1208 const char* os::get_current_directory(char *buf, int buflen) { | |
1209 return _getcwd(buf, buflen); | |
1210 } | |
1211 | |
1212 //----------------------------------------------------------- | |
1213 // Helper functions for fatal error handler | |
1214 #ifdef _WIN64 | |
1215 // Helper routine which returns true if address in | |
1216 // within the NTDLL address space. | |
1217 // | |
1218 static bool _addr_in_ntdll( address addr ) | |
1219 { | |
1220 HMODULE hmod; | |
1221 MODULEINFO minfo; | |
1222 | |
1223 hmod = GetModuleHandle("NTDLL.DLL"); | |
1224 if ( hmod == NULL ) return false; | |
3833
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
1225 if ( !os::PSApiDll::GetModuleInformation( GetCurrentProcess(), hmod, |
0 | 1226 &minfo, sizeof(MODULEINFO)) ) |
1227 return false; | |
1228 | |
1229 if ( (addr >= minfo.lpBaseOfDll) && | |
1230 (addr < (address)((uintptr_t)minfo.lpBaseOfDll + (uintptr_t)minfo.SizeOfImage))) | |
1231 return true; | |
1232 else | |
1233 return false; | |
1234 } | |
1235 #endif | |
1236 | |
1237 | |
1238 // Enumerate all modules for a given process ID | |
1239 // | |
1240 // Notice that Windows 95/98/Me and Windows NT/2000/XP have | |
1241 // different API for doing this. We use PSAPI.DLL on NT based | |
1242 // Windows and ToolHelp on 95/98/Me. | |
1243 | |
1244 // Callback function that is called by enumerate_modules() on | |
1245 // every DLL module. | |
1246 // Input parameters: | |
1247 // int pid, | |
1248 // char* module_file_name, | |
1249 // address module_base_addr, | |
1250 // unsigned module_size, | |
1251 // void* param | |
1252 typedef int (*EnumModulesCallbackFunc)(int, char *, address, unsigned, void *); | |
1253 | |
1254 // enumerate_modules for Windows NT, using PSAPI | |
1255 static int _enumerate_modules_winnt( int pid, EnumModulesCallbackFunc func, void * param) | |
1256 { | |
1257 HANDLE hProcess ; | |
1258 | |
1259 # define MAX_NUM_MODULES 128 | |
1260 HMODULE modules[MAX_NUM_MODULES]; | |
1261 static char filename[ MAX_PATH ]; | |
1262 int result = 0; | |
1263 | |
3833
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
1264 if (!os::PSApiDll::PSApiAvailable()) { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
1265 return 0; |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
1266 } |
0 | 1267 |
1268 hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, | |
1269 FALSE, pid ) ; | |
1270 if (hProcess == NULL) return 0; | |
1271 | |
1272 DWORD size_needed; | |
3833
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
1273 if (!os::PSApiDll::EnumProcessModules(hProcess, modules, |
0 | 1274 sizeof(modules), &size_needed)) { |
1275 CloseHandle( hProcess ); | |
1276 return 0; | |
1277 } | |
1278 | |
1279 // number of modules that are currently loaded | |
1280 int num_modules = size_needed / sizeof(HMODULE); | |
1281 | |
1282 for (int i = 0; i < MIN2(num_modules, MAX_NUM_MODULES); i++) { | |
1283 // Get Full pathname: | |
3833
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
1284 if(!os::PSApiDll::GetModuleFileNameEx(hProcess, modules[i], |
0 | 1285 filename, sizeof(filename))) { |
1286 filename[0] = '\0'; | |
1287 } | |
1288 | |
1289 MODULEINFO modinfo; | |
3833
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
1290 if (!os::PSApiDll::GetModuleInformation(hProcess, modules[i], |
0 | 1291 &modinfo, sizeof(modinfo))) { |
1292 modinfo.lpBaseOfDll = NULL; | |
1293 modinfo.SizeOfImage = 0; | |
1294 } | |
1295 | |
1296 // Invoke callback function | |
1297 result = func(pid, filename, (address)modinfo.lpBaseOfDll, | |
1298 modinfo.SizeOfImage, param); | |
1299 if (result) break; | |
1300 } | |
1301 | |
1302 CloseHandle( hProcess ) ; | |
1303 return result; | |
1304 } | |
1305 | |
1306 | |
1307 // enumerate_modules for Windows 95/98/ME, using TOOLHELP | |
1308 static int _enumerate_modules_windows( int pid, EnumModulesCallbackFunc func, void *param) | |
1309 { | |
1310 HANDLE hSnapShot ; | |
1311 static MODULEENTRY32 modentry ; | |
1312 int result = 0; | |
1313 | |
3833
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
1314 if (!os::Kernel32Dll::HelpToolsAvailable()) { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
1315 return 0; |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
1316 } |
0 | 1317 |
1318 // Get a handle to a Toolhelp snapshot of the system | |
3833
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
1319 hSnapShot = os::Kernel32Dll::CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pid ) ; |
0 | 1320 if( hSnapShot == INVALID_HANDLE_VALUE ) { |
1321 return FALSE ; | |
1322 } | |
1323 | |
1324 // iterate through all modules | |
1325 modentry.dwSize = sizeof(MODULEENTRY32) ; | |
3833
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
1326 bool not_done = os::Kernel32Dll::Module32First( hSnapShot, &modentry ) != 0; |
0 | 1327 |
1328 while( not_done ) { | |
1329 // invoke the callback | |
1330 result=func(pid, modentry.szExePath, (address)modentry.modBaseAddr, | |
1331 modentry.modBaseSize, param); | |
1332 if (result) break; | |
1333 | |
1334 modentry.dwSize = sizeof(MODULEENTRY32) ; | |
3833
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
1335 not_done = os::Kernel32Dll::Module32Next( hSnapShot, &modentry ) != 0; |
0 | 1336 } |
1337 | |
1338 CloseHandle(hSnapShot); | |
1339 return result; | |
1340 } | |
1341 | |
1342 int enumerate_modules( int pid, EnumModulesCallbackFunc func, void * param ) | |
1343 { | |
1344 // Get current process ID if caller doesn't provide it. | |
1345 if (!pid) pid = os::current_process_id(); | |
1346 | |
1347 if (os::win32::is_nt()) return _enumerate_modules_winnt (pid, func, param); | |
1348 else return _enumerate_modules_windows(pid, func, param); | |
1349 } | |
1350 | |
1351 struct _modinfo { | |
1352 address addr; | |
1353 char* full_path; // point to a char buffer | |
1354 int buflen; // size of the buffer | |
1355 address base_addr; | |
1356 }; | |
1357 | |
1358 static int _locate_module_by_addr(int pid, char * mod_fname, address base_addr, | |
1359 unsigned size, void * param) { | |
1360 struct _modinfo *pmod = (struct _modinfo *)param; | |
1361 if (!pmod) return -1; | |
1362 | |
1363 if (base_addr <= pmod->addr && | |
1364 base_addr+size > pmod->addr) { | |
1365 // if a buffer is provided, copy path name to the buffer | |
1366 if (pmod->full_path) { | |
1367 jio_snprintf(pmod->full_path, pmod->buflen, "%s", mod_fname); | |
1368 } | |
1369 pmod->base_addr = base_addr; | |
1370 return 1; | |
1371 } | |
1372 return 0; | |
1373 } | |
1374 | |
1375 bool os::dll_address_to_library_name(address addr, char* buf, | |
1376 int buflen, int* offset) { | |
1377 // NOTE: the reason we don't use SymGetModuleInfo() is it doesn't always | |
1378 // return the full path to the DLL file, sometimes it returns path | |
1379 // to the corresponding PDB file (debug info); sometimes it only | |
1380 // returns partial path, which makes life painful. | |
1381 | |
1382 struct _modinfo mi; | |
1383 mi.addr = addr; | |
1384 mi.full_path = buf; | |
1385 mi.buflen = buflen; | |
1386 int pid = os::current_process_id(); | |
1387 if (enumerate_modules(pid, _locate_module_by_addr, (void *)&mi)) { | |
1388 // buf already contains path name | |
1389 if (offset) *offset = addr - mi.base_addr; | |
1390 return true; | |
1391 } else { | |
1392 if (buf) buf[0] = '\0'; | |
1393 if (offset) *offset = -1; | |
1394 return false; | |
1395 } | |
1396 } | |
1397 | |
1398 bool os::dll_address_to_function_name(address addr, char *buf, | |
1399 int buflen, int *offset) { | |
4803 | 1400 if (Decoder::decode(addr, buf, buflen, offset)) { |
2022
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
1972
diff
changeset
|
1401 return true; |
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
1972
diff
changeset
|
1402 } |
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
1972
diff
changeset
|
1403 if (offset != NULL) *offset = -1; |
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
1972
diff
changeset
|
1404 if (buf != NULL) buf[0] = '\0'; |
0 | 1405 return false; |
1406 } | |
1407 | |
1408 // save the start and end address of jvm.dll into param[0] and param[1] | |
1409 static int _locate_jvm_dll(int pid, char* mod_fname, address base_addr, | |
1410 unsigned size, void * param) { | |
1411 if (!param) return -1; | |
1412 | |
1413 if (base_addr <= (address)_locate_jvm_dll && | |
1414 base_addr+size > (address)_locate_jvm_dll) { | |
1415 ((address*)param)[0] = base_addr; | |
1416 ((address*)param)[1] = base_addr + size; | |
1417 return 1; | |
1418 } | |
1419 return 0; | |
1420 } | |
1421 | |
1422 address vm_lib_location[2]; // start and end address of jvm.dll | |
1423 | |
1424 // check if addr is inside jvm.dll | |
1425 bool os::address_is_in_vm(address addr) { | |
1426 if (!vm_lib_location[0] || !vm_lib_location[1]) { | |
1427 int pid = os::current_process_id(); | |
1428 if (!enumerate_modules(pid, _locate_jvm_dll, (void *)vm_lib_location)) { | |
1429 assert(false, "Can't find jvm module."); | |
1430 return false; | |
1431 } | |
1432 } | |
1433 | |
1434 return (vm_lib_location[0] <= addr) && (addr < vm_lib_location[1]); | |
1435 } | |
1436 | |
1437 // print module info; param is outputStream* | |
1438 static int _print_module(int pid, char* fname, address base, | |
1439 unsigned size, void* param) { | |
1440 if (!param) return -1; | |
1441 | |
1442 outputStream* st = (outputStream*)param; | |
1443 | |
1444 address end_addr = base + size; | |
1445 st->print(PTR_FORMAT " - " PTR_FORMAT " \t%s\n", base, end_addr, fname); | |
1446 return 0; | |
1447 } | |
1448 | |
1449 // Loads .dll/.so and | |
1450 // in case of error it checks if .dll/.so was built for the | |
1451 // same architecture as Hotspot is running on | |
1452 void * os::dll_load(const char *name, char *ebuf, int ebuflen) | |
1453 { | |
1454 void * result = LoadLibrary(name); | |
1455 if (result != NULL) | |
1456 { | |
1457 return result; | |
1458 } | |
1459 | |
4750
b16494a69d3d
7126185: Clean up lasterror handling, add os::get_last_error()
phh
parents:
4720
diff
changeset
|
1460 DWORD errcode = GetLastError(); |
0 | 1461 if (errcode == ERROR_MOD_NOT_FOUND) { |
1462 strncpy(ebuf, "Can't find dependent libraries", ebuflen-1); | |
1463 ebuf[ebuflen-1]='\0'; | |
1464 return NULL; | |
1465 } | |
1466 | |
1467 // Parsing dll below | |
1468 // If we can read dll-info and find that dll was built | |
1469 // for an architecture other than Hotspot is running in | |
1470 // - then print to buffer "DLL was built for a different architecture" | |
4750
b16494a69d3d
7126185: Clean up lasterror handling, add os::get_last_error()
phh
parents:
4720
diff
changeset
|
1471 // else call os::lasterror to obtain system error message |
0 | 1472 |
1473 // Read system error message into ebuf | |
1474 // It may or may not be overwritten below (in the for loop and just above) | |
4750
b16494a69d3d
7126185: Clean up lasterror handling, add os::get_last_error()
phh
parents:
4720
diff
changeset
|
1475 lasterror(ebuf, (size_t) ebuflen); |
0 | 1476 ebuf[ebuflen-1]='\0'; |
1477 int file_descriptor=::open(name, O_RDONLY | O_BINARY, 0); | |
1478 if (file_descriptor<0) | |
1479 { | |
1480 return NULL; | |
1481 } | |
1482 | |
1483 uint32_t signature_offset; | |
1484 uint16_t lib_arch=0; | |
1485 bool failed_to_get_lib_arch= | |
1486 ( | |
1487 //Go to position 3c in the dll | |
1488 (os::seek_to_file_offset(file_descriptor,IMAGE_FILE_PTR_TO_SIGNATURE)<0) | |
1489 || | |
1490 // Read loacation of signature | |
1491 (sizeof(signature_offset)!= | |
1492 (os::read(file_descriptor, (void*)&signature_offset,sizeof(signature_offset)))) | |
1493 || | |
1494 //Go to COFF File Header in dll | |
1495 //that is located after"signature" (4 bytes long) | |
1496 (os::seek_to_file_offset(file_descriptor, | |
1497 signature_offset+IMAGE_FILE_SIGNATURE_LENGTH)<0) | |
1498 || | |
1499 //Read field that contains code of architecture | |
1500 // that dll was build for | |
1501 (sizeof(lib_arch)!= | |
1502 (os::read(file_descriptor, (void*)&lib_arch,sizeof(lib_arch)))) | |
1503 ); | |
1504 | |
1505 ::close(file_descriptor); | |
1506 if (failed_to_get_lib_arch) | |
1507 { | |
4750
b16494a69d3d
7126185: Clean up lasterror handling, add os::get_last_error()
phh
parents:
4720
diff
changeset
|
1508 // file i/o error - report os::lasterror(...) msg |
0 | 1509 return NULL; |
1510 } | |
1511 | |
1512 typedef struct | |
1513 { | |
1514 uint16_t arch_code; | |
1515 char* arch_name; | |
1516 } arch_t; | |
1517 | |
1518 static const arch_t arch_array[]={ | |
1519 {IMAGE_FILE_MACHINE_I386, (char*)"IA 32"}, | |
1520 {IMAGE_FILE_MACHINE_AMD64, (char*)"AMD 64"}, | |
1521 {IMAGE_FILE_MACHINE_IA64, (char*)"IA 64"} | |
1522 }; | |
1523 #if (defined _M_IA64) | |
1524 static const uint16_t running_arch=IMAGE_FILE_MACHINE_IA64; | |
1525 #elif (defined _M_AMD64) | |
1526 static const uint16_t running_arch=IMAGE_FILE_MACHINE_AMD64; | |
1527 #elif (defined _M_IX86) | |
1528 static const uint16_t running_arch=IMAGE_FILE_MACHINE_I386; | |
1529 #else | |
1530 #error Method os::dll_load requires that one of following \ | |
1531 is defined :_M_IA64,_M_AMD64 or _M_IX86 | |
1532 #endif | |
1533 | |
1534 | |
1535 // Obtain a string for printf operation | |
1536 // lib_arch_str shall contain string what platform this .dll was built for | |
1537 // running_arch_str shall string contain what platform Hotspot was built for | |
1538 char *running_arch_str=NULL,*lib_arch_str=NULL; | |
1539 for (unsigned int i=0;i<ARRAY_SIZE(arch_array);i++) | |
1540 { | |
1541 if (lib_arch==arch_array[i].arch_code) | |
1542 lib_arch_str=arch_array[i].arch_name; | |
1543 if (running_arch==arch_array[i].arch_code) | |
1544 running_arch_str=arch_array[i].arch_name; | |
1545 } | |
1546 | |
1547 assert(running_arch_str, | |
1548 "Didn't find runing architecture code in arch_array"); | |
1549 | |
1550 // If the architure is right | |
4750
b16494a69d3d
7126185: Clean up lasterror handling, add os::get_last_error()
phh
parents:
4720
diff
changeset
|
1551 // but some other error took place - report os::lasterror(...) msg |
0 | 1552 if (lib_arch == running_arch) |
1553 { | |
1554 return NULL; | |
1555 } | |
1556 | |
1557 if (lib_arch_str!=NULL) | |
1558 { | |
1559 ::_snprintf(ebuf, ebuflen-1, | |
1560 "Can't load %s-bit .dll on a %s-bit platform", | |
1561 lib_arch_str,running_arch_str); | |
1562 } | |
1563 else | |
1564 { | |
1565 // don't know what architecture this dll was build for | |
1566 ::_snprintf(ebuf, ebuflen-1, | |
1567 "Can't load this .dll (machine code=0x%x) on a %s-bit platform", | |
1568 lib_arch,running_arch_str); | |
1569 } | |
1570 | |
1571 return NULL; | |
1572 } | |
1573 | |
1574 | |
1575 void os::print_dll_info(outputStream *st) { | |
1576 int pid = os::current_process_id(); | |
1577 st->print_cr("Dynamic libraries:"); | |
1578 enumerate_modules(pid, _print_module, (void *)st); | |
1579 } | |
1580 | |
6080
7432b9db36ff
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
6044
diff
changeset
|
1581 void os::print_os_info_brief(outputStream* st) { |
7432b9db36ff
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
6044
diff
changeset
|
1582 os::print_os_info(st); |
7432b9db36ff
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
6044
diff
changeset
|
1583 } |
7432b9db36ff
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
6044
diff
changeset
|
1584 |
0 | 1585 void os::print_os_info(outputStream* st) { |
273
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1586 st->print("OS:"); |
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1587 |
6080
7432b9db36ff
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
6044
diff
changeset
|
1588 os::win32::print_windows_version(st); |
7432b9db36ff
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
6044
diff
changeset
|
1589 } |
7432b9db36ff
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
6044
diff
changeset
|
1590 |
7432b9db36ff
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
6044
diff
changeset
|
1591 void os::win32::print_windows_version(outputStream* st) { |
273
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1592 OSVERSIONINFOEX osvi; |
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1593 ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); |
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1594 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); |
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1595 |
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1596 if (!GetVersionEx((OSVERSIONINFO *)&osvi)) { |
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1597 st->print_cr("N/A"); |
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1598 return; |
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1599 } |
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1600 |
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1601 int os_vers = osvi.dwMajorVersion * 1000 + osvi.dwMinorVersion; |
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1602 if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) { |
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1603 switch (os_vers) { |
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1604 case 3051: st->print(" Windows NT 3.51"); break; |
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1605 case 4000: st->print(" Windows NT 4.0"); break; |
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1606 case 5000: st->print(" Windows 2000"); break; |
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1607 case 5001: st->print(" Windows XP"); break; |
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1608 case 5002: |
962
aafa4232dfd7
6821003: Update hotspot windows os_win32 for windows 7
asaha
parents:
877
diff
changeset
|
1609 case 6000: |
6126
de909f001528
7170275: os::print_os_info needs to know about Windows 8
mikael
parents:
6080
diff
changeset
|
1610 case 6001: |
de909f001528
7170275: os::print_os_info needs to know about Windows 8
mikael
parents:
6080
diff
changeset
|
1611 case 6002: { |
273
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1612 // Retrieve SYSTEM_INFO from GetNativeSystemInfo call so that we could |
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1613 // find out whether we are running on 64 bit processor or not. |
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1614 SYSTEM_INFO si; |
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1615 ZeroMemory(&si, sizeof(SYSTEM_INFO)); |
3833
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
1616 if (!os::Kernel32Dll::GetNativeSystemInfoAvailable()){ |
273
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1617 GetSystemInfo(&si); |
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1618 } else { |
3833
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
1619 os::Kernel32Dll::GetNativeSystemInfo(&si); |
273
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1620 } |
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1621 if (os_vers == 5002) { |
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1622 if (osvi.wProductType == VER_NT_WORKSTATION && |
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1623 si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) |
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1624 st->print(" Windows XP x64 Edition"); |
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1625 else |
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1626 st->print(" Windows Server 2003 family"); |
962
aafa4232dfd7
6821003: Update hotspot windows os_win32 for windows 7
asaha
parents:
877
diff
changeset
|
1627 } else if (os_vers == 6000) { |
273
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1628 if (osvi.wProductType == VER_NT_WORKSTATION) |
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1629 st->print(" Windows Vista"); |
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1630 else |
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1631 st->print(" Windows Server 2008"); |
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1632 if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) |
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1633 st->print(" , 64 bit"); |
962
aafa4232dfd7
6821003: Update hotspot windows os_win32 for windows 7
asaha
parents:
877
diff
changeset
|
1634 } else if (os_vers == 6001) { |
aafa4232dfd7
6821003: Update hotspot windows os_win32 for windows 7
asaha
parents:
877
diff
changeset
|
1635 if (osvi.wProductType == VER_NT_WORKSTATION) { |
aafa4232dfd7
6821003: Update hotspot windows os_win32 for windows 7
asaha
parents:
877
diff
changeset
|
1636 st->print(" Windows 7"); |
aafa4232dfd7
6821003: Update hotspot windows os_win32 for windows 7
asaha
parents:
877
diff
changeset
|
1637 } else { |
aafa4232dfd7
6821003: Update hotspot windows os_win32 for windows 7
asaha
parents:
877
diff
changeset
|
1638 // Unrecognized windows, print out its major and minor versions |
aafa4232dfd7
6821003: Update hotspot windows os_win32 for windows 7
asaha
parents:
877
diff
changeset
|
1639 st->print(" Windows NT %d.%d", osvi.dwMajorVersion, osvi.dwMinorVersion); |
aafa4232dfd7
6821003: Update hotspot windows os_win32 for windows 7
asaha
parents:
877
diff
changeset
|
1640 } |
aafa4232dfd7
6821003: Update hotspot windows os_win32 for windows 7
asaha
parents:
877
diff
changeset
|
1641 if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) |
aafa4232dfd7
6821003: Update hotspot windows os_win32 for windows 7
asaha
parents:
877
diff
changeset
|
1642 st->print(" , 64 bit"); |
6126
de909f001528
7170275: os::print_os_info needs to know about Windows 8
mikael
parents:
6080
diff
changeset
|
1643 } else if (os_vers == 6002) { |
de909f001528
7170275: os::print_os_info needs to know about Windows 8
mikael
parents:
6080
diff
changeset
|
1644 if (osvi.wProductType == VER_NT_WORKSTATION) { |
de909f001528
7170275: os::print_os_info needs to know about Windows 8
mikael
parents:
6080
diff
changeset
|
1645 st->print(" Windows 8"); |
de909f001528
7170275: os::print_os_info needs to know about Windows 8
mikael
parents:
6080
diff
changeset
|
1646 } else { |
de909f001528
7170275: os::print_os_info needs to know about Windows 8
mikael
parents:
6080
diff
changeset
|
1647 st->print(" Windows Server 2012"); |
de909f001528
7170275: os::print_os_info needs to know about Windows 8
mikael
parents:
6080
diff
changeset
|
1648 } |
de909f001528
7170275: os::print_os_info needs to know about Windows 8
mikael
parents:
6080
diff
changeset
|
1649 if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) |
de909f001528
7170275: os::print_os_info needs to know about Windows 8
mikael
parents:
6080
diff
changeset
|
1650 st->print(" , 64 bit"); |
962
aafa4232dfd7
6821003: Update hotspot windows os_win32 for windows 7
asaha
parents:
877
diff
changeset
|
1651 } else { // future os |
aafa4232dfd7
6821003: Update hotspot windows os_win32 for windows 7
asaha
parents:
877
diff
changeset
|
1652 // Unrecognized windows, print out its major and minor versions |
aafa4232dfd7
6821003: Update hotspot windows os_win32 for windows 7
asaha
parents:
877
diff
changeset
|
1653 st->print(" Windows NT %d.%d", osvi.dwMajorVersion, osvi.dwMinorVersion); |
aafa4232dfd7
6821003: Update hotspot windows os_win32 for windows 7
asaha
parents:
877
diff
changeset
|
1654 if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) |
aafa4232dfd7
6821003: Update hotspot windows os_win32 for windows 7
asaha
parents:
877
diff
changeset
|
1655 st->print(" , 64 bit"); |
273
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1656 } |
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1657 break; |
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1658 } |
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1659 default: // future windows, print out its major and minor versions |
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1660 st->print(" Windows NT %d.%d", osvi.dwMajorVersion, osvi.dwMinorVersion); |
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1661 } |
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1662 } else { |
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1663 switch (os_vers) { |
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1664 case 4000: st->print(" Windows 95"); break; |
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1665 case 4010: st->print(" Windows 98"); break; |
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1666 case 4090: st->print(" Windows Me"); break; |
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1667 default: // future windows, print out its major and minor versions |
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1668 st->print(" Windows %d.%d", osvi.dwMajorVersion, osvi.dwMinorVersion); |
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1669 } |
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1670 } |
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1671 st->print(" Build %d", osvi.dwBuildNumber); |
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1672 st->print(" %s", osvi.szCSDVersion); // service pack |
6f17a7c9f8b4
6719981: Update Hotspot Windows os_win32 for windows XP 64 bit and windows 2008
xlu
parents:
242
diff
changeset
|
1673 st->cr(); |
0 | 1674 } |
1675 | |
3800
bf6481e5f96d
7061225: os::print_cpu_info() should support os-specific data
jcoomes
parents:
3318
diff
changeset
|
1676 void os::pd_print_cpu_info(outputStream* st) { |
bf6481e5f96d
7061225: os::print_cpu_info() should support os-specific data
jcoomes
parents:
3318
diff
changeset
|
1677 // Nothing to do for now. |
bf6481e5f96d
7061225: os::print_cpu_info() should support os-specific data
jcoomes
parents:
3318
diff
changeset
|
1678 } |
bf6481e5f96d
7061225: os::print_cpu_info() should support os-specific data
jcoomes
parents:
3318
diff
changeset
|
1679 |
0 | 1680 void os::print_memory_info(outputStream* st) { |
1681 st->print("Memory:"); | |
1682 st->print(" %dk page", os::vm_page_size()>>10); | |
1683 | |
877
8c79517a9300
6840305: Discrepancy in system memory details (when 4G or greater) reported by JVM and Windows OS
poonam
parents:
717
diff
changeset
|
1684 // Use GlobalMemoryStatusEx() because GlobalMemoryStatus() may return incorrect |
8c79517a9300
6840305: Discrepancy in system memory details (when 4G or greater) reported by JVM and Windows OS
poonam
parents:
717
diff
changeset
|
1685 // value if total memory is larger than 4GB |
8c79517a9300
6840305: Discrepancy in system memory details (when 4G or greater) reported by JVM and Windows OS
poonam
parents:
717
diff
changeset
|
1686 MEMORYSTATUSEX ms; |
8c79517a9300
6840305: Discrepancy in system memory details (when 4G or greater) reported by JVM and Windows OS
poonam
parents:
717
diff
changeset
|
1687 ms.dwLength = sizeof(ms); |
8c79517a9300
6840305: Discrepancy in system memory details (when 4G or greater) reported by JVM and Windows OS
poonam
parents:
717
diff
changeset
|
1688 GlobalMemoryStatusEx(&ms); |
0 | 1689 |
1690 st->print(", physical %uk", os::physical_memory() >> 10); | |
1691 st->print("(%uk free)", os::available_memory() >> 10); | |
1692 | |
877
8c79517a9300
6840305: Discrepancy in system memory details (when 4G or greater) reported by JVM and Windows OS
poonam
parents:
717
diff
changeset
|
1693 st->print(", swap %uk", ms.ullTotalPageFile >> 10); |
8c79517a9300
6840305: Discrepancy in system memory details (when 4G or greater) reported by JVM and Windows OS
poonam
parents:
717
diff
changeset
|
1694 st->print("(%uk free)", ms.ullAvailPageFile >> 10); |
0 | 1695 st->cr(); |
1696 } | |
1697 | |
1698 void os::print_siginfo(outputStream *st, void *siginfo) { | |
1699 EXCEPTION_RECORD* er = (EXCEPTION_RECORD*)siginfo; | |
1700 st->print("siginfo:"); | |
1701 st->print(" ExceptionCode=0x%x", er->ExceptionCode); | |
1702 | |
1703 if (er->ExceptionCode == EXCEPTION_ACCESS_VIOLATION && | |
1704 er->NumberParameters >= 2) { | |
1705 switch (er->ExceptionInformation[0]) { | |
1706 case 0: st->print(", reading address"); break; | |
1707 case 1: st->print(", writing address"); break; | |
1708 default: st->print(", ExceptionInformation=" INTPTR_FORMAT, | |
1709 er->ExceptionInformation[0]); | |
1710 } | |
1711 st->print(" " INTPTR_FORMAT, er->ExceptionInformation[1]); | |
1712 } else if (er->ExceptionCode == EXCEPTION_IN_PAGE_ERROR && | |
1713 er->NumberParameters >= 2 && UseSharedSpaces) { | |
1714 FileMapInfo* mapinfo = FileMapInfo::current_info(); | |
1715 if (mapinfo->is_in_shared_space((void*)er->ExceptionInformation[1])) { | |
1716 st->print("\n\nError accessing class data sharing archive." \ | |
1717 " Mapped file inaccessible during execution, " \ | |
1718 " possible disk/network problem."); | |
1719 } | |
1720 } else { | |
1721 int num = er->NumberParameters; | |
1722 if (num > 0) { | |
1723 st->print(", ExceptionInformation="); | |
1724 for (int i = 0; i < num; i++) { | |
1725 st->print(INTPTR_FORMAT " ", er->ExceptionInformation[i]); | |
1726 } | |
1727 } | |
1728 } | |
1729 st->cr(); | |
1730 } | |
1731 | |
1732 void os::print_signal_handlers(outputStream* st, char* buf, size_t buflen) { | |
1733 // do nothing | |
1734 } | |
1735 | |
1736 static char saved_jvm_path[MAX_PATH] = {0}; | |
1737 | |
1738 // Find the full path to the current module, jvm.dll or jvm_g.dll | |
1739 void os::jvm_path(char *buf, jint buflen) { | |
1740 // Error checking. | |
1741 if (buflen < MAX_PATH) { | |
1742 assert(false, "must use a large-enough buffer"); | |
1743 buf[0] = '\0'; | |
1744 return; | |
1745 } | |
1746 // Lazy resolve the path to current module. | |
1747 if (saved_jvm_path[0] != 0) { | |
1748 strcpy(buf, saved_jvm_path); | |
1749 return; | |
1750 } | |
1751 | |
1985 | 1752 buf[0] = '\0'; |
2302
da091bb67459
7022037: Pause when exiting if debugger is attached on windows
sla
parents:
2205
diff
changeset
|
1753 if (Arguments::created_by_gamma_launcher()) { |
1985 | 1754 // Support for the gamma launcher. Check for an |
2027
aa6e219afbf1
7006354: Updates to Visual Studio project creation and development launcher
sla
parents:
2023
diff
changeset
|
1755 // JAVA_HOME environment variable |
1985 | 1756 // and fix up the path so it looks like |
1757 // libjvm.so is installed there (append a fake suffix | |
1758 // hotspot/libjvm.so). | |
2027
aa6e219afbf1
7006354: Updates to Visual Studio project creation and development launcher
sla
parents:
2023
diff
changeset
|
1759 char* java_home_var = ::getenv("JAVA_HOME"); |
1985 | 1760 if (java_home_var != NULL && java_home_var[0] != 0) { |
1761 | |
1762 strncpy(buf, java_home_var, buflen); | |
1763 | |
1764 // determine if this is a legacy image or modules image | |
1765 // modules image doesn't have "jre" subdirectory | |
1766 size_t len = strlen(buf); | |
1767 char* jrebin_p = buf + len; | |
1768 jio_snprintf(jrebin_p, buflen-len, "\\jre\\bin\\"); | |
1769 if (0 != _access(buf, 0)) { | |
1770 jio_snprintf(jrebin_p, buflen-len, "\\bin\\"); | |
1771 } | |
1772 len = strlen(buf); | |
1773 jio_snprintf(buf + len, buflen-len, "hotspot\\jvm.dll"); | |
1774 } | |
1775 } | |
1776 | |
1777 if(buf[0] == '\0') { | |
0 | 1778 GetModuleFileName(vm_lib_handle, buf, buflen); |
1985 | 1779 } |
0 | 1780 strcpy(saved_jvm_path, buf); |
1781 } | |
1782 | |
1783 | |
1784 void os::print_jni_name_prefix_on(outputStream* st, int args_size) { | |
1785 #ifndef _WIN64 | |
1786 st->print("_"); | |
1787 #endif | |
1788 } | |
1789 | |
1790 | |
1791 void os::print_jni_name_suffix_on(outputStream* st, int args_size) { | |
1792 #ifndef _WIN64 | |
1793 st->print("@%d", args_size * sizeof(int)); | |
1794 #endif | |
1795 } | |
1796 | |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
1797 // This method is a copy of JDK's sysGetLastErrorString |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
1798 // from src/windows/hpi/src/system_md.c |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
1799 |
4750
b16494a69d3d
7126185: Clean up lasterror handling, add os::get_last_error()
phh
parents:
4720
diff
changeset
|
1800 size_t os::lasterror(char* buf, size_t len) { |
b16494a69d3d
7126185: Clean up lasterror handling, add os::get_last_error()
phh
parents:
4720
diff
changeset
|
1801 DWORD errval; |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
1802 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
1803 if ((errval = GetLastError()) != 0) { |
4750
b16494a69d3d
7126185: Clean up lasterror handling, add os::get_last_error()
phh
parents:
4720
diff
changeset
|
1804 // DOS error |
b16494a69d3d
7126185: Clean up lasterror handling, add os::get_last_error()
phh
parents:
4720
diff
changeset
|
1805 size_t n = (size_t)FormatMessage( |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
1806 FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
1807 NULL, |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
1808 errval, |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
1809 0, |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
1810 buf, |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
1811 (DWORD)len, |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
1812 NULL); |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
1813 if (n > 3) { |
4750
b16494a69d3d
7126185: Clean up lasterror handling, add os::get_last_error()
phh
parents:
4720
diff
changeset
|
1814 // Drop final '.', CR, LF |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
1815 if (buf[n - 1] == '\n') n--; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
1816 if (buf[n - 1] == '\r') n--; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
1817 if (buf[n - 1] == '.') n--; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
1818 buf[n] = '\0'; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
1819 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
1820 return n; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
1821 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
1822 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
1823 if (errno != 0) { |
4750
b16494a69d3d
7126185: Clean up lasterror handling, add os::get_last_error()
phh
parents:
4720
diff
changeset
|
1824 // C runtime error that has no corresponding DOS error code |
b16494a69d3d
7126185: Clean up lasterror handling, add os::get_last_error()
phh
parents:
4720
diff
changeset
|
1825 const char* s = strerror(errno); |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
1826 size_t n = strlen(s); |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
1827 if (n >= len) n = len - 1; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
1828 strncpy(buf, s, n); |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
1829 buf[n] = '\0'; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
1830 return n; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
1831 } |
4750
b16494a69d3d
7126185: Clean up lasterror handling, add os::get_last_error()
phh
parents:
4720
diff
changeset
|
1832 |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
1833 return 0; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
1834 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
1835 |
4750
b16494a69d3d
7126185: Clean up lasterror handling, add os::get_last_error()
phh
parents:
4720
diff
changeset
|
1836 int os::get_last_error() { |
b16494a69d3d
7126185: Clean up lasterror handling, add os::get_last_error()
phh
parents:
4720
diff
changeset
|
1837 DWORD error = GetLastError(); |
b16494a69d3d
7126185: Clean up lasterror handling, add os::get_last_error()
phh
parents:
4720
diff
changeset
|
1838 if (error == 0) |
b16494a69d3d
7126185: Clean up lasterror handling, add os::get_last_error()
phh
parents:
4720
diff
changeset
|
1839 error = errno; |
b16494a69d3d
7126185: Clean up lasterror handling, add os::get_last_error()
phh
parents:
4720
diff
changeset
|
1840 return (int)error; |
b16494a69d3d
7126185: Clean up lasterror handling, add os::get_last_error()
phh
parents:
4720
diff
changeset
|
1841 } |
b16494a69d3d
7126185: Clean up lasterror handling, add os::get_last_error()
phh
parents:
4720
diff
changeset
|
1842 |
0 | 1843 // sun.misc.Signal |
1844 // NOTE that this is a workaround for an apparent kernel bug where if | |
1845 // a signal handler for SIGBREAK is installed then that signal handler | |
1846 // takes priority over the console control handler for CTRL_CLOSE_EVENT. | |
1847 // See bug 4416763. | |
1848 static void (*sigbreakHandler)(int) = NULL; | |
1849 | |
1850 static void UserHandler(int sig, void *siginfo, void *context) { | |
1851 os::signal_notify(sig); | |
1852 // We need to reinstate the signal handler each time... | |
1853 os::signal(sig, (void*)UserHandler); | |
1854 } | |
1855 | |
1856 void* os::user_handler() { | |
1857 return (void*) UserHandler; | |
1858 } | |
1859 | |
1860 void* os::signal(int signal_number, void* handler) { | |
1861 if ((signal_number == SIGBREAK) && (!ReduceSignalUsage)) { | |
1862 void (*oldHandler)(int) = sigbreakHandler; | |
1863 sigbreakHandler = (void (*)(int)) handler; | |
1864 return (void*) oldHandler; | |
1865 } else { | |
1866 return (void*)::signal(signal_number, (void (*)(int))handler); | |
1867 } | |
1868 } | |
1869 | |
1870 void os::signal_raise(int signal_number) { | |
1871 raise(signal_number); | |
1872 } | |
1873 | |
1874 // The Win32 C runtime library maps all console control events other than ^C | |
1875 // into SIGBREAK, which makes it impossible to distinguish ^BREAK from close, | |
1876 // logoff, and shutdown events. We therefore install our own console handler | |
1877 // that raises SIGTERM for the latter cases. | |
1878 // | |
1879 static BOOL WINAPI consoleHandler(DWORD event) { | |
1880 switch(event) { | |
1881 case CTRL_C_EVENT: | |
1882 if (is_error_reported()) { | |
1883 // Ctrl-C is pressed during error reporting, likely because the error | |
1884 // handler fails to abort. Let VM die immediately. | |
1885 os::die(); | |
1886 } | |
1887 | |
1888 os::signal_raise(SIGINT); | |
1889 return TRUE; | |
1890 break; | |
1891 case CTRL_BREAK_EVENT: | |
1892 if (sigbreakHandler != NULL) { | |
1893 (*sigbreakHandler)(SIGBREAK); | |
1894 } | |
1895 return TRUE; | |
1896 break; | |
1897 case CTRL_CLOSE_EVENT: | |
1898 case CTRL_LOGOFF_EVENT: | |
1899 case CTRL_SHUTDOWN_EVENT: | |
1900 os::signal_raise(SIGTERM); | |
1901 return TRUE; | |
1902 break; | |
1903 default: | |
1904 break; | |
1905 } | |
1906 return FALSE; | |
1907 } | |
1908 | |
1909 /* | |
1910 * The following code is moved from os.cpp for making this | |
1911 * code platform specific, which it is by its very nature. | |
1912 */ | |
1913 | |
1914 // Return maximum OS signal used + 1 for internal use only | |
1915 // Used as exit signal for signal_thread | |
1916 int os::sigexitnum_pd(){ | |
1917 return NSIG; | |
1918 } | |
1919 | |
1920 // a counter for each possible signal value, including signal_thread exit signal | |
1921 static volatile jint pending_signals[NSIG+1] = { 0 }; | |
1922 static HANDLE sig_sem; | |
1923 | |
1924 void os::signal_init_pd() { | |
1925 // Initialize signal structures | |
1926 memset((void*)pending_signals, 0, sizeof(pending_signals)); | |
1927 | |
1928 sig_sem = ::CreateSemaphore(NULL, 0, NSIG+1, NULL); | |
1929 | |
1930 // Programs embedding the VM do not want it to attempt to receive | |
1931 // events like CTRL_LOGOFF_EVENT, which are used to implement the | |
1932 // shutdown hooks mechanism introduced in 1.3. For example, when | |
1933 // the VM is run as part of a Windows NT service (i.e., a servlet | |
1934 // engine in a web server), the correct behavior is for any console | |
1935 // control handler to return FALSE, not TRUE, because the OS's | |
1936 // "final" handler for such events allows the process to continue if | |
1937 // it is a service (while terminating it if it is not a service). | |
1938 // To make this behavior uniform and the mechanism simpler, we | |
1939 // completely disable the VM's usage of these console events if -Xrs | |
1940 // (=ReduceSignalUsage) is specified. This means, for example, that | |
1941 // the CTRL-BREAK thread dump mechanism is also disabled in this | |
1942 // case. See bugs 4323062, 4345157, and related bugs. | |
1943 | |
1944 if (!ReduceSignalUsage) { | |
1945 // Add a CTRL-C handler | |
1946 SetConsoleCtrlHandler(consoleHandler, TRUE); | |
1947 } | |
1948 } | |
1949 | |
1950 void os::signal_notify(int signal_number) { | |
1951 BOOL ret; | |
1952 | |
1953 Atomic::inc(&pending_signals[signal_number]); | |
1954 ret = ::ReleaseSemaphore(sig_sem, 1, NULL); | |
1955 assert(ret != 0, "ReleaseSemaphore() failed"); | |
1956 } | |
1957 | |
1958 static int check_pending_signals(bool wait_for_signal) { | |
1959 DWORD ret; | |
1960 while (true) { | |
1961 for (int i = 0; i < NSIG + 1; i++) { | |
1962 jint n = pending_signals[i]; | |
1963 if (n > 0 && n == Atomic::cmpxchg(n - 1, &pending_signals[i], n)) { | |
1964 return i; | |
1965 } | |
1966 } | |
1967 if (!wait_for_signal) { | |
1968 return -1; | |
1969 } | |
1970 | |
1971 JavaThread *thread = JavaThread::current(); | |
1972 | |
1973 ThreadBlockInVM tbivm(thread); | |
1974 | |
1975 bool threadIsSuspended; | |
1976 do { | |
1977 thread->set_suspend_equivalent(); | |
1978 // cleared by handle_special_suspend_equivalent_condition() or java_suspend_self() | |
1979 ret = ::WaitForSingleObject(sig_sem, INFINITE); | |
1980 assert(ret == WAIT_OBJECT_0, "WaitForSingleObject() failed"); | |
1981 | |
1982 // were we externally suspended while we were waiting? | |
1983 threadIsSuspended = thread->handle_special_suspend_equivalent_condition(); | |
1984 if (threadIsSuspended) { | |
1985 // | |
1986 // The semaphore has been incremented, but while we were waiting | |
1987 // another thread suspended us. We don't want to continue running | |
1988 // while suspended because that would surprise the thread that | |
1989 // suspended us. | |
1990 // | |
1991 ret = ::ReleaseSemaphore(sig_sem, 1, NULL); | |
1992 assert(ret != 0, "ReleaseSemaphore() failed"); | |
1993 | |
1994 thread->java_suspend_self(); | |
1995 } | |
1996 } while (threadIsSuspended); | |
1997 } | |
1998 } | |
1999 | |
2000 int os::signal_lookup() { | |
2001 return check_pending_signals(false); | |
2002 } | |
2003 | |
2004 int os::signal_wait() { | |
2005 return check_pending_signals(true); | |
2006 } | |
2007 | |
2008 // Implicit OS exception handling | |
2009 | |
2010 LONG Handle_Exception(struct _EXCEPTION_POINTERS* exceptionInfo, address handler) { | |
2011 JavaThread* thread = JavaThread::current(); | |
2012 // Save pc in thread | |
2013 #ifdef _M_IA64 | |
2014 thread->set_saved_exception_pc((address)exceptionInfo->ContextRecord->StIIP); | |
2015 // Set pc to handler | |
2016 exceptionInfo->ContextRecord->StIIP = (DWORD64)handler; | |
2017 #elif _M_AMD64 | |
2018 thread->set_saved_exception_pc((address)exceptionInfo->ContextRecord->Rip); | |
2019 // Set pc to handler | |
2020 exceptionInfo->ContextRecord->Rip = (DWORD64)handler; | |
2021 #else | |
2022 thread->set_saved_exception_pc((address)exceptionInfo->ContextRecord->Eip); | |
2023 // Set pc to handler | |
2024 exceptionInfo->ContextRecord->Eip = (LONG)handler; | |
2025 #endif | |
2026 | |
2027 // Continue the execution | |
2028 return EXCEPTION_CONTINUE_EXECUTION; | |
2029 } | |
2030 | |
2031 | |
2032 // Used for PostMortemDump | |
2033 extern "C" void safepoints(); | |
2034 extern "C" void find(int x); | |
2035 extern "C" void events(); | |
2036 | |
2037 // According to Windows API documentation, an illegal instruction sequence should generate | |
2038 // the 0xC000001C exception code. However, real world experience shows that occasionnaly | |
2039 // the execution of an illegal instruction can generate the exception code 0xC000001E. This | |
2040 // seems to be an undocumented feature of Win NT 4.0 (and probably other Windows systems). | |
2041 | |
2042 #define EXCEPTION_ILLEGAL_INSTRUCTION_2 0xC000001E | |
2043 | |
2044 // From "Execution Protection in the Windows Operating System" draft 0.35 | |
2045 // Once a system header becomes available, the "real" define should be | |
2046 // included or copied here. | |
2047 #define EXCEPTION_INFO_EXEC_VIOLATION 0x08 | |
2048 | |
2049 #define def_excpt(val) #val, val | |
2050 | |
2051 struct siglabel { | |
2052 char *name; | |
2053 int number; | |
2054 }; | |
2055 | |
2068
1e637defdda6
6961186: Better VM handling of unexpected exceptions from application native code
zgu
parents:
2023
diff
changeset
|
2056 // All Visual C++ exceptions thrown from code generated by the Microsoft Visual |
1e637defdda6
6961186: Better VM handling of unexpected exceptions from application native code
zgu
parents:
2023
diff
changeset
|
2057 // C++ compiler contain this error code. Because this is a compiler-generated |
1e637defdda6
6961186: Better VM handling of unexpected exceptions from application native code
zgu
parents:
2023
diff
changeset
|
2058 // error, the code is not listed in the Win32 API header files. |
1e637defdda6
6961186: Better VM handling of unexpected exceptions from application native code
zgu
parents:
2023
diff
changeset
|
2059 // The code is actually a cryptic mnemonic device, with the initial "E" |
1e637defdda6
6961186: Better VM handling of unexpected exceptions from application native code
zgu
parents:
2023
diff
changeset
|
2060 // standing for "exception" and the final 3 bytes (0x6D7363) representing the |
1e637defdda6
6961186: Better VM handling of unexpected exceptions from application native code
zgu
parents:
2023
diff
changeset
|
2061 // ASCII values of "msc". |
1e637defdda6
6961186: Better VM handling of unexpected exceptions from application native code
zgu
parents:
2023
diff
changeset
|
2062 |
1e637defdda6
6961186: Better VM handling of unexpected exceptions from application native code
zgu
parents:
2023
diff
changeset
|
2063 #define EXCEPTION_UNCAUGHT_CXX_EXCEPTION 0xE06D7363 |
1e637defdda6
6961186: Better VM handling of unexpected exceptions from application native code
zgu
parents:
2023
diff
changeset
|
2064 |
1e637defdda6
6961186: Better VM handling of unexpected exceptions from application native code
zgu
parents:
2023
diff
changeset
|
2065 |
0 | 2066 struct siglabel exceptlabels[] = { |
2067 def_excpt(EXCEPTION_ACCESS_VIOLATION), | |
2068 def_excpt(EXCEPTION_DATATYPE_MISALIGNMENT), | |
2069 def_excpt(EXCEPTION_BREAKPOINT), | |
2070 def_excpt(EXCEPTION_SINGLE_STEP), | |
2071 def_excpt(EXCEPTION_ARRAY_BOUNDS_EXCEEDED), | |
2072 def_excpt(EXCEPTION_FLT_DENORMAL_OPERAND), | |
2073 def_excpt(EXCEPTION_FLT_DIVIDE_BY_ZERO), | |
2074 def_excpt(EXCEPTION_FLT_INEXACT_RESULT), | |
2075 def_excpt(EXCEPTION_FLT_INVALID_OPERATION), | |
2076 def_excpt(EXCEPTION_FLT_OVERFLOW), | |
2077 def_excpt(EXCEPTION_FLT_STACK_CHECK), | |
2078 def_excpt(EXCEPTION_FLT_UNDERFLOW), | |
2079 def_excpt(EXCEPTION_INT_DIVIDE_BY_ZERO), | |
2080 def_excpt(EXCEPTION_INT_OVERFLOW), | |
2081 def_excpt(EXCEPTION_PRIV_INSTRUCTION), | |
2082 def_excpt(EXCEPTION_IN_PAGE_ERROR), | |
2083 def_excpt(EXCEPTION_ILLEGAL_INSTRUCTION), | |
2084 def_excpt(EXCEPTION_ILLEGAL_INSTRUCTION_2), | |
2085 def_excpt(EXCEPTION_NONCONTINUABLE_EXCEPTION), | |
2086 def_excpt(EXCEPTION_STACK_OVERFLOW), | |
2087 def_excpt(EXCEPTION_INVALID_DISPOSITION), | |
2088 def_excpt(EXCEPTION_GUARD_PAGE), | |
2089 def_excpt(EXCEPTION_INVALID_HANDLE), | |
2068
1e637defdda6
6961186: Better VM handling of unexpected exceptions from application native code
zgu
parents:
2023
diff
changeset
|
2090 def_excpt(EXCEPTION_UNCAUGHT_CXX_EXCEPTION), |
0 | 2091 NULL, 0 |
2092 }; | |
2093 | |
2094 const char* os::exception_name(int exception_code, char *buf, size_t size) { | |
2095 for (int i = 0; exceptlabels[i].name != NULL; i++) { | |
2096 if (exceptlabels[i].number == exception_code) { | |
2097 jio_snprintf(buf, size, "%s", exceptlabels[i].name); | |
2098 return buf; | |
2099 } | |
2100 } | |
2101 | |
2102 return NULL; | |
2103 } | |
2104 | |
2105 //----------------------------------------------------------------------------- | |
2106 LONG Handle_IDiv_Exception(struct _EXCEPTION_POINTERS* exceptionInfo) { | |
2107 // handle exception caused by idiv; should only happen for -MinInt/-1 | |
2108 // (division by zero is handled explicitly) | |
2109 #ifdef _M_IA64 | |
2110 assert(0, "Fix Handle_IDiv_Exception"); | |
2111 #elif _M_AMD64 | |
2112 PCONTEXT ctx = exceptionInfo->ContextRecord; | |
2113 address pc = (address)ctx->Rip; | |
4979
18a5539bf19b
More diff vs hsx24 optimizations.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
4970
diff
changeset
|
2114 #ifndef GRAAL |
0 | 2115 assert(pc[0] == 0xF7, "not an idiv opcode"); |
2116 assert((pc[1] & ~0x7) == 0xF8, "cannot handle non-register operands"); | |
2117 assert(ctx->Rax == min_jint, "unexpected idiv exception"); | |
4979
18a5539bf19b
More diff vs hsx24 optimizations.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
4970
diff
changeset
|
2118 #endif |
0 | 2119 // set correct result values and continue after idiv instruction |
2120 ctx->Rip = (DWORD)pc + 2; // idiv reg, reg is 2 bytes | |
2121 ctx->Rax = (DWORD)min_jint; // result | |
2122 ctx->Rdx = (DWORD)0; // remainder | |
2123 // Continue the execution | |
2124 #else | |
2125 PCONTEXT ctx = exceptionInfo->ContextRecord; | |
2126 address pc = (address)ctx->Eip; | |
2127 assert(pc[0] == 0xF7, "not an idiv opcode"); | |
2128 assert((pc[1] & ~0x7) == 0xF8, "cannot handle non-register operands"); | |
2129 assert(ctx->Eax == min_jint, "unexpected idiv exception"); | |
2130 // set correct result values and continue after idiv instruction | |
2131 ctx->Eip = (DWORD)pc + 2; // idiv reg, reg is 2 bytes | |
2132 ctx->Eax = (DWORD)min_jint; // result | |
2133 ctx->Edx = (DWORD)0; // remainder | |
2134 // Continue the execution | |
2135 #endif | |
2136 return EXCEPTION_CONTINUE_EXECUTION; | |
2137 } | |
2138 | |
2139 #ifndef _WIN64 | |
2140 //----------------------------------------------------------------------------- | |
2141 LONG WINAPI Handle_FLT_Exception(struct _EXCEPTION_POINTERS* exceptionInfo) { | |
1214
0fc941df6fb7
6918421: 1/1 in-process JVM now ignores preset Windows unhandled exception filter
dcubed
parents:
477
diff
changeset
|
2142 // handle exception caused by native method modifying control word |
0 | 2143 PCONTEXT ctx = exceptionInfo->ContextRecord; |
2144 DWORD exception_code = exceptionInfo->ExceptionRecord->ExceptionCode; | |
2145 | |
2146 switch (exception_code) { | |
2147 case EXCEPTION_FLT_DENORMAL_OPERAND: | |
2148 case EXCEPTION_FLT_DIVIDE_BY_ZERO: | |
2149 case EXCEPTION_FLT_INEXACT_RESULT: | |
2150 case EXCEPTION_FLT_INVALID_OPERATION: | |
2151 case EXCEPTION_FLT_OVERFLOW: | |
2152 case EXCEPTION_FLT_STACK_CHECK: | |
2153 case EXCEPTION_FLT_UNDERFLOW: | |
2154 jint fp_control_word = (* (jint*) StubRoutines::addr_fpu_cntrl_wrd_std()); | |
2155 if (fp_control_word != ctx->FloatSave.ControlWord) { | |
2156 // Restore FPCW and mask out FLT exceptions | |
2157 ctx->FloatSave.ControlWord = fp_control_word | 0xffffffc0; | |
2158 // Mask out pending FLT exceptions | |
2159 ctx->FloatSave.StatusWord &= 0xffffff00; | |
2160 return EXCEPTION_CONTINUE_EXECUTION; | |
2161 } | |
2162 } | |
1214
0fc941df6fb7
6918421: 1/1 in-process JVM now ignores preset Windows unhandled exception filter
dcubed
parents:
477
diff
changeset
|
2163 |
0fc941df6fb7
6918421: 1/1 in-process JVM now ignores preset Windows unhandled exception filter
dcubed
parents:
477
diff
changeset
|
2164 if (prev_uef_handler != NULL) { |
0fc941df6fb7
6918421: 1/1 in-process JVM now ignores preset Windows unhandled exception filter
dcubed
parents:
477
diff
changeset
|
2165 // We didn't handle this exception so pass it to the previous |
0fc941df6fb7
6918421: 1/1 in-process JVM now ignores preset Windows unhandled exception filter
dcubed
parents:
477
diff
changeset
|
2166 // UnhandledExceptionFilter. |
0fc941df6fb7
6918421: 1/1 in-process JVM now ignores preset Windows unhandled exception filter
dcubed
parents:
477
diff
changeset
|
2167 return (prev_uef_handler)(exceptionInfo); |
0fc941df6fb7
6918421: 1/1 in-process JVM now ignores preset Windows unhandled exception filter
dcubed
parents:
477
diff
changeset
|
2168 } |
0fc941df6fb7
6918421: 1/1 in-process JVM now ignores preset Windows unhandled exception filter
dcubed
parents:
477
diff
changeset
|
2169 |
0 | 2170 return EXCEPTION_CONTINUE_SEARCH; |
2171 } | |
2172 #else //_WIN64 | |
2173 /* | |
2174 On Windows, the mxcsr control bits are non-volatile across calls | |
2175 See also CR 6192333 | |
2176 If EXCEPTION_FLT_* happened after some native method modified | |
2177 mxcsr - it is not a jvm fault. | |
2178 However should we decide to restore of mxcsr after a faulty | |
2179 native method we can uncomment following code | |
2180 jint MxCsr = INITIAL_MXCSR; | |
2181 // we can't use StubRoutines::addr_mxcsr_std() | |
2182 // because in Win64 mxcsr is not saved there | |
2183 if (MxCsr != ctx->MxCsr) { | |
2184 ctx->MxCsr = MxCsr; | |
2185 return EXCEPTION_CONTINUE_EXECUTION; | |
2186 } | |
2187 | |
2188 */ | |
2189 #endif //_WIN64 | |
2190 | |
2191 | |
2192 // Fatal error reporting is single threaded so we can make this a | |
2193 // static and preallocated. If it's more than MAX_PATH silently ignore | |
2194 // it. | |
2195 static char saved_error_file[MAX_PATH] = {0}; | |
2196 | |
2197 void os::set_error_file(const char *logfile) { | |
2198 if (strlen(logfile) <= MAX_PATH) { | |
2199 strncpy(saved_error_file, logfile, MAX_PATH); | |
2200 } | |
2201 } | |
2202 | |
2203 static inline void report_error(Thread* t, DWORD exception_code, | |
2204 address addr, void* siginfo, void* context) { | |
2205 VMError err(t, exception_code, addr, siginfo, context); | |
2206 err.report_and_die(); | |
2207 | |
2208 // If UseOsErrorReporting, this will return here and save the error file | |
2209 // somewhere where we can find it in the minidump. | |
2210 } | |
2211 | |
2212 //----------------------------------------------------------------------------- | |
2213 LONG WINAPI topLevelExceptionFilter(struct _EXCEPTION_POINTERS* exceptionInfo) { | |
2214 if (InterceptOSException) return EXCEPTION_CONTINUE_SEARCH; | |
2215 DWORD exception_code = exceptionInfo->ExceptionRecord->ExceptionCode; | |
2216 #ifdef _M_IA64 | |
2217 address pc = (address) exceptionInfo->ContextRecord->StIIP; | |
2218 #elif _M_AMD64 | |
2219 address pc = (address) exceptionInfo->ContextRecord->Rip; | |
2220 #else | |
2221 address pc = (address) exceptionInfo->ContextRecord->Eip; | |
2222 #endif | |
2223 Thread* t = ThreadLocalStorage::get_thread_slow(); // slow & steady | |
2224 | |
2225 #ifndef _WIN64 | |
2226 // Execution protection violation - win32 running on AMD64 only | |
2227 // Handled first to avoid misdiagnosis as a "normal" access violation; | |
2228 // This is safe to do because we have a new/unique ExceptionInformation | |
2229 // code for this condition. | |
2230 if (exception_code == EXCEPTION_ACCESS_VIOLATION) { | |
2231 PEXCEPTION_RECORD exceptionRecord = exceptionInfo->ExceptionRecord; | |
2232 int exception_subcode = (int) exceptionRecord->ExceptionInformation[0]; | |
2233 address addr = (address) exceptionRecord->ExceptionInformation[1]; | |
2234 | |
2235 if (exception_subcode == EXCEPTION_INFO_EXEC_VIOLATION) { | |
2236 int page_size = os::vm_page_size(); | |
2237 | |
2238 // Make sure the pc and the faulting address are sane. | |
2239 // | |
2240 // If an instruction spans a page boundary, and the page containing | |
2241 // the beginning of the instruction is executable but the following | |
2242 // page is not, the pc and the faulting address might be slightly | |
2243 // different - we still want to unguard the 2nd page in this case. | |
2244 // | |
2245 // 15 bytes seems to be a (very) safe value for max instruction size. | |
2246 bool pc_is_near_addr = | |
2247 (pointer_delta((void*) addr, (void*) pc, sizeof(char)) < 15); | |
2248 bool instr_spans_page_boundary = | |
2249 (align_size_down((intptr_t) pc ^ (intptr_t) addr, | |
2250 (intptr_t) page_size) > 0); | |
2251 | |
2252 if (pc == addr || (pc_is_near_addr && instr_spans_page_boundary)) { | |
2253 static volatile address last_addr = | |
2254 (address) os::non_memory_address_word(); | |
2255 | |
2256 // In conservative mode, don't unguard unless the address is in the VM | |
2257 if (UnguardOnExecutionViolation > 0 && addr != last_addr && | |
2258 (UnguardOnExecutionViolation > 1 || os::address_is_in_vm(addr))) { | |
2259 | |
477
24fda36852ce
6727377: VM stack guard pages on Windows should PAGE_READWRITE not PAGE_EXECUTE_READWRITE
coleenp
parents:
467
diff
changeset
|
2260 // Set memory to RWX and retry |
0 | 2261 address page_start = |
2262 (address) align_size_down((intptr_t) addr, (intptr_t) page_size); | |
477
24fda36852ce
6727377: VM stack guard pages on Windows should PAGE_READWRITE not PAGE_EXECUTE_READWRITE
coleenp
parents:
467
diff
changeset
|
2263 bool res = os::protect_memory((char*) page_start, page_size, |
24fda36852ce
6727377: VM stack guard pages on Windows should PAGE_READWRITE not PAGE_EXECUTE_READWRITE
coleenp
parents:
467
diff
changeset
|
2264 os::MEM_PROT_RWX); |
0 | 2265 |
2266 if (PrintMiscellaneous && Verbose) { | |
2267 char buf[256]; | |
2268 jio_snprintf(buf, sizeof(buf), "Execution protection violation " | |
2269 "at " INTPTR_FORMAT | |
2270 ", unguarding " INTPTR_FORMAT ": %s", addr, | |
2271 page_start, (res ? "success" : strerror(errno))); | |
2272 tty->print_raw_cr(buf); | |
2273 } | |
2274 | |
2275 // Set last_addr so if we fault again at the same address, we don't | |
2276 // end up in an endless loop. | |
2277 // | |
2278 // There are two potential complications here. Two threads trapping | |
2279 // at the same address at the same time could cause one of the | |
2280 // threads to think it already unguarded, and abort the VM. Likely | |
2281 // very rare. | |
2282 // | |
2283 // The other race involves two threads alternately trapping at | |
2284 // different addresses and failing to unguard the page, resulting in | |
2285 // an endless loop. This condition is probably even more unlikely | |
2286 // than the first. | |
2287 // | |
2288 // Although both cases could be avoided by using locks or thread | |
2289 // local last_addr, these solutions are unnecessary complication: | |
2290 // this handler is a best-effort safety net, not a complete solution. | |
2291 // It is disabled by default and should only be used as a workaround | |
2292 // in case we missed any no-execute-unsafe VM code. | |
2293 | |
2294 last_addr = addr; | |
2295 | |
2296 return EXCEPTION_CONTINUE_EXECUTION; | |
2297 } | |
2298 } | |
2299 | |
2300 // Last unguard failed or not unguarding | |
2301 tty->print_raw_cr("Execution protection violation"); | |
2302 report_error(t, exception_code, addr, exceptionInfo->ExceptionRecord, | |
2303 exceptionInfo->ContextRecord); | |
2304 return EXCEPTION_CONTINUE_SEARCH; | |
2305 } | |
2306 } | |
2307 #endif // _WIN64 | |
2308 | |
2309 // Check to see if we caught the safepoint code in the | |
2310 // process of write protecting the memory serialization page. | |
2311 // It write enables the page immediately after protecting it | |
2312 // so just return. | |
2313 if ( exception_code == EXCEPTION_ACCESS_VIOLATION ) { | |
2314 JavaThread* thread = (JavaThread*) t; | |
2315 PEXCEPTION_RECORD exceptionRecord = exceptionInfo->ExceptionRecord; | |
2316 address addr = (address) exceptionRecord->ExceptionInformation[1]; | |
2317 if ( os::is_memory_serialize_page(thread, addr) ) { | |
2318 // Block current thread until the memory serialize page permission restored. | |
2319 os::block_on_serialize_page_trap(); | |
2320 return EXCEPTION_CONTINUE_EXECUTION; | |
2321 } | |
2322 } | |
2323 | |
2324 if (t != NULL && t->is_Java_thread()) { | |
2325 JavaThread* thread = (JavaThread*) t; | |
2326 bool in_java = thread->thread_state() == _thread_in_Java; | |
2327 | |
2328 // Handle potential stack overflows up front. | |
2329 if (exception_code == EXCEPTION_STACK_OVERFLOW) { | |
2330 if (os::uses_stack_guard_pages()) { | |
2331 #ifdef _M_IA64 | |
2332 // | |
2333 // If it's a legal stack address continue, Windows will map it in. | |
2334 // | |
2335 PEXCEPTION_RECORD exceptionRecord = exceptionInfo->ExceptionRecord; | |
2336 address addr = (address) exceptionRecord->ExceptionInformation[1]; | |
2337 if (addr > thread->stack_yellow_zone_base() && addr < thread->stack_base() ) | |
2338 return EXCEPTION_CONTINUE_EXECUTION; | |
2339 | |
2340 // The register save area is the same size as the memory stack | |
2341 // and starts at the page just above the start of the memory stack. | |
2342 // If we get a fault in this area, we've run out of register | |
2343 // stack. If we are in java, try throwing a stack overflow exception. | |
2344 if (addr > thread->stack_base() && | |
2345 addr <= (thread->stack_base()+thread->stack_size()) ) { | |
2346 char buf[256]; | |
2347 jio_snprintf(buf, sizeof(buf), | |
2348 "Register stack overflow, addr:%p, stack_base:%p\n", | |
2349 addr, thread->stack_base() ); | |
2350 tty->print_raw_cr(buf); | |
2351 // If not in java code, return and hope for the best. | |
2352 return in_java ? Handle_Exception(exceptionInfo, | |
2353 SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::STACK_OVERFLOW)) | |
2354 : EXCEPTION_CONTINUE_EXECUTION; | |
2355 } | |
2356 #endif | |
2357 if (thread->stack_yellow_zone_enabled()) { | |
2358 // Yellow zone violation. The o/s has unprotected the first yellow | |
2359 // zone page for us. Note: must call disable_stack_yellow_zone to | |
2360 // update the enabled status, even if the zone contains only one page. | |
2361 thread->disable_stack_yellow_zone(); | |
2362 // If not in java code, return and hope for the best. | |
2363 return in_java ? Handle_Exception(exceptionInfo, | |
2364 SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::STACK_OVERFLOW)) | |
2365 : EXCEPTION_CONTINUE_EXECUTION; | |
2366 } else { | |
2367 // Fatal red zone violation. | |
2368 thread->disable_stack_red_zone(); | |
2369 tty->print_raw_cr("An unrecoverable stack overflow has occurred."); | |
2370 report_error(t, exception_code, pc, exceptionInfo->ExceptionRecord, | |
2371 exceptionInfo->ContextRecord); | |
2372 return EXCEPTION_CONTINUE_SEARCH; | |
2373 } | |
2374 } else if (in_java) { | |
2375 // JVM-managed guard pages cannot be used on win95/98. The o/s provides | |
2376 // a one-time-only guard page, which it has released to us. The next | |
2377 // stack overflow on this thread will result in an ACCESS_VIOLATION. | |
2378 return Handle_Exception(exceptionInfo, | |
2379 SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::STACK_OVERFLOW)); | |
2380 } else { | |
2381 // Can only return and hope for the best. Further stack growth will | |
2382 // result in an ACCESS_VIOLATION. | |
2383 return EXCEPTION_CONTINUE_EXECUTION; | |
2384 } | |
2385 } else if (exception_code == EXCEPTION_ACCESS_VIOLATION) { | |
2386 // Either stack overflow or null pointer exception. | |
2387 if (in_java) { | |
2388 PEXCEPTION_RECORD exceptionRecord = exceptionInfo->ExceptionRecord; | |
2389 address addr = (address) exceptionRecord->ExceptionInformation[1]; | |
2390 address stack_end = thread->stack_base() - thread->stack_size(); | |
2391 if (addr < stack_end && addr >= stack_end - os::vm_page_size()) { | |
2392 // Stack overflow. | |
2393 assert(!os::uses_stack_guard_pages(), | |
2394 "should be caught by red zone code above."); | |
2395 return Handle_Exception(exceptionInfo, | |
2396 SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::STACK_OVERFLOW)); | |
2397 } | |
2398 // | |
2399 // Check for safepoint polling and implicit null | |
2400 // We only expect null pointers in the stubs (vtable) | |
2401 // the rest are checked explicitly now. | |
2402 // | |
2403 CodeBlob* cb = CodeCache::find_blob(pc); | |
2404 if (cb != NULL) { | |
2405 if (os::is_poll_address(addr)) { | |
2406 address stub = SharedRuntime::get_poll_stub(pc); | |
2407 return Handle_Exception(exceptionInfo, stub); | |
2408 } | |
2409 } | |
2410 { | |
2411 #ifdef _WIN64 | |
2412 // | |
2413 // If it's a legal stack address map the entire region in | |
2414 // | |
2415 PEXCEPTION_RECORD exceptionRecord = exceptionInfo->ExceptionRecord; | |
2416 address addr = (address) exceptionRecord->ExceptionInformation[1]; | |
2417 if (addr > thread->stack_yellow_zone_base() && addr < thread->stack_base() ) { | |
2418 addr = (address)((uintptr_t)addr & | |
2419 (~((uintptr_t)os::vm_page_size() - (uintptr_t)1))); | |
656 | 2420 os::commit_memory((char *)addr, thread->stack_base() - addr, |
2421 false ); | |
0 | 2422 return EXCEPTION_CONTINUE_EXECUTION; |
2423 } | |
2424 else | |
2425 #endif | |
2426 { | |
2427 // Null pointer exception. | |
2428 #ifdef _M_IA64 | |
2429 // We catch register stack overflows in compiled code by doing | |
2430 // an explicit compare and executing a st8(G0, G0) if the | |
2431 // BSP enters into our guard area. We test for the overflow | |
2432 // condition and fall into the normal null pointer exception | |
2433 // code if BSP hasn't overflowed. | |
2434 if ( in_java ) { | |
2435 if(thread->register_stack_overflow()) { | |
2436 assert((address)exceptionInfo->ContextRecord->IntS3 == | |
2437 thread->register_stack_limit(), | |
2438 "GR7 doesn't contain register_stack_limit"); | |
2439 // Disable the yellow zone which sets the state that | |
2440 // we've got a stack overflow problem. | |
2441 if (thread->stack_yellow_zone_enabled()) { | |
2442 thread->disable_stack_yellow_zone(); | |
2443 } | |
2444 // Give us some room to process the exception | |
2445 thread->disable_register_stack_guard(); | |
2446 // Update GR7 with the new limit so we can continue running | |
2447 // compiled code. | |
2448 exceptionInfo->ContextRecord->IntS3 = | |
2449 (ULONGLONG)thread->register_stack_limit(); | |
2450 return Handle_Exception(exceptionInfo, | |
2451 SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::STACK_OVERFLOW)); | |
2452 } else { | |
2453 // | |
2454 // Check for implicit null | |
2455 // We only expect null pointers in the stubs (vtable) | |
2456 // the rest are checked explicitly now. | |
2457 // | |
465
dc16daa0329d
6739363: Xcheck jni doesn't check native function arguments
poonam
parents:
389
diff
changeset
|
2458 if (((uintptr_t)addr) < os::vm_page_size() ) { |
dc16daa0329d
6739363: Xcheck jni doesn't check native function arguments
poonam
parents:
389
diff
changeset
|
2459 // an access to the first page of VM--assume it is a null pointer |
dc16daa0329d
6739363: Xcheck jni doesn't check native function arguments
poonam
parents:
389
diff
changeset
|
2460 address stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL); |
dc16daa0329d
6739363: Xcheck jni doesn't check native function arguments
poonam
parents:
389
diff
changeset
|
2461 if (stub != NULL) return Handle_Exception(exceptionInfo, stub); |
0 | 2462 } |
2463 } | |
2464 } // in_java | |
2465 | |
2466 // IA64 doesn't use implicit null checking yet. So we shouldn't | |
2467 // get here. | |
2468 tty->print_raw_cr("Access violation, possible null pointer exception"); | |
2469 report_error(t, exception_code, pc, exceptionInfo->ExceptionRecord, | |
2470 exceptionInfo->ContextRecord); | |
2471 return EXCEPTION_CONTINUE_SEARCH; | |
2472 #else /* !IA64 */ | |
2473 | |
2474 // Windows 98 reports faulting addresses incorrectly | |
2475 if (!MacroAssembler::needs_explicit_null_check((intptr_t)addr) || | |
2476 !os::win32::is_nt()) { | |
465
dc16daa0329d
6739363: Xcheck jni doesn't check native function arguments
poonam
parents:
389
diff
changeset
|
2477 address stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL); |
dc16daa0329d
6739363: Xcheck jni doesn't check native function arguments
poonam
parents:
389
diff
changeset
|
2478 if (stub != NULL) return Handle_Exception(exceptionInfo, stub); |
0 | 2479 } |
2480 report_error(t, exception_code, pc, exceptionInfo->ExceptionRecord, | |
2481 exceptionInfo->ContextRecord); | |
2482 return EXCEPTION_CONTINUE_SEARCH; | |
2483 #endif | |
2484 } | |
2485 } | |
2486 } | |
2487 | |
2488 #ifdef _WIN64 | |
2489 // Special care for fast JNI field accessors. | |
2490 // jni_fast_Get<Primitive>Field can trap at certain pc's if a GC kicks | |
2491 // in and the heap gets shrunk before the field access. | |
2492 if (exception_code == EXCEPTION_ACCESS_VIOLATION) { | |
2493 address addr = JNI_FastGetField::find_slowcase_pc(pc); | |
2494 if (addr != (address)-1) { | |
2495 return Handle_Exception(exceptionInfo, addr); | |
2496 } | |
2497 } | |
2498 #endif | |
2499 | |
2500 #ifdef _WIN64 | |
2501 // Windows will sometimes generate an access violation | |
2502 // when we call malloc. Since we use VectoredExceptions | |
2503 // on 64 bit platforms, we see this exception. We must | |
2504 // pass this exception on so Windows can recover. | |
2505 // We check to see if the pc of the fault is in NTDLL.DLL | |
2506 // if so, we pass control on to Windows for handling. | |
2507 if (UseVectoredExceptions && _addr_in_ntdll(pc)) return EXCEPTION_CONTINUE_SEARCH; | |
2508 #endif | |
2509 | |
2510 // Stack overflow or null pointer exception in native code. | |
2511 report_error(t, exception_code, pc, exceptionInfo->ExceptionRecord, | |
2512 exceptionInfo->ContextRecord); | |
2513 return EXCEPTION_CONTINUE_SEARCH; | |
2514 } | |
2515 | |
2516 if (in_java) { | |
2517 switch (exception_code) { | |
2518 case EXCEPTION_INT_DIVIDE_BY_ZERO: | |
2519 return Handle_Exception(exceptionInfo, SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_DIVIDE_BY_ZERO)); | |
2520 | |
2521 case EXCEPTION_INT_OVERFLOW: | |
2522 return Handle_IDiv_Exception(exceptionInfo); | |
2523 | |
2524 } // switch | |
2525 } | |
2526 #ifndef _WIN64 | |
2068
1e637defdda6
6961186: Better VM handling of unexpected exceptions from application native code
zgu
parents:
2023
diff
changeset
|
2527 if (((thread->thread_state() == _thread_in_Java) || |
1e637defdda6
6961186: Better VM handling of unexpected exceptions from application native code
zgu
parents:
2023
diff
changeset
|
2528 (thread->thread_state() == _thread_in_native)) && |
1e637defdda6
6961186: Better VM handling of unexpected exceptions from application native code
zgu
parents:
2023
diff
changeset
|
2529 exception_code != EXCEPTION_UNCAUGHT_CXX_EXCEPTION) |
0 | 2530 { |
2531 LONG result=Handle_FLT_Exception(exceptionInfo); | |
2532 if (result==EXCEPTION_CONTINUE_EXECUTION) return result; | |
2533 } | |
2534 #endif //_WIN64 | |
2535 } | |
2536 | |
2537 if (exception_code != EXCEPTION_BREAKPOINT) { | |
2538 #ifndef _WIN64 | |
2539 report_error(t, exception_code, pc, exceptionInfo->ExceptionRecord, | |
2540 exceptionInfo->ContextRecord); | |
2541 #else | |
2542 // Itanium Windows uses a VectoredExceptionHandler | |
2543 // Which means that C++ programatic exception handlers (try/except) | |
2544 // will get here. Continue the search for the right except block if | |
2545 // the exception code is not a fatal code. | |
2546 switch ( exception_code ) { | |
2547 case EXCEPTION_ACCESS_VIOLATION: | |
2548 case EXCEPTION_STACK_OVERFLOW: | |
2549 case EXCEPTION_ILLEGAL_INSTRUCTION: | |
2550 case EXCEPTION_ILLEGAL_INSTRUCTION_2: | |
2551 case EXCEPTION_INT_OVERFLOW: | |
2552 case EXCEPTION_INT_DIVIDE_BY_ZERO: | |
2068
1e637defdda6
6961186: Better VM handling of unexpected exceptions from application native code
zgu
parents:
2023
diff
changeset
|
2553 case EXCEPTION_UNCAUGHT_CXX_EXCEPTION: |
0 | 2554 { report_error(t, exception_code, pc, exceptionInfo->ExceptionRecord, |
2555 exceptionInfo->ContextRecord); | |
2556 } | |
2557 break; | |
2558 default: | |
2559 break; | |
2560 } | |
2561 #endif | |
2562 } | |
2563 return EXCEPTION_CONTINUE_SEARCH; | |
2564 } | |
2565 | |
2566 #ifndef _WIN64 | |
2567 // Special care for fast JNI accessors. | |
2568 // jni_fast_Get<Primitive>Field can trap at certain pc's if a GC kicks in and | |
2569 // the heap gets shrunk before the field access. | |
2570 // Need to install our own structured exception handler since native code may | |
2571 // install its own. | |
2572 LONG WINAPI fastJNIAccessorExceptionFilter(struct _EXCEPTION_POINTERS* exceptionInfo) { | |
2573 DWORD exception_code = exceptionInfo->ExceptionRecord->ExceptionCode; | |
2574 if (exception_code == EXCEPTION_ACCESS_VIOLATION) { | |
2575 address pc = (address) exceptionInfo->ContextRecord->Eip; | |
2576 address addr = JNI_FastGetField::find_slowcase_pc(pc); | |
2577 if (addr != (address)-1) { | |
2578 return Handle_Exception(exceptionInfo, addr); | |
2579 } | |
2580 } | |
2581 return EXCEPTION_CONTINUE_SEARCH; | |
2582 } | |
2583 | |
2584 #define DEFINE_FAST_GETFIELD(Return,Fieldname,Result) \ | |
2585 Return JNICALL jni_fast_Get##Result##Field_wrapper(JNIEnv *env, jobject obj, jfieldID fieldID) { \ | |
2586 __try { \ | |
2587 return (*JNI_FastGetField::jni_fast_Get##Result##Field_fp)(env, obj, fieldID); \ | |
2588 } __except(fastJNIAccessorExceptionFilter((_EXCEPTION_POINTERS*)_exception_info())) { \ | |
2589 } \ | |
2590 return 0; \ | |
2591 } | |
2592 | |
2593 DEFINE_FAST_GETFIELD(jboolean, bool, Boolean) | |
2594 DEFINE_FAST_GETFIELD(jbyte, byte, Byte) | |
2595 DEFINE_FAST_GETFIELD(jchar, char, Char) | |
2596 DEFINE_FAST_GETFIELD(jshort, short, Short) | |
2597 DEFINE_FAST_GETFIELD(jint, int, Int) | |
2598 DEFINE_FAST_GETFIELD(jlong, long, Long) | |
2599 DEFINE_FAST_GETFIELD(jfloat, float, Float) | |
2600 DEFINE_FAST_GETFIELD(jdouble, double, Double) | |
2601 | |
2602 address os::win32::fast_jni_accessor_wrapper(BasicType type) { | |
2603 switch (type) { | |
2604 case T_BOOLEAN: return (address)jni_fast_GetBooleanField_wrapper; | |
2605 case T_BYTE: return (address)jni_fast_GetByteField_wrapper; | |
2606 case T_CHAR: return (address)jni_fast_GetCharField_wrapper; | |
2607 case T_SHORT: return (address)jni_fast_GetShortField_wrapper; | |
2608 case T_INT: return (address)jni_fast_GetIntField_wrapper; | |
2609 case T_LONG: return (address)jni_fast_GetLongField_wrapper; | |
2610 case T_FLOAT: return (address)jni_fast_GetFloatField_wrapper; | |
2611 case T_DOUBLE: return (address)jni_fast_GetDoubleField_wrapper; | |
2612 default: ShouldNotReachHere(); | |
2613 } | |
2614 return (address)-1; | |
2615 } | |
2616 #endif | |
2617 | |
2618 // Virtual Memory | |
2619 | |
2620 int os::vm_page_size() { return os::win32::vm_page_size(); } | |
2621 int os::vm_allocation_granularity() { | |
2622 return os::win32::vm_allocation_granularity(); | |
2623 } | |
2624 | |
2625 // Windows large page support is available on Windows 2003. In order to use | |
2626 // large page memory, the administrator must first assign additional privilege | |
2627 // to the user: | |
2628 // + select Control Panel -> Administrative Tools -> Local Security Policy | |
2629 // + select Local Policies -> User Rights Assignment | |
2630 // + double click "Lock pages in memory", add users and/or groups | |
2631 // + reboot | |
2632 // Note the above steps are needed for administrator as well, as administrators | |
2633 // by default do not have the privilege to lock pages in memory. | |
2634 // | |
2635 // Note about Windows 2003: although the API supports committing large page | |
2636 // memory on a page-by-page basis and VirtualAlloc() returns success under this | |
2637 // scenario, I found through experiment it only uses large page if the entire | |
2638 // memory region is reserved and committed in a single VirtualAlloc() call. | |
2639 // This makes Windows large page support more or less like Solaris ISM, in | |
2640 // that the entire heap must be committed upfront. This probably will change | |
2641 // in the future, if so the code below needs to be revisited. | |
2642 | |
2643 #ifndef MEM_LARGE_PAGES | |
2644 #define MEM_LARGE_PAGES 0x20000000 | |
2645 #endif | |
2646 | |
2647 static HANDLE _hProcess; | |
2648 static HANDLE _hToken; | |
2649 | |
3885 | 2650 // Container for NUMA node list info |
2651 class NUMANodeListHolder { | |
2652 private: | |
2653 int *_numa_used_node_list; // allocated below | |
2654 int _numa_used_node_count; | |
2655 | |
2656 void free_node_list() { | |
2657 if (_numa_used_node_list != NULL) { | |
6197 | 2658 FREE_C_HEAP_ARRAY(int, _numa_used_node_list, mtInternal); |
3885 | 2659 } |
2660 } | |
2661 | |
2662 public: | |
2663 NUMANodeListHolder() { | |
2664 _numa_used_node_count = 0; | |
2665 _numa_used_node_list = NULL; | |
2666 // do rest of initialization in build routine (after function pointers are set up) | |
2667 } | |
2668 | |
2669 ~NUMANodeListHolder() { | |
2670 free_node_list(); | |
2671 } | |
2672 | |
2673 bool build() { | |
2674 DWORD_PTR proc_aff_mask; | |
2675 DWORD_PTR sys_aff_mask; | |
2676 if (!GetProcessAffinityMask(GetCurrentProcess(), &proc_aff_mask, &sys_aff_mask)) return false; | |
2677 ULONG highest_node_number; | |
2678 if (!os::Kernel32Dll::GetNumaHighestNodeNumber(&highest_node_number)) return false; | |
2679 free_node_list(); | |
6197 | 2680 _numa_used_node_list = NEW_C_HEAP_ARRAY(int, highest_node_number + 1, mtInternal); |
3885 | 2681 for (unsigned int i = 0; i <= highest_node_number; i++) { |
2682 ULONGLONG proc_mask_numa_node; | |
2683 if (!os::Kernel32Dll::GetNumaNodeProcessorMask(i, &proc_mask_numa_node)) return false; | |
2684 if ((proc_aff_mask & proc_mask_numa_node)!=0) { | |
2685 _numa_used_node_list[_numa_used_node_count++] = i; | |
2686 } | |
2687 } | |
2688 return (_numa_used_node_count > 1); | |
2689 } | |
2690 | |
2691 int get_count() {return _numa_used_node_count;} | |
2692 int get_node_list_entry(int n) { | |
2693 // for indexes out of range, returns -1 | |
2694 return (n < _numa_used_node_count ? _numa_used_node_list[n] : -1); | |
2695 } | |
2696 | |
2697 } numa_node_list_holder; | |
2698 | |
2699 | |
2700 | |
0 | 2701 static size_t _large_page_size = 0; |
2702 | |
2703 static bool resolve_functions_for_large_page_init() { | |
3833
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
2704 return os::Kernel32Dll::GetLargePageMinimumAvailable() && |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
2705 os::Advapi32Dll::AdvapiAvailable(); |
0 | 2706 } |
2707 | |
2708 static bool request_lock_memory_privilege() { | |
2709 _hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, | |
2710 os::current_process_id()); | |
2711 | |
2712 LUID luid; | |
2713 if (_hProcess != NULL && | |
3833
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
2714 os::Advapi32Dll::OpenProcessToken(_hProcess, TOKEN_ADJUST_PRIVILEGES, &_hToken) && |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
2715 os::Advapi32Dll::LookupPrivilegeValue(NULL, "SeLockMemoryPrivilege", &luid)) { |
0 | 2716 |
2717 TOKEN_PRIVILEGES tp; | |
2718 tp.PrivilegeCount = 1; | |
2719 tp.Privileges[0].Luid = luid; | |
2720 tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; | |
2721 | |
2722 // AdjustTokenPrivileges() may return TRUE even when it couldn't change the | |
2723 // privilege. Check GetLastError() too. See MSDN document. | |
3833
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
2724 if (os::Advapi32Dll::AdjustTokenPrivileges(_hToken, false, &tp, sizeof(tp), NULL, NULL) && |
0 | 2725 (GetLastError() == ERROR_SUCCESS)) { |
2726 return true; | |
2727 } | |
2728 } | |
2729 | |
2730 return false; | |
2731 } | |
2732 | |
2733 static void cleanup_after_large_page_init() { | |
2734 if (_hProcess) CloseHandle(_hProcess); | |
2735 _hProcess = NULL; | |
2736 if (_hToken) CloseHandle(_hToken); | |
2737 _hToken = NULL; | |
2738 } | |
2739 | |
3885 | 2740 static bool numa_interleaving_init() { |
2741 bool success = false; | |
2742 bool use_numa_interleaving_specified = !FLAG_IS_DEFAULT(UseNUMAInterleaving); | |
2743 | |
3918
a6128a8ed624
7086226: UseNUMA fails on old versions of windows
iveresov
parents:
3885
diff
changeset
|
2744 // print a warning if UseNUMAInterleaving flag is specified on command line |
a6128a8ed624
7086226: UseNUMA fails on old versions of windows
iveresov
parents:
3885
diff
changeset
|
2745 bool warn_on_failure = use_numa_interleaving_specified; |
3885 | 2746 # define WARN(msg) if (warn_on_failure) { warning(msg); } |
2747 | |
2748 // NUMAInterleaveGranularity cannot be less than vm_allocation_granularity (or _large_page_size if using large pages) | |
2749 size_t min_interleave_granularity = UseLargePages ? _large_page_size : os::vm_allocation_granularity(); | |
2750 NUMAInterleaveGranularity = align_size_up(NUMAInterleaveGranularity, min_interleave_granularity); | |
2751 | |
2752 if (os::Kernel32Dll::NumaCallsAvailable()) { | |
2753 if (numa_node_list_holder.build()) { | |
2754 if (PrintMiscellaneous && Verbose) { | |
3918
a6128a8ed624
7086226: UseNUMA fails on old versions of windows
iveresov
parents:
3885
diff
changeset
|
2755 tty->print("NUMA UsedNodeCount=%d, namely ", numa_node_list_holder.get_count()); |
3885 | 2756 for (int i = 0; i < numa_node_list_holder.get_count(); i++) { |
2757 tty->print("%d ", numa_node_list_holder.get_node_list_entry(i)); | |
2758 } | |
2759 tty->print("\n"); | |
2760 } | |
2761 success = true; | |
2762 } else { | |
2763 WARN("Process does not cover multiple NUMA nodes."); | |
2764 } | |
2765 } else { | |
2766 WARN("NUMA Interleaving is not supported by the operating system."); | |
2767 } | |
2768 if (!success) { | |
2769 if (use_numa_interleaving_specified) WARN("...Ignoring UseNUMAInterleaving flag."); | |
2770 } | |
2771 return success; | |
2772 #undef WARN | |
2773 } | |
2774 | |
2775 // this routine is used whenever we need to reserve a contiguous VA range | |
2776 // but we need to make separate VirtualAlloc calls for each piece of the range | |
2777 // Reasons for doing this: | |
2778 // * UseLargePagesIndividualAllocation was set (normally only needed on WS2003 but possible to be set otherwise) | |
2779 // * UseNUMAInterleaving requires a separate node for each piece | |
2780 static char* allocate_pages_individually(size_t bytes, char* addr, DWORD flags, DWORD prot, | |
2781 bool should_inject_error=false) { | |
2782 char * p_buf; | |
2783 // note: at setup time we guaranteed that NUMAInterleaveGranularity was aligned up to a page size | |
2784 size_t page_size = UseLargePages ? _large_page_size : os::vm_allocation_granularity(); | |
2785 size_t chunk_size = UseNUMAInterleaving ? NUMAInterleaveGranularity : page_size; | |
2786 | |
2787 // first reserve enough address space in advance since we want to be | |
2788 // able to break a single contiguous virtual address range into multiple | |
2789 // large page commits but WS2003 does not allow reserving large page space | |
2790 // so we just use 4K pages for reserve, this gives us a legal contiguous | |
2791 // address space. then we will deallocate that reservation, and re alloc | |
2792 // using large pages | |
2793 const size_t size_of_reserve = bytes + chunk_size; | |
2794 if (bytes > size_of_reserve) { | |
2795 // Overflowed. | |
2796 return NULL; | |
2797 } | |
2798 p_buf = (char *) VirtualAlloc(addr, | |
2799 size_of_reserve, // size of Reserve | |
2800 MEM_RESERVE, | |
2801 PAGE_READWRITE); | |
2802 // If reservation failed, return NULL | |
2803 if (p_buf == NULL) return NULL; | |
2804 | |
2805 os::release_memory(p_buf, bytes + chunk_size); | |
2806 | |
2807 // we still need to round up to a page boundary (in case we are using large pages) | |
2808 // but not to a chunk boundary (in case InterleavingGranularity doesn't align with page size) | |
2809 // instead we handle this in the bytes_to_rq computation below | |
2810 p_buf = (char *) align_size_up((size_t)p_buf, page_size); | |
2811 | |
2812 // now go through and allocate one chunk at a time until all bytes are | |
2813 // allocated | |
2814 size_t bytes_remaining = bytes; | |
2815 // An overflow of align_size_up() would have been caught above | |
2816 // in the calculation of size_of_reserve. | |
2817 char * next_alloc_addr = p_buf; | |
2818 HANDLE hProc = GetCurrentProcess(); | |
2819 | |
2820 #ifdef ASSERT | |
2821 // Variable for the failure injection | |
2822 long ran_num = os::random(); | |
2823 size_t fail_after = ran_num % bytes; | |
2824 #endif | |
2825 | |
2826 int count=0; | |
2827 while (bytes_remaining) { | |
2828 // select bytes_to_rq to get to the next chunk_size boundary | |
2829 | |
2830 size_t bytes_to_rq = MIN2(bytes_remaining, chunk_size - ((size_t)next_alloc_addr % chunk_size)); | |
2831 // Note allocate and commit | |
2832 char * p_new; | |
2833 | |
2834 #ifdef ASSERT | |
2835 bool inject_error_now = should_inject_error && (bytes_remaining <= fail_after); | |
2836 #else | |
2837 const bool inject_error_now = false; | |
2838 #endif | |
2839 | |
2840 if (inject_error_now) { | |
2841 p_new = NULL; | |
2842 } else { | |
2843 if (!UseNUMAInterleaving) { | |
2844 p_new = (char *) VirtualAlloc(next_alloc_addr, | |
2845 bytes_to_rq, | |
2846 flags, | |
2847 prot); | |
2848 } else { | |
2849 // get the next node to use from the used_node_list | |
3918
a6128a8ed624
7086226: UseNUMA fails on old versions of windows
iveresov
parents:
3885
diff
changeset
|
2850 assert(numa_node_list_holder.get_count() > 0, "Multiple NUMA nodes expected"); |
a6128a8ed624
7086226: UseNUMA fails on old versions of windows
iveresov
parents:
3885
diff
changeset
|
2851 DWORD node = numa_node_list_holder.get_node_list_entry(count % numa_node_list_holder.get_count()); |
3885 | 2852 p_new = (char *)os::Kernel32Dll::VirtualAllocExNuma(hProc, |
2853 next_alloc_addr, | |
2854 bytes_to_rq, | |
2855 flags, | |
2856 prot, | |
2857 node); | |
2858 } | |
2859 } | |
2860 | |
2861 if (p_new == NULL) { | |
2862 // Free any allocated pages | |
2863 if (next_alloc_addr > p_buf) { | |
2864 // Some memory was committed so release it. | |
2865 size_t bytes_to_release = bytes - bytes_remaining; | |
2866 os::release_memory(p_buf, bytes_to_release); | |
2867 } | |
2868 #ifdef ASSERT | |
2869 if (should_inject_error) { | |
2870 if (TracePageSizes && Verbose) { | |
2871 tty->print_cr("Reserving pages individually failed."); | |
2872 } | |
2873 } | |
2874 #endif | |
2875 return NULL; | |
2876 } | |
2877 bytes_remaining -= bytes_to_rq; | |
2878 next_alloc_addr += bytes_to_rq; | |
2879 count++; | |
2880 } | |
2881 // made it this far, success | |
2882 return p_buf; | |
2883 } | |
2884 | |
2885 | |
2886 | |
3318
188c9a5d6a6d
7040485: Use transparent huge page on linux by default
iveresov
parents:
3240
diff
changeset
|
2887 void os::large_page_init() { |
188c9a5d6a6d
7040485: Use transparent huge page on linux by default
iveresov
parents:
3240
diff
changeset
|
2888 if (!UseLargePages) return; |
0 | 2889 |
2890 // print a warning if any large page related flag is specified on command line | |
2891 bool warn_on_failure = !FLAG_IS_DEFAULT(UseLargePages) || | |
2892 !FLAG_IS_DEFAULT(LargePageSizeInBytes); | |
2893 bool success = false; | |
2894 | |
2895 # define WARN(msg) if (warn_on_failure) { warning(msg); } | |
2896 if (resolve_functions_for_large_page_init()) { | |
2897 if (request_lock_memory_privilege()) { | |
3833
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
2898 size_t s = os::Kernel32Dll::GetLargePageMinimum(); |
0 | 2899 if (s) { |
2900 #if defined(IA32) || defined(AMD64) | |
2901 if (s > 4*M || LargePageSizeInBytes > 4*M) { | |
2902 WARN("JVM cannot use large pages bigger than 4mb."); | |
2903 } else { | |
2904 #endif | |
2905 if (LargePageSizeInBytes && LargePageSizeInBytes % s == 0) { | |
2906 _large_page_size = LargePageSizeInBytes; | |
2907 } else { | |
2908 _large_page_size = s; | |
2909 } | |
2910 success = true; | |
2911 #if defined(IA32) || defined(AMD64) | |
2912 } | |
2913 #endif | |
2914 } else { | |
2915 WARN("Large page is not supported by the processor."); | |
2916 } | |
2917 } else { | |
2918 WARN("JVM cannot use large page memory because it does not have enough privilege to lock pages in memory."); | |
2919 } | |
2920 } else { | |
2921 WARN("Large page is not supported by the operating system."); | |
2922 } | |
2923 #undef WARN | |
2924 | |
2925 const size_t default_page_size = (size_t) vm_page_size(); | |
2926 if (success && _large_page_size > default_page_size) { | |
2927 _page_sizes[0] = _large_page_size; | |
2928 _page_sizes[1] = default_page_size; | |
2929 _page_sizes[2] = 0; | |
2930 } | |
2931 | |
2932 cleanup_after_large_page_init(); | |
3318
188c9a5d6a6d
7040485: Use transparent huge page on linux by default
iveresov
parents:
3240
diff
changeset
|
2933 UseLargePages = success; |
0 | 2934 } |
2935 | |
2936 // On win32, one cannot release just a part of reserved memory, it's an | |
2937 // all or nothing deal. When we split a reservation, we must break the | |
2938 // reservation into two reservations. | |
6197 | 2939 void os::pd_split_reserved_memory(char *base, size_t size, size_t split, |
0 | 2940 bool realloc) { |
2941 if (size > 0) { | |
2942 release_memory(base, size); | |
2943 if (realloc) { | |
2944 reserve_memory(split, base); | |
2945 } | |
2946 if (size != split) { | |
2947 reserve_memory(size - split, base + split); | |
2948 } | |
2949 } | |
2950 } | |
2951 | |
6197 | 2952 char* os::pd_reserve_memory(size_t bytes, char* addr, size_t alignment_hint) { |
0 | 2953 assert((size_t)addr % os::vm_allocation_granularity() == 0, |
2954 "reserve alignment"); | |
2955 assert(bytes % os::vm_allocation_granularity() == 0, "reserve block size"); | |
3885 | 2956 char* res; |
2957 // note that if UseLargePages is on, all the areas that require interleaving | |
2958 // will go thru reserve_memory_special rather than thru here. | |
2959 bool use_individual = (UseNUMAInterleaving && !UseLargePages); | |
2960 if (!use_individual) { | |
2961 res = (char*)VirtualAlloc(addr, bytes, MEM_RESERVE, PAGE_READWRITE); | |
2962 } else { | |
2963 elapsedTimer reserveTimer; | |
2964 if( Verbose && PrintMiscellaneous ) reserveTimer.start(); | |
2965 // in numa interleaving, we have to allocate pages individually | |
2966 // (well really chunks of NUMAInterleaveGranularity size) | |
2967 res = allocate_pages_individually(bytes, addr, MEM_RESERVE, PAGE_READWRITE); | |
2968 if (res == NULL) { | |
2969 warning("NUMA page allocation failed"); | |
2970 } | |
2971 if( Verbose && PrintMiscellaneous ) { | |
2972 reserveTimer.stop(); | |
2973 tty->print_cr("reserve_memory of %Ix bytes took %ld ms (%ld ticks)", bytes, | |
2974 reserveTimer.milliseconds(), reserveTimer.ticks()); | |
2975 } | |
2976 } | |
0 | 2977 assert(res == NULL || addr == NULL || addr == res, |
2978 "Unexpected address from reserve."); | |
3885 | 2979 |
0 | 2980 return res; |
2981 } | |
2982 | |
2983 // Reserve memory at an arbitrary address, only if that area is | |
2984 // available (and not reserved for something else). | |
6197 | 2985 char* os::pd_attempt_reserve_memory_at(size_t bytes, char* requested_addr) { |
0 | 2986 // Windows os::reserve_memory() fails of the requested address range is |
2987 // not avilable. | |
2988 return reserve_memory(bytes, requested_addr); | |
2989 } | |
2990 | |
2991 size_t os::large_page_size() { | |
2992 return _large_page_size; | |
2993 } | |
2994 | |
2995 bool os::can_commit_large_page_memory() { | |
2996 // Windows only uses large page memory when the entire region is reserved | |
2997 // and committed in a single VirtualAlloc() call. This may change in the | |
2998 // future, but with Windows 2003 it's not possible to commit on demand. | |
2999 return false; | |
3000 } | |
3001 | |
79
82db0859acbe
6642862: Code cache allocation fails with large pages after 6588638
jcoomes
parents:
62
diff
changeset
|
3002 bool os::can_execute_large_page_memory() { |
82db0859acbe
6642862: Code cache allocation fails with large pages after 6588638
jcoomes
parents:
62
diff
changeset
|
3003 return true; |
82db0859acbe
6642862: Code cache allocation fails with large pages after 6588638
jcoomes
parents:
62
diff
changeset
|
3004 } |
82db0859acbe
6642862: Code cache allocation fails with large pages after 6588638
jcoomes
parents:
62
diff
changeset
|
3005 |
656 | 3006 char* os::reserve_memory_special(size_t bytes, char* addr, bool exec) { |
389
ee21eaa8ffe1
6660681: Incrementally reserve pages on win server 2003 for better large page affinity
jmasa
parents:
356
diff
changeset
|
3007 |
717 | 3008 const DWORD prot = exec ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE; |
3885 | 3009 const DWORD flags = MEM_RESERVE | MEM_COMMIT | MEM_LARGE_PAGES; |
3010 | |
3011 // with large pages, there are two cases where we need to use Individual Allocation | |
3012 // 1) the UseLargePagesIndividualAllocation flag is set (set by default on WS2003) | |
3013 // 2) NUMA Interleaving is enabled, in which case we use a different node for each page | |
3014 if (UseLargePagesIndividualAllocation || UseNUMAInterleaving) { | |
389
ee21eaa8ffe1
6660681: Incrementally reserve pages on win server 2003 for better large page affinity
jmasa
parents:
356
diff
changeset
|
3015 if (TracePageSizes && Verbose) { |
ee21eaa8ffe1
6660681: Incrementally reserve pages on win server 2003 for better large page affinity
jmasa
parents:
356
diff
changeset
|
3016 tty->print_cr("Reserving large pages individually."); |
ee21eaa8ffe1
6660681: Incrementally reserve pages on win server 2003 for better large page affinity
jmasa
parents:
356
diff
changeset
|
3017 } |
3885 | 3018 char * p_buf = allocate_pages_individually(bytes, addr, flags, prot, LargePagesIndividualAllocationInjectError); |
3019 if (p_buf == NULL) { | |
3020 // give an appropriate warning message | |
3021 if (UseNUMAInterleaving) { | |
3022 warning("NUMA large page allocation failed, UseLargePages flag ignored"); | |
3023 } | |
3024 if (UseLargePagesIndividualAllocation) { | |
3025 warning("Individually allocated large pages failed, " | |
3026 "use -XX:-UseLargePagesIndividualAllocation to turn off"); | |
3027 } | |
389
ee21eaa8ffe1
6660681: Incrementally reserve pages on win server 2003 for better large page affinity
jmasa
parents:
356
diff
changeset
|
3028 return NULL; |
ee21eaa8ffe1
6660681: Incrementally reserve pages on win server 2003 for better large page affinity
jmasa
parents:
356
diff
changeset
|
3029 } |
ee21eaa8ffe1
6660681: Incrementally reserve pages on win server 2003 for better large page affinity
jmasa
parents:
356
diff
changeset
|
3030 |
ee21eaa8ffe1
6660681: Incrementally reserve pages on win server 2003 for better large page affinity
jmasa
parents:
356
diff
changeset
|
3031 return p_buf; |
ee21eaa8ffe1
6660681: Incrementally reserve pages on win server 2003 for better large page affinity
jmasa
parents:
356
diff
changeset
|
3032 |
ee21eaa8ffe1
6660681: Incrementally reserve pages on win server 2003 for better large page affinity
jmasa
parents:
356
diff
changeset
|
3033 } else { |
ee21eaa8ffe1
6660681: Incrementally reserve pages on win server 2003 for better large page affinity
jmasa
parents:
356
diff
changeset
|
3034 // normal policy just allocate it all at once |
ee21eaa8ffe1
6660681: Incrementally reserve pages on win server 2003 for better large page affinity
jmasa
parents:
356
diff
changeset
|
3035 DWORD flag = MEM_RESERVE | MEM_COMMIT | MEM_LARGE_PAGES; |
717 | 3036 char * res = (char *)VirtualAlloc(NULL, bytes, flag, prot); |
389
ee21eaa8ffe1
6660681: Incrementally reserve pages on win server 2003 for better large page affinity
jmasa
parents:
356
diff
changeset
|
3037 return res; |
ee21eaa8ffe1
6660681: Incrementally reserve pages on win server 2003 for better large page affinity
jmasa
parents:
356
diff
changeset
|
3038 } |
0 | 3039 } |
3040 | |
3041 bool os::release_memory_special(char* base, size_t bytes) { | |
3042 return release_memory(base, bytes); | |
3043 } | |
3044 | |
3045 void os::print_statistics() { | |
3046 } | |
3047 | |
6197 | 3048 bool os::pd_commit_memory(char* addr, size_t bytes, bool exec) { |
0 | 3049 if (bytes == 0) { |
3050 // Don't bother the OS with noops. | |
3051 return true; | |
3052 } | |
3053 assert((size_t) addr % os::vm_page_size() == 0, "commit on page boundaries"); | |
3054 assert(bytes % os::vm_page_size() == 0, "commit in page-sized chunks"); | |
3055 // Don't attempt to print anything if the OS call fails. We're | |
3056 // probably low on resources, so the print itself may cause crashes. | |
3885 | 3057 |
3058 // unless we have NUMAInterleaving enabled, the range of a commit | |
3059 // is always within a reserve covered by a single VirtualAlloc | |
3060 // in that case we can just do a single commit for the requested size | |
3061 if (!UseNUMAInterleaving) { | |
3062 if (VirtualAlloc(addr, bytes, MEM_COMMIT, PAGE_READWRITE) == NULL) return false; | |
3063 if (exec) { | |
3064 DWORD oldprot; | |
3065 // Windows doc says to use VirtualProtect to get execute permissions | |
3066 if (!VirtualProtect(addr, bytes, PAGE_EXECUTE_READWRITE, &oldprot)) return false; | |
3067 } | |
3068 return true; | |
656 | 3069 } else { |
3885 | 3070 |
3071 // when NUMAInterleaving is enabled, the commit might cover a range that | |
3072 // came from multiple VirtualAlloc reserves (using allocate_pages_individually). | |
3073 // VirtualQuery can help us determine that. The RegionSize that VirtualQuery | |
3074 // returns represents the number of bytes that can be committed in one step. | |
3075 size_t bytes_remaining = bytes; | |
3076 char * next_alloc_addr = addr; | |
3077 while (bytes_remaining > 0) { | |
3078 MEMORY_BASIC_INFORMATION alloc_info; | |
3079 VirtualQuery(next_alloc_addr, &alloc_info, sizeof(alloc_info)); | |
3080 size_t bytes_to_rq = MIN2(bytes_remaining, (size_t)alloc_info.RegionSize); | |
3081 if (VirtualAlloc(next_alloc_addr, bytes_to_rq, MEM_COMMIT, PAGE_READWRITE) == NULL) | |
3082 return false; | |
3083 if (exec) { | |
3084 DWORD oldprot; | |
3085 if (!VirtualProtect(next_alloc_addr, bytes_to_rq, PAGE_EXECUTE_READWRITE, &oldprot)) | |
3086 return false; | |
3087 } | |
3088 bytes_remaining -= bytes_to_rq; | |
3089 next_alloc_addr += bytes_to_rq; | |
3090 } | |
3091 } | |
3092 // if we made it this far, return true | |
3093 return true; | |
0 | 3094 } |
3095 | |
6197 | 3096 bool os::pd_commit_memory(char* addr, size_t size, size_t alignment_hint, |
656 | 3097 bool exec) { |
3098 return commit_memory(addr, size, exec); | |
0 | 3099 } |
3100 | |
6197 | 3101 bool os::pd_uncommit_memory(char* addr, size_t bytes) { |
0 | 3102 if (bytes == 0) { |
3103 // Don't bother the OS with noops. | |
3104 return true; | |
3105 } | |
3106 assert((size_t) addr % os::vm_page_size() == 0, "uncommit on page boundaries"); | |
3107 assert(bytes % os::vm_page_size() == 0, "uncommit in page-sized chunks"); | |
6197 | 3108 return (VirtualFree(addr, bytes, MEM_DECOMMIT) != 0); |
3109 } | |
3110 | |
3111 bool os::pd_release_memory(char* addr, size_t bytes) { | |
0 | 3112 return VirtualFree(addr, 0, MEM_RELEASE) != 0; |
3113 } | |
3114 | |
6197 | 3115 bool os::pd_create_stack_guard_pages(char* addr, size_t size) { |
1320
3b3d12e645e7
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
1215
diff
changeset
|
3116 return os::commit_memory(addr, size); |
3b3d12e645e7
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
1215
diff
changeset
|
3117 } |
3b3d12e645e7
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
1215
diff
changeset
|
3118 |
3b3d12e645e7
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
1215
diff
changeset
|
3119 bool os::remove_stack_guard_pages(char* addr, size_t size) { |
3b3d12e645e7
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
1215
diff
changeset
|
3120 return os::uncommit_memory(addr, size); |
3b3d12e645e7
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
1215
diff
changeset
|
3121 } |
3b3d12e645e7
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
1215
diff
changeset
|
3122 |
237
1fdb98a17101
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
196
diff
changeset
|
3123 // Set protections specified |
1fdb98a17101
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
196
diff
changeset
|
3124 bool os::protect_memory(char* addr, size_t bytes, ProtType prot, |
1fdb98a17101
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
196
diff
changeset
|
3125 bool is_committed) { |
1fdb98a17101
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
196
diff
changeset
|
3126 unsigned int p = 0; |
1fdb98a17101
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
196
diff
changeset
|
3127 switch (prot) { |
1fdb98a17101
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
196
diff
changeset
|
3128 case MEM_PROT_NONE: p = PAGE_NOACCESS; break; |
1fdb98a17101
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
196
diff
changeset
|
3129 case MEM_PROT_READ: p = PAGE_READONLY; break; |
1fdb98a17101
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
196
diff
changeset
|
3130 case MEM_PROT_RW: p = PAGE_READWRITE; break; |
1fdb98a17101
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
196
diff
changeset
|
3131 case MEM_PROT_RWX: p = PAGE_EXECUTE_READWRITE; break; |
1fdb98a17101
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
196
diff
changeset
|
3132 default: |
1fdb98a17101
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
196
diff
changeset
|
3133 ShouldNotReachHere(); |
1fdb98a17101
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
196
diff
changeset
|
3134 } |
1fdb98a17101
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
196
diff
changeset
|
3135 |
0 | 3136 DWORD old_status; |
237
1fdb98a17101
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
196
diff
changeset
|
3137 |
1fdb98a17101
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
196
diff
changeset
|
3138 // Strange enough, but on Win32 one can change protection only for committed |
1fdb98a17101
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
196
diff
changeset
|
3139 // memory, not a big deal anyway, as bytes less or equal than 64K |
656 | 3140 if (!is_committed && !commit_memory(addr, bytes, prot == MEM_PROT_RWX)) { |
237
1fdb98a17101
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
196
diff
changeset
|
3141 fatal("cannot commit protection page"); |
1fdb98a17101
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
196
diff
changeset
|
3142 } |
1fdb98a17101
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
196
diff
changeset
|
3143 // One cannot use os::guard_memory() here, as on Win32 guard page |
1fdb98a17101
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
196
diff
changeset
|
3144 // have different (one-shot) semantics, from MSDN on PAGE_GUARD: |
1fdb98a17101
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
196
diff
changeset
|
3145 // |
1fdb98a17101
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
196
diff
changeset
|
3146 // Pages in the region become guard pages. Any attempt to access a guard page |
1fdb98a17101
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
196
diff
changeset
|
3147 // causes the system to raise a STATUS_GUARD_PAGE exception and turn off |
1fdb98a17101
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
196
diff
changeset
|
3148 // the guard page status. Guard pages thus act as a one-time access alarm. |
1fdb98a17101
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
196
diff
changeset
|
3149 return VirtualProtect(addr, bytes, p, &old_status) != 0; |
0 | 3150 } |
3151 | |
3152 bool os::guard_memory(char* addr, size_t bytes) { | |
3153 DWORD old_status; | |
477
24fda36852ce
6727377: VM stack guard pages on Windows should PAGE_READWRITE not PAGE_EXECUTE_READWRITE
coleenp
parents:
467
diff
changeset
|
3154 return VirtualProtect(addr, bytes, PAGE_READWRITE | PAGE_GUARD, &old_status) != 0; |
0 | 3155 } |
3156 | |
3157 bool os::unguard_memory(char* addr, size_t bytes) { | |
3158 DWORD old_status; | |
477
24fda36852ce
6727377: VM stack guard pages on Windows should PAGE_READWRITE not PAGE_EXECUTE_READWRITE
coleenp
parents:
467
diff
changeset
|
3159 return VirtualProtect(addr, bytes, PAGE_READWRITE, &old_status) != 0; |
0 | 3160 } |
3161 | |
6197 | 3162 void os::pd_realign_memory(char *addr, size_t bytes, size_t alignment_hint) { } |
3163 void os::pd_free_memory(char *addr, size_t bytes, size_t alignment_hint) { } | |
0 | 3164 void os::numa_make_global(char *addr, size_t bytes) { } |
141 | 3165 void os::numa_make_local(char *addr, size_t bytes, int lgrp_hint) { } |
0 | 3166 bool os::numa_topology_changed() { return false; } |
3918
a6128a8ed624
7086226: UseNUMA fails on old versions of windows
iveresov
parents:
3885
diff
changeset
|
3167 size_t os::numa_get_groups_num() { return MAX2(numa_node_list_holder.get_count(), 1); } |
0 | 3168 int os::numa_get_group_id() { return 0; } |
3169 size_t os::numa_get_leaf_groups(int *ids, size_t size) { | |
3918
a6128a8ed624
7086226: UseNUMA fails on old versions of windows
iveresov
parents:
3885
diff
changeset
|
3170 if (numa_node_list_holder.get_count() == 0 && size > 0) { |
a6128a8ed624
7086226: UseNUMA fails on old versions of windows
iveresov
parents:
3885
diff
changeset
|
3171 // Provide an answer for UMA systems |
a6128a8ed624
7086226: UseNUMA fails on old versions of windows
iveresov
parents:
3885
diff
changeset
|
3172 ids[0] = 0; |
a6128a8ed624
7086226: UseNUMA fails on old versions of windows
iveresov
parents:
3885
diff
changeset
|
3173 return 1; |
a6128a8ed624
7086226: UseNUMA fails on old versions of windows
iveresov
parents:
3885
diff
changeset
|
3174 } else { |
a6128a8ed624
7086226: UseNUMA fails on old versions of windows
iveresov
parents:
3885
diff
changeset
|
3175 // check for size bigger than actual groups_num |
a6128a8ed624
7086226: UseNUMA fails on old versions of windows
iveresov
parents:
3885
diff
changeset
|
3176 size = MIN2(size, numa_get_groups_num()); |
a6128a8ed624
7086226: UseNUMA fails on old versions of windows
iveresov
parents:
3885
diff
changeset
|
3177 for (int i = 0; i < (int)size; i++) { |
a6128a8ed624
7086226: UseNUMA fails on old versions of windows
iveresov
parents:
3885
diff
changeset
|
3178 ids[i] = numa_node_list_holder.get_node_list_entry(i); |
a6128a8ed624
7086226: UseNUMA fails on old versions of windows
iveresov
parents:
3885
diff
changeset
|
3179 } |
a6128a8ed624
7086226: UseNUMA fails on old versions of windows
iveresov
parents:
3885
diff
changeset
|
3180 return size; |
a6128a8ed624
7086226: UseNUMA fails on old versions of windows
iveresov
parents:
3885
diff
changeset
|
3181 } |
0 | 3182 } |
3183 | |
3184 bool os::get_page_info(char *start, page_info* info) { | |
3185 return false; | |
3186 } | |
3187 | |
3188 char *os::scan_pages(char *start, char* end, page_info* page_expected, page_info* page_found) { | |
3189 return end; | |
3190 } | |
3191 | |
3192 char* os::non_memory_address_word() { | |
3193 // Must never look like an address returned by reserve_memory, | |
3194 // even in its subfields (as defined by the CPU immediate fields, | |
3195 // if the CPU splits constants across multiple instructions). | |
3196 return (char*)-1; | |
3197 } | |
3198 | |
3199 #define MAX_ERROR_COUNT 100 | |
3200 #define SYS_THREAD_ERROR 0xffffffffUL | |
3201 | |
3202 void os::pd_start_thread(Thread* thread) { | |
3203 DWORD ret = ResumeThread(thread->osthread()->thread_handle()); | |
3204 // Returns previous suspend state: | |
3205 // 0: Thread was not suspended | |
3206 // 1: Thread is running now | |
3207 // >1: Thread is still suspended. | |
3208 assert(ret != SYS_THREAD_ERROR, "StartThread failed"); // should propagate back | |
3209 } | |
3210 | |
3211 class HighResolutionInterval { | |
3212 // The default timer resolution seems to be 10 milliseconds. | |
3213 // (Where is this written down?) | |
3214 // If someone wants to sleep for only a fraction of the default, | |
3215 // then we set the timer resolution down to 1 millisecond for | |
3216 // the duration of their interval. | |
3217 // We carefully set the resolution back, since otherwise we | |
3218 // seem to incur an overhead (3%?) that we don't need. | |
3219 // CONSIDER: if ms is small, say 3, then we should run with a high resolution time. | |
3220 // Buf if ms is large, say 500, or 503, we should avoid the call to timeBeginPeriod(). | |
3221 // Alternatively, we could compute the relative error (503/500 = .6%) and only use | |
3222 // timeBeginPeriod() if the relative error exceeded some threshold. | |
3223 // timeBeginPeriod() has been linked to problems with clock drift on win32 systems and | |
3224 // to decreased efficiency related to increased timer "tick" rates. We want to minimize | |
3225 // (a) calls to timeBeginPeriod() and timeEndPeriod() and (b) time spent with high | |
3226 // resolution timers running. | |
3227 private: | |
3228 jlong resolution; | |
3229 public: | |
3230 HighResolutionInterval(jlong ms) { | |
3231 resolution = ms % 10L; | |
3232 if (resolution != 0) { | |
3233 MMRESULT result = timeBeginPeriod(1L); | |
3234 } | |
3235 } | |
3236 ~HighResolutionInterval() { | |
3237 if (resolution != 0) { | |
3238 MMRESULT result = timeEndPeriod(1L); | |
3239 } | |
3240 resolution = 0L; | |
3241 } | |
3242 }; | |
3243 | |
3244 int os::sleep(Thread* thread, jlong ms, bool interruptable) { | |
3245 jlong limit = (jlong) MAXDWORD; | |
3246 | |
3247 while(ms > limit) { | |
3248 int res; | |
3249 if ((res = sleep(thread, limit, interruptable)) != OS_TIMEOUT) | |
3250 return res; | |
3251 ms -= limit; | |
3252 } | |
3253 | |
3254 assert(thread == Thread::current(), "thread consistency check"); | |
3255 OSThread* osthread = thread->osthread(); | |
3256 OSThreadWaitState osts(osthread, false /* not Object.wait() */); | |
3257 int result; | |
3258 if (interruptable) { | |
3259 assert(thread->is_Java_thread(), "must be java thread"); | |
3260 JavaThread *jt = (JavaThread *) thread; | |
3261 ThreadBlockInVM tbivm(jt); | |
3262 | |
3263 jt->set_suspend_equivalent(); | |
3264 // cleared by handle_special_suspend_equivalent_condition() or | |
3265 // java_suspend_self() via check_and_wait_while_suspended() | |
3266 | |
3267 HANDLE events[1]; | |
3268 events[0] = osthread->interrupt_event(); | |
3269 HighResolutionInterval *phri=NULL; | |
3270 if(!ForceTimeHighResolution) | |
3271 phri = new HighResolutionInterval( ms ); | |
3272 if (WaitForMultipleObjects(1, events, FALSE, (DWORD)ms) == WAIT_TIMEOUT) { | |
3273 result = OS_TIMEOUT; | |
3274 } else { | |
3275 ResetEvent(osthread->interrupt_event()); | |
3276 osthread->set_interrupted(false); | |
3277 result = OS_INTRPT; | |
3278 } | |
3279 delete phri; //if it is NULL, harmless | |
3280 | |
3281 // were we externally suspended while we were waiting? | |
3282 jt->check_and_wait_while_suspended(); | |
3283 } else { | |
3284 assert(!thread->is_Java_thread(), "must not be java thread"); | |
3285 Sleep((long) ms); | |
3286 result = OS_TIMEOUT; | |
3287 } | |
3288 return result; | |
3289 } | |
3290 | |
3291 // Sleep forever; naked call to OS-specific sleep; use with CAUTION | |
3292 void os::infinite_sleep() { | |
3293 while (true) { // sleep forever ... | |
3294 Sleep(100000); // ... 100 seconds at a time | |
3295 } | |
3296 } | |
3297 | |
3298 typedef BOOL (WINAPI * STTSignature)(void) ; | |
3299 | |
3300 os::YieldResult os::NakedYield() { | |
3301 // Use either SwitchToThread() or Sleep(0) | |
3302 // Consider passing back the return value from SwitchToThread(). | |
3833
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
3303 if (os::Kernel32Dll::SwitchToThreadAvailable()) { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
3304 return SwitchToThread() ? os::YIELD_SWITCHED : os::YIELD_NONEREADY ; |
0 | 3305 } else { |
3833
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
3306 Sleep(0); |
0 | 3307 } |
3308 return os::YIELD_UNKNOWN ; | |
3309 } | |
3310 | |
3311 void os::yield() { os::NakedYield(); } | |
3312 | |
3313 void os::yield_all(int attempts) { | |
3314 // Yields to all threads, including threads with lower priorities | |
3315 Sleep(1); | |
3316 } | |
3317 | |
3318 // Win32 only gives you access to seven real priorities at a time, | |
3319 // so we compress Java's ten down to seven. It would be better | |
3320 // if we dynamically adjusted relative priorities. | |
3321 | |
4854
de268c8a8075
7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents:
4803
diff
changeset
|
3322 int os::java_to_os_priority[CriticalPriority + 1] = { |
0 | 3323 THREAD_PRIORITY_IDLE, // 0 Entry should never be used |
3324 THREAD_PRIORITY_LOWEST, // 1 MinPriority | |
3325 THREAD_PRIORITY_LOWEST, // 2 | |
3326 THREAD_PRIORITY_BELOW_NORMAL, // 3 | |
3327 THREAD_PRIORITY_BELOW_NORMAL, // 4 | |
3328 THREAD_PRIORITY_NORMAL, // 5 NormPriority | |
3329 THREAD_PRIORITY_NORMAL, // 6 | |
3330 THREAD_PRIORITY_ABOVE_NORMAL, // 7 | |
3331 THREAD_PRIORITY_ABOVE_NORMAL, // 8 | |
3332 THREAD_PRIORITY_HIGHEST, // 9 NearMaxPriority | |
4854
de268c8a8075
7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents:
4803
diff
changeset
|
3333 THREAD_PRIORITY_HIGHEST, // 10 MaxPriority |
de268c8a8075
7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents:
4803
diff
changeset
|
3334 THREAD_PRIORITY_HIGHEST // 11 CriticalPriority |
0 | 3335 }; |
3336 | |
4854
de268c8a8075
7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents:
4803
diff
changeset
|
3337 int prio_policy1[CriticalPriority + 1] = { |
0 | 3338 THREAD_PRIORITY_IDLE, // 0 Entry should never be used |
3339 THREAD_PRIORITY_LOWEST, // 1 MinPriority | |
3340 THREAD_PRIORITY_LOWEST, // 2 | |
3341 THREAD_PRIORITY_BELOW_NORMAL, // 3 | |
3342 THREAD_PRIORITY_BELOW_NORMAL, // 4 | |
3343 THREAD_PRIORITY_NORMAL, // 5 NormPriority | |
3344 THREAD_PRIORITY_ABOVE_NORMAL, // 6 | |
3345 THREAD_PRIORITY_ABOVE_NORMAL, // 7 | |
3346 THREAD_PRIORITY_HIGHEST, // 8 | |
3347 THREAD_PRIORITY_HIGHEST, // 9 NearMaxPriority | |
4854
de268c8a8075
7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents:
4803
diff
changeset
|
3348 THREAD_PRIORITY_TIME_CRITICAL, // 10 MaxPriority |
de268c8a8075
7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents:
4803
diff
changeset
|
3349 THREAD_PRIORITY_TIME_CRITICAL // 11 CriticalPriority |
0 | 3350 }; |
3351 | |
3352 static int prio_init() { | |
3353 // If ThreadPriorityPolicy is 1, switch tables | |
3354 if (ThreadPriorityPolicy == 1) { | |
3355 int i; | |
4854
de268c8a8075
7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents:
4803
diff
changeset
|
3356 for (i = 0; i < CriticalPriority + 1; i++) { |
0 | 3357 os::java_to_os_priority[i] = prio_policy1[i]; |
3358 } | |
3359 } | |
4854
de268c8a8075
7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents:
4803
diff
changeset
|
3360 if (UseCriticalJavaThreadPriority) { |
de268c8a8075
7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents:
4803
diff
changeset
|
3361 os::java_to_os_priority[MaxPriority] = os::java_to_os_priority[CriticalPriority] ; |
de268c8a8075
7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents:
4803
diff
changeset
|
3362 } |
0 | 3363 return 0; |
3364 } | |
3365 | |
3366 OSReturn os::set_native_priority(Thread* thread, int priority) { | |
3367 if (!UseThreadPriorities) return OS_OK; | |
3368 bool ret = SetThreadPriority(thread->osthread()->thread_handle(), priority) != 0; | |
3369 return ret ? OS_OK : OS_ERR; | |
3370 } | |
3371 | |
3372 OSReturn os::get_native_priority(const Thread* const thread, int* priority_ptr) { | |
3373 if ( !UseThreadPriorities ) { | |
3374 *priority_ptr = java_to_os_priority[NormPriority]; | |
3375 return OS_OK; | |
3376 } | |
3377 int os_prio = GetThreadPriority(thread->osthread()->thread_handle()); | |
3378 if (os_prio == THREAD_PRIORITY_ERROR_RETURN) { | |
3379 assert(false, "GetThreadPriority failed"); | |
3380 return OS_ERR; | |
3381 } | |
3382 *priority_ptr = os_prio; | |
3383 return OS_OK; | |
3384 } | |
3385 | |
3386 | |
3387 // Hint to the underlying OS that a task switch would not be good. | |
3388 // Void return because it's a hint and can fail. | |
3389 void os::hint_no_preempt() {} | |
3390 | |
3391 void os::interrupt(Thread* thread) { | |
3392 assert(!thread->is_Java_thread() || Thread::current() == thread || Threads_lock->owned_by_self(), | |
3393 "possibility of dangling Thread pointer"); | |
3394 | |
3395 OSThread* osthread = thread->osthread(); | |
3396 osthread->set_interrupted(true); | |
3397 // More than one thread can get here with the same value of osthread, | |
3398 // resulting in multiple notifications. We do, however, want the store | |
3399 // to interrupted() to be visible to other threads before we post | |
3400 // the interrupt event. | |
3401 OrderAccess::release(); | |
3402 SetEvent(osthread->interrupt_event()); | |
3403 // For JSR166: unpark after setting status | |
3404 if (thread->is_Java_thread()) | |
3405 ((JavaThread*)thread)->parker()->unpark(); | |
3406 | |
3407 ParkEvent * ev = thread->_ParkEvent ; | |
3408 if (ev != NULL) ev->unpark() ; | |
3409 | |
3410 } | |
3411 | |
3412 | |
3413 bool os::is_interrupted(Thread* thread, bool clear_interrupted) { | |
3414 assert(!thread->is_Java_thread() || Thread::current() == thread || Threads_lock->owned_by_self(), | |
3415 "possibility of dangling Thread pointer"); | |
3416 | |
3417 OSThread* osthread = thread->osthread(); | |
2386
083f13976b51
6535709: interrupt of wait()ing thread isn't triggerring InterruptedException - test intwait3
dholmes
parents:
2306
diff
changeset
|
3418 bool interrupted = osthread->interrupted(); |
083f13976b51
6535709: interrupt of wait()ing thread isn't triggerring InterruptedException - test intwait3
dholmes
parents:
2306
diff
changeset
|
3419 // There is no synchronization between the setting of the interrupt |
083f13976b51
6535709: interrupt of wait()ing thread isn't triggerring InterruptedException - test intwait3
dholmes
parents:
2306
diff
changeset
|
3420 // and it being cleared here. It is critical - see 6535709 - that |
083f13976b51
6535709: interrupt of wait()ing thread isn't triggerring InterruptedException - test intwait3
dholmes
parents:
2306
diff
changeset
|
3421 // we only clear the interrupt state, and reset the interrupt event, |
083f13976b51
6535709: interrupt of wait()ing thread isn't triggerring InterruptedException - test intwait3
dholmes
parents:
2306
diff
changeset
|
3422 // if we are going to report that we were indeed interrupted - else |
083f13976b51
6535709: interrupt of wait()ing thread isn't triggerring InterruptedException - test intwait3
dholmes
parents:
2306
diff
changeset
|
3423 // an interrupt can be "lost", leading to spurious wakeups or lost wakeups |
083f13976b51
6535709: interrupt of wait()ing thread isn't triggerring InterruptedException - test intwait3
dholmes
parents:
2306
diff
changeset
|
3424 // depending on the timing |
083f13976b51
6535709: interrupt of wait()ing thread isn't triggerring InterruptedException - test intwait3
dholmes
parents:
2306
diff
changeset
|
3425 if (interrupted && clear_interrupted) { |
0 | 3426 osthread->set_interrupted(false); |
3427 ResetEvent(osthread->interrupt_event()); | |
3428 } // Otherwise leave the interrupted state alone | |
3429 | |
3430 return interrupted; | |
3431 } | |
3432 | |
3433 // Get's a pc (hint) for a running thread. Currently used only for profiling. | |
3434 ExtendedPC os::get_thread_pc(Thread* thread) { | |
3435 CONTEXT context; | |
3436 context.ContextFlags = CONTEXT_CONTROL; | |
3437 HANDLE handle = thread->osthread()->thread_handle(); | |
3438 #ifdef _M_IA64 | |
3439 assert(0, "Fix get_thread_pc"); | |
3440 return ExtendedPC(NULL); | |
3441 #else | |
3442 if (GetThreadContext(handle, &context)) { | |
3443 #ifdef _M_AMD64 | |
3444 return ExtendedPC((address) context.Rip); | |
3445 #else | |
3446 return ExtendedPC((address) context.Eip); | |
3447 #endif | |
3448 } else { | |
3449 return ExtendedPC(NULL); | |
3450 } | |
3451 #endif | |
3452 } | |
3453 | |
3454 // GetCurrentThreadId() returns DWORD | |
3455 intx os::current_thread_id() { return GetCurrentThreadId(); } | |
3456 | |
3457 static int _initial_pid = 0; | |
3458 | |
3459 int os::current_process_id() | |
3460 { | |
3461 return (_initial_pid ? _initial_pid : _getpid()); | |
3462 } | |
3463 | |
3464 int os::win32::_vm_page_size = 0; | |
3465 int os::win32::_vm_allocation_granularity = 0; | |
3466 int os::win32::_processor_type = 0; | |
3467 // Processor level is not available on non-NT systems, use vm_version instead | |
3468 int os::win32::_processor_level = 0; | |
3469 julong os::win32::_physical_memory = 0; | |
3470 size_t os::win32::_default_stack_size = 0; | |
3471 | |
3472 intx os::win32::_os_thread_limit = 0; | |
3473 volatile intx os::win32::_os_thread_count = 0; | |
3474 | |
3475 bool os::win32::_is_nt = false; | |
389
ee21eaa8ffe1
6660681: Incrementally reserve pages on win server 2003 for better large page affinity
jmasa
parents:
356
diff
changeset
|
3476 bool os::win32::_is_windows_2003 = false; |
2204
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
3477 bool os::win32::_is_windows_server = false; |
0 | 3478 |
3479 void os::win32::initialize_system_info() { | |
3480 SYSTEM_INFO si; | |
3481 GetSystemInfo(&si); | |
3482 _vm_page_size = si.dwPageSize; | |
3483 _vm_allocation_granularity = si.dwAllocationGranularity; | |
3484 _processor_type = si.dwProcessorType; | |
3485 _processor_level = si.wProcessorLevel; | |
1123
167c2986d91b
6843629: Make current hotspot build part of jdk5 control build
phh
parents:
962
diff
changeset
|
3486 set_processor_count(si.dwNumberOfProcessors); |
0 | 3487 |
877
8c79517a9300
6840305: Discrepancy in system memory details (when 4G or greater) reported by JVM and Windows OS
poonam
parents:
717
diff
changeset
|
3488 MEMORYSTATUSEX ms; |
8c79517a9300
6840305: Discrepancy in system memory details (when 4G or greater) reported by JVM and Windows OS
poonam
parents:
717
diff
changeset
|
3489 ms.dwLength = sizeof(ms); |
8c79517a9300
6840305: Discrepancy in system memory details (when 4G or greater) reported by JVM and Windows OS
poonam
parents:
717
diff
changeset
|
3490 |
0 | 3491 // also returns dwAvailPhys (free physical memory bytes), dwTotalVirtual, dwAvailVirtual, |
3492 // dwMemoryLoad (% of memory in use) | |
877
8c79517a9300
6840305: Discrepancy in system memory details (when 4G or greater) reported by JVM and Windows OS
poonam
parents:
717
diff
changeset
|
3493 GlobalMemoryStatusEx(&ms); |
8c79517a9300
6840305: Discrepancy in system memory details (when 4G or greater) reported by JVM and Windows OS
poonam
parents:
717
diff
changeset
|
3494 _physical_memory = ms.ullTotalPhys; |
0 | 3495 |
2204
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
3496 OSVERSIONINFOEX oi; |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
3497 oi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
3498 GetVersionEx((OSVERSIONINFO*)&oi); |
0 | 3499 switch(oi.dwPlatformId) { |
3500 case VER_PLATFORM_WIN32_WINDOWS: _is_nt = false; break; | |
389
ee21eaa8ffe1
6660681: Incrementally reserve pages on win server 2003 for better large page affinity
jmasa
parents:
356
diff
changeset
|
3501 case VER_PLATFORM_WIN32_NT: |
ee21eaa8ffe1
6660681: Incrementally reserve pages on win server 2003 for better large page affinity
jmasa
parents:
356
diff
changeset
|
3502 _is_nt = true; |
ee21eaa8ffe1
6660681: Incrementally reserve pages on win server 2003 for better large page affinity
jmasa
parents:
356
diff
changeset
|
3503 { |
ee21eaa8ffe1
6660681: Incrementally reserve pages on win server 2003 for better large page affinity
jmasa
parents:
356
diff
changeset
|
3504 int os_vers = oi.dwMajorVersion * 1000 + oi.dwMinorVersion; |
ee21eaa8ffe1
6660681: Incrementally reserve pages on win server 2003 for better large page affinity
jmasa
parents:
356
diff
changeset
|
3505 if (os_vers == 5002) { |
ee21eaa8ffe1
6660681: Incrementally reserve pages on win server 2003 for better large page affinity
jmasa
parents:
356
diff
changeset
|
3506 _is_windows_2003 = true; |
ee21eaa8ffe1
6660681: Incrementally reserve pages on win server 2003 for better large page affinity
jmasa
parents:
356
diff
changeset
|
3507 } |
2204
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
3508 if (oi.wProductType == VER_NT_DOMAIN_CONTROLLER || |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
3509 oi.wProductType == VER_NT_SERVER) { |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
3510 _is_windows_server = true; |
63d374c54045
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
2130
diff
changeset
|
3511 } |
389
ee21eaa8ffe1
6660681: Incrementally reserve pages on win server 2003 for better large page affinity
jmasa
parents:
356
diff
changeset
|
3512 } |
ee21eaa8ffe1
6660681: Incrementally reserve pages on win server 2003 for better large page affinity
jmasa
parents:
356
diff
changeset
|
3513 break; |
0 | 3514 default: fatal("Unknown platform"); |
3515 } | |
3516 | |
3517 _default_stack_size = os::current_stack_size(); | |
3518 assert(_default_stack_size > (size_t) _vm_page_size, "invalid stack size"); | |
3519 assert((_default_stack_size & (_vm_page_size - 1)) == 0, | |
3520 "stack size not a multiple of page size"); | |
3521 | |
3522 initialize_performance_counter(); | |
3523 | |
3524 // Win95/Win98 scheduler bug work-around. The Win95/98 scheduler is | |
3525 // known to deadlock the system, if the VM issues to thread operations with | |
3526 // a too high frequency, e.g., such as changing the priorities. | |
3527 // The 6000 seems to work well - no deadlocks has been notices on the test | |
3528 // programs that we have seen experience this problem. | |
3529 if (!os::win32::is_nt()) { | |
3530 StarvationMonitorInterval = 6000; | |
3531 } | |
3532 } | |
3533 | |
3534 | |
3833
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
3535 HINSTANCE os::win32::load_Windows_dll(const char* name, char *ebuf, int ebuflen) { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
3536 char path[MAX_PATH]; |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
3537 DWORD size; |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
3538 DWORD pathLen = (DWORD)sizeof(path); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
3539 HINSTANCE result = NULL; |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
3540 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
3541 // only allow library name without path component |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
3542 assert(strchr(name, '\\') == NULL, "path not allowed"); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
3543 assert(strchr(name, ':') == NULL, "path not allowed"); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
3544 if (strchr(name, '\\') != NULL || strchr(name, ':') != NULL) { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
3545 jio_snprintf(ebuf, ebuflen, |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
3546 "Invalid parameter while calling os::win32::load_windows_dll(): cannot take path: %s", name); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
3547 return NULL; |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
3548 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
3549 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
3550 // search system directory |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
3551 if ((size = GetSystemDirectory(path, pathLen)) > 0) { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
3552 strcat(path, "\\"); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
3553 strcat(path, name); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
3554 if ((result = (HINSTANCE)os::dll_load(path, ebuf, ebuflen)) != NULL) { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
3555 return result; |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
3556 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
3557 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
3558 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
3559 // try Windows directory |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
3560 if ((size = GetWindowsDirectory(path, pathLen)) > 0) { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
3561 strcat(path, "\\"); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
3562 strcat(path, name); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
3563 if ((result = (HINSTANCE)os::dll_load(path, ebuf, ebuflen)) != NULL) { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
3564 return result; |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
3565 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
3566 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
3567 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
3568 jio_snprintf(ebuf, ebuflen, |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
3569 "os::win32::load_windows_dll() cannot load %s from system directories.", name); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
3570 return NULL; |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
3571 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
3572 |
0 | 3573 void os::win32::setmode_streams() { |
3574 _setmode(_fileno(stdin), _O_BINARY); | |
3575 _setmode(_fileno(stdout), _O_BINARY); | |
3576 _setmode(_fileno(stderr), _O_BINARY); | |
3577 } | |
3578 | |
3579 | |
2302
da091bb67459
7022037: Pause when exiting if debugger is attached on windows
sla
parents:
2205
diff
changeset
|
3580 bool os::is_debugger_attached() { |
da091bb67459
7022037: Pause when exiting if debugger is attached on windows
sla
parents:
2205
diff
changeset
|
3581 return IsDebuggerPresent() ? true : false; |
da091bb67459
7022037: Pause when exiting if debugger is attached on windows
sla
parents:
2205
diff
changeset
|
3582 } |
da091bb67459
7022037: Pause when exiting if debugger is attached on windows
sla
parents:
2205
diff
changeset
|
3583 |
da091bb67459
7022037: Pause when exiting if debugger is attached on windows
sla
parents:
2205
diff
changeset
|
3584 |
da091bb67459
7022037: Pause when exiting if debugger is attached on windows
sla
parents:
2205
diff
changeset
|
3585 void os::wait_for_keypress_at_exit(void) { |
da091bb67459
7022037: Pause when exiting if debugger is attached on windows
sla
parents:
2205
diff
changeset
|
3586 if (PauseAtExit) { |
da091bb67459
7022037: Pause when exiting if debugger is attached on windows
sla
parents:
2205
diff
changeset
|
3587 fprintf(stderr, "Press any key to continue...\n"); |
da091bb67459
7022037: Pause when exiting if debugger is attached on windows
sla
parents:
2205
diff
changeset
|
3588 fgetc(stdin); |
da091bb67459
7022037: Pause when exiting if debugger is attached on windows
sla
parents:
2205
diff
changeset
|
3589 } |
da091bb67459
7022037: Pause when exiting if debugger is attached on windows
sla
parents:
2205
diff
changeset
|
3590 } |
da091bb67459
7022037: Pause when exiting if debugger is attached on windows
sla
parents:
2205
diff
changeset
|
3591 |
da091bb67459
7022037: Pause when exiting if debugger is attached on windows
sla
parents:
2205
diff
changeset
|
3592 |
0 | 3593 int os::message_box(const char* title, const char* message) { |
3594 int result = MessageBox(NULL, message, title, | |
3595 MB_YESNO | MB_ICONERROR | MB_SYSTEMMODAL | MB_DEFAULT_DESKTOP_ONLY); | |
3596 return result == IDYES; | |
3597 } | |
3598 | |
3599 int os::allocate_thread_local_storage() { | |
3600 return TlsAlloc(); | |
3601 } | |
3602 | |
3603 | |
3604 void os::free_thread_local_storage(int index) { | |
3605 TlsFree(index); | |
3606 } | |
3607 | |
3608 | |
3609 void os::thread_local_storage_at_put(int index, void* value) { | |
3610 TlsSetValue(index, value); | |
3611 assert(thread_local_storage_at(index) == value, "Just checking"); | |
3612 } | |
3613 | |
3614 | |
3615 void* os::thread_local_storage_at(int index) { | |
3616 return TlsGetValue(index); | |
3617 } | |
3618 | |
3619 | |
3620 #ifndef PRODUCT | |
3621 #ifndef _WIN64 | |
3622 // Helpers to check whether NX protection is enabled | |
3623 int nx_exception_filter(_EXCEPTION_POINTERS *pex) { | |
3624 if (pex->ExceptionRecord->ExceptionCode == EXCEPTION_ACCESS_VIOLATION && | |
3625 pex->ExceptionRecord->NumberParameters > 0 && | |
3626 pex->ExceptionRecord->ExceptionInformation[0] == | |
3627 EXCEPTION_INFO_EXEC_VIOLATION) { | |
3628 return EXCEPTION_EXECUTE_HANDLER; | |
3629 } | |
3630 return EXCEPTION_CONTINUE_SEARCH; | |
3631 } | |
3632 | |
3633 void nx_check_protection() { | |
3634 // If NX is enabled we'll get an exception calling into code on the stack | |
3635 char code[] = { (char)0xC3 }; // ret | |
3636 void *code_ptr = (void *)code; | |
3637 __try { | |
3638 __asm call code_ptr | |
3639 } __except(nx_exception_filter((_EXCEPTION_POINTERS*)_exception_info())) { | |
3640 tty->print_raw_cr("NX protection detected."); | |
3641 } | |
3642 } | |
3643 #endif // _WIN64 | |
3644 #endif // PRODUCT | |
3645 | |
3646 // this is called _before_ the global arguments have been parsed | |
3647 void os::init(void) { | |
3648 _initial_pid = _getpid(); | |
3649 | |
3650 init_random(1234567); | |
3651 | |
3652 win32::initialize_system_info(); | |
3653 win32::setmode_streams(); | |
3654 init_page_sizes((size_t) win32::vm_page_size()); | |
3655 | |
3656 // For better scalability on MP systems (must be called after initialize_system_info) | |
3657 #ifndef PRODUCT | |
3658 if (is_MP()) { | |
3659 NoYieldsInMicrolock = true; | |
3660 } | |
3661 #endif | |
389
ee21eaa8ffe1
6660681: Incrementally reserve pages on win server 2003 for better large page affinity
jmasa
parents:
356
diff
changeset
|
3662 // This may be overridden later when argument processing is done. |
ee21eaa8ffe1
6660681: Incrementally reserve pages on win server 2003 for better large page affinity
jmasa
parents:
356
diff
changeset
|
3663 FLAG_SET_ERGO(bool, UseLargePagesIndividualAllocation, |
ee21eaa8ffe1
6660681: Incrementally reserve pages on win server 2003 for better large page affinity
jmasa
parents:
356
diff
changeset
|
3664 os::win32::is_windows_2003()); |
ee21eaa8ffe1
6660681: Incrementally reserve pages on win server 2003 for better large page affinity
jmasa
parents:
356
diff
changeset
|
3665 |
0 | 3666 // Initialize main_process and main_thread |
3667 main_process = GetCurrentProcess(); // Remember main_process is a pseudo handle | |
389
ee21eaa8ffe1
6660681: Incrementally reserve pages on win server 2003 for better large page affinity
jmasa
parents:
356
diff
changeset
|
3668 if (!DuplicateHandle(main_process, GetCurrentThread(), main_process, |
0 | 3669 &main_thread, THREAD_ALL_ACCESS, false, 0)) { |
3670 fatal("DuplicateHandle failed\n"); | |
3671 } | |
3672 main_thread_id = (int) GetCurrentThreadId(); | |
3673 } | |
3674 | |
3675 // To install functions for atexit processing | |
3676 extern "C" { | |
3677 static void perfMemory_exit_helper() { | |
3678 perfMemory_exit(); | |
3679 } | |
3680 } | |
3681 | |
3682 // this is called _after_ the global arguments have been parsed | |
3683 jint os::init_2(void) { | |
3684 // Allocate a single page and mark it as readable for safepoint polling | |
3685 address polling_page = (address)VirtualAlloc(NULL, os::vm_page_size(), MEM_RESERVE, PAGE_READONLY); | |
3686 guarantee( polling_page != NULL, "Reserve Failed for polling page"); | |
3687 | |
3688 address return_page = (address)VirtualAlloc(polling_page, os::vm_page_size(), MEM_COMMIT, PAGE_READONLY); | |
3689 guarantee( return_page != NULL, "Commit Failed for polling page"); | |
3690 | |
3691 os::set_polling_page( polling_page ); | |
3692 | |
3693 #ifndef PRODUCT | |
3694 if( Verbose && PrintMiscellaneous ) | |
3695 tty->print("[SafePoint Polling address: " INTPTR_FORMAT "]\n", (intptr_t)polling_page); | |
3696 #endif | |
3697 | |
3698 if (!UseMembar) { | |
656 | 3699 address mem_serialize_page = (address)VirtualAlloc(NULL, os::vm_page_size(), MEM_RESERVE, PAGE_READWRITE); |
0 | 3700 guarantee( mem_serialize_page != NULL, "Reserve Failed for memory serialize page"); |
3701 | |
656 | 3702 return_page = (address)VirtualAlloc(mem_serialize_page, os::vm_page_size(), MEM_COMMIT, PAGE_READWRITE); |
0 | 3703 guarantee( return_page != NULL, "Commit Failed for memory serialize page"); |
3704 | |
3705 os::set_memory_serialize_page( mem_serialize_page ); | |
3706 | |
3707 #ifndef PRODUCT | |
3708 if(Verbose && PrintMiscellaneous) | |
3709 tty->print("[Memory Serialize Page address: " INTPTR_FORMAT "]\n", (intptr_t)mem_serialize_page); | |
3710 #endif | |
3885 | 3711 } |
0 | 3712 |
3318
188c9a5d6a6d
7040485: Use transparent huge page on linux by default
iveresov
parents:
3240
diff
changeset
|
3713 os::large_page_init(); |
0 | 3714 |
3715 // Setup Windows Exceptions | |
3716 | |
3717 // On Itanium systems, Structured Exception Handling does not | |
3718 // work since stack frames must be walkable by the OS. Since | |
3719 // much of our code is dynamically generated, and we do not have | |
3720 // proper unwind .xdata sections, the system simply exits | |
3721 // rather than delivering the exception. To work around | |
3722 // this we use VectorExceptions instead. | |
3723 #ifdef _WIN64 | |
3724 if (UseVectoredExceptions) { | |
3725 topLevelVectoredExceptionHandler = AddVectoredExceptionHandler( 1, topLevelExceptionFilter); | |
3726 } | |
3727 #endif | |
3728 | |
3729 // for debugging float code generation bugs | |
3730 if (ForceFloatExceptions) { | |
3731 #ifndef _WIN64 | |
3732 static long fp_control_word = 0; | |
3733 __asm { fstcw fp_control_word } | |
3734 // see Intel PPro Manual, Vol. 2, p 7-16 | |
3735 const long precision = 0x20; | |
3736 const long underflow = 0x10; | |
3737 const long overflow = 0x08; | |
3738 const long zero_div = 0x04; | |
3739 const long denorm = 0x02; | |
3740 const long invalid = 0x01; | |
3741 fp_control_word |= invalid; | |
3742 __asm { fldcw fp_control_word } | |
3743 #endif | |
3744 } | |
3745 | |
3746 // If stack_commit_size is 0, windows will reserve the default size, | |
3747 // but only commit a small portion of it. | |
3748 size_t stack_commit_size = round_to(ThreadStackSize*K, os::vm_page_size()); | |
3749 size_t default_reserve_size = os::win32::default_stack_size(); | |
3750 size_t actual_reserve_size = stack_commit_size; | |
3751 if (stack_commit_size < default_reserve_size) { | |
3752 // If stack_commit_size == 0, we want this too | |
3753 actual_reserve_size = default_reserve_size; | |
3754 } | |
3755 | |
1867
b6aedd1acdc0
6983240: guarantee((Solaris::min_stack_allowed >= (StackYellowPages+StackRedPages...) wrong
coleenp
parents:
1865
diff
changeset
|
3756 // Check minimum allowable stack size for thread creation and to initialize |
b6aedd1acdc0
6983240: guarantee((Solaris::min_stack_allowed >= (StackYellowPages+StackRedPages...) wrong
coleenp
parents:
1865
diff
changeset
|
3757 // the java system classes, including StackOverflowError - depends on page |
b6aedd1acdc0
6983240: guarantee((Solaris::min_stack_allowed >= (StackYellowPages+StackRedPages...) wrong
coleenp
parents:
1865
diff
changeset
|
3758 // size. Add a page for compiler2 recursion in main thread. |
b6aedd1acdc0
6983240: guarantee((Solaris::min_stack_allowed >= (StackYellowPages+StackRedPages...) wrong
coleenp
parents:
1865
diff
changeset
|
3759 // Add in 2*BytesPerWord times page size to account for VM stack during |
b6aedd1acdc0
6983240: guarantee((Solaris::min_stack_allowed >= (StackYellowPages+StackRedPages...) wrong
coleenp
parents:
1865
diff
changeset
|
3760 // class initialization depending on 32 or 64 bit VM. |
b6aedd1acdc0
6983240: guarantee((Solaris::min_stack_allowed >= (StackYellowPages+StackRedPages...) wrong
coleenp
parents:
1865
diff
changeset
|
3761 size_t min_stack_allowed = |
b6aedd1acdc0
6983240: guarantee((Solaris::min_stack_allowed >= (StackYellowPages+StackRedPages...) wrong
coleenp
parents:
1865
diff
changeset
|
3762 (size_t)(StackYellowPages+StackRedPages+StackShadowPages+ |
b6aedd1acdc0
6983240: guarantee((Solaris::min_stack_allowed >= (StackYellowPages+StackRedPages...) wrong
coleenp
parents:
1865
diff
changeset
|
3763 2*BytesPerWord COMPILER2_PRESENT(+1)) * os::vm_page_size(); |
b6aedd1acdc0
6983240: guarantee((Solaris::min_stack_allowed >= (StackYellowPages+StackRedPages...) wrong
coleenp
parents:
1865
diff
changeset
|
3764 if (actual_reserve_size < min_stack_allowed) { |
b6aedd1acdc0
6983240: guarantee((Solaris::min_stack_allowed >= (StackYellowPages+StackRedPages...) wrong
coleenp
parents:
1865
diff
changeset
|
3765 tty->print_cr("\nThe stack size specified is too small, " |
b6aedd1acdc0
6983240: guarantee((Solaris::min_stack_allowed >= (StackYellowPages+StackRedPages...) wrong
coleenp
parents:
1865
diff
changeset
|
3766 "Specify at least %dk", |
b6aedd1acdc0
6983240: guarantee((Solaris::min_stack_allowed >= (StackYellowPages+StackRedPages...) wrong
coleenp
parents:
1865
diff
changeset
|
3767 min_stack_allowed / K); |
b6aedd1acdc0
6983240: guarantee((Solaris::min_stack_allowed >= (StackYellowPages+StackRedPages...) wrong
coleenp
parents:
1865
diff
changeset
|
3768 return JNI_ERR; |
b6aedd1acdc0
6983240: guarantee((Solaris::min_stack_allowed >= (StackYellowPages+StackRedPages...) wrong
coleenp
parents:
1865
diff
changeset
|
3769 } |
b6aedd1acdc0
6983240: guarantee((Solaris::min_stack_allowed >= (StackYellowPages+StackRedPages...) wrong
coleenp
parents:
1865
diff
changeset
|
3770 |
0 | 3771 JavaThread::set_stack_size_at_create(stack_commit_size); |
3772 | |
3773 // Calculate theoretical max. size of Threads to guard gainst artifical | |
3774 // out-of-memory situations, where all available address-space has been | |
3775 // reserved by thread stacks. | |
3776 assert(actual_reserve_size != 0, "Must have a stack"); | |
3777 | |
3778 // Calculate the thread limit when we should start doing Virtual Memory | |
3779 // banging. Currently when the threads will have used all but 200Mb of space. | |
3780 // | |
3781 // TODO: consider performing a similar calculation for commit size instead | |
3782 // as reserve size, since on a 64-bit platform we'll run into that more | |
3783 // often than running out of virtual memory space. We can use the | |
3784 // lower value of the two calculations as the os_thread_limit. | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
79
diff
changeset
|
3785 size_t max_address_space = ((size_t)1 << (BitsPerWord - 1)) - (200 * K * K); |
0 | 3786 win32::_os_thread_limit = (intx)(max_address_space / actual_reserve_size); |
3787 | |
3788 // at exit methods are called in the reverse order of their registration. | |
3789 // there is no limit to the number of functions registered. atexit does | |
3790 // not set errno. | |
3791 | |
3792 if (PerfAllowAtExitRegistration) { | |
3793 // only register atexit functions if PerfAllowAtExitRegistration is set. | |
3794 // atexit functions can be delayed until process exit time, which | |
3795 // can be problematic for embedded VM situations. Embedded VMs should | |
3796 // call DestroyJavaVM() to assure that VM resources are released. | |
3797 | |
3798 // note: perfMemory_exit_helper atexit function may be removed in | |
3799 // the future if the appropriate cleanup code can be added to the | |
3800 // VM_Exit VMOperation's doit method. | |
3801 if (atexit(perfMemory_exit_helper) != 0) { | |
3802 warning("os::init_2 atexit(perfMemory_exit_helper) failed"); | |
3803 } | |
3804 } | |
3805 | |
3806 #ifndef _WIN64 | |
3807 // Print something if NX is enabled (win32 on AMD64) | |
3808 NOT_PRODUCT(if (PrintMiscellaneous && Verbose) nx_check_protection()); | |
3809 #endif | |
3810 | |
3811 // initialize thread priority policy | |
3812 prio_init(); | |
3813 | |
3918
a6128a8ed624
7086226: UseNUMA fails on old versions of windows
iveresov
parents:
3885
diff
changeset
|
3814 if (UseNUMA && !ForceNUMA) { |
a6128a8ed624
7086226: UseNUMA fails on old versions of windows
iveresov
parents:
3885
diff
changeset
|
3815 UseNUMA = false; // We don't fully support this yet |
a6128a8ed624
7086226: UseNUMA fails on old versions of windows
iveresov
parents:
3885
diff
changeset
|
3816 } |
a6128a8ed624
7086226: UseNUMA fails on old versions of windows
iveresov
parents:
3885
diff
changeset
|
3817 |
3885 | 3818 if (UseNUMAInterleaving) { |
3819 // first check whether this Windows OS supports VirtualAllocExNuma, if not ignore this flag | |
3820 bool success = numa_interleaving_init(); | |
3821 if (!success) UseNUMAInterleaving = false; | |
462
85f1b9537f70
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
389
diff
changeset
|
3822 } |
85f1b9537f70
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
389
diff
changeset
|
3823 |
0 | 3824 return JNI_OK; |
3825 } | |
3826 | |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1552
diff
changeset
|
3827 void os::init_3(void) { |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1552
diff
changeset
|
3828 return; |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1552
diff
changeset
|
3829 } |
0 | 3830 |
3831 // Mark the polling page as unreadable | |
3832 void os::make_polling_page_unreadable(void) { | |
3833 DWORD old_status; | |
3834 if( !VirtualProtect((char *)_polling_page, os::vm_page_size(), PAGE_NOACCESS, &old_status) ) | |
3835 fatal("Could not disable polling page"); | |
3836 }; | |
3837 | |
3838 // Mark the polling page as readable | |
3839 void os::make_polling_page_readable(void) { | |
3840 DWORD old_status; | |
3841 if( !VirtualProtect((char *)_polling_page, os::vm_page_size(), PAGE_READONLY, &old_status) ) | |
3842 fatal("Could not enable polling page"); | |
3843 }; | |
3844 | |
3845 | |
3846 int os::stat(const char *path, struct stat *sbuf) { | |
3847 char pathbuf[MAX_PATH]; | |
3848 if (strlen(path) > MAX_PATH - 1) { | |
3849 errno = ENAMETOOLONG; | |
3850 return -1; | |
3851 } | |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
3852 os::native_path(strcpy(pathbuf, path)); |
0 | 3853 int ret = ::stat(pathbuf, sbuf); |
3854 if (sbuf != NULL && UseUTCFileTimestamp) { | |
3855 // Fix for 6539723. st_mtime returned from stat() is dependent on | |
3856 // the system timezone and so can return different values for the | |
3857 // same file if/when daylight savings time changes. This adjustment | |
3858 // makes sure the same timestamp is returned regardless of the TZ. | |
3859 // | |
3860 // See: | |
3861 // http://msdn.microsoft.com/library/ | |
3862 // default.asp?url=/library/en-us/sysinfo/base/ | |
3863 // time_zone_information_str.asp | |
3864 // and | |
3865 // http://msdn.microsoft.com/library/default.asp?url= | |
3866 // /library/en-us/sysinfo/base/settimezoneinformation.asp | |
3867 // | |
3868 // NOTE: there is a insidious bug here: If the timezone is changed | |
3869 // after the call to stat() but before 'GetTimeZoneInformation()', then | |
3870 // the adjustment we do here will be wrong and we'll return the wrong | |
3871 // value (which will likely end up creating an invalid class data | |
3872 // archive). Absent a better API for this, or some time zone locking | |
3873 // mechanism, we'll have to live with this risk. | |
3874 TIME_ZONE_INFORMATION tz; | |
3875 DWORD tzid = GetTimeZoneInformation(&tz); | |
3876 int daylightBias = | |
3877 (tzid == TIME_ZONE_ID_DAYLIGHT) ? tz.DaylightBias : tz.StandardBias; | |
3878 sbuf->st_mtime += (tz.Bias + daylightBias) * 60; | |
3879 } | |
3880 return ret; | |
3881 } | |
3882 | |
3883 | |
3884 #define FT2INT64(ft) \ | |
3885 ((jlong)((jlong)(ft).dwHighDateTime << 32 | (julong)(ft).dwLowDateTime)) | |
3886 | |
3887 | |
3888 // current_thread_cpu_time(bool) and thread_cpu_time(Thread*, bool) | |
3889 // are used by JVM M&M and JVMTI to get user+sys or user CPU time | |
3890 // of a thread. | |
3891 // | |
3892 // current_thread_cpu_time() and thread_cpu_time(Thread*) returns | |
3893 // the fast estimate available on the platform. | |
3894 | |
3895 // current_thread_cpu_time() is not optimized for Windows yet | |
3896 jlong os::current_thread_cpu_time() { | |
3897 // return user + sys since the cost is the same | |
3898 return os::thread_cpu_time(Thread::current(), true /* user+sys */); | |
3899 } | |
3900 | |
3901 jlong os::thread_cpu_time(Thread* thread) { | |
3902 // consistent with what current_thread_cpu_time() returns. | |
3903 return os::thread_cpu_time(thread, true /* user+sys */); | |
3904 } | |
3905 | |
3906 jlong os::current_thread_cpu_time(bool user_sys_cpu_time) { | |
3907 return os::thread_cpu_time(Thread::current(), user_sys_cpu_time); | |
3908 } | |
3909 | |
3910 jlong os::thread_cpu_time(Thread* thread, bool user_sys_cpu_time) { | |
3911 // This code is copy from clasic VM -> hpi::sysThreadCPUTime | |
3912 // If this function changes, os::is_thread_cpu_time_supported() should too | |
3913 if (os::win32::is_nt()) { | |
3914 FILETIME CreationTime; | |
3915 FILETIME ExitTime; | |
3916 FILETIME KernelTime; | |
3917 FILETIME UserTime; | |
3918 | |
3919 if ( GetThreadTimes(thread->osthread()->thread_handle(), | |
3920 &CreationTime, &ExitTime, &KernelTime, &UserTime) == 0) | |
3921 return -1; | |
3922 else | |
3923 if (user_sys_cpu_time) { | |
3924 return (FT2INT64(UserTime) + FT2INT64(KernelTime)) * 100; | |
3925 } else { | |
3926 return FT2INT64(UserTime) * 100; | |
3927 } | |
3928 } else { | |
3929 return (jlong) timeGetTime() * 1000000; | |
3930 } | |
3931 } | |
3932 | |
3933 void os::current_thread_cpu_time_info(jvmtiTimerInfo *info_ptr) { | |
3934 info_ptr->max_value = ALL_64_BITS; // the max value -- all 64 bits | |
3935 info_ptr->may_skip_backward = false; // GetThreadTimes returns absolute time | |
3936 info_ptr->may_skip_forward = false; // GetThreadTimes returns absolute time | |
3937 info_ptr->kind = JVMTI_TIMER_TOTAL_CPU; // user+system time is returned | |
3938 } | |
3939 | |
3940 void os::thread_cpu_time_info(jvmtiTimerInfo *info_ptr) { | |
3941 info_ptr->max_value = ALL_64_BITS; // the max value -- all 64 bits | |
3942 info_ptr->may_skip_backward = false; // GetThreadTimes returns absolute time | |
3943 info_ptr->may_skip_forward = false; // GetThreadTimes returns absolute time | |
3944 info_ptr->kind = JVMTI_TIMER_TOTAL_CPU; // user+system time is returned | |
3945 } | |
3946 | |
3947 bool os::is_thread_cpu_time_supported() { | |
3948 // see os::thread_cpu_time | |
3949 if (os::win32::is_nt()) { | |
3950 FILETIME CreationTime; | |
3951 FILETIME ExitTime; | |
3952 FILETIME KernelTime; | |
3953 FILETIME UserTime; | |
3954 | |
3955 if ( GetThreadTimes(GetCurrentThread(), | |
3956 &CreationTime, &ExitTime, &KernelTime, &UserTime) == 0) | |
3957 return false; | |
3958 else | |
3959 return true; | |
3960 } else { | |
3961 return false; | |
3962 } | |
3963 } | |
3964 | |
3965 // Windows does't provide a loadavg primitive so this is stubbed out for now. | |
3966 // It does have primitives (PDH API) to get CPU usage and run queue length. | |
3967 // "\\Processor(_Total)\\% Processor Time", "\\System\\Processor Queue Length" | |
3968 // If we wanted to implement loadavg on Windows, we have a few options: | |
3969 // | |
3970 // a) Query CPU usage and run queue length and "fake" an answer by | |
3971 // returning the CPU usage if it's under 100%, and the run queue | |
3972 // length otherwise. It turns out that querying is pretty slow | |
3973 // on Windows, on the order of 200 microseconds on a fast machine. | |
3974 // Note that on the Windows the CPU usage value is the % usage | |
3975 // since the last time the API was called (and the first call | |
3976 // returns 100%), so we'd have to deal with that as well. | |
3977 // | |
3978 // b) Sample the "fake" answer using a sampling thread and store | |
3979 // the answer in a global variable. The call to loadavg would | |
3980 // just return the value of the global, avoiding the slow query. | |
3981 // | |
3982 // c) Sample a better answer using exponential decay to smooth the | |
3983 // value. This is basically the algorithm used by UNIX kernels. | |
3984 // | |
3985 // Note that sampling thread starvation could affect both (b) and (c). | |
3986 int os::loadavg(double loadavg[], int nelem) { | |
3987 return -1; | |
3988 } | |
3989 | |
3990 | |
3991 // DontYieldALot=false by default: dutifully perform all yields as requested by JVM_Yield() | |
3992 bool os::dont_yield() { | |
3993 return DontYieldALot; | |
3994 } | |
3995 | |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
3996 // This method is a slightly reworked copy of JDK's sysOpen |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
3997 // from src/windows/hpi/src/sys_api_md.c |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
3998 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
3999 int os::open(const char *path, int oflag, int mode) { |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4000 char pathbuf[MAX_PATH]; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4001 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4002 if (strlen(path) > MAX_PATH - 1) { |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4003 errno = ENAMETOOLONG; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4004 return -1; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4005 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4006 os::native_path(strcpy(pathbuf, path)); |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4007 return ::open(pathbuf, oflag | O_BINARY | O_NOINHERIT, mode); |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4008 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4009 |
0 | 4010 // Is a (classpath) directory empty? |
4011 bool os::dir_is_empty(const char* path) { | |
4012 WIN32_FIND_DATA fd; | |
4013 HANDLE f = FindFirstFile(path, &fd); | |
4014 if (f == INVALID_HANDLE_VALUE) { | |
4015 return true; | |
4016 } | |
4017 FindClose(f); | |
4018 return false; | |
4019 } | |
4020 | |
4021 // create binary file, rewriting existing file if required | |
4022 int os::create_binary_file(const char* path, bool rewrite_existing) { | |
4023 int oflags = _O_CREAT | _O_WRONLY | _O_BINARY; | |
4024 if (!rewrite_existing) { | |
4025 oflags |= _O_EXCL; | |
4026 } | |
4027 return ::open(path, oflags, _S_IREAD | _S_IWRITE); | |
4028 } | |
4029 | |
4030 // return current position of file pointer | |
4031 jlong os::current_file_offset(int fd) { | |
4032 return (jlong)::_lseeki64(fd, (__int64)0L, SEEK_CUR); | |
4033 } | |
4034 | |
4035 // move file pointer to the specified offset | |
4036 jlong os::seek_to_file_offset(int fd, jlong offset) { | |
4037 return (jlong)::_lseeki64(fd, (__int64)offset, SEEK_SET); | |
4038 } | |
4039 | |
4040 | |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4041 jlong os::lseek(int fd, jlong offset, int whence) { |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4042 return (jlong) ::_lseeki64(fd, offset, whence); |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4043 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4044 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4045 // This method is a slightly reworked copy of JDK's sysNativePath |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4046 // from src/windows/hpi/src/path_md.c |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4047 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4048 /* Convert a pathname to native format. On win32, this involves forcing all |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4049 separators to be '\\' rather than '/' (both are legal inputs, but Win95 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4050 sometimes rejects '/') and removing redundant separators. The input path is |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4051 assumed to have been converted into the character encoding used by the local |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4052 system. Because this might be a double-byte encoding, care is taken to |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4053 treat double-byte lead characters correctly. |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4054 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4055 This procedure modifies the given path in place, as the result is never |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4056 longer than the original. There is no error return; this operation always |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4057 succeeds. */ |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4058 char * os::native_path(char *path) { |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4059 char *src = path, *dst = path, *end = path; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4060 char *colon = NULL; /* If a drive specifier is found, this will |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4061 point to the colon following the drive |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4062 letter */ |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4063 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4064 /* Assumption: '/', '\\', ':', and drive letters are never lead bytes */ |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4065 assert(((!::IsDBCSLeadByte('/')) |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4066 && (!::IsDBCSLeadByte('\\')) |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4067 && (!::IsDBCSLeadByte(':'))), |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4068 "Illegal lead byte"); |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4069 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4070 /* Check for leading separators */ |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4071 #define isfilesep(c) ((c) == '/' || (c) == '\\') |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4072 while (isfilesep(*src)) { |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4073 src++; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4074 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4075 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4076 if (::isalpha(*src) && !::IsDBCSLeadByte(*src) && src[1] == ':') { |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4077 /* Remove leading separators if followed by drive specifier. This |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4078 hack is necessary to support file URLs containing drive |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4079 specifiers (e.g., "file://c:/path"). As a side effect, |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4080 "/c:/path" can be used as an alternative to "c:/path". */ |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4081 *dst++ = *src++; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4082 colon = dst; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4083 *dst++ = ':'; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4084 src++; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4085 } else { |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4086 src = path; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4087 if (isfilesep(src[0]) && isfilesep(src[1])) { |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4088 /* UNC pathname: Retain first separator; leave src pointed at |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4089 second separator so that further separators will be collapsed |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4090 into the second separator. The result will be a pathname |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4091 beginning with "\\\\" followed (most likely) by a host name. */ |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4092 src = dst = path + 1; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4093 path[0] = '\\'; /* Force first separator to '\\' */ |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4094 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4095 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4096 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4097 end = dst; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4098 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4099 /* Remove redundant separators from remainder of path, forcing all |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4100 separators to be '\\' rather than '/'. Also, single byte space |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4101 characters are removed from the end of the path because those |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4102 are not legal ending characters on this operating system. |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4103 */ |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4104 while (*src != '\0') { |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4105 if (isfilesep(*src)) { |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4106 *dst++ = '\\'; src++; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4107 while (isfilesep(*src)) src++; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4108 if (*src == '\0') { |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4109 /* Check for trailing separator */ |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4110 end = dst; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4111 if (colon == dst - 2) break; /* "z:\\" */ |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4112 if (dst == path + 1) break; /* "\\" */ |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4113 if (dst == path + 2 && isfilesep(path[0])) { |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4114 /* "\\\\" is not collapsed to "\\" because "\\\\" marks the |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4115 beginning of a UNC pathname. Even though it is not, by |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4116 itself, a valid UNC pathname, we leave it as is in order |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4117 to be consistent with the path canonicalizer as well |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4118 as the win32 APIs, which treat this case as an invalid |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4119 UNC pathname rather than as an alias for the root |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4120 directory of the current drive. */ |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4121 break; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4122 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4123 end = --dst; /* Path does not denote a root directory, so |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4124 remove trailing separator */ |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4125 break; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4126 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4127 end = dst; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4128 } else { |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4129 if (::IsDBCSLeadByte(*src)) { /* Copy a double-byte character */ |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4130 *dst++ = *src++; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4131 if (*src) *dst++ = *src++; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4132 end = dst; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4133 } else { /* Copy a single-byte character */ |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4134 char c = *src++; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4135 *dst++ = c; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4136 /* Space is not a legal ending character */ |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4137 if (c != ' ') end = dst; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4138 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4139 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4140 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4141 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4142 *end = '\0'; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4143 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4144 /* For "z:", add "." to work around a bug in the C runtime library */ |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4145 if (colon == dst - 1) { |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4146 path[2] = '.'; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4147 path[3] = '\0'; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4148 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4149 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4150 #ifdef DEBUG |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4151 jio_fprintf(stderr, "sysNativePath: %s\n", path); |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4152 #endif DEBUG |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4153 return path; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4154 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4155 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4156 // This code is a copy of JDK's sysSetLength |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4157 // from src/windows/hpi/src/sys_api_md.c |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4158 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4159 int os::ftruncate(int fd, jlong length) { |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4160 HANDLE h = (HANDLE)::_get_osfhandle(fd); |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4161 long high = (long)(length >> 32); |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4162 DWORD ret; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4163 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4164 if (h == (HANDLE)(-1)) { |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4165 return -1; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4166 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4167 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4168 ret = ::SetFilePointer(h, (long)(length), &high, FILE_BEGIN); |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4169 if ((ret == 0xFFFFFFFF) && (::GetLastError() != NO_ERROR)) { |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4170 return -1; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4171 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4172 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4173 if (::SetEndOfFile(h) == FALSE) { |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4174 return -1; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4175 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4176 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4177 return 0; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4178 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4179 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4180 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4181 // This code is a copy of JDK's sysSync |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4182 // from src/windows/hpi/src/sys_api_md.c |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4183 // except for the legacy workaround for a bug in Win 98 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4184 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4185 int os::fsync(int fd) { |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4186 HANDLE handle = (HANDLE)::_get_osfhandle(fd); |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4187 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4188 if ( (!::FlushFileBuffers(handle)) && |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4189 (GetLastError() != ERROR_ACCESS_DENIED) ) { |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4190 /* from winerror.h */ |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4191 return -1; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4192 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4193 return 0; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4194 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4195 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4196 static int nonSeekAvailable(int, long *); |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4197 static int stdinAvailable(int, long *); |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4198 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4199 #define S_ISCHR(mode) (((mode) & _S_IFCHR) == _S_IFCHR) |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4200 #define S_ISFIFO(mode) (((mode) & _S_IFIFO) == _S_IFIFO) |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4201 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4202 // This code is a copy of JDK's sysAvailable |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4203 // from src/windows/hpi/src/sys_api_md.c |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4204 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4205 int os::available(int fd, jlong *bytes) { |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4206 jlong cur, end; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4207 struct _stati64 stbuf64; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4208 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4209 if (::_fstati64(fd, &stbuf64) >= 0) { |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4210 int mode = stbuf64.st_mode; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4211 if (S_ISCHR(mode) || S_ISFIFO(mode)) { |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4212 int ret; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4213 long lpbytes; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4214 if (fd == 0) { |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4215 ret = stdinAvailable(fd, &lpbytes); |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4216 } else { |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4217 ret = nonSeekAvailable(fd, &lpbytes); |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4218 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4219 (*bytes) = (jlong)(lpbytes); |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4220 return ret; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4221 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4222 if ((cur = ::_lseeki64(fd, 0L, SEEK_CUR)) == -1) { |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4223 return FALSE; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4224 } else if ((end = ::_lseeki64(fd, 0L, SEEK_END)) == -1) { |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4225 return FALSE; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4226 } else if (::_lseeki64(fd, cur, SEEK_SET) == -1) { |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4227 return FALSE; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4228 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4229 *bytes = end - cur; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4230 return TRUE; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4231 } else { |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4232 return FALSE; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4233 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4234 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4235 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4236 // This code is a copy of JDK's nonSeekAvailable |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4237 // from src/windows/hpi/src/sys_api_md.c |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4238 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4239 static int nonSeekAvailable(int fd, long *pbytes) { |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4240 /* This is used for available on non-seekable devices |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4241 * (like both named and anonymous pipes, such as pipes |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4242 * connected to an exec'd process). |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4243 * Standard Input is a special case. |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4244 * |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4245 */ |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4246 HANDLE han; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4247 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4248 if ((han = (HANDLE) ::_get_osfhandle(fd)) == (HANDLE)(-1)) { |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4249 return FALSE; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4250 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4251 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4252 if (! ::PeekNamedPipe(han, NULL, 0, NULL, (LPDWORD)pbytes, NULL)) { |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4253 /* PeekNamedPipe fails when at EOF. In that case we |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4254 * simply make *pbytes = 0 which is consistent with the |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4255 * behavior we get on Solaris when an fd is at EOF. |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4256 * The only alternative is to raise an Exception, |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4257 * which isn't really warranted. |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4258 */ |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4259 if (::GetLastError() != ERROR_BROKEN_PIPE) { |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4260 return FALSE; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4261 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4262 *pbytes = 0; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4263 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4264 return TRUE; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4265 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4266 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4267 #define MAX_INPUT_EVENTS 2000 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4268 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4269 // This code is a copy of JDK's stdinAvailable |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4270 // from src/windows/hpi/src/sys_api_md.c |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4271 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4272 static int stdinAvailable(int fd, long *pbytes) { |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4273 HANDLE han; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4274 DWORD numEventsRead = 0; /* Number of events read from buffer */ |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4275 DWORD numEvents = 0; /* Number of events in buffer */ |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4276 DWORD i = 0; /* Loop index */ |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4277 DWORD curLength = 0; /* Position marker */ |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4278 DWORD actualLength = 0; /* Number of bytes readable */ |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4279 BOOL error = FALSE; /* Error holder */ |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4280 INPUT_RECORD *lpBuffer; /* Pointer to records of input events */ |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4281 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4282 if ((han = ::GetStdHandle(STD_INPUT_HANDLE)) == INVALID_HANDLE_VALUE) { |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4283 return FALSE; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4284 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4285 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4286 /* Construct an array of input records in the console buffer */ |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4287 error = ::GetNumberOfConsoleInputEvents(han, &numEvents); |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4288 if (error == 0) { |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4289 return nonSeekAvailable(fd, pbytes); |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4290 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4291 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4292 /* lpBuffer must fit into 64K or else PeekConsoleInput fails */ |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4293 if (numEvents > MAX_INPUT_EVENTS) { |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4294 numEvents = MAX_INPUT_EVENTS; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4295 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4296 |
6197 | 4297 lpBuffer = (INPUT_RECORD *)os::malloc(numEvents * sizeof(INPUT_RECORD), mtInternal); |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4298 if (lpBuffer == NULL) { |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4299 return FALSE; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4300 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4301 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4302 error = ::PeekConsoleInput(han, lpBuffer, numEvents, &numEventsRead); |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4303 if (error == 0) { |
6197 | 4304 os::free(lpBuffer, mtInternal); |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4305 return FALSE; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4306 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4307 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4308 /* Examine input records for the number of bytes available */ |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4309 for(i=0; i<numEvents; i++) { |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4310 if (lpBuffer[i].EventType == KEY_EVENT) { |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4311 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4312 KEY_EVENT_RECORD *keyRecord = (KEY_EVENT_RECORD *) |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4313 &(lpBuffer[i].Event); |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4314 if (keyRecord->bKeyDown == TRUE) { |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4315 CHAR *keyPressed = (CHAR *) &(keyRecord->uChar); |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4316 curLength++; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4317 if (*keyPressed == '\r') { |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4318 actualLength = curLength; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4319 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4320 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4321 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4322 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4323 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4324 if(lpBuffer != NULL) { |
6197 | 4325 os::free(lpBuffer, mtInternal); |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4326 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4327 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4328 *pbytes = (long) actualLength; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4329 return TRUE; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4330 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4331 |
0 | 4332 // Map a block of memory. |
6197 | 4333 char* os::pd_map_memory(int fd, const char* file_name, size_t file_offset, |
0 | 4334 char *addr, size_t bytes, bool read_only, |
4335 bool allow_exec) { | |
4336 HANDLE hFile; | |
4337 char* base; | |
4338 | |
4339 hFile = CreateFile(file_name, GENERIC_READ, FILE_SHARE_READ, NULL, | |
4340 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); | |
4341 if (hFile == NULL) { | |
4342 if (PrintMiscellaneous && Verbose) { | |
4343 DWORD err = GetLastError(); | |
4344 tty->print_cr("CreateFile() failed: GetLastError->%ld."); | |
4345 } | |
4346 return NULL; | |
4347 } | |
4348 | |
4349 if (allow_exec) { | |
4350 // CreateFileMapping/MapViewOfFileEx can't map executable memory | |
4351 // unless it comes from a PE image (which the shared archive is not.) | |
4352 // Even VirtualProtect refuses to give execute access to mapped memory | |
4353 // that was not previously executable. | |
4354 // | |
4355 // Instead, stick the executable region in anonymous memory. Yuck. | |
4356 // Penalty is that ~4 pages will not be shareable - in the future | |
4357 // we might consider DLLizing the shared archive with a proper PE | |
4358 // header so that mapping executable + sharing is possible. | |
4359 | |
4360 base = (char*) VirtualAlloc(addr, bytes, MEM_COMMIT | MEM_RESERVE, | |
4361 PAGE_READWRITE); | |
4362 if (base == NULL) { | |
4363 if (PrintMiscellaneous && Verbose) { | |
4364 DWORD err = GetLastError(); | |
4365 tty->print_cr("VirtualAlloc() failed: GetLastError->%ld.", err); | |
4366 } | |
4367 CloseHandle(hFile); | |
4368 return NULL; | |
4369 } | |
4370 | |
4371 DWORD bytes_read; | |
4372 OVERLAPPED overlapped; | |
4373 overlapped.Offset = (DWORD)file_offset; | |
4374 overlapped.OffsetHigh = 0; | |
4375 overlapped.hEvent = NULL; | |
4376 // ReadFile guarantees that if the return value is true, the requested | |
4377 // number of bytes were read before returning. | |
4378 bool res = ReadFile(hFile, base, (DWORD)bytes, &bytes_read, &overlapped) != 0; | |
4379 if (!res) { | |
4380 if (PrintMiscellaneous && Verbose) { | |
4381 DWORD err = GetLastError(); | |
4382 tty->print_cr("ReadFile() failed: GetLastError->%ld.", err); | |
4383 } | |
4384 release_memory(base, bytes); | |
4385 CloseHandle(hFile); | |
4386 return NULL; | |
4387 } | |
4388 } else { | |
4389 HANDLE hMap = CreateFileMapping(hFile, NULL, PAGE_WRITECOPY, 0, 0, | |
4390 NULL /*file_name*/); | |
4391 if (hMap == NULL) { | |
4392 if (PrintMiscellaneous && Verbose) { | |
4393 DWORD err = GetLastError(); | |
4394 tty->print_cr("CreateFileMapping() failed: GetLastError->%ld."); | |
4395 } | |
4396 CloseHandle(hFile); | |
4397 return NULL; | |
4398 } | |
4399 | |
4400 DWORD access = read_only ? FILE_MAP_READ : FILE_MAP_COPY; | |
4401 base = (char*)MapViewOfFileEx(hMap, access, 0, (DWORD)file_offset, | |
4402 (DWORD)bytes, addr); | |
4403 if (base == NULL) { | |
4404 if (PrintMiscellaneous && Verbose) { | |
4405 DWORD err = GetLastError(); | |
4406 tty->print_cr("MapViewOfFileEx() failed: GetLastError->%ld.", err); | |
4407 } | |
4408 CloseHandle(hMap); | |
4409 CloseHandle(hFile); | |
4410 return NULL; | |
4411 } | |
4412 | |
4413 if (CloseHandle(hMap) == 0) { | |
4414 if (PrintMiscellaneous && Verbose) { | |
4415 DWORD err = GetLastError(); | |
4416 tty->print_cr("CloseHandle(hMap) failed: GetLastError->%ld.", err); | |
4417 } | |
4418 CloseHandle(hFile); | |
4419 return base; | |
4420 } | |
4421 } | |
4422 | |
4423 if (allow_exec) { | |
4424 DWORD old_protect; | |
4425 DWORD exec_access = read_only ? PAGE_EXECUTE_READ : PAGE_EXECUTE_READWRITE; | |
4426 bool res = VirtualProtect(base, bytes, exec_access, &old_protect) != 0; | |
4427 | |
4428 if (!res) { | |
4429 if (PrintMiscellaneous && Verbose) { | |
4430 DWORD err = GetLastError(); | |
4431 tty->print_cr("VirtualProtect() failed: GetLastError->%ld.", err); | |
4432 } | |
4433 // Don't consider this a hard error, on IA32 even if the | |
4434 // VirtualProtect fails, we should still be able to execute | |
4435 CloseHandle(hFile); | |
4436 return base; | |
4437 } | |
4438 } | |
4439 | |
4440 if (CloseHandle(hFile) == 0) { | |
4441 if (PrintMiscellaneous && Verbose) { | |
4442 DWORD err = GetLastError(); | |
4443 tty->print_cr("CloseHandle(hFile) failed: GetLastError->%ld.", err); | |
4444 } | |
4445 return base; | |
4446 } | |
4447 | |
4448 return base; | |
4449 } | |
4450 | |
4451 | |
4452 // Remap a block of memory. | |
6197 | 4453 char* os::pd_remap_memory(int fd, const char* file_name, size_t file_offset, |
0 | 4454 char *addr, size_t bytes, bool read_only, |
4455 bool allow_exec) { | |
4456 // This OS does not allow existing memory maps to be remapped so we | |
4457 // have to unmap the memory before we remap it. | |
4458 if (!os::unmap_memory(addr, bytes)) { | |
4459 return NULL; | |
4460 } | |
4461 | |
4462 // There is a very small theoretical window between the unmap_memory() | |
4463 // call above and the map_memory() call below where a thread in native | |
4464 // code may be able to access an address that is no longer mapped. | |
4465 | |
6197 | 4466 return os::map_memory(fd, file_name, file_offset, addr, bytes, |
4467 read_only, allow_exec); | |
0 | 4468 } |
4469 | |
4470 | |
4471 // Unmap a block of memory. | |
4472 // Returns true=success, otherwise false. | |
4473 | |
6197 | 4474 bool os::pd_unmap_memory(char* addr, size_t bytes) { |
0 | 4475 BOOL result = UnmapViewOfFile(addr); |
4476 if (result == 0) { | |
4477 if (PrintMiscellaneous && Verbose) { | |
4478 DWORD err = GetLastError(); | |
4479 tty->print_cr("UnmapViewOfFile() failed: GetLastError->%ld.", err); | |
4480 } | |
4481 return false; | |
4482 } | |
4483 return true; | |
4484 } | |
4485 | |
4486 void os::pause() { | |
4487 char filename[MAX_PATH]; | |
4488 if (PauseAtStartupFile && PauseAtStartupFile[0]) { | |
4489 jio_snprintf(filename, MAX_PATH, PauseAtStartupFile); | |
4490 } else { | |
4491 jio_snprintf(filename, MAX_PATH, "./vm.paused.%d", current_process_id()); | |
4492 } | |
4493 | |
4494 int fd = ::open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666); | |
4495 if (fd != -1) { | |
4496 struct stat buf; | |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4497 ::close(fd); |
0 | 4498 while (::stat(filename, &buf) == 0) { |
4499 Sleep(100); | |
4500 } | |
4501 } else { | |
4502 jio_fprintf(stderr, | |
4503 "Could not open pause file '%s', continuing immediately.\n", filename); | |
4504 } | |
4505 } | |
4506 | |
4507 // An Event wraps a win32 "CreateEvent" kernel handle. | |
4508 // | |
4509 // We have a number of choices regarding "CreateEvent" win32 handle leakage: | |
4510 // | |
4511 // 1: When a thread dies return the Event to the EventFreeList, clear the ParkHandle | |
4512 // field, and call CloseHandle() on the win32 event handle. Unpark() would | |
4513 // need to be modified to tolerate finding a NULL (invalid) win32 event handle. | |
4514 // In addition, an unpark() operation might fetch the handle field, but the | |
4515 // event could recycle between the fetch and the SetEvent() operation. | |
4516 // SetEvent() would either fail because the handle was invalid, or inadvertently work, | |
4517 // as the win32 handle value had been recycled. In an ideal world calling SetEvent() | |
4518 // on an stale but recycled handle would be harmless, but in practice this might | |
4519 // confuse other non-Sun code, so it's not a viable approach. | |
4520 // | |
4521 // 2: Once a win32 event handle is associated with an Event, it remains associated | |
4522 // with the Event. The event handle is never closed. This could be construed | |
4523 // as handle leakage, but only up to the maximum # of threads that have been extant | |
4524 // at any one time. This shouldn't be an issue, as windows platforms typically | |
4525 // permit a process to have hundreds of thousands of open handles. | |
4526 // | |
4527 // 3: Same as (1), but periodically, at stop-the-world time, rundown the EventFreeList | |
4528 // and release unused handles. | |
4529 // | |
4530 // 4: Add a CRITICAL_SECTION to the Event to protect LD+SetEvent from LD;ST(null);CloseHandle. | |
4531 // It's not clear, however, that we wouldn't be trading one type of leak for another. | |
4532 // | |
4533 // 5. Use an RCU-like mechanism (Read-Copy Update). | |
4534 // Or perhaps something similar to Maged Michael's "Hazard pointers". | |
4535 // | |
4536 // We use (2). | |
4537 // | |
4538 // TODO-FIXME: | |
4539 // 1. Reconcile Doug's JSR166 j.u.c park-unpark with the objectmonitor implementation. | |
4540 // 2. Consider wrapping the WaitForSingleObject(Ex) calls in SEH try/finally blocks | |
4541 // to recover from (or at least detect) the dreaded Windows 841176 bug. | |
4542 // 3. Collapse the interrupt_event, the JSR166 parker event, and the objectmonitor ParkEvent | |
4543 // into a single win32 CreateEvent() handle. | |
4544 // | |
4545 // _Event transitions in park() | |
4546 // -1 => -1 : illegal | |
4547 // 1 => 0 : pass - return immediately | |
4548 // 0 => -1 : block | |
4549 // | |
4550 // _Event serves as a restricted-range semaphore : | |
4551 // -1 : thread is blocked | |
4552 // 0 : neutral - thread is running or ready | |
4553 // 1 : signaled - thread is running or ready | |
4554 // | |
4555 // Another possible encoding of _Event would be | |
4556 // with explicit "PARKED" and "SIGNALED" bits. | |
4557 | |
4558 int os::PlatformEvent::park (jlong Millis) { | |
4559 guarantee (_ParkHandle != NULL , "Invariant") ; | |
4560 guarantee (Millis > 0 , "Invariant") ; | |
4561 int v ; | |
4562 | |
4563 // CONSIDER: defer assigning a CreateEvent() handle to the Event until | |
4564 // the initial park() operation. | |
4565 | |
4566 for (;;) { | |
4567 v = _Event ; | |
4568 if (Atomic::cmpxchg (v-1, &_Event, v) == v) break ; | |
4569 } | |
4570 guarantee ((v == 0) || (v == 1), "invariant") ; | |
4571 if (v != 0) return OS_OK ; | |
4572 | |
4573 // Do this the hard way by blocking ... | |
4574 // TODO: consider a brief spin here, gated on the success of recent | |
4575 // spin attempts by this thread. | |
4576 // | |
4577 // We decompose long timeouts into series of shorter timed waits. | |
4578 // Evidently large timo values passed in WaitForSingleObject() are problematic on some | |
4579 // versions of Windows. See EventWait() for details. This may be superstition. Or not. | |
4580 // We trust the WAIT_TIMEOUT indication and don't track the elapsed wait time | |
4581 // with os::javaTimeNanos(). Furthermore, we assume that spurious returns from | |
4582 // ::WaitForSingleObject() caused by latent ::setEvent() operations will tend | |
4583 // to happen early in the wait interval. Specifically, after a spurious wakeup (rv == | |
4584 // WAIT_OBJECT_0 but _Event is still < 0) we don't bother to recompute Millis to compensate | |
4585 // for the already waited time. This policy does not admit any new outcomes. | |
4586 // In the future, however, we might want to track the accumulated wait time and | |
4587 // adjust Millis accordingly if we encounter a spurious wakeup. | |
4588 | |
4589 const int MAXTIMEOUT = 0x10000000 ; | |
4590 DWORD rv = WAIT_TIMEOUT ; | |
4591 while (_Event < 0 && Millis > 0) { | |
4592 DWORD prd = Millis ; // set prd = MAX (Millis, MAXTIMEOUT) | |
4593 if (Millis > MAXTIMEOUT) { | |
4594 prd = MAXTIMEOUT ; | |
4595 } | |
4596 rv = ::WaitForSingleObject (_ParkHandle, prd) ; | |
4597 assert (rv == WAIT_OBJECT_0 || rv == WAIT_TIMEOUT, "WaitForSingleObject failed") ; | |
4598 if (rv == WAIT_TIMEOUT) { | |
4599 Millis -= prd ; | |
4600 } | |
4601 } | |
4602 v = _Event ; | |
4603 _Event = 0 ; | |
4604 OrderAccess::fence() ; | |
4605 // If we encounter a nearly simultanous timeout expiry and unpark() | |
4606 // we return OS_OK indicating we awoke via unpark(). | |
4607 // Implementor's license -- returning OS_TIMEOUT would be equally valid, however. | |
4608 return (v >= 0) ? OS_OK : OS_TIMEOUT ; | |
4609 } | |
4610 | |
4611 void os::PlatformEvent::park () { | |
4612 guarantee (_ParkHandle != NULL, "Invariant") ; | |
4613 // Invariant: Only the thread associated with the Event/PlatformEvent | |
4614 // may call park(). | |
4615 int v ; | |
4616 for (;;) { | |
4617 v = _Event ; | |
4618 if (Atomic::cmpxchg (v-1, &_Event, v) == v) break ; | |
4619 } | |
4620 guarantee ((v == 0) || (v == 1), "invariant") ; | |
4621 if (v != 0) return ; | |
4622 | |
4623 // Do this the hard way by blocking ... | |
4624 // TODO: consider a brief spin here, gated on the success of recent | |
4625 // spin attempts by this thread. | |
4626 while (_Event < 0) { | |
4627 DWORD rv = ::WaitForSingleObject (_ParkHandle, INFINITE) ; | |
4628 assert (rv == WAIT_OBJECT_0, "WaitForSingleObject failed") ; | |
4629 } | |
4630 | |
4631 // Usually we'll find _Event == 0 at this point, but as | |
4632 // an optional optimization we clear it, just in case can | |
4633 // multiple unpark() operations drove _Event up to 1. | |
4634 _Event = 0 ; | |
4635 OrderAccess::fence() ; | |
4636 guarantee (_Event >= 0, "invariant") ; | |
4637 } | |
4638 | |
4639 void os::PlatformEvent::unpark() { | |
4640 guarantee (_ParkHandle != NULL, "Invariant") ; | |
4641 int v ; | |
4642 for (;;) { | |
4643 v = _Event ; // Increment _Event if it's < 1. | |
4644 if (v > 0) { | |
4645 // If it's already signaled just return. | |
4646 // The LD of _Event could have reordered or be satisfied | |
4647 // by a read-aside from this processor's write buffer. | |
4648 // To avoid problems execute a barrier and then | |
4649 // ratify the value. A degenerate CAS() would also work. | |
4650 // Viz., CAS (v+0, &_Event, v) == v). | |
4651 OrderAccess::fence() ; | |
4652 if (_Event == v) return ; | |
4653 continue ; | |
4654 } | |
4655 if (Atomic::cmpxchg (v+1, &_Event, v) == v) break ; | |
4656 } | |
4657 if (v < 0) { | |
4658 ::SetEvent (_ParkHandle) ; | |
4659 } | |
4660 } | |
4661 | |
4662 | |
4663 // JSR166 | |
4664 // ------------------------------------------------------- | |
4665 | |
4666 /* | |
4667 * The Windows implementation of Park is very straightforward: Basic | |
4668 * operations on Win32 Events turn out to have the right semantics to | |
4669 * use them directly. We opportunistically resuse the event inherited | |
4670 * from Monitor. | |
4671 */ | |
4672 | |
4673 | |
4674 void Parker::park(bool isAbsolute, jlong time) { | |
4675 guarantee (_ParkEvent != NULL, "invariant") ; | |
4676 // First, demultiplex/decode time arguments | |
4677 if (time < 0) { // don't wait | |
4678 return; | |
4679 } | |
1865
1c352af0135d
6763959: java.util.concurrent.locks.LockSupport.parkUntil(0) blocks forever
acorn
parents:
1681
diff
changeset
|
4680 else if (time == 0 && !isAbsolute) { |
0 | 4681 time = INFINITE; |
4682 } | |
4683 else if (isAbsolute) { | |
4684 time -= os::javaTimeMillis(); // convert to relative time | |
4685 if (time <= 0) // already elapsed | |
4686 return; | |
4687 } | |
4688 else { // relative | |
4689 time /= 1000000; // Must coarsen from nanos to millis | |
4690 if (time == 0) // Wait for the minimal time unit if zero | |
4691 time = 1; | |
4692 } | |
4693 | |
4694 JavaThread* thread = (JavaThread*)(Thread::current()); | |
4695 assert(thread->is_Java_thread(), "Must be JavaThread"); | |
4696 JavaThread *jt = (JavaThread *)thread; | |
4697 | |
4698 // Don't wait if interrupted or already triggered | |
4699 if (Thread::is_interrupted(thread, false) || | |
4700 WaitForSingleObject(_ParkEvent, 0) == WAIT_OBJECT_0) { | |
4701 ResetEvent(_ParkEvent); | |
4702 return; | |
4703 } | |
4704 else { | |
4705 ThreadBlockInVM tbivm(jt); | |
4706 OSThreadWaitState osts(thread->osthread(), false /* not Object.wait() */); | |
4707 jt->set_suspend_equivalent(); | |
4708 | |
4709 WaitForSingleObject(_ParkEvent, time); | |
4710 ResetEvent(_ParkEvent); | |
4711 | |
4712 // If externally suspended while waiting, re-suspend | |
4713 if (jt->handle_special_suspend_equivalent_condition()) { | |
4714 jt->java_suspend_self(); | |
4715 } | |
4716 } | |
4717 } | |
4718 | |
4719 void Parker::unpark() { | |
4720 guarantee (_ParkEvent != NULL, "invariant") ; | |
4721 SetEvent(_ParkEvent); | |
4722 } | |
4723 | |
4724 // Run the specified command in a separate process. Return its exit value, | |
4725 // or -1 on failure (e.g. can't create a new process). | |
4726 int os::fork_and_exec(char* cmd) { | |
4727 STARTUPINFO si; | |
4728 PROCESS_INFORMATION pi; | |
4729 | |
4730 memset(&si, 0, sizeof(si)); | |
4731 si.cb = sizeof(si); | |
4732 memset(&pi, 0, sizeof(pi)); | |
4733 BOOL rslt = CreateProcess(NULL, // executable name - use command line | |
4734 cmd, // command line | |
4735 NULL, // process security attribute | |
4736 NULL, // thread security attribute | |
4737 TRUE, // inherits system handles | |
4738 0, // no creation flags | |
4739 NULL, // use parent's environment block | |
4740 NULL, // use parent's starting directory | |
4741 &si, // (in) startup information | |
4742 &pi); // (out) process information | |
4743 | |
4744 if (rslt) { | |
4745 // Wait until child process exits. | |
4746 WaitForSingleObject(pi.hProcess, INFINITE); | |
4747 | |
4748 DWORD exit_code; | |
4749 GetExitCodeProcess(pi.hProcess, &exit_code); | |
4750 | |
4751 // Close process and thread handles. | |
4752 CloseHandle(pi.hProcess); | |
4753 CloseHandle(pi.hThread); | |
4754 | |
4755 return (int)exit_code; | |
4756 } else { | |
4757 return -1; | |
4758 } | |
4759 } | |
4760 | |
4761 //-------------------------------------------------------------------------------------------------- | |
4762 // Non-product code | |
4763 | |
4764 static int mallocDebugIntervalCounter = 0; | |
4765 static int mallocDebugCounter = 0; | |
4766 bool os::check_heap(bool force) { | |
4767 if (++mallocDebugCounter < MallocVerifyStart && !force) return true; | |
4768 if (++mallocDebugIntervalCounter >= MallocVerifyInterval || force) { | |
4769 // Note: HeapValidate executes two hardware breakpoints when it finds something | |
4770 // wrong; at these points, eax contains the address of the offending block (I think). | |
4771 // To get to the exlicit error message(s) below, just continue twice. | |
4772 HANDLE heap = GetProcessHeap(); | |
4773 { HeapLock(heap); | |
4774 PROCESS_HEAP_ENTRY phe; | |
4775 phe.lpData = NULL; | |
4776 while (HeapWalk(heap, &phe) != 0) { | |
4777 if ((phe.wFlags & PROCESS_HEAP_ENTRY_BUSY) && | |
4778 !HeapValidate(heap, 0, phe.lpData)) { | |
4779 tty->print_cr("C heap has been corrupted (time: %d allocations)", mallocDebugCounter); | |
4780 tty->print_cr("corrupted block near address %#x, length %d", phe.lpData, phe.cbData); | |
4781 fatal("corrupted C heap"); | |
4782 } | |
4783 } | |
4750
b16494a69d3d
7126185: Clean up lasterror handling, add os::get_last_error()
phh
parents:
4720
diff
changeset
|
4784 DWORD err = GetLastError(); |
0 | 4785 if (err != ERROR_NO_MORE_ITEMS && err != ERROR_CALL_NOT_IMPLEMENTED) { |
1490
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1353
diff
changeset
|
4786 fatal(err_msg("heap walk aborted with error %d", err)); |
0 | 4787 } |
4788 HeapUnlock(heap); | |
4789 } | |
4790 mallocDebugIntervalCounter = 0; | |
4791 } | |
4792 return true; | |
4793 } | |
4794 | |
4795 | |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1552
diff
changeset
|
4796 bool os::find(address addr, outputStream* st) { |
0 | 4797 // Nothing yet |
4798 return false; | |
4799 } | |
4800 | |
4801 LONG WINAPI os::win32::serialize_fault_filter(struct _EXCEPTION_POINTERS* e) { | |
4802 DWORD exception_code = e->ExceptionRecord->ExceptionCode; | |
4803 | |
4804 if ( exception_code == EXCEPTION_ACCESS_VIOLATION ) { | |
4805 JavaThread* thread = (JavaThread*)ThreadLocalStorage::get_thread_slow(); | |
4806 PEXCEPTION_RECORD exceptionRecord = e->ExceptionRecord; | |
4807 address addr = (address) exceptionRecord->ExceptionInformation[1]; | |
4808 | |
4809 if (os::is_memory_serialize_page(thread, addr)) | |
4810 return EXCEPTION_CONTINUE_EXECUTION; | |
4811 } | |
4812 | |
4813 return EXCEPTION_CONTINUE_SEARCH; | |
4814 } | |
4815 | |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1552
diff
changeset
|
4816 // We don't build a headless jre for Windows |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1552
diff
changeset
|
4817 bool os::is_headless_jre() { return false; } |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1552
diff
changeset
|
4818 |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4819 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4820 typedef CRITICAL_SECTION mutex_t; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4821 #define mutexInit(m) InitializeCriticalSection(m) |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4822 #define mutexDestroy(m) DeleteCriticalSection(m) |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4823 #define mutexLock(m) EnterCriticalSection(m) |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4824 #define mutexUnlock(m) LeaveCriticalSection(m) |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4825 |
3833
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
4826 static bool sock_initialized = FALSE; |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4827 static mutex_t sockFnTableMutex; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4828 |
3833
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
4829 static void initSock() { |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4830 WSADATA wsadata; |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4831 |
3833
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
4832 if (!os::WinSock2Dll::WinSock2Available()) { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
4833 jio_fprintf(stderr, "Could not load Winsock 2 (error: %d)\n", |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
4834 ::GetLastError()); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
4835 return; |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
4836 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
4837 if (sock_initialized == TRUE) return; |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
4838 |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4839 ::mutexInit(&sockFnTableMutex); |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4840 ::mutexLock(&sockFnTableMutex); |
3833
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
4841 if (os::WinSock2Dll::WSAStartup(MAKEWORD(1,1), &wsadata) != 0) { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
4842 jio_fprintf(stderr, "Could not initialize Winsock\n"); |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4843 } |
3833
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
4844 sock_initialized = TRUE; |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4845 ::mutexUnlock(&sockFnTableMutex); |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4846 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4847 |
4717
11c26bfcf8c7
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
4006
diff
changeset
|
4848 struct hostent* os::get_host_by_name(char* name) { |
3833
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
4849 if (!sock_initialized) { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
4850 initSock(); |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4851 } |
3833
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
4852 if (!os::WinSock2Dll::WinSock2Available()) { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
4853 return NULL; |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
4854 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
4855 return (struct hostent*)os::WinSock2Dll::gethostbyname(name); |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4856 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4857 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4858 int os::socket_close(int fd) { |
6044
ec15e8f6e4f1
7157695: Add windows implementation of socket interface
twisti
parents:
5903
diff
changeset
|
4859 return ::closesocket(fd); |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4860 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4861 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4862 int os::socket_available(int fd, jint *pbytes) { |
6044
ec15e8f6e4f1
7157695: Add windows implementation of socket interface
twisti
parents:
5903
diff
changeset
|
4863 int ret = ::ioctlsocket(fd, FIONREAD, (u_long*)pbytes); |
ec15e8f6e4f1
7157695: Add windows implementation of socket interface
twisti
parents:
5903
diff
changeset
|
4864 return (ret < 0) ? 0 : 1; |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4865 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4866 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4867 int os::socket(int domain, int type, int protocol) { |
6044
ec15e8f6e4f1
7157695: Add windows implementation of socket interface
twisti
parents:
5903
diff
changeset
|
4868 return ::socket(domain, type, protocol); |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4869 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4870 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4871 int os::listen(int fd, int count) { |
6044
ec15e8f6e4f1
7157695: Add windows implementation of socket interface
twisti
parents:
5903
diff
changeset
|
4872 return ::listen(fd, count); |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4873 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4874 |
4717
11c26bfcf8c7
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
4006
diff
changeset
|
4875 int os::connect(int fd, struct sockaddr* him, socklen_t len) { |
6044
ec15e8f6e4f1
7157695: Add windows implementation of socket interface
twisti
parents:
5903
diff
changeset
|
4876 return ::connect(fd, him, len); |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4877 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4878 |
4717
11c26bfcf8c7
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
4006
diff
changeset
|
4879 int os::accept(int fd, struct sockaddr* him, socklen_t* len) { |
6044
ec15e8f6e4f1
7157695: Add windows implementation of socket interface
twisti
parents:
5903
diff
changeset
|
4880 return ::accept(fd, him, len); |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4881 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4882 |
4717
11c26bfcf8c7
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
4006
diff
changeset
|
4883 int os::sendto(int fd, char* buf, size_t len, uint flags, |
11c26bfcf8c7
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
4006
diff
changeset
|
4884 struct sockaddr* to, socklen_t tolen) { |
6044
ec15e8f6e4f1
7157695: Add windows implementation of socket interface
twisti
parents:
5903
diff
changeset
|
4885 |
ec15e8f6e4f1
7157695: Add windows implementation of socket interface
twisti
parents:
5903
diff
changeset
|
4886 return ::sendto(fd, buf, (int)len, flags, to, tolen); |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4887 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4888 |
4717
11c26bfcf8c7
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
4006
diff
changeset
|
4889 int os::recvfrom(int fd, char *buf, size_t nBytes, uint flags, |
11c26bfcf8c7
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
4006
diff
changeset
|
4890 sockaddr* from, socklen_t* fromlen) { |
6044
ec15e8f6e4f1
7157695: Add windows implementation of socket interface
twisti
parents:
5903
diff
changeset
|
4891 |
ec15e8f6e4f1
7157695: Add windows implementation of socket interface
twisti
parents:
5903
diff
changeset
|
4892 return ::recvfrom(fd, buf, (int)nBytes, flags, from, fromlen); |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4893 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4894 |
4717
11c26bfcf8c7
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
4006
diff
changeset
|
4895 int os::recv(int fd, char* buf, size_t nBytes, uint flags) { |
6044
ec15e8f6e4f1
7157695: Add windows implementation of socket interface
twisti
parents:
5903
diff
changeset
|
4896 return ::recv(fd, buf, (int)nBytes, flags); |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4897 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4898 |
4717
11c26bfcf8c7
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
4006
diff
changeset
|
4899 int os::send(int fd, char* buf, size_t nBytes, uint flags) { |
6044
ec15e8f6e4f1
7157695: Add windows implementation of socket interface
twisti
parents:
5903
diff
changeset
|
4900 return ::send(fd, buf, (int)nBytes, flags); |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4901 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4902 |
4717
11c26bfcf8c7
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
4006
diff
changeset
|
4903 int os::raw_send(int fd, char* buf, size_t nBytes, uint flags) { |
6044
ec15e8f6e4f1
7157695: Add windows implementation of socket interface
twisti
parents:
5903
diff
changeset
|
4904 return ::send(fd, buf, (int)nBytes, flags); |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4905 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4906 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4907 int os::timeout(int fd, long timeout) { |
6044
ec15e8f6e4f1
7157695: Add windows implementation of socket interface
twisti
parents:
5903
diff
changeset
|
4908 fd_set tbl; |
ec15e8f6e4f1
7157695: Add windows implementation of socket interface
twisti
parents:
5903
diff
changeset
|
4909 struct timeval t; |
ec15e8f6e4f1
7157695: Add windows implementation of socket interface
twisti
parents:
5903
diff
changeset
|
4910 |
ec15e8f6e4f1
7157695: Add windows implementation of socket interface
twisti
parents:
5903
diff
changeset
|
4911 t.tv_sec = timeout / 1000; |
ec15e8f6e4f1
7157695: Add windows implementation of socket interface
twisti
parents:
5903
diff
changeset
|
4912 t.tv_usec = (timeout % 1000) * 1000; |
ec15e8f6e4f1
7157695: Add windows implementation of socket interface
twisti
parents:
5903
diff
changeset
|
4913 |
ec15e8f6e4f1
7157695: Add windows implementation of socket interface
twisti
parents:
5903
diff
changeset
|
4914 tbl.fd_count = 1; |
ec15e8f6e4f1
7157695: Add windows implementation of socket interface
twisti
parents:
5903
diff
changeset
|
4915 tbl.fd_array[0] = fd; |
ec15e8f6e4f1
7157695: Add windows implementation of socket interface
twisti
parents:
5903
diff
changeset
|
4916 |
ec15e8f6e4f1
7157695: Add windows implementation of socket interface
twisti
parents:
5903
diff
changeset
|
4917 return ::select(1, &tbl, 0, 0, &t); |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4918 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4919 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4920 int os::get_host_name(char* name, int namelen) { |
6044
ec15e8f6e4f1
7157695: Add windows implementation of socket interface
twisti
parents:
5903
diff
changeset
|
4921 return ::gethostname(name, namelen); |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4922 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4923 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4924 int os::socket_shutdown(int fd, int howto) { |
6044
ec15e8f6e4f1
7157695: Add windows implementation of socket interface
twisti
parents:
5903
diff
changeset
|
4925 return ::shutdown(fd, howto); |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4926 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4927 |
4717
11c26bfcf8c7
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
4006
diff
changeset
|
4928 int os::bind(int fd, struct sockaddr* him, socklen_t len) { |
6044
ec15e8f6e4f1
7157695: Add windows implementation of socket interface
twisti
parents:
5903
diff
changeset
|
4929 return ::bind(fd, him, len); |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4930 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4931 |
4717
11c26bfcf8c7
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
4006
diff
changeset
|
4932 int os::get_sock_name(int fd, struct sockaddr* him, socklen_t* len) { |
6044
ec15e8f6e4f1
7157695: Add windows implementation of socket interface
twisti
parents:
5903
diff
changeset
|
4933 return ::getsockname(fd, him, len); |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4934 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4935 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4936 int os::get_sock_opt(int fd, int level, int optname, |
4717
11c26bfcf8c7
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
4006
diff
changeset
|
4937 char* optval, socklen_t* optlen) { |
6044
ec15e8f6e4f1
7157695: Add windows implementation of socket interface
twisti
parents:
5903
diff
changeset
|
4938 return ::getsockopt(fd, level, optname, optval, optlen); |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4939 } |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4940 |
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4941 int os::set_sock_opt(int fd, int level, int optname, |
4717
11c26bfcf8c7
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
4006
diff
changeset
|
4942 const char* optval, socklen_t optlen) { |
6044
ec15e8f6e4f1
7157695: Add windows implementation of socket interface
twisti
parents:
5903
diff
changeset
|
4943 return ::setsockopt(fd, level, optname, optval, optlen); |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
4944 } |
3833
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
4945 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
4946 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
4947 // Kernel32 API |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
4948 typedef SIZE_T (WINAPI* GetLargePageMinimum_Fn)(void); |
3885 | 4949 typedef LPVOID (WINAPI *VirtualAllocExNuma_Fn) (HANDLE, LPVOID, SIZE_T, DWORD, DWORD, DWORD); |
4950 typedef BOOL (WINAPI *GetNumaHighestNodeNumber_Fn) (PULONG); | |
4951 typedef BOOL (WINAPI *GetNumaNodeProcessorMask_Fn) (UCHAR, PULONGLONG); | |
6197 | 4952 typedef USHORT (WINAPI* RtlCaptureStackBackTrace_Fn)(ULONG, ULONG, PVOID*, PULONG); |
3885 | 4953 |
3833
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
4954 GetLargePageMinimum_Fn os::Kernel32Dll::_GetLargePageMinimum = NULL; |
3885 | 4955 VirtualAllocExNuma_Fn os::Kernel32Dll::_VirtualAllocExNuma = NULL; |
4956 GetNumaHighestNodeNumber_Fn os::Kernel32Dll::_GetNumaHighestNodeNumber = NULL; | |
4957 GetNumaNodeProcessorMask_Fn os::Kernel32Dll::_GetNumaNodeProcessorMask = NULL; | |
6197 | 4958 RtlCaptureStackBackTrace_Fn os::Kernel32Dll::_RtlCaptureStackBackTrace = NULL; |
4959 | |
4960 | |
3833
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
4961 BOOL os::Kernel32Dll::initialized = FALSE; |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
4962 SIZE_T os::Kernel32Dll::GetLargePageMinimum() { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
4963 assert(initialized && _GetLargePageMinimum != NULL, |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
4964 "GetLargePageMinimumAvailable() not yet called"); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
4965 return _GetLargePageMinimum(); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
4966 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
4967 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
4968 BOOL os::Kernel32Dll::GetLargePageMinimumAvailable() { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
4969 if (!initialized) { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
4970 initialize(); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
4971 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
4972 return _GetLargePageMinimum != NULL; |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
4973 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
4974 |
3885 | 4975 BOOL os::Kernel32Dll::NumaCallsAvailable() { |
4976 if (!initialized) { | |
4977 initialize(); | |
4978 } | |
4979 return _VirtualAllocExNuma != NULL; | |
4980 } | |
4981 | |
4982 LPVOID os::Kernel32Dll::VirtualAllocExNuma(HANDLE hProc, LPVOID addr, SIZE_T bytes, DWORD flags, DWORD prot, DWORD node) { | |
4983 assert(initialized && _VirtualAllocExNuma != NULL, | |
4984 "NUMACallsAvailable() not yet called"); | |
4985 | |
4986 return _VirtualAllocExNuma(hProc, addr, bytes, flags, prot, node); | |
4987 } | |
4988 | |
4989 BOOL os::Kernel32Dll::GetNumaHighestNodeNumber(PULONG ptr_highest_node_number) { | |
4990 assert(initialized && _GetNumaHighestNodeNumber != NULL, | |
4991 "NUMACallsAvailable() not yet called"); | |
4992 | |
4993 return _GetNumaHighestNodeNumber(ptr_highest_node_number); | |
4994 } | |
4995 | |
4996 BOOL os::Kernel32Dll::GetNumaNodeProcessorMask(UCHAR node, PULONGLONG proc_mask) { | |
4997 assert(initialized && _GetNumaNodeProcessorMask != NULL, | |
4998 "NUMACallsAvailable() not yet called"); | |
4999 | |
5000 return _GetNumaNodeProcessorMask(node, proc_mask); | |
5001 } | |
5002 | |
6197 | 5003 USHORT os::Kernel32Dll::RtlCaptureStackBackTrace(ULONG FrameToSkip, |
5004 ULONG FrameToCapture, PVOID* BackTrace, PULONG BackTraceHash) { | |
5005 if (!initialized) { | |
5006 initialize(); | |
5007 } | |
5008 | |
5009 if (_RtlCaptureStackBackTrace != NULL) { | |
5010 return _RtlCaptureStackBackTrace(FrameToSkip, FrameToCapture, | |
5011 BackTrace, BackTraceHash); | |
5012 } else { | |
5013 return 0; | |
5014 } | |
5015 } | |
3885 | 5016 |
5017 void os::Kernel32Dll::initializeCommon() { | |
5018 if (!initialized) { | |
5019 HMODULE handle = ::GetModuleHandle("Kernel32.dll"); | |
5020 assert(handle != NULL, "Just check"); | |
5021 _GetLargePageMinimum = (GetLargePageMinimum_Fn)::GetProcAddress(handle, "GetLargePageMinimum"); | |
5022 _VirtualAllocExNuma = (VirtualAllocExNuma_Fn)::GetProcAddress(handle, "VirtualAllocExNuma"); | |
5023 _GetNumaHighestNodeNumber = (GetNumaHighestNodeNumber_Fn)::GetProcAddress(handle, "GetNumaHighestNodeNumber"); | |
5024 _GetNumaNodeProcessorMask = (GetNumaNodeProcessorMask_Fn)::GetProcAddress(handle, "GetNumaNodeProcessorMask"); | |
6197 | 5025 _RtlCaptureStackBackTrace = (RtlCaptureStackBackTrace_Fn)::GetProcAddress(handle, "RtlCaptureStackBackTrace"); |
3885 | 5026 initialized = TRUE; |
5027 } | |
5028 } | |
5029 | |
5030 | |
3833
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5031 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5032 #ifndef JDK6_OR_EARLIER |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5033 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5034 void os::Kernel32Dll::initialize() { |
3885 | 5035 initializeCommon(); |
3833
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5036 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5037 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5038 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5039 // Kernel32 API |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5040 inline BOOL os::Kernel32Dll::SwitchToThread() { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5041 return ::SwitchToThread(); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5042 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5043 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5044 inline BOOL os::Kernel32Dll::SwitchToThreadAvailable() { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5045 return true; |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5046 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5047 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5048 // Help tools |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5049 inline BOOL os::Kernel32Dll::HelpToolsAvailable() { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5050 return true; |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5051 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5052 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5053 inline HANDLE os::Kernel32Dll::CreateToolhelp32Snapshot(DWORD dwFlags,DWORD th32ProcessId) { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5054 return ::CreateToolhelp32Snapshot(dwFlags, th32ProcessId); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5055 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5056 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5057 inline BOOL os::Kernel32Dll::Module32First(HANDLE hSnapshot,LPMODULEENTRY32 lpme) { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5058 return ::Module32First(hSnapshot, lpme); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5059 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5060 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5061 inline BOOL os::Kernel32Dll::Module32Next(HANDLE hSnapshot,LPMODULEENTRY32 lpme) { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5062 return ::Module32Next(hSnapshot, lpme); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5063 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5064 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5065 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5066 inline BOOL os::Kernel32Dll::GetNativeSystemInfoAvailable() { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5067 return true; |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5068 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5069 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5070 inline void os::Kernel32Dll::GetNativeSystemInfo(LPSYSTEM_INFO lpSystemInfo) { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5071 ::GetNativeSystemInfo(lpSystemInfo); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5072 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5073 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5074 // PSAPI API |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5075 inline BOOL os::PSApiDll::EnumProcessModules(HANDLE hProcess, HMODULE *lpModule, DWORD cb, LPDWORD lpcbNeeded) { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5076 return ::EnumProcessModules(hProcess, lpModule, cb, lpcbNeeded); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5077 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5078 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5079 inline DWORD os::PSApiDll::GetModuleFileNameEx(HANDLE hProcess, HMODULE hModule, LPTSTR lpFilename, DWORD nSize) { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5080 return ::GetModuleFileNameEx(hProcess, hModule, lpFilename, nSize); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5081 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5082 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5083 inline BOOL os::PSApiDll::GetModuleInformation(HANDLE hProcess, HMODULE hModule, LPMODULEINFO lpmodinfo, DWORD cb) { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5084 return ::GetModuleInformation(hProcess, hModule, lpmodinfo, cb); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5085 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5086 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5087 inline BOOL os::PSApiDll::PSApiAvailable() { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5088 return true; |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5089 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5090 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5091 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5092 // WinSock2 API |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5093 inline BOOL os::WinSock2Dll::WSAStartup(WORD wVersionRequested, LPWSADATA lpWSAData) { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5094 return ::WSAStartup(wVersionRequested, lpWSAData); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5095 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5096 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5097 inline struct hostent* os::WinSock2Dll::gethostbyname(const char *name) { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5098 return ::gethostbyname(name); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5099 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5100 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5101 inline BOOL os::WinSock2Dll::WinSock2Available() { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5102 return true; |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5103 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5104 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5105 // Advapi API |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5106 inline BOOL os::Advapi32Dll::AdjustTokenPrivileges(HANDLE TokenHandle, |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5107 BOOL DisableAllPrivileges, PTOKEN_PRIVILEGES NewState, DWORD BufferLength, |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5108 PTOKEN_PRIVILEGES PreviousState, PDWORD ReturnLength) { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5109 return ::AdjustTokenPrivileges(TokenHandle, DisableAllPrivileges, NewState, |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5110 BufferLength, PreviousState, ReturnLength); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5111 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5112 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5113 inline BOOL os::Advapi32Dll::OpenProcessToken(HANDLE ProcessHandle, DWORD DesiredAccess, |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5114 PHANDLE TokenHandle) { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5115 return ::OpenProcessToken(ProcessHandle, DesiredAccess, TokenHandle); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5116 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5117 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5118 inline BOOL os::Advapi32Dll::LookupPrivilegeValue(LPCTSTR lpSystemName, LPCTSTR lpName, PLUID lpLuid) { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5119 return ::LookupPrivilegeValue(lpSystemName, lpName, lpLuid); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5120 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5121 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5122 inline BOOL os::Advapi32Dll::AdvapiAvailable() { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5123 return true; |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5124 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5125 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5126 #else |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5127 // Kernel32 API |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5128 typedef BOOL (WINAPI* SwitchToThread_Fn)(void); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5129 typedef HANDLE (WINAPI* CreateToolhelp32Snapshot_Fn)(DWORD,DWORD); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5130 typedef BOOL (WINAPI* Module32First_Fn)(HANDLE,LPMODULEENTRY32); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5131 typedef BOOL (WINAPI* Module32Next_Fn)(HANDLE,LPMODULEENTRY32); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5132 typedef void (WINAPI* GetNativeSystemInfo_Fn)(LPSYSTEM_INFO); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5133 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5134 SwitchToThread_Fn os::Kernel32Dll::_SwitchToThread = NULL; |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5135 CreateToolhelp32Snapshot_Fn os::Kernel32Dll::_CreateToolhelp32Snapshot = NULL; |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5136 Module32First_Fn os::Kernel32Dll::_Module32First = NULL; |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5137 Module32Next_Fn os::Kernel32Dll::_Module32Next = NULL; |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5138 GetNativeSystemInfo_Fn os::Kernel32Dll::_GetNativeSystemInfo = NULL; |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5139 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5140 void os::Kernel32Dll::initialize() { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5141 if (!initialized) { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5142 HMODULE handle = ::GetModuleHandle("Kernel32.dll"); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5143 assert(handle != NULL, "Just check"); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5144 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5145 _SwitchToThread = (SwitchToThread_Fn)::GetProcAddress(handle, "SwitchToThread"); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5146 _CreateToolhelp32Snapshot = (CreateToolhelp32Snapshot_Fn) |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5147 ::GetProcAddress(handle, "CreateToolhelp32Snapshot"); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5148 _Module32First = (Module32First_Fn)::GetProcAddress(handle, "Module32First"); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5149 _Module32Next = (Module32Next_Fn)::GetProcAddress(handle, "Module32Next"); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5150 _GetNativeSystemInfo = (GetNativeSystemInfo_Fn)::GetProcAddress(handle, "GetNativeSystemInfo"); |
3885 | 5151 initializeCommon(); // resolve the functions that always need resolving |
3833
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5152 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5153 initialized = TRUE; |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5154 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5155 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5156 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5157 BOOL os::Kernel32Dll::SwitchToThread() { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5158 assert(initialized && _SwitchToThread != NULL, |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5159 "SwitchToThreadAvailable() not yet called"); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5160 return _SwitchToThread(); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5161 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5162 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5163 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5164 BOOL os::Kernel32Dll::SwitchToThreadAvailable() { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5165 if (!initialized) { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5166 initialize(); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5167 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5168 return _SwitchToThread != NULL; |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5169 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5170 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5171 // Help tools |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5172 BOOL os::Kernel32Dll::HelpToolsAvailable() { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5173 if (!initialized) { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5174 initialize(); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5175 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5176 return _CreateToolhelp32Snapshot != NULL && |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5177 _Module32First != NULL && |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5178 _Module32Next != NULL; |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5179 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5180 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5181 HANDLE os::Kernel32Dll::CreateToolhelp32Snapshot(DWORD dwFlags,DWORD th32ProcessId) { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5182 assert(initialized && _CreateToolhelp32Snapshot != NULL, |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5183 "HelpToolsAvailable() not yet called"); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5184 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5185 return _CreateToolhelp32Snapshot(dwFlags, th32ProcessId); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5186 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5187 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5188 BOOL os::Kernel32Dll::Module32First(HANDLE hSnapshot,LPMODULEENTRY32 lpme) { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5189 assert(initialized && _Module32First != NULL, |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5190 "HelpToolsAvailable() not yet called"); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5191 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5192 return _Module32First(hSnapshot, lpme); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5193 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5194 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5195 inline BOOL os::Kernel32Dll::Module32Next(HANDLE hSnapshot,LPMODULEENTRY32 lpme) { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5196 assert(initialized && _Module32Next != NULL, |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5197 "HelpToolsAvailable() not yet called"); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5198 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5199 return _Module32Next(hSnapshot, lpme); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5200 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5201 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5202 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5203 BOOL os::Kernel32Dll::GetNativeSystemInfoAvailable() { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5204 if (!initialized) { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5205 initialize(); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5206 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5207 return _GetNativeSystemInfo != NULL; |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5208 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5209 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5210 void os::Kernel32Dll::GetNativeSystemInfo(LPSYSTEM_INFO lpSystemInfo) { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5211 assert(initialized && _GetNativeSystemInfo != NULL, |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5212 "GetNativeSystemInfoAvailable() not yet called"); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5213 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5214 _GetNativeSystemInfo(lpSystemInfo); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5215 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5216 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5217 // PSAPI API |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5218 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5219 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5220 typedef BOOL (WINAPI *EnumProcessModules_Fn)(HANDLE, HMODULE *, DWORD, LPDWORD); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5221 typedef BOOL (WINAPI *GetModuleFileNameEx_Fn)(HANDLE, HMODULE, LPTSTR, DWORD);; |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5222 typedef BOOL (WINAPI *GetModuleInformation_Fn)(HANDLE, HMODULE, LPMODULEINFO, DWORD); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5223 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5224 EnumProcessModules_Fn os::PSApiDll::_EnumProcessModules = NULL; |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5225 GetModuleFileNameEx_Fn os::PSApiDll::_GetModuleFileNameEx = NULL; |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5226 GetModuleInformation_Fn os::PSApiDll::_GetModuleInformation = NULL; |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5227 BOOL os::PSApiDll::initialized = FALSE; |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5228 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5229 void os::PSApiDll::initialize() { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5230 if (!initialized) { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5231 HMODULE handle = os::win32::load_Windows_dll("PSAPI.DLL", NULL, 0); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5232 if (handle != NULL) { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5233 _EnumProcessModules = (EnumProcessModules_Fn)::GetProcAddress(handle, |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5234 "EnumProcessModules"); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5235 _GetModuleFileNameEx = (GetModuleFileNameEx_Fn)::GetProcAddress(handle, |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5236 "GetModuleFileNameExA"); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5237 _GetModuleInformation = (GetModuleInformation_Fn)::GetProcAddress(handle, |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5238 "GetModuleInformation"); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5239 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5240 initialized = TRUE; |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5241 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5242 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5243 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5244 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5245 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5246 BOOL os::PSApiDll::EnumProcessModules(HANDLE hProcess, HMODULE *lpModule, DWORD cb, LPDWORD lpcbNeeded) { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5247 assert(initialized && _EnumProcessModules != NULL, |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5248 "PSApiAvailable() not yet called"); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5249 return _EnumProcessModules(hProcess, lpModule, cb, lpcbNeeded); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5250 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5251 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5252 DWORD os::PSApiDll::GetModuleFileNameEx(HANDLE hProcess, HMODULE hModule, LPTSTR lpFilename, DWORD nSize) { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5253 assert(initialized && _GetModuleFileNameEx != NULL, |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5254 "PSApiAvailable() not yet called"); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5255 return _GetModuleFileNameEx(hProcess, hModule, lpFilename, nSize); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5256 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5257 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5258 BOOL os::PSApiDll::GetModuleInformation(HANDLE hProcess, HMODULE hModule, LPMODULEINFO lpmodinfo, DWORD cb) { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5259 assert(initialized && _GetModuleInformation != NULL, |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5260 "PSApiAvailable() not yet called"); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5261 return _GetModuleInformation(hProcess, hModule, lpmodinfo, cb); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5262 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5263 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5264 BOOL os::PSApiDll::PSApiAvailable() { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5265 if (!initialized) { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5266 initialize(); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5267 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5268 return _EnumProcessModules != NULL && |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5269 _GetModuleFileNameEx != NULL && |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5270 _GetModuleInformation != NULL; |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5271 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5272 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5273 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5274 // WinSock2 API |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5275 typedef int (PASCAL FAR* WSAStartup_Fn)(WORD, LPWSADATA); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5276 typedef struct hostent *(PASCAL FAR *gethostbyname_Fn)(...); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5277 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5278 WSAStartup_Fn os::WinSock2Dll::_WSAStartup = NULL; |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5279 gethostbyname_Fn os::WinSock2Dll::_gethostbyname = NULL; |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5280 BOOL os::WinSock2Dll::initialized = FALSE; |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5281 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5282 void os::WinSock2Dll::initialize() { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5283 if (!initialized) { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5284 HMODULE handle = os::win32::load_Windows_dll("ws2_32.dll", NULL, 0); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5285 if (handle != NULL) { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5286 _WSAStartup = (WSAStartup_Fn)::GetProcAddress(handle, "WSAStartup"); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5287 _gethostbyname = (gethostbyname_Fn)::GetProcAddress(handle, "gethostbyname"); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5288 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5289 initialized = TRUE; |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5290 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5291 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5292 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5293 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5294 BOOL os::WinSock2Dll::WSAStartup(WORD wVersionRequested, LPWSADATA lpWSAData) { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5295 assert(initialized && _WSAStartup != NULL, |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5296 "WinSock2Available() not yet called"); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5297 return _WSAStartup(wVersionRequested, lpWSAData); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5298 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5299 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5300 struct hostent* os::WinSock2Dll::gethostbyname(const char *name) { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5301 assert(initialized && _gethostbyname != NULL, |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5302 "WinSock2Available() not yet called"); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5303 return _gethostbyname(name); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5304 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5305 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5306 BOOL os::WinSock2Dll::WinSock2Available() { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5307 if (!initialized) { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5308 initialize(); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5309 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5310 return _WSAStartup != NULL && |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5311 _gethostbyname != NULL; |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5312 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5313 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5314 typedef BOOL (WINAPI *AdjustTokenPrivileges_Fn)(HANDLE, BOOL, PTOKEN_PRIVILEGES, DWORD, PTOKEN_PRIVILEGES, PDWORD); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5315 typedef BOOL (WINAPI *OpenProcessToken_Fn)(HANDLE, DWORD, PHANDLE); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5316 typedef BOOL (WINAPI *LookupPrivilegeValue_Fn)(LPCTSTR, LPCTSTR, PLUID); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5317 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5318 AdjustTokenPrivileges_Fn os::Advapi32Dll::_AdjustTokenPrivileges = NULL; |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5319 OpenProcessToken_Fn os::Advapi32Dll::_OpenProcessToken = NULL; |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5320 LookupPrivilegeValue_Fn os::Advapi32Dll::_LookupPrivilegeValue = NULL; |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5321 BOOL os::Advapi32Dll::initialized = FALSE; |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5322 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5323 void os::Advapi32Dll::initialize() { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5324 if (!initialized) { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5325 HMODULE handle = os::win32::load_Windows_dll("advapi32.dll", NULL, 0); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5326 if (handle != NULL) { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5327 _AdjustTokenPrivileges = (AdjustTokenPrivileges_Fn)::GetProcAddress(handle, |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5328 "AdjustTokenPrivileges"); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5329 _OpenProcessToken = (OpenProcessToken_Fn)::GetProcAddress(handle, |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5330 "OpenProcessToken"); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5331 _LookupPrivilegeValue = (LookupPrivilegeValue_Fn)::GetProcAddress(handle, |
3834
279ef1916773
7065535: Mistyped function name that disabled UseLargePages on Windows
zgu
parents:
3833
diff
changeset
|
5332 "LookupPrivilegeValueA"); |
3833
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5333 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5334 initialized = TRUE; |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5335 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5336 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5337 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5338 BOOL os::Advapi32Dll::AdjustTokenPrivileges(HANDLE TokenHandle, |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5339 BOOL DisableAllPrivileges, PTOKEN_PRIVILEGES NewState, DWORD BufferLength, |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5340 PTOKEN_PRIVILEGES PreviousState, PDWORD ReturnLength) { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5341 assert(initialized && _AdjustTokenPrivileges != NULL, |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5342 "AdvapiAvailable() not yet called"); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5343 return _AdjustTokenPrivileges(TokenHandle, DisableAllPrivileges, NewState, |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5344 BufferLength, PreviousState, ReturnLength); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5345 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5346 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5347 BOOL os::Advapi32Dll::OpenProcessToken(HANDLE ProcessHandle, DWORD DesiredAccess, |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5348 PHANDLE TokenHandle) { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5349 assert(initialized && _OpenProcessToken != NULL, |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5350 "AdvapiAvailable() not yet called"); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5351 return _OpenProcessToken(ProcessHandle, DesiredAccess, TokenHandle); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5352 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5353 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5354 BOOL os::Advapi32Dll::LookupPrivilegeValue(LPCTSTR lpSystemName, LPCTSTR lpName, PLUID lpLuid) { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5355 assert(initialized && _LookupPrivilegeValue != NULL, |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5356 "AdvapiAvailable() not yet called"); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5357 return _LookupPrivilegeValue(lpSystemName, lpName, lpLuid); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5358 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5359 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5360 BOOL os::Advapi32Dll::AdvapiAvailable() { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5361 if (!initialized) { |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5362 initialize(); |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5363 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5364 return _AdjustTokenPrivileges != NULL && |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5365 _OpenProcessToken != NULL && |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5366 _LookupPrivilegeValue != NULL; |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5367 } |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5368 |
b1cbb0907b36
7016797: Hotspot: securely/restrictive load dlls and new API for loading system dlls
zgu
parents:
3800
diff
changeset
|
5369 #endif |