hotspot/src/os/windows/vm/os_windows.cpp
changeset 19981 6821d0a573c3
parent 19560 d44eb8cd7ecc
child 19986 33d188c66ed9
equal deleted inserted replaced
19979:ebe1dbb6e1aa 19981:6821d0a573c3
  3187     }
  3187     }
  3188 
  3188 
  3189     return p_buf;
  3189     return p_buf;
  3190 
  3190 
  3191   } else {
  3191   } else {
       
  3192     if (TracePageSizes && Verbose) {
       
  3193        tty->print_cr("Reserving large pages in a single large chunk.");
       
  3194     }
  3192     // normal policy just allocate it all at once
  3195     // normal policy just allocate it all at once
  3193     DWORD flag = MEM_RESERVE | MEM_COMMIT | MEM_LARGE_PAGES;
  3196     DWORD flag = MEM_RESERVE | MEM_COMMIT | MEM_LARGE_PAGES;
  3194     char * res = (char *)VirtualAlloc(NULL, bytes, flag, prot);
  3197     char * res = (char *)VirtualAlloc(addr, bytes, flag, prot);
  3195     if (res != NULL) {
  3198     if (res != NULL) {
  3196       address pc = CALLER_PC;
  3199       address pc = CALLER_PC;
  3197       MemTracker::record_virtual_memory_reserve_and_commit((address)res, bytes, mtNone, pc);
  3200       MemTracker::record_virtual_memory_reserve_and_commit((address)res, bytes, mtNone, pc);
  3198     }
  3201     }
  3199 
  3202 
  5712 }
  5715 }
  5713 
  5716 
  5714 #endif
  5717 #endif
  5715 
  5718 
  5716 #ifndef PRODUCT
  5719 #ifndef PRODUCT
       
  5720 
       
  5721 // test the code path in reserve_memory_special() that tries to allocate memory in a single
       
  5722 // contiguous memory block at a particular address.
       
  5723 // The test first tries to find a good approximate address to allocate at by using the same
       
  5724 // method to allocate some memory at any address. The test then tries to allocate memory in
       
  5725 // the vicinity (not directly after it to avoid possible by-chance use of that location)
       
  5726 // This is of course only some dodgy assumption, there is no guarantee that the vicinity of
       
  5727 // the previously allocated memory is available for allocation. The only actual failure
       
  5728 // that is reported is when the test tries to allocate at a particular location but gets a
       
  5729 // different valid one. A NULL return value at this point is not considered an error but may
       
  5730 // be legitimate.
       
  5731 // If -XX:+VerboseInternalVMTests is enabled, print some explanatory messages.
  5717 void TestReserveMemorySpecial_test() {
  5732 void TestReserveMemorySpecial_test() {
  5718   // No tests available for this platform
  5733   if (!UseLargePages) {
  5719 }
  5734     if (VerboseInternalVMTests) {
  5720 #endif
  5735       gclog_or_tty->print("Skipping test because large pages are disabled");
       
  5736     }
       
  5737     return;
       
  5738   }
       
  5739   // save current value of globals
       
  5740   bool old_use_large_pages_individual_allocation = UseLargePagesIndividualAllocation;
       
  5741   bool old_use_numa_interleaving = UseNUMAInterleaving;
       
  5742 
       
  5743   // set globals to make sure we hit the correct code path
       
  5744   UseLargePagesIndividualAllocation = UseNUMAInterleaving = false;
       
  5745 
       
  5746   // do an allocation at an address selected by the OS to get a good one.
       
  5747   const size_t large_allocation_size = os::large_page_size() * 4;
       
  5748   char* result = os::reserve_memory_special(large_allocation_size, os::large_page_size(), NULL, false);
       
  5749   if (result == NULL) {
       
  5750     if (VerboseInternalVMTests) {
       
  5751       gclog_or_tty->print("Failed to allocate control block with size "SIZE_FORMAT". Skipping remainder of test.",
       
  5752         large_allocation_size);
       
  5753     }
       
  5754   } else {
       
  5755     os::release_memory_special(result, large_allocation_size);
       
  5756 
       
  5757     // allocate another page within the recently allocated memory area which seems to be a good location. At least
       
  5758     // we managed to get it once.
       
  5759     const size_t expected_allocation_size = os::large_page_size();
       
  5760     char* expected_location = result + os::large_page_size();
       
  5761     char* actual_location = os::reserve_memory_special(expected_allocation_size, os::large_page_size(), expected_location, false);
       
  5762     if (actual_location == NULL) {
       
  5763       if (VerboseInternalVMTests) {
       
  5764         gclog_or_tty->print("Failed to allocate any memory at "PTR_FORMAT" size "SIZE_FORMAT". Skipping remainder of test.",
       
  5765           expected_location, large_allocation_size);
       
  5766       }
       
  5767     } else {
       
  5768       // release memory
       
  5769       os::release_memory_special(actual_location, expected_allocation_size);
       
  5770       // only now check, after releasing any memory to avoid any leaks.
       
  5771       assert(actual_location == expected_location,
       
  5772         err_msg("Failed to allocate memory at requested location "PTR_FORMAT" of size "SIZE_FORMAT", is "PTR_FORMAT" instead",
       
  5773           expected_location, expected_allocation_size, actual_location));
       
  5774     }
       
  5775   }
       
  5776 
       
  5777   // restore globals
       
  5778   UseLargePagesIndividualAllocation = old_use_large_pages_individual_allocation;
       
  5779   UseNUMAInterleaving = old_use_numa_interleaving;
       
  5780 }
       
  5781 #endif // PRODUCT
       
  5782