Path: blob/master/runtime/gc_structs/PointerArrayIterator.hpp
5985 views
1/*******************************************************************************2* Copyright (c) 1991, 2021 IBM Corp. and others3*4* This program and the accompanying materials are made available under5* the terms of the Eclipse Public License 2.0 which accompanies this6* distribution and is available at https://www.eclipse.org/legal/epl-2.0/7* or the Apache License, Version 2.0 which accompanies this distribution and8* is available at https://www.apache.org/licenses/LICENSE-2.0.9*10* This Source Code may also be made available under the following11* Secondary Licenses when the conditions for such availability set12* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU13* General Public License, version 2 with the GNU Classpath14* Exception [1] and GNU General Public License, version 2 with the15* OpenJDK Assembly Exception [2].16*17* [1] https://www.gnu.org/software/classpath/license.html18* [2] http://openjdk.java.net/legal/assembly-exception.html19*20* 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-exception21*******************************************************************************/2223/**24* @file25* @ingroup GC_Structs26*/2728#if !defined(POINTERARRAYITERATOR_HPP_)29#define POINTERARRAYITERATOR_HPP_3031#include "j9.h"32#include "j9cfg.h"33#include "ModronAssertions.h"3435#include "ArrayObjectModel.hpp"36#include "Bits.hpp"37#include "GCExtensionsBase.hpp"38#include "ObjectIteratorState.hpp"39#include "PointerArrayletIterator.hpp"40#include "PointerContiguousArrayIterator.hpp"41#include "SlotObject.hpp"4243/**44* Iterate over all slots in a pointer array which contain an object reference45* @ingroup GC_Structs46*/47class GC_PointerArrayIterator48{49private:50bool _contiguous;51GC_PointerContiguousArrayIterator _contiguousArrayIterator;52GC_PointerArrayletIterator _pointerArrayletIterator; /**< Iterator instance specific for Contiguous (standard) array */5354protected:55public:56/**57* @param objectPtr the array object to be processed58*/59GC_PointerArrayIterator(J9JavaVM *javaVM, J9Object *objectPtr)60: _contiguousArrayIterator(javaVM->omrVM)61, _pointerArrayletIterator(javaVM)62{63initialize(javaVM, objectPtr);64}6566GC_PointerArrayIterator(J9JavaVM *javaVM)67: _contiguousArrayIterator(javaVM->omrVM)68, _pointerArrayletIterator(javaVM)69{70}7172MMINLINE void initialize(J9JavaVM *javaVM, J9Object *objectPtr)73{74MM_GCExtensionsBase *extensions = MM_GCExtensionsBase::getExtensions(javaVM->omrVM);75_contiguous = extensions->indexableObjectModel.isInlineContiguousArraylet((J9IndexableObject *)objectPtr);76if (_contiguous) {77_contiguousArrayIterator.initialize(objectPtr);78} else {79_pointerArrayletIterator.initialize(objectPtr);80}81}8283/**84* Restores the iterator state into this class85* @param[in] objectIteratorState partially scanned object iterator state86*/87MMINLINE void restore(GC_ObjectIteratorState *objectIteratorState)88{89_contiguous = objectIteratorState->_contiguous;90if (_contiguous) {91_contiguousArrayIterator.restore(objectIteratorState);92} else {93_pointerArrayletIterator.restore(objectIteratorState);94}95}9697/**98* Saves the partially scanned state of this class99* @param[in] objectIteratorState where to store the state100*/101MMINLINE void save(GC_ObjectIteratorState *objectIteratorState)102{103if (_contiguous) {104_contiguousArrayIterator.save(objectIteratorState);105} else {106_pointerArrayletIterator.save(objectIteratorState);107}108objectIteratorState->_contiguous = _contiguous;109}110111MMINLINE GC_SlotObject *nextSlot()112{113GC_SlotObject *slotObject = NULL;114if (_contiguous) {115slotObject = _contiguousArrayIterator.nextSlot();116} else {117slotObject = _pointerArrayletIterator.nextSlot();118}119return slotObject;120}121122MMINLINE J9Object *getObject()123{124J9Object *objectPtr = NULL;125if (_contiguous) {126objectPtr = _contiguousArrayIterator.getObject();127} else {128objectPtr = _pointerArrayletIterator.getObject();129}130return (J9Object *)objectPtr;131}132133/**134* Gets the current slot's array index.135* @return slot number (or zero based array index) of the last call to nextSlot.136* @return undefined if nextSlot has yet to be called.137*/138MMINLINE UDATA getIndex()139{140UDATA index = 0;141if (_contiguous) {142index = _contiguousArrayIterator.getIndex();143} else {144index = _pointerArrayletIterator.getIndex();145}146return index;147}148149MMINLINE void setIndex(UDATA index)150{151if (_contiguous) {152_contiguousArrayIterator.setIndex(index);153} else {154_pointerArrayletIterator.setIndex(index);155}156}157};158159#endif /* POINTERARRAYITERATOR_HPP_ */160161162