Path: blob/master/runtime/gc_structs/PointerArrayletInlineLeafIterator.hpp
5985 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(POINTERARRAYLETINLINELEAFITERATOR_HPP_)28#define POINTERARRAYLETINLINELEAFITERATOR_HPP_2930#include "j9.h"31#include "j9cfg.h"32#include "ModronAssertions.h"3334#include "ArrayObjectModel.hpp"35#include "Bits.hpp"36#include "GCExtensionsBase.hpp"37#include "ObjectIteratorState.hpp"38#include "SlotObject.hpp"3940/**41* Iterate over all slots in a pointer array's inline leaf which contain an object reference (will iterate over nothing if the object is fully discontiguous)42* @ingroup GC_Structs43*/44class GC_PointerArrayletInlineLeafIterator45{46/* Data Members */47private:48GC_SlotObject _slotObject; /**< Create own SlotObject class to provide output */49UDATA _arrayletLeafSize; /* The size of an arraylet leaf */50UDATA _fobjectsPerLeaf; /* The number of fj9object_t's per leaf */51fj9object_t * _currentArrayletBaseAddress; /* The base address of the current arraylet */52UDATA _currentArrayletOffset; /* The offset to the _index'ed item from the currentArrayletBaseAddress */53UDATA _elementsStillToRead; /**< The number of elements this iterator is still expecting to return */54J9JavaVM *_javaVM; /**< The JavaVM */55protected:56#if defined(OMR_GC_COMPRESSED_POINTERS) && defined(OMR_GC_FULL_POINTERS)57bool const _compressObjectReferences;58#endif /* defined(OMR_GC_COMPRESSED_POINTERS) && defined(OMR_GC_FULL_POINTERS) */59public:6061/* Member Functions */62private:63protected:64public:65/**66* Return back true if object references are compressed67* @return true, if object references are compressed68*/69MMINLINE bool compressObjectReferences() {70return OMR_COMPRESS_OBJECT_REFERENCES(_compressObjectReferences);71}7273MMINLINE void initialize(J9Object *objectPtr) {74MM_GCExtensionsBase *extensions = MM_GCExtensionsBase::getExtensions(_javaVM->omrVM);7576J9IndexableObject *arrayPtr = (J9IndexableObject *)objectPtr;7778/* Set current and end scan pointers */79UDATA index = extensions->indexableObjectModel.getSizeInElements(arrayPtr);80if(0 == index) {81_currentArrayletOffset = 0;82_currentArrayletBaseAddress = NULL;83_elementsStillToRead = 0;84} else {85UDATA currentArrayletIndex = ((U_32)index-1) / _fobjectsPerLeaf; /* The index of the arraylet containing _index */86_currentArrayletOffset = ((U_32)index-1) % _fobjectsPerLeaf; /* The offset of _index in the current arraylet */8788fj9object_t *arrayoidPointer = extensions->indexableObjectModel.getArrayoidPointer(arrayPtr);89GC_SlotObject arrayletBaseSlotObject(_javaVM->omrVM, GC_SlotObject::addToSlotAddress(arrayoidPointer, currentArrayletIndex, compressObjectReferences()));90_currentArrayletBaseAddress = (fj9object_t *)arrayletBaseSlotObject.readReferenceFromSlot();91_elementsStillToRead = index % _fobjectsPerLeaf;92}93}9495MMINLINE GC_SlotObject *nextSlot()96{97GC_SlotObject *slotObject = NULL;9899if (_elementsStillToRead > 0) {100_slotObject.writeAddressToSlot(GC_SlotObject::addToSlotAddress(_currentArrayletBaseAddress, _currentArrayletOffset, compressObjectReferences()));101102_elementsStillToRead -= 1;103_currentArrayletOffset -= 1;104105slotObject = &_slotObject;106}107return slotObject;108}109110GC_PointerArrayletInlineLeafIterator(J9JavaVM *javaVM)111: _slotObject(GC_SlotObject(javaVM->omrVM, NULL))112, _javaVM(javaVM)113#if defined(OMR_GC_COMPRESSED_POINTERS) && defined(OMR_GC_FULL_POINTERS)114, _compressObjectReferences(J9JAVAVM_COMPRESS_OBJECT_REFERENCES(javaVM))115#endif /* defined(OMR_GC_COMPRESSED_POINTERS) && defined(OMR_GC_FULL_POINTERS) */116{117_arrayletLeafSize = _javaVM->arrayletLeafSize;118_fobjectsPerLeaf = _arrayletLeafSize / J9JAVAVM_REFERENCE_SIZE(javaVM);119}120121/**122* @param objectPtr the array object to be processed123*/124GC_PointerArrayletInlineLeafIterator(J9JavaVM *javaVM, J9Object *objectPtr)125: _slotObject(GC_SlotObject(javaVM->omrVM, NULL))126, _javaVM(javaVM)127#if defined(OMR_GC_COMPRESSED_POINTERS) && defined(OMR_GC_FULL_POINTERS)128, _compressObjectReferences(J9JAVAVM_COMPRESS_OBJECT_REFERENCES(javaVM))129#endif /* defined(OMR_GC_COMPRESSED_POINTERS) && defined(OMR_GC_FULL_POINTERS) */130{131_arrayletLeafSize = _javaVM->arrayletLeafSize;132_fobjectsPerLeaf = _arrayletLeafSize / J9JAVAVM_REFERENCE_SIZE(javaVM);133initialize(objectPtr);134}135};136137#endif /* POINTERARRAYLETINLINELEAFITERATOR_HPP_ */138139140