duke@435: /* brutisso@3711: * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #ifndef SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSOLDGEN_HPP stefank@2314: #define SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSOLDGEN_HPP stefank@2314: stefank@2314: #include "gc_implementation/parallelScavenge/objectStartArray.hpp" stefank@2314: #include "gc_implementation/parallelScavenge/psGenerationCounters.hpp" stefank@2314: #include "gc_implementation/parallelScavenge/psVirtualspace.hpp" stefank@2314: #include "gc_implementation/shared/mutableSpace.hpp" stefank@2314: #include "gc_implementation/shared/spaceCounters.hpp" stefank@2314: #include "runtime/safepoint.hpp" stefank@2314: duke@435: class PSMarkSweepDecorator; duke@435: zgu@3900: class PSOldGen : public CHeapObj { duke@435: friend class VMStructs; duke@435: friend class PSPromotionManager; // Uses the cas_allocate methods duke@435: friend class ParallelScavengeHeap; duke@435: friend class AdjoiningGenerations; duke@435: duke@435: protected: duke@435: MemRegion _reserved; // Used for simple containment tests duke@435: PSVirtualSpace* _virtual_space; // Controls mapping and unmapping of virtual mem duke@435: ObjectStartArray _start_array; // Keeps track of where objects start in a 512b block duke@435: MutableSpace* _object_space; // Where all the objects live duke@435: PSMarkSweepDecorator* _object_mark_sweep; // The mark sweep view of _object_space duke@435: const char* const _name; // Name of this generation. duke@435: duke@435: // Performance Counters duke@435: PSGenerationCounters* _gen_counters; duke@435: SpaceCounters* _space_counters; duke@435: duke@435: // Sizing information, in bytes, set in constructor duke@435: const size_t _init_gen_size; duke@435: const size_t _min_gen_size; duke@435: const size_t _max_gen_size; duke@435: duke@435: // Used when initializing the _name field. duke@435: static inline const char* select_name(); duke@435: tonyp@2971: HeapWord* allocate_noexpand(size_t word_size) { duke@435: // We assume the heap lock is held here. duke@435: assert_locked_or_safepoint(Heap_lock); duke@435: HeapWord* res = object_space()->allocate(word_size); duke@435: if (res != NULL) { duke@435: _start_array.allocate_block(res); duke@435: } duke@435: return res; duke@435: } duke@435: duke@435: // Support for MT garbage collection. CAS allocation is lower overhead than grabbing duke@435: // and releasing the heap lock, which is held during gc's anyway. This method is not duke@435: // safe for use at the same time as allocate_noexpand()! duke@435: HeapWord* cas_allocate_noexpand(size_t word_size) { jcoomes@1844: assert(SafepointSynchronize::is_at_safepoint(), "Must only be called at safepoint"); duke@435: HeapWord* res = object_space()->cas_allocate(word_size); duke@435: if (res != NULL) { duke@435: _start_array.allocate_block(res); duke@435: } duke@435: return res; duke@435: } duke@435: duke@435: // Support for MT garbage collection. See above comment. duke@435: HeapWord* cas_allocate(size_t word_size) { duke@435: HeapWord* res = cas_allocate_noexpand(word_size); duke@435: return (res == NULL) ? expand_and_cas_allocate(word_size) : res; duke@435: } duke@435: tonyp@2971: HeapWord* expand_and_allocate(size_t word_size); duke@435: HeapWord* expand_and_cas_allocate(size_t word_size); duke@435: void expand(size_t bytes); duke@435: bool expand_by(size_t bytes); duke@435: bool expand_to_reserved(); duke@435: duke@435: void shrink(size_t bytes); duke@435: duke@435: void post_resize(); duke@435: duke@435: public: duke@435: // Initialize the generation. duke@435: PSOldGen(ReservedSpace rs, size_t alignment, duke@435: size_t initial_size, size_t min_size, size_t max_size, duke@435: const char* perf_data_name, int level); duke@435: duke@435: PSOldGen(size_t initial_size, size_t min_size, size_t max_size, duke@435: const char* perf_data_name, int level); duke@435: coleenp@4037: virtual void initialize(ReservedSpace rs, size_t alignment, duke@435: const char* perf_data_name, int level); duke@435: void initialize_virtual_space(ReservedSpace rs, size_t alignment); jmasa@5311: virtual void initialize_work(const char* perf_data_name, int level); coleenp@4037: virtual void initialize_performance_counters(const char* perf_data_name, int level); duke@435: duke@435: MemRegion reserved() const { return _reserved; } duke@435: virtual size_t max_gen_size() { return _max_gen_size; } duke@435: size_t min_gen_size() { return _min_gen_size; } duke@435: duke@435: // Returns limit on the maximum size of the generation. This duke@435: // is the same as _max_gen_size for PSOldGen but need not be duke@435: // for a derived class. duke@435: virtual size_t gen_size_limit(); duke@435: duke@435: bool is_in(const void* p) const { duke@435: return _virtual_space->contains((void *)p); duke@435: } duke@435: duke@435: bool is_in_reserved(const void* p) const { duke@435: return reserved().contains(p); duke@435: } duke@435: duke@435: MutableSpace* object_space() const { return _object_space; } duke@435: PSMarkSweepDecorator* object_mark_sweep() const { return _object_mark_sweep; } duke@435: ObjectStartArray* start_array() { return &_start_array; } duke@435: PSVirtualSpace* virtual_space() const { return _virtual_space;} duke@435: duke@435: // Has the generation been successfully allocated? duke@435: bool is_allocated(); duke@435: duke@435: // MarkSweep methods duke@435: virtual void precompact(); duke@435: void adjust_pointers(); duke@435: void compact(); duke@435: duke@435: // Size info duke@435: size_t capacity_in_bytes() const { return object_space()->capacity_in_bytes(); } duke@435: size_t used_in_bytes() const { return object_space()->used_in_bytes(); } duke@435: size_t free_in_bytes() const { return object_space()->free_in_bytes(); } duke@435: duke@435: size_t capacity_in_words() const { return object_space()->capacity_in_words(); } duke@435: size_t used_in_words() const { return object_space()->used_in_words(); } duke@435: size_t free_in_words() const { return object_space()->free_in_words(); } duke@435: duke@435: // Includes uncommitted memory duke@435: size_t contiguous_available() const; duke@435: duke@435: bool is_maximal_no_gc() const { duke@435: return virtual_space()->uncommitted_size() == 0; duke@435: } duke@435: duke@435: // Calculating new sizes duke@435: void resize(size_t desired_free_space); duke@435: duke@435: // Allocation. We report all successful allocations to the size policy duke@435: // Note that the perm gen does not use this method, and should not! tonyp@2971: HeapWord* allocate(size_t word_size); duke@435: duke@435: // Iteration. coleenp@4037: void oop_iterate_no_header(OopClosure* cl) { object_space()->oop_iterate_no_header(cl); } duke@435: void object_iterate(ObjectClosure* cl) { object_space()->object_iterate(cl); } duke@435: duke@435: // Debugging - do not use for time critical operations duke@435: virtual void print() const; duke@435: virtual void print_on(outputStream* st) const; duke@435: void print_used_change(size_t prev_used) const; duke@435: brutisso@3711: void verify(); duke@435: void verify_object_start_array(); duke@435: duke@435: // These should not used duke@435: virtual void reset_after_change(); duke@435: duke@435: // These should not used duke@435: virtual size_t available_for_expansion(); duke@435: virtual size_t available_for_contraction(); duke@435: duke@435: void space_invariants() PRODUCT_RETURN; duke@435: duke@435: // Performace Counter support duke@435: void update_counters(); duke@435: duke@435: // Printing support duke@435: virtual const char* name() const { return _name; } jmasa@698: jmasa@698: // Debugging support jmasa@698: // Save the tops of all spaces for later use during mangling. jmasa@698: void record_spaces_top() PRODUCT_RETURN; duke@435: }; stefank@2314: stefank@2314: #endif // SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSOLDGEN_HPP