Path: blob/master/runtime/gc_glue_java/ReferenceObjectScanner.hpp
5990 views
/*******************************************************************************1* Copyright (c) 2016, 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_Structs25*/2627#if !defined(REFERENCEOBJECTSCANNER_HPP_)28#define REFERENCEOBJECTSCANNER_HPP_2930#include "MixedObjectScanner.hpp"3132/**33* This class is used to iterate over the slots of a Java reference object.34*/35class GC_ReferenceObjectScanner : public GC_MixedObjectScanner36{37/* Data Members */38private:39fomrobject_t * _referentSlotAddress;4041protected:4243public:4445/* Member Functions */46private:47/**48* The referent slot must be skipped unless the referent must be marked. So clear49* the corresponding bit in the scan map when the scan pointer is reset to contain50* the referent slot within its mapped range.51*/52MMINLINE uintptr_t skipReferentSlot(fomrobject_t *mapPtr, uintptr_t scanMap)53{54if (_referentSlotAddress > mapPtr) {55/* Skip over referent slot */56intptr_t referentSlotDistance = GC_SlotObject::subtractSlotAddresses(_referentSlotAddress, mapPtr, compressObjectReferences());57if (referentSlotDistance < _bitsPerScanMap) {58scanMap &= ~((uintptr_t)1 << referentSlotDistance);59}60}61return scanMap;62}6364protected:65/**66* Instantiation constructor.67*68* @param[in] env pointer to the environment for the current thread69* @param[in] objectPtr pointer to the object to be processed70* @param[in] referentSlotAddress pointer to referent slot, if this slot is to be skipped; otherwise, specify NULL71* @param[in] flags Scanning context flags72*/73MMINLINE GC_ReferenceObjectScanner(MM_EnvironmentBase *env, omrobjectptr_t objectPtr, fomrobject_t *referentSlotAddress, uintptr_t flags)74: GC_MixedObjectScanner(env, objectPtr, flags)75, _referentSlotAddress(referentSlotAddress)76{77_typeId = __FUNCTION__;78}7980/**81* Subclasses must call this method to set up the instance description bits and description pointer.82*/83MMINLINE void84initialize(MM_EnvironmentBase *env, J9Class *clazzPtr)85{86GC_MixedObjectScanner::initialize(env, clazzPtr);8788/* Skip over referent slot if required */89_scanMap = skipReferentSlot(_scanPtr, _scanMap);90}9192public:93/**94* In-place instantiation and initialization for reference object scanner.95*96* @param[in] env The scanning thread environment97* @param[in] objectPtr The object to scan98* @param[in] referentSlotAddress pointer to referent slot, if this slot is to be skipped; otherwise, specify NULL99* @param[in] allocSpace Pointer to space for in-place instantiation (at least sizeof(GC_ReferenceObjectScanner) bytes)100* @param[in] flags Scanning context flags101* @return Pointer to GC_ReferenceObjectScanner instance in allocSpace102*/103MMINLINE static GC_ReferenceObjectScanner *104newInstance(MM_EnvironmentBase *env, omrobjectptr_t objectPtr, fomrobject_t *referentSlotAddress, void *allocSpace, uintptr_t flags)105{106GC_ReferenceObjectScanner *objectScanner = (GC_ReferenceObjectScanner *)allocSpace;107new(objectScanner) GC_ReferenceObjectScanner(env, objectPtr, referentSlotAddress, flags);108objectScanner->initialize(env, J9GC_J9OBJECT_CLAZZ(objectPtr, env));109return objectScanner;110}111112/**113* Return base pointer and slot bit map for next block of contiguous slots to be scanned. The114* base pointer must be fomrobject_t-aligned. Bits in the bit map are scanned in order of115* increasing significance, and the least significant bit maps to the slot at the returned116* base pointer.117*118* @param[out] scanMap the bit map for the slots contiguous with the returned base pointer119* @param[out] hasNextSlotMap set this to true if this method should be called again, false if this map is known to be last120* @return a pointer to the first slot mapped by the least significant bit of the map, or NULL if no more slots121*/122virtual fomrobject_t *123getNextSlotMap(uintptr_t *slotMap, bool *hasNextSlotMap)124{125fomrobject_t *mapPtr = GC_MixedObjectScanner::getNextSlotMap(slotMap, hasNextSlotMap);126127/* Skip over referent slot */128*slotMap = skipReferentSlot(mapPtr, *slotMap);129130return mapPtr;131}132133#if defined(OMR_GC_LEAF_BITS)134/**135* Return base pointer and slot bit map for next block of contiguous slots to be scanned. The136* base pointer must be fomrobject_t-aligned. Bits in the bit map are scanned in order of137* increasing significance, and the least significant bit maps to the slot at the returned138* base pointer.139*140* @param[out] scanMap the bit map for the slots contiguous with the returned base pointer141* @param[out] leafMap the leaf bit map for the slots contiguous with the returned base pointer142* @param[out] hasNextSlotMap set this to true if this method should be called again, false if this map is known to be last143* @return a pointer to the first slot mapped by the least significant bit of the map, or NULL if no more slots144*/145virtual fomrobject_t *146getNextSlotMap(uintptr_t *slotMap, uintptr_t *leafMap, bool *hasNextSlotMap)147{148fomrobject_t *mapPtr = GC_MixedObjectScanner::getNextSlotMap(slotMap, leafMap, hasNextSlotMap);149150/* Skip over referent slot */151*slotMap = skipReferentSlot(mapPtr, *slotMap);152153return mapPtr;154}155#endif /* defined(OMR_GC_LEAF_BITS) */156};157#endif /* REFERENCEOBJECTSCANNER_HPP_ */158159160