Path: blob/master/src/hotspot/share/gc/parallel/mutableSpace.hpp
41152 views
/*1* Copyright (c) 2001, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_GC_PARALLEL_MUTABLESPACE_HPP25#define SHARE_GC_PARALLEL_MUTABLESPACE_HPP2627#include "memory/allocation.hpp"28#include "memory/iterator.hpp"29#include "memory/memRegion.hpp"30#include "utilities/copy.hpp"31#include "utilities/globalDefinitions.hpp"32#include "utilities/macros.hpp"3334class WorkGang;3536// A MutableSpace supports the concept of allocation. This includes the37// concepts that a space may be only partially full, and the query methods38// that go with such an assumption.39//40// MutableSpace is also responsible for minimizing the41// page allocation time by having the memory pretouched (with42// AlwaysPretouch) and for optimizing page placement on NUMA systems43// by make the underlying region interleaved (with UseNUMA).44//45// Invariant: bottom() <= top() <= end()46// top() and end() are exclusive.4748class MutableSpaceMangler;4950class MutableSpace: public CHeapObj<mtGC> {51friend class VMStructs;5253// Helper for mangling unused space in debug builds54MutableSpaceMangler* _mangler;55// The last region which page had been setup to be interleaved.56MemRegion _last_setup_region;57size_t _alignment;58HeapWord* _bottom;59HeapWord* volatile _top;60HeapWord* _end;6162MutableSpaceMangler* mangler() { return _mangler; }6364void numa_setup_pages(MemRegion mr, bool clear_space);6566void set_last_setup_region(MemRegion mr) { _last_setup_region = mr; }67MemRegion last_setup_region() const { return _last_setup_region; }6869public:70virtual ~MutableSpace();71MutableSpace(size_t page_size);7273// Accessors74HeapWord* bottom() const { return _bottom; }75HeapWord* top() const { return _top; }76HeapWord* end() const { return _end; }7778void set_bottom(HeapWord* value) { _bottom = value; }79virtual void set_top(HeapWord* value) { _top = value; }80void set_end(HeapWord* value) { _end = value; }8182HeapWord* volatile* top_addr() { return &_top; }83HeapWord** end_addr() { return &_end; }8485size_t alignment() { return _alignment; }8687MemRegion region() const { return MemRegion(bottom(), end()); }8889size_t capacity_in_bytes() const { return capacity_in_words() * HeapWordSize; }90size_t capacity_in_words() const { return pointer_delta(end(), bottom()); }91virtual size_t capacity_in_words(Thread*) const { return capacity_in_words(); }9293// Returns a subregion containing all objects in this space.94MemRegion used_region() { return MemRegion(bottom(), top()); }9596static const bool SetupPages = true;97static const bool DontSetupPages = false;9899// Initialization100virtual void initialize(MemRegion mr,101bool clear_space,102bool mangle_space,103bool setup_pages = SetupPages,104WorkGang* pretouch_gang = NULL);105106virtual void clear(bool mangle_space);107virtual void update() { }108virtual void accumulate_statistics() { }109110// Methods used in mangling. See descriptions under SpaceMangler.111virtual void mangle_unused_area() PRODUCT_RETURN;112virtual void mangle_unused_area_complete() PRODUCT_RETURN;113virtual void check_mangled_unused_area(HeapWord* limit) PRODUCT_RETURN;114virtual void check_mangled_unused_area_complete() PRODUCT_RETURN;115virtual void set_top_for_allocations(HeapWord* v) PRODUCT_RETURN;116117// Used to save the space's current top for later use during mangling.118virtual void set_top_for_allocations() PRODUCT_RETURN;119120virtual void ensure_parsability() { }121122virtual void mangle_region(MemRegion mr) PRODUCT_RETURN;123124// Boolean queries.125bool is_empty() const { return used_in_words() == 0; }126bool not_empty() const { return used_in_words() > 0; }127bool contains(const void* p) const { return _bottom <= p && p < _end; }128129// Size computations. Sizes are in bytes.130size_t used_in_bytes() const { return used_in_words() * HeapWordSize; }131size_t free_in_bytes() const { return free_in_words() * HeapWordSize; }132133// Size computations. Sizes are in heapwords.134virtual size_t used_in_words() const { return pointer_delta(top(), bottom()); }135virtual size_t free_in_words() const { return pointer_delta(end(), top()); }136virtual size_t tlab_capacity(Thread* thr) const { return capacity_in_bytes(); }137virtual size_t tlab_used(Thread* thr) const { return used_in_bytes(); }138virtual size_t unsafe_max_tlab_alloc(Thread* thr) const { return free_in_bytes(); }139140// Allocation (return NULL if full)141virtual HeapWord* cas_allocate(size_t word_size);142// Optional deallocation. Used in NUMA-allocator.143bool cas_deallocate(HeapWord *obj, size_t size);144// Return true if this space needs to be expanded in order to satisfy an145// allocation request of the indicated size. Concurrent allocations and146// resizes may change the result of a later call. Used by oldgen allocator.147// precondition: holding ExpandHeap_lock148bool needs_expand(size_t word_size) const;149150// Iteration.151void oop_iterate(OopIterateClosure* cl);152void object_iterate(ObjectClosure* cl);153154// Debugging155virtual void print() const;156virtual void print_on(outputStream* st) const;157virtual void print_short() const;158virtual void print_short_on(outputStream* st) const;159virtual void verify();160};161162#endif // SHARE_GC_PARALLEL_MUTABLESPACE_HPP163164165