1 /*
2 * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation.
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 *
91 // While there are no constraints in the GC code that HeapWordSize
92 // be any particular value, there are multiple other areas in the
93 // system which believe this to be true (e.g. oop->object_size in some
94 // cases incorrectly returns the size in wordSize units rather than
95 // HeapWordSize).
96 guarantee(HeapWordSize == wordSize, "HeapWordSize must equal wordSize");
97
98 // The heap must be at least as aligned as generations.
99 size_t gen_alignment = Generation::GenGrain;
100
101 _gen_specs = gen_policy()->generations();
102
103 // Make sure the sizes are all aligned.
104 for (i = 0; i < _n_gens; i++) {
105 _gen_specs[i]->align(gen_alignment);
106 }
107
108 // Allocate space for the heap.
109
110 char* heap_address;
111 size_t total_reserved = 0;
112 ReservedSpace heap_rs;
113
114 size_t heap_alignment = collector_policy()->heap_alignment();
115
116 heap_address = allocate(heap_alignment, &total_reserved, &heap_rs);
117
118 if (!heap_rs.is_reserved()) {
119 vm_shutdown_during_initialization(
120 "Could not reserve enough space for object heap");
121 return JNI_ENOMEM;
122 }
123
124 initialize_reserved_region((HeapWord*)heap_rs.base(), (HeapWord*)(heap_rs.base() + heap_rs.size()));
125
126 _rem_set = collector_policy()->create_rem_set(reserved_region());
127 set_barrier_set(rem_set()->bs());
128
129 _gch = this;
130
131 for (i = 0; i < _n_gens; i++) {
132 ReservedSpace this_rs = heap_rs.first_part(_gen_specs[i]->max_size(), false, false);
133 _gens[i] = _gen_specs[i]->init(this_rs, i, rem_set());
134 heap_rs = heap_rs.last_part(_gen_specs[i]->max_size());
135 }
136 clear_incremental_collection_failed();
137
138 #if INCLUDE_ALL_GCS
139 // If we are running CMS, create the collector responsible
140 // for collecting the CMS generations.
141 if (collector_policy()->is_concurrent_mark_sweep_policy()) {
142 bool success = create_cms_collector();
143 if (!success) return JNI_ENOMEM;
144 }
145 #endif // INCLUDE_ALL_GCS
146
147 return JNI_OK;
148 }
149
150
151 char* GenCollectedHeap::allocate(size_t alignment,
152 size_t* _total_reserved,
153 ReservedSpace* heap_rs){
154 const char overflow_msg[] = "The size of the object heap + VM data exceeds "
155 "the maximum representable size";
156
157 // Now figure out the total size.
158 size_t total_reserved = 0;
159 const size_t pageSize = UseLargePages ?
160 os::large_page_size() : os::vm_page_size();
161
162 assert(alignment % pageSize == 0, "Must be");
163
164 for (int i = 0; i < _n_gens; i++) {
165 total_reserved += _gen_specs[i]->max_size();
166 if (total_reserved < _gen_specs[i]->max_size()) {
167 vm_exit_during_initialization(overflow_msg);
168 }
169 }
170 assert(total_reserved % alignment == 0,
171 err_msg("Gen size; total_reserved=" SIZE_FORMAT ", alignment="
172 SIZE_FORMAT, total_reserved, alignment));
173
174 *_total_reserved = total_reserved;
175
176 *heap_rs = Universe::reserve_heap(total_reserved, alignment);
177 return heap_rs->base();
178 }
179
180
181 void GenCollectedHeap::post_initialize() {
182 SharedHeap::post_initialize();
183 GenCollectorPolicy *policy = (GenCollectorPolicy *)collector_policy();
184 guarantee(policy->is_generation_policy(), "Illegal policy type");
185 assert((get_gen(0)->kind() == Generation::DefNew) ||
186 (get_gen(0)->kind() == Generation::ParNew),
187 "Wrong youngest generation type");
188 DefNewGeneration* def_new_gen = (DefNewGeneration*)get_gen(0);
189
190 Generation* old_gen = get_gen(1);
191 assert(old_gen->kind() == Generation::ConcurrentMarkSweep ||
192 old_gen->kind() == Generation::MarkSweepCompact,
193 "Wrong generation kind");
194
|
1 /*
2 * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation.
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 *
91 // While there are no constraints in the GC code that HeapWordSize
92 // be any particular value, there are multiple other areas in the
93 // system which believe this to be true (e.g. oop->object_size in some
94 // cases incorrectly returns the size in wordSize units rather than
95 // HeapWordSize).
96 guarantee(HeapWordSize == wordSize, "HeapWordSize must equal wordSize");
97
98 // The heap must be at least as aligned as generations.
99 size_t gen_alignment = Generation::GenGrain;
100
101 _gen_specs = gen_policy()->generations();
102
103 // Make sure the sizes are all aligned.
104 for (i = 0; i < _n_gens; i++) {
105 _gen_specs[i]->align(gen_alignment);
106 }
107
108 // Allocate space for the heap.
109
110 char* heap_address;
111 ReservedSpace heap_rs;
112
113 size_t heap_alignment = collector_policy()->heap_alignment();
114
115 heap_address = allocate(heap_alignment, &heap_rs);
116
117 if (!heap_rs.is_reserved()) {
118 vm_shutdown_during_initialization(
119 "Could not reserve enough space for object heap");
120 return JNI_ENOMEM;
121 }
122
123 initialize_reserved_region((HeapWord*)heap_rs.base(), (HeapWord*)(heap_rs.base() + heap_rs.size()));
124
125 _rem_set = collector_policy()->create_rem_set(reserved_region());
126 set_barrier_set(rem_set()->bs());
127
128 _gch = this;
129
130 for (i = 0; i < _n_gens; i++) {
131 ReservedSpace this_rs = heap_rs.first_part(_gen_specs[i]->max_size(), false, false);
132 _gens[i] = _gen_specs[i]->init(this_rs, i, rem_set());
133 heap_rs = heap_rs.last_part(_gen_specs[i]->max_size());
134 }
135 clear_incremental_collection_failed();
136
137 #if INCLUDE_ALL_GCS
138 // If we are running CMS, create the collector responsible
139 // for collecting the CMS generations.
140 if (collector_policy()->is_concurrent_mark_sweep_policy()) {
141 bool success = create_cms_collector();
142 if (!success) return JNI_ENOMEM;
143 }
144 #endif // INCLUDE_ALL_GCS
145
146 return JNI_OK;
147 }
148
149
150 char* GenCollectedHeap::allocate(size_t alignment,
151 ReservedSpace* heap_rs){
152 const char overflow_msg[] = "The size of the object heap + VM data exceeds "
153 "the maximum representable size";
154
155 // Now figure out the total size.
156 size_t total_reserved = 0;
157 const size_t pageSize = UseLargePages ?
158 os::large_page_size() : os::vm_page_size();
159
160 assert(alignment % pageSize == 0, "Must be");
161
162 for (int i = 0; i < _n_gens; i++) {
163 total_reserved += _gen_specs[i]->max_size();
164 if (total_reserved < _gen_specs[i]->max_size()) {
165 vm_exit_during_initialization(overflow_msg);
166 }
167 }
168 assert(total_reserved % alignment == 0,
169 err_msg("Gen size; total_reserved=" SIZE_FORMAT ", alignment="
170 SIZE_FORMAT, total_reserved, alignment));
171
172 *heap_rs = Universe::reserve_heap(total_reserved, alignment);
173 return heap_rs->base();
174 }
175
176
177 void GenCollectedHeap::post_initialize() {
178 SharedHeap::post_initialize();
179 GenCollectorPolicy *policy = (GenCollectorPolicy *)collector_policy();
180 guarantee(policy->is_generation_policy(), "Illegal policy type");
181 assert((get_gen(0)->kind() == Generation::DefNew) ||
182 (get_gen(0)->kind() == Generation::ParNew),
183 "Wrong youngest generation type");
184 DefNewGeneration* def_new_gen = (DefNewGeneration*)get_gen(0);
185
186 Generation* old_gen = get_gen(1);
187 assert(old_gen->kind() == Generation::ConcurrentMarkSweep ||
188 old_gen->kind() == Generation::MarkSweepCompact,
189 "Wrong generation kind");
190
|