< prev index next >

src/hotspot/share/memory/virtualspace.cpp

Print this page

  96   if (base == requested_address || requested_address == NULL)
  97     return false; // did not fail
  98 
  99   if (base != NULL) {
 100     // Different reserve address may be acceptable in other cases
 101     // but for compressed oops heap should be at requested address.
 102     assert(UseCompressedOops, "currently requested address used only for compressed oops");
 103     log_debug(gc, heap, coops)("Reserved memory not at requested address: " PTR_FORMAT " vs " PTR_FORMAT, p2i(base), p2i(requested_address));
 104     // OS ignored requested address. Try different address.
 105     if (special) {
 106       if (!os::release_memory_special(base, size)) {
 107         fatal("os::release_memory_special failed");
 108       }
 109     } else {
 110       unmap_or_release_memory(base, size, is_file_mapped);
 111     }
 112   }
 113   return true;
 114 }
 115 





















 116 void ReservedSpace::initialize(size_t size, size_t alignment, bool large,
 117                                char* requested_address,
 118                                bool executable) {
 119   const size_t granularity = os::vm_allocation_granularity();
 120   assert((size & (granularity - 1)) == 0,
 121          "size not aligned to os::vm_allocation_granularity()");
 122   assert((alignment & (granularity - 1)) == 0,
 123          "alignment not aligned to os::vm_allocation_granularity()");
 124   assert(alignment == 0 || is_power_of_2((intptr_t)alignment),
 125          "not a power of 2");
 126 
 127   alignment = MAX2(alignment, (size_t)os::vm_page_size());
 128 
 129   _base = NULL;
 130   _size = 0;
 131   _special = false;
 132   _executable = executable;
 133   _alignment = 0;
 134   _noaccess_prefix = 0;
 135   if (size == 0) {
 136     return;
 137   }
 138 
 139   // If OS doesn't support demand paging for large page memory, we need
 140   // to use reserve_memory_special() to reserve and pin the entire region.
 141   // If there is a backing file directory for this space then whether
 142   // large pages are allocated is up to the filesystem of the backing file.
 143   // So we ignore the UseLargePages flag in this case.
 144   bool special = large && !os::can_commit_large_page_memory();
 145   if (special && _fd_for_heap != -1) {
 146     special = false;
 147     if (UseLargePages && (!FLAG_IS_DEFAULT(UseLargePages) ||
 148       !FLAG_IS_DEFAULT(LargePageSizeInBytes))) {
 149       log_debug(gc, heap)("Ignoring UseLargePages since large page support is up to the file system of the backing file for Java heap");
 150     }
 151   }
 152 
 153   char* base = NULL;
 154 
 155   if (special) {
 156 
 157     base = os::reserve_memory_special(size, alignment, requested_address, executable);
 158 
 159     if (base != NULL) {
 160       if (failed_to_reserve_as_requested(base, requested_address, size, true)) {
 161         // OS ignored requested address. Try different address.
 162         return;
 163       }
 164       // Check alignment constraints.
 165       assert((uintptr_t) base % alignment == 0,
 166              "Large pages returned a non-aligned address, base: "
 167              PTR_FORMAT " alignment: " SIZE_FORMAT_HEX,
 168              p2i(base), alignment);
 169       _special = true;
 170     } else {
 171       // failed; try to reserve regular memory below

 312 
 313   _base += _noaccess_prefix;
 314   _size -= _noaccess_prefix;
 315   assert(((uintptr_t)_base % _alignment == 0), "must be exactly of required alignment");
 316 }
 317 
 318 // Tries to allocate memory of size 'size' at address requested_address with alignment 'alignment'.
 319 // Does not check whether the reserved memory actually is at requested_address, as the memory returned
 320 // might still fulfill the wishes of the caller.
 321 // Assures the memory is aligned to 'alignment'.
 322 // NOTE: If ReservedHeapSpace already points to some reserved memory this is freed, first.
 323 void ReservedHeapSpace::try_reserve_heap(size_t size,
 324                                          size_t alignment,
 325                                          bool large,
 326                                          char* requested_address) {
 327   if (_base != NULL) {
 328     // We tried before, but we didn't like the address delivered.
 329     release();
 330   }
 331 
 332   // If OS doesn't support demand paging for large page memory, we need
 333   // to use reserve_memory_special() to reserve and pin the entire region.
 334   // If there is a backing file directory for this space then whether
 335   // large pages are allocated is up to the filesystem of the backing file.
 336   // So we ignore the UseLargePages flag in this case.
 337   bool special = large && !os::can_commit_large_page_memory();
 338   if (special && _fd_for_heap != -1) {
 339     special = false;
 340     if (UseLargePages && (!FLAG_IS_DEFAULT(UseLargePages) ||
 341                           !FLAG_IS_DEFAULT(LargePageSizeInBytes))) {
 342       log_debug(gc, heap)("Cannot allocate large pages for Java Heap when AllocateHeapAt option is set.");
 343     }
 344   }
 345   char* base = NULL;
 346 
 347   log_trace(gc, heap, coops)("Trying to allocate at address " PTR_FORMAT
 348                              " heap of size " SIZE_FORMAT_HEX,
 349                              p2i(requested_address),
 350                              size);
 351 
 352   if (special) {
 353     base = os::reserve_memory_special(size, alignment, requested_address, false);
 354 
 355     if (base != NULL) {
 356       // Check alignment constraints.
 357       assert((uintptr_t) base % alignment == 0,
 358              "Large pages returned a non-aligned address, base: "
 359              PTR_FORMAT " alignment: " SIZE_FORMAT_HEX,
 360              p2i(base), alignment);
 361       _special = true;
 362     }
 363   }
 364 

  96   if (base == requested_address || requested_address == NULL)
  97     return false; // did not fail
  98 
  99   if (base != NULL) {
 100     // Different reserve address may be acceptable in other cases
 101     // but for compressed oops heap should be at requested address.
 102     assert(UseCompressedOops, "currently requested address used only for compressed oops");
 103     log_debug(gc, heap, coops)("Reserved memory not at requested address: " PTR_FORMAT " vs " PTR_FORMAT, p2i(base), p2i(requested_address));
 104     // OS ignored requested address. Try different address.
 105     if (special) {
 106       if (!os::release_memory_special(base, size)) {
 107         fatal("os::release_memory_special failed");
 108       }
 109     } else {
 110       unmap_or_release_memory(base, size, is_file_mapped);
 111     }
 112   }
 113   return true;
 114 }
 115 
 116 // Helper method.
 117 static bool should_use_reserve_memory_special(bool large, 
 118                                               int fd_for_heap, 
 119                                               const char* fallback_log_message)
 120 {
 121   // If OS doesn't support demand paging for large page memory, we need
 122   // to use reserve_memory_special() to reserve and pin the entire region.
 123   // If there is a backing file directory for this space then whether
 124   // large pages are allocated is up to the filesystem of the backing file.
 125   // So we ignore the UseLargePages flag in this case.
 126   bool special = large && !os::can_commit_large_page_memory();
 127   if (special && fd_for_heap != -1) {
 128     special = false;
 129     if (UseLargePages && (!FLAG_IS_DEFAULT(UseLargePages) ||
 130                           !FLAG_IS_DEFAULT(LargePageSizeInBytes))) {
 131       log_debug(gc, heap)("%s", fallback_log_message);
 132     }
 133   }
 134   return special;
 135 }
 136 
 137 void ReservedSpace::initialize(size_t size, size_t alignment, bool large,
 138                                char* requested_address,
 139                                bool executable) {
 140   const size_t granularity = os::vm_allocation_granularity();
 141   assert((size & (granularity - 1)) == 0,
 142          "size not aligned to os::vm_allocation_granularity()");
 143   assert((alignment & (granularity - 1)) == 0,
 144          "alignment not aligned to os::vm_allocation_granularity()");
 145   assert(alignment == 0 || is_power_of_2((intptr_t)alignment),
 146          "not a power of 2");
 147 
 148   alignment = MAX2(alignment, (size_t)os::vm_page_size());
 149 
 150   _base = NULL;
 151   _size = 0;
 152   _special = false;
 153   _executable = executable;
 154   _alignment = 0;
 155   _noaccess_prefix = 0;
 156   if (size == 0) {
 157     return;
 158   }
 159 
 160   bool special = should_use_reserve_memory_special(large, _fd_for_heap, 
 161                                                    "Ignoring UseLargePages since large page "
 162                                                    "support is up to the file system of the "
 163                                                    "backing file for Java heap");









 164 
 165   char* base = NULL;
 166 
 167   if (special) {
 168 
 169     base = os::reserve_memory_special(size, alignment, requested_address, executable);
 170 
 171     if (base != NULL) {
 172       if (failed_to_reserve_as_requested(base, requested_address, size, true)) {
 173         // OS ignored requested address. Try different address.
 174         return;
 175       }
 176       // Check alignment constraints.
 177       assert((uintptr_t) base % alignment == 0,
 178              "Large pages returned a non-aligned address, base: "
 179              PTR_FORMAT " alignment: " SIZE_FORMAT_HEX,
 180              p2i(base), alignment);
 181       _special = true;
 182     } else {
 183       // failed; try to reserve regular memory below

 324 
 325   _base += _noaccess_prefix;
 326   _size -= _noaccess_prefix;
 327   assert(((uintptr_t)_base % _alignment == 0), "must be exactly of required alignment");
 328 }
 329 
 330 // Tries to allocate memory of size 'size' at address requested_address with alignment 'alignment'.
 331 // Does not check whether the reserved memory actually is at requested_address, as the memory returned
 332 // might still fulfill the wishes of the caller.
 333 // Assures the memory is aligned to 'alignment'.
 334 // NOTE: If ReservedHeapSpace already points to some reserved memory this is freed, first.
 335 void ReservedHeapSpace::try_reserve_heap(size_t size,
 336                                          size_t alignment,
 337                                          bool large,
 338                                          char* requested_address) {
 339   if (_base != NULL) {
 340     // We tried before, but we didn't like the address delivered.
 341     release();
 342   }
 343 
 344   bool special = should_use_reserve_memory_special(large, _fd_for_heap, 
 345                                                    "Cannot allocate large pages for Java Heap "
 346                                                    "when AllocateHeapAt option is set.");










 347   char* base = NULL;
 348 
 349   log_trace(gc, heap, coops)("Trying to allocate at address " PTR_FORMAT
 350                              " heap of size " SIZE_FORMAT_HEX,
 351                              p2i(requested_address),
 352                              size);
 353 
 354   if (special) {
 355     base = os::reserve_memory_special(size, alignment, requested_address, false);
 356 
 357     if (base != NULL) {
 358       // Check alignment constraints.
 359       assert((uintptr_t) base % alignment == 0,
 360              "Large pages returned a non-aligned address, base: "
 361              PTR_FORMAT " alignment: " SIZE_FORMAT_HEX,
 362              p2i(base), alignment);
 363       _special = true;
 364     }
 365   }
 366 
< prev index next >