提交 f6921aa8 编写于 作者: S stefank

8024547: MaxMetaspaceSize should limit the committed memory used by the metaspaces

Reviewed-by: brutisso, jmasa, coleenp
上级 e540de76
...@@ -214,9 +214,6 @@ class VM_CollectForMetadataAllocation: public VM_GC_Operation { ...@@ -214,9 +214,6 @@ class VM_CollectForMetadataAllocation: public VM_GC_Operation {
: VM_GC_Operation(gc_count_before, gc_cause, full_gc_count_before, true), : VM_GC_Operation(gc_count_before, gc_cause, full_gc_count_before, true),
_loader_data(loader_data), _size(size), _mdtype(mdtype), _result(NULL) { _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 VMOp_Type type() const { return VMOp_CollectForMetadataAllocation; }
virtual void doit(); virtual void doit();
MetaWord* result() const { return _result; } MetaWord* result() const { return _result; }
......
...@@ -202,12 +202,6 @@ void CollectedHeap::collect_as_vm_thread(GCCause::Cause cause) { ...@@ -202,12 +202,6 @@ void CollectedHeap::collect_as_vm_thread(GCCause::Cause cause) {
ShouldNotReachHere(); // Unexpected use of this function 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() { void CollectedHeap::pre_initialize() {
// Used for ReduceInitialCardMarks (when COMPILER2 is used); // Used for ReduceInitialCardMarks (when COMPILER2 is used);
......
...@@ -475,11 +475,6 @@ class CollectedHeap : public CHeapObj<mtInternal> { ...@@ -475,11 +475,6 @@ class CollectedHeap : public CHeapObj<mtInternal> {
// the context of the vm thread. // the context of the vm thread.
virtual void collect_as_vm_thread(GCCause::Cause cause); 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 // Returns the barrier set for this heap
BarrierSet* barrier_set() { return _barrier_set; } BarrierSet* barrier_set() { return _barrier_set; }
......
...@@ -47,11 +47,6 @@ ...@@ -47,11 +47,6 @@
// CollectorPolicy methods. // 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() { void CollectorPolicy::initialize_flags() {
assert(_max_alignment >= _min_alignment, assert(_max_alignment >= _min_alignment,
err_msg("max_alignment: " SIZE_FORMAT " less than min_alignment: " SIZE_FORMAT, err_msg("max_alignment: " SIZE_FORMAT " less than min_alignment: " SIZE_FORMAT,
...@@ -64,34 +59,7 @@ void CollectorPolicy::initialize_flags() { ...@@ -64,34 +59,7 @@ void CollectorPolicy::initialize_flags() {
vm_exit_during_initialization("Incompatible initial and maximum heap sizes specified"); 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); 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() { void CollectorPolicy::initialize_size_info() {
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#define SHARE_VM_MEMORY_FILEMAP_HPP #define SHARE_VM_MEMORY_FILEMAP_HPP
#include "memory/metaspaceShared.hpp" #include "memory/metaspaceShared.hpp"
#include "memory/metaspace.hpp"
// Layout of the file: // Layout of the file:
// header: dump of archive instance plus versioning info, datestamp, etc. // header: dump of archive instance plus versioning info, datestamp, etc.
......
此差异已折叠。
...@@ -87,9 +87,10 @@ class Metaspace : public CHeapObj<mtClass> { ...@@ -87,9 +87,10 @@ class Metaspace : public CHeapObj<mtClass> {
friend class MetaspaceAux; friend class MetaspaceAux;
public: public:
enum MetadataType {ClassType = 0, enum MetadataType {
NonClassType = ClassType + 1, ClassType,
MetadataTypeCount = ClassType + 2 NonClassType,
MetadataTypeCount
}; };
enum MetaspaceType { enum MetaspaceType {
StandardMetaspaceType, StandardMetaspaceType,
...@@ -103,6 +104,9 @@ class Metaspace : public CHeapObj<mtClass> { ...@@ -103,6 +104,9 @@ class Metaspace : public CHeapObj<mtClass> {
private: private:
void initialize(Mutex* lock, MetaspaceType type); 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, Metachunk* get_initialization_chunk(MetadataType mdtype,
size_t chunk_word_size, size_t chunk_word_size,
size_t chunk_bunch); size_t chunk_bunch);
...@@ -123,6 +127,9 @@ class Metaspace : public CHeapObj<mtClass> { ...@@ -123,6 +127,9 @@ class Metaspace : public CHeapObj<mtClass> {
static size_t _first_chunk_word_size; static size_t _first_chunk_word_size;
static size_t _first_class_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;
SpaceManager* vsm() const { return _vsm; } SpaceManager* vsm() const { return _vsm; }
...@@ -191,12 +198,17 @@ class Metaspace : public CHeapObj<mtClass> { ...@@ -191,12 +198,17 @@ class Metaspace : public CHeapObj<mtClass> {
Metaspace(Mutex* lock, MetaspaceType type); Metaspace(Mutex* lock, MetaspaceType type);
~Metaspace(); ~Metaspace();
// Initialize globals for Metaspace static void ergo_initialize();
static void global_initialize(); static void global_initialize();
static size_t first_chunk_word_size() { return _first_chunk_word_size; } 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 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; char* bottom() const;
size_t used_words_slow(MetadataType mdtype) const; size_t used_words_slow(MetadataType mdtype) const;
size_t free_words_slow(MetadataType mdtype) const; size_t free_words_slow(MetadataType mdtype) const;
...@@ -219,6 +231,9 @@ class Metaspace : public CHeapObj<mtClass> { ...@@ -219,6 +231,9 @@ class Metaspace : public CHeapObj<mtClass> {
static void purge(MetadataType mdtype); static void purge(MetadataType mdtype);
static void purge(); static void purge();
static void report_metadata_oome(ClassLoaderData* loader_data, size_t word_size,
MetadataType mdtype, TRAPS);
void print_on(outputStream* st) const; void print_on(outputStream* st) const;
// Debugging support // Debugging support
void verify(); void verify();
...@@ -352,17 +367,10 @@ class MetaspaceAux : AllStatic { ...@@ -352,17 +367,10 @@ class MetaspaceAux : AllStatic {
class MetaspaceGC : AllStatic { class MetaspaceGC : AllStatic {
// The current high-water-mark for inducing a GC. When // The current high-water-mark for inducing a GC.
// the capacity of all space in the virtual lists reaches this value, // When committed memory of all metaspaces reaches this value,
// a GC is induced and the value is increased. This should be changed // a GC is induced and the value is increased. Size is in bytes.
// to the space actually used for allocations to avoid affects of static volatile intptr_t _capacity_until_GC;
// 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;
// For a CMS collection, signal that a concurrent collection should // For a CMS collection, signal that a concurrent collection should
// be started. // be started.
...@@ -370,20 +378,16 @@ class MetaspaceGC : AllStatic { ...@@ -370,20 +378,16 @@ class MetaspaceGC : AllStatic {
static uint _shrink_factor; 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; } static size_t shrink_factor() { return _shrink_factor; }
void set_shrink_factor(uint v) { _shrink_factor = v; } void set_shrink_factor(uint v) { _shrink_factor = v; }
public: public:
static size_t capacity_until_GC() { return _capacity_until_GC; } static void initialize() { _capacity_until_GC = MetaspaceSize; }
static void inc_capacity_until_GC(size_t v) { _capacity_until_GC += v; }
static void dec_capacity_until_GC(size_t v) { static size_t capacity_until_GC();
_capacity_until_GC = _capacity_until_GC > v ? _capacity_until_GC - v : 0; static size_t inc_capacity_until_GC(size_t v);
} static size_t dec_capacity_until_GC(size_t v);
static bool expand_after_GC() { return _expand_after_GC; }
static void set_expand_after_GC(bool v) { _expand_after_GC = v; }
static bool should_concurrent_collect() { return _should_concurrent_collect; } static bool should_concurrent_collect() { return _should_concurrent_collect; }
static void set_should_concurrent_collect(bool v) { static void set_should_concurrent_collect(bool v) {
...@@ -391,11 +395,14 @@ class MetaspaceGC : AllStatic { ...@@ -391,11 +395,14 @@ class MetaspaceGC : AllStatic {
} }
// The amount to increase the high-water-mark (_capacity_until_GC) // 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);
// Tells if we have can expand metaspace without hitting set limits.
static bool can_expand(size_t words, bool is_class);
// It is expected that this will be called when the current capacity // Returns amount that we can expand without hitting a GC,
// has been used and a GC should be considered. // measured in words.
static bool should_expand(VirtualSpaceList* vsl, size_t word_size); static size_t allowed_expansion();
// Calculate the new high-water mark at which to induce // Calculate the new high-water mark at which to induce
// a GC. // a GC.
......
...@@ -3656,6 +3656,9 @@ jint Arguments::apply_ergo() { ...@@ -3656,6 +3656,9 @@ jint Arguments::apply_ergo() {
assert(verify_serial_gc_flags(), "SerialGC unset"); assert(verify_serial_gc_flags(), "SerialGC unset");
#endif // INCLUDE_ALL_GCS #endif // INCLUDE_ALL_GCS
// Initialize Metaspace flags and alignments.
Metaspace::ergo_initialize();
// Set bytecode rewriting flags // Set bytecode rewriting flags
set_bytecode_flags(); set_bytecode_flags();
......
...@@ -502,6 +502,10 @@ class CommandLineFlags { ...@@ -502,6 +502,10 @@ class CommandLineFlags {
develop(bool, LargePagesIndividualAllocationInjectError, false, \ develop(bool, LargePagesIndividualAllocationInjectError, false, \
"Fail large pages individual allocation") \ "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, \ develop(bool, TracePageSizes, false, \
"Trace page size selection and usage") \ "Trace page size selection and usage") \
\ \
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册