8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "precompiled.hpp" 26 #include "gc/parallel/adjoiningGenerations.hpp" 27 #include "gc/parallel/adjoiningVirtualSpaces.hpp" 28 #include "gc/parallel/generationSizer.hpp" 29 #include "gc/parallel/parallelScavengeHeap.hpp" 30 #include "logging/log.hpp" 31 #include "logging/logStream.hpp" 32 #include "memory/resourceArea.hpp" 33 #include "utilities/align.hpp" 34 #include "utilities/ostream.hpp" 35 36 // If boundary moving is being used, create the young gen and old 37 // gen with ASPSYoungGen and ASPSOldGen, respectively. Revert to 38 // the old behavior otherwise (with PSYoungGen and PSOldGen). 39 40 AdjoiningGenerations::AdjoiningGenerations(ReservedSpace old_young_rs, 41 GenerationSizer* policy, 42 size_t alignment) : 43 _virtual_spaces(old_young_rs, policy->min_old_size(), 44 policy->min_young_size(), alignment) { 45 size_t init_low_byte_size = policy->initial_old_size(); 46 size_t min_low_byte_size = policy->min_old_size(); 47 size_t max_low_byte_size = policy->max_old_size(); 48 size_t init_high_byte_size = policy->initial_young_size(); 49 size_t min_high_byte_size = policy->min_young_size(); 50 size_t max_high_byte_size = policy->max_young_size(); 51 52 assert(min_low_byte_size <= init_low_byte_size && 53 init_low_byte_size <= max_low_byte_size, "Parameter check"); 54 assert(min_high_byte_size <= init_high_byte_size && 55 init_high_byte_size <= max_high_byte_size, "Parameter check"); 56 // Create the generations differently based on the option to 57 // move the boundary. 58 if (UseAdaptiveGCBoundary) { 59 // Initialize the adjoining virtual spaces. Then pass the 60 // a virtual to each generation for initialization of the 61 // generation. 62 63 // Does the actual creation of the virtual spaces 64 _virtual_spaces.initialize(max_low_byte_size, 65 init_low_byte_size, 66 init_high_byte_size); 67 68 // Place the young gen at the high end. Passes in the virtual space. 69 _young_gen = new ASPSYoungGen(_virtual_spaces.high(), 70 _virtual_spaces.high()->committed_size(), 71 min_high_byte_size, 72 _virtual_spaces.high_byte_size_limit()); 73 74 // Place the old gen at the low end. Passes in the virtual space. 75 _old_gen = new ASPSOldGen(_virtual_spaces.low(), 76 _virtual_spaces.low()->committed_size(), 77 min_low_byte_size, 78 _virtual_spaces.low_byte_size_limit(), 79 "old", 1); 80 81 young_gen()->initialize_work(); 82 assert(young_gen()->reserved().byte_size() <= young_gen()->gen_size_limit(), 83 "Consistency check"); 84 assert(old_young_rs.size() >= young_gen()->gen_size_limit(), 85 "Consistency check"); 86 87 old_gen()->initialize_work("old", 1); 88 assert(old_gen()->reserved().byte_size() <= old_gen()->gen_size_limit(), 89 "Consistency check"); 90 assert(old_young_rs.size() >= old_gen()->gen_size_limit(), 91 "Consistency check"); 92 } else { 93 94 // Layout the reserved space for the generations. 95 ReservedSpace old_rs = 96 virtual_spaces()->reserved_space().first_part(max_low_byte_size); 97 ReservedSpace heap_rs = 98 virtual_spaces()->reserved_space().last_part(max_low_byte_size); 99 ReservedSpace young_rs = heap_rs.first_part(max_high_byte_size); 100 assert(young_rs.size() == heap_rs.size(), "Didn't reserve all of the heap"); 101 102 // Create the generations. Virtual spaces are not passed in. 103 _young_gen = new PSYoungGen(init_high_byte_size, 104 min_high_byte_size, 105 max_high_byte_size); 106 _old_gen = new PSOldGen(init_low_byte_size, 107 min_low_byte_size, 108 max_low_byte_size, 109 "old", 1); 110 111 // The virtual spaces are created by the initialization of the gens. 112 _young_gen->initialize(young_rs, alignment); 113 assert(young_gen()->gen_size_limit() == young_rs.size(), 114 "Consistency check"); 115 _old_gen->initialize(old_rs, alignment, "old", 1); 116 assert(old_gen()->gen_size_limit() == old_rs.size(), "Consistency check"); 117 } 118 } 119 120 size_t AdjoiningGenerations::reserved_byte_size() { 121 return virtual_spaces()->reserved_space().size(); 122 } 123 124 void log_before_expansion(bool old, size_t expand_in_bytes, size_t change_in_bytes, size_t max_size) { 125 Log(heap, ergo) log; 126 if (!log.is_debug()) { 127 return; 128 } 129 log.debug("Before expansion of %s gen with boundary move", old ? "old" : "young"); 130 log.debug(" Requested change: " SIZE_FORMAT_HEX " Attempted change: " SIZE_FORMAT_HEX, 131 expand_in_bytes, change_in_bytes); 132 ResourceMark rm; 133 LogStream ls(log.debug()); 134 ParallelScavengeHeap::heap()->print_on(&ls); 135 log.debug(" PS%sGen max size: " SIZE_FORMAT "K", old ? "Old" : "Young", max_size/K); | 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "precompiled.hpp" 26 #include "gc/parallel/adjoiningGenerations.hpp" 27 #include "gc/parallel/adjoiningVirtualSpaces.hpp" 28 #include "gc/parallel/parallelScavengeHeap.hpp" 29 #include "gc/parallel/psSettings.hpp" 30 #include "logging/log.hpp" 31 #include "logging/logStream.hpp" 32 #include "memory/resourceArea.hpp" 33 #include "utilities/align.hpp" 34 #include "utilities/ostream.hpp" 35 36 // If boundary moving is being used, create the young gen and old 37 // gen with ASPSYoungGen and ASPSOldGen, respectively. Revert to 38 // the old behavior otherwise (with PSYoungGen and PSOldGen). 39 40 AdjoiningGenerations::AdjoiningGenerations(ReservedSpace old_young_rs, 41 const PSSettings& s) : 42 _virtual_spaces(old_young_rs, s._min_old_size, 43 s._min_young_size, s._gen_alignment) { 44 45 assert(s._min_old_size <= s._initial_old_size && 46 s._initial_old_size <= s._max_old_size, "Parameter check"); 47 assert(s._min_young_size <= s._initial_young_size && 48 s._initial_young_size <= s._max_young_size, "Parameter check"); 49 // Create the generations differently based on the option to 50 // move the boundary. 51 if (UseAdaptiveGCBoundary) { 52 // Initialize the adjoining virtual spaces. Then pass the 53 // a virtual to each generation for initialization of the 54 // generation. 55 56 // Does the actual creation of the virtual spaces 57 _virtual_spaces.initialize(s._max_old_size, 58 s._initial_old_size, 59 s._initial_young_size); 60 61 // Place the young gen at the high end. Passes in the virtual space. 62 _young_gen = new ASPSYoungGen(_virtual_spaces.high(), 63 _virtual_spaces.high()->committed_size(), 64 s._min_young_size, 65 _virtual_spaces.high_byte_size_limit()); 66 67 // Place the old gen at the low end. Passes in the virtual space. 68 _old_gen = new ASPSOldGen(_virtual_spaces.low(), 69 _virtual_spaces.low()->committed_size(), 70 s._min_old_size, 71 _virtual_spaces.low_byte_size_limit(), 72 "old", 1); 73 74 young_gen()->initialize_work(); 75 assert(young_gen()->reserved().byte_size() <= young_gen()->gen_size_limit(), 76 "Consistency check"); 77 assert(old_young_rs.size() >= young_gen()->gen_size_limit(), 78 "Consistency check"); 79 80 old_gen()->initialize_work("old", 1); 81 assert(old_gen()->reserved().byte_size() <= old_gen()->gen_size_limit(), 82 "Consistency check"); 83 assert(old_young_rs.size() >= old_gen()->gen_size_limit(), 84 "Consistency check"); 85 } else { 86 87 // Layout the reserved space for the generations. 88 ReservedSpace old_rs = 89 virtual_spaces()->reserved_space().first_part(s._max_old_size); 90 ReservedSpace heap_rs = 91 virtual_spaces()->reserved_space().last_part(s._max_old_size); 92 ReservedSpace young_rs = heap_rs.first_part(s._max_young_size); 93 assert(young_rs.size() == heap_rs.size(), "Didn't reserve all of the heap"); 94 95 // Create the generations. Virtual spaces are not passed in. 96 _young_gen = new PSYoungGen(s._initial_young_size, 97 s._min_young_size, 98 s._max_young_size); 99 _old_gen = new PSOldGen(s._initial_old_size, 100 s._min_old_size, 101 s._max_old_size, 102 "old", 1); 103 104 // The virtual spaces are created by the initialization of the gens. 105 _young_gen->initialize(young_rs, s._gen_alignment); 106 assert(young_gen()->gen_size_limit() == young_rs.size(), 107 "Consistency check"); 108 _old_gen->initialize(old_rs, s._gen_alignment, "old", 1); 109 assert(old_gen()->gen_size_limit() == old_rs.size(), "Consistency check"); 110 } 111 } 112 113 size_t AdjoiningGenerations::reserved_byte_size() { 114 return virtual_spaces()->reserved_space().size(); 115 } 116 117 void log_before_expansion(bool old, size_t expand_in_bytes, size_t change_in_bytes, size_t max_size) { 118 Log(heap, ergo) log; 119 if (!log.is_debug()) { 120 return; 121 } 122 log.debug("Before expansion of %s gen with boundary move", old ? "old" : "young"); 123 log.debug(" Requested change: " SIZE_FORMAT_HEX " Attempted change: " SIZE_FORMAT_HEX, 124 expand_in_bytes, change_in_bytes); 125 ResourceMark rm; 126 LogStream ls(log.debug()); 127 ParallelScavengeHeap::heap()->print_on(&ls); 128 log.debug(" PS%sGen max size: " SIZE_FORMAT "K", old ? "Old" : "Young", max_size/K); |