comparison src/share/vm/memory/collectorPolicy.cpp @ 14359:f7f0c6a77d6d

8033426: Scale initial NewSize using NewRatio if not set on command line Summary: Now using NewRatio to size initial NewSize if not specified on commandline. Reviewed-by: jmasa, jwilhelm
author sjohanss
date Wed, 05 Feb 2014 11:05:13 +0100
parents 63a4eb8bcd23
children bac9ef65b71d 4ca6dc0799b6
comparison
equal deleted inserted replaced
14358:e5d78f318aec 14359:f7f0c6a77d6d
444 _min_gen0_size = max_new_size; 444 _min_gen0_size = max_new_size;
445 _initial_gen0_size = max_new_size; 445 _initial_gen0_size = max_new_size;
446 _max_gen0_size = max_new_size; 446 _max_gen0_size = max_new_size;
447 } else { 447 } else {
448 size_t desired_new_size = 0; 448 size_t desired_new_size = 0;
449 if (!FLAG_IS_DEFAULT(NewSize)) { 449 if (FLAG_IS_CMDLINE(NewSize)) {
450 // If NewSize is set ergonomically (for example by cms), it 450 // If NewSize is set on the command line, we must use it as
451 // would make sense to use it. If it is used, also use it 451 // the initial size and it also makes sense to use it as the
452 // to set the initial size. Although there is no reason 452 // lower limit.
453 // the minimum size and the initial size have to be the same,
454 // the current implementation gets into trouble during the calculation
455 // of the tenured generation sizes if they are different.
456 // Note that this makes the initial size and the minimum size
457 // generally small compared to the NewRatio calculation.
458 _min_gen0_size = NewSize; 453 _min_gen0_size = NewSize;
459 desired_new_size = NewSize; 454 desired_new_size = NewSize;
455 max_new_size = MAX2(max_new_size, NewSize);
456 } else if (FLAG_IS_ERGO(NewSize)) {
457 // If NewSize is set ergonomically, we should use it as a lower
458 // limit, but use NewRatio to calculate the initial size.
459 _min_gen0_size = NewSize;
460 desired_new_size =
461 MAX2(scale_by_NewRatio_aligned(_initial_heap_byte_size), NewSize);
460 max_new_size = MAX2(max_new_size, NewSize); 462 max_new_size = MAX2(max_new_size, NewSize);
461 } else { 463 } else {
462 // For the case where NewSize is the default, use NewRatio 464 // For the case where NewSize is the default, use NewRatio
463 // to size the minimum and initial generation sizes. 465 // to size the minimum and initial generation sizes.
464 // Use the default NewSize as the floor for these values. If 466 // Use the default NewSize as the floor for these values. If
978 _gc_policy_counters = new GCPolicyCounters("ParNew:MSC", 2, 3); 980 _gc_policy_counters = new GCPolicyCounters("ParNew:MSC", 2, 3);
979 } else { 981 } else {
980 _gc_policy_counters = new GCPolicyCounters("Copy:MSC", 2, 3); 982 _gc_policy_counters = new GCPolicyCounters("Copy:MSC", 2, 3);
981 } 983 }
982 } 984 }
985
986 /////////////// Unit tests ///////////////
987
988 #ifndef PRODUCT
989 // Testing that the NewSize flag is handled correct is hard because it
990 // depends on so many other configurable variables. This test only tries to
991 // verify that there are some basic rules for NewSize honored by the policies.
992 class TestGenCollectorPolicy {
993 public:
994 static void test() {
995 size_t flag_value;
996
997 save_flags();
998
999 // Set some limits that makes the math simple.
1000 FLAG_SET_ERGO(uintx, MaxHeapSize, 180 * M);
1001 FLAG_SET_ERGO(uintx, InitialHeapSize, 120 * M);
1002 Arguments::set_min_heap_size(40 * M);
1003
1004 // If NewSize is set on the command line, it should be used
1005 // for both min and initial young size if less than min heap.
1006 flag_value = 20 * M;
1007 FLAG_SET_CMDLINE(uintx, NewSize, flag_value);
1008 verify_min(flag_value);
1009 verify_initial(flag_value);
1010
1011 // If NewSize is set on command line, but is larger than the min
1012 // heap size, it should only be used for initial young size.
1013 flag_value = 80 * M;
1014 FLAG_SET_CMDLINE(uintx, NewSize, flag_value);
1015 verify_initial(flag_value);
1016
1017 // If NewSize has been ergonomically set, the collector policy
1018 // should use it for min but calculate the initial young size
1019 // using NewRatio.
1020 flag_value = 20 * M;
1021 FLAG_SET_ERGO(uintx, NewSize, flag_value);
1022 verify_min(flag_value);
1023 verify_scaled_initial(InitialHeapSize);
1024
1025 restore_flags();
1026
1027 }
1028
1029 static void verify_min(size_t expected) {
1030 MarkSweepPolicy msp;
1031 msp.initialize_all();
1032
1033 assert(msp.min_gen0_size() <= expected, err_msg("%zu > %zu", msp.min_gen0_size(), expected));
1034 }
1035
1036 static void verify_initial(size_t expected) {
1037 MarkSweepPolicy msp;
1038 msp.initialize_all();
1039
1040 assert(msp.initial_gen0_size() == expected, err_msg("%zu != %zu", msp.initial_gen0_size(), expected));
1041 }
1042
1043 static void verify_scaled_initial(size_t initial_heap_size) {
1044 MarkSweepPolicy msp;
1045 msp.initialize_all();
1046
1047 size_t expected = msp.scale_by_NewRatio_aligned(initial_heap_size);
1048 assert(msp.initial_gen0_size() == expected, err_msg("%zu != %zu", msp.initial_gen0_size(), expected));
1049 assert(FLAG_IS_ERGO(NewSize) && NewSize == expected,
1050 err_msg("NewSize should have been set ergonomically to %zu, but was %zu", expected, NewSize));
1051 }
1052
1053 private:
1054 static size_t original_InitialHeapSize;
1055 static size_t original_MaxHeapSize;
1056 static size_t original_MaxNewSize;
1057 static size_t original_MinHeapDeltaBytes;
1058 static size_t original_NewSize;
1059 static size_t original_OldSize;
1060
1061 static void save_flags() {
1062 original_InitialHeapSize = InitialHeapSize;
1063 original_MaxHeapSize = MaxHeapSize;
1064 original_MaxNewSize = MaxNewSize;
1065 original_MinHeapDeltaBytes = MinHeapDeltaBytes;
1066 original_NewSize = NewSize;
1067 original_OldSize = OldSize;
1068 }
1069
1070 static void restore_flags() {
1071 InitialHeapSize = original_InitialHeapSize;
1072 MaxHeapSize = original_MaxHeapSize;
1073 MaxNewSize = original_MaxNewSize;
1074 MinHeapDeltaBytes = original_MinHeapDeltaBytes;
1075 NewSize = original_NewSize;
1076 OldSize = original_OldSize;
1077 }
1078 };
1079
1080 size_t TestGenCollectorPolicy::original_InitialHeapSize = 0;
1081 size_t TestGenCollectorPolicy::original_MaxHeapSize = 0;
1082 size_t TestGenCollectorPolicy::original_MaxNewSize = 0;
1083 size_t TestGenCollectorPolicy::original_MinHeapDeltaBytes = 0;
1084 size_t TestGenCollectorPolicy::original_NewSize = 0;
1085 size_t TestGenCollectorPolicy::original_OldSize = 0;
1086
1087 void TestNewSize_test() {
1088 TestGenCollectorPolicy::test();
1089 }
1090
1091 #endif