0N/A/*
3203N/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_PARALLELSCAVENGEHEAP_HPP
1879N/A#define SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PARALLELSCAVENGEHEAP_HPP
1879N/A
1879N/A#include "gc_implementation/parallelScavenge/objectStartArray.hpp"
1879N/A#include "gc_implementation/parallelScavenge/psGCAdaptivePolicyCounters.hpp"
1879N/A#include "gc_implementation/parallelScavenge/psOldGen.hpp"
1879N/A#include "gc_implementation/parallelScavenge/psPermGen.hpp"
1879N/A#include "gc_implementation/parallelScavenge/psYoungGen.hpp"
1879N/A#include "gc_implementation/shared/gcPolicyCounters.hpp"
1879N/A#include "gc_interface/collectedHeap.inline.hpp"
1879N/A#include "utilities/ostream.hpp"
1879N/A
0N/Aclass AdjoiningGenerations;
4141N/Aclass CollectorPolicy;
4141N/Aclass GCHeapSummary;
0N/Aclass GCTaskManager;
1387N/Aclass GenerationSizer;
1387N/Aclass CollectorPolicy;
4141N/Aclass PSAdaptiveSizePolicy;
4141N/Aclass PSHeapSummary;
4141N/Aclass VirtualSpaceSummary;
0N/A
0N/Aclass ParallelScavengeHeap : public CollectedHeap {
0N/A friend class VMStructs;
0N/A private:
0N/A static PSYoungGen* _young_gen;
0N/A static PSOldGen* _old_gen;
0N/A static PSPermGen* _perm_gen;
0N/A
0N/A // Sizing policy for entire heap
0N/A static PSAdaptiveSizePolicy* _size_policy;
0N/A static PSGCAdaptivePolicyCounters* _gc_policy_counters;
0N/A
0N/A static ParallelScavengeHeap* _psh;
0N/A
0N/A size_t _perm_gen_alignment;
0N/A size_t _young_gen_alignment;
0N/A size_t _old_gen_alignment;
0N/A
1387N/A GenerationSizer* _collector_policy;
1387N/A
0N/A inline size_t set_alignment(size_t& var, size_t val);
0N/A
0N/A // Collection of generations that are adjacent in the
0N/A // space reserved for the heap.
0N/A AdjoiningGenerations* _gens;
3203N/A unsigned int _death_march_count;
0N/A
0N/A static GCTaskManager* _gc_task_manager; // The task manager.
0N/A
4141N/A void trace_heap(GCWhen::Type when, GCTracer* tracer);
4141N/A
0N/A protected:
0N/A static inline size_t total_invocations();
0N/A HeapWord* allocate_new_tlab(size_t size);
0N/A
3203N/A inline bool should_alloc_in_eden(size_t size) const;
3203N/A inline void death_march_check(HeapWord* const result, size_t size);
3203N/A HeapWord* mem_allocate_old_gen(size_t size);
3203N/A
0N/A public:
0N/A ParallelScavengeHeap() : CollectedHeap() {
3203N/A _death_march_count = 0;
13N/A set_alignment(_perm_gen_alignment, intra_heap_alignment());
13N/A set_alignment(_young_gen_alignment, intra_heap_alignment());
13N/A set_alignment(_old_gen_alignment, intra_heap_alignment());
0N/A }
0N/A
0N/A // For use by VM operations
0N/A enum CollectionType {
0N/A Scavenge,
0N/A MarkSweep
0N/A };
0N/A
0N/A ParallelScavengeHeap::Name kind() const {
0N/A return CollectedHeap::ParallelScavengeHeap;
0N/A }
0N/A
1387N/ACollectorPolicy* collector_policy() const { return (CollectorPolicy*) _collector_policy; }
1387N/A // GenerationSizer* collector_policy() const { return _collector_policy; }
1387N/A
0N/A static PSYoungGen* young_gen() { return _young_gen; }
0N/A static PSOldGen* old_gen() { return _old_gen; }
0N/A static PSPermGen* perm_gen() { return _perm_gen; }
0N/A
0N/A virtual PSAdaptiveSizePolicy* size_policy() { return _size_policy; }
0N/A
0N/A static PSGCAdaptivePolicyCounters* gc_policy_counters() { return _gc_policy_counters; }
0N/A
0N/A static ParallelScavengeHeap* heap();
0N/A
0N/A static GCTaskManager* const gc_task_manager() { return _gc_task_manager; }
0N/A
0N/A AdjoiningGenerations* gens() { return _gens; }
0N/A
0N/A // Returns JNI_OK on success
0N/A virtual jint initialize();
0N/A
0N/A void post_initialize();
0N/A void update_counters();
0N/A // The alignment used for the various generations.
0N/A size_t perm_gen_alignment() const { return _perm_gen_alignment; }
0N/A size_t young_gen_alignment() const { return _young_gen_alignment; }
0N/A size_t old_gen_alignment() const { return _old_gen_alignment; }
0N/A
13N/A // The alignment used for eden and survivors within the young gen
13N/A // and for boundary between young gen and old gen.
4535N/A size_t intra_heap_alignment() const { return 64 * K * HeapWordSize; }
0N/A
0N/A size_t capacity() const;
0N/A size_t used() const;
0N/A
0N/A // Return "true" if all generations (but perm) have reached the
0N/A // maximal committed limit that they can reach, without a garbage
0N/A // collection.
0N/A virtual bool is_maximal_no_gc() const;
0N/A
2474N/A // Return true if the reference points to an object that
2474N/A // can be moved in a partial collection. For currently implemented
2474N/A // generational collectors that means during a collection of
2474N/A // the young gen.
2474N/A virtual bool is_scavengable(const void* addr);
2474N/A
0N/A // Does this heap support heap inspection? (+PrintClassHistogram)
0N/A bool supports_heap_inspection() const { return true; }
0N/A
0N/A size_t permanent_capacity() const;
0N/A size_t permanent_used() const;
0N/A
0N/A size_t max_capacity() const;
0N/A
0N/A // Whether p is in the allocated part of the heap
0N/A bool is_in(const void* p) const;
0N/A
0N/A bool is_in_reserved(const void* p) const;
0N/A bool is_in_permanent(const void *p) const { // reserved part
0N/A return perm_gen()->reserved().contains(p);
0N/A }
0N/A
2474N/A#ifdef ASSERT
2474N/A virtual bool is_in_partial_collection(const void *p);
2474N/A#endif
2474N/A
0N/A bool is_permanent(const void *p) const { // committed part
0N/A return perm_gen()->is_in(p);
0N/A }
0N/A
1027N/A inline bool is_in_young(oop p); // reserved part
1027N/A inline bool is_in_old_or_perm(oop p); // reserved part
0N/A
0N/A // Memory allocation. "gc_time_limit_was_exceeded" will
0N/A // be set to true if the adaptive size policy determine that
0N/A // an excessive amount of time is being spent doing collections
0N/A // and caused a NULL to be returned. If a NULL is not returned,
0N/A // "gc_time_limit_was_exceeded" has an undefined meaning.
2599N/A HeapWord* mem_allocate(size_t size,
2599N/A bool* gc_overhead_limit_was_exceeded);
0N/A
2599N/A // Allocation attempt(s) during a safepoint. It should never be called
2599N/A // to allocate a new TLAB as this allocation might be satisfied out
2599N/A // of the old generation.
2599N/A HeapWord* failed_mem_allocate(size_t size);
0N/A
0N/A HeapWord* permanent_mem_allocate(size_t size);
0N/A HeapWord* failed_permanent_mem_allocate(size_t size);
0N/A
0N/A // Support for System.gc()
0N/A void collect(GCCause::Cause cause);
0N/A
0N/A // This interface assumes that it's being called by the
0N/A // vm thread. It collects the heap assuming that the
0N/A // heap lock is already held and that we are executing in
0N/A // the context of the vm thread.
0N/A void collect_as_vm_thread(GCCause::Cause cause);
0N/A
0N/A // These also should be called by the vm thread at a safepoint (e.g., from a
0N/A // VM operation).
0N/A //
0N/A // The first collects the young generation only, unless the scavenge fails; it
0N/A // will then attempt a full gc. The second collects the entire heap; if
0N/A // maximum_compaction is true, it will compact everything and clear all soft
0N/A // references.
0N/A inline void invoke_scavenge();
0N/A inline void invoke_full_gc(bool maximum_compaction);
0N/A
0N/A bool supports_inline_contig_alloc() const { return !UseNUMA; }
141N/A
141N/A HeapWord** top_addr() const { return !UseNUMA ? young_gen()->top_addr() : (HeapWord**)-1; }
141N/A HeapWord** end_addr() const { return !UseNUMA ? young_gen()->end_addr() : (HeapWord**)-1; }
0N/A
0N/A void ensure_parsability(bool retire_tlabs);
0N/A void accumulate_statistics_all_tlabs();
0N/A void resize_all_tlabs();
0N/A
0N/A size_t unsafe_max_alloc();
0N/A
0N/A bool supports_tlab_allocation() const { return true; }
0N/A
0N/A size_t tlab_capacity(Thread* thr) const;
0N/A size_t unsafe_max_tlab_alloc(Thread* thr) const;
0N/A
342N/A // Can a compiler initialize a new object without store barriers?
342N/A // This permission only extends from the creation of a new object
342N/A // via a TLAB up to the first subsequent safepoint.
342N/A virtual bool can_elide_tlab_store_barriers() const {
342N/A return true;
342N/A }
342N/A
1166N/A virtual bool card_mark_must_follow_store() const {
1166N/A return false;
1166N/A }
1166N/A
1027N/A // Return true if we don't we need a store barrier for
1027N/A // initializing stores to an object at this address.
1027N/A virtual bool can_elide_initializing_store_barrier(oop new_obj);
1027N/A
342N/A // Can a compiler elide a store barrier when it writes
342N/A // a permanent oop into the heap? Applies when the compiler
342N/A // is storing x to the heap, where x->is_perm() is true.
342N/A virtual bool can_elide_permanent_oop_store_barriers() const {
342N/A return true;
342N/A }
342N/A
0N/A void oop_iterate(OopClosure* cl);
0N/A void object_iterate(ObjectClosure* cl);
517N/A void safe_object_iterate(ObjectClosure* cl) { object_iterate(cl); }
0N/A void permanent_oop_iterate(OopClosure* cl);
0N/A void permanent_object_iterate(ObjectClosure* cl);
0N/A
0N/A HeapWord* block_start(const void* addr) const;
0N/A size_t block_size(const HeapWord* addr) const;
0N/A bool block_is_obj(const HeapWord* addr) const;
0N/A
0N/A jlong millis_since_last_gc();
0N/A
0N/A void prepare_for_verify();
4141N/A PSHeapSummary create_ps_heap_summary();
4141N/A VirtualSpaceSummary create_perm_gen_space_summary();
2911N/A virtual void print_on(outputStream* st) const;
0N/A virtual void print_gc_threads_on(outputStream* st) const;
0N/A virtual void gc_threads_do(ThreadClosure* tc) const;
0N/A virtual void print_tracing_info() const;
0N/A
3679N/A void verify(bool silent, VerifyOption option /* ignored */);
0N/A
0N/A void print_heap_change(size_t prev_used);
0N/A
0N/A // Resize the young generation. The reserved space for the
0N/A // generation may be expanded in preparation for the resize.
0N/A void resize_young_gen(size_t eden_size, size_t survivor_size);
0N/A
0N/A // Resize the old generation. The reserved space for the
0N/A // generation may be expanded in preparation for the resize.
0N/A void resize_old_gen(size_t desired_free_space);
263N/A
263N/A // Save the tops of the spaces in all generations
263N/A void record_gen_tops_before_GC() PRODUCT_RETURN;
263N/A
263N/A // Mangle the unused parts of all spaces in the heap
263N/A void gen_mangle_unused_area() PRODUCT_RETURN;
989N/A
989N/A // Call these in sequential code around the processing of strong roots.
989N/A class ParStrongRootsScope : public MarkingCodeBlobClosure::MarkScope {
989N/A public:
989N/A ParStrongRootsScope();
989N/A ~ParStrongRootsScope();
989N/A };
0N/A};
0N/A
0N/Ainline size_t ParallelScavengeHeap::set_alignment(size_t& var, size_t val)
0N/A{
0N/A assert(is_power_of_2((intptr_t)val), "must be a power of 2");
13N/A var = round_to(val, intra_heap_alignment());
0N/A return var;
0N/A}
1879N/A
1879N/A#endif // SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PARALLELSCAVENGEHEAP_HPP