188 size_t commit = MAX2(min_bytes, preferred_bytes);
189 commit = MIN2(commit, uncommitted);
190 assert(commit <= uncommitted, "sanity");
191
192 if (!_vs->expand_by(commit, false)) {
193 vm_exit_during_initialization(err_msg("Failed to expand shared space to " SIZE_FORMAT " bytes",
194 need_committed_size));
195 }
196
197 const char* which;
198 if (_rs->base() == (char*)MetaspaceShared::symbol_rs_base()) {
199 which = "symbol";
200 } else {
201 which = "shared";
202 }
203 log_debug(cds)("Expanding %s spaces by " SIZE_FORMAT_W(7) " bytes [total " SIZE_FORMAT_W(9) " bytes ending at %p]",
204 which, commit, _vs->actual_committed_size(), _vs->high());
205 }
206
207
208 char* DumpRegion::allocate(size_t num_bytes) {
209 char* p = (char*)align_up(_top, (size_t)SharedSpaceObjectAlignment);
210 char* newtop = p + align_up(num_bytes, (size_t)SharedSpaceObjectAlignment);
211 expand_top_to(newtop);
212 memset(p, 0, newtop - p);
213 return p;
214 }
215
216 void DumpRegion::append_intptr_t(intptr_t n, bool need_to_mark) {
217 assert(is_aligned(_top, sizeof(intptr_t)), "bad alignment");
218 intptr_t *p = (intptr_t*)_top;
219 char* newtop = _top + sizeof(intptr_t);
220 expand_top_to(newtop);
221 *p = n;
222 if (need_to_mark) {
223 ArchivePtrMarker::mark_pointer(p);
224 }
225 }
226
227 void DumpRegion::print(size_t total_bytes) const {
228 log_debug(cds)("%-3s space: " SIZE_FORMAT_W(9) " [ %4.1f%% of total] out of " SIZE_FORMAT_W(9) " bytes [%5.1f%% used] at " INTPTR_FORMAT,
229 _name, used(), percent_of(used(), total_bytes), reserved(), percent_of(used(), reserved()),
230 p2i(ArchiveBuilder::current()->to_requested(_base)));
231 }
232
233 void DumpRegion::print_out_of_space_msg(const char* failing_region, size_t needed_bytes) {
234 log_error(cds)("[%-8s] " PTR_FORMAT " - " PTR_FORMAT " capacity =%9d, allocated =%9d",
235 _name, p2i(_base), p2i(_top), int(_end - _base), int(_top - _base));
292 intptr_t obj = nextPtr();
293 assert((intptr_t)obj >= 0 || (intptr_t)obj < -100,
294 "hit tag while initializing ptrs.");
295 *p = (void*)obj;
296 }
297
298 void ReadClosure::do_u4(u4* p) {
299 intptr_t obj = nextPtr();
300 *p = (u4)(uintx(obj));
301 }
302
303 void ReadClosure::do_bool(bool* p) {
304 intptr_t obj = nextPtr();
305 *p = (bool)(uintx(obj));
306 }
307
308 void ReadClosure::do_tag(int tag) {
309 int old_tag;
310 old_tag = (int)(intptr_t)nextPtr();
311 // do_int(&old_tag);
312 assert(tag == old_tag, "old tag doesn't match");
313 FileMapInfo::assert_mark(tag == old_tag);
314 }
315
316 void ReadClosure::do_oop(oop *p) {
317 if (UseCompressedOops) {
318 narrowOop o = CompressedOops::narrow_oop_cast(nextPtr());
319 if (CompressedOops::is_null(o) || !ArchiveHeapLoader::is_fully_available()) {
320 *p = nullptr;
321 } else {
322 assert(ArchiveHeapLoader::can_use(), "sanity");
323 assert(ArchiveHeapLoader::is_fully_available(), "must be");
324 *p = ArchiveHeapLoader::decode_from_archive(o);
325 }
326 } else {
327 intptr_t dumptime_oop = nextPtr();
328 if (dumptime_oop == 0 || !ArchiveHeapLoader::is_fully_available()) {
329 *p = nullptr;
330 } else {
331 assert(!ArchiveHeapLoader::is_loaded(), "ArchiveHeapLoader::can_load() is not supported for uncompessed oops");
332 intptr_t runtime_oop = dumptime_oop + ArchiveHeapLoader::mapped_heap_delta();
|
188 size_t commit = MAX2(min_bytes, preferred_bytes);
189 commit = MIN2(commit, uncommitted);
190 assert(commit <= uncommitted, "sanity");
191
192 if (!_vs->expand_by(commit, false)) {
193 vm_exit_during_initialization(err_msg("Failed to expand shared space to " SIZE_FORMAT " bytes",
194 need_committed_size));
195 }
196
197 const char* which;
198 if (_rs->base() == (char*)MetaspaceShared::symbol_rs_base()) {
199 which = "symbol";
200 } else {
201 which = "shared";
202 }
203 log_debug(cds)("Expanding %s spaces by " SIZE_FORMAT_W(7) " bytes [total " SIZE_FORMAT_W(9) " bytes ending at %p]",
204 which, commit, _vs->actual_committed_size(), _vs->high());
205 }
206
207
208 char* DumpRegion::allocate(size_t num_bytes, size_t alignment) {
209 // We align the starting address of each allocation.
210 char* p = (char*)align_up(_top, alignment);
211 char* newtop = p + num_bytes;
212 // Leave _top always SharedSpaceObjectAlignment aligned. But not more -
213 // if we allocate with large alignments, lets not waste the gaps.
214 // Ideally we would not need to align _top to anything here but CDS has
215 // a number of implicit alignment assumptions. Leaving this unaligned
216 // here will trip of at least ReadClosure (assuming word alignment) and
217 // DumpAllocStats (will get confused about counting bytes on 32-bit
218 // platforms if we align to anything less than SharedSpaceObjectAlignment
219 // here).
220 newtop = align_up(newtop, SharedSpaceObjectAlignment);
221 expand_top_to(newtop);
222 memset(p, 0, newtop - p); // todo: needed? debug_only?
223 return p;
224 }
225
226 char* DumpRegion::allocate(size_t num_bytes) {
227 return allocate(num_bytes, SharedSpaceObjectAlignment);
228 }
229
230 void DumpRegion::append_intptr_t(intptr_t n, bool need_to_mark) {
231 assert(is_aligned(_top, sizeof(intptr_t)), "bad alignment");
232 intptr_t *p = (intptr_t*)_top;
233 char* newtop = _top + sizeof(intptr_t);
234 expand_top_to(newtop);
235 *p = n;
236 if (need_to_mark) {
237 ArchivePtrMarker::mark_pointer(p);
238 }
239 }
240
241 void DumpRegion::print(size_t total_bytes) const {
242 log_debug(cds)("%-3s space: " SIZE_FORMAT_W(9) " [ %4.1f%% of total] out of " SIZE_FORMAT_W(9) " bytes [%5.1f%% used] at " INTPTR_FORMAT,
243 _name, used(), percent_of(used(), total_bytes), reserved(), percent_of(used(), reserved()),
244 p2i(ArchiveBuilder::current()->to_requested(_base)));
245 }
246
247 void DumpRegion::print_out_of_space_msg(const char* failing_region, size_t needed_bytes) {
248 log_error(cds)("[%-8s] " PTR_FORMAT " - " PTR_FORMAT " capacity =%9d, allocated =%9d",
249 _name, p2i(_base), p2i(_top), int(_end - _base), int(_top - _base));
306 intptr_t obj = nextPtr();
307 assert((intptr_t)obj >= 0 || (intptr_t)obj < -100,
308 "hit tag while initializing ptrs.");
309 *p = (void*)obj;
310 }
311
312 void ReadClosure::do_u4(u4* p) {
313 intptr_t obj = nextPtr();
314 *p = (u4)(uintx(obj));
315 }
316
317 void ReadClosure::do_bool(bool* p) {
318 intptr_t obj = nextPtr();
319 *p = (bool)(uintx(obj));
320 }
321
322 void ReadClosure::do_tag(int tag) {
323 int old_tag;
324 old_tag = (int)(intptr_t)nextPtr();
325 // do_int(&old_tag);
326 assert(tag == old_tag, "tag doesn't match (%d, expected %d)", old_tag, tag);
327 FileMapInfo::assert_mark(tag == old_tag);
328 }
329
330 void ReadClosure::do_oop(oop *p) {
331 if (UseCompressedOops) {
332 narrowOop o = CompressedOops::narrow_oop_cast(nextPtr());
333 if (CompressedOops::is_null(o) || !ArchiveHeapLoader::is_fully_available()) {
334 *p = nullptr;
335 } else {
336 assert(ArchiveHeapLoader::can_use(), "sanity");
337 assert(ArchiveHeapLoader::is_fully_available(), "must be");
338 *p = ArchiveHeapLoader::decode_from_archive(o);
339 }
340 } else {
341 intptr_t dumptime_oop = nextPtr();
342 if (dumptime_oop == 0 || !ArchiveHeapLoader::is_fully_available()) {
343 *p = nullptr;
344 } else {
345 assert(!ArchiveHeapLoader::is_loaded(), "ArchiveHeapLoader::can_load() is not supported for uncompessed oops");
346 intptr_t runtime_oop = dumptime_oop + ArchiveHeapLoader::mapped_heap_delta();
|