Skip to content

Commit

Permalink
8230674: Heap dumps should exclude dormant CDS archived objects of un…
Browse files Browse the repository at this point in the history
…loaded classes

Reviewed-by: phh
Backport-of: e90970b
  • Loading branch information
jianglizhou committed Aug 3, 2021
1 parent 815d3e1 commit aebdee3
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions src/hotspot/share/services/heapDumper.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -683,6 +683,16 @@ class DumperSupport : AllStatic {

// fixes up the current dump record and writes HPROF_HEAP_DUMP_END record
static void end_of_dump(DumpWriter* writer);

static oop mask_dormant_archived_object(oop o) {
if (o != NULL && o->klass()->java_mirror() == NULL) {
// Ignore this object since the corresponding java mirror is not loaded.
// Might be a dormant archive object.
return NULL;
} else {
return o;
}
}
};

// write a header of the given type
Expand Down Expand Up @@ -758,6 +768,13 @@ void DumperSupport::dump_field_value(DumpWriter* writer, char type, oop obj, int
case JVM_SIGNATURE_CLASS :
case JVM_SIGNATURE_ARRAY : {
oop o = obj->obj_field_access<ON_UNKNOWN_OOP_REF | AS_NO_KEEPALIVE>(offset);
if (o != NULL && log_is_enabled(Debug, cds, heap) && mask_dormant_archived_object(o) == NULL) {
ResourceMark rm;
log_debug(cds, heap)("skipped dormant archived object " INTPTR_FORMAT " (%s) referenced by " INTPTR_FORMAT " (%s)",
p2i(o), o->klass()->external_name(),
p2i(obj), obj->klass()->external_name());
}
o = mask_dormant_archived_object(o);
assert(oopDesc::is_oop_or_null(o), "Expected an oop or NULL at " PTR_FORMAT, p2i(o));
writer->write_objectID(o);
break;
Expand Down Expand Up @@ -955,11 +972,6 @@ void DumperSupport::dump_instance_field_descriptors(DumpWriter* writer, Klass* k
// creates HPROF_GC_INSTANCE_DUMP record for the given object
void DumperSupport::dump_instance(DumpWriter* writer, oop o) {
Klass* k = o->klass();
if (k->java_mirror() == NULL) {
// Ignoring this object since the corresponding java mirror is not loaded.
// Might be a dormant archive object.
return;
}

writer->write_u1(HPROF_GC_INSTANCE_DUMP);
writer->write_objectID(o);
Expand Down Expand Up @@ -1145,6 +1157,13 @@ void DumperSupport::dump_object_array(DumpWriter* writer, objArrayOop array) {
// [id]* elements
for (int index = 0; index < length; index++) {
oop o = array->obj_at(index);
if (o != NULL && log_is_enabled(Debug, cds, heap) && mask_dormant_archived_object(o) == NULL) {
ResourceMark rm;
log_debug(cds, heap)("skipped dormant archived object " INTPTR_FORMAT " (%s) referenced by " INTPTR_FORMAT " (%s)",
p2i(o), o->klass()->external_name(),
p2i(array), array->klass()->external_name());
}
o = mask_dormant_archived_object(o);
writer->write_objectID(o);
}
}
Expand Down Expand Up @@ -1424,6 +1443,11 @@ void HeapObjectDumper::do_object(oop o) {
}
}

if (DumperSupport::mask_dormant_archived_object(o) == NULL) {
log_debug(cds, heap)("skipped dormant archived object " INTPTR_FORMAT " (%s)", p2i(o), o->klass()->external_name());
return;
}

if (o->is_instance()) {
// create a HPROF_GC_INSTANCE record for each object
DumperSupport::dump_instance(writer(), o);
Expand Down

1 comment on commit aebdee3

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

Please sign in to comment.