@@ -178,6 +178,91 @@ static inline double fileTimeAsDouble(FILETIME* time) {
178
178
179
179
// Implementation of os
180
180
181
+ #define RANGE_FORMAT " [" PTR_FORMAT " -" PTR_FORMAT " )"
182
+ #define RANGE_FORMAT_ARGS (p, len ) p2i(p), p2i((address)p + len)
183
+
184
+ // A number of wrappers for more frequently used system calls, to add standard logging.
185
+
186
+ struct PreserveLastError {
187
+ const DWORD v;
188
+ PreserveLastError () : v(::GetLastError()) {}
189
+ ~PreserveLastError () { ::SetLastError (v); }
190
+ };
191
+
192
+ // Logging wrapper for VirtualAlloc
193
+ static LPVOID virtualAlloc (LPVOID lpAddress, SIZE_T dwSize, DWORD flAllocationType, DWORD flProtect) {
194
+ LPVOID result = ::VirtualAlloc (lpAddress, dwSize, flAllocationType, flProtect);
195
+ if (result != NULL ) {
196
+ log_trace (os)(" VirtualAlloc(" PTR_FORMAT " , " SIZE_FORMAT " , %x, %x) returned " PTR_FORMAT " %s." ,
197
+ p2i (lpAddress), dwSize, flAllocationType, flProtect, p2i (result),
198
+ ((lpAddress != NULL && result != lpAddress) ? " <different base!>" : " " ));
199
+ } else {
200
+ PreserveLastError ple;
201
+ log_info (os)(" VirtualAlloc(" PTR_FORMAT " , " SIZE_FORMAT " , %x, %x) failed (%u)." ,
202
+ p2i (lpAddress), dwSize, flAllocationType, flProtect, ple.v );
203
+ }
204
+ return result;
205
+ }
206
+
207
+ // Logging wrapper for VirtualFree
208
+ static BOOL virtualFree (LPVOID lpAddress, SIZE_T dwSize, DWORD dwFreeType) {
209
+ BOOL result = ::VirtualFree (lpAddress, dwSize, dwFreeType);
210
+ if (result != FALSE ) {
211
+ log_trace (os)(" VirtualFree(" PTR_FORMAT " , " SIZE_FORMAT " , %x) succeeded" ,
212
+ p2i (lpAddress), dwSize, dwFreeType);
213
+ } else {
214
+ PreserveLastError ple;
215
+ log_info (os)(" VirtualFree(" PTR_FORMAT " , " SIZE_FORMAT " , %x) failed (%u)." ,
216
+ p2i (lpAddress), dwSize, dwFreeType, ple.v );
217
+ }
218
+ return result;
219
+ }
220
+
221
+ // Logging wrapper for VirtualAllocExNuma
222
+ static LPVOID virtualAllocExNuma (HANDLE hProcess, LPVOID lpAddress, SIZE_T dwSize, DWORD flAllocationType,
223
+ DWORD flProtect, DWORD nndPreferred) {
224
+ LPVOID result = ::VirtualAllocExNuma (hProcess, lpAddress, dwSize, flAllocationType, flProtect, nndPreferred);
225
+ if (result != NULL ) {
226
+ log_trace (os)(" VirtualAllocExNuma(" PTR_FORMAT " , " SIZE_FORMAT " , %x, %x, %x) returned " PTR_FORMAT " %s." ,
227
+ p2i (lpAddress), dwSize, flAllocationType, flProtect, nndPreferred, p2i (result),
228
+ ((lpAddress != NULL && result != lpAddress) ? " <different base!>" : " " ));
229
+ } else {
230
+ PreserveLastError ple;
231
+ log_info (os)(" VirtualAllocExNuma(" PTR_FORMAT " , " SIZE_FORMAT " , %x, %x, %x) failed (%u)." ,
232
+ p2i (lpAddress), dwSize, flAllocationType, flProtect, nndPreferred, ple.v );
233
+ }
234
+ return result;
235
+ }
236
+
237
+ // Logging wrapper for MapViewOfFileEx
238
+ static LPVOID mapViewOfFileEx (HANDLE hFileMappingObject, DWORD dwDesiredAccess, DWORD dwFileOffsetHigh,
239
+ DWORD dwFileOffsetLow, SIZE_T dwNumberOfBytesToMap, LPVOID lpBaseAddress) {
240
+ LPVOID result = ::MapViewOfFileEx (hFileMappingObject, dwDesiredAccess, dwFileOffsetHigh,
241
+ dwFileOffsetLow, dwNumberOfBytesToMap, lpBaseAddress);
242
+ if (result != NULL ) {
243
+ log_trace (os)(" MapViewOfFileEx(" PTR_FORMAT " , " SIZE_FORMAT " ) returned " PTR_FORMAT " %s." ,
244
+ p2i (lpBaseAddress), dwNumberOfBytesToMap, p2i (result),
245
+ ((lpBaseAddress != NULL && result != lpBaseAddress) ? " <different base!>" : " " ));
246
+ } else {
247
+ PreserveLastError ple;
248
+ log_info (os)(" MapViewOfFileEx(" PTR_FORMAT " , " SIZE_FORMAT " ) failed (%u)." ,
249
+ p2i (lpBaseAddress), dwNumberOfBytesToMap, ple.v );
250
+ }
251
+ return result;
252
+ }
253
+
254
+ // Logging wrapper for UnmapViewOfFile
255
+ static BOOL unmapViewOfFile (LPCVOID lpBaseAddress) {
256
+ BOOL result = ::UnmapViewOfFile (lpBaseAddress);
257
+ if (result != FALSE ) {
258
+ log_trace (os)(" UnmapViewOfFile(" PTR_FORMAT " ) succeeded" , p2i (lpBaseAddress));
259
+ } else {
260
+ PreserveLastError ple;
261
+ log_info (os)(" UnmapViewOfFile(" PTR_FORMAT " ) failed (%u)." , p2i (lpBaseAddress), ple.v );
262
+ }
263
+ return result;
264
+ }
265
+
181
266
bool os::unsetenv (const char * name) {
182
267
assert (name != NULL , " Null pointer" );
183
268
return (SetEnvironmentVariable (name, NULL ) == TRUE );
@@ -340,7 +425,6 @@ int os::get_native_stack(address* stack, int frames, int toSkip) {
340
425
return captured;
341
426
}
342
427
343
-
344
428
// os::current_stack_base()
345
429
//
346
430
// Returns the base of the stack, which is the stack's
@@ -2900,7 +2984,7 @@ static char* allocate_pages_individually(size_t bytes, char* addr, DWORD flags,
2900
2984
// Overflowed.
2901
2985
return NULL ;
2902
2986
}
2903
- p_buf = (char *) VirtualAlloc (addr,
2987
+ p_buf = (char *) virtualAlloc (addr,
2904
2988
size_of_reserve, // size of Reserve
2905
2989
MEM_RESERVE,
2906
2990
PAGE_READWRITE);
@@ -2946,15 +3030,15 @@ static char* allocate_pages_individually(size_t bytes, char* addr, DWORD flags,
2946
3030
p_new = NULL ;
2947
3031
} else {
2948
3032
if (!UseNUMAInterleaving) {
2949
- p_new = (char *) VirtualAlloc (next_alloc_addr,
3033
+ p_new = (char *) virtualAlloc (next_alloc_addr,
2950
3034
bytes_to_rq,
2951
3035
flags,
2952
3036
prot);
2953
3037
} else {
2954
3038
// get the next node to use from the used_node_list
2955
3039
assert (numa_node_list_holder.get_count () > 0 , " Multiple NUMA nodes expected" );
2956
3040
DWORD node = numa_node_list_holder.get_node_list_entry (count % numa_node_list_holder.get_count ());
2957
- p_new = (char *)VirtualAllocExNuma (hProc, next_alloc_addr, bytes_to_rq, flags, prot, node);
3041
+ p_new = (char *)virtualAllocExNuma (hProc, next_alloc_addr, bytes_to_rq, flags, prot, node);
2958
3042
}
2959
3043
}
2960
3044
@@ -3100,7 +3184,7 @@ char* os::map_memory_to_file(char* base, size_t size, int fd) {
3100
3184
return NULL ;
3101
3185
}
3102
3186
3103
- LPVOID addr = MapViewOfFileEx (fileMapping, FILE_MAP_WRITE, 0 , 0 , size, base);
3187
+ LPVOID addr = mapViewOfFileEx (fileMapping, FILE_MAP_WRITE, 0 , 0 , size, base);
3104
3188
3105
3189
CloseHandle (fileMapping);
3106
3190
@@ -3127,14 +3211,19 @@ void os::split_reserved_memory(char *base, size_t size, size_t split) {
3127
3211
assert (is_aligned (base, os::vm_allocation_granularity ()), " Sanity" );
3128
3212
assert (is_aligned (split_address, os::vm_allocation_granularity ()), " Sanity" );
3129
3213
3130
- release_memory (base, size);
3131
- attempt_reserve_memory_at (base, split);
3132
- attempt_reserve_memory_at (split_address, size - split);
3214
+ const bool rc = release_memory (base, size) &&
3215
+ (attempt_reserve_memory_at (base, split) != NULL ) &&
3216
+ (attempt_reserve_memory_at (split_address, size - split) != NULL );
3217
+ if (!rc) {
3218
+ log_warning (os)(" os::split_reserved_memory failed for [" RANGE_FORMAT " )" ,
3219
+ RANGE_FORMAT_ARGS (base, size));
3220
+ assert (false , " os::split_reserved_memory failed for [" RANGE_FORMAT " )" ,
3221
+ RANGE_FORMAT_ARGS (base, size));
3222
+ }
3133
3223
3134
3224
// NMT: nothing to do here. Since Windows implements the split by
3135
3225
// releasing and re-reserving memory, the parts are already registered
3136
3226
// as individual mappings with NMT.
3137
-
3138
3227
}
3139
3228
3140
3229
// Multiple threads can race in this code but it's not possible to unmap small sections of
@@ -3198,7 +3287,7 @@ char* os::pd_attempt_reserve_memory_at(char* addr, size_t bytes) {
3198
3287
// will go thru reserve_memory_special rather than thru here.
3199
3288
bool use_individual = (UseNUMAInterleaving && !UseLargePages);
3200
3289
if (!use_individual) {
3201
- res = (char *)VirtualAlloc (addr, bytes, MEM_RESERVE, PAGE_READWRITE);
3290
+ res = (char *)virtualAlloc (addr, bytes, MEM_RESERVE, PAGE_READWRITE);
3202
3291
} else {
3203
3292
elapsedTimer reserveTimer;
3204
3293
if (Verbose && PrintMiscellaneous) reserveTimer.start ();
@@ -3277,7 +3366,7 @@ char* os::pd_reserve_memory_special(size_t bytes, size_t alignment, char* addr,
3277
3366
3278
3367
// normal policy just allocate it all at once
3279
3368
DWORD flag = MEM_RESERVE | MEM_COMMIT | MEM_LARGE_PAGES;
3280
- char * res = (char *)VirtualAlloc (addr, bytes, flag, prot);
3369
+ char * res = (char *)virtualAlloc (addr, bytes, flag, prot);
3281
3370
3282
3371
return res;
3283
3372
}
@@ -3314,7 +3403,7 @@ bool os::pd_commit_memory(char* addr, size_t bytes, bool exec) {
3314
3403
// is always within a reserve covered by a single VirtualAlloc
3315
3404
// in that case we can just do a single commit for the requested size
3316
3405
if (!UseNUMAInterleaving) {
3317
- if (VirtualAlloc (addr, bytes, MEM_COMMIT, PAGE_READWRITE) == NULL ) {
3406
+ if (virtualAlloc (addr, bytes, MEM_COMMIT, PAGE_READWRITE) == NULL ) {
3318
3407
NOT_PRODUCT (warn_fail_commit_memory (addr, bytes, exec);)
3319
3408
return false ;
3320
3409
}
@@ -3339,7 +3428,7 @@ bool os::pd_commit_memory(char* addr, size_t bytes, bool exec) {
3339
3428
MEMORY_BASIC_INFORMATION alloc_info;
3340
3429
VirtualQuery (next_alloc_addr, &alloc_info, sizeof (alloc_info));
3341
3430
size_t bytes_to_rq = MIN2 (bytes_remaining, (size_t )alloc_info.RegionSize );
3342
- if (VirtualAlloc (next_alloc_addr, bytes_to_rq, MEM_COMMIT,
3431
+ if (virtualAlloc (next_alloc_addr, bytes_to_rq, MEM_COMMIT,
3343
3432
PAGE_READWRITE) == NULL ) {
3344
3433
NOT_PRODUCT (warn_fail_commit_memory (next_alloc_addr, bytes_to_rq,
3345
3434
exec);)
@@ -3391,11 +3480,11 @@ bool os::pd_uncommit_memory(char* addr, size_t bytes) {
3391
3480
}
3392
3481
assert ((size_t ) addr % os::vm_page_size () == 0 , " uncommit on page boundaries" );
3393
3482
assert (bytes % os::vm_page_size () == 0 , " uncommit in page-sized chunks" );
3394
- return (VirtualFree (addr, bytes, MEM_DECOMMIT) != 0 );
3483
+ return (virtualFree (addr, bytes, MEM_DECOMMIT) == TRUE );
3395
3484
}
3396
3485
3397
3486
bool os::pd_release_memory (char * addr, size_t bytes) {
3398
- return VirtualFree (addr, 0 , MEM_RELEASE) != 0 ;
3487
+ return virtualFree (addr, 0 , MEM_RELEASE) != 0 ;
3399
3488
}
3400
3489
3401
3490
bool os::pd_create_stack_guard_pages (char * addr, size_t size) {
@@ -4941,10 +5030,9 @@ char* os::pd_map_memory(int fd, const char* file_name, size_t file_offset,
4941
5030
// we might consider DLLizing the shared archive with a proper PE
4942
5031
// header so that mapping executable + sharing is possible.
4943
5032
4944
- base = (char *) VirtualAlloc (addr, bytes, MEM_COMMIT | MEM_RESERVE,
5033
+ base = (char *) virtualAlloc (addr, bytes, MEM_COMMIT | MEM_RESERVE,
4945
5034
PAGE_READWRITE);
4946
5035
if (base == NULL ) {
4947
- log_info (os)(" VirtualAlloc() failed: GetLastError->%ld." , GetLastError ());
4948
5036
CloseHandle (hFile);
4949
5037
return NULL ;
4950
5038
}
@@ -4976,10 +5064,9 @@ char* os::pd_map_memory(int fd, const char* file_name, size_t file_offset,
4976
5064
}
4977
5065
4978
5066
DWORD access = read_only ? FILE_MAP_READ : FILE_MAP_COPY;
4979
- base = (char *)MapViewOfFileEx (hMap, access, 0 , (DWORD)file_offset,
5067
+ base = (char *)mapViewOfFileEx (hMap, access, 0 , (DWORD)file_offset,
4980
5068
(DWORD)bytes, addr);
4981
5069
if (base == NULL ) {
4982
- log_info (os)(" MapViewOfFileEx() failed: GetLastError->%ld." , GetLastError ());
4983
5070
CloseHandle (hMap);
4984
5071
CloseHandle (hFile);
4985
5072
return NULL ;
@@ -5051,9 +5138,8 @@ bool os::pd_unmap_memory(char* addr, size_t bytes) {
5051
5138
return pd_release_memory (addr, bytes);
5052
5139
}
5053
5140
5054
- BOOL result = UnmapViewOfFile (addr);
5141
+ BOOL result = unmapViewOfFile (addr);
5055
5142
if (result == 0 ) {
5056
- log_info (os)(" UnmapViewOfFile() failed: GetLastError->%ld." , GetLastError ());
5057
5143
return false ;
5058
5144
}
5059
5145
return true ;
0 commit comments