8298126: Print statistics for objects in CDS archive heap

Reviewed-by: ccheung
This commit is contained in:
Ioi Lam 2022-12-11 02:58:59 +00:00
parent 8ea2a6777b
commit a37de62d9d
2 changed files with 64 additions and 0 deletions

View file

@ -84,6 +84,11 @@ bool HeapShared::_disable_writing = false;
DumpedInternedStrings *HeapShared::_dumped_interned_strings = NULL; DumpedInternedStrings *HeapShared::_dumped_interned_strings = NULL;
GrowableArrayCHeap<Metadata**, mtClassShared>* HeapShared::_native_pointers = NULL; GrowableArrayCHeap<Metadata**, mtClassShared>* HeapShared::_native_pointers = NULL;
size_t HeapShared::_alloc_count[HeapShared::ALLOC_STAT_SLOTS];
size_t HeapShared::_alloc_size[HeapShared::ALLOC_STAT_SLOTS];
size_t HeapShared::_total_obj_count;
size_t HeapShared::_total_obj_size;
#ifndef PRODUCT #ifndef PRODUCT
#define ARCHIVE_TEST_FIELD_NAME "archivedObjects" #define ARCHIVE_TEST_FIELD_NAME "archivedObjects"
static Array<char>* _archived_ArchiveHeapTestClass = NULL; static Array<char>* _archived_ArchiveHeapTestClass = NULL;
@ -301,6 +306,7 @@ oop HeapShared::archive_object(oop obj) {
oop archived_oop = cast_to_oop(G1CollectedHeap::heap()->archive_mem_allocate(len)); oop archived_oop = cast_to_oop(G1CollectedHeap::heap()->archive_mem_allocate(len));
if (archived_oop != NULL) { if (archived_oop != NULL) {
count_allocation(len);
Copy::aligned_disjoint_words(cast_from_oop<HeapWord*>(obj), cast_from_oop<HeapWord*>(archived_oop), len); Copy::aligned_disjoint_words(cast_from_oop<HeapWord*>(obj), cast_from_oop<HeapWord*>(archived_oop), len);
// Reinitialize markword to remove age/marking/locking/etc. // Reinitialize markword to remove age/marking/locking/etc.
// //
@ -586,6 +592,7 @@ void HeapShared::copy_roots() {
roots()->obj_at_put(i, _pending_roots->at(i)); roots()->obj_at_put(i, _pending_roots->at(i));
} }
log_info(cds)("archived obj roots[%d] = " SIZE_FORMAT " words, klass = %p, obj = %p", length, size, k, mem); log_info(cds)("archived obj roots[%d] = " SIZE_FORMAT " words, klass = %p, obj = %p", length, size, k, mem);
count_allocation(roots()->size());
} }
// //
@ -831,6 +838,9 @@ void HeapShared::write_subgraph_info_table() {
_archived_ArchiveHeapTestClass = array; _archived_ArchiveHeapTestClass = array;
} }
#endif #endif
if (log_is_enabled(Info, cds, heap)) {
print_stats();
}
} }
void HeapShared::serialize_root(SerializeClosure* soc) { void HeapShared::serialize_root(SerializeClosure* soc) {
@ -1858,4 +1868,49 @@ ResourceBitMap HeapShared::calculate_ptrmap(MemRegion region) {
} }
} }
void HeapShared::count_allocation(size_t size) {
_total_obj_count ++;
_total_obj_size += size;
for (int i = 0; i < ALLOC_STAT_SLOTS; i++) {
if (size <= (size_t(1) << i)) {
_alloc_count[i] ++;
_alloc_size[i] += size;
return;
}
}
}
static double avg_size(size_t size, size_t count) {
double avg = 0;
if (count > 0) {
avg = double(size * HeapWordSize) / double(count);
}
return avg;
}
void HeapShared::print_stats() {
size_t huge_count = _total_obj_count;
size_t huge_size = _total_obj_size;
for (int i = 0; i < ALLOC_STAT_SLOTS; i++) {
size_t byte_size_limit = (size_t(1) << i) * HeapWordSize;
size_t count = _alloc_count[i];
size_t size = _alloc_size[i];
log_info(cds, heap)(SIZE_FORMAT_W(8) " objects are <= " SIZE_FORMAT_W(-6)
" bytes (total " SIZE_FORMAT_W(8) " bytes, avg %8.1f bytes)",
count, byte_size_limit, size * HeapWordSize, avg_size(size, count));
huge_count -= count;
huge_size -= size;
}
log_info(cds, heap)(SIZE_FORMAT_W(8) " huge objects (total " SIZE_FORMAT_W(8) " bytes"
", avg %8.1f bytes)",
huge_count, huge_size * HeapWordSize,
avg_size(huge_size, huge_count));
log_info(cds, heap)(SIZE_FORMAT_W(8) " total objects (total " SIZE_FORMAT_W(8) " bytes"
", avg %8.1f bytes)",
_total_obj_count, _total_obj_size * HeapWordSize,
avg_size(_total_obj_size, _total_obj_count));
}
#endif // INCLUDE_CDS_JAVA_HEAP #endif // INCLUDE_CDS_JAVA_HEAP

View file

@ -162,6 +162,15 @@ private:
static DumpedInternedStrings *_dumped_interned_strings; static DumpedInternedStrings *_dumped_interned_strings;
static GrowableArrayCHeap<Metadata**, mtClassShared>* _native_pointers; static GrowableArrayCHeap<Metadata**, mtClassShared>* _native_pointers;
// statistics
constexpr static int ALLOC_STAT_SLOTS = 16;
static size_t _alloc_count[ALLOC_STAT_SLOTS];
static size_t _alloc_size[ALLOC_STAT_SLOTS];
static size_t _total_obj_count;
static size_t _total_obj_size; // in HeapWords
static void count_allocation(size_t size);
static void print_stats();
public: public:
static unsigned oop_hash(oop const& p); static unsigned oop_hash(oop const& p);
static unsigned string_oop_hash(oop const& string) { static unsigned string_oop_hash(oop const& string) {