mirror of
https://github.com/openjdk/jdk.git
synced 2026-04-09 14:38:42 +00:00
8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces
Reviewed-by: brutisso, jmasa, coleenp
This commit is contained in:
parent
30ed89669a
commit
55cbe80300
@ -214,9 +214,6 @@ class VM_CollectForMetadataAllocation: public VM_GC_Operation {
|
||||
: VM_GC_Operation(gc_count_before, gc_cause, full_gc_count_before, true),
|
||||
_loader_data(loader_data), _size(size), _mdtype(mdtype), _result(NULL) {
|
||||
}
|
||||
~VM_CollectForMetadataAllocation() {
|
||||
MetaspaceGC::set_expand_after_GC(false);
|
||||
}
|
||||
virtual VMOp_Type type() const { return VMOp_CollectForMetadataAllocation; }
|
||||
virtual void doit();
|
||||
MetaWord* result() const { return _result; }
|
||||
|
||||
@ -202,12 +202,6 @@ void CollectedHeap::collect_as_vm_thread(GCCause::Cause cause) {
|
||||
ShouldNotReachHere(); // Unexpected use of this function
|
||||
}
|
||||
}
|
||||
MetaWord* CollectedHeap::satisfy_failed_metadata_allocation(
|
||||
ClassLoaderData* loader_data,
|
||||
size_t size, Metaspace::MetadataType mdtype) {
|
||||
return collector_policy()->satisfy_failed_metadata_allocation(loader_data, size, mdtype);
|
||||
}
|
||||
|
||||
|
||||
void CollectedHeap::pre_initialize() {
|
||||
// Used for ReduceInitialCardMarks (when COMPILER2 is used);
|
||||
|
||||
@ -475,11 +475,6 @@ class CollectedHeap : public CHeapObj<mtInternal> {
|
||||
// the context of the vm thread.
|
||||
virtual void collect_as_vm_thread(GCCause::Cause cause);
|
||||
|
||||
// Callback from VM_CollectForMetadataAllocation operation.
|
||||
MetaWord* satisfy_failed_metadata_allocation(ClassLoaderData* loader_data,
|
||||
size_t size,
|
||||
Metaspace::MetadataType mdtype);
|
||||
|
||||
// Returns the barrier set for this heap
|
||||
BarrierSet* barrier_set() { return _barrier_set; }
|
||||
|
||||
|
||||
@ -47,11 +47,6 @@
|
||||
|
||||
// CollectorPolicy methods.
|
||||
|
||||
// Align down. If the aligning result in 0, return 'alignment'.
|
||||
static size_t restricted_align_down(size_t size, size_t alignment) {
|
||||
return MAX2(alignment, align_size_down_(size, alignment));
|
||||
}
|
||||
|
||||
void CollectorPolicy::initialize_flags() {
|
||||
assert(_max_alignment >= _min_alignment,
|
||||
err_msg("max_alignment: " SIZE_FORMAT " less than min_alignment: " SIZE_FORMAT,
|
||||
@ -64,34 +59,7 @@ void CollectorPolicy::initialize_flags() {
|
||||
vm_exit_during_initialization("Incompatible initial and maximum heap sizes specified");
|
||||
}
|
||||
|
||||
// Do not use FLAG_SET_ERGO to update MaxMetaspaceSize, since this will
|
||||
// override if MaxMetaspaceSize was set on the command line or not.
|
||||
// This information is needed later to conform to the specification of the
|
||||
// java.lang.management.MemoryUsage API.
|
||||
//
|
||||
// Ideally, we would be able to set the default value of MaxMetaspaceSize in
|
||||
// globals.hpp to the aligned value, but this is not possible, since the
|
||||
// alignment depends on other flags being parsed.
|
||||
MaxMetaspaceSize = restricted_align_down(MaxMetaspaceSize, _max_alignment);
|
||||
|
||||
if (MetaspaceSize > MaxMetaspaceSize) {
|
||||
MetaspaceSize = MaxMetaspaceSize;
|
||||
}
|
||||
|
||||
MetaspaceSize = restricted_align_down(MetaspaceSize, _min_alignment);
|
||||
|
||||
assert(MetaspaceSize <= MaxMetaspaceSize, "Must be");
|
||||
|
||||
MinMetaspaceExpansion = restricted_align_down(MinMetaspaceExpansion, _min_alignment);
|
||||
MaxMetaspaceExpansion = restricted_align_down(MaxMetaspaceExpansion, _min_alignment);
|
||||
|
||||
MinHeapDeltaBytes = align_size_up(MinHeapDeltaBytes, _min_alignment);
|
||||
|
||||
assert(MetaspaceSize % _min_alignment == 0, "metapace alignment");
|
||||
assert(MaxMetaspaceSize % _max_alignment == 0, "maximum metaspace alignment");
|
||||
if (MetaspaceSize < 256*K) {
|
||||
vm_exit_during_initialization("Too small initial Metaspace size");
|
||||
}
|
||||
}
|
||||
|
||||
void CollectorPolicy::initialize_size_info() {
|
||||
|
||||
@ -26,6 +26,7 @@
|
||||
#define SHARE_VM_MEMORY_FILEMAP_HPP
|
||||
|
||||
#include "memory/metaspaceShared.hpp"
|
||||
#include "memory/metaspace.hpp"
|
||||
|
||||
// Layout of the file:
|
||||
// header: dump of archive instance plus versioning info, datestamp, etc.
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -87,9 +87,10 @@ class Metaspace : public CHeapObj<mtClass> {
|
||||
friend class MetaspaceAux;
|
||||
|
||||
public:
|
||||
enum MetadataType {ClassType = 0,
|
||||
NonClassType = ClassType + 1,
|
||||
MetadataTypeCount = ClassType + 2
|
||||
enum MetadataType {
|
||||
ClassType,
|
||||
NonClassType,
|
||||
MetadataTypeCount
|
||||
};
|
||||
enum MetaspaceType {
|
||||
StandardMetaspaceType,
|
||||
@ -103,6 +104,9 @@ class Metaspace : public CHeapObj<mtClass> {
|
||||
private:
|
||||
void initialize(Mutex* lock, MetaspaceType type);
|
||||
|
||||
// Get the first chunk for a Metaspace. Used for
|
||||
// special cases such as the boot class loader, reflection
|
||||
// class loader and anonymous class loader.
|
||||
Metachunk* get_initialization_chunk(MetadataType mdtype,
|
||||
size_t chunk_word_size,
|
||||
size_t chunk_bunch);
|
||||
@ -123,6 +127,9 @@ class Metaspace : public CHeapObj<mtClass> {
|
||||
static size_t _first_chunk_word_size;
|
||||
static size_t _first_class_chunk_word_size;
|
||||
|
||||
static size_t _commit_alignment;
|
||||
static size_t _reserve_alignment;
|
||||
|
||||
SpaceManager* _vsm;
|
||||
SpaceManager* vsm() const { return _vsm; }
|
||||
|
||||
@ -191,12 +198,17 @@ class Metaspace : public CHeapObj<mtClass> {
|
||||
Metaspace(Mutex* lock, MetaspaceType type);
|
||||
~Metaspace();
|
||||
|
||||
// Initialize globals for Metaspace
|
||||
static void ergo_initialize();
|
||||
static void global_initialize();
|
||||
|
||||
static size_t first_chunk_word_size() { return _first_chunk_word_size; }
|
||||
static size_t first_class_chunk_word_size() { return _first_class_chunk_word_size; }
|
||||
|
||||
static size_t reserve_alignment() { return _reserve_alignment; }
|
||||
static size_t reserve_alignment_words() { return _reserve_alignment / BytesPerWord; }
|
||||
static size_t commit_alignment() { return _commit_alignment; }
|
||||
static size_t commit_alignment_words() { return _commit_alignment / BytesPerWord; }
|
||||
|
||||
char* bottom() const;
|
||||
size_t used_words_slow(MetadataType mdtype) const;
|
||||
size_t free_words_slow(MetadataType mdtype) const;
|
||||
@ -219,6 +231,9 @@ class Metaspace : public CHeapObj<mtClass> {
|
||||
static void purge(MetadataType mdtype);
|
||||
static void purge();
|
||||
|
||||
static void report_metadata_oome(ClassLoaderData* loader_data, size_t word_size,
|
||||
MetadataType mdtype, TRAPS);
|
||||
|
||||
void print_on(outputStream* st) const;
|
||||
// Debugging support
|
||||
void verify();
|
||||
@ -352,17 +367,10 @@ class MetaspaceAux : AllStatic {
|
||||
|
||||
class MetaspaceGC : AllStatic {
|
||||
|
||||
// The current high-water-mark for inducing a GC. When
|
||||
// the capacity of all space in the virtual lists reaches this value,
|
||||
// a GC is induced and the value is increased. This should be changed
|
||||
// to the space actually used for allocations to avoid affects of
|
||||
// fragmentation losses to partially used chunks. Size is in words.
|
||||
static size_t _capacity_until_GC;
|
||||
|
||||
// After a GC is done any allocation that fails should try to expand
|
||||
// the capacity of the Metaspaces. This flag is set during attempts
|
||||
// to allocate in the VMGCOperation that does the GC.
|
||||
static bool _expand_after_GC;
|
||||
// The current high-water-mark for inducing a GC.
|
||||
// When committed memory of all metaspaces reaches this value,
|
||||
// a GC is induced and the value is increased. Size is in bytes.
|
||||
static volatile intptr_t _capacity_until_GC;
|
||||
|
||||
// For a CMS collection, signal that a concurrent collection should
|
||||
// be started.
|
||||
@ -370,20 +378,16 @@ class MetaspaceGC : AllStatic {
|
||||
|
||||
static uint _shrink_factor;
|
||||
|
||||
static void set_capacity_until_GC(size_t v) { _capacity_until_GC = v; }
|
||||
|
||||
static size_t shrink_factor() { return _shrink_factor; }
|
||||
void set_shrink_factor(uint v) { _shrink_factor = v; }
|
||||
|
||||
public:
|
||||
|
||||
static size_t capacity_until_GC() { return _capacity_until_GC; }
|
||||
static void inc_capacity_until_GC(size_t v) { _capacity_until_GC += v; }
|
||||
static void dec_capacity_until_GC(size_t v) {
|
||||
_capacity_until_GC = _capacity_until_GC > v ? _capacity_until_GC - v : 0;
|
||||
}
|
||||
static bool expand_after_GC() { return _expand_after_GC; }
|
||||
static void set_expand_after_GC(bool v) { _expand_after_GC = v; }
|
||||
static void initialize() { _capacity_until_GC = MetaspaceSize; }
|
||||
|
||||
static size_t capacity_until_GC();
|
||||
static size_t inc_capacity_until_GC(size_t v);
|
||||
static size_t dec_capacity_until_GC(size_t v);
|
||||
|
||||
static bool should_concurrent_collect() { return _should_concurrent_collect; }
|
||||
static void set_should_concurrent_collect(bool v) {
|
||||
@ -391,11 +395,14 @@ class MetaspaceGC : AllStatic {
|
||||
}
|
||||
|
||||
// The amount to increase the high-water-mark (_capacity_until_GC)
|
||||
static size_t delta_capacity_until_GC(size_t word_size);
|
||||
static size_t delta_capacity_until_GC(size_t bytes);
|
||||
|
||||
// It is expected that this will be called when the current capacity
|
||||
// has been used and a GC should be considered.
|
||||
static bool should_expand(VirtualSpaceList* vsl, size_t word_size);
|
||||
// Tells if we have can expand metaspace without hitting set limits.
|
||||
static bool can_expand(size_t words, bool is_class);
|
||||
|
||||
// Returns amount that we can expand without hitting a GC,
|
||||
// measured in words.
|
||||
static size_t allowed_expansion();
|
||||
|
||||
// Calculate the new high-water mark at which to induce
|
||||
// a GC.
|
||||
|
||||
@ -3656,6 +3656,9 @@ jint Arguments::apply_ergo() {
|
||||
assert(verify_serial_gc_flags(), "SerialGC unset");
|
||||
#endif // INCLUDE_ALL_GCS
|
||||
|
||||
// Initialize Metaspace flags and alignments.
|
||||
Metaspace::ergo_initialize();
|
||||
|
||||
// Set bytecode rewriting flags
|
||||
set_bytecode_flags();
|
||||
|
||||
|
||||
@ -502,6 +502,10 @@ class CommandLineFlags {
|
||||
develop(bool, LargePagesIndividualAllocationInjectError, false, \
|
||||
"Fail large pages individual allocation") \
|
||||
\
|
||||
product(bool, UseLargePagesInMetaspace, false, \
|
||||
"Use large page memory in metaspace. " \
|
||||
"Only used if UseLargePages is enabled.") \
|
||||
\
|
||||
develop(bool, TracePageSizes, false, \
|
||||
"Trace page size selection and usage") \
|
||||
\
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user