5937 } 5938 5939 #endif 5940 5941 #ifndef PRODUCT 5942 5943 // test the code path in reserve_memory_special() that tries to allocate memory in a single 5944 // contiguous memory block at a particular address. 5945 // The test first tries to find a good approximate address to allocate at by using the same 5946 // method to allocate some memory at any address. The test then tries to allocate memory in 5947 // the vicinity (not directly after it to avoid possible by-chance use of that location) 5948 // This is of course only some dodgy assumption, there is no guarantee that the vicinity of 5949 // the previously allocated memory is available for allocation. The only actual failure 5950 // that is reported is when the test tries to allocate at a particular location but gets a 5951 // different valid one. A NULL return value at this point is not considered an error but may 5952 // be legitimate. 5953 // If -XX:+VerboseInternalVMTests is enabled, print some explanatory messages. 5954 void TestReserveMemorySpecial_test() { 5955 if (!UseLargePages) { 5956 if (VerboseInternalVMTests) { 5957 gclog_or_tty->print("Skipping test because large pages are disabled"); 5958 } 5959 return; 5960 } 5961 // save current value of globals 5962 bool old_use_large_pages_individual_allocation = UseLargePagesIndividualAllocation; 5963 bool old_use_numa_interleaving = UseNUMAInterleaving; 5964 5965 // set globals to make sure we hit the correct code path 5966 UseLargePagesIndividualAllocation = UseNUMAInterleaving = false; 5967 5968 // do an allocation at an address selected by the OS to get a good one. 5969 const size_t large_allocation_size = os::large_page_size() * 4; 5970 char* result = os::reserve_memory_special(large_allocation_size, os::large_page_size(), NULL, false); 5971 if (result == NULL) { 5972 if (VerboseInternalVMTests) { 5973 gclog_or_tty->print("Failed to allocate control block with size " SIZE_FORMAT ". Skipping remainder of test.", 5974 large_allocation_size); 5975 } 5976 } else { 5977 os::release_memory_special(result, large_allocation_size); 5978 5979 // allocate another page within the recently allocated memory area which seems to be a good location. At least 5980 // we managed to get it once. 5981 const size_t expected_allocation_size = os::large_page_size(); 5982 char* expected_location = result + os::large_page_size(); 5983 char* actual_location = os::reserve_memory_special(expected_allocation_size, os::large_page_size(), expected_location, false); 5984 if (actual_location == NULL) { 5985 if (VerboseInternalVMTests) { 5986 gclog_or_tty->print("Failed to allocate any memory at " PTR_FORMAT " size " SIZE_FORMAT ". Skipping remainder of test.", 5987 expected_location, large_allocation_size); 5988 } 5989 } else { 5990 // release memory 5991 os::release_memory_special(actual_location, expected_allocation_size); 5992 // only now check, after releasing any memory to avoid any leaks. 5993 assert(actual_location == expected_location, 5994 "Failed to allocate memory at requested location " PTR_FORMAT " of size " SIZE_FORMAT ", is " PTR_FORMAT " instead", 5995 expected_location, expected_allocation_size, actual_location); 5996 } 5997 } 5998 5999 // restore globals 6000 UseLargePagesIndividualAllocation = old_use_large_pages_individual_allocation; 6001 UseNUMAInterleaving = old_use_numa_interleaving; 6002 } 6003 #endif // PRODUCT | 5937 } 5938 5939 #endif 5940 5941 #ifndef PRODUCT 5942 5943 // test the code path in reserve_memory_special() that tries to allocate memory in a single 5944 // contiguous memory block at a particular address. 5945 // The test first tries to find a good approximate address to allocate at by using the same 5946 // method to allocate some memory at any address. The test then tries to allocate memory in 5947 // the vicinity (not directly after it to avoid possible by-chance use of that location) 5948 // This is of course only some dodgy assumption, there is no guarantee that the vicinity of 5949 // the previously allocated memory is available for allocation. The only actual failure 5950 // that is reported is when the test tries to allocate at a particular location but gets a 5951 // different valid one. A NULL return value at this point is not considered an error but may 5952 // be legitimate. 5953 // If -XX:+VerboseInternalVMTests is enabled, print some explanatory messages. 5954 void TestReserveMemorySpecial_test() { 5955 if (!UseLargePages) { 5956 if (VerboseInternalVMTests) { 5957 tty->print("Skipping test because large pages are disabled"); 5958 } 5959 return; 5960 } 5961 // save current value of globals 5962 bool old_use_large_pages_individual_allocation = UseLargePagesIndividualAllocation; 5963 bool old_use_numa_interleaving = UseNUMAInterleaving; 5964 5965 // set globals to make sure we hit the correct code path 5966 UseLargePagesIndividualAllocation = UseNUMAInterleaving = false; 5967 5968 // do an allocation at an address selected by the OS to get a good one. 5969 const size_t large_allocation_size = os::large_page_size() * 4; 5970 char* result = os::reserve_memory_special(large_allocation_size, os::large_page_size(), NULL, false); 5971 if (result == NULL) { 5972 if (VerboseInternalVMTests) { 5973 tty->print("Failed to allocate control block with size " SIZE_FORMAT ". Skipping remainder of test.", 5974 large_allocation_size); 5975 } 5976 } else { 5977 os::release_memory_special(result, large_allocation_size); 5978 5979 // allocate another page within the recently allocated memory area which seems to be a good location. At least 5980 // we managed to get it once. 5981 const size_t expected_allocation_size = os::large_page_size(); 5982 char* expected_location = result + os::large_page_size(); 5983 char* actual_location = os::reserve_memory_special(expected_allocation_size, os::large_page_size(), expected_location, false); 5984 if (actual_location == NULL) { 5985 if (VerboseInternalVMTests) { 5986 tty->print("Failed to allocate any memory at " PTR_FORMAT " size " SIZE_FORMAT ". Skipping remainder of test.", 5987 expected_location, large_allocation_size); 5988 } 5989 } else { 5990 // release memory 5991 os::release_memory_special(actual_location, expected_allocation_size); 5992 // only now check, after releasing any memory to avoid any leaks. 5993 assert(actual_location == expected_location, 5994 "Failed to allocate memory at requested location " PTR_FORMAT " of size " SIZE_FORMAT ", is " PTR_FORMAT " instead", 5995 expected_location, expected_allocation_size, actual_location); 5996 } 5997 } 5998 5999 // restore globals 6000 UseLargePagesIndividualAllocation = old_use_large_pages_individual_allocation; 6001 UseNUMAInterleaving = old_use_numa_interleaving; 6002 } 6003 #endif // PRODUCT |