Path: blob/master/runtime/gc_structs/ClassIterator.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(CLASSITERATOR_HPP_)29#define CLASSITERATOR_HPP_3031#include "j9.h"32#include "j9cfg.h"3334#include "CallSitesIterator.hpp"35#include "ClassStaticsIterator.hpp"36#include "ConstantPoolObjectSlotIterator.hpp"37#include "EnvironmentBase.hpp"38#include "GCExtensionsBase.hpp"39#include "MethodTypesIterator.hpp"40#include "ValueTypesIterator.hpp"4142/**43* State constants representing the current stage of the iteration process44* @anchor ClassIteratorState45*/46enum {47classiterator_state_start = 0,48classiterator_state_statics,49classiterator_state_constant_pool,50classiterator_state_slots,51classiterator_state_callsites,52classiterator_state_methodtypes,53#if defined(J9VM_OPT_METHOD_HANDLE)54classiterator_state_varhandlemethodtypes,55#endif /* defined(J9VM_OPT_METHOD_HANDLE) */56classiterator_state_valuetypes,57classiterator_state_end58};5960/**61* Iterate over all slots in a class which contain an object reference62*63* @see GC_ClassIteratorClassSlots64*65* @ingroup GC_Structs66*/67class GC_ClassIterator {68protected:69J9Class *_clazzPtr;70int _state;71UDATA _scanIndex;7273GC_ClassStaticsIterator _classStaticsIterator;74GC_ConstantPoolObjectSlotIterator _constantPoolObjectSlotIterator;75GC_CallSitesIterator _callSitesIterator;76GC_MethodTypesIterator _methodTypesIterator;77#if defined(J9VM_OPT_METHOD_HANDLE)78GC_MethodTypesIterator _varHandlesMethodTypesIterator;79#endif /* defined(J9VM_OPT_METHOD_HANDLE) */80GC_ValueTypesIterator _valueTypesIterator;81const bool _shouldScanClassObject; /**< Boolean needed for balanced GC to prevent ClassObject from being scanned twice */8283public:84GC_ClassIterator(MM_EnvironmentBase *env, J9Class *clazz, bool shouldScanClassObject = true)85: _clazzPtr(clazz)86, _state(classiterator_state_start)87, _scanIndex(0)88, _classStaticsIterator(env, clazz)89, _constantPoolObjectSlotIterator((J9JavaVM *)env->getLanguageVM(), clazz)90, _callSitesIterator(clazz)91#if defined(J9VM_OPT_OPENJDK_METHODHANDLE)92, _methodTypesIterator(clazz->romClass->invokeCacheCount, clazz->invokeCache)93#else /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */94, _methodTypesIterator(clazz->romClass->methodTypeCount, clazz->methodTypes)95, _varHandlesMethodTypesIterator(clazz->romClass->varHandleMethodTypeCount, clazz->varHandleMethodTypes)96#endif /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */97, _valueTypesIterator(clazz)98, _shouldScanClassObject(shouldScanClassObject)99{}100101GC_ClassIterator(MM_GCExtensionsBase *extensions, J9Class *clazz)102: _clazzPtr(clazz)103, _state(classiterator_state_start)104, _scanIndex(0)105, _classStaticsIterator(extensions, clazz)106, _constantPoolObjectSlotIterator((J9JavaVM *)extensions->getOmrVM()->_language_vm, clazz)107, _callSitesIterator(clazz)108#if defined(J9VM_OPT_OPENJDK_METHODHANDLE)109, _methodTypesIterator(clazz->romClass->invokeCacheCount, clazz->invokeCache)110#else /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */111, _methodTypesIterator(clazz->romClass->methodTypeCount, clazz->methodTypes)112, _varHandlesMethodTypesIterator(clazz->romClass->varHandleMethodTypeCount, clazz->varHandleMethodTypes)113#endif /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */114, _valueTypesIterator(clazz)115, _shouldScanClassObject(true)116{}117118MMINLINE int getState()119{120return _state;121}122123/**124* Fetch the next slot in the class.125* Note that the pointer is volatile. In concurrent applications the mutator may126* change the value in the slot while iteration is in progress.127* @return the next static slot in the class containing an object reference128* @return NULL if there are no more such slots129*/130virtual volatile j9object_t *nextSlot();131};132133#endif /* CLASSITERATOR_HPP_ */134135136137