Path: blob/master/runtime/gc_glue_java/HeadlessMixedObjectScanner.hpp
5990 views
/*******************************************************************************1* Copyright (c) 2019, 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#if !defined(HEADLESSMIXEDOBJECTSCANNER_HPP_)23#define HEADLESSMIXEDOBJECTSCANNER_HPP_2425#include "j9.h"2627#include "ObjectScanner.hpp"2829class GC_HeadlessMixedObjectScanner : public GC_ObjectScanner30{31/* Data Members */32private:3334protected:35fomrobject_t *_endPtr; /**< end scan pointer */36fomrobject_t *_mapPtr; /**< pointer to first slot in current scan segment */37uintptr_t *_descriptionPtr; /**< current description pointer */38#if defined(J9VM_GC_LEAF_BITS)39uintptr_t *_leafPtr; /**< current leaf description pointer */40#endif /* J9VM_GC_LEAF_BITS */4142public:4344/* Member Functions */45private:4647protected:4849public:5051/**52* @param env The scanning thread environment53* @param scanPtr Pointer to the start of the object54* @param size The instance size55* @param flags Scanning context flags56*/57MMINLINE GC_HeadlessMixedObjectScanner(MM_EnvironmentBase *env, fomrobject_t *scanPtr, uintptr_t size, uintptr_t flags)58: GC_ObjectScanner(env, scanPtr, 0, flags)59, _endPtr((fomrobject_t *)((uintptr_t)scanPtr + size))60, _mapPtr(scanPtr)61, _descriptionPtr(NULL)62#if defined(J9VM_GC_LEAF_BITS)63, _leafPtr(NULL)64#endif /* J9VM_GC_LEAF_BITS */65{66_typeId = __FUNCTION__;67}6869MMINLINE void70initialize(MM_EnvironmentBase *env, uintptr_t *descriptionPtr, uintptr_t *leafPtr)71{72GC_ObjectScanner::initialize(env);7374/* Initialize the slot map from description bits */75_scanMap = (uintptr_t)descriptionPtr;76#if defined(J9VM_GC_LEAF_BITS)77_leafMap = (uintptr_t)leafPtr;78#endif /* J9VM_GC_LEAF_BITS */79if (_scanMap & 1) {80_scanMap >>= 1;81_descriptionPtr = NULL;82#if defined(J9VM_GC_LEAF_BITS)83_leafMap >>= 1;84_leafPtr = NULL;85#endif /* J9VM_GC_LEAF_BITS */86setNoMoreSlots();87} else {88_descriptionPtr = (uintptr_t *)_scanMap;89_scanMap = *_descriptionPtr;90_descriptionPtr += 1;91#if defined(J9VM_GC_LEAF_BITS)92_leafPtr = (uintptr_t *)_leafMap;93_leafMap = *_leafPtr;94_leafPtr += 1;95#endif /* J9VM_GC_LEAF_BITS */96}97}9899MMINLINE void100initialize(MM_EnvironmentBase *env, uintptr_t *descriptionPtr)101{102initialize(env, descriptionPtr, NULL);103}104105MMINLINE uintptr_t getBytesRemaining() { return (uintptr_t)_endPtr - (uintptr_t)_scanPtr; }106107/**108* Return base pointer and slot bit map for next block of contiguous slots to be scanned. The109* base pointer must be fomrobject_t-aligned. Bits in the bit map are scanned in order of110* increasing significance, and the least significant bit maps to the slot at the returned111* base pointer.112*113* @param[out] scanMap the bit map for the slots contiguous with the returned base pointer114* @param[out] hasNextSlotMap set this to true if this method should be called again, false if this map is known to be last115* @return a pointer to the first slot mapped by the least significant bit of the map, or NULL if no more slots116*/117virtual fomrobject_t *118getNextSlotMap(uintptr_t *slotMap, bool *hasNextSlotMap)119{120bool const compressed = compressObjectReferences();121fomrobject_t *result = NULL;122*slotMap = 0;123*hasNextSlotMap = false;124_mapPtr = GC_SlotObject::addToSlotAddress(_mapPtr, _bitsPerScanMap, compressed);125while (_endPtr > _mapPtr) {126*slotMap = *_descriptionPtr;127_descriptionPtr += 1;128if (0 != *slotMap) {129*hasNextSlotMap = _bitsPerScanMap < GC_SlotObject::subtractSlotAddresses(_endPtr, _mapPtr, compressed);130result = _mapPtr;131break;132}133_mapPtr = GC_SlotObject::addToSlotAddress(_mapPtr, _bitsPerScanMap, compressed);134}135return result;136}137138#if defined(J9VM_GC_LEAF_BITS)139/**140* Return base pointer and slot bit map for next block of contiguous slots to be scanned. The141* base pointer must be fomrobject_t-aligned. Bits in the bit map are scanned in order of142* increasing significance, and the least significant bit maps to the slot at the returned143* base pointer.144*145* @param[out] scanMap the bit map for the slots contiguous with the returned base pointer146* @param[out] leafMap the leaf bit map for the slots contiguous with the returned base pointer147* @param[out] hasNextSlotMap set this to true if this method should be called again, false if this map is known to be last148* @return a pointer to the first slot mapped by the least significant bit of the map, or NULL if no more slots149*/150virtual fomrobject_t *151getNextSlotMap(uintptr_t *slotMap, uintptr_t *leafMap, bool *hasNextSlotMap)152{153bool const compressed = compressObjectReferences();154fomrobject_t *result = NULL;155*slotMap = 0;156*leafMap = 0;157*hasNextSlotMap = false;158_mapPtr = GC_SlotObject::addToSlotAddress(_mapPtr, _bitsPerScanMap, compressed);159while (_endPtr > _mapPtr) {160*slotMap = *_descriptionPtr;161_descriptionPtr += 1;162*leafMap = *_leafPtr;163_leafPtr += 1;164if (0 != *slotMap) {165*hasNextSlotMap = _bitsPerScanMap < GC_SlotObject::subtractSlotAddresses(_endPtr, _mapPtr, compressed);166result = _mapPtr;167break;168}169_mapPtr = GC_SlotObject::addToSlotAddress(_mapPtr, _bitsPerScanMap, compressed);170}171return result;172}173#endif /* J9VM_GC_LEAF_BITS */174};175176#endif /* HEADLESSMIXEDOBJECTSCANNER_HPP_ */177178