2007-12-01 00:00:00 +00:00
|
|
|
/*
|
2013-01-28 15:41:45 +01:00
|
|
|
* Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
|
2007-12-01 00:00:00 +00:00
|
|
|
* 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.
|
|
|
|
*
|
2010-05-27 19:08:38 -07:00
|
|
|
* 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.
|
2007-12-01 00:00:00 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-11-23 13:22:55 -08:00
|
|
|
#ifndef SHARE_VM_MEMORY_COLLECTORPOLICY_HPP
|
|
|
|
#define SHARE_VM_MEMORY_COLLECTORPOLICY_HPP
|
|
|
|
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
#include "memory/allocation.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "memory/barrierSet.hpp"
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
#include "memory/generationSpec.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "memory/genRemSet.hpp"
|
2013-01-23 13:02:39 -05:00
|
|
|
#include "utilities/macros.hpp"
|
2010-11-23 13:22:55 -08:00
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
// This class (or more correctly, subtypes of this class)
|
|
|
|
// are used to define global garbage collector attributes.
|
|
|
|
// This includes initialization of generations and any other
|
|
|
|
// shared resources they may need.
|
|
|
|
//
|
|
|
|
// In general, all flag adjustment and validation should be
|
|
|
|
// done in initialize_flags(), which is called prior to
|
|
|
|
// initialize_size_info().
|
|
|
|
//
|
|
|
|
// This class is not fully developed yet. As more collector(s)
|
|
|
|
// are added, it is expected that we will come across further
|
|
|
|
// behavior that requires global attention. The correct place
|
|
|
|
// to deal with those issues is this class.
|
|
|
|
|
|
|
|
// Forward declarations.
|
|
|
|
class GenCollectorPolicy;
|
2008-06-05 15:57:56 -07:00
|
|
|
class AdaptiveSizePolicy;
|
2013-01-23 13:02:39 -05:00
|
|
|
#if INCLUDE_ALL_GCS
|
2007-12-01 00:00:00 +00:00
|
|
|
class ConcurrentMarkSweepPolicy;
|
2008-06-05 15:57:56 -07:00
|
|
|
class G1CollectorPolicy;
|
2013-01-23 13:02:39 -05:00
|
|
|
#endif // INCLUDE_ALL_GCS
|
2008-06-05 15:57:56 -07:00
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
class GCPolicyCounters;
|
|
|
|
class MarkSweepPolicy;
|
|
|
|
|
2012-06-28 17:03:16 -04:00
|
|
|
class CollectorPolicy : public CHeapObj<mtGC> {
|
2007-12-01 00:00:00 +00:00
|
|
|
protected:
|
|
|
|
GCPolicyCounters* _gc_policy_counters;
|
|
|
|
|
2013-11-01 17:09:38 +01:00
|
|
|
virtual void initialize_alignments() = 0;
|
2007-12-01 00:00:00 +00:00
|
|
|
virtual void initialize_flags();
|
2008-06-05 15:57:56 -07:00
|
|
|
virtual void initialize_size_info();
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2013-11-01 17:09:38 +01:00
|
|
|
DEBUG_ONLY(virtual void assert_flags();)
|
|
|
|
DEBUG_ONLY(virtual void assert_size_info();)
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
size_t _initial_heap_byte_size;
|
|
|
|
size_t _max_heap_byte_size;
|
|
|
|
size_t _min_heap_byte_size;
|
|
|
|
|
2013-11-01 17:09:38 +01:00
|
|
|
size_t _space_alignment;
|
|
|
|
size_t _heap_alignment;
|
|
|
|
|
|
|
|
// Needed to keep information if MaxHeapSize was set on the command line
|
2014-01-23 14:47:23 +01:00
|
|
|
// when the flag value is aligned etc by ergonomics.
|
2013-11-01 17:09:38 +01:00
|
|
|
bool _max_heap_size_cmdline;
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2014-01-23 14:47:23 +01:00
|
|
|
// The sizing of the heap is controlled by a sizing policy.
|
2010-04-13 13:52:10 -07:00
|
|
|
AdaptiveSizePolicy* _size_policy;
|
|
|
|
|
|
|
|
// Set to true when policy wants soft refs cleared.
|
|
|
|
// Reset to false by gc after it clears all soft refs.
|
|
|
|
bool _should_clear_all_soft_refs;
|
2013-10-21 18:56:20 +02:00
|
|
|
|
2010-04-13 13:52:10 -07:00
|
|
|
// Set to true by the GC if the just-completed gc cleared all
|
|
|
|
// softrefs. This is set to true whenever a gc clears all softrefs, and
|
|
|
|
// set to false each time gc returns to the mutator. For example, in the
|
|
|
|
// ParallelScavengeHeap case the latter would be done toward the end of
|
|
|
|
// mem_allocate() where it returns op.result()
|
|
|
|
bool _all_soft_refs_clear;
|
|
|
|
|
2013-11-01 17:09:38 +01:00
|
|
|
CollectorPolicy();
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
public:
|
2013-11-01 17:09:38 +01:00
|
|
|
virtual void initialize_all() {
|
|
|
|
initialize_alignments();
|
|
|
|
initialize_flags();
|
|
|
|
initialize_size_info();
|
|
|
|
}
|
|
|
|
|
2014-01-23 14:47:23 +01:00
|
|
|
// Return maximum heap alignment that may be imposed by the policy.
|
2013-11-01 17:09:38 +01:00
|
|
|
static size_t compute_heap_alignment();
|
2013-09-11 16:25:02 +02:00
|
|
|
|
2013-11-01 17:09:38 +01:00
|
|
|
size_t space_alignment() { return _space_alignment; }
|
|
|
|
size_t heap_alignment() { return _heap_alignment; }
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
size_t initial_heap_byte_size() { return _initial_heap_byte_size; }
|
|
|
|
size_t max_heap_byte_size() { return _max_heap_byte_size; }
|
|
|
|
size_t min_heap_byte_size() { return _min_heap_byte_size; }
|
|
|
|
|
|
|
|
enum Name {
|
|
|
|
CollectorPolicyKind,
|
2014-04-29 22:57:19 +02:00
|
|
|
GenCollectorPolicyKind,
|
2007-12-01 00:00:00 +00:00
|
|
|
ConcurrentMarkSweepPolicyKind,
|
2008-06-05 15:57:56 -07:00
|
|
|
G1CollectorPolicyKind
|
2007-12-01 00:00:00 +00:00
|
|
|
};
|
|
|
|
|
2010-04-13 13:52:10 -07:00
|
|
|
AdaptiveSizePolicy* size_policy() { return _size_policy; }
|
|
|
|
bool should_clear_all_soft_refs() { return _should_clear_all_soft_refs; }
|
|
|
|
void set_should_clear_all_soft_refs(bool v) { _should_clear_all_soft_refs = v; }
|
|
|
|
// Returns the current value of _should_clear_all_soft_refs.
|
|
|
|
// _should_clear_all_soft_refs is set to false as a side effect.
|
|
|
|
bool use_should_clear_all_soft_refs(bool v);
|
|
|
|
bool all_soft_refs_clear() { return _all_soft_refs_clear; }
|
|
|
|
void set_all_soft_refs_clear(bool v) { _all_soft_refs_clear = v; }
|
|
|
|
|
|
|
|
// Called by the GC after Soft Refs have been cleared to indicate
|
|
|
|
// that the request in _should_clear_all_soft_refs has been fulfilled.
|
|
|
|
void cleared_all_soft_refs();
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
// Identification methods.
|
2008-06-05 15:57:56 -07:00
|
|
|
virtual GenCollectorPolicy* as_generation_policy() { return NULL; }
|
2007-12-01 00:00:00 +00:00
|
|
|
virtual MarkSweepPolicy* as_mark_sweep_policy() { return NULL; }
|
2013-01-23 13:02:39 -05:00
|
|
|
#if INCLUDE_ALL_GCS
|
2007-12-01 00:00:00 +00:00
|
|
|
virtual ConcurrentMarkSweepPolicy* as_concurrent_mark_sweep_policy() { return NULL; }
|
2008-06-05 15:57:56 -07:00
|
|
|
virtual G1CollectorPolicy* as_g1_policy() { return NULL; }
|
2013-01-23 13:02:39 -05:00
|
|
|
#endif // INCLUDE_ALL_GCS
|
2007-12-01 00:00:00 +00:00
|
|
|
// Note that these are not virtual.
|
|
|
|
bool is_generation_policy() { return as_generation_policy() != NULL; }
|
|
|
|
bool is_mark_sweep_policy() { return as_mark_sweep_policy() != NULL; }
|
2013-01-23 13:02:39 -05:00
|
|
|
#if INCLUDE_ALL_GCS
|
2007-12-01 00:00:00 +00:00
|
|
|
bool is_concurrent_mark_sweep_policy() { return as_concurrent_mark_sweep_policy() != NULL; }
|
2008-06-05 15:57:56 -07:00
|
|
|
bool is_g1_policy() { return as_g1_policy() != NULL; }
|
2013-01-23 13:02:39 -05:00
|
|
|
#else // INCLUDE_ALL_GCS
|
2007-12-01 00:00:00 +00:00
|
|
|
bool is_concurrent_mark_sweep_policy() { return false; }
|
2008-06-05 15:57:56 -07:00
|
|
|
bool is_g1_policy() { return false; }
|
2013-01-23 13:02:39 -05:00
|
|
|
#endif // INCLUDE_ALL_GCS
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2008-06-05 15:57:56 -07:00
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
virtual BarrierSet::Name barrier_set_name() = 0;
|
|
|
|
|
|
|
|
// Create the remembered set (to cover the given reserved region,
|
|
|
|
// allowing breaking up into at most "max_covered_regions").
|
|
|
|
virtual GenRemSet* create_rem_set(MemRegion reserved,
|
|
|
|
int max_covered_regions);
|
|
|
|
|
|
|
|
// This method controls how a collector satisfies a request
|
|
|
|
// for a block of memory. "gc_time_limit_was_exceeded" will
|
|
|
|
// be set to true if the adaptive size policy determine that
|
|
|
|
// an excessive amount of time is being spent doing collections
|
|
|
|
// and caused a NULL to be returned. If a NULL is not returned,
|
|
|
|
// "gc_time_limit_was_exceeded" has an undefined meaning.
|
|
|
|
virtual HeapWord* mem_allocate_work(size_t size,
|
|
|
|
bool is_tlab,
|
|
|
|
bool* gc_overhead_limit_was_exceeded) = 0;
|
|
|
|
|
|
|
|
// This method controls how a collector handles one or more
|
|
|
|
// of its generations being fully allocated.
|
|
|
|
virtual HeapWord *satisfy_failed_allocation(size_t size, bool is_tlab) = 0;
|
6964458: Reimplement class meta-data storage to use native memory
Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Tom Rodriguez <tom.rodriguez@oracle.com>
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
2012-09-01 13:25:18 -04:00
|
|
|
// This method controls how a collector handles a metadata allocation
|
|
|
|
// failure.
|
|
|
|
virtual MetaWord* satisfy_failed_metadata_allocation(ClassLoaderData* loader_data,
|
|
|
|
size_t size,
|
|
|
|
Metaspace::MetadataType mdtype);
|
|
|
|
|
2014-01-23 14:47:23 +01:00
|
|
|
// Performance Counter support
|
2007-12-01 00:00:00 +00:00
|
|
|
GCPolicyCounters* counters() { return _gc_policy_counters; }
|
|
|
|
|
|
|
|
// Create the jstat counters for the GC policy. By default, policy's
|
|
|
|
// don't have associated counters, and we complain if this is invoked.
|
|
|
|
virtual void initialize_gc_policy_counters() {
|
|
|
|
ShouldNotReachHere();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual CollectorPolicy::Name kind() {
|
|
|
|
return CollectorPolicy::CollectorPolicyKind;
|
|
|
|
}
|
|
|
|
|
2013-11-01 17:09:38 +01:00
|
|
|
// Do any updates required to global flags that are due to heap initialization
|
|
|
|
// changes
|
|
|
|
virtual void post_heap_initialize() = 0;
|
2007-12-01 00:00:00 +00:00
|
|
|
};
|
|
|
|
|
2010-04-13 13:52:10 -07:00
|
|
|
class ClearedAllSoftRefs : public StackObj {
|
|
|
|
bool _clear_all_soft_refs;
|
|
|
|
CollectorPolicy* _collector_policy;
|
|
|
|
public:
|
|
|
|
ClearedAllSoftRefs(bool clear_all_soft_refs,
|
|
|
|
CollectorPolicy* collector_policy) :
|
|
|
|
_clear_all_soft_refs(clear_all_soft_refs),
|
|
|
|
_collector_policy(collector_policy) {}
|
|
|
|
|
|
|
|
~ClearedAllSoftRefs() {
|
|
|
|
if (_clear_all_soft_refs) {
|
|
|
|
_collector_policy->cleared_all_soft_refs();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
class GenCollectorPolicy : public CollectorPolicy {
|
2014-02-05 11:05:13 +01:00
|
|
|
friend class TestGenCollectorPolicy;
|
2007-12-01 00:00:00 +00:00
|
|
|
protected:
|
2014-05-02 02:11:34 +02:00
|
|
|
size_t _min_young_size;
|
|
|
|
size_t _initial_young_size;
|
|
|
|
size_t _max_young_size;
|
|
|
|
size_t _min_old_size;
|
|
|
|
size_t _initial_old_size;
|
|
|
|
size_t _max_old_size;
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2013-11-01 17:09:38 +01:00
|
|
|
// _gen_alignment and _space_alignment will have the same value most of the
|
|
|
|
// time. When using large pages they can differ.
|
|
|
|
size_t _gen_alignment;
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
GenerationSpec **_generations;
|
|
|
|
|
2014-01-23 14:47:23 +01:00
|
|
|
// Return true if an allocation should be attempted in the older generation
|
|
|
|
// if it fails in the younger generation. Return false, otherwise.
|
2007-12-01 00:00:00 +00:00
|
|
|
virtual bool should_try_older_generation_allocation(size_t word_size) const;
|
|
|
|
|
|
|
|
void initialize_flags();
|
|
|
|
void initialize_size_info();
|
|
|
|
|
2013-11-01 17:09:38 +01:00
|
|
|
DEBUG_ONLY(void assert_flags();)
|
|
|
|
DEBUG_ONLY(void assert_size_info();)
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
// Try to allocate space by expanding the heap.
|
|
|
|
virtual HeapWord* expand_heap_and_allocate(size_t size, bool is_tlab);
|
|
|
|
|
2014-01-23 14:47:23 +01:00
|
|
|
// Compute max heap alignment.
|
2013-11-01 17:09:38 +01:00
|
|
|
size_t compute_max_alignment();
|
|
|
|
|
2014-03-19 17:08:03 +01:00
|
|
|
// Scale the base_size by NewRatio according to
|
|
|
|
// result = base_size / (NewRatio + 1)
|
|
|
|
// and align by min_alignment()
|
|
|
|
size_t scale_by_NewRatio_aligned(size_t base_size);
|
2008-03-02 16:10:12 -08:00
|
|
|
|
2014-03-19 17:08:03 +01:00
|
|
|
// Bound the value by the given maximum minus the min_alignment.
|
|
|
|
size_t bound_minus_alignment(size_t desired_size, size_t maximum_size);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
public:
|
2013-11-01 17:09:38 +01:00
|
|
|
GenCollectorPolicy();
|
|
|
|
|
2008-03-02 16:10:12 -08:00
|
|
|
// Accessors
|
2014-05-02 02:11:34 +02:00
|
|
|
size_t min_young_size() { return _min_young_size; }
|
|
|
|
size_t initial_young_size() { return _initial_young_size; }
|
|
|
|
size_t max_young_size() { return _max_young_size; }
|
|
|
|
size_t gen_alignment() { return _gen_alignment; }
|
|
|
|
size_t min_old_size() { return _min_old_size; }
|
|
|
|
size_t initial_old_size() { return _initial_old_size; }
|
|
|
|
size_t max_old_size() { return _max_old_size; }
|
2008-03-02 16:10:12 -08:00
|
|
|
|
2014-04-29 22:57:19 +02:00
|
|
|
int number_of_generations() { return 2; }
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2013-10-21 18:56:20 +02:00
|
|
|
virtual GenerationSpec **generations() {
|
2007-12-01 00:00:00 +00:00
|
|
|
assert(_generations != NULL, "Sanity check");
|
|
|
|
return _generations;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual GenCollectorPolicy* as_generation_policy() { return this; }
|
|
|
|
|
2013-11-01 17:09:38 +01:00
|
|
|
virtual void initialize_generations() { };
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
virtual void initialize_all() {
|
2013-11-01 17:09:38 +01:00
|
|
|
CollectorPolicy::initialize_all();
|
2007-12-01 00:00:00 +00:00
|
|
|
initialize_generations();
|
|
|
|
}
|
|
|
|
|
2013-11-01 17:09:38 +01:00
|
|
|
size_t young_gen_size_lower_bound();
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
HeapWord* mem_allocate_work(size_t size,
|
|
|
|
bool is_tlab,
|
|
|
|
bool* gc_overhead_limit_was_exceeded);
|
|
|
|
|
|
|
|
HeapWord *satisfy_failed_allocation(size_t size, bool is_tlab);
|
|
|
|
|
|
|
|
// Adaptive size policy
|
|
|
|
virtual void initialize_size_policy(size_t init_eden_size,
|
|
|
|
size_t init_promo_size,
|
|
|
|
size_t init_survivor_size);
|
2013-10-21 18:56:20 +02:00
|
|
|
|
2013-11-01 17:09:38 +01:00
|
|
|
virtual void post_heap_initialize() {
|
2014-05-02 02:11:34 +02:00
|
|
|
assert(_max_young_size == MaxNewSize, "Should be taken care of by initialize_size_info");
|
2013-10-21 18:56:20 +02:00
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2013-10-21 18:56:20 +02:00
|
|
|
BarrierSet::Name barrier_set_name() { return BarrierSet::CardTableModRef; }
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
virtual CollectorPolicy::Name kind() {
|
2014-04-29 22:57:19 +02:00
|
|
|
return CollectorPolicy::GenCollectorPolicyKind;
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-04-29 22:57:19 +02:00
|
|
|
class MarkSweepPolicy : public GenCollectorPolicy {
|
2007-12-01 00:00:00 +00:00
|
|
|
protected:
|
2013-11-01 17:09:38 +01:00
|
|
|
void initialize_alignments();
|
2007-12-01 00:00:00 +00:00
|
|
|
void initialize_generations();
|
|
|
|
|
|
|
|
public:
|
2013-11-01 17:09:38 +01:00
|
|
|
MarkSweepPolicy() {}
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
MarkSweepPolicy* as_mark_sweep_policy() { return this; }
|
|
|
|
|
|
|
|
void initialize_gc_policy_counters();
|
|
|
|
};
|
2010-11-23 13:22:55 -08:00
|
|
|
|
|
|
|
#endif // SHARE_VM_MEMORY_COLLECTORPOLICY_HPP
|