3172 if (UseLargePagesIndividualAllocation || UseNUMAInterleaving) {
3173 if (TracePageSizes && Verbose) {
3174 tty->print_cr("Reserving large pages individually.");
3175 }
3176 char * p_buf = allocate_pages_individually(bytes, addr, flags, prot, LargePagesIndividualAllocationInjectError);
3177 if (p_buf == NULL) {
3178 // give an appropriate warning message
3179 if (UseNUMAInterleaving) {
3180 warning("NUMA large page allocation failed, UseLargePages flag ignored");
3181 }
3182 if (UseLargePagesIndividualAllocation) {
3183 warning("Individually allocated large pages failed, "
3184 "use -XX:-UseLargePagesIndividualAllocation to turn off");
3185 }
3186 return NULL;
3187 }
3188
3189 return p_buf;
3190
3191 } else {
3192 // normal policy just allocate it all at once
3193 DWORD flag = MEM_RESERVE | MEM_COMMIT | MEM_LARGE_PAGES;
3194 char * res = (char *)VirtualAlloc(NULL, bytes, flag, prot);
3195 if (res != NULL) {
3196 address pc = CALLER_PC;
3197 MemTracker::record_virtual_memory_reserve_and_commit((address)res, bytes, mtNone, pc);
3198 }
3199
3200 return res;
3201 }
3202 }
3203
3204 bool os::release_memory_special(char* base, size_t bytes) {
3205 assert(base != NULL, "Sanity check");
3206 return release_memory(base, bytes);
3207 }
3208
3209 void os::print_statistics() {
3210 }
3211
3212 static void warn_fail_commit_memory(char* addr, size_t bytes, bool exec) {
3213 int err = os::get_last_error();
3214 char buf[256];
5628 }
5629
5630 BOOL os::Advapi32Dll::LookupPrivilegeValue(LPCTSTR lpSystemName, LPCTSTR lpName, PLUID lpLuid) {
5631 assert(initialized && _LookupPrivilegeValue != NULL,
5632 "AdvapiAvailable() not yet called");
5633 return _LookupPrivilegeValue(lpSystemName, lpName, lpLuid);
5634 }
5635
5636 BOOL os::Advapi32Dll::AdvapiAvailable() {
5637 if (!initialized) {
5638 initialize();
5639 }
5640 return _AdjustTokenPrivileges != NULL &&
5641 _OpenProcessToken != NULL &&
5642 _LookupPrivilegeValue != NULL;
5643 }
5644
5645 #endif
5646
5647 #ifndef PRODUCT
5648 void TestReserveMemorySpecial_test() {
5649 // No tests available for this platform
5650 }
5651 #endif
|
3172 if (UseLargePagesIndividualAllocation || UseNUMAInterleaving) {
3173 if (TracePageSizes && Verbose) {
3174 tty->print_cr("Reserving large pages individually.");
3175 }
3176 char * p_buf = allocate_pages_individually(bytes, addr, flags, prot, LargePagesIndividualAllocationInjectError);
3177 if (p_buf == NULL) {
3178 // give an appropriate warning message
3179 if (UseNUMAInterleaving) {
3180 warning("NUMA large page allocation failed, UseLargePages flag ignored");
3181 }
3182 if (UseLargePagesIndividualAllocation) {
3183 warning("Individually allocated large pages failed, "
3184 "use -XX:-UseLargePagesIndividualAllocation to turn off");
3185 }
3186 return NULL;
3187 }
3188
3189 return p_buf;
3190
3191 } else {
3192 if (TracePageSizes && Verbose) {
3193 tty->print_cr("Reserving large pages in a single large chunk.");
3194 }
3195 // normal policy just allocate it all at once
3196 DWORD flag = MEM_RESERVE | MEM_COMMIT | MEM_LARGE_PAGES;
3197 char * res = (char *)VirtualAlloc(addr, bytes, flag, prot);
3198 if (res != NULL) {
3199 address pc = CALLER_PC;
3200 MemTracker::record_virtual_memory_reserve_and_commit((address)res, bytes, mtNone, pc);
3201 }
3202
3203 return res;
3204 }
3205 }
3206
3207 bool os::release_memory_special(char* base, size_t bytes) {
3208 assert(base != NULL, "Sanity check");
3209 return release_memory(base, bytes);
3210 }
3211
3212 void os::print_statistics() {
3213 }
3214
3215 static void warn_fail_commit_memory(char* addr, size_t bytes, bool exec) {
3216 int err = os::get_last_error();
3217 char buf[256];
5631 }
5632
5633 BOOL os::Advapi32Dll::LookupPrivilegeValue(LPCTSTR lpSystemName, LPCTSTR lpName, PLUID lpLuid) {
5634 assert(initialized && _LookupPrivilegeValue != NULL,
5635 "AdvapiAvailable() not yet called");
5636 return _LookupPrivilegeValue(lpSystemName, lpName, lpLuid);
5637 }
5638
5639 BOOL os::Advapi32Dll::AdvapiAvailable() {
5640 if (!initialized) {
5641 initialize();
5642 }
5643 return _AdjustTokenPrivileges != NULL &&
5644 _OpenProcessToken != NULL &&
5645 _LookupPrivilegeValue != NULL;
5646 }
5647
5648 #endif
5649
5650 #ifndef PRODUCT
5651
5652 // test the code path in reserve_memory_special() that tries to allocate memory in a single
5653 // contiguous memory block at a particular address.
5654 // The test first tries to find a good approximate address to allocate at by using the same
5655 // method to allocate some memory at any address. The test then tries to allocate memory in
5656 // the vicinity (not directly after it to avoid possible by-chance use of that location)
5657 // This is of course only some dodgy assumption, there is no guarantee that the vicinity of
5658 // the previously allocated memory is available for allocation. The only actual failure
5659 // that is reported is when the test tries to allocate at a particular location but gets a
5660 // different valid one. A NULL return value at this point is not considered an error but may
5661 // be legitimate.
5662 // If -XX:+Verbose is enabled, print some explanatory messages.
5663 void TestReserveMemorySpecial_test() {
5664 if (!UseLargePages) {
5665 if (VerboseInternalVMTests) {
5666 gclog_or_tty->print("Skipping test because large pages are disabled");
5667 }
5668 return;
5669 }
5670 // save current value of globals
5671 bool old_use_large_pages_individual_allocation = UseLargePagesIndividualAllocation;
5672 bool old_use_numa_interleaving = UseNUMAInterleaving;
5673
5674 // set globals to make sure we hit the correct code path
5675 UseLargePagesIndividualAllocation = UseNUMAInterleaving = false;
5676
5677 // do an allocation at an address selected by the OS to get a good one.
5678 const size_t large_allocation_size = os::large_page_size() * 4;
5679 char* result = os::reserve_memory_special(large_allocation_size, os::large_page_size(), NULL, false);
5680 if (result == NULL) {
5681 if (VerboseInternalVMTests) {
5682 gclog_or_tty->print("Failed to allocate control block with size "SIZE_FORMAT". Skipping remainder of test.",
5683 large_allocation_size);
5684 }
5685 } else {
5686 os::release_memory_special(result, large_allocation_size);
5687
5688 // allocate another page within the recently allocated memory area which seems to be a good location. At least
5689 // we managed to get it once.
5690 const size_t expected_allocation_size = os::large_page_size();
5691 char* expected_location = result + os::large_page_size();
5692 char* actual_location = os::reserve_memory_special(expected_allocation_size, os::large_page_size(), expected_location, false);
5693 if (actual_location == NULL) {
5694 if (VerboseInternalVMTests) {
5695 gclog_or_tty->print("Failed to allocate any memory at "PTR_FORMAT" size "SIZE_FORMAT". Skipping remainder of test.",
5696 expected_location, large_allocation_size);
5697 }
5698 } else {
5699 // release memory
5700 os::release_memory_special(actual_location, expected_allocation_size);
5701 // only now check, after releasing any memory to avoid any leaks.
5702 assert(actual_location == expected_location,
5703 err_msg("Failed to allocate memory at requested location "PTR_FORMAT" of size "SIZE_FORMAT", is "PTR_FORMAT" instead",
5704 expected_location, expected_allocation_size, actual_location));
5705 }
5706 }
5707
5708 // restore globals
5709 UseLargePagesIndividualAllocation = old_use_large_pages_individual_allocation;
5710 UseNUMAInterleaving = old_use_numa_interleaving;
5711 }
5712 #endif // PRODUCT
|