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