Skip to content

Commit 6802277

Browse files
committed
8298524: Debug function to trace reachability of CDS archived heap objects
Reviewed-by: ccheung
1 parent 23e1827 commit 6802277

File tree

2 files changed

+29
-19
lines changed

2 files changed

+29
-19
lines changed

src/hotspot/share/cds/cdsHeapVerifier.cpp

+26-18
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ inline bool CDSHeapVerifier::do_entry(oop& orig_obj, HeapShared::CachedOopInfo&
236236
ls.print("Value: ");
237237
orig_obj->print_on(&ls);
238238
ls.print_cr("--- trace begin ---");
239-
trace_to_root(orig_obj, NULL, &value);
239+
trace_to_root(&ls, orig_obj, NULL, &value);
240240
ls.print_cr("--- trace end ---");
241241
ls.cr();
242242
_problems ++;
@@ -248,54 +248,62 @@ inline bool CDSHeapVerifier::do_entry(oop& orig_obj, HeapShared::CachedOopInfo&
248248
class CDSHeapVerifier::TraceFields : public FieldClosure {
249249
oop _orig_obj;
250250
oop _orig_field;
251-
LogStream* _ls;
251+
outputStream* _st;
252252

253253
public:
254-
TraceFields(oop orig_obj, oop orig_field, LogStream* ls)
255-
: _orig_obj(orig_obj), _orig_field(orig_field), _ls(ls) {}
254+
TraceFields(oop orig_obj, oop orig_field, outputStream* st)
255+
: _orig_obj(orig_obj), _orig_field(orig_field), _st(st) {}
256256

257257
void do_field(fieldDescriptor* fd) {
258258
if (fd->field_type() == T_OBJECT || fd->field_type() == T_ARRAY) {
259259
oop obj_field = _orig_obj->obj_field(fd->offset());
260260
if (obj_field == _orig_field) {
261-
_ls->print("::%s (offset = %d)", fd->name()->as_C_string(), fd->offset());
261+
_st->print("::%s (offset = %d)", fd->name()->as_C_string(), fd->offset());
262262
}
263263
}
264264
}
265265
};
266266

267-
// Hint: to exercise this function, uncomment out one of the ADD_EXCL lines above.
268-
int CDSHeapVerifier::trace_to_root(oop orig_obj, oop orig_field, HeapShared::CachedOopInfo* p) {
267+
// Call this function (from gdb, etc) if you want to know why an object is archived.
268+
void CDSHeapVerifier::trace_to_root(outputStream* st, oop orig_obj) {
269+
HeapShared::CachedOopInfo* info = HeapShared::archived_object_cache()->get(orig_obj);
270+
if (info != NULL) {
271+
trace_to_root(st, orig_obj, NULL, info);
272+
} else {
273+
st->print_cr("Not an archived object??");
274+
}
275+
}
276+
277+
int CDSHeapVerifier::trace_to_root(outputStream* st, oop orig_obj, oop orig_field, HeapShared::CachedOopInfo* info) {
269278
int level = 0;
270-
LogStream ls(Log(cds, heap)::warning());
271-
if (p->_referrer != NULL) {
272-
HeapShared::CachedOopInfo* ref = HeapShared::archived_object_cache()->get(p->_referrer);
279+
if (info->_referrer != NULL) {
280+
HeapShared::CachedOopInfo* ref = HeapShared::archived_object_cache()->get(info->_referrer);
273281
assert(ref != NULL, "sanity");
274-
level = trace_to_root(p->_referrer, orig_obj, ref) + 1;
282+
level = trace_to_root(st, info->_referrer, orig_obj, ref) + 1;
275283
} else if (java_lang_String::is_instance(orig_obj)) {
276-
ls.print_cr("[%2d] (shared string table)", level++);
284+
st->print_cr("[%2d] (shared string table)", level++);
277285
}
278286
Klass* k = orig_obj->klass();
279287
ResourceMark rm;
280-
ls.print("[%2d] ", level);
281-
orig_obj->print_address_on(&ls);
282-
ls.print(" %s", k->internal_name());
288+
st->print("[%2d] ", level);
289+
orig_obj->print_address_on(st);
290+
st->print(" %s", k->internal_name());
283291
if (orig_field != NULL) {
284292
if (k->is_instance_klass()) {
285-
TraceFields clo(orig_obj, orig_field, &ls);;
293+
TraceFields clo(orig_obj, orig_field, st);
286294
InstanceKlass::cast(k)->do_nonstatic_fields(&clo);
287295
} else {
288296
assert(orig_obj->is_objArray(), "must be");
289297
objArrayOop array = (objArrayOop)orig_obj;
290298
for (int i = 0; i < array->length(); i++) {
291299
if (array->obj_at(i) == orig_field) {
292-
ls.print(" @[%d]", i);
300+
st->print(" @[%d]", i);
293301
break;
294302
}
295303
}
296304
}
297305
}
298-
ls.cr();
306+
st->cr();
299307

300308
return level;
301309
}

src/hotspot/share/cds/cdsHeapVerifier.hpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class CDSHeapVerifier : public KlassClosure {
6969
}
7070
return NULL;
7171
}
72-
int trace_to_root(oop orig_obj, oop orig_field, HeapShared::CachedOopInfo* p);
72+
static int trace_to_root(outputStream* st, oop orig_obj, oop orig_field, HeapShared::CachedOopInfo* p);
7373

7474
CDSHeapVerifier();
7575
~CDSHeapVerifier();
@@ -83,6 +83,8 @@ class CDSHeapVerifier : public KlassClosure {
8383
inline bool do_entry(oop& orig_obj, HeapShared::CachedOopInfo& value);
8484

8585
static void verify() NOT_DEBUG_RETURN;
86+
87+
static void trace_to_root(outputStream* st, oop orig_obj);
8688
};
8789

8890
#endif // INCLUDE_CDS_JAVA_HEAP

0 commit comments

Comments
 (0)