src/share/vm/runtime/virtualspace.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hsx-rt.8007074 Sdiff src/share/vm/runtime

src/share/vm/runtime/virtualspace.cpp

Print this page




  25 #include "precompiled.hpp"
  26 #include "oops/markOop.hpp"
  27 #include "oops/oop.inline.hpp"
  28 #include "runtime/virtualspace.hpp"
  29 #include "services/memTracker.hpp"
  30 #ifdef TARGET_OS_FAMILY_linux
  31 # include "os_linux.inline.hpp"
  32 #endif
  33 #ifdef TARGET_OS_FAMILY_solaris
  34 # include "os_solaris.inline.hpp"
  35 #endif
  36 #ifdef TARGET_OS_FAMILY_windows
  37 # include "os_windows.inline.hpp"
  38 #endif
  39 #ifdef TARGET_OS_FAMILY_bsd
  40 # include "os_bsd.inline.hpp"
  41 #endif
  42 
  43 
  44 // ReservedSpace






  45 ReservedSpace::ReservedSpace(size_t size) {
  46   initialize(size, 0, false, NULL, 0, false);





  47 }
  48 
  49 ReservedSpace::ReservedSpace(size_t size, size_t alignment,
  50                              bool large,
  51                              char* requested_address,
  52                              const size_t noaccess_prefix) {
  53   initialize(size+noaccess_prefix, alignment, large, requested_address,
  54              noaccess_prefix, false);
  55 }
  56 
  57 ReservedSpace::ReservedSpace(size_t size, size_t alignment,
  58                              bool large,
  59                              bool executable) {
  60   initialize(size, alignment, large, NULL, 0, executable);
  61 }
  62 
  63 // Helper method.
  64 static bool failed_to_reserve_as_requested(char* base, char* requested_address,
  65                                            const size_t size, bool special)
  66 {


 112   _special = false;
 113   _executable = executable;
 114   _alignment = 0;
 115   _noaccess_prefix = 0;
 116   if (size == 0) {
 117     return;
 118   }
 119 
 120   // If OS doesn't support demand paging for large page memory, we need
 121   // to use reserve_memory_special() to reserve and pin the entire region.
 122   bool special = large && !os::can_commit_large_page_memory();
 123   char* base = NULL;
 124 
 125   if (requested_address != 0) {
 126     requested_address -= noaccess_prefix; // adjust requested address
 127     assert(requested_address != NULL, "huge noaccess prefix?");
 128   }
 129 
 130   if (special) {
 131 
 132     base = os::reserve_memory_special(size, requested_address, executable);
 133 
 134     if (base != NULL) {
 135       if (failed_to_reserve_as_requested(base, requested_address, size, true)) {
 136         // OS ignored requested address. Try different address.
 137         return;
 138       }
 139       // Check alignment constraints
 140       assert((uintptr_t) base % alignment == 0,
 141              "Large pages returned a non-aligned address");


 142       _special = true;
 143     } else {
 144       // failed; try to reserve regular memory below
 145       if (UseLargePages && (!FLAG_IS_DEFAULT(UseLargePages) ||
 146                             !FLAG_IS_DEFAULT(LargePageSizeInBytes))) {
 147         if (PrintCompressedOopsMode) {
 148           tty->cr();
 149           tty->print_cr("Reserve regular memory without large pages.");
 150         }
 151       }
 152     }
 153   }
 154 
 155   if (base == NULL) {
 156     // Optimistically assume that the OSes returns an aligned base pointer.
 157     // When reserving a large address range, most OSes seem to align to at
 158     // least 64K.
 159 
 160     // If the memory was requested at a particular address, use
 161     // os::attempt_reserve_memory_at() to avoid over mapping something


 697          middle_high() <= middle_high_boundary(),
 698          "high address must be contained within the region");
 699   assert(middle_high_boundary() <= upper_high() &&
 700          upper_high() <= upper_high_boundary(),
 701          "high address must be contained within the region");
 702   assert(low() >= low_boundary(), "low");
 703   assert(low_boundary() <= lower_high_boundary(), "lower high boundary");
 704   assert(upper_high_boundary() <= high_boundary(), "upper high boundary");
 705   assert(high() <= upper_high(), "upper high");
 706 }
 707 
 708 void VirtualSpace::print() {
 709   tty->print   ("Virtual space:");
 710   if (special()) tty->print(" (pinned in memory)");
 711   tty->cr();
 712   tty->print_cr(" - committed: " SIZE_FORMAT, committed_size());
 713   tty->print_cr(" - reserved:  " SIZE_FORMAT, reserved_size());
 714   tty->print_cr(" - [low, high]:     [" INTPTR_FORMAT ", " INTPTR_FORMAT "]",  low(), high());
 715   tty->print_cr(" - [low_b, high_b]: [" INTPTR_FORMAT ", " INTPTR_FORMAT "]",  low_boundary(), high_boundary());
 716 }
























































































































































































 717 
 718 #endif


  25 #include "precompiled.hpp"
  26 #include "oops/markOop.hpp"
  27 #include "oops/oop.inline.hpp"
  28 #include "runtime/virtualspace.hpp"
  29 #include "services/memTracker.hpp"
  30 #ifdef TARGET_OS_FAMILY_linux
  31 # include "os_linux.inline.hpp"
  32 #endif
  33 #ifdef TARGET_OS_FAMILY_solaris
  34 # include "os_solaris.inline.hpp"
  35 #endif
  36 #ifdef TARGET_OS_FAMILY_windows
  37 # include "os_windows.inline.hpp"
  38 #endif
  39 #ifdef TARGET_OS_FAMILY_bsd
  40 # include "os_bsd.inline.hpp"
  41 #endif
  42 
  43 
  44 // ReservedSpace
  45 
  46 // Dummy constructor
  47 ReservedSpace::ReservedSpace() : _base(NULL), _size(0), _noaccess_prefix(0),
  48     _alignment(0), _special(false), _executable(false) {
  49 }
  50 
  51 ReservedSpace::ReservedSpace(size_t size) {
  52   size_t page_size = os::page_size_for_region(size, size, 1);
  53   bool large_pages = page_size != (size_t)os::vm_page_size();
  54   // Don't force the alignment to be large page aligned,
  55   // since that will waste memory.
  56   size_t alignment = os::vm_allocation_granularity();
  57   initialize(size, alignment, large_pages, NULL, 0, false);
  58 }
  59 
  60 ReservedSpace::ReservedSpace(size_t size, size_t alignment,
  61                              bool large,
  62                              char* requested_address,
  63                              const size_t noaccess_prefix) {
  64   initialize(size+noaccess_prefix, alignment, large, requested_address,
  65              noaccess_prefix, false);
  66 }
  67 
  68 ReservedSpace::ReservedSpace(size_t size, size_t alignment,
  69                              bool large,
  70                              bool executable) {
  71   initialize(size, alignment, large, NULL, 0, executable);
  72 }
  73 
  74 // Helper method.
  75 static bool failed_to_reserve_as_requested(char* base, char* requested_address,
  76                                            const size_t size, bool special)
  77 {


 123   _special = false;
 124   _executable = executable;
 125   _alignment = 0;
 126   _noaccess_prefix = 0;
 127   if (size == 0) {
 128     return;
 129   }
 130 
 131   // If OS doesn't support demand paging for large page memory, we need
 132   // to use reserve_memory_special() to reserve and pin the entire region.
 133   bool special = large && !os::can_commit_large_page_memory();
 134   char* base = NULL;
 135 
 136   if (requested_address != 0) {
 137     requested_address -= noaccess_prefix; // adjust requested address
 138     assert(requested_address != NULL, "huge noaccess prefix?");
 139   }
 140 
 141   if (special) {
 142 
 143     base = os::reserve_memory_special(size, alignment, requested_address, executable);
 144 
 145     if (base != NULL) {
 146       if (failed_to_reserve_as_requested(base, requested_address, size, true)) {
 147         // OS ignored requested address. Try different address.
 148         return;
 149       }
 150       // Check alignment constraints.
 151       assert((uintptr_t) base % alignment == 0,
 152              err_msg("Large pages returned a non-aligned address, base: "
 153                  PTR_FORMAT " alignment: " PTR_FORMAT,
 154                  base, (void*)(uintptr_t)alignment));
 155       _special = true;
 156     } else {
 157       // failed; try to reserve regular memory below
 158       if (UseLargePages && (!FLAG_IS_DEFAULT(UseLargePages) ||
 159                             !FLAG_IS_DEFAULT(LargePageSizeInBytes))) {
 160         if (PrintCompressedOopsMode) {
 161           tty->cr();
 162           tty->print_cr("Reserve regular memory without large pages.");
 163         }
 164       }
 165     }
 166   }
 167 
 168   if (base == NULL) {
 169     // Optimistically assume that the OSes returns an aligned base pointer.
 170     // When reserving a large address range, most OSes seem to align to at
 171     // least 64K.
 172 
 173     // If the memory was requested at a particular address, use
 174     // os::attempt_reserve_memory_at() to avoid over mapping something


 710          middle_high() <= middle_high_boundary(),
 711          "high address must be contained within the region");
 712   assert(middle_high_boundary() <= upper_high() &&
 713          upper_high() <= upper_high_boundary(),
 714          "high address must be contained within the region");
 715   assert(low() >= low_boundary(), "low");
 716   assert(low_boundary() <= lower_high_boundary(), "lower high boundary");
 717   assert(upper_high_boundary() <= high_boundary(), "upper high boundary");
 718   assert(high() <= upper_high(), "upper high");
 719 }
 720 
 721 void VirtualSpace::print() {
 722   tty->print   ("Virtual space:");
 723   if (special()) tty->print(" (pinned in memory)");
 724   tty->cr();
 725   tty->print_cr(" - committed: " SIZE_FORMAT, committed_size());
 726   tty->print_cr(" - reserved:  " SIZE_FORMAT, reserved_size());
 727   tty->print_cr(" - [low, high]:     [" INTPTR_FORMAT ", " INTPTR_FORMAT "]",  low(), high());
 728   tty->print_cr(" - [low_b, high_b]: [" INTPTR_FORMAT ", " INTPTR_FORMAT "]",  low_boundary(), high_boundary());
 729 }
 730 
 731 
 732 /////////////// Unit tests ///////////////
 733 
 734 #ifndef PRODUCT
 735 
 736 #define test_log(...) \
 737   do {\
 738     if (VerboseInternalVMTests) { \
 739       tty->print_cr(__VA_ARGS__); \
 740       tty->flush(); \
 741     }\
 742   } while (false)
 743 
 744 class TestReservedSpace : AllStatic {
 745  public:
 746   static void small_page_write(void* addr, size_t size) {
 747     size_t page_size = os::vm_page_size();
 748 
 749     char* end = (char*)addr + size;
 750     for (char* p = (char*)addr; p < end; p += page_size) {
 751       *p = 1;
 752     }
 753   }
 754 
 755   static void release_memory_for_test(ReservedSpace rs) {
 756     if (rs.special()) {
 757       guarantee(os::release_memory_special(rs.base(), rs.size()), "Shouldn't fail");
 758     } else {
 759       guarantee(os::release_memory(rs.base(), rs.size()), "Shouldn't fail");
 760     }
 761   }
 762 
 763   static void test_reserved_space1(size_t size, size_t alignment) {
 764     test_log("test_reserved_space1(%p)", (void*) (uintptr_t) size);
 765 
 766     assert(is_size_aligned(size, alignment), "Incorrect input parameters");
 767 
 768     ReservedSpace rs(size,          // size
 769                      alignment,     // alignment
 770                      UseLargePages, // large
 771                      NULL,          // requested_address
 772                      0);            // noacces_prefix
 773 
 774     test_log(" rs.special() == %d", rs.special());
 775 
 776     assert(rs.base() != NULL, "Must be");
 777     assert(rs.size() == size, "Must be");
 778 
 779     assert(is_ptr_aligned(rs.base(), alignment), "aligned sizes should always give aligned addresses");
 780     assert(is_size_aligned(rs.size(), alignment), "aligned sizes should always give aligned addresses");
 781 
 782     if (rs.special()) {
 783       small_page_write(rs.base(), size);
 784     }
 785 
 786     release_memory_for_test(rs);
 787   }
 788 
 789   static void test_reserved_space2(size_t size) {
 790     test_log("test_reserved_space2(%p)", (void*)(uintptr_t)size);
 791 
 792     assert(is_size_aligned(size, os::vm_allocation_granularity()), "Must be at least AG aligned");
 793 
 794     ReservedSpace rs(size);
 795 
 796     test_log(" rs.special() == %d", rs.special());
 797 
 798     assert(rs.base() != NULL, "Must be");
 799     assert(rs.size() == size, "Must be");
 800 
 801     if (rs.special()) {
 802       small_page_write(rs.base(), size);
 803     }
 804 
 805     release_memory_for_test(rs);
 806   }
 807 
 808   static void test_reserved_space3(size_t size, size_t alignment, bool maybe_large) {
 809     test_log("test_reserved_space3(%p, %p, %d)",
 810         (void*)(uintptr_t)size, (void*)(uintptr_t)alignment, maybe_large);
 811 
 812     assert(is_size_aligned(size, os::vm_allocation_granularity()), "Must be at least AG aligned");
 813     assert(is_size_aligned(size, alignment), "Must be at least aligned against alignment");
 814 
 815     bool large = maybe_large && UseLargePages && size >= os::large_page_size();
 816 
 817     ReservedSpace rs(size, alignment, large, false);
 818 
 819     test_log(" rs.special() == %d", rs.special());
 820 
 821     assert(rs.base() != NULL, "Must be");
 822     assert(rs.size() == size, "Must be");
 823 
 824     if (rs.special()) {
 825       small_page_write(rs.base(), size);
 826     }
 827 
 828     release_memory_for_test(rs);
 829   }
 830 
 831 
 832   static void test_reserved_space1() {
 833     size_t size = 2 * 1024 * 1024;
 834     size_t ag   = os::vm_allocation_granularity();
 835 
 836     test_reserved_space1(size,      ag);
 837     test_reserved_space1(size * 2,  ag);
 838     test_reserved_space1(size * 10, ag);
 839   }
 840 
 841   static void test_reserved_space2() {
 842     size_t size = 2 * 1024 * 1024;
 843     size_t ag = os::vm_allocation_granularity();
 844 
 845     test_reserved_space2(size * 1);
 846     test_reserved_space2(size * 2);
 847     test_reserved_space2(size * 10);
 848     test_reserved_space2(ag);
 849     test_reserved_space2(size - ag);
 850     test_reserved_space2(size);
 851     test_reserved_space2(size + ag);
 852     test_reserved_space2(size * 2);
 853     test_reserved_space2(size * 2 - ag);
 854     test_reserved_space2(size * 2 + ag);
 855     test_reserved_space2(size * 3);
 856     test_reserved_space2(size * 3 - ag);
 857     test_reserved_space2(size * 3 + ag);
 858     test_reserved_space2(size * 10);
 859     test_reserved_space2(size * 10 + size / 2);
 860   }
 861 
 862   static void test_reserved_space3() {
 863     size_t ag = os::vm_allocation_granularity();
 864 
 865     test_reserved_space3(ag,      ag    , false);
 866     test_reserved_space3(ag * 2,  ag    , false);
 867     test_reserved_space3(ag * 3,  ag    , false);
 868     test_reserved_space3(ag * 2,  ag * 2, false);
 869     test_reserved_space3(ag * 4,  ag * 2, false);
 870     test_reserved_space3(ag * 8,  ag * 2, false);
 871     test_reserved_space3(ag * 4,  ag * 4, false);
 872     test_reserved_space3(ag * 8,  ag * 4, false);
 873     test_reserved_space3(ag * 16, ag * 4, false);
 874 
 875     if (UseLargePages) {
 876       size_t lp = os::large_page_size();
 877 
 878       // Without large pages
 879       test_reserved_space3(lp,     ag * 4, false);
 880       test_reserved_space3(lp * 2, ag * 4, false);
 881       test_reserved_space3(lp * 4, ag * 4, false);
 882       test_reserved_space3(lp,     lp    , false);
 883       test_reserved_space3(lp * 2, lp    , false);
 884       test_reserved_space3(lp * 3, lp    , false);
 885       test_reserved_space3(lp * 2, lp * 2, false);
 886       test_reserved_space3(lp * 4, lp * 2, false);
 887       test_reserved_space3(lp * 8, lp * 2, false);
 888 
 889       // With large pages
 890       test_reserved_space3(lp, ag * 4    , true);
 891       test_reserved_space3(lp * 2, ag * 4, true);
 892       test_reserved_space3(lp * 4, ag * 4, true);
 893       test_reserved_space3(lp, lp        , true);
 894       test_reserved_space3(lp * 2, lp    , true);
 895       test_reserved_space3(lp * 3, lp    , true);
 896       test_reserved_space3(lp * 2, lp * 2, true);
 897       test_reserved_space3(lp * 4, lp * 2, true);
 898       test_reserved_space3(lp * 8, lp * 2, true);
 899     }
 900   }
 901 
 902   static void test_reserved_space() {
 903     test_reserved_space1();
 904     test_reserved_space2();
 905     test_reserved_space3();
 906   }
 907 };
 908 
 909 void TestReservedSpace_test() {
 910   TestReservedSpace::test_reserved_space();
 911 }
 912 
 913 #endif // PRODUCT
 914 
 915 #endif
src/share/vm/runtime/virtualspace.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File