Path: blob/master/runtime/gc_vlhgc/ClassLoaderRememberedSet.hpp
5986 views
/*******************************************************************************1* Copyright (c) 1991, 2020 IBM Corp. and others2*3* This program and the accompanying materials are made available under4* the terms of the Eclipse Public License 2.0 which accompanies this5* distribution and is available at https://www.eclipse.org/legal/epl-2.0/6* or the Apache License, Version 2.0 which accompanies this distribution and7* is available at https://www.apache.org/licenses/LICENSE-2.0.8*9* This Source Code may also be made available under the following10* Secondary Licenses when the conditions for such availability set11* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU12* General Public License, version 2 with the GNU Classpath13* Exception [1] and GNU General Public License, version 2 with the14* OpenJDK Assembly Exception [2].15*16* [1] https://www.gnu.org/software/classpath/license.html17* [2] http://openjdk.java.net/legal/assembly-exception.html18*19* 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-exception20*******************************************************************************/2122/**23* @file24* @ingroup gc_vlhgc25*/2627#if !defined(CLASSLOADERREMEMBEREDSET_HPP)28#define CLASSLOADERREMEMBEREDSET_HPP2930#include "j9.h"31#include "j9cfg.h"32#include "modron.h"33#include "pool_api.h"34#include "ModronAssertions.h"3536#include "BaseVirtual.hpp"37#include "LightweightNonReentrantLock.hpp"38#include "GCExtensions.hpp"3940class MM_EnvironmentBase;41class MM_HeapRegionDescriptor;42class MM_HeapRegionManager;43struct J9Pool;4445class MM_ClassLoaderRememberedSet : public MM_BaseVirtual46{47private:48MM_GCExtensions * const _extensions; /**< cached pointer to the extensions structure */49MM_HeapRegionManager * const _regionManager; /** cached pointer to the region manager */50UDATA const _bitVectorSize; /**< The size of each bit vector in UDATAs */51J9Pool *_bitVectorPool; /**< A pool of bit vectors to associate with J9ClassLoaders */52MM_LightweightNonReentrantLock _lock; /**< A lock to protect _bitVectorPool */53UDATA * _bitsToClear; /**< A bit vector which is built up before a garbage collection */5455private:56MM_ClassLoaderRememberedSet(MM_EnvironmentBase* env);5758/**59* Allocation helper for J9Pool.60*/61static void * poolAllocateHelper(void* userData, U_32 size, const char* callSite, U_32 memoryCategory, U_32 type, U_32* doInit);6263/**64* Deallocation helper for J9Pool.65*/66static void poolFreeHelper(void* userData, void* address, U_32 type);6768/**69* Upgrade the specified class loader from a single remembered region to a full bit vector.70* If a bit vector can't be installed, set the loader to overflowed.71* @param env[in] the current thread72* @param gcRememberedSetAddress[in/out] an address of gcRememberedSet slot73*/74void installBitVector(MM_EnvironmentBase* env, volatile UDATA *gcRememberedSetAddress);7576/**77* Atomically set the specified bit in the specified bit vector.78* @param env[in] the current thread79* @param bitVector[in] the bitVector to modify80* @param bit the index of the bit to set81*/82void setBit(MM_EnvironmentBase* env, volatile UDATA* bitVector, UDATA bit);8384/**85* Determine if the specified gcRememberedSet field value represents an overflowed set.86* @param rememberedSet the value of a J9ClassLoader's gcRememberedSet field87* @return true if the remembered set is overflowed88*/89MMINLINE bool isOverflowedRemememberedSet(UDATA rememberedSet) { return UDATA_MAX == rememberedSet; }9091/**92* Determine if the specified gcRememberedSet field value represents a tagged region index.93* Note that overflowed class loaders will return true!94* @param rememberedSet the value of a J9ClassLoader's gcRememberedSet field95* @return true if the remembered set is a tagged region index (or overflowed), false otherwise96*/97MMINLINE bool isTaggedRegionIndex(UDATA rememberedSet) { return 1 == (1 & rememberedSet); }9899/**100* Convert the specified region index into a tagged value suitable to be stored in the gcRememberedSet field.101* @param regionIndex the index to store102* @return the tagged version of the index103*/104MMINLINE UDATA asTaggedRegionIndex(UDATA regionIndex) { return (regionIndex << 1) | 1; }105106/**107* Convert a tagged region index back to the actual value108* @param rememberedSet the value of a J9ClassLoader's gcRememberedSet field109* @return the region index it represents110*/111MMINLINE UDATA asUntaggedRegionIndex(UDATA rememberedSet) { return rememberedSet >> 1; }112113/**114* Determine if the specified bit is set in the specified bit vector.115* @param env[in] the current thread116* @param bitVector[in] the bit vector to test117* @param bit the index of the bit to test118* @return true if the bit is set, false otherwise119*/120bool isBitSet(MM_EnvironmentBase* env, volatile UDATA* bitVector, UDATA bit);121122/**123* Implementation helper for rememberInstance() based on region index.124*125* @param env[in] the current thread126* @param regionIndex[in] the region index to remember127* @param gcRememberedSetAddress[in/out] an address of gcRememberedSet slot128*/129void rememberRegionInternal(MM_EnvironmentBase* env, UDATA regionIndex, volatile UDATA *gcRememberedSetAddress);130131/**132* Implementation helper for isRemembered().133*134* @param env[in] the current thread135* @param gcRememberedSet[in] gcRememberedSet slot136*/137bool isRememberedInternal(MM_EnvironmentBase *env, UDATA gcRememberedSet);138139/**140* Implementation helper for isRemembered() based on region index.141*142* @param env[in] the current thread143* @param regionIndex[in] the region index to remember144* @param gcRememberedSet[in] gcRememberedSet slot145*/146bool isRegionRemembered(MM_EnvironmentBase *env, UDATA regionIndex, UDATA gcRememberedSet);147148/**149* Implementation helper for killRememberedSet().150*151* @param env[in] the current thread152* @param gcRememberedSet[in] gcRememberedSet slot153*/154void killRememberedSetInternal(MM_EnvironmentBase *env, UDATA gcRememberedSet);155156/**157* Implementation helper for clearRememberedSets().158*159* @param env[in] the current thread160* @param gcRememberedSetAddress[in/out] an address of gcRememberedSet slot161*/162void clearRememberedSetsInternal(MM_EnvironmentBase *env, volatile UDATA *gcRememberedSetAddress);163164protected:165public:166static MM_ClassLoaderRememberedSet *newInstance(MM_EnvironmentBase* env);167virtual void kill(MM_EnvironmentBase *env);168169/*170* Initialize ClassLoaderRememberedSet171*/172bool initialize(MM_EnvironmentBase* env);173174/*175* Teardown ClassLoaderRememberedSet176*/177virtual void tearDown(MM_EnvironmentBase* env);178179/**180* Update the remembered set data for the specified object's class loader to record the object.181*182* The object's region and class loader are identified, and the relationship between them is recorded in the class loader.183*184* @param env[in] the current thread185* @param object[in] the object to remember186*/187void rememberInstance(MM_EnvironmentBase* env, J9Object* object);188189/**190* Determine if there are any instances of classes defined by specified class loader.191* @param env[in] the current thread192* @param classLoader[in] the loader to examine193* @return true if there are instances (or the loader is overflowed), false otherwise194*/195bool isRemembered(MM_EnvironmentBase *env, J9ClassLoader *classLoader);196197/**198* Determine if there are instances of anonymous class defined.199* @param env[in] the current thread200* @param clazz[in] the anonymous class to examine201* @return true if there are instances, false otherwise202*/203bool isClassRemembered(MM_EnvironmentBase *env, J9Class *clazz);204205/**206* Determine if the specified object is remembered in its class loader.207* @note This is intended primarily for verification208* @param env[in] the current thread209* @param object[in] the object to test210* @return true if the object is properly remembered211*/212bool isInstanceRemembered(MM_EnvironmentBase *env, J9Object* object);213214/**215* Delete any resources associated with the remembered set for the specified class loader.216* @param env[in] the current thread217* @param classLoader[in] the loader to modify218*/219void killRememberedSet(MM_EnvironmentBase *env, J9ClassLoader *classLoader);220221/**222* Called before a partial GC to initialize the preserved regions bit vector.223* All bits are 1 (preserved) once this call completes.224* See also #prepareToClearRememberedSetForRegion() and #clearRememberedSets()225* @param env[in] the current thread226*/227void resetRegionsToClear(MM_EnvironmentBase *env);228229/**230* Ensure that the remembered bits for the specified region will be cleared when #clearRememberedSets() is called.231* This may safely be called from multiple threads.232* @param env[in] the current thread233* @param region[in] a region which is part of the collection set and should be cleared234*/235void prepareToClearRememberedSetForRegion(MM_EnvironmentBase *env, MM_HeapRegionDescriptor *region);236237/**238* Called before a partial GC to clear remembered sets in all class loaders for regions239* which have been marked using #prepareToClearRememberedSetForRegion()240* @param env[in] the current thread241*/242void clearRememberedSets(MM_EnvironmentBase *env);243244/**245* Called by the main thread before a GC cycle to perform any setup required before a collection.246* @param env[in] the current thread247*/248void setupBeforeGC(MM_EnvironmentBase *env);249};250251#endif /* CLASSLOADERREMEMBEREDSET_HPP */252253254