Skip to content

Commit 855f16e

Browse files
committed
8229278: Improve hs_err location printing to assume less about GC internals
Reviewed-by: stefank, kbarrett
1 parent 2750569 commit 855f16e

23 files changed

+243
-127
lines changed

src/hotspot/share/gc/epsilon/epsilonHeap.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "gc/epsilon/epsilonMemoryPool.hpp"
2727
#include "gc/epsilon/epsilonThreadLocalData.hpp"
2828
#include "gc/shared/gcArguments.hpp"
29+
#include "gc/shared/locationPrinter.inline.hpp"
2930
#include "memory/allocation.hpp"
3031
#include "memory/allocation.inline.hpp"
3132
#include "memory/resourceArea.hpp"
@@ -305,6 +306,10 @@ void EpsilonHeap::print_on(outputStream *st) const {
305306
MetaspaceUtils::print_on(st);
306307
}
307308

309+
bool EpsilonHeap::print_location(outputStream* st, void* addr) const {
310+
return BlockLocationPrinter<EpsilonHeap>::print_location(st, addr);
311+
}
312+
308313
void EpsilonHeap::print_tracing_info() const {
309314
print_heap_info(used());
310315
print_metaspace_info();

src/hotspot/share/gc/epsilon/epsilonHeap.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ class EpsilonHeap : public CollectedHeap {
114114
virtual void unpin_object(JavaThread* thread, oop obj) { }
115115

116116
// No support for block parsing.
117-
virtual HeapWord* block_start(const void* addr) const { return NULL; }
118-
virtual bool block_is_obj(const HeapWord* addr) const { return false; }
117+
HeapWord* block_start(const void* addr) const { return NULL; }
118+
bool block_is_obj(const HeapWord* addr) const { return false; }
119119

120120
// No GC threads
121121
virtual void print_gc_threads_on(outputStream* st) const {}
@@ -138,6 +138,7 @@ class EpsilonHeap : public CollectedHeap {
138138

139139
virtual void print_on(outputStream* st) const;
140140
virtual void print_tracing_info() const;
141+
virtual bool print_location(outputStream* st, void* addr) const;
141142

142143
private:
143144
void print_heap_info(size_t used) const;

src/hotspot/share/gc/g1/g1CollectedHeap.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
#include "gc/shared/gcTraceTime.inline.hpp"
7575
#include "gc/shared/generationSpec.hpp"
7676
#include "gc/shared/isGCActiveMark.hpp"
77+
#include "gc/shared/locationPrinter.inline.hpp"
7778
#include "gc/shared/oopStorageParState.hpp"
7879
#include "gc/shared/preservedMarks.inline.hpp"
7980
#include "gc/shared/suspendibleThreadSet.hpp"
@@ -2490,6 +2491,10 @@ void G1CollectedHeap::print_all_rsets() {
24902491
}
24912492
#endif // PRODUCT
24922493

2494+
bool G1CollectedHeap::print_location(outputStream* st, void* addr) const {
2495+
return BlockLocationPrinter<G1CollectedHeap>::print_location(st, addr);
2496+
}
2497+
24932498
G1HeapSummary G1CollectedHeap::create_g1_heap_summary() {
24942499

24952500
size_t eden_used_bytes = _eden.used_bytes();

src/hotspot/share/gc/g1/g1CollectedHeap.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,11 +1211,11 @@ class G1CollectedHeap : public CollectedHeap {
12111211
// address "addr". We say "blocks" instead of "object" since some heaps
12121212
// may not pack objects densely; a chunk may either be an object or a
12131213
// non-object.
1214-
virtual HeapWord* block_start(const void* addr) const;
1214+
HeapWord* block_start(const void* addr) const;
12151215

12161216
// Requires "addr" to be the start of a block, and returns "TRUE" iff
12171217
// the block is an object.
1218-
virtual bool block_is_obj(const HeapWord* addr) const;
1218+
bool block_is_obj(const HeapWord* addr) const;
12191219

12201220
// Section on thread-local allocation buffers (TLABs)
12211221
// See CollectedHeap for semantics.
@@ -1428,6 +1428,9 @@ class G1CollectedHeap : public CollectedHeap {
14281428
void print_cset_rsets() PRODUCT_RETURN;
14291429
void print_all_rsets() PRODUCT_RETURN;
14301430

1431+
// Used to print information about locations in the hs_err file.
1432+
virtual bool print_location(outputStream* st, void* addr) const;
1433+
14311434
size_t pending_card_num();
14321435
};
14331436

src/hotspot/share/gc/parallel/parallelScavengeHeap.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "gc/shared/gcLocker.hpp"
4242
#include "gc/shared/gcWhen.hpp"
4343
#include "gc/shared/genArguments.hpp"
44+
#include "gc/shared/locationPrinter.inline.hpp"
4445
#include "gc/shared/scavengableNMethods.hpp"
4546
#include "logging/log.hpp"
4647
#include "memory/metaspaceCounters.hpp"
@@ -584,6 +585,10 @@ PSHeapSummary ParallelScavengeHeap::create_ps_heap_summary() {
584585
return PSHeapSummary(heap_summary, used(), old_summary, old_space, young_summary, eden_space, from_space, to_space);
585586
}
586587

588+
bool ParallelScavengeHeap::print_location(outputStream* st, void* addr) const {
589+
return BlockLocationPrinter<ParallelScavengeHeap>::print_location(st, addr);
590+
}
591+
587592
void ParallelScavengeHeap::print_on(outputStream* st) const {
588593
young_gen()->print_on(st);
589594
old_gen()->print_on(st);

src/hotspot/share/gc/parallel/parallelScavengeHeap.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,9 @@ class ParallelScavengeHeap : public CollectedHeap {
228228
PreGenGCValues get_pre_gc_values() const;
229229
void print_heap_change(const PreGenGCValues& pre_gc_values) const;
230230

231+
// Used to print information about locations in the hs_err file.
232+
virtual bool print_location(outputStream* st, void* addr) const;
233+
231234
void verify(VerifyOption option /* ignored */);
232235

233236
// Resize the young generation. The reserved space for the

src/hotspot/share/gc/shared/collectedHeap.hpp

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -402,28 +402,6 @@ class CollectedHeap : public CHeapObj<mtInternal> {
402402
// over live objects.
403403
virtual void safe_object_iterate(ObjectClosure* cl) = 0;
404404

405-
// NOTE! There is no requirement that a collector implement these
406-
// functions.
407-
//
408-
// A CollectedHeap is divided into a dense sequence of "blocks"; that is,
409-
// each address in the (reserved) heap is a member of exactly
410-
// one block. The defining characteristic of a block is that it is
411-
// possible to find its size, and thus to progress forward to the next
412-
// block. (Blocks may be of different sizes.) Thus, blocks may
413-
// represent Java objects, or they might be free blocks in a
414-
// free-list-based heap (or subheap), as long as the two kinds are
415-
// distinguishable and the size of each is determinable.
416-
417-
// Returns the address of the start of the "block" that contains the
418-
// address "addr". We say "blocks" instead of "object" since some heaps
419-
// may not pack objects densely; a chunk may either be an object or a
420-
// non-object.
421-
virtual HeapWord* block_start(const void* addr) const = 0;
422-
423-
// Requires "addr" to be the start of a block, and returns "TRUE" iff
424-
// the block is an object.
425-
virtual bool block_is_obj(const HeapWord* addr) const = 0;
426-
427405
// Returns the longest time (in ms) that has elapsed since the last
428406
// time that any part of the heap was examined by a garbage collection.
429407
virtual jlong millis_since_last_gc() = 0;
@@ -461,6 +439,9 @@ class CollectedHeap : public CHeapObj<mtInternal> {
461439

462440
virtual void print_on_error(outputStream* st) const;
463441

442+
// Used to print information about locations in the hs_err file.
443+
virtual bool print_location(outputStream* st, void* addr) const = 0;
444+
464445
// Print all GC threads (other than the VM thread)
465446
// used by this heap.
466447
virtual void print_gc_threads_on(outputStream* st) const = 0;

src/hotspot/share/gc/shared/genCollectedHeap.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include "gc/shared/genCollectedHeap.hpp"
4848
#include "gc/shared/genOopClosures.inline.hpp"
4949
#include "gc/shared/generationSpec.hpp"
50+
#include "gc/shared/locationPrinter.inline.hpp"
5051
#include "gc/shared/oopStorageParState.inline.hpp"
5152
#include "gc/shared/scavengableNMethods.hpp"
5253
#include "gc/shared/space.hpp"
@@ -1260,6 +1261,10 @@ void GenCollectedHeap::gc_threads_do(ThreadClosure* tc) const {
12601261
void GenCollectedHeap::print_gc_threads_on(outputStream* st) const {
12611262
}
12621263

1264+
bool GenCollectedHeap::print_location(outputStream* st, void* addr) const {
1265+
return BlockLocationPrinter<GenCollectedHeap>::print_location(st, addr);
1266+
}
1267+
12631268
void GenCollectedHeap::print_tracing_info() const {
12641269
if (log_is_enabled(Debug, gc, heap, exit)) {
12651270
LogStreamHandle(Debug, gc, heap, exit) lsh;

src/hotspot/share/gc/shared/genCollectedHeap.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,13 +260,13 @@ class GenCollectedHeap : public CollectedHeap {
260260
// address "addr". We say "blocks" instead of "object" since some heaps
261261
// may not pack objects densely; a chunk may either be an object or a
262262
// non-object.
263-
virtual HeapWord* block_start(const void* addr) const;
263+
HeapWord* block_start(const void* addr) const;
264264

265265
// Requires "addr" to be the start of a block, and returns "TRUE" iff
266266
// the block is an object. Assumes (and verifies in non-product
267267
// builds) that addr is in the allocated part of the heap and is
268268
// the start of a chunk.
269-
virtual bool block_is_obj(const HeapWord* addr) const;
269+
bool block_is_obj(const HeapWord* addr) const;
270270

271271
// Section on TLAB's.
272272
virtual bool supports_tlab_allocation() const;
@@ -332,6 +332,9 @@ class GenCollectedHeap : public CollectedHeap {
332332
virtual void gc_threads_do(ThreadClosure* tc) const;
333333
virtual void print_tracing_info() const;
334334

335+
// Used to print information about locations in the hs_err file.
336+
virtual bool print_location(outputStream* st, void* addr) const;
337+
335338
void print_heap_change(size_t young_prev_used, size_t old_prev_used) const;
336339

337340
// The functions below are helper functions that a subclass of
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*
23+
*/
24+
25+
#include "precompiled.hpp"
26+
#include "gc/shared/collectedHeap.hpp"
27+
#include "gc/shared/locationPrinter.hpp"
28+
#include "memory/universe.hpp"
29+
#include "runtime/os.hpp"
30+
#include "oops/klass.hpp"
31+
32+
bool LocationPrinter::is_valid_obj(void* obj) {
33+
if (!is_object_aligned(obj)) {
34+
return false;
35+
}
36+
if (obj < (void*)os::min_page_size()) {
37+
return false;
38+
}
39+
40+
// We need at least the mark and the klass word in the committed region.
41+
if (!os::is_readable_range(obj, (HeapWord*)obj + oopDesc::header_size())) {
42+
return false;
43+
}
44+
if (!Universe::heap()->is_in(obj)) {
45+
return false;
46+
}
47+
48+
Klass* k = (Klass*)oopDesc::load_klass_raw((oopDesc*)obj);
49+
return Klass::is_valid(k);
50+
}

0 commit comments

Comments
 (0)