Skip to content

Commit bf0ebd2

Browse files
committed
8223575: add subspace transitions to gc+metaspace=info log lines
Reviewed-by: mdoerr Backport-of: dacaff4
1 parent 39109e5 commit bf0ebd2

13 files changed

+153
-29
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ G1HeapTransition::Data::Data(G1CollectedHeap* g1_heap) {
3434
_survivor_length = g1_heap->survivor_regions_count();
3535
_old_length = g1_heap->old_regions_count();
3636
_humongous_length = g1_heap->humongous_regions_count();
37-
_metaspace_used_bytes = MetaspaceUtils::used_bytes();
3837
}
3938

4039
G1HeapTransition::G1HeapTransition(G1CollectedHeap* g1_heap) : _g1_heap(g1_heap), _before(g1_heap) { }
@@ -117,5 +116,5 @@ void G1HeapTransition::print() {
117116
log_trace(gc, heap)(" Used: " SIZE_FORMAT "K, Waste: " SIZE_FORMAT "K",
118117
usage._humongous_used / K, ((after._humongous_length * HeapRegion::GrainBytes) - usage._humongous_used) / K);
119118

120-
MetaspaceUtils::print_metaspace_change(_before._metaspace_used_bytes);
119+
MetaspaceUtils::print_metaspace_change(_before._meta_sizes);
121120
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#define SHARE_VM_GC_G1_G1HEAPTRANSITION_HPP
2727

2828
#include "gc/shared/plab.hpp"
29+
#include "memory/metaspace/metaspaceSizesSnapshot.hpp"
2930

3031
class G1CollectedHeap;
3132

@@ -35,7 +36,7 @@ class G1HeapTransition {
3536
size_t _survivor_length;
3637
size_t _old_length;
3738
size_t _humongous_length;
38-
size_t _metaspace_used_bytes;
39+
const metaspace::MetaspaceSizesSnapshot _meta_sizes;
3940

4041
Data(G1CollectedHeap* g1_heap);
4142
};

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "gc/shared/softRefPolicy.hpp"
3939
#include "gc/shared/strongRootsScope.hpp"
4040
#include "memory/metaspace.hpp"
41+
#include "memory/metaspace/metaspaceSizesSnapshot.hpp"
4142
#include "utilities/growableArray.hpp"
4243
#include "utilities/ostream.hpp"
4344

@@ -267,19 +268,18 @@ class PreGCValues {
267268
PreGCValues(ParallelScavengeHeap* heap) :
268269
_heap_used(heap->used()),
269270
_young_gen_used(heap->young_gen()->used_in_bytes()),
270-
_old_gen_used(heap->old_gen()->used_in_bytes()),
271-
_metadata_used(MetaspaceUtils::used_bytes()) { };
271+
_old_gen_used(heap->old_gen()->used_in_bytes()) { }
272272

273273
size_t heap_used() const { return _heap_used; }
274274
size_t young_gen_used() const { return _young_gen_used; }
275275
size_t old_gen_used() const { return _old_gen_used; }
276-
size_t metadata_used() const { return _metadata_used; }
276+
const metaspace::MetaspaceSizesSnapshot& metaspace_sizes() const { return _meta_sizes; }
277277

278278
private:
279279
size_t _heap_used;
280280
size_t _young_gen_used;
281281
size_t _old_gen_used;
282-
size_t _metadata_used;
282+
const metaspace::MetaspaceSizesSnapshot _meta_sizes;
283283
};
284284

285285
// Class that can be used to print information about the

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,7 @@ bool PSMarkSweep::invoke_no_policy(bool clear_all_softrefs) {
190190
CodeCache::gc_prologue();
191191
BiasedLocking::preserve_marks();
192192

193-
// Capture metadata size before collection for sizing.
194-
size_t metadata_prev_used = MetaspaceUtils::used_bytes();
195-
196-
size_t old_gen_prev_used = old_gen->used_in_bytes();
197-
size_t young_gen_prev_used = young_gen->used_in_bytes();
193+
const PreGCValues pre_gc_values(heap);
198194

199195
allocate_stacks();
200196

@@ -351,9 +347,9 @@ bool PSMarkSweep::invoke_no_policy(bool clear_all_softrefs) {
351347
accumulated_time()->stop();
352348
}
353349

354-
young_gen->print_used_change(young_gen_prev_used);
355-
old_gen->print_used_change(old_gen_prev_used);
356-
MetaspaceUtils::print_metaspace_change(metadata_prev_used);
350+
young_gen->print_used_change(pre_gc_values.young_gen_used());
351+
old_gen->print_used_change(pre_gc_values.old_gen_used());
352+
MetaspaceUtils::print_metaspace_change(pre_gc_values.metaspace_sizes());
357353

358354
// Track memory usage and detect low memory
359355
MemoryService::track_memory_usage();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,7 +1753,7 @@ bool PSParallelCompact::invoke_no_policy(bool maximum_heap_compaction) {
17531753
// miscellaneous bookkeeping.
17541754
pre_compact();
17551755

1756-
PreGCValues pre_gc_values(heap);
1756+
const PreGCValues pre_gc_values(heap);
17571757

17581758
// Get the compaction manager reserved for the VM thread.
17591759
ParCompactionManager* const vmthread_cm =
@@ -1902,7 +1902,7 @@ bool PSParallelCompact::invoke_no_policy(bool maximum_heap_compaction) {
19021902

19031903
young_gen->print_used_change(pre_gc_values.young_gen_used());
19041904
old_gen->print_used_change(pre_gc_values.old_gen_used());
1905-
MetaspaceUtils::print_metaspace_change(pre_gc_values.metadata_used());
1905+
MetaspaceUtils::print_metaspace_change(pre_gc_values.metaspace_sizes());
19061906

19071907
// Track memory usage and detect low memory
19081908
MemoryService::track_memory_usage();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ bool PSScavenge::invoke_no_policy() {
328328
reference_processor()->enable_discovery();
329329
reference_processor()->setup_policy(false);
330330

331-
PreGCValues pre_gc_values(heap);
331+
const PreGCValues pre_gc_values(heap);
332332

333333
// Reset our survivor overflow.
334334
set_survivor_overflow(false);
@@ -608,7 +608,7 @@ bool PSScavenge::invoke_no_policy() {
608608

609609
young_gen->print_used_change(pre_gc_values.young_gen_used());
610610
old_gen->print_used_change(pre_gc_values.old_gen_used());
611-
MetaspaceUtils::print_metaspace_change(pre_gc_values.metadata_used());
611+
MetaspaceUtils::print_metaspace_change(pre_gc_values.metaspace_sizes());
612612

613613
// Track memory usage and detect low memory
614614
MemoryService::track_memory_usage();

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -564,8 +564,6 @@ void GenCollectedHeap::do_collection(bool full,
564564

565565
ClearedAllSoftRefs casr(do_clear_all_soft_refs, soft_ref_policy());
566566

567-
const size_t metadata_prev_used = MetaspaceUtils::used_bytes();
568-
569567
print_heap_before_gc();
570568

571569
{
@@ -590,6 +588,7 @@ void GenCollectedHeap::do_collection(bool full,
590588

591589
size_t young_prev_used = _young_gen->used();
592590
size_t old_prev_used = _old_gen->used();
591+
const metaspace::MetaspaceSizesSnapshot prev_meta_sizes;
593592

594593
bool run_verification = total_collections() >= VerifyGCStartAt;
595594

@@ -650,7 +649,7 @@ void GenCollectedHeap::do_collection(bool full,
650649
complete = complete || collected_old;
651650

652651
print_heap_change(young_prev_used, old_prev_used);
653-
MetaspaceUtils::print_metaspace_change(metadata_prev_used);
652+
MetaspaceUtils::print_metaspace_change(prev_meta_sizes);
654653

655654
// Adjust generation sizes.
656655
if (collected_old) {

src/hotspot/share/gc/shenandoah/shenandoahControlThread.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ void ShenandoahControlThread::run_service() {
187187
heap->reset_bytes_allocated_since_gc_start();
188188

189189
// Capture metaspace usage before GC.
190-
const size_t metadata_prev_used = MetaspaceUtils::used_bytes();
190+
const metaspace::MetaspaceSizesSnapshot prev_meta_sizes;
191191

192192
// If GC was requested, we are sampling the counters even without actual triggers
193193
// from allocation machinery. This captures GC phases more accurately.
@@ -273,7 +273,7 @@ void ShenandoahControlThread::run_service() {
273273
heap->phase_timings()->flush_cycle_to_global();
274274

275275
// Print Metaspace change following GC (if logging is enabled).
276-
MetaspaceUtils::print_metaspace_change(metadata_prev_used);
276+
MetaspaceUtils::print_metaspace_change(prev_meta_sizes);
277277

278278
// GC is over, we are at idle now
279279
if (ShenandoahPacing) {

src/hotspot/share/memory/metaspace.cpp

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -470,9 +470,36 @@ MetaspaceChunkFreeListSummary MetaspaceUtils::chunk_free_list_summary(Metaspace:
470470
return cm->chunk_free_list_summary();
471471
}
472472

473-
void MetaspaceUtils::print_metaspace_change(size_t prev_metadata_used) {
474-
log_info(gc, metaspace)("Metaspace: " SIZE_FORMAT "K->" SIZE_FORMAT "K(" SIZE_FORMAT "K)",
475-
prev_metadata_used/K, used_bytes()/K, reserved_bytes()/K);
473+
void MetaspaceUtils::print_metaspace_change(const metaspace::MetaspaceSizesSnapshot& pre_meta_values) {
474+
const metaspace::MetaspaceSizesSnapshot meta_values;
475+
476+
if (Metaspace::using_class_space()) {
477+
log_info(gc, metaspace)(HEAP_CHANGE_FORMAT" "
478+
HEAP_CHANGE_FORMAT" "
479+
HEAP_CHANGE_FORMAT,
480+
HEAP_CHANGE_FORMAT_ARGS("Metaspace",
481+
pre_meta_values.used(),
482+
pre_meta_values.committed(),
483+
meta_values.used(),
484+
meta_values.committed()),
485+
HEAP_CHANGE_FORMAT_ARGS("NonClass",
486+
pre_meta_values.non_class_used(),
487+
pre_meta_values.non_class_committed(),
488+
meta_values.non_class_used(),
489+
meta_values.non_class_committed()),
490+
HEAP_CHANGE_FORMAT_ARGS("Class",
491+
pre_meta_values.class_used(),
492+
pre_meta_values.class_committed(),
493+
meta_values.class_used(),
494+
meta_values.class_committed()));
495+
} else {
496+
log_info(gc, metaspace)(HEAP_CHANGE_FORMAT,
497+
HEAP_CHANGE_FORMAT_ARGS("Metaspace",
498+
pre_meta_values.used(),
499+
pre_meta_values.committed(),
500+
meta_values.used(),
501+
meta_values.committed()));
502+
}
476503
}
477504

478505
void MetaspaceUtils::print_on(outputStream* out) {

src/hotspot/share/memory/metaspace.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "memory/memRegion.hpp"
2929
#include "memory/metaspaceChunkFreeListSummary.hpp"
3030
#include "memory/virtualspace.hpp"
31+
#include "memory/metaspace/metaspaceSizesSnapshot.hpp"
3132
#include "utilities/exceptions.hpp"
3233
#include "utilities/macros.hpp"
3334

@@ -427,8 +428,8 @@ class MetaspaceUtils : AllStatic {
427428
static bool has_chunk_free_list(Metaspace::MetadataType mdtype);
428429
static MetaspaceChunkFreeListSummary chunk_free_list_summary(Metaspace::MetadataType mdtype);
429430

430-
// Print change in used metadata.
431-
static void print_metaspace_change(size_t prev_metadata_used);
431+
// Log change in used metadata.
432+
static void print_metaspace_change(const metaspace::MetaspaceSizesSnapshot& pre_meta_values);
432433
static void print_on(outputStream * out);
433434

434435
// Prints an ASCII representation of the given space.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
3+
* Copyright (c) 2019, Twitter, Inc.
4+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5+
*
6+
* This code is free software; you can redistribute it and/or modify it
7+
* under the terms of the GNU General Public License version 2 only, as
8+
* published by the Free Software Foundation.
9+
*
10+
* This code is distributed in the hope that it will be useful, but WITHOUT
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13+
* version 2 for more details (a copy is included in the LICENSE file that
14+
* accompanied this code).
15+
*
16+
* You should have received a copy of the GNU General Public License version
17+
* 2 along with this work; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19+
*
20+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21+
* or visit www.oracle.com if you need additional information or have any
22+
* questions.
23+
*
24+
*/
25+
26+
#include "precompiled.hpp"
27+
28+
#include "memory/metaspace.hpp"
29+
#include "memory/metaspace/metaspaceSizesSnapshot.hpp"
30+
31+
namespace metaspace {
32+
33+
MetaspaceSizesSnapshot::MetaspaceSizesSnapshot()
34+
: _used(MetaspaceUtils::used_bytes()),
35+
_committed(MetaspaceUtils::committed_bytes()),
36+
_non_class_used(MetaspaceUtils::used_bytes(Metaspace::NonClassType)),
37+
_non_class_committed(MetaspaceUtils::committed_bytes(Metaspace::NonClassType)),
38+
_class_used(MetaspaceUtils::used_bytes(Metaspace::ClassType)),
39+
_class_committed(MetaspaceUtils::committed_bytes(Metaspace::ClassType)) { }
40+
41+
} // namespace metaspace
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
3+
* Copyright (c) 2019, Twitter, Inc.
4+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5+
*
6+
* This code is free software; you can redistribute it and/or modify it
7+
* under the terms of the GNU General Public License version 2 only, as
8+
* published by the Free Software Foundation.
9+
*
10+
* This code is distributed in the hope that it will be useful, but WITHOUT
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13+
* version 2 for more details (a copy is included in the LICENSE file that
14+
* accompanied this code).
15+
*
16+
* You should have received a copy of the GNU General Public License version
17+
* 2 along with this work; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19+
*
20+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21+
* or visit www.oracle.com if you need additional information or have any
22+
* questions.
23+
*
24+
*/
25+
26+
#ifndef SHARE_MEMORY_METASPACE_METASPACESIZESSNAPSHOT_HPP
27+
#define SHARE_MEMORY_METASPACE_METASPACESIZESSNAPSHOT_HPP
28+
29+
namespace metaspace {
30+
31+
class MetaspaceSizesSnapshot {
32+
public:
33+
MetaspaceSizesSnapshot();
34+
35+
size_t used() const { return _used; }
36+
size_t committed() const { return _committed; }
37+
size_t non_class_used() const { return _non_class_used; }
38+
size_t non_class_committed() const { return _non_class_committed; }
39+
size_t class_used() const { return _class_used; }
40+
size_t class_committed() const { return _class_committed; }
41+
42+
private:
43+
const size_t _used;
44+
const size_t _committed;
45+
const size_t _non_class_used;
46+
const size_t _non_class_committed;
47+
const size_t _class_used;
48+
const size_t _class_committed;
49+
};
50+
51+
} // namespace metaspace
52+
53+
#endif // SHARE_MEMORY_METASPACE_METASPACESIZESSNAPSHOT_HPP

src/hotspot/share/utilities/globalDefinitions.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,13 @@ inline size_t byte_size_in_exact_unit(size_t s) {
333333
return s;
334334
}
335335

336+
// Memory size transition formatting.
337+
338+
#define HEAP_CHANGE_FORMAT "%s: " SIZE_FORMAT "K(" SIZE_FORMAT "K)->" SIZE_FORMAT "K(" SIZE_FORMAT "K)"
339+
340+
#define HEAP_CHANGE_FORMAT_ARGS(_name_, _prev_used_, _prev_capacity_, _used_, _capacity_) \
341+
(_name_), (_prev_used_) / K, (_prev_capacity_) / K, (_used_) / K, (_capacity_) / K
342+
336343
//----------------------------------------------------------------------------------------------------
337344
// VM type definitions
338345

0 commit comments

Comments
 (0)