94 #include <errno.h> |
94 #include <errno.h> |
95 #include <fcntl.h> |
95 #include <fcntl.h> |
96 #include <io.h> |
96 #include <io.h> |
97 #include <process.h> // For _beginthreadex(), _endthreadex() |
97 #include <process.h> // For _beginthreadex(), _endthreadex() |
98 #include <imagehlp.h> // For os::dll_address_to_function_name |
98 #include <imagehlp.h> // For os::dll_address_to_function_name |
99 |
|
100 /* for enumerating dll libraries */ |
99 /* for enumerating dll libraries */ |
101 #include <vdmdbg.h> |
100 #include <vdmdbg.h> |
102 |
101 |
103 // for timer info max values which include all bits |
102 // for timer info max values which include all bits |
104 #define ALL_64_BITS CONST64(0xFFFFFFFFFFFFFFFF) |
103 #define ALL_64_BITS CONST64(0xFFFFFFFFFFFFFFFF) |
212 if (pslash != NULL) |
211 if (pslash != NULL) |
213 *pslash = '\0'; /* get rid of \bin */ |
212 *pslash = '\0'; /* get rid of \bin */ |
214 } |
213 } |
215 } |
214 } |
216 |
215 |
217 home_path = NEW_C_HEAP_ARRAY(char, strlen(home_dir) + 1); |
216 home_path = NEW_C_HEAP_ARRAY(char, strlen(home_dir) + 1, mtInternal); |
218 if (home_path == NULL) |
217 if (home_path == NULL) |
219 return; |
218 return; |
220 strcpy(home_path, home_dir); |
219 strcpy(home_path, home_dir); |
221 Arguments::set_java_home(home_path); |
220 Arguments::set_java_home(home_path); |
222 |
221 |
223 dll_path = NEW_C_HEAP_ARRAY(char, strlen(home_dir) + strlen(bin) + 1); |
222 dll_path = NEW_C_HEAP_ARRAY(char, strlen(home_dir) + strlen(bin) + 1, mtInternal); |
224 if (dll_path == NULL) |
223 if (dll_path == NULL) |
225 return; |
224 return; |
226 strcpy(dll_path, home_dir); |
225 strcpy(dll_path, home_dir); |
227 strcat(dll_path, bin); |
226 strcat(dll_path, bin); |
228 Arguments::set_dll_dir(dll_path); |
227 Arguments::set_dll_dir(dll_path); |
249 char *library_path; |
248 char *library_path; |
250 char tmp[MAX_PATH]; |
249 char tmp[MAX_PATH]; |
251 char *path_str = ::getenv("PATH"); |
250 char *path_str = ::getenv("PATH"); |
252 |
251 |
253 library_path = NEW_C_HEAP_ARRAY(char, MAX_PATH * 5 + sizeof(PACKAGE_DIR) + |
252 library_path = NEW_C_HEAP_ARRAY(char, MAX_PATH * 5 + sizeof(PACKAGE_DIR) + |
254 sizeof(BIN_DIR) + (path_str ? strlen(path_str) : 0) + 10); |
253 sizeof(BIN_DIR) + (path_str ? strlen(path_str) : 0) + 10, mtInternal); |
255 |
254 |
256 library_path[0] = '\0'; |
255 library_path[0] = '\0'; |
257 |
256 |
258 GetModuleFileName(NULL, tmp, sizeof(tmp)); |
257 GetModuleFileName(NULL, tmp, sizeof(tmp)); |
259 *(strrchr(tmp, '\\')) = '\0'; |
258 *(strrchr(tmp, '\\')) = '\0'; |
278 } |
277 } |
279 |
278 |
280 strcat(library_path, ";."); |
279 strcat(library_path, ";."); |
281 |
280 |
282 Arguments::set_library_path(library_path); |
281 Arguments::set_library_path(library_path); |
283 FREE_C_HEAP_ARRAY(char, library_path); |
282 FREE_C_HEAP_ARRAY(char, library_path, mtInternal); |
284 } |
283 } |
285 |
284 |
286 /* Default extensions directory */ |
285 /* Default extensions directory */ |
287 { |
286 { |
288 char path[MAX_PATH]; |
287 char path[MAX_PATH]; |
298 |
297 |
299 /* Default endorsed standards directory. */ |
298 /* Default endorsed standards directory. */ |
300 { |
299 { |
301 #define ENDORSED_DIR "\\lib\\endorsed" |
300 #define ENDORSED_DIR "\\lib\\endorsed" |
302 size_t len = strlen(Arguments::get_java_home()) + sizeof(ENDORSED_DIR); |
301 size_t len = strlen(Arguments::get_java_home()) + sizeof(ENDORSED_DIR); |
303 char * buf = NEW_C_HEAP_ARRAY(char, len); |
302 char * buf = NEW_C_HEAP_ARRAY(char, len, mtInternal); |
304 sprintf(buf, "%s%s", Arguments::get_java_home(), ENDORSED_DIR); |
303 sprintf(buf, "%s%s", Arguments::get_java_home(), ENDORSED_DIR); |
305 Arguments::set_endorsed_dirs(buf); |
304 Arguments::set_endorsed_dirs(buf); |
306 #undef ENDORSED_DIR |
305 #undef ENDORSED_DIR |
307 } |
306 } |
308 |
307 |
321 |
320 |
322 // Invoked from the BREAKPOINT Macro |
321 // Invoked from the BREAKPOINT Macro |
323 extern "C" void breakpoint() { |
322 extern "C" void breakpoint() { |
324 os::breakpoint(); |
323 os::breakpoint(); |
325 } |
324 } |
|
325 |
|
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 |
326 |
342 |
327 // os::current_stack_base() |
343 // os::current_stack_base() |
328 // |
344 // |
329 // Returns the base of the stack, which is the stack's |
345 // Returns the base of the stack, which is the stack's |
330 // starting address. This function must be called |
346 // starting address. This function must be called |
1012 |
1028 |
1013 DIR * |
1029 DIR * |
1014 os::opendir(const char *dirname) |
1030 os::opendir(const char *dirname) |
1015 { |
1031 { |
1016 assert(dirname != NULL, "just checking"); // hotspot change |
1032 assert(dirname != NULL, "just checking"); // hotspot change |
1017 DIR *dirp = (DIR *)malloc(sizeof(DIR)); |
1033 DIR *dirp = (DIR *)malloc(sizeof(DIR), mtInternal); |
1018 DWORD fattr; // hotspot change |
1034 DWORD fattr; // hotspot change |
1019 char alt_dirname[4] = { 0, 0, 0, 0 }; |
1035 char alt_dirname[4] = { 0, 0, 0, 0 }; |
1020 |
1036 |
1021 if (dirp == 0) { |
1037 if (dirp == 0) { |
1022 errno = ENOMEM; |
1038 errno = ENOMEM; |
1034 alt_dirname[2] = '\\'; |
1050 alt_dirname[2] = '\\'; |
1035 alt_dirname[3] = '\0'; |
1051 alt_dirname[3] = '\0'; |
1036 dirname = alt_dirname; |
1052 dirname = alt_dirname; |
1037 } |
1053 } |
1038 |
1054 |
1039 dirp->path = (char *)malloc(strlen(dirname) + 5); |
1055 dirp->path = (char *)malloc(strlen(dirname) + 5, mtInternal); |
1040 if (dirp->path == 0) { |
1056 if (dirp->path == 0) { |
1041 free(dirp); |
1057 free(dirp, mtInternal); |
1042 errno = ENOMEM; |
1058 errno = ENOMEM; |
1043 return 0; |
1059 return 0; |
1044 } |
1060 } |
1045 strcpy(dirp->path, dirname); |
1061 strcpy(dirp->path, dirname); |
1046 |
1062 |
1047 fattr = GetFileAttributes(dirp->path); |
1063 fattr = GetFileAttributes(dirp->path); |
1048 if (fattr == 0xffffffff) { |
1064 if (fattr == 0xffffffff) { |
1049 free(dirp->path); |
1065 free(dirp->path, mtInternal); |
1050 free(dirp); |
1066 free(dirp, mtInternal); |
1051 errno = ENOENT; |
1067 errno = ENOENT; |
1052 return 0; |
1068 return 0; |
1053 } else if ((fattr & FILE_ATTRIBUTE_DIRECTORY) == 0) { |
1069 } else if ((fattr & FILE_ATTRIBUTE_DIRECTORY) == 0) { |
1054 free(dirp->path); |
1070 free(dirp->path, mtInternal); |
1055 free(dirp); |
1071 free(dirp, mtInternal); |
1056 errno = ENOTDIR; |
1072 errno = ENOTDIR; |
1057 return 0; |
1073 return 0; |
1058 } |
1074 } |
1059 |
1075 |
1060 /* Append "*.*", or possibly "\\*.*", to path */ |
1076 /* Append "*.*", or possibly "\\*.*", to path */ |
1112 errno = EBADF; |
1128 errno = EBADF; |
1113 return -1; |
1129 return -1; |
1114 } |
1130 } |
1115 dirp->handle = INVALID_HANDLE_VALUE; |
1131 dirp->handle = INVALID_HANDLE_VALUE; |
1116 } |
1132 } |
1117 free(dirp->path); |
1133 free(dirp->path, mtInternal); |
1118 free(dirp); |
1134 free(dirp, mtInternal); |
1119 return 0; |
1135 return 0; |
1120 } |
1136 } |
1121 |
1137 |
1122 // This must be hard coded because it's the system's temporary |
1138 // This must be hard coded because it's the system's temporary |
1123 // directory not the java application's temp directory, ala java.io.tmpdir. |
1139 // directory not the java application's temp directory, ala java.io.tmpdir. |
1174 } |
1190 } |
1175 } |
1191 } |
1176 // release the storage |
1192 // release the storage |
1177 for (int i = 0 ; i < n ; i++) { |
1193 for (int i = 0 ; i < n ; i++) { |
1178 if (pelements[i] != NULL) { |
1194 if (pelements[i] != NULL) { |
1179 FREE_C_HEAP_ARRAY(char, pelements[i]); |
1195 FREE_C_HEAP_ARRAY(char, pelements[i], mtInternal); |
1180 } |
1196 } |
1181 } |
1197 } |
1182 if (pelements != NULL) { |
1198 if (pelements != NULL) { |
1183 FREE_C_HEAP_ARRAY(char*, pelements); |
1199 FREE_C_HEAP_ARRAY(char*, pelements, mtInternal); |
1184 } |
1200 } |
1185 } else { |
1201 } else { |
1186 jio_snprintf(buffer, buflen, "%s\\%s.dll", pname, fname); |
1202 jio_snprintf(buffer, buflen, "%s\\%s.dll", pname, fname); |
1187 } |
1203 } |
1188 } |
1204 } |
2635 int *_numa_used_node_list; // allocated below |
2651 int *_numa_used_node_list; // allocated below |
2636 int _numa_used_node_count; |
2652 int _numa_used_node_count; |
2637 |
2653 |
2638 void free_node_list() { |
2654 void free_node_list() { |
2639 if (_numa_used_node_list != NULL) { |
2655 if (_numa_used_node_list != NULL) { |
2640 FREE_C_HEAP_ARRAY(int, _numa_used_node_list); |
2656 FREE_C_HEAP_ARRAY(int, _numa_used_node_list, mtInternal); |
2641 } |
2657 } |
2642 } |
2658 } |
2643 |
2659 |
2644 public: |
2660 public: |
2645 NUMANodeListHolder() { |
2661 NUMANodeListHolder() { |
2657 DWORD_PTR sys_aff_mask; |
2673 DWORD_PTR sys_aff_mask; |
2658 if (!GetProcessAffinityMask(GetCurrentProcess(), &proc_aff_mask, &sys_aff_mask)) return false; |
2674 if (!GetProcessAffinityMask(GetCurrentProcess(), &proc_aff_mask, &sys_aff_mask)) return false; |
2659 ULONG highest_node_number; |
2675 ULONG highest_node_number; |
2660 if (!os::Kernel32Dll::GetNumaHighestNodeNumber(&highest_node_number)) return false; |
2676 if (!os::Kernel32Dll::GetNumaHighestNodeNumber(&highest_node_number)) return false; |
2661 free_node_list(); |
2677 free_node_list(); |
2662 _numa_used_node_list = NEW_C_HEAP_ARRAY(int, highest_node_number + 1); |
2678 _numa_used_node_list = NEW_C_HEAP_ARRAY(int, highest_node_number + 1, mtInternal); |
2663 for (unsigned int i = 0; i <= highest_node_number; i++) { |
2679 for (unsigned int i = 0; i <= highest_node_number; i++) { |
2664 ULONGLONG proc_mask_numa_node; |
2680 ULONGLONG proc_mask_numa_node; |
2665 if (!os::Kernel32Dll::GetNumaNodeProcessorMask(i, &proc_mask_numa_node)) return false; |
2681 if (!os::Kernel32Dll::GetNumaNodeProcessorMask(i, &proc_mask_numa_node)) return false; |
2666 if ((proc_aff_mask & proc_mask_numa_node)!=0) { |
2682 if ((proc_aff_mask & proc_mask_numa_node)!=0) { |
2667 _numa_used_node_list[_numa_used_node_count++] = i; |
2683 _numa_used_node_list[_numa_used_node_count++] = i; |
2916 } |
2932 } |
2917 |
2933 |
2918 // On win32, one cannot release just a part of reserved memory, it's an |
2934 // On win32, one cannot release just a part of reserved memory, it's an |
2919 // all or nothing deal. When we split a reservation, we must break the |
2935 // all or nothing deal. When we split a reservation, we must break the |
2920 // reservation into two reservations. |
2936 // reservation into two reservations. |
2921 void os::split_reserved_memory(char *base, size_t size, size_t split, |
2937 void os::pd_split_reserved_memory(char *base, size_t size, size_t split, |
2922 bool realloc) { |
2938 bool realloc) { |
2923 if (size > 0) { |
2939 if (size > 0) { |
2924 release_memory(base, size); |
2940 release_memory(base, size); |
2925 if (realloc) { |
2941 if (realloc) { |
2926 reserve_memory(split, base); |
2942 reserve_memory(split, base); |
2929 reserve_memory(size - split, base + split); |
2945 reserve_memory(size - split, base + split); |
2930 } |
2946 } |
2931 } |
2947 } |
2932 } |
2948 } |
2933 |
2949 |
2934 char* os::reserve_memory(size_t bytes, char* addr, size_t alignment_hint) { |
2950 char* os::pd_reserve_memory(size_t bytes, char* addr, size_t alignment_hint) { |
2935 assert((size_t)addr % os::vm_allocation_granularity() == 0, |
2951 assert((size_t)addr % os::vm_allocation_granularity() == 0, |
2936 "reserve alignment"); |
2952 "reserve alignment"); |
2937 assert(bytes % os::vm_allocation_granularity() == 0, "reserve block size"); |
2953 assert(bytes % os::vm_allocation_granularity() == 0, "reserve block size"); |
2938 char* res; |
2954 char* res; |
2939 // note that if UseLargePages is on, all the areas that require interleaving |
2955 // note that if UseLargePages is on, all the areas that require interleaving |
2962 return res; |
2978 return res; |
2963 } |
2979 } |
2964 |
2980 |
2965 // Reserve memory at an arbitrary address, only if that area is |
2981 // Reserve memory at an arbitrary address, only if that area is |
2966 // available (and not reserved for something else). |
2982 // available (and not reserved for something else). |
2967 char* os::attempt_reserve_memory_at(size_t bytes, char* requested_addr) { |
2983 char* os::pd_attempt_reserve_memory_at(size_t bytes, char* requested_addr) { |
2968 // Windows os::reserve_memory() fails of the requested address range is |
2984 // Windows os::reserve_memory() fails of the requested address range is |
2969 // not avilable. |
2985 // not avilable. |
2970 return reserve_memory(bytes, requested_addr); |
2986 return reserve_memory(bytes, requested_addr); |
2971 } |
2987 } |
2972 |
2988 |
3025 } |
3041 } |
3026 |
3042 |
3027 void os::print_statistics() { |
3043 void os::print_statistics() { |
3028 } |
3044 } |
3029 |
3045 |
3030 bool os::commit_memory(char* addr, size_t bytes, bool exec) { |
3046 bool os::pd_commit_memory(char* addr, size_t bytes, bool exec) { |
3031 if (bytes == 0) { |
3047 if (bytes == 0) { |
3032 // Don't bother the OS with noops. |
3048 // Don't bother the OS with noops. |
3033 return true; |
3049 return true; |
3034 } |
3050 } |
3035 assert((size_t) addr % os::vm_page_size() == 0, "commit on page boundaries"); |
3051 assert((size_t) addr % os::vm_page_size() == 0, "commit on page boundaries"); |
3073 } |
3089 } |
3074 // if we made it this far, return true |
3090 // if we made it this far, return true |
3075 return true; |
3091 return true; |
3076 } |
3092 } |
3077 |
3093 |
3078 bool os::commit_memory(char* addr, size_t size, size_t alignment_hint, |
3094 bool os::pd_commit_memory(char* addr, size_t size, size_t alignment_hint, |
3079 bool exec) { |
3095 bool exec) { |
3080 return commit_memory(addr, size, exec); |
3096 return commit_memory(addr, size, exec); |
3081 } |
3097 } |
3082 |
3098 |
3083 bool os::uncommit_memory(char* addr, size_t bytes) { |
3099 bool os::pd_uncommit_memory(char* addr, size_t bytes) { |
3084 if (bytes == 0) { |
3100 if (bytes == 0) { |
3085 // Don't bother the OS with noops. |
3101 // Don't bother the OS with noops. |
3086 return true; |
3102 return true; |
3087 } |
3103 } |
3088 assert((size_t) addr % os::vm_page_size() == 0, "uncommit on page boundaries"); |
3104 assert((size_t) addr % os::vm_page_size() == 0, "uncommit on page boundaries"); |
3089 assert(bytes % os::vm_page_size() == 0, "uncommit in page-sized chunks"); |
3105 assert(bytes % os::vm_page_size() == 0, "uncommit in page-sized chunks"); |
3090 return VirtualFree(addr, bytes, MEM_DECOMMIT) != 0; |
3106 return (VirtualFree(addr, bytes, MEM_DECOMMIT) != 0); |
3091 } |
3107 } |
3092 |
3108 |
3093 bool os::release_memory(char* addr, size_t bytes) { |
3109 bool os::pd_release_memory(char* addr, size_t bytes) { |
3094 return VirtualFree(addr, 0, MEM_RELEASE) != 0; |
3110 return VirtualFree(addr, 0, MEM_RELEASE) != 0; |
3095 } |
3111 } |
3096 |
3112 |
3097 bool os::create_stack_guard_pages(char* addr, size_t size) { |
3113 bool os::pd_create_stack_guard_pages(char* addr, size_t size) { |
3098 return os::commit_memory(addr, size); |
3114 return os::commit_memory(addr, size); |
3099 } |
3115 } |
3100 |
3116 |
3101 bool os::remove_stack_guard_pages(char* addr, size_t size) { |
3117 bool os::remove_stack_guard_pages(char* addr, size_t size) { |
3102 return os::uncommit_memory(addr, size); |
3118 return os::uncommit_memory(addr, size); |
3139 bool os::unguard_memory(char* addr, size_t bytes) { |
3155 bool os::unguard_memory(char* addr, size_t bytes) { |
3140 DWORD old_status; |
3156 DWORD old_status; |
3141 return VirtualProtect(addr, bytes, PAGE_READWRITE, &old_status) != 0; |
3157 return VirtualProtect(addr, bytes, PAGE_READWRITE, &old_status) != 0; |
3142 } |
3158 } |
3143 |
3159 |
3144 void os::realign_memory(char *addr, size_t bytes, size_t alignment_hint) { } |
3160 void os::pd_realign_memory(char *addr, size_t bytes, size_t alignment_hint) { } |
3145 void os::free_memory(char *addr, size_t bytes, size_t alignment_hint) { } |
3161 void os::pd_free_memory(char *addr, size_t bytes, size_t alignment_hint) { } |
3146 void os::numa_make_global(char *addr, size_t bytes) { } |
3162 void os::numa_make_global(char *addr, size_t bytes) { } |
3147 void os::numa_make_local(char *addr, size_t bytes, int lgrp_hint) { } |
3163 void os::numa_make_local(char *addr, size_t bytes, int lgrp_hint) { } |
3148 bool os::numa_topology_changed() { return false; } |
3164 bool os::numa_topology_changed() { return false; } |
3149 size_t os::numa_get_groups_num() { return MAX2(numa_node_list_holder.get_count(), 1); } |
3165 size_t os::numa_get_groups_num() { return MAX2(numa_node_list_holder.get_count(), 1); } |
3150 int os::numa_get_group_id() { return 0; } |
3166 int os::numa_get_group_id() { return 0; } |
4274 /* lpBuffer must fit into 64K or else PeekConsoleInput fails */ |
4290 /* lpBuffer must fit into 64K or else PeekConsoleInput fails */ |
4275 if (numEvents > MAX_INPUT_EVENTS) { |
4291 if (numEvents > MAX_INPUT_EVENTS) { |
4276 numEvents = MAX_INPUT_EVENTS; |
4292 numEvents = MAX_INPUT_EVENTS; |
4277 } |
4293 } |
4278 |
4294 |
4279 lpBuffer = (INPUT_RECORD *)os::malloc(numEvents * sizeof(INPUT_RECORD)); |
4295 lpBuffer = (INPUT_RECORD *)os::malloc(numEvents * sizeof(INPUT_RECORD), mtInternal); |
4280 if (lpBuffer == NULL) { |
4296 if (lpBuffer == NULL) { |
4281 return FALSE; |
4297 return FALSE; |
4282 } |
4298 } |
4283 |
4299 |
4284 error = ::PeekConsoleInput(han, lpBuffer, numEvents, &numEventsRead); |
4300 error = ::PeekConsoleInput(han, lpBuffer, numEvents, &numEventsRead); |
4285 if (error == 0) { |
4301 if (error == 0) { |
4286 os::free(lpBuffer); |
4302 os::free(lpBuffer, mtInternal); |
4287 return FALSE; |
4303 return FALSE; |
4288 } |
4304 } |
4289 |
4305 |
4290 /* Examine input records for the number of bytes available */ |
4306 /* Examine input records for the number of bytes available */ |
4291 for(i=0; i<numEvents; i++) { |
4307 for(i=0; i<numEvents; i++) { |
4302 } |
4318 } |
4303 } |
4319 } |
4304 } |
4320 } |
4305 |
4321 |
4306 if(lpBuffer != NULL) { |
4322 if(lpBuffer != NULL) { |
4307 os::free(lpBuffer); |
4323 os::free(lpBuffer, mtInternal); |
4308 } |
4324 } |
4309 |
4325 |
4310 *pbytes = (long) actualLength; |
4326 *pbytes = (long) actualLength; |
4311 return TRUE; |
4327 return TRUE; |
4312 } |
4328 } |
4313 |
4329 |
4314 // Map a block of memory. |
4330 // Map a block of memory. |
4315 char* os::map_memory(int fd, const char* file_name, size_t file_offset, |
4331 char* os::pd_map_memory(int fd, const char* file_name, size_t file_offset, |
4316 char *addr, size_t bytes, bool read_only, |
4332 char *addr, size_t bytes, bool read_only, |
4317 bool allow_exec) { |
4333 bool allow_exec) { |
4318 HANDLE hFile; |
4334 HANDLE hFile; |
4319 char* base; |
4335 char* base; |
4320 |
4336 |
4430 return base; |
4446 return base; |
4431 } |
4447 } |
4432 |
4448 |
4433 |
4449 |
4434 // Remap a block of memory. |
4450 // Remap a block of memory. |
4435 char* os::remap_memory(int fd, const char* file_name, size_t file_offset, |
4451 char* os::pd_remap_memory(int fd, const char* file_name, size_t file_offset, |
4436 char *addr, size_t bytes, bool read_only, |
4452 char *addr, size_t bytes, bool read_only, |
4437 bool allow_exec) { |
4453 bool allow_exec) { |
4438 // This OS does not allow existing memory maps to be remapped so we |
4454 // This OS does not allow existing memory maps to be remapped so we |
4439 // have to unmap the memory before we remap it. |
4455 // have to unmap the memory before we remap it. |
4440 if (!os::unmap_memory(addr, bytes)) { |
4456 if (!os::unmap_memory(addr, bytes)) { |
4443 |
4459 |
4444 // There is a very small theoretical window between the unmap_memory() |
4460 // There is a very small theoretical window between the unmap_memory() |
4445 // call above and the map_memory() call below where a thread in native |
4461 // call above and the map_memory() call below where a thread in native |
4446 // code may be able to access an address that is no longer mapped. |
4462 // code may be able to access an address that is no longer mapped. |
4447 |
4463 |
4448 return os::map_memory(fd, file_name, file_offset, addr, bytes, read_only, |
4464 return os::map_memory(fd, file_name, file_offset, addr, bytes, |
4449 allow_exec); |
4465 read_only, allow_exec); |
4450 } |
4466 } |
4451 |
4467 |
4452 |
4468 |
4453 // Unmap a block of memory. |
4469 // Unmap a block of memory. |
4454 // Returns true=success, otherwise false. |
4470 // Returns true=success, otherwise false. |
4455 |
4471 |
4456 bool os::unmap_memory(char* addr, size_t bytes) { |
4472 bool os::pd_unmap_memory(char* addr, size_t bytes) { |
4457 BOOL result = UnmapViewOfFile(addr); |
4473 BOOL result = UnmapViewOfFile(addr); |
4458 if (result == 0) { |
4474 if (result == 0) { |
4459 if (PrintMiscellaneous && Verbose) { |
4475 if (PrintMiscellaneous && Verbose) { |
4460 DWORD err = GetLastError(); |
4476 DWORD err = GetLastError(); |
4461 tty->print_cr("UnmapViewOfFile() failed: GetLastError->%ld.", err); |
4477 tty->print_cr("UnmapViewOfFile() failed: GetLastError->%ld.", err); |
4929 // Kernel32 API |
4945 // Kernel32 API |
4930 typedef SIZE_T (WINAPI* GetLargePageMinimum_Fn)(void); |
4946 typedef SIZE_T (WINAPI* GetLargePageMinimum_Fn)(void); |
4931 typedef LPVOID (WINAPI *VirtualAllocExNuma_Fn) (HANDLE, LPVOID, SIZE_T, DWORD, DWORD, DWORD); |
4947 typedef LPVOID (WINAPI *VirtualAllocExNuma_Fn) (HANDLE, LPVOID, SIZE_T, DWORD, DWORD, DWORD); |
4932 typedef BOOL (WINAPI *GetNumaHighestNodeNumber_Fn) (PULONG); |
4948 typedef BOOL (WINAPI *GetNumaHighestNodeNumber_Fn) (PULONG); |
4933 typedef BOOL (WINAPI *GetNumaNodeProcessorMask_Fn) (UCHAR, PULONGLONG); |
4949 typedef BOOL (WINAPI *GetNumaNodeProcessorMask_Fn) (UCHAR, PULONGLONG); |
|
4950 typedef USHORT (WINAPI* RtlCaptureStackBackTrace_Fn)(ULONG, ULONG, PVOID*, PULONG); |
4934 |
4951 |
4935 GetLargePageMinimum_Fn os::Kernel32Dll::_GetLargePageMinimum = NULL; |
4952 GetLargePageMinimum_Fn os::Kernel32Dll::_GetLargePageMinimum = NULL; |
4936 VirtualAllocExNuma_Fn os::Kernel32Dll::_VirtualAllocExNuma = NULL; |
4953 VirtualAllocExNuma_Fn os::Kernel32Dll::_VirtualAllocExNuma = NULL; |
4937 GetNumaHighestNodeNumber_Fn os::Kernel32Dll::_GetNumaHighestNodeNumber = NULL; |
4954 GetNumaHighestNodeNumber_Fn os::Kernel32Dll::_GetNumaHighestNodeNumber = NULL; |
4938 GetNumaNodeProcessorMask_Fn os::Kernel32Dll::_GetNumaNodeProcessorMask = NULL; |
4955 GetNumaNodeProcessorMask_Fn os::Kernel32Dll::_GetNumaNodeProcessorMask = NULL; |
|
4956 RtlCaptureStackBackTrace_Fn os::Kernel32Dll::_RtlCaptureStackBackTrace = NULL; |
|
4957 |
|
4958 |
4939 BOOL os::Kernel32Dll::initialized = FALSE; |
4959 BOOL os::Kernel32Dll::initialized = FALSE; |
4940 SIZE_T os::Kernel32Dll::GetLargePageMinimum() { |
4960 SIZE_T os::Kernel32Dll::GetLargePageMinimum() { |
4941 assert(initialized && _GetLargePageMinimum != NULL, |
4961 assert(initialized && _GetLargePageMinimum != NULL, |
4942 "GetLargePageMinimumAvailable() not yet called"); |
4962 "GetLargePageMinimumAvailable() not yet called"); |
4943 return _GetLargePageMinimum(); |
4963 return _GetLargePageMinimum(); |
4976 "NUMACallsAvailable() not yet called"); |
4996 "NUMACallsAvailable() not yet called"); |
4977 |
4997 |
4978 return _GetNumaNodeProcessorMask(node, proc_mask); |
4998 return _GetNumaNodeProcessorMask(node, proc_mask); |
4979 } |
4999 } |
4980 |
5000 |
|
5001 USHORT os::Kernel32Dll::RtlCaptureStackBackTrace(ULONG FrameToSkip, |
|
5002 ULONG FrameToCapture, PVOID* BackTrace, PULONG BackTraceHash) { |
|
5003 if (!initialized) { |
|
5004 initialize(); |
|
5005 } |
|
5006 |
|
5007 if (_RtlCaptureStackBackTrace != NULL) { |
|
5008 return _RtlCaptureStackBackTrace(FrameToSkip, FrameToCapture, |
|
5009 BackTrace, BackTraceHash); |
|
5010 } else { |
|
5011 return 0; |
|
5012 } |
|
5013 } |
4981 |
5014 |
4982 void os::Kernel32Dll::initializeCommon() { |
5015 void os::Kernel32Dll::initializeCommon() { |
4983 if (!initialized) { |
5016 if (!initialized) { |
4984 HMODULE handle = ::GetModuleHandle("Kernel32.dll"); |
5017 HMODULE handle = ::GetModuleHandle("Kernel32.dll"); |
4985 assert(handle != NULL, "Just check"); |
5018 assert(handle != NULL, "Just check"); |
4986 _GetLargePageMinimum = (GetLargePageMinimum_Fn)::GetProcAddress(handle, "GetLargePageMinimum"); |
5019 _GetLargePageMinimum = (GetLargePageMinimum_Fn)::GetProcAddress(handle, "GetLargePageMinimum"); |
4987 _VirtualAllocExNuma = (VirtualAllocExNuma_Fn)::GetProcAddress(handle, "VirtualAllocExNuma"); |
5020 _VirtualAllocExNuma = (VirtualAllocExNuma_Fn)::GetProcAddress(handle, "VirtualAllocExNuma"); |
4988 _GetNumaHighestNodeNumber = (GetNumaHighestNodeNumber_Fn)::GetProcAddress(handle, "GetNumaHighestNodeNumber"); |
5021 _GetNumaHighestNodeNumber = (GetNumaHighestNodeNumber_Fn)::GetProcAddress(handle, "GetNumaHighestNodeNumber"); |
4989 _GetNumaNodeProcessorMask = (GetNumaNodeProcessorMask_Fn)::GetProcAddress(handle, "GetNumaNodeProcessorMask"); |
5022 _GetNumaNodeProcessorMask = (GetNumaNodeProcessorMask_Fn)::GetProcAddress(handle, "GetNumaNodeProcessorMask"); |
|
5023 _RtlCaptureStackBackTrace = (RtlCaptureStackBackTrace_Fn)::GetProcAddress(handle, "RtlCaptureStackBackTrace"); |
4990 initialized = TRUE; |
5024 initialized = TRUE; |
4991 } |
5025 } |
4992 } |
5026 } |
4993 |
5027 |
4994 |
5028 |
5099 CreateToolhelp32Snapshot_Fn os::Kernel32Dll::_CreateToolhelp32Snapshot = NULL; |
5133 CreateToolhelp32Snapshot_Fn os::Kernel32Dll::_CreateToolhelp32Snapshot = NULL; |
5100 Module32First_Fn os::Kernel32Dll::_Module32First = NULL; |
5134 Module32First_Fn os::Kernel32Dll::_Module32First = NULL; |
5101 Module32Next_Fn os::Kernel32Dll::_Module32Next = NULL; |
5135 Module32Next_Fn os::Kernel32Dll::_Module32Next = NULL; |
5102 GetNativeSystemInfo_Fn os::Kernel32Dll::_GetNativeSystemInfo = NULL; |
5136 GetNativeSystemInfo_Fn os::Kernel32Dll::_GetNativeSystemInfo = NULL; |
5103 |
5137 |
5104 |
|
5105 void os::Kernel32Dll::initialize() { |
5138 void os::Kernel32Dll::initialize() { |
5106 if (!initialized) { |
5139 if (!initialized) { |
5107 HMODULE handle = ::GetModuleHandle("Kernel32.dll"); |
5140 HMODULE handle = ::GetModuleHandle("Kernel32.dll"); |
5108 assert(handle != NULL, "Just check"); |
5141 assert(handle != NULL, "Just check"); |
5109 |
5142 |
5176 assert(initialized && _GetNativeSystemInfo != NULL, |
5209 assert(initialized && _GetNativeSystemInfo != NULL, |
5177 "GetNativeSystemInfoAvailable() not yet called"); |
5210 "GetNativeSystemInfoAvailable() not yet called"); |
5178 |
5211 |
5179 _GetNativeSystemInfo(lpSystemInfo); |
5212 _GetNativeSystemInfo(lpSystemInfo); |
5180 } |
5213 } |
5181 |
|
5182 |
|
5183 |
5214 |
5184 // PSAPI API |
5215 // PSAPI API |
5185 |
5216 |
5186 |
5217 |
5187 typedef BOOL (WINAPI *EnumProcessModules_Fn)(HANDLE, HMODULE *, DWORD, LPDWORD); |
5218 typedef BOOL (WINAPI *EnumProcessModules_Fn)(HANDLE, HMODULE *, DWORD, LPDWORD); |