Path: blob/master/runtime/gc_structs/ArrayletLeafIterator.hpp
5990 views
/*******************************************************************************1* Copyright (c) 1991, 2021 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(ARRAYLETLEAFITERATOR_HPP_)28#define ARRAYLETLEAFITERATOR_HPP_2930#include "j9.h"31#include "j9cfg.h"32#include "modron.h"33#include "ModronAssertions.h"3435#include "GCExtensionsBase.hpp"36#include "SlotObject.hpp"37#include "ArrayObjectModel.hpp"38#include "ArrayletObjectModel.hpp"3940/**41* Defines the interface for iterating over all slots in an object which contain an object reference42* @ingroup GC_Structs43*/44class GC_ArrayletLeafIterator45{46protected:47OMR_VM *const _omrVM;48#if defined(OMR_GC_COMPRESSED_POINTERS) && defined(OMR_GC_FULL_POINTERS)49bool const _compressObjectReferences;50#endif /* defined(OMR_GC_COMPRESSED_POINTERS) && defined(OMR_GC_FULL_POINTERS) */51GC_SlotObject _slotObject;52J9IndexableObject *_spinePtr; /**< The pointer to the beginning of the actual indexable object (ie: the spine) */53GC_ArrayletObjectModel::ArrayLayout _layout; /**< The layout of the arraylet being iterated */54fj9object_t *_arrayoid; /**< The pointer to the beginning of the arraylet leaf pointers (that is, the first slot after the object header) */55UDATA _numLeafs; /**< The number of leaf pointers beginning at the _arrayoid. This includes inline and out-of-line leaf pointers */56UDATA _numLeafsCounted;57void *_endOfSpine; /**< Pointer to the first slot AFTER the arraylet spine */5859public:60/**61* Return back true if object references are compressed62* @return true, if object references are compressed63*/64MMINLINE bool compressObjectReferences() {65return OMR_COMPRESS_OBJECT_REFERENCES(_compressObjectReferences);66}6768/**69* @return the next leaf reference slot in the arraylet70* @return NULL if there are no more reference slots in the object71*/72MMINLINE GC_SlotObject *nextLeafPointer()73{74if (_numLeafsCounted < _numLeafs) {75_slotObject.writeAddressToSlot(GC_SlotObject::addToSlotAddress(_arrayoid, _numLeafsCounted, compressObjectReferences()));76_numLeafsCounted += 1;77return &_slotObject;78} else {79return NULL;80}81}8283MMINLINE void84initialize(J9IndexableObject *objectPtr)85{86MM_GCExtensionsBase *extensions = MM_GCExtensionsBase::getExtensions(_omrVM);87_spinePtr = objectPtr;88_layout = extensions->indexableObjectModel.getArrayLayout(objectPtr);8990/* For a hybrid arraylet spec, this iterator should not be called for a contiguous arraylet */91Assert_MM_true(GC_ArrayletObjectModel::InlineContiguous != _layout);9293/* for 0-sized arrays, there is no need to return the fake leaf pointer.94* It can potentially be problematic to return this fake leaf pointer as users of95* this iterator assume we return valid leaf pointers.96*/97if (0 == extensions->indexableObjectModel.getSizeInElements(objectPtr)) {98_arrayoid = NULL;99_numLeafs = 0;100} else {101_arrayoid = extensions->indexableObjectModel.getArrayoidPointer(objectPtr);102_numLeafs = extensions->indexableObjectModel.numArraylets(objectPtr);103}104_numLeafsCounted = 0;105_endOfSpine = ((U_8 *)objectPtr) + extensions->indexableObjectModel.getSizeInBytesWithHeader(objectPtr);106}107108MMINLINE UDATA getNumLeafs() { return _numLeafs ; }109110MMINLINE void *getEndOfSpine() { return _endOfSpine ; }111112GC_ArrayletLeafIterator(J9JavaVM *javaVM, J9IndexableObject *objectPtr) :113_omrVM(javaVM->omrVM)114#if defined(OMR_GC_COMPRESSED_POINTERS) && defined(OMR_GC_FULL_POINTERS)115, _compressObjectReferences(J9JAVAVM_COMPRESS_OBJECT_REFERENCES(javaVM))116#endif /* defined(OMR_GC_COMPRESSED_POINTERS) && defined(OMR_GC_FULL_POINTERS) */117, _slotObject(GC_SlotObject(_omrVM, NULL))118{119initialize(objectPtr);120}121};122123#endif /* ARRAYLETLEAFITERATOR_HPP_ */124125126