Path: blob/master/runtime/gc_glue_java/ObjectIterator.hpp
5985 views
/*******************************************************************************1* Copyright (c) 2014, 2019 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(OBJECTITERATOR_HPP_)23#define OBJECTITERATOR_HPP_2425#include "j9.h"26#include "j9cfg.h"27#include "ModronAssertions.h"28#include "modronbase.h"29#include "objectdescription.h"3031#include "Base.hpp"32#include "GCExtensions.hpp"33#include "MixedObjectIterator.hpp"34#include "ObjectModel.hpp"35#include "PointerContiguousArrayIterator.hpp"36#include "SlotObject.hpp"3738class GC_ObjectIterator {39/* Data Members */40private:41OMR_VM* _omrVM;4243GC_ObjectModel::ScanType _type;4445GC_SlotObject _slotObject;4647GC_MixedObjectIterator _mixedObjectIterator;48GC_PointerContiguousArrayIterator _pointerContiguousArrayIterator;4950protected:51public:52/* Member Functions */53private:54protected:55public:56/**57* Initialize the internal walk description for the given object.58* @param objectPtr[in] object to be scanned59*/60MMINLINE void initialize(omrobjectptr_t objectPtr)61{62/* check scan type and initialize the proper iterator */63_type = MM_GCExtensions::getExtensions(_omrVM)->objectModel.getScanType(objectPtr);64switch (_type) {65case GC_ObjectModel::SCAN_INVALID_OBJECT:66return;67case GC_ObjectModel::SCAN_MIXED_OBJECT_LINKED:68case GC_ObjectModel::SCAN_ATOMIC_MARKABLE_REFERENCE_OBJECT:69case GC_ObjectModel::SCAN_MIXED_OBJECT:70case GC_ObjectModel::SCAN_CLASS_OBJECT:71case GC_ObjectModel::SCAN_CLASSLOADER_OBJECT:72case GC_ObjectModel::SCAN_OWNABLESYNCHRONIZER_OBJECT:73case GC_ObjectModel::SCAN_REFERENCE_MIXED_OBJECT:74return _mixedObjectIterator.initialize(_omrVM, objectPtr);75case GC_ObjectModel::SCAN_POINTER_ARRAY_OBJECT:76return _pointerContiguousArrayIterator.initialize(objectPtr);77case GC_ObjectModel::SCAN_PRIMITIVE_ARRAY_OBJECT:78return;79default:80Assert_MM_unreachable();81}82}8384/**85* Return back SlotObject for next reference86* @return SlotObject87*/88MMINLINE GC_SlotObject* nextSlot()89{90/* check scan type and call nextSlot on the proper iterator */91switch (_type) {92case GC_ObjectModel::SCAN_INVALID_OBJECT:93return NULL;94case GC_ObjectModel::SCAN_MIXED_OBJECT_LINKED:95case GC_ObjectModel::SCAN_ATOMIC_MARKABLE_REFERENCE_OBJECT:96case GC_ObjectModel::SCAN_MIXED_OBJECT:97case GC_ObjectModel::SCAN_CLASS_OBJECT:98case GC_ObjectModel::SCAN_CLASSLOADER_OBJECT:99case GC_ObjectModel::SCAN_OWNABLESYNCHRONIZER_OBJECT:100case GC_ObjectModel::SCAN_REFERENCE_MIXED_OBJECT:101return _mixedObjectIterator.nextSlot();102case GC_ObjectModel::SCAN_POINTER_ARRAY_OBJECT:103return _pointerContiguousArrayIterator.nextSlot();104case GC_ObjectModel::SCAN_PRIMITIVE_ARRAY_OBJECT:105return NULL;106default:107Assert_MM_unreachable();108}109return NULL;110}111112/**113* Restores the iterator state into this class114* @param[in] objectIteratorState partially scanned object iterator state115*/116MMINLINE void restore(GC_ObjectIteratorState* objectIteratorState)117{118/* check scan type and call restore on the proper iterator */119switch (_type) {120case GC_ObjectModel::SCAN_INVALID_OBJECT:121return;122case GC_ObjectModel::SCAN_MIXED_OBJECT_LINKED:123case GC_ObjectModel::SCAN_ATOMIC_MARKABLE_REFERENCE_OBJECT:124case GC_ObjectModel::SCAN_MIXED_OBJECT:125case GC_ObjectModel::SCAN_CLASS_OBJECT:126case GC_ObjectModel::SCAN_CLASSLOADER_OBJECT:127case GC_ObjectModel::SCAN_OWNABLESYNCHRONIZER_OBJECT:128case GC_ObjectModel::SCAN_REFERENCE_MIXED_OBJECT:129return _mixedObjectIterator.restore(objectIteratorState);130case GC_ObjectModel::SCAN_POINTER_ARRAY_OBJECT:131return _pointerContiguousArrayIterator.restore(objectIteratorState);132case GC_ObjectModel::SCAN_PRIMITIVE_ARRAY_OBJECT:133return;134default:135Assert_MM_unreachable();136}137}138139/**140* Saves the partially scanned state of this class141* @param[in] objectIteratorState where to store the state142*/143MMINLINE void save(GC_ObjectIteratorState* objectIteratorState)144{145/* check scan type and call nextSlot on the proper iterator */146switch (_type) {147case GC_ObjectModel::SCAN_INVALID_OBJECT:148return;149case GC_ObjectModel::SCAN_MIXED_OBJECT_LINKED:150case GC_ObjectModel::SCAN_ATOMIC_MARKABLE_REFERENCE_OBJECT:151case GC_ObjectModel::SCAN_MIXED_OBJECT:152case GC_ObjectModel::SCAN_CLASS_OBJECT:153case GC_ObjectModel::SCAN_CLASSLOADER_OBJECT:154case GC_ObjectModel::SCAN_OWNABLESYNCHRONIZER_OBJECT:155case GC_ObjectModel::SCAN_REFERENCE_MIXED_OBJECT:156return _mixedObjectIterator.save(objectIteratorState);157case GC_ObjectModel::SCAN_POINTER_ARRAY_OBJECT:158return _pointerContiguousArrayIterator.save(objectIteratorState);159case GC_ObjectModel::SCAN_PRIMITIVE_ARRAY_OBJECT:160return;161default:162Assert_MM_unreachable();163}164}165166/**167* @param omrVM[in] pointer to the OMR VM168*/169GC_ObjectIterator(OMR_VM* omrVM)170: _omrVM(omrVM)171, _type(GC_ObjectModel::SCAN_INVALID_OBJECT)172, _slotObject(GC_SlotObject(omrVM, NULL))173, _mixedObjectIterator(omrVM)174, _pointerContiguousArrayIterator(omrVM)175{176}177178/**179* @param omrVM[in] pointer to the OMR VM180* @param objectPtr[in] the object to be processed181*/182GC_ObjectIterator(OMR_VM* omrVM, omrobjectptr_t objectPtr)183: _omrVM(omrVM)184, _type(GC_ObjectModel::SCAN_INVALID_OBJECT)185, _slotObject(GC_SlotObject(omrVM, NULL))186, _mixedObjectIterator(omrVM)187, _pointerContiguousArrayIterator(omrVM)188{189initialize(objectPtr);190}191};192193#endif /* OBJECTITERATOR_HPP_ */194195196