@@ -1586,7 +1586,7 @@ class PatchLoadedRegionPointers: public BitMapClosure {
1586
1586
};
1587
1587
1588
1588
int HeapShared::init_loaded_regions (FileMapInfo* mapinfo, LoadedArchiveHeapRegion* loaded_regions,
1589
- uintptr_t * buffer_ret ) {
1589
+ MemRegion& archive_space ) {
1590
1590
size_t total_bytes = 0 ;
1591
1591
int num_loaded_regions = 0 ;
1592
1592
for (int i = MetaspaceShared::first_archive_heap_region;
@@ -1604,12 +1604,16 @@ int HeapShared::init_loaded_regions(FileMapInfo* mapinfo, LoadedArchiveHeapRegio
1604
1604
}
1605
1605
1606
1606
assert (is_aligned (total_bytes, HeapWordSize), " must be" );
1607
- uintptr_t buffer = (uintptr_t )
1608
- Universe::heap ()->allocate_loaded_archive_space (total_bytes / HeapWordSize);
1609
- _loaded_heap_bottom = buffer;
1610
- _loaded_heap_top = buffer + total_bytes;
1607
+ size_t word_size = total_bytes / HeapWordSize;
1608
+ HeapWord* buffer = Universe::heap ()->allocate_loaded_archive_space (word_size);
1609
+ if (buffer == nullptr ) {
1610
+ return 0 ;
1611
+ }
1612
+
1613
+ archive_space = MemRegion (buffer, word_size);
1614
+ _loaded_heap_bottom = (uintptr_t )archive_space.start ();
1615
+ _loaded_heap_top = _loaded_heap_bottom + total_bytes;
1611
1616
1612
- *buffer_ret = buffer;
1613
1617
return num_loaded_regions;
1614
1618
}
1615
1619
@@ -1638,15 +1642,17 @@ bool HeapShared::load_regions(FileMapInfo* mapinfo, LoadedArchiveHeapRegion* loa
1638
1642
LoadedArchiveHeapRegion* ri = &loaded_regions[i];
1639
1643
FileMapRegion* r = mapinfo->space_at (ri->_region_index );
1640
1644
1641
- if (!mapinfo->read_region (ri->_region_index , (char *)load_address, r->used ())) {
1645
+ if (!mapinfo->read_region (ri->_region_index , (char *)load_address, r->used (), /* do_commit = */ false )) {
1642
1646
// There's no easy way to free the buffer, so we will fill it with zero later
1643
1647
// in fill_failed_loaded_region(), and it will eventually be GC'ed.
1644
1648
log_warning (cds)(" Loading of heap region %d has failed. Archived objects are disabled" , i);
1645
1649
_loading_failed = true ;
1646
1650
return false ;
1647
1651
}
1648
- log_info (cds)(" Loaded heap region #%d at base " INTPTR_FORMAT " size = " SIZE_FORMAT_W (8 ) " bytes, delta = " INTX_FORMAT,
1649
- ri->_region_index , load_address, ri->_region_size , ri->_runtime_offset );
1652
+ log_info (cds)(" Loaded heap region #%d at base " INTPTR_FORMAT " top " INTPTR_FORMAT
1653
+ " size " SIZE_FORMAT_W (6 ) " delta " INTX_FORMAT,
1654
+ ri->_region_index , load_address, load_address + ri->_region_size ,
1655
+ ri->_region_size , ri->_runtime_offset );
1650
1656
1651
1657
uintptr_t oopmap = bitmap_base + r->oopmap_offset ();
1652
1658
BitMapView bm ((BitMap::bm_word_t *)oopmap, r->oopmap_size_in_bits ());
@@ -1675,10 +1681,14 @@ bool HeapShared::load_heap_regions(FileMapInfo* mapinfo) {
1675
1681
LoadedArchiveHeapRegion loaded_regions[MetaspaceShared::max_num_heap_regions];
1676
1682
memset (loaded_regions, 0 , sizeof (loaded_regions));
1677
1683
1678
- uintptr_t buffer;
1679
- int num_loaded_regions = init_loaded_regions (mapinfo, loaded_regions, &buffer);
1680
- sort_loaded_regions (loaded_regions, num_loaded_regions, buffer);
1681
- if (!load_regions (mapinfo, loaded_regions, num_loaded_regions, buffer)) {
1684
+ MemRegion archive_space;
1685
+ int num_loaded_regions = init_loaded_regions (mapinfo, loaded_regions, archive_space);
1686
+ if (num_loaded_regions <= 0 ) {
1687
+ return false ;
1688
+ }
1689
+ sort_loaded_regions (loaded_regions, num_loaded_regions, (uintptr_t )archive_space.start ());
1690
+ if (!load_regions (mapinfo, loaded_regions, num_loaded_regions, (uintptr_t )archive_space.start ())) {
1691
+ assert (_loading_failed, " must be" );
1682
1692
return false ;
1683
1693
}
1684
1694
@@ -1711,7 +1721,15 @@ class VerifyLoadedHeapEmbeddedPointers: public BasicOopIterateClosure {
1711
1721
}
1712
1722
};
1713
1723
1714
- void HeapShared::verify_loaded_heap () {
1724
+ void HeapShared::finish_initialization () {
1725
+ if (is_loaded ()) {
1726
+ HeapWord* bottom = (HeapWord*)_loaded_heap_bottom;
1727
+ HeapWord* top = (HeapWord*)_loaded_heap_top;
1728
+
1729
+ MemRegion archive_space = MemRegion (bottom, top);
1730
+ Universe::heap ()->complete_loaded_archive_space (archive_space);
1731
+ }
1732
+
1715
1733
if (VerifyArchivedFields <= 0 || !is_loaded ()) {
1716
1734
return ;
1717
1735
}
@@ -1739,9 +1757,12 @@ void HeapShared::verify_loaded_heap() {
1739
1757
1740
1758
void HeapShared::fill_failed_loaded_region () {
1741
1759
assert (_loading_failed, " must be" );
1742
- HeapWord* bottom = (HeapWord*)_loaded_heap_bottom;
1743
- HeapWord* top = (HeapWord*)_loaded_heap_top;
1744
- Universe::heap ()->fill_with_objects (bottom, top - bottom);
1760
+ if (_loaded_heap_bottom != 0 ) {
1761
+ assert (_loaded_heap_top != 0 , " must be" );
1762
+ HeapWord* bottom = (HeapWord*)_loaded_heap_bottom;
1763
+ HeapWord* top = (HeapWord*)_loaded_heap_top;
1764
+ Universe::heap ()->fill_with_objects (bottom, top - bottom);
1765
+ }
1745
1766
}
1746
1767
1747
1768
#endif // INCLUDE_CDS_JAVA_HEAP
0 commit comments