116 } else { 117 max_survivor_size = size / InitialSurvivorRatio; 118 119 // round the survivor space size down to the nearest alignment 120 // and make sure its size is greater than 0. 121 max_survivor_size = align_size_down(max_survivor_size, alignment); 122 max_survivor_size = MAX2(max_survivor_size, alignment); 123 124 // set the maximum size of eden to be the size of the young gen 125 // less two times the survivor size when the generation is 100% 126 // committed. The minimum survivor size for -UseAdaptiveSizePolicy 127 // is dependent on the committed portion (current capacity) of the 128 // generation - the less space committed, the smaller the survivor 129 // space, possibly as small as an alignment. However, we are interested 130 // in the case where the young generation is 100% committed, as this 131 // is the point where eden reachs its maximum size. At this point, 132 // the size of a survivor space is max_survivor_size. 133 max_eden_size = size - 2 * max_survivor_size; 134 } 135 136 _eden_counters = new SpaceCounters("eden", 0, max_eden_size, _eden_space, 137 _gen_counters); 138 _from_counters = new SpaceCounters("s0", 1, max_survivor_size, _from_space, 139 _gen_counters); 140 _to_counters = new SpaceCounters("s1", 2, max_survivor_size, _to_space, 141 _gen_counters); 142 143 compute_initial_space_boundaries(); 144 } 145 146 void PSYoungGen::compute_initial_space_boundaries() { 147 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); 148 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); 149 150 // Compute sizes 151 size_t alignment = heap->intra_heap_alignment(); 152 size_t size = virtual_space()->committed_size(); 153 154 size_t survivor_size = size / InitialSurvivorRatio; 155 survivor_size = align_size_down(survivor_size, alignment); 156 // ... but never less than an alignment 157 survivor_size = MAX2(survivor_size, alignment); 158 159 // Young generation is eden + 2 survivor spaces 160 size_t eden_size = size - (2 * survivor_size); 161 162 // Now go ahead and set 'em. 163 set_space_boundaries(eden_size, survivor_size); 164 space_invariants(); 165 166 if (UsePerfData) { 167 _eden_counters->update_capacity(); 168 _from_counters->update_capacity(); 169 _to_counters->update_capacity(); 170 } 171 } 172 173 void PSYoungGen::set_space_boundaries(size_t eden_size, size_t survivor_size) { 174 assert(eden_size < virtual_space()->committed_size(), "just checking"); 175 assert(eden_size > 0 && survivor_size > 0, "just checking"); 176 177 // Initial layout is Eden, to, from. After swapping survivor spaces, 178 // that leaves us with Eden, from, to, which is step one in our two 179 // step resize-with-live-data procedure. 180 char *eden_start = virtual_space()->low(); 181 char *to_start = eden_start + eden_size; 182 char *from_start = to_start + survivor_size; 183 char *from_end = from_start + survivor_size; 184 185 assert(from_end == virtual_space()->high(), "just checking"); 932 _from_counters->update_all(); 933 _to_counters->update_all(); 934 _gen_counters->update_all(); 935 } 936 } 937 938 void PSYoungGen::verify(bool allow_dirty) { 939 eden_space()->verify(allow_dirty); 940 from_space()->verify(allow_dirty); 941 to_space()->verify(allow_dirty); 942 } 943 944 #ifndef PRODUCT 945 void PSYoungGen::record_spaces_top() { 946 assert(ZapUnusedHeapArea, "Not mangling unused space"); 947 eden_space()->set_top_for_allocations(); 948 from_space()->set_top_for_allocations(); 949 to_space()->set_top_for_allocations(); 950 } 951 #endif | 116 } else { 117 max_survivor_size = size / InitialSurvivorRatio; 118 119 // round the survivor space size down to the nearest alignment 120 // and make sure its size is greater than 0. 121 max_survivor_size = align_size_down(max_survivor_size, alignment); 122 max_survivor_size = MAX2(max_survivor_size, alignment); 123 124 // set the maximum size of eden to be the size of the young gen 125 // less two times the survivor size when the generation is 100% 126 // committed. The minimum survivor size for -UseAdaptiveSizePolicy 127 // is dependent on the committed portion (current capacity) of the 128 // generation - the less space committed, the smaller the survivor 129 // space, possibly as small as an alignment. However, we are interested 130 // in the case where the young generation is 100% committed, as this 131 // is the point where eden reachs its maximum size. At this point, 132 // the size of a survivor space is max_survivor_size. 133 max_eden_size = size - 2 * max_survivor_size; 134 } 135 136 _max_eden_size = max_eden_size; 137 _max_survivor_size = max_survivor_size; 138 139 _eden_counters = new SpaceCounters("eden", 0, max_eden_size, _eden_space, 140 _gen_counters); 141 _from_counters = new SpaceCounters("s0", 1, max_survivor_size, _from_space, 142 _gen_counters); 143 _to_counters = new SpaceCounters("s1", 2, max_survivor_size, _to_space, 144 _gen_counters); 145 146 compute_initial_space_boundaries(); 147 } 148 149 void PSYoungGen::compute_initial_space_boundaries() { 150 ParallelScavengeHeap* heap = (ParallelScavengeHeap*)Universe::heap(); 151 assert(heap->kind() == CollectedHeap::ParallelScavengeHeap, "Sanity"); 152 153 // Compute sizes 154 size_t alignment = heap->intra_heap_alignment(); 155 size_t size = virtual_space()->committed_size(); 156 157 size_t survivor_size = size / InitialSurvivorRatio; 158 survivor_size = align_size_down(survivor_size, alignment); 159 // ... but never less than an alignment 160 survivor_size = MAX2(survivor_size, alignment); 161 162 // Young generation is eden + 2 survivor spaces 163 size_t eden_size = size - (2 * survivor_size); 164 165 // Now go ahead and set 'em. 166 set_space_boundaries(eden_size, survivor_size); 167 space_invariants(); 168 169 _init_survivor_size = survivor_size; 170 _init_eden_size = eden_size; 171 172 if (UsePerfData) { 173 _eden_counters->update_capacity(); 174 _from_counters->update_capacity(); 175 _to_counters->update_capacity(); 176 } 177 } 178 179 void PSYoungGen::set_space_boundaries(size_t eden_size, size_t survivor_size) { 180 assert(eden_size < virtual_space()->committed_size(), "just checking"); 181 assert(eden_size > 0 && survivor_size > 0, "just checking"); 182 183 // Initial layout is Eden, to, from. After swapping survivor spaces, 184 // that leaves us with Eden, from, to, which is step one in our two 185 // step resize-with-live-data procedure. 186 char *eden_start = virtual_space()->low(); 187 char *to_start = eden_start + eden_size; 188 char *from_start = to_start + survivor_size; 189 char *from_end = from_start + survivor_size; 190 191 assert(from_end == virtual_space()->high(), "just checking"); 938 _from_counters->update_all(); 939 _to_counters->update_all(); 940 _gen_counters->update_all(); 941 } 942 } 943 944 void PSYoungGen::verify(bool allow_dirty) { 945 eden_space()->verify(allow_dirty); 946 from_space()->verify(allow_dirty); 947 to_space()->verify(allow_dirty); 948 } 949 950 #ifndef PRODUCT 951 void PSYoungGen::record_spaces_top() { 952 assert(ZapUnusedHeapArea, "Not mangling unused space"); 953 eden_space()->set_top_for_allocations(); 954 from_space()->set_top_for_allocations(); 955 to_space()->set_top_for_allocations(); 956 } 957 #endif 958 959 void PSYoungGen::try_to_expand_by(size_t expand_bytes) { 960 size_t available_bytes = max_size() - capacity_in_bytes(); 961 if (available_bytes == 0) { 962 // cannot expand 963 return; 964 } 965 size_t eden_available_bytes = _max_eden_size - eden_space()->used_in_bytes(); 966 size_t survivor_available_bytes = _max_survivor_size - from_space()->used_in_bytes(); 967 size_t eden_expand_bytes = 968 (size_t) (expand_bytes * ((double) eden_available_bytes / available_bytes)); 969 size_t survivor_expand_bytes = 970 (size_t) (expand_bytes * ((double) survivor_available_bytes / available_bytes)); 971 972 // Don't expand unless it's significant 973 if (eden_expand_bytes < MinHeapDeltaBytes) { 974 eden_expand_bytes = 0; 975 } 976 if (survivor_expand_bytes < MinHeapDeltaBytes) { 977 survivor_expand_bytes = 0; 978 } 979 980 if (eden_expand_bytes == 0 && survivor_expand_bytes == 0) { 981 return; // no change, so return now 982 } 983 984 size_t eden_desired_capacity = 985 eden_space()->capacity_in_bytes() + eden_expand_bytes; 986 eden_desired_capacity = MIN2(eden_desired_capacity, _max_eden_size); 987 eden_desired_capacity = align_size_down(eden_desired_capacity, 988 virtual_space()->alignment()); 989 990 size_t survivor_desired_capacity = 991 from_space()->capacity_in_bytes() + survivor_expand_bytes; 992 survivor_desired_capacity = MIN2(survivor_desired_capacity, _max_survivor_size); 993 survivor_desired_capacity = align_size_down(survivor_desired_capacity, 994 virtual_space()->alignment()); 995 996 if (eden_desired_capacity == eden_space()->capacity_in_bytes() 997 && survivor_desired_capacity == from_space()->capacity_in_bytes()) { 998 return; // no change, so return now 999 } 1000 1001 if (PrintGC) { 1002 gclog_or_tty->print_cr(" Resizing young gen. expand_bytes=%d,%d", 1003 eden_expand_bytes, survivor_expand_bytes); 1004 gclog_or_tty->print("BEFORE: Young Gen: "); 1005 gclog_or_tty->print("eden capacity : " SIZE_FORMAT ", ", 1006 eden_space()->capacity_in_bytes()); 1007 gclog_or_tty->print("eden used : " SIZE_FORMAT ", " , 1008 eden_space()->used_in_bytes()); 1009 gclog_or_tty->print("survivor capacity : " SIZE_FORMAT ", ", 1010 from_space()->capacity_in_bytes()); 1011 gclog_or_tty->print_cr("survivor used : " SIZE_FORMAT ", " , 1012 from_space()->used_in_bytes()); 1013 } 1014 1015 resize(eden_desired_capacity, survivor_desired_capacity); 1016 1017 if (PrintGC) { 1018 gclog_or_tty->print("AFTER: Young Gen: "); 1019 gclog_or_tty->print("eden capacity : " SIZE_FORMAT ", ", 1020 eden_space()->capacity_in_bytes()); 1021 gclog_or_tty->print("eden used : " SIZE_FORMAT ", " , 1022 eden_space()->used_in_bytes()); 1023 gclog_or_tty->print("survivor capacity : " SIZE_FORMAT ", ", 1024 from_space()->capacity_in_bytes()); 1025 gclog_or_tty->print_cr("survivor used : " SIZE_FORMAT ", " , 1026 from_space()->used_in_bytes()); 1027 } 1028 } 1029 1030 void PSYoungGen::try_to_shrink_by(size_t shrink_bytes) { 1031 size_t free_bytes = capacity_in_bytes() - used_in_bytes(); 1032 if (free_bytes == 0) { 1033 // cannot shrink 1034 return; 1035 } 1036 size_t eden_free_bytes = eden_space()->capacity_in_bytes() - eden_space()->used_in_bytes(); 1037 size_t survivor_free_bytes = from_space()->capacity_in_bytes() - from_space()->used_in_bytes(); 1038 size_t eden_shrink_bytes = 1039 (size_t) (shrink_bytes * ((double) eden_free_bytes / free_bytes)); 1040 size_t survivor_shrink_bytes = 1041 (size_t) (shrink_bytes * ((double) survivor_free_bytes / free_bytes)); 1042 1043 // Don't shrink unless it's significant 1044 if (eden_shrink_bytes < MinHeapDeltaBytes) { 1045 eden_shrink_bytes = 0; 1046 } 1047 if (survivor_shrink_bytes < MinHeapDeltaBytes) { 1048 survivor_shrink_bytes = 0; 1049 } 1050 1051 if (eden_shrink_bytes == 0 && survivor_shrink_bytes == 0) { 1052 return; // no change, so return now 1053 } 1054 1055 size_t eden_desired_capacity = 1056 eden_space()->capacity_in_bytes() - eden_shrink_bytes; 1057 eden_desired_capacity = MAX2(eden_desired_capacity, _init_eden_size); 1058 assert(eden_space()->used_in_bytes() <= eden_desired_capacity, "sanity check"); 1059 eden_desired_capacity = align_size_down(eden_desired_capacity, 1060 virtual_space()->alignment()); 1061 1062 size_t survivor_desired_capacity = 1063 from_space()->capacity_in_bytes() - survivor_shrink_bytes; 1064 survivor_desired_capacity = MAX2(survivor_desired_capacity, _init_survivor_size); 1065 assert(from_space()->used_in_bytes() <= survivor_desired_capacity, "sanity check"); 1066 survivor_desired_capacity = align_size_down(survivor_desired_capacity, 1067 virtual_space()->alignment()); 1068 1069 if (eden_desired_capacity == eden_space()->capacity_in_bytes() 1070 && survivor_desired_capacity == from_space()->capacity_in_bytes()) { 1071 return; // no change, so return now 1072 } 1073 1074 if (PrintGC) { 1075 gclog_or_tty->print_cr(" Resizing young gen. shrink_bytes=%d,%d", 1076 eden_shrink_bytes, survivor_shrink_bytes); 1077 gclog_or_tty->print("BEFORE: Young Gen: "); 1078 gclog_or_tty->print("eden capacity : " SIZE_FORMAT ", ", 1079 eden_space()->capacity_in_bytes()); 1080 gclog_or_tty->print("eden used : " SIZE_FORMAT ", " , 1081 eden_space()->used_in_bytes()); 1082 gclog_or_tty->print("survivor capacity : " SIZE_FORMAT ", ", 1083 from_space()->capacity_in_bytes()); 1084 gclog_or_tty->print_cr("survivor used : " SIZE_FORMAT ", " , 1085 from_space()->used_in_bytes()); 1086 } 1087 1088 resize(eden_desired_capacity, survivor_desired_capacity); 1089 1090 if (PrintGC) { 1091 gclog_or_tty->print("AFTER: Young Gen: "); 1092 gclog_or_tty->print("eden capacity : " SIZE_FORMAT ", ", 1093 eden_space()->capacity_in_bytes()); 1094 gclog_or_tty->print("eden used : " SIZE_FORMAT ", " , 1095 eden_space()->used_in_bytes()); 1096 gclog_or_tty->print("survivor capacity : " SIZE_FORMAT ", ", 1097 from_space()->capacity_in_bytes()); 1098 gclog_or_tty->print_cr("survivor used : " SIZE_FORMAT ", " , 1099 from_space()->used_in_bytes()); 1100 } 1101 } |