Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8270803: Reduce CDS API verbosity #4834

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1080,16 +1080,16 @@ void ArchiveBuilder::write_archive(FileMapInfo* mapinfo,
bitmap_size_in_bytes);

if (closed_heap_regions != NULL) {
_total_closed_heap_region_size = mapinfo->write_archive_heap_regions(
_total_closed_heap_region_size = mapinfo->write_heap_regions(
closed_heap_regions,
closed_heap_oopmaps,
MetaspaceShared::first_closed_archive_heap_region,
MetaspaceShared::max_closed_archive_heap_region);
_total_open_heap_region_size = mapinfo->write_archive_heap_regions(
MetaspaceShared::first_closed_heap_region,
MetaspaceShared::max_closed_heap_region);
_total_open_heap_region_size = mapinfo->write_heap_regions(
open_heap_regions,
open_heap_oopmaps,
MetaspaceShared::first_open_archive_heap_region,
MetaspaceShared::max_open_archive_heap_region);
MetaspaceShared::first_open_heap_region,
MetaspaceShared::max_open_heap_region);
}

print_region_stats(mapinfo, closed_heap_regions, open_heap_regions);
@@ -1155,12 +1155,12 @@ void ArchiveBuilder::print_bitmap_region_stats(size_t size, size_t total_size) {
size, size/double(total_size)*100.0, size);
}

