1.1 --- a/src/share/vm/runtime/virtualspace.cpp Thu Sep 12 10:15:30 2013 +0200 1.2 +++ b/src/share/vm/runtime/virtualspace.cpp Thu Sep 12 10:15:54 2013 +0200 1.3 @@ -453,6 +453,42 @@ 1.4 return reserved_size() - committed_size(); 1.5 } 1.6 1.7 +size_t VirtualSpace::actual_committed_size() const { 1.8 + // Special VirtualSpaces commit all reserved space up front. 1.9 + if (special()) { 1.10 + return reserved_size(); 1.11 + } 1.12 + 1.13 + size_t committed_low = pointer_delta(_lower_high, _low_boundary, sizeof(char)); 1.14 + size_t committed_middle = pointer_delta(_middle_high, _lower_high_boundary, sizeof(char)); 1.15 + size_t committed_high = pointer_delta(_upper_high, _middle_high_boundary, sizeof(char)); 1.16 + 1.17 +#ifdef ASSERT 1.18 + size_t lower = pointer_delta(_lower_high_boundary, _low_boundary, sizeof(char)); 1.19 + size_t middle = pointer_delta(_middle_high_boundary, _lower_high_boundary, sizeof(char)); 1.20 + size_t upper = pointer_delta(_upper_high_boundary, _middle_high_boundary, sizeof(char)); 1.21 + 1.22 + if (committed_high > 0) { 1.23 + assert(committed_low == lower, "Must be"); 1.24 + assert(committed_middle == middle, "Must be"); 1.25 + } 1.26 + 1.27 + if (committed_middle > 0) { 1.28 + assert(committed_low == lower, "Must be"); 1.29 + } 1.30 + if (committed_middle < middle) { 1.31 + assert(committed_high == 0, "Must be"); 1.32 + } 1.33 + 1.34 + if (committed_low < lower) { 1.35 + assert(committed_high == 0, "Must be"); 1.36 + assert(committed_middle == 0, "Must be"); 1.37 + } 1.38 +#endif 1.39 + 1.40 + return committed_low + committed_middle + committed_high; 1.41 +} 1.42 + 1.43 1.44 bool VirtualSpace::contains(const void* p) const { 1.45 return low() <= (const char*) p && (const char*) p < high(); 1.46 @@ -910,6 +946,109 @@ 1.47 TestReservedSpace::test_reserved_space(); 1.48 } 1.49 1.50 +#define assert_equals(actual, expected) \ 1.51 + assert(actual == expected, \ 1.52 + err_msg("Got " SIZE_FORMAT " expected " \ 1.53 + SIZE_FORMAT, actual, expected)); 1.54 + 1.55 +#define assert_ge(value1, value2) \ 1.56 + assert(value1 >= value2, \ 1.57 + err_msg("'" #value1 "': " SIZE_FORMAT " '" \ 1.58 + #value2 "': " SIZE_FORMAT, value1, value2)); 1.59 + 1.60 +#define assert_lt(value1, value2) \ 1.61 + assert(value1 < value2, \ 1.62 + err_msg("'" #value1 "': " SIZE_FORMAT " '" \ 1.63 + #value2 "': " SIZE_FORMAT, value1, value2)); 1.64 + 1.65 + 1.66 +class TestVirtualSpace : AllStatic { 1.67 + public: 1.68 + static void test_virtual_space_actual_committed_space(size_t reserve_size, size_t commit_size) { 1.69 + size_t granularity = os::vm_allocation_granularity(); 1.70 + size_t reserve_size_aligned = align_size_up(reserve_size, granularity); 1.71 + 1.72 + ReservedSpace reserved(reserve_size_aligned); 1.73 + 1.74 + assert(reserved.is_reserved(), "Must be"); 1.75 + 1.76 + VirtualSpace vs; 1.77 + bool initialized = vs.initialize(reserved, 0); 1.78 + assert(initialized, "Failed to initialize VirtualSpace"); 1.79 + 1.80 + vs.expand_by(commit_size, false); 1.81 + 1.82 + if (vs.special()) { 1.83 + assert_equals(vs.actual_committed_size(), reserve_size_aligned); 1.84 + } else { 1.85 + assert_ge(vs.actual_committed_size(), commit_size); 1.86 + // Approximate the commit granularity. 1.87 + size_t commit_granularity = UseLargePages ? os::large_page_size() : os::vm_page_size(); 1.88 + assert_lt(vs.actual_committed_size(), commit_size + commit_granularity); 1.89 + } 1.90 + 1.91 + reserved.release(); 1.92 + } 1.93 + 1.94 + static void test_virtual_space_actual_committed_space_one_large_page() { 1.95 + if (!UseLargePages) { 1.96 + return; 1.97 + } 1.98 + 1.99 + size_t large_page_size = os::large_page_size(); 1.100 + 1.101 + ReservedSpace reserved(large_page_size, large_page_size, true, false); 1.102 + 1.103 + assert(reserved.is_reserved(), "Must be"); 1.104 + 1.105 + VirtualSpace vs; 1.106 + bool initialized = vs.initialize(reserved, 0); 1.107 + assert(initialized, "Failed to initialize VirtualSpace"); 1.108 + 1.109 + vs.expand_by(large_page_size, false); 1.110 + 1.111 + assert_equals(vs.actual_committed_size(), large_page_size); 1.112 + 1.113 + reserved.release(); 1.114 + } 1.115 + 1.116 + static void test_virtual_space_actual_committed_space() { 1.117 + test_virtual_space_actual_committed_space(4 * K, 0); 1.118 + test_virtual_space_actual_committed_space(4 * K, 4 * K); 1.119 + test_virtual_space_actual_committed_space(8 * K, 0); 1.120 + test_virtual_space_actual_committed_space(8 * K, 4 * K); 1.121 + test_virtual_space_actual_committed_space(8 * K, 8 * K); 1.122 + test_virtual_space_actual_committed_space(12 * K, 0); 1.123 + test_virtual_space_actual_committed_space(12 * K, 4 * K); 1.124 + test_virtual_space_actual_committed_space(12 * K, 8 * K); 1.125 + test_virtual_space_actual_committed_space(12 * K, 12 * K); 1.126 + test_virtual_space_actual_committed_space(64 * K, 0); 1.127 + test_virtual_space_actual_committed_space(64 * K, 32 * K); 1.128 + test_virtual_space_actual_committed_space(64 * K, 64 * K); 1.129 + test_virtual_space_actual_committed_space(2 * M, 0); 1.130 + test_virtual_space_actual_committed_space(2 * M, 4 * K); 1.131 + test_virtual_space_actual_committed_space(2 * M, 64 * K); 1.132 + test_virtual_space_actual_committed_space(2 * M, 1 * M); 1.133 + test_virtual_space_actual_committed_space(2 * M, 2 * M); 1.134 + test_virtual_space_actual_committed_space(10 * M, 0); 1.135 + test_virtual_space_actual_committed_space(10 * M, 4 * K); 1.136 + test_virtual_space_actual_committed_space(10 * M, 8 * K); 1.137 + test_virtual_space_actual_committed_space(10 * M, 1 * M); 1.138 + test_virtual_space_actual_committed_space(10 * M, 2 * M); 1.139 + test_virtual_space_actual_committed_space(10 * M, 5 * M); 1.140 + test_virtual_space_actual_committed_space(10 * M, 10 * M); 1.141 + } 1.142 + 1.143 + static void test_virtual_space() { 1.144 + test_virtual_space_actual_committed_space(); 1.145 + test_virtual_space_actual_committed_space_one_large_page(); 1.146 + } 1.147 +}; 1.148 + 1.149 +void TestVirtualSpace_test() { 1.150 + TestVirtualSpace::test_virtual_space(); 1.151 +} 1.152 + 1.153 #endif // PRODUCT 1.154 1.155 #endif