Path: blob/master/runtime/gc_vlhgc/CompressedCardTable.hpp
5986 views
1/*******************************************************************************2* Copyright (c) 1991, 2021 IBM Corp. and others3*4* This program and the accompanying materials are made available under5* the terms of the Eclipse Public License 2.0 which accompanies this6* distribution and is available at https://www.eclipse.org/legal/epl-2.0/7* or the Apache License, Version 2.0 which accompanies this distribution and8* is available at https://www.apache.org/licenses/LICENSE-2.0.9*10* This Source Code may also be made available under the following11* Secondary Licenses when the conditions for such availability set12* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU13* General Public License, version 2 with the GNU Classpath14* Exception [1] and GNU General Public License, version 2 with the15* OpenJDK Assembly Exception [2].16*17* [1] https://www.gnu.org/software/classpath/license.html18* [2] http://openjdk.java.net/legal/assembly-exception.html19*20* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception21*******************************************************************************/2223/**24* @file25* @ingroup gc_vlhgc26*/2728#if !defined(COMPRESSEDCARDTABLE_HPP_)29#define COMPRESSEDCARDTABLE_HPP_303132#include "j9.h"33#include "j9cfg.h"3435#include "AtomicOperations.hpp"36#include "Base.hpp"37#include "CardTable.hpp"3839class MM_CardCleaner;40class MM_EnvironmentBase;41class MM_Heap;42class MM_HeapRegionDescriptor;4344#define BITS_PER_BYTE 845#define COMPRESSED_CARDS_PER_WORD (sizeof(UDATA) * BITS_PER_BYTE)4647class MM_CompressedCardTable : public MM_BaseNonVirtual48{49public:50protected:51private:52UDATA *_compressedCardTable; /**< start address of compressed card table */53UDATA _heapBase; /**< Store heap base locally. Use UDATA type because need it for arithmetic only */54volatile UDATA _totalRegions; /**< total number of regions discovered at table rebuild time */55volatile UDATA _regionsProcessed; /**< number of regions completed while table is being rebuilt */5657public:58/**59* Create new instance of class60* @param env current thread environment61* @param heap current heap62*/63static MM_CompressedCardTable *newInstance(MM_EnvironmentBase *env, MM_Heap *heap);6465/**66* Set all Compressed Cards correspondent with given heap range dirty for partial collect67* @param startHeapAddress start heap address68* @param endHeapAddress end heap address69*/70void setCompressedCardsDirtyForPartialCollect(void *startHeapAddress, void *endHeapAddress);7172/**73* Rebuild Compressed Cards for given heap range74* Card is going to be marked dirty if original card is dirty for partial collect75* @param env current thread environment76* @param startHeapAddress start heap address77* @param endHeapAddress end heap address78*/79void rebuildCompressedCardTableForPartialCollect(MM_EnvironmentBase *env, void *startHeapAddress, void *endHeapAddress);8081/**82* Check is Compressed Card correspondent with heap address dirty for partial collect83* @param env current thread environment84* @param heapAddress heap address85* @return true if fast card is set dirty86*/87bool isCompressedCardDirtyForPartialCollect(MM_EnvironmentBase *env, void *heapAddr);8889/**90* Cleaning cards for range91* Iterate Compressed Cards and clean marked dirty92* It is important that set of card states treated 'dirty' in given Card Cleaner must be the same or narrower then93* was used for in Compressed Card Table rebuild. If it is not correct some dirty cards might be missed94* @param env current thread environment95* @param cardCleaner given Card Cleaner96* @param region region card cleaning should be done97*/98void cleanCardsInRegion(MM_EnvironmentBase *env, MM_CardCleaner *cardCleaner, MM_HeapRegionDescriptor *region);99100/**101* Check is Card Table Summary rebuild is completed102* @return true if rebuild is completed103*/104bool isReady();105106/**107* Clear processed regions counter108*/109MMINLINE void clearRegionsProcessedCounter()110{111_regionsProcessed = 0;112}113114/**115* Atomically increment processed regions counter116* @param total total number of discovered regions117* @param processed number of processed regions118*/119MMINLINE void incrementProcessedRegionsCounter(UDATA total, UDATA processed)120{121_totalRegions = total;122123if (processed > 0) {124MM_AtomicOperations::storeSync();125MM_AtomicOperations::add(&_regionsProcessed, processed);126}127}128129/**130* General class kill131* @param env current thread environment132*/133void kill(MM_EnvironmentBase *env);134135protected:136/**137* General class initialization138* @param env current thread environment139* @param heap heap140*/141bool initialize(MM_EnvironmentBase *env, MM_Heap *heap);142143/**144* General class tear down145* @param env current thread environment146*/147void tearDown(MM_EnvironmentBase *env);148149/**150* Create a compressedCardTable object.151*/152MM_CompressedCardTable()153: MM_BaseNonVirtual()154, _compressedCardTable(NULL)155, _heapBase(0)156, _totalRegions(1)157, _regionsProcessed(0)158{159_typeId = __FUNCTION__;160}161162private:163/**164* Check should card be treated as dirty for partial collect165* @param state current card state166*/167bool isDirtyCardForPartialCollect(Card state);168169/**170* Cleaning cards for range171* Iterate Compressed Cards and clean marked dirty172* It is important that set of card states treated 'dirty' in given Card Cleaner must be the same or narrower then173* was used for in Compressed Card Table rebuild. If it is not correct some dirty cards might be missed174* @param env current thread environment175* @param cardCleaner given Card Cleaner176* @param startHeapAddress start heap address177* @param endHeapAddress end heap address178*/179void cleanCardsInRange(MM_EnvironmentBase *env, MM_CardCleaner *cardCleaner, void *startHeapAddress, void *endHeapAddress);180};181182#endif /* COMPRESSEDCARDTABLE_HPP_ */183184185