Skip to content

Commit

Permalink
8223575: add subspace transitions to gc+metaspace=info log lines
Browse files Browse the repository at this point in the history
Reviewed-by: mdoerr
Backport-of: dacaff4
  • Loading branch information
GoeLin committed Jun 10, 2022
1 parent 39109e5 commit bf0ebd2
Show file tree
Hide file tree
Showing 13 changed files with 153 additions and 29 deletions.
3 changes: 1 addition & 2 deletions src/hotspot/share/gc/g1/g1HeapTransition.cpp
Expand Up @@ -34,7 +34,6 @@ G1HeapTransition::Data::Data(G1CollectedHeap* g1_heap) {
_survivor_length = g1_heap->survivor_regions_count();
_old_length = g1_heap->old_regions_count();
_humongous_length = g1_heap->humongous_regions_count();
_metaspace_used_bytes = MetaspaceUtils::used_bytes();
}

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

MetaspaceUtils::print_metaspace_change(_before._metaspace_used_bytes);
MetaspaceUtils::print_metaspace_change(_before._meta_sizes);
}
3 changes: 2 additions & 1 deletion src/hotspot/share/gc/g1/g1HeapTransition.hpp
Expand Up @@ -26,6 +26,7 @@
#define SHARE_VM_GC_G1_G1HEAPTRANSITION_HPP

#include "gc/shared/plab.hpp"
#include "memory/metaspace/metaspaceSizesSnapshot.hpp"

class G1CollectedHeap;

Expand All @@ -35,7 +36,7 @@ class G1HeapTransition {
size_t _survivor_length;
size_t _old_length;
size_t _humongous_length;
size_t _metaspace_used_bytes;
const metaspace::MetaspaceSizesSnapshot _meta_sizes;

Data(G1CollectedHeap* g1_heap);
};
Expand Down
8 changes: 4 additions & 4 deletions src/hotspot/share/gc/parallel/parallelScavengeHeap.hpp
Expand Up @@ -38,6 +38,7 @@
#include "gc/shared/softRefPolicy.hpp"
#include "gc/shared/strongRootsScope.hpp"
#include "memory/metaspace.hpp"
#include "memory/metaspace/metaspaceSizesSnapshot.hpp"
#include "utilities/growableArray.hpp"
#include "utilities/ostream.hpp"

Expand Down Expand Up @@ -267,19 +268,18 @@ class PreGCValues {
PreGCValues(ParallelScavengeHeap* heap) :
_heap_used(heap->used()),
_young_gen_used(heap->young_gen()->used_in_bytes()),
_old_gen_used(heap->old_gen()->used_in_bytes()),
_metadata_used(MetaspaceUtils::used_bytes()) { };
_old_gen_used(heap->old_gen()->used_in_bytes()) { }

size_t heap_used() const { return _heap_used; }
size_t young_gen_used() const { return _young_gen_used; }
size_t old_gen_used() const { return _old_gen_used; }
size_t metadata_used() const { return _metadata_used; }
const metaspace::MetaspaceSizesSnapshot& metaspace_sizes() const { return _meta_sizes; }

private:
size_t _heap_used;
size_t _young_gen_used;
size_t _old_gen_used;
size_t _metadata_used;
const metaspace::MetaspaceSizesSnapshot _meta_sizes;
};