void ArchiveBuilder::print_heap_region_stats(GrowableArray<MemRegion> *heap_mem,
void ArchiveBuilder::print_heap_region_stats(GrowableArray<MemRegion>* regions,
const char *name, size_t total_size) {
int arr_len = heap_mem == NULL ? 0 : heap_mem->length();
int arr_len = regions == NULL ? 0 : regions->length();
for (int i = 0; i < arr_len; i++) {
char* start = (char*)heap_mem->at(i).start();
size_t size = heap_mem->at(i).byte_size();
char* start = (char*)regions->at(i).start();
size_t size = regions->at(i).byte_size();
char* top = start + size;
log_debug(cds)("%s%d space: " SIZE_FORMAT_W(9) " [ %4.1f%% of total] out of " SIZE_FORMAT_W(9) " bytes [100.0%% used] at " INTPTR_FORMAT,
name, i, size, size/double(total_size)*100.0, size, p2i(start));
@@ -216,7 +216,7 @@ class ArchiveBuilder : public StackObj {
GrowableArray<MemRegion>* closed_heap_regions,
GrowableArray<MemRegion>* open_heap_regions);
void print_bitmap_region_stats(size_t size, size_t total_size);
void print_heap_region_stats(GrowableArray<MemRegion> *heap_mem,
void print_heap_region_stats(GrowableArray<MemRegion>* regions,
const char *name, size_t total_size);

// For global access.
@@ -307,12 +307,12 @@ void ReadClosure::do_tag(int tag) {

void ReadClosure::do_oop(oop *p) {
narrowOop o = CompressedOops::narrow_oop_cast(nextPtr());
if (CompressedOops::is_null(o) || !HeapShared::open_archive_heap_region_mapped()) {
if (CompressedOops::is_null(o) || !HeapShared::open_regions_mapped()) {
*p = NULL;
} else {
assert(HeapShared::is_heap_object_archiving_allowed(),
"Archived heap object is not allowed");
assert(HeapShared::open_archive_heap_region_mapped(),
assert(HeapShared::open_regions_mapped(),
"Open archive heap region is not mapped");
*p = HeapShared::decode_from_archive(o);
}
@@ -1406,13 +1406,13 @@ char* FileMapInfo::write_bitmap_region(const CHeapBitMap* ptrmap,

// Write out the given archive heap memory regions. GC code combines multiple
// consecutive archive GC regions into one MemRegion whenever possible and
// produces the 'heap_mem' array.
// produces the 'regions' array.
//
// If the archive heap memory size is smaller than a single dump time GC region
// size, there is only one MemRegion in the array.
//
// If the archive heap memory size is bigger than one dump time GC region size,
// the 'heap_mem' array may contain more than one consolidated MemRegions. When
// the 'regions' array may contain more than one consolidated MemRegions. When
// the first/bottom archive GC region is a partial GC region (with the empty
// portion at the higher address within the region), one MemRegion is used for
// the bottom partial archive GC region. The rest of the consecutive archive
@@ -1435,13 +1435,13 @@ char* FileMapInfo::write_bitmap_region(const CHeapBitMap* ptrmap,
// ^^^
// |
// +-- gap
size_t FileMapInfo::write_archive_heap_regions(GrowableArray<MemRegion> *heap_mem,
GrowableArray<ArchiveHeapOopmapInfo> *oopmaps,
int first_region_id, int max_num_regions) {
size_t FileMapInfo::write_heap_regions(GrowableArray<MemRegion>* regions,
GrowableArray<ArchiveHeapOopmapInfo>* oopmaps,
int first_region_id, int max_num_regions) {
assert(max_num_regions <= 2, "Only support maximum 2 memory regions");

int arr_len = heap_mem == NULL ? 0 : heap_mem->length();
if(arr_len > max_num_regions) {
int arr_len = regions == NULL ? 0 : regions->length();
if (arr_len > max_num_regions) {
fail_stop("Unable to write archive heap memory regions: "
"number of memory regions exceeds maximum due to fragmentation. "
"Please increase java heap size "
@@ -1454,8 +1454,8 @@ size_t FileMapInfo::write_archive_heap_regions(GrowableArray<MemRegion> *heap_me
char* start = NULL;
size_t size = 0;
if (i < arr_len) {
start = (char*)heap_mem->at(i).start();
size = heap_mem->at(i).byte_size();
start = (char*)regions->at(i).start();
size = regions->at(i).byte_size();
total_size += size;
}

@@ -1766,14 +1766,14 @@ address FileMapInfo::decode_start_address(FileMapRegion* spc, bool with_current_
}
}

static MemRegion *closed_archive_heap_ranges = NULL;
static MemRegion *open_archive_heap_ranges = NULL;
static int num_closed_archive_heap_ranges = 0;
static int num_open_archive_heap_ranges = 0;
static MemRegion *closed_heap_regions = NULL;
static MemRegion *open_heap_regions = NULL;
static int num_closed_heap_regions = 0;
static int num_open_heap_regions = 0;

#if INCLUDE_CDS_JAVA_HEAP
bool FileMapInfo::has_heap_regions() {
return (space_at(MetaspaceShared::first_closed_archive_heap_region)->used() > 0);
return (space_at(MetaspaceShared::first_closed_heap_region)->used() > 0);
}

// Returns the address range of the archived heap regions computed using the
@@ -1784,7 +1784,7 @@ MemRegion FileMapInfo::get_heap_regions_range_with_current_oop_encoding_mode() {
address start = (address) max_uintx;
address end = NULL;

for (int i = MetaspaceShared::first_closed_archive_heap_region;
for (int i = MetaspaceShared::first_closed_heap_region;
i <= MetaspaceShared::last_valid_region;
i++) {
FileMapRegion* si = space_at(i);
@@ -1899,7 +1899,7 @@ void FileMapInfo::map_heap_regions_impl() {
log_info(cds)("CDS heap data relocation delta = " INTX_FORMAT " bytes", delta);
HeapShared::init_narrow_oop_decoding(narrow_oop_base() + delta, narrow_oop_shift());

FileMapRegion* si = space_at(MetaspaceShared::first_closed_archive_heap_region);
FileMapRegion* si = space_at(MetaspaceShared::first_closed_heap_region);
address relocated_closed_heap_region_bottom = start_address_as_decoded_from_archive(si);
if (!is_aligned(relocated_closed_heap_region_bottom, HeapRegion::GrainBytes)) {
// Align the bottom of the closed archive heap regions at G1 region boundary.
@@ -1918,20 +1918,20 @@ void FileMapInfo::map_heap_regions_impl() {
assert(is_aligned(relocated_closed_heap_region_bottom, HeapRegion::GrainBytes),
"must be");

// Map the closed_archive_heap regions, GC does not write into the regions.
if (map_heap_data(&closed_archive_heap_ranges,
MetaspaceShared::first_closed_archive_heap_region,
MetaspaceShared::max_closed_archive_heap_region,
&num_closed_archive_heap_ranges)) {
HeapShared::set_closed_archive_heap_region_mapped();
// Map the closed_heap regions, GC does not write into the regions.
if (map_heap_regions(&closed_heap_regions,
MetaspaceShared::first_closed_heap_region,
MetaspaceShared::max_closed_heap_region,
&num_closed_heap_regions)) {
HeapShared::set_closed_regions_mapped();

// Now, map open_archive heap regions, GC can write into the regions.
if (map_heap_data(&open_archive_heap_ranges,
MetaspaceShared::first_open_archive_heap_region,
MetaspaceShared::max_open_archive_heap_region,
&num_open_archive_heap_ranges,
true /* open */)) {
HeapShared::set_open_archive_heap_region_mapped();
if (map_heap_regions(&open_heap_regions,
MetaspaceShared::first_open_heap_region,
MetaspaceShared::max_open_heap_region,
&num_open_heap_regions,
true /* open */)) {
HeapShared::set_open_regions_mapped();
HeapShared::set_roots(header()->heap_obj_roots());
}
}
@@ -1942,19 +1942,19 @@ void FileMapInfo::map_heap_regions() {
map_heap_regions_impl();
}

if (!HeapShared::closed_archive_heap_region_mapped()) {
assert(closed_archive_heap_ranges == NULL &&
num_closed_archive_heap_ranges == 0, "sanity");
if (!HeapShared::closed_regions_mapped()) {
assert(closed_heap_regions == NULL &&
num_closed_heap_regions == 0, "sanity");
}

if (!HeapShared::open_archive_heap_region_mapped()) {
assert(open_archive_heap_ranges == NULL && num_open_archive_heap_ranges == 0, "sanity");
if (!HeapShared::open_regions_mapped()) {
assert(open_heap_regions == NULL && num_open_heap_regions == 0, "sanity");
MetaspaceShared::disable_full_module_graph();
}
}

bool FileMapInfo::map_heap_data(MemRegion **heap_mem, int first,
int max, int* num, bool is_open_archive) {
bool FileMapInfo::map_heap_regions(MemRegion** regions_ret, int first,
int max, int* num_ret, bool is_open_archive) {
MemRegion* regions = MemRegion::create_array(max, mtInternal);

struct Cleanup {
@@ -1985,7 +1985,7 @@ bool FileMapInfo::map_heap_data(MemRegion **heap_mem, int first,
return false; // no archived java heap data
}

// Check that ranges are within the java heap
// Check that regions are within the java heap
if (!G1CollectedHeap::heap()->check_archive_addresses(regions, region_num)) {
log_info(cds)("UseSharedSpaces: Unable to allocate region, range is not within java heap.");
return false;
@@ -2009,7 +2009,7 @@ bool FileMapInfo::map_heap_data(MemRegion **heap_mem, int first,
si->allow_exec());
if (base == NULL || base != addr) {
// dealloc the regions from java heap
dealloc_archive_heap_regions(regions, region_num);
dealloc_heap_regions(regions, region_num);
log_info(cds)("UseSharedSpaces: Unable to map at required address in java heap. "
INTPTR_FORMAT ", size = " SIZE_FORMAT " bytes",
p2i(addr), regions[i].byte_size());
@@ -2018,44 +2018,44 @@ bool FileMapInfo::map_heap_data(MemRegion **heap_mem, int first,

if (VerifySharedSpaces && !region_crc_check(addr, regions[i].byte_size(), si->crc())) {
// dealloc the regions from java heap
dealloc_archive_heap_regions(regions, region_num);
dealloc_heap_regions(regions, region_num);
log_info(cds)("UseSharedSpaces: mapped heap regions are corrupt");
return false;
}
}

cleanup._aborted = false;
// the shared heap data is mapped successfully
*heap_mem = regions;
*num = region_num;
*regions_ret = regions;
*num_ret = region_num;
Copy link
Member

@calvinccheung calvinccheung Jul 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of num_ret, I think num_regions is easier to understand.

Copy link
Member Author

@iklam iklam Jul 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I renamed it to num_regions_ret to be consistent with regions_ret: both of them are outgoing parameters. Now their names are also consistent with the globals like closed_heap_regions and num_closed_heap_regions.

I also rearranged the parameter order to put the outgoing ones at the end.

return true;
}

void FileMapInfo::patch_archived_heap_embedded_pointers() {
void FileMapInfo::patch_heap_embedded_pointers() {
if (!_heap_pointers_need_patching) {
return;
}

log_info(cds)("patching heap embedded pointers");
patch_archived_heap_embedded_pointers(closed_archive_heap_ranges,
num_closed_archive_heap_ranges,
MetaspaceShared::first_closed_archive_heap_region);
patch_heap_embedded_pointers(closed_heap_regions,
num_closed_heap_regions,
MetaspaceShared::first_closed_heap_region);

patch_archived_heap_embedded_pointers(open_archive_heap_ranges,
num_open_archive_heap_ranges,
MetaspaceShared::first_open_archive_heap_region);
patch_heap_embedded_pointers(open_heap_regions,
num_open_heap_regions,
MetaspaceShared::first_open_heap_region);
}

void FileMapInfo::patch_archived_heap_embedded_pointers(MemRegion* ranges, int num_ranges,
int first_region_idx) {
void FileMapInfo::patch_heap_embedded_pointers(MemRegion* regions, int num_regions,
int first_region_idx) {
char* bitmap_base = map_bitmap_region();
if (bitmap_base == NULL) {
return;
}
for (int i=0; i<num_ranges; i++) {
for (int i=0; i<num_regions; i++) {
FileMapRegion* si = space_at(i + first_region_idx);
HeapShared::patch_archived_heap_embedded_pointers(
ranges[i],
HeapShared::patch_embedded_pointers(
regions[i],
(address)(space_at(MetaspaceShared::bm)->mapped_base()) + si->oopmap_offset(),
si->oopmap_size_in_bits());
}
@@ -2066,19 +2066,19 @@ void FileMapInfo::patch_archived_heap_embedded_pointers(MemRegion* ranges, int n
void FileMapInfo::fixup_mapped_heap_regions() {
assert(vmClasses::Object_klass_loaded(), "must be");
// If any closed regions were found, call the fill routine to make them parseable.
// Note that closed_archive_heap_ranges may be non-NULL even if no ranges were found.
if (num_closed_archive_heap_ranges != 0) {
assert(closed_archive_heap_ranges != NULL,
"Null closed_archive_heap_ranges array with non-zero count");
G1CollectedHeap::heap()->fill_archive_regions(closed_archive_heap_ranges,
num_closed_archive_heap_ranges);
// Note that closed_heap_regions may be non-NULL even if no regions were found.
if (num_closed_heap_regions != 0) {
assert(closed_heap_regions != NULL,
"Null closed_heap_regions array with non-zero count");
G1CollectedHeap::heap()->fill_archive_regions(closed_heap_regions,
num_closed_heap_regions);
}

// do the same for mapped open archive heap regions
if (num_open_archive_heap_ranges != 0) {
assert(open_archive_heap_ranges != NULL, "NULL open_archive_heap_ranges array with non-zero count");
G1CollectedHeap::heap()->fill_archive_regions(open_archive_heap_ranges,
num_open_archive_heap_ranges);
if (num_open_heap_regions != 0) {
assert(open_heap_regions != NULL, "NULL open_heap_regions array with non-zero count");
G1CollectedHeap::heap()->fill_archive_regions(open_heap_regions,
num_open_heap_regions);

// Populate the open archive regions' G1BlockOffsetTableParts. That ensures
// fast G1BlockOffsetTablePart::block_start operations for any given address
@@ -2089,15 +2089,15 @@ void FileMapInfo::fixup_mapped_heap_regions() {
// regions, because objects in closed archive regions never reference objects
// outside the closed archive regions and they are immutable. So we never
// need their BOT during garbage collection.
G1CollectedHeap::heap()->populate_archive_regions_bot_part(open_archive_heap_ranges,
num_open_archive_heap_ranges);
G1CollectedHeap::heap()->populate_archive_regions_bot_part(open_heap_regions,
num_open_heap_regions);
}
}

// dealloc the archive regions from java heap
void FileMapInfo::dealloc_archive_heap_regions(MemRegion* regions, int num) {
void FileMapInfo::dealloc_heap_regions(MemRegion* regions, int num) {
if (num > 0) {
assert(regions != NULL, "Null archive ranges array with non-zero count");
assert(regions != NULL, "Null archive regions array with non-zero count");
G1CollectedHeap::heap()->dealloc_archive_regions(regions, num);
}
}
@@ -2361,10 +2361,10 @@ void FileMapInfo::stop_sharing_and_unmap(const char* msg) {
}
// Dealloc the archive heap regions only without unmapping. The regions are part
// of the java heap. Unmapping of the heap regions are managed by GC.
map_info->dealloc_archive_heap_regions(open_archive_heap_ranges,
num_open_archive_heap_ranges);
map_info->dealloc_archive_heap_regions(closed_archive_heap_ranges,
num_closed_archive_heap_ranges);
map_info->dealloc_heap_regions(open_heap_regions,
num_open_heap_regions);
map_info->dealloc_heap_regions(closed_heap_regions,
num_closed_heap_regions);
} else if (DumpSharedSpaces) {
fail_stop("%s", msg);
}