61 assert(InitialHeapSize % _heap_alignment == 0, "InitialHeapSize alignment"); 62 assert(MaxHeapSize % _heap_alignment == 0, "MaxHeapSize alignment"); 63 } 64 65 void CollectorPolicy::assert_size_info() { 66 assert(InitialHeapSize == _initial_heap_byte_size, "Discrepancy between InitialHeapSize flag and local storage"); 67 assert(MaxHeapSize == _max_heap_byte_size, "Discrepancy between MaxHeapSize flag and local storage"); 68 assert(_max_heap_byte_size >= _min_heap_byte_size, "Ergonomics decided on incompatible minimum and maximum heap sizes"); 69 assert(_initial_heap_byte_size >= _min_heap_byte_size, "Ergonomics decided on incompatible initial and minimum heap sizes"); 70 assert(_max_heap_byte_size >= _initial_heap_byte_size, "Ergonomics decided on incompatible initial and maximum heap sizes"); 71 assert(_min_heap_byte_size % _heap_alignment == 0, "min_heap_byte_size alignment"); 72 assert(_initial_heap_byte_size % _heap_alignment == 0, "initial_heap_byte_size alignment"); 73 assert(_max_heap_byte_size % _heap_alignment == 0, "max_heap_byte_size alignment"); 74 } 75 #endif // ASSERT 76 77 void CollectorPolicy::initialize_flags() { 78 assert(_space_alignment != 0, "Space alignment not set up properly"); 79 assert(_heap_alignment != 0, "Heap alignment not set up properly"); 80 assert(_heap_alignment >= _space_alignment, 81 err_msg("heap_alignment: " SIZE_FORMAT " less than space_alignment: " SIZE_FORMAT, 82 _heap_alignment, _space_alignment)); 83 assert(_heap_alignment % _space_alignment == 0, 84 err_msg("heap_alignment: " SIZE_FORMAT " not aligned by space_alignment: " SIZE_FORMAT, 85 _heap_alignment, _space_alignment)); 86 87 if (FLAG_IS_CMDLINE(MaxHeapSize)) { 88 if (FLAG_IS_CMDLINE(InitialHeapSize) && InitialHeapSize > MaxHeapSize) { 89 vm_exit_during_initialization("Initial heap size set to a larger value than the maximum heap size"); 90 } 91 if (_min_heap_byte_size != 0 && MaxHeapSize < _min_heap_byte_size) { 92 vm_exit_during_initialization("Incompatible minimum and maximum heap sizes specified"); 93 } 94 _max_heap_size_cmdline = true; 95 } 96 97 // Check heap parameter properties 98 if (InitialHeapSize < M) { 99 vm_exit_during_initialization("Too small initial heap"); 100 } 101 if (_min_heap_byte_size < M) { 102 vm_exit_during_initialization("Too small minimum heap"); 103 } 104 105 // User inputs from -Xmx and -Xms must be aligned 258 assert(_initial_young_size <= bound_minus_alignment(_initial_young_size, _initial_heap_byte_size), 259 "Ergonomics made initial young generation larger than initial heap"); 260 assert(_max_young_size <= bound_minus_alignment(_max_young_size, _max_heap_byte_size), 261 "Ergonomics made maximum young generation lager than maximum heap"); 262 assert(_min_old_size <= _initial_old_size, "Ergonomics decided on incompatible minimum and initial old gen sizes"); 263 assert(_initial_old_size <= _max_old_size, "Ergonomics decided on incompatible initial and maximum old gen sizes"); 264 assert(_max_old_size % _gen_alignment == 0, "_max_old_size alignment"); 265 assert(_initial_old_size % _gen_alignment == 0, "_initial_old_size alignment"); 266 assert(_max_heap_byte_size <= (_max_young_size + _max_old_size), "Total maximum heap sizes must be sum of generation maximum sizes"); 267 assert(_min_young_size + _min_old_size <= _min_heap_byte_size, "Minimum generation sizes exceed minimum heap size"); 268 assert(_initial_young_size + _initial_old_size == _initial_heap_byte_size, "Initial generation sizes should match initial heap size"); 269 assert(_max_young_size + _max_old_size == _max_heap_byte_size, "Maximum generation sizes should match maximum heap size"); 270 } 271 #endif // ASSERT 272 273 void GenCollectorPolicy::initialize_flags() { 274 CollectorPolicy::initialize_flags(); 275 276 assert(_gen_alignment != 0, "Generation alignment not set up properly"); 277 assert(_heap_alignment >= _gen_alignment, 278 err_msg("heap_alignment: " SIZE_FORMAT " less than gen_alignment: " SIZE_FORMAT, 279 _heap_alignment, _gen_alignment)); 280 assert(_gen_alignment % _space_alignment == 0, 281 err_msg("gen_alignment: " SIZE_FORMAT " not aligned by space_alignment: " SIZE_FORMAT, 282 _gen_alignment, _space_alignment)); 283 assert(_heap_alignment % _gen_alignment == 0, 284 err_msg("heap_alignment: " SIZE_FORMAT " not aligned by gen_alignment: " SIZE_FORMAT, 285 _heap_alignment, _gen_alignment)); 286 287 // All generational heaps have a youngest gen; handle those flags here 288 289 // Make sure the heap is large enough for two generations 290 size_t smallest_new_size = young_gen_size_lower_bound(); 291 size_t smallest_heap_size = align_size_up(smallest_new_size + old_gen_size_lower_bound(), 292 _heap_alignment); 293 if (MaxHeapSize < smallest_heap_size) { 294 FLAG_SET_ERGO(size_t, MaxHeapSize, smallest_heap_size); 295 _max_heap_byte_size = MaxHeapSize; 296 } 297 // If needed, synchronize _min_heap_byte size and _initial_heap_byte_size 298 if (_min_heap_byte_size < smallest_heap_size) { 299 _min_heap_byte_size = smallest_heap_size; 300 if (InitialHeapSize < _min_heap_byte_size) { 301 FLAG_SET_ERGO(size_t, InitialHeapSize, smallest_heap_size); 302 _initial_heap_byte_size = smallest_heap_size; 303 } 304 } 305 995 // If MaxNewSize is large, the maximum OldSize will be less than 996 // what's requested on the command line and it should be reset 997 // ergonomically. 998 // We intentionally set MaxNewSize + OldSize > MaxHeapSize (see over_size). 999 flag_value = 30 * M; 1000 set_basic_flag_values(); 1001 FLAG_SET_CMDLINE(size_t, OldSize, flag_value); 1002 size_t over_size = 20*M; 1003 size_t new_size_value = align_size_up(MaxHeapSize, heap_alignment) - flag_value + over_size; 1004 FLAG_SET_CMDLINE(size_t, MaxNewSize, new_size_value); 1005 // Calculate what we expect the flag to be. 1006 expected_old_initial = align_size_up(MaxHeapSize, heap_alignment) - MaxNewSize; 1007 verify_old_initial(expected_old_initial); 1008 restore_flags(); 1009 } 1010 1011 static void verify_young_min(size_t expected) { 1012 MarkSweepPolicy msp; 1013 msp.initialize_all(); 1014 1015 assert(msp.min_young_size() <= expected, err_msg("%zu > %zu", msp.min_young_size(), expected)); 1016 } 1017 1018 static void verify_young_initial(size_t expected) { 1019 MarkSweepPolicy msp; 1020 msp.initialize_all(); 1021 1022 assert(msp.initial_young_size() == expected, err_msg("%zu != %zu", msp.initial_young_size(), expected)); 1023 } 1024 1025 static void verify_scaled_young_initial(size_t initial_heap_size) { 1026 MarkSweepPolicy msp; 1027 msp.initialize_all(); 1028 1029 if (InitialHeapSize > initial_heap_size) { 1030 // InitialHeapSize was adapted by msp.initialize_all, e.g. due to alignment 1031 // caused by 64K page size. 1032 initial_heap_size = InitialHeapSize; 1033 } 1034 1035 size_t expected = msp.scale_by_NewRatio_aligned(initial_heap_size); 1036 assert(msp.initial_young_size() == expected, err_msg("%zu != %zu", msp.initial_young_size(), expected)); 1037 assert(FLAG_IS_ERGO(NewSize) && NewSize == expected, 1038 err_msg("NewSize should have been set ergonomically to %zu, but was %zu", expected, NewSize)); 1039 } 1040 1041 static void verify_old_min(size_t expected) { 1042 MarkSweepPolicy msp; 1043 msp.initialize_all(); 1044 1045 assert(msp.min_old_size() <= expected, err_msg("%zu > %zu", msp.min_old_size(), expected)); 1046 } 1047 1048 static void verify_old_initial(size_t expected) { 1049 MarkSweepPolicy msp; 1050 msp.initialize_all(); 1051 1052 assert(msp.initial_old_size() == expected, err_msg("%zu != %zu", msp.initial_old_size(), expected)); 1053 } 1054 1055 1056 private: 1057 static size_t original_InitialHeapSize; 1058 static size_t original_MaxHeapSize; 1059 static size_t original_MaxNewSize; 1060 static size_t original_MinHeapDeltaBytes; 1061 static size_t original_NewSize; 1062 static size_t original_OldSize; 1063 1064 static void set_basic_flag_values() { 1065 FLAG_SET_ERGO(size_t, MaxHeapSize, 180 * M); 1066 FLAG_SET_ERGO(size_t, InitialHeapSize, 100 * M); 1067 FLAG_SET_ERGO(size_t, OldSize, 4 * M); 1068 FLAG_SET_ERGO(size_t, NewSize, 1 * M); 1069 FLAG_SET_ERGO(size_t, MaxNewSize, 80 * M); 1070 Arguments::set_min_heap_size(40 * M); 1071 } 1072 | 61 assert(InitialHeapSize % _heap_alignment == 0, "InitialHeapSize alignment"); 62 assert(MaxHeapSize % _heap_alignment == 0, "MaxHeapSize alignment"); 63 } 64 65 void CollectorPolicy::assert_size_info() { 66 assert(InitialHeapSize == _initial_heap_byte_size, "Discrepancy between InitialHeapSize flag and local storage"); 67 assert(MaxHeapSize == _max_heap_byte_size, "Discrepancy between MaxHeapSize flag and local storage"); 68 assert(_max_heap_byte_size >= _min_heap_byte_size, "Ergonomics decided on incompatible minimum and maximum heap sizes"); 69 assert(_initial_heap_byte_size >= _min_heap_byte_size, "Ergonomics decided on incompatible initial and minimum heap sizes"); 70 assert(_max_heap_byte_size >= _initial_heap_byte_size, "Ergonomics decided on incompatible initial and maximum heap sizes"); 71 assert(_min_heap_byte_size % _heap_alignment == 0, "min_heap_byte_size alignment"); 72 assert(_initial_heap_byte_size % _heap_alignment == 0, "initial_heap_byte_size alignment"); 73 assert(_max_heap_byte_size % _heap_alignment == 0, "max_heap_byte_size alignment"); 74 } 75 #endif // ASSERT 76 77 void CollectorPolicy::initialize_flags() { 78 assert(_space_alignment != 0, "Space alignment not set up properly"); 79 assert(_heap_alignment != 0, "Heap alignment not set up properly"); 80 assert(_heap_alignment >= _space_alignment, 81 "heap_alignment: " SIZE_FORMAT " less than space_alignment: " SIZE_FORMAT, 82 _heap_alignment, _space_alignment); 83 assert(_heap_alignment % _space_alignment == 0, 84 "heap_alignment: " SIZE_FORMAT " not aligned by space_alignment: " SIZE_FORMAT, 85 _heap_alignment, _space_alignment); 86 87 if (FLAG_IS_CMDLINE(MaxHeapSize)) { 88 if (FLAG_IS_CMDLINE(InitialHeapSize) && InitialHeapSize > MaxHeapSize) { 89 vm_exit_during_initialization("Initial heap size set to a larger value than the maximum heap size"); 90 } 91 if (_min_heap_byte_size != 0 && MaxHeapSize < _min_heap_byte_size) { 92 vm_exit_during_initialization("Incompatible minimum and maximum heap sizes specified"); 93 } 94 _max_heap_size_cmdline = true; 95 } 96 97 // Check heap parameter properties 98 if (InitialHeapSize < M) { 99 vm_exit_during_initialization("Too small initial heap"); 100 } 101 if (_min_heap_byte_size < M) { 102 vm_exit_during_initialization("Too small minimum heap"); 103 } 104 105 // User inputs from -Xmx and -Xms must be aligned 258 assert(_initial_young_size <= bound_minus_alignment(_initial_young_size, _initial_heap_byte_size), 259 "Ergonomics made initial young generation larger than initial heap"); 260 assert(_max_young_size <= bound_minus_alignment(_max_young_size, _max_heap_byte_size), 261 "Ergonomics made maximum young generation lager than maximum heap"); 262 assert(_min_old_size <= _initial_old_size, "Ergonomics decided on incompatible minimum and initial old gen sizes"); 263 assert(_initial_old_size <= _max_old_size, "Ergonomics decided on incompatible initial and maximum old gen sizes"); 264 assert(_max_old_size % _gen_alignment == 0, "_max_old_size alignment"); 265 assert(_initial_old_size % _gen_alignment == 0, "_initial_old_size alignment"); 266 assert(_max_heap_byte_size <= (_max_young_size + _max_old_size), "Total maximum heap sizes must be sum of generation maximum sizes"); 267 assert(_min_young_size + _min_old_size <= _min_heap_byte_size, "Minimum generation sizes exceed minimum heap size"); 268 assert(_initial_young_size + _initial_old_size == _initial_heap_byte_size, "Initial generation sizes should match initial heap size"); 269 assert(_max_young_size + _max_old_size == _max_heap_byte_size, "Maximum generation sizes should match maximum heap size"); 270 } 271 #endif // ASSERT 272 273 void GenCollectorPolicy::initialize_flags() { 274 CollectorPolicy::initialize_flags(); 275 276 assert(_gen_alignment != 0, "Generation alignment not set up properly"); 277 assert(_heap_alignment >= _gen_alignment, 278 "heap_alignment: " SIZE_FORMAT " less than gen_alignment: " SIZE_FORMAT, 279 _heap_alignment, _gen_alignment); 280 assert(_gen_alignment % _space_alignment == 0, 281 "gen_alignment: " SIZE_FORMAT " not aligned by space_alignment: " SIZE_FORMAT, 282 _gen_alignment, _space_alignment); 283 assert(_heap_alignment % _gen_alignment == 0, 284 "heap_alignment: " SIZE_FORMAT " not aligned by gen_alignment: " SIZE_FORMAT, 285 _heap_alignment, _gen_alignment); 286 287 // All generational heaps have a youngest gen; handle those flags here 288 289 // Make sure the heap is large enough for two generations 290 size_t smallest_new_size = young_gen_size_lower_bound(); 291 size_t smallest_heap_size = align_size_up(smallest_new_size + old_gen_size_lower_bound(), 292 _heap_alignment); 293 if (MaxHeapSize < smallest_heap_size) { 294 FLAG_SET_ERGO(size_t, MaxHeapSize, smallest_heap_size); 295 _max_heap_byte_size = MaxHeapSize; 296 } 297 // If needed, synchronize _min_heap_byte size and _initial_heap_byte_size 298 if (_min_heap_byte_size < smallest_heap_size) { 299 _min_heap_byte_size = smallest_heap_size; 300 if (InitialHeapSize < _min_heap_byte_size) { 301 FLAG_SET_ERGO(size_t, InitialHeapSize, smallest_heap_size); 302 _initial_heap_byte_size = smallest_heap_size; 303 } 304 } 305 995 // If MaxNewSize is large, the maximum OldSize will be less than 996 // what's requested on the command line and it should be reset 997 // ergonomically. 998 // We intentionally set MaxNewSize + OldSize > MaxHeapSize (see over_size). 999 flag_value = 30 * M; 1000 set_basic_flag_values(); 1001 FLAG_SET_CMDLINE(size_t, OldSize, flag_value); 1002 size_t over_size = 20*M; 1003 size_t new_size_value = align_size_up(MaxHeapSize, heap_alignment) - flag_value + over_size; 1004 FLAG_SET_CMDLINE(size_t, MaxNewSize, new_size_value); 1005 // Calculate what we expect the flag to be. 1006 expected_old_initial = align_size_up(MaxHeapSize, heap_alignment) - MaxNewSize; 1007 verify_old_initial(expected_old_initial); 1008 restore_flags(); 1009 } 1010 1011 static void verify_young_min(size_t expected) { 1012 MarkSweepPolicy msp; 1013 msp.initialize_all(); 1014 1015 assert(msp.min_young_size() <= expected, "%zu > %zu", msp.min_young_size(), expected); 1016 } 1017 1018 static void verify_young_initial(size_t expected) { 1019 MarkSweepPolicy msp; 1020 msp.initialize_all(); 1021 1022 assert(msp.initial_young_size() == expected, "%zu != %zu", msp.initial_young_size(), expected); 1023 } 1024 1025 static void verify_scaled_young_initial(size_t initial_heap_size) { 1026 MarkSweepPolicy msp; 1027 msp.initialize_all(); 1028 1029 if (InitialHeapSize > initial_heap_size) { 1030 // InitialHeapSize was adapted by msp.initialize_all, e.g. due to alignment 1031 // caused by 64K page size. 1032 initial_heap_size = InitialHeapSize; 1033 } 1034 1035 size_t expected = msp.scale_by_NewRatio_aligned(initial_heap_size); 1036 assert(msp.initial_young_size() == expected, "%zu != %zu", msp.initial_young_size(), expected); 1037 assert(FLAG_IS_ERGO(NewSize) && NewSize == expected, 1038 "NewSize should have been set ergonomically to %zu, but was %zu", expected, NewSize); 1039 } 1040 1041 static void verify_old_min(size_t expected) { 1042 MarkSweepPolicy msp; 1043 msp.initialize_all(); 1044 1045 assert(msp.min_old_size() <= expected, "%zu > %zu", msp.min_old_size(), expected); 1046 } 1047 1048 static void verify_old_initial(size_t expected) { 1049 MarkSweepPolicy msp; 1050 msp.initialize_all(); 1051 1052 assert(msp.initial_old_size() == expected, "%zu != %zu", msp.initial_old_size(), expected); 1053 } 1054 1055 1056 private: 1057 static size_t original_InitialHeapSize; 1058 static size_t original_MaxHeapSize; 1059 static size_t original_MaxNewSize; 1060 static size_t original_MinHeapDeltaBytes; 1061 static size_t original_NewSize; 1062 static size_t original_OldSize; 1063 1064 static void set_basic_flag_values() { 1065 FLAG_SET_ERGO(size_t, MaxHeapSize, 180 * M); 1066 FLAG_SET_ERGO(size_t, InitialHeapSize, 100 * M); 1067 FLAG_SET_ERGO(size_t, OldSize, 4 * M); 1068 FLAG_SET_ERGO(size_t, NewSize, 1 * M); 1069 FLAG_SET_ERGO(size_t, MaxNewSize, 80 * M); 1070 Arguments::set_min_heap_size(40 * M); 1071 } 1072 |