5969 } 5970 5971 #endif 5972 5973 #ifndef PRODUCT 5974 5975 // test the code path in reserve_memory_special() that tries to allocate memory in a single 5976 // contiguous memory block at a particular address. 5977 // The test first tries to find a good approximate address to allocate at by using the same 5978 // method to allocate some memory at any address. The test then tries to allocate memory in 5979 // the vicinity (not directly after it to avoid possible by-chance use of that location) 5980 // This is of course only some dodgy assumption, there is no guarantee that the vicinity of 5981 // the previously allocated memory is available for allocation. The only actual failure 5982 // that is reported is when the test tries to allocate at a particular location but gets a 5983 // different valid one. A NULL return value at this point is not considered an error but may 5984 // be legitimate. 5985 // If -XX:+VerboseInternalVMTests is enabled, print some explanatory messages. 5986 void TestReserveMemorySpecial_test() { 5987 if (!UseLargePages) { 5988 if (VerboseInternalVMTests) { 5989 gclog_or_tty->print("Skipping test because large pages are disabled"); 5990 } 5991 return; 5992 } 5993 // save current value of globals 5994 bool old_use_large_pages_individual_allocation = UseLargePagesIndividualAllocation; 5995 bool old_use_numa_interleaving = UseNUMAInterleaving; 5996 5997 // set globals to make sure we hit the correct code path 5998 UseLargePagesIndividualAllocation = UseNUMAInterleaving = false; 5999 6000 // do an allocation at an address selected by the OS to get a good one. 6001 const size_t large_allocation_size = os::large_page_size() * 4; 6002 char* result = os::reserve_memory_special(large_allocation_size, os::large_page_size(), NULL, false); 6003 if (result == NULL) { 6004 if (VerboseInternalVMTests) { 6005 gclog_or_tty->print("Failed to allocate control block with size " SIZE_FORMAT ". Skipping remainder of test.", 6006 large_allocation_size); 6007 } 6008 } else { 6009 os::release_memory_special(result, large_allocation_size); 6010 6011 // allocate another page within the recently allocated memory area which seems to be a good location. At least 6012 // we managed to get it once. 6013 const size_t expected_allocation_size = os::large_page_size(); 6014 char* expected_location = result + os::large_page_size(); 6015 char* actual_location = os::reserve_memory_special(expected_allocation_size, os::large_page_size(), expected_location, false); 6016 if (actual_location == NULL) { 6017 if (VerboseInternalVMTests) { 6018 gclog_or_tty->print("Failed to allocate any memory at " PTR_FORMAT " size " SIZE_FORMAT ". Skipping remainder of test.", 6019 expected_location, large_allocation_size); 6020 } 6021 } else { 6022 // release memory 6023 os::release_memory_special(actual_location, expected_allocation_size); 6024 // only now check, after releasing any memory to avoid any leaks. 6025 assert(actual_location == expected_location, 6026 "Failed to allocate memory at requested location " PTR_FORMAT " of size " SIZE_FORMAT ", is " PTR_FORMAT " instead", 6027 expected_location, expected_allocation_size, actual_location); 6028 } 6029 } 6030 6031 // restore globals 6032 UseLargePagesIndividualAllocation = old_use_large_pages_individual_allocation; 6033 UseNUMAInterleaving = old_use_numa_interleaving; 6034 } 6035 #endif // PRODUCT | 5969 } 5970 5971 #endif 5972 5973 #ifndef PRODUCT 5974 5975 // test the code path in reserve_memory_special() that tries to allocate memory in a single 5976 // contiguous memory block at a particular address. 5977 // The test first tries to find a good approximate address to allocate at by using the same 5978 // method to allocate some memory at any address. The test then tries to allocate memory in 5979 // the vicinity (not directly after it to avoid possible by-chance use of that location) 5980 // This is of course only some dodgy assumption, there is no guarantee that the vicinity of 5981 // the previously allocated memory is available for allocation. The only actual failure 5982 // that is reported is when the test tries to allocate at a particular location but gets a 5983 // different valid one. A NULL return value at this point is not considered an error but may 5984 // be legitimate. 5985 // If -XX:+VerboseInternalVMTests is enabled, print some explanatory messages. 5986 void TestReserveMemorySpecial_test() { 5987 if (!UseLargePages) { 5988 if (VerboseInternalVMTests) { 5989 tty->print("Skipping test because large pages are disabled"); 5990 } 5991 return; 5992 } 5993 // save current value of globals 5994 bool old_use_large_pages_individual_allocation = UseLargePagesIndividualAllocation; 5995 bool old_use_numa_interleaving = UseNUMAInterleaving; 5996 5997 // set globals to make sure we hit the correct code path 5998 UseLargePagesIndividualAllocation = UseNUMAInterleaving = false; 5999 6000 // do an allocation at an address selected by the OS to get a good one. 6001 const size_t large_allocation_size = os::large_page_size() * 4; 6002 char* result = os::reserve_memory_special(large_allocation_size, os::large_page_size(), NULL, false); 6003 if (result == NULL) { 6004 if (VerboseInternalVMTests) { 6005 tty->print("Failed to allocate control block with size " SIZE_FORMAT ". Skipping remainder of test.", 6006 large_allocation_size); 6007 } 6008 } else { 6009 os::release_memory_special(result, large_allocation_size); 6010 6011 // allocate another page within the recently allocated memory area which seems to be a good location. At least 6012 // we managed to get it once. 6013 const size_t expected_allocation_size = os::large_page_size(); 6014 char* expected_location = result + os::large_page_size(); 6015 char* actual_location = os::reserve_memory_special(expected_allocation_size, os::large_page_size(), expected_location, false); 6016 if (actual_location == NULL) { 6017 if (VerboseInternalVMTests) { 6018 tty->print("Failed to allocate any memory at " PTR_FORMAT " size " SIZE_FORMAT ". Skipping remainder of test.", 6019 expected_location, large_allocation_size); 6020 } 6021 } else { 6022 // release memory 6023 os::release_memory_special(actual_location, expected_allocation_size); 6024 // only now check, after releasing any memory to avoid any leaks. 6025 assert(actual_location == expected_location, 6026 "Failed to allocate memory at requested location " PTR_FORMAT " of size " SIZE_FORMAT ", is " PTR_FORMAT " instead", 6027 expected_location, expected_allocation_size, actual_location); 6028 } 6029 } 6030 6031 // restore globals 6032 UseLargePagesIndividualAllocation = old_use_large_pages_individual_allocation; 6033 UseNUMAInterleaving = old_use_numa_interleaving; 6034 } 6035 #endif // PRODUCT |