comparison src/share/vm/memory/collectorPolicy.cpp @ 18041:52b4284cb496

Merge with jdk8u20-b26
author Gilles Duboscq <duboscq@ssw.jku.at>
date Wed, 15 Oct 2014 16:02:50 +0200
parents 4ca6dc0799b6 78bbf4d43a14
children 7848fc12602b
comparison
equal deleted inserted replaced
17606:45d7b2c7029d 18041:52b4284cb496
1 /* 1 /*
2 * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
305 _initial_heap_byte_size = smallest_heap_size; 305 _initial_heap_byte_size = smallest_heap_size;
306 } 306 }
307 } 307 }
308 308
309 // Now take the actual NewSize into account. We will silently increase NewSize 309 // Now take the actual NewSize into account. We will silently increase NewSize
310 // if the user specified a smaller value. 310 // if the user specified a smaller or unaligned value.
311 smallest_new_size = MAX2(smallest_new_size, (uintx)align_size_down(NewSize, _gen_alignment)); 311 smallest_new_size = MAX2(smallest_new_size, (uintx)align_size_down(NewSize, _gen_alignment));
312 if (smallest_new_size != NewSize) { 312 if (smallest_new_size != NewSize) {
313 FLAG_SET_ERGO(uintx, NewSize, smallest_new_size); 313 // Do not use FLAG_SET_ERGO to update NewSize here, since this will override
314 // if NewSize was set on the command line or not. This information is needed
315 // later when setting the initial and minimum young generation size.
316 NewSize = smallest_new_size;
314 } 317 }
315 _initial_gen0_size = NewSize; 318 _initial_gen0_size = NewSize;
316 319
317 if (!FLAG_IS_DEFAULT(MaxNewSize)) { 320 if (!FLAG_IS_DEFAULT(MaxNewSize)) {
318 uintx min_new_size = MAX2(_gen_alignment, _min_gen0_size); 321 uintx min_new_size = MAX2(_gen_alignment, _min_gen0_size);
448 _min_gen0_size = max_new_size; 451 _min_gen0_size = max_new_size;
449 _initial_gen0_size = max_new_size; 452 _initial_gen0_size = max_new_size;
450 _max_gen0_size = max_new_size; 453 _max_gen0_size = max_new_size;
451 } else { 454 } else {
452 size_t desired_new_size = 0; 455 size_t desired_new_size = 0;
453 if (!FLAG_IS_DEFAULT(NewSize)) { 456 if (FLAG_IS_CMDLINE(NewSize)) {
454 // If NewSize is set ergonomically (for example by cms), it 457 // If NewSize is set on the command line, we must use it as
455 // would make sense to use it. If it is used, also use it 458 // the initial size and it also makes sense to use it as the
456 // to set the initial size. Although there is no reason 459 // lower limit.
457 // the minimum size and the initial size have to be the same,
458 // the current implementation gets into trouble during the calculation
459 // of the tenured generation sizes if they are different.
460 // Note that this makes the initial size and the minimum size
461 // generally small compared to the NewRatio calculation.
462 _min_gen0_size = NewSize; 460 _min_gen0_size = NewSize;
463 desired_new_size = NewSize; 461 desired_new_size = NewSize;
462 max_new_size = MAX2(max_new_size, NewSize);
463 } else if (FLAG_IS_ERGO(NewSize)) {
464 // If NewSize is set ergonomically, we should use it as a lower
465 // limit, but use NewRatio to calculate the initial size.
466 _min_gen0_size = NewSize;
467 desired_new_size =
468 MAX2(scale_by_NewRatio_aligned(_initial_heap_byte_size), NewSize);
464 max_new_size = MAX2(max_new_size, NewSize); 469 max_new_size = MAX2(max_new_size, NewSize);
465 } else { 470 } else {
466 // For the case where NewSize is the default, use NewRatio 471 // For the case where NewSize is the default, use NewRatio
467 // to size the minimum and initial generation sizes. 472 // to size the minimum and initial generation sizes.
468 // Use the default NewSize as the floor for these values. If 473 // Use the default NewSize as the floor for these values. If
762 767
763 // Give a warning if we seem to be looping forever. 768 // Give a warning if we seem to be looping forever.
764 if ((QueuedAllocationWarningCount > 0) && 769 if ((QueuedAllocationWarningCount > 0) &&
765 (try_count % QueuedAllocationWarningCount == 0)) { 770 (try_count % QueuedAllocationWarningCount == 0)) {
766 warning("TwoGenerationCollectorPolicy::mem_allocate_work retries %d times \n\t" 771 warning("TwoGenerationCollectorPolicy::mem_allocate_work retries %d times \n\t"
767 " size=%d %s", try_count, size, is_tlab ? "(TLAB)" : ""); 772 " size=" SIZE_FORMAT " %s", try_count, size, is_tlab ? "(TLAB)" : "");
768 } 773 }
769 } 774 }
770 } 775 }
771 776
772 HeapWord* GenCollectorPolicy::expand_heap_and_allocate(size_t size, 777 HeapWord* GenCollectorPolicy::expand_heap_and_allocate(size_t size,
931 } 936 }
932 loop_count++; 937 loop_count++;
933 if ((QueuedAllocationWarningCount > 0) && 938 if ((QueuedAllocationWarningCount > 0) &&
934 (loop_count % QueuedAllocationWarningCount == 0)) { 939 (loop_count % QueuedAllocationWarningCount == 0)) {
935 warning("satisfy_failed_metadata_allocation() retries %d times \n\t" 940 warning("satisfy_failed_metadata_allocation() retries %d times \n\t"
936 " size=%d", loop_count, word_size); 941 " size=" SIZE_FORMAT, loop_count, word_size);
937 } 942 }
938 } while (true); // Until a GC is done 943 } while (true); // Until a GC is done
939 } 944 }
940 945
941 // Return true if any of the following is true: 946 // Return true if any of the following is true:
987 _gc_policy_counters = new GCPolicyCounters("ParNew:MSC", 2, 3); 992 _gc_policy_counters = new GCPolicyCounters("ParNew:MSC", 2, 3);
988 } else { 993 } else {
989 _gc_policy_counters = new GCPolicyCounters("Copy:MSC", 2, 3); 994 _gc_policy_counters = new GCPolicyCounters("Copy:MSC", 2, 3);
990 } 995 }
991 } 996 }
997
998 /////////////// Unit tests ///////////////
999
1000 #ifndef PRODUCT
1001 // Testing that the NewSize flag is handled correct is hard because it
1002 // depends on so many other configurable variables. This test only tries to
1003 // verify that there are some basic rules for NewSize honored by the policies.
1004 class TestGenCollectorPolicy {
1005 public:
1006 static void test() {
1007 size_t flag_value;
1008
1009 save_flags();
1010
1011 // Set some limits that makes the math simple.
1012 FLAG_SET_ERGO(uintx, MaxHeapSize, 180 * M);
1013 FLAG_SET_ERGO(uintx, InitialHeapSize, 120 * M);
1014 Arguments::set_min_heap_size(40 * M);
1015
1016 // If NewSize is set on the command line, it should be used
1017 // for both min and initial young size if less than min heap.
1018 flag_value = 20 * M;
1019 FLAG_SET_CMDLINE(uintx, NewSize, flag_value);
1020 verify_min(flag_value);
1021 verify_initial(flag_value);
1022
1023 // If NewSize is set on command line, but is larger than the min
1024 // heap size, it should only be used for initial young size.
1025 flag_value = 80 * M;
1026 FLAG_SET_CMDLINE(uintx, NewSize, flag_value);
1027 verify_initial(flag_value);
1028
1029 // If NewSize has been ergonomically set, the collector policy
1030 // should use it for min but calculate the initial young size
1031 // using NewRatio.
1032 flag_value = 20 * M;
1033 FLAG_SET_ERGO(uintx, NewSize, flag_value);
1034 verify_min(flag_value);
1035 verify_scaled_initial(InitialHeapSize);
1036
1037 restore_flags();
1038
1039 }
1040
1041 static void verify_min(size_t expected) {
1042 MarkSweepPolicy msp;
1043 msp.initialize_all();
1044
1045 assert(msp.min_gen0_size() <= expected, err_msg("%zu > %zu", msp.min_gen0_size(), expected));
1046 }
1047
1048 static void verify_initial(size_t expected) {
1049 MarkSweepPolicy msp;
1050 msp.initialize_all();
1051
1052 assert(msp.initial_gen0_size() == expected, err_msg("%zu != %zu", msp.initial_gen0_size(), expected));
1053 }
1054
1055 static void verify_scaled_initial(size_t initial_heap_size) {
1056 MarkSweepPolicy msp;
1057 msp.initialize_all();
1058
1059 size_t expected = msp.scale_by_NewRatio_aligned(initial_heap_size);
1060 assert(msp.initial_gen0_size() == expected, err_msg("%zu != %zu", msp.initial_gen0_size(), expected));
1061 assert(FLAG_IS_ERGO(NewSize) && NewSize == expected,
1062 err_msg("NewSize should have been set ergonomically to %zu, but was %zu", expected, NewSize));
1063 }
1064
1065 private:
1066 static size_t original_InitialHeapSize;
1067 static size_t original_MaxHeapSize;
1068 static size_t original_MaxNewSize;
1069 static size_t original_MinHeapDeltaBytes;
1070 static size_t original_NewSize;
1071 static size_t original_OldSize;
1072
1073 static void save_flags() {
1074 original_InitialHeapSize = InitialHeapSize;
1075 original_MaxHeapSize = MaxHeapSize;
1076 original_MaxNewSize = MaxNewSize;
1077 original_MinHeapDeltaBytes = MinHeapDeltaBytes;
1078 original_NewSize = NewSize;
1079 original_OldSize = OldSize;
1080 }
1081
1082 static void restore_flags() {
1083 InitialHeapSize = original_InitialHeapSize;
1084 MaxHeapSize = original_MaxHeapSize;
1085 MaxNewSize = original_MaxNewSize;
1086 MinHeapDeltaBytes = original_MinHeapDeltaBytes;
1087 NewSize = original_NewSize;
1088 OldSize = original_OldSize;
1089 }
1090 };
1091
1092 size_t TestGenCollectorPolicy::original_InitialHeapSize = 0;
1093 size_t TestGenCollectorPolicy::original_MaxHeapSize = 0;
1094 size_t TestGenCollectorPolicy::original_MaxNewSize = 0;
1095 size_t TestGenCollectorPolicy::original_MinHeapDeltaBytes = 0;
1096 size_t TestGenCollectorPolicy::original_NewSize = 0;
1097 size_t TestGenCollectorPolicy::original_OldSize = 0;
1098
1099 void TestNewSize_test() {
1100 TestGenCollectorPolicy::test();
1101 }
1102
1103 #endif