@@ -351,6 +351,23 @@ TEST_VM(os, jio_snprintf) {
351
351
test_snprintf (jio_snprintf, false );
352
352
}
353
353
354
+ #ifdef __APPLE__
355
+ // Not all macOS versions can use os::reserve_memory (i.e. anon_mmap) API
356
+ // to reserve executable memory, so before attempting to use it,
357
+ // we need to verify that we can do so by asking for a tiny executable
358
+ // memory chunk.
359
+ static inline bool can_reserve_executable_memory (void ) {
360
+ bool executable = true ;
361
+ size_t len = 128 ;
362
+ char * p = os::reserve_memory (len, executable);
363
+ bool exec_supported = (p != NULL );
364
+ if (exec_supported) {
365
+ os::release_memory (p, len);
366
+ }
367
+ return exec_supported;
368
+ }
369
+ #endif
370
+
354
371
// Test that os::release_memory() can deal with areas containing multiple mappings.
355
372
#define PRINT_MAPPINGS (s ) { tty->print_cr (" %s" , s); os::print_memory_mappings ((char *)p, total_range_len, tty); }
356
373
// #define PRINT_MAPPINGS
@@ -360,6 +377,13 @@ TEST_VM(os, jio_snprintf) {
360
377
// (from multiple calls to os::reserve_memory)
361
378
static address reserve_multiple (int num_stripes, size_t stripe_len) {
362
379
assert (is_aligned (stripe_len, os::vm_allocation_granularity ()), " Sanity" );
380
+
381
+ #ifdef __APPLE__
382
+ // Workaround: try reserving executable memory to figure out
383
+ // if such operation is supported on this macOS version
384
+ const bool exec_supported = can_reserve_executable_memory ();
385
+ #endif
386
+
363
387
size_t total_range_len = num_stripes * stripe_len;
364
388
// Reserve a large contiguous area to get the address space...
365
389
address p = (address)os::reserve_memory (total_range_len);
@@ -371,7 +395,11 @@ static address reserve_multiple(int num_stripes, size_t stripe_len) {
371
395
address q = p + (stripe * stripe_len);
372
396
// Commit, alternatingly with or without exec permission,
373
397
// to prevent kernel from folding these mappings.
398
+ #ifdef __APPLE__
399
+ const bool executable = exec_supported ? (stripe % 2 == 0 ) : false ;
400
+ #else
374
401
const bool executable = stripe % 2 == 0 ;
402
+ #endif
375
403
q = (address)os::attempt_reserve_memory_at ((char *)q, stripe_len, executable);
376
404
EXPECT_NE (q, (address)NULL );
377
405
EXPECT_TRUE (os::commit_memory ((char *)q, stripe_len, executable));
@@ -413,11 +441,7 @@ struct NUMASwitcher {
413
441
#endif
414
442
415
443
#ifndef _AIX // JDK-8257041
416
- #if defined(__APPLE__) && !defined(AARCH64) // See JDK-8267341.
417
- TEST_VM (os, DISABLED_release_multi_mappings) {
418
- #else
419
444
TEST_VM (os, release_multi_mappings) {
420
- #endif
421
445
422
446
// With NMT enabled, this will trigger JDK-8263464. For now disable the test if NMT=on.
423
447
if (MemTracker::tracking_level () > NMT_off) {
0 commit comments