Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/promotionInfo.hpp
38920 views
/*1* Copyright (c) 2010, 2012, 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_VM_GC_IMPLEMENTATION_CONCURRENTMARKSWEEP_PROMOTIONINFO_HPP25#define SHARE_VM_GC_IMPLEMENTATION_CONCURRENTMARKSWEEP_PROMOTIONINFO_HPP2627#include "gc_implementation/concurrentMarkSweep/freeChunk.hpp"28#include "memory/allocation.hpp"2930// Forward declarations31class CompactibleFreeListSpace;3233class PromotedObject VALUE_OBJ_CLASS_SPEC {34private:35enum {36promoted_mask = right_n_bits(2), // i.e. 0x337displaced_mark = nth_bit(2), // i.e. 0x438next_mask = ~(right_n_bits(3)) // i.e. ~(0x7)39};4041// Below, we want _narrow_next in the "higher" 32 bit slot,42// whose position will depend on endian-ness of the platform.43// This is so that there is no interference with the44// cms_free_bit occupying bit position 7 (lsb == 0)45// when we are using compressed oops; see FreeChunk::is_free().46// We cannot move the cms_free_bit down because currently47// biased locking code assumes that age bits are contiguous48// with the lock bits. Even if that assumption were relaxed,49// the least position we could move this bit to would be50// to bit position 3, which would require 16 byte alignment.51typedef struct {52#ifdef VM_LITTLE_ENDIAN53LP64_ONLY(narrowOop _pad;)54narrowOop _narrow_next;55#else56narrowOop _narrow_next;57LP64_ONLY(narrowOop _pad;)58#endif59} Data;6061union {62intptr_t _next;63Data _data;64};65public:66inline PromotedObject* next() const {67assert(!((FreeChunk*)this)->is_free(), "Error");68PromotedObject* res;69if (UseCompressedOops) {70// The next pointer is a compressed oop stored in the top 32 bits71res = (PromotedObject*)oopDesc::decode_heap_oop(_data._narrow_next);72} else {73res = (PromotedObject*)(_next & next_mask);74}75assert(oop(res)->is_oop_or_null(true /* ignore mark word */), "Not an oop?");76return res;77}78inline void setNext(PromotedObject* x) {79assert(((intptr_t)x & ~next_mask) == 0, "Conflict in bit usage, "80"or insufficient alignment of objects");81if (UseCompressedOops) {82assert(_data._narrow_next == 0, "Overwrite?");83_data._narrow_next = oopDesc::encode_heap_oop(oop(x));84} else {85_next |= (intptr_t)x;86}87assert(!((FreeChunk*)this)->is_free(), "Error");88}89inline void setPromotedMark() {90_next |= promoted_mask;91assert(!((FreeChunk*)this)->is_free(), "Error");92}93inline bool hasPromotedMark() const {94assert(!((FreeChunk*)this)->is_free(), "Error");95return (_next & promoted_mask) == promoted_mask;96}97inline void setDisplacedMark() {98_next |= displaced_mark;99assert(!((FreeChunk*)this)->is_free(), "Error");100}101inline bool hasDisplacedMark() const {102assert(!((FreeChunk*)this)->is_free(), "Error");103return (_next & displaced_mark) != 0;104}105inline void clear_next() {106_next = 0;107assert(!((FreeChunk*)this)->is_free(), "Error");108}109debug_only(void *next_addr() { return (void *) &_next; })110};111112class SpoolBlock: public FreeChunk {113friend class PromotionInfo;114protected:115SpoolBlock* nextSpoolBlock;116size_t bufferSize; // number of usable words in this block117markOop* displacedHdr; // the displaced headers start here118119// Note about bufferSize: it denotes the number of entries available plus 1;120// legal indices range from 1 through BufferSize - 1. See the verification121// code verify() that counts the number of displaced headers spooled.122size_t computeBufferSize() {123return (size() * sizeof(HeapWord) - sizeof(*this)) / sizeof(markOop);124}125126public:127void init() {128bufferSize = computeBufferSize();129displacedHdr = (markOop*)&displacedHdr;130nextSpoolBlock = NULL;131}132133void print_on(outputStream* st) const;134void print() const { print_on(gclog_or_tty); }135};136137class PromotionInfo VALUE_OBJ_CLASS_SPEC {138bool _tracking; // set if tracking139CompactibleFreeListSpace* _space; // the space to which this belongs140PromotedObject* _promoHead; // head of list of promoted objects141PromotedObject* _promoTail; // tail of list of promoted objects142SpoolBlock* _spoolHead; // first spooling block143SpoolBlock* _spoolTail; // last non-full spooling block or null144SpoolBlock* _splice_point; // when _spoolTail is null, holds list tail145SpoolBlock* _spareSpool; // free spool buffer146size_t _firstIndex; // first active index in147// first spooling block (_spoolHead)148size_t _nextIndex; // last active index + 1 in last149// spooling block (_spoolTail)150private:151// ensure that spooling space exists; return true if there is spooling space152bool ensure_spooling_space_work();153154public:155PromotionInfo() :156_tracking(0), _space(NULL),157_promoHead(NULL), _promoTail(NULL),158_spoolHead(NULL), _spoolTail(NULL),159_spareSpool(NULL), _firstIndex(1),160_nextIndex(1) {}161162bool noPromotions() const {163assert(_promoHead != NULL || _promoTail == NULL, "list inconsistency");164return _promoHead == NULL;165}166void startTrackingPromotions();167void stopTrackingPromotions(uint worker_id = 0);168bool tracking() const { return _tracking; }169void track(PromotedObject* trackOop); // keep track of a promoted oop170// The following variant must be used when trackOop is not fully171// initialized and has a NULL klass:172void track(PromotedObject* trackOop, Klass* klassOfOop); // keep track of a promoted oop173void setSpace(CompactibleFreeListSpace* sp) { _space = sp; }174CompactibleFreeListSpace* space() const { return _space; }175markOop nextDisplacedHeader(); // get next header & forward spool pointer176void saveDisplacedHeader(markOop hdr);177// save header and forward spool178179inline size_t refillSize() const;180181SpoolBlock* getSpoolBlock(); // return a free spooling block182inline bool has_spooling_space() {183return _spoolTail != NULL && _spoolTail->bufferSize > _nextIndex;184}185// ensure that spooling space exists186bool ensure_spooling_space() {187return has_spooling_space() || ensure_spooling_space_work();188}189#define PROMOTED_OOPS_ITERATE_DECL(OopClosureType, nv_suffix) \190void promoted_oops_iterate##nv_suffix(OopClosureType* cl);191ALL_SINCE_SAVE_MARKS_CLOSURES(PROMOTED_OOPS_ITERATE_DECL)192#undef PROMOTED_OOPS_ITERATE_DECL193void promoted_oops_iterate(OopsInGenClosure* cl) {194promoted_oops_iterate_v(cl);195}196void verify() const;197void reset() {198_promoHead = NULL;199_promoTail = NULL;200_spoolHead = NULL;201_spoolTail = NULL;202_spareSpool = NULL;203_firstIndex = 0;204_nextIndex = 0;205206}207208void print_on(outputStream* st) const;209void print_statistics(uint worker_id) const;210};211212213#endif // SHARE_VM_GC_IMPLEMENTATION_CONCURRENTMARKSWEEP_PROMOTIONINFO_HPP214215216