// Class that can be used to print information about the
Expand Down
12 changes: 4 additions & 8 deletions src/hotspot/share/gc/parallel/psMarkSweep.cpp
Expand Up @@ -190,11 +190,7 @@ bool PSMarkSweep::invoke_no_policy(bool clear_all_softrefs) {
CodeCache::gc_prologue();
BiasedLocking::preserve_marks();

// Capture metadata size before collection for sizing.
size_t metadata_prev_used = MetaspaceUtils::used_bytes();

size_t old_gen_prev_used = old_gen->used_in_bytes();
size_t young_gen_prev_used = young_gen->used_in_bytes();
const PreGCValues pre_gc_values(heap);

allocate_stacks();

Expand Down Expand Up @@ -351,9 +347,9 @@ bool PSMarkSweep::invoke_no_policy(bool clear_all_softrefs) {
accumulated_time()->stop();
}

young_gen->print_used_change(young_gen_prev_used);
old_gen->print_used_change(old_gen_prev_used);
MetaspaceUtils::print_metaspace_change(metadata_prev_used);
young_gen->print_used_change(pre_gc_values.young_gen_used());
old_gen->print_used_change(pre_gc_values.old_gen_used());
MetaspaceUtils::print_metaspace_change(pre_gc_values.metaspace_sizes());

// Track memory usage and detect low memory
MemoryService::track_memory_usage();
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/share/gc/parallel/psParallelCompact.cpp
Expand Up @@ -1753,7 +1753,7 @@ bool PSParallelCompact::invoke_no_policy(bool maximum_heap_compaction) {
// miscellaneous bookkeeping.
pre_compact();

PreGCValues pre_gc_values(heap);
const PreGCValues pre_gc_values(heap);

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

young_gen->print_used_change(pre_gc_values.young_gen_used());
old_gen->print_used_change(pre_gc_values.old_gen_used());
MetaspaceUtils::print_metaspace_change(pre_gc_values.metadata_used());
MetaspaceUtils::print_metaspace_change(pre_gc_values.metaspace_sizes());

// Track memory usage and detect low memory
MemoryService::track_memory_usage();
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/share/gc/parallel/psScavenge.cpp
Expand Up @@ -328,7 +328,7 @@ bool PSScavenge::invoke_no_policy() {
reference_processor()->enable_discovery();
reference_processor()->setup_policy(false);

PreGCValues pre_gc_values(heap);
const PreGCValues pre_gc_values(heap);

// Reset our survivor overflow.
set_survivor_overflow(false);
Expand Down Expand Up @@ -608,7 +608,7 @@ bool PSScavenge::invoke_no_policy() {

young_gen->print_used_change(pre_gc_values.young_gen_used());
old_gen->print_used_change(pre_gc_values.old_gen_used());
MetaspaceUtils::print_metaspace_change(pre_gc_values.metadata_used());
MetaspaceUtils::print_metaspace_change(pre_gc_values.metaspace_sizes());

// Track memory usage and detect low memory
MemoryService::track_memory_usage();
Expand Down
5 changes: 2 additions & 3 deletions src/hotspot/share/gc/shared/genCollectedHeap.cpp
Expand Up @@ -564,8 +564,6 @@ void GenCollectedHeap::do_collection(bool full,

ClearedAllSoftRefs casr(do_clear_all_soft_refs, soft_ref_policy());

const size_t metadata_prev_used = MetaspaceUtils::used_bytes();

print_heap_before_gc();

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

size_t young_prev_used = _young_gen->used();
size_t old_prev_used = _old_gen->used();
const metaspace::MetaspaceSizesSnapshot prev_meta_sizes;

bool run_verification = total_collections() >= VerifyGCStartAt;

Expand Down Expand Up @@ -650,7 +649,7 @@ void GenCollectedHeap::do_collection(bool full,
complete = complete || collected_old;

print_heap_change(young_prev_used, old_prev_used);
MetaspaceUtils::print_metaspace_change(metadata_prev_used);
MetaspaceUtils::print_metaspace_change(prev_meta_sizes);

// Adjust generation sizes.
if (collected_old) {
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/share/gc/shenandoah/shenandoahControlThread.cpp
Expand Up @@ -187,7 +187,7 @@ void ShenandoahControlThread::run_service() {
heap->reset_bytes_allocated_since_gc_start();

// Capture metaspace usage before GC.
const size_t metadata_prev_used = MetaspaceUtils::used_bytes();
const metaspace::MetaspaceSizesSnapshot prev_meta_sizes;

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

// Print Metaspace change following GC (if logging is enabled).
MetaspaceUtils::print_metaspace_change(metadata_prev_used);
MetaspaceUtils::print_metaspace_change(prev_meta_sizes);

// GC is over, we are at idle now
if (ShenandoahPacing) {
Expand Down
33 changes: 30 additions & 3 deletions src/hotspot/share/memory/metaspace.cpp
Expand Up @@ -470,9 +470,36 @@ MetaspaceChunkFreeListSummary MetaspaceUtils::chunk_free_list_summary(Metaspace:
return cm->chunk_free_list_summary();
}

void MetaspaceUtils::print_metaspace_change(size_t prev_metadata_used) {
log_info(gc, metaspace)("Metaspace: " SIZE_FORMAT "K->" SIZE_FORMAT "K(" SIZE_FORMAT "K)",
prev_metadata_used/K, used_bytes()/K, reserved_bytes()/K);
void MetaspaceUtils::print_metaspace_change(const metaspace::MetaspaceSizesSnapshot& pre_meta_values) {
const metaspace::MetaspaceSizesSnapshot meta_values;

if (Metaspace::using_class_space()) {
log_info(gc, metaspace)(HEAP_CHANGE_FORMAT" "
HEAP_CHANGE_FORMAT" "
HEAP_CHANGE_FORMAT,
HEAP_CHANGE_FORMAT_ARGS("Metaspace",
pre_meta_values.used(),
pre_meta_values.committed(),
meta_values.used(),
meta_values.committed()),
HEAP_CHANGE_FORMAT_ARGS("NonClass",
pre_meta_values.non_class_used(),
pre_meta_values.non_class_committed(),
meta_values.non_class_used(),
meta_values.non_class_committed()),
HEAP_CHANGE_FORMAT_ARGS("Class",
pre_meta_values.class_used(),
pre_meta_values.class_committed(),
meta_values.class_used(),
meta_values.class_committed()));
} else {
log_info(gc, metaspace)(HEAP_CHANGE_FORMAT,
HEAP_CHANGE_FORMAT_ARGS("Metaspace",
pre_meta_values.used(),
pre_meta_values.committed(),
meta_values.used(),
meta_values.committed()));
}
}

void MetaspaceUtils::print_on(outputStream* out) {
Expand Down
5 changes: 3 additions & 2 deletions src/hotspot/share/memory/metaspace.hpp
Expand Up @@ -28,6 +28,7 @@
#include "memory/memRegion.hpp"
#include "memory/metaspaceChunkFreeListSummary.hpp"
#include "memory/virtualspace.hpp"
#include "memory/metaspace/metaspaceSizesSnapshot.hpp"
#include "utilities/exceptions.hpp"
#include "utilities/macros.hpp"

Expand Down Expand Up @@ -427,8 +428,8 @@ class MetaspaceUtils : AllStatic {
static bool has_chunk_free_list(Metaspace::MetadataType mdtype);
static MetaspaceChunkFreeListSummary chunk_free_list_summary(Metaspace::MetadataType mdtype);

// Print change in used metadata.
static void print_metaspace_change(size_t prev_metadata_used);
// Log change in used metadata.
static void print_metaspace_change(const metaspace::MetaspaceSizesSnapshot& pre_meta_values);
static void print_on(outputStream * out);

// Prints an ASCII representation of the given space.
Expand Down
41 changes: 41 additions & 0 deletions src/hotspot/share/memory/metaspace/metaspaceSizesSnapshot.cpp
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, Twitter, Inc.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/

#include "precompiled.hpp"

#include "memory/metaspace.hpp"
#include "memory/metaspace/metaspaceSizesSnapshot.hpp"

namespace metaspace {

MetaspaceSizesSnapshot::MetaspaceSizesSnapshot()
: _used(MetaspaceUtils::used_bytes()),
_committed(MetaspaceUtils::committed_bytes()),
_non_class_used(MetaspaceUtils::used_bytes(Metaspace::NonClassType)),
_non_class_committed(MetaspaceUtils::committed_bytes(Metaspace::NonClassType)),
_class_used(MetaspaceUtils::used_bytes(Metaspace::ClassType)),
_class_committed(MetaspaceUtils::committed_bytes(Metaspace::ClassType)) { }

} // namespace metaspace
53 changes: 53 additions & 0 deletions src/hotspot/share/memory/metaspace/metaspaceSizesSnapshot.hpp
@@ -0,0 +1,53 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, Twitter, Inc.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/

#ifndef SHARE_MEMORY_METASPACE_METASPACESIZESSNAPSHOT_HPP
#define SHARE_MEMORY_METASPACE_METASPACESIZESSNAPSHOT_HPP

namespace metaspace {

class MetaspaceSizesSnapshot {
public:
MetaspaceSizesSnapshot();

size_t used() const { return _used; }
size_t committed() const { return _committed; }
size_t non_class_used() const { return _non_class_used; }
size_t non_class_committed() const { return _non_class_committed; }
size_t class_used() const { return _class_used; }
size_t class_committed() const { return _class_committed; }

private:
const size_t _used;
const size_t _committed;
const size_t _non_class_used;
const size_t _non_class_committed;
const size_t _class_used;
const size_t _class_committed;
};

} // namespace metaspace

#endif // SHARE_MEMORY_METASPACE_METASPACESIZESSNAPSHOT_HPP
7 changes: 7 additions & 0 deletions src/hotspot/share/utilities/globalDefinitions.hpp
Expand Up @@ -333,6 +333,13 @@ inline size_t byte_size_in_exact_unit(size_t s) {
return s;
}

// Memory size transition formatting.

#define HEAP_CHANGE_FORMAT "%s: " SIZE_FORMAT "K(" SIZE_FORMAT "K)->" SIZE_FORMAT "K(" SIZE_FORMAT "K)"

#define HEAP_CHANGE_FORMAT_ARGS(_name_, _prev_used_, _prev_capacity_, _used_, _capacity_) \
(_name_), (_prev_used_) / K, (_prev_capacity_) / K, (_used_) / K, (_capacity_) / K

//----------------------------------------------------------------------------------------------------
// VM type definitions

Expand Down

1 comment on commit bf0ebd2

@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.