Path: blob/master/runtime/gc_structs/ClassStaticsIterator.hpp
5985 views
1/*******************************************************************************2* Copyright (c) 1991, 2018 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(CLASSSTATICSITERATOR_HPP_)29#define CLASSSTATICSITERATOR_HPP_3031#include "j9.h"32#include "j9cfg.h"33#include "j9cp.h"34#include "util_api.h"35#include "modron.h"3637#include "EnvironmentBase.hpp"38#include "GCExtensions.hpp"3940/**41* Iterate over all static slots in a class which contain an object reference.42* @ingroup GC_Structs43*/44class GC_ClassStaticsIterator45{46U_32 _objectStaticCount;47j9object_t *_staticPtr;4849public:50GC_ClassStaticsIterator(MM_EnvironmentBase *env, J9Class *clazz)51: _objectStaticCount(clazz->romClass->objectStaticCount)52, _staticPtr((j9object_t *)clazz->ramStatics)53{54/* check if the class's statics have been abandoned due to hot55* code replace. If so, this class has no statics of its own56*/57/*58* Note: we have no special recognition for J9ArrayClass here59* J9ArrayClass does not have a ramStatics field but something else at this place60* so direct check (NULL != clazz->ramStatics) would not be correct,61* however romClazz->objectStaticCount must be 0 for this case62* as well as J9ArrayClass can not be hot swapped.63*64* Classes which have been hotswapped by fast HCR still have the ramStatics field65* set. Statics must be walked only once, so only walk them for the most current66* version of the class.67*/68if ((NULL == _staticPtr) || (J9ClassReusedStatics == (J9CLASS_EXTENDED_FLAGS(clazz) & J9ClassReusedStatics))) {69_objectStaticCount = 0;70}71};7273GC_ClassStaticsIterator(MM_GCExtensionsBase *extensions, J9Class *clazz)74: _objectStaticCount(clazz->romClass->objectStaticCount)75, _staticPtr((j9object_t *)clazz->ramStatics)76{77/* check if the class's statics have been abandoned due to hot78* code replace. If so, this class has no statics of its own79*/80/*81* Note: we have no special recognition for J9ArrayClass here82* J9ArrayClass does not have a ramStatics field but something else at this place83* so direct check (NULL != clazz->ramStatics) would not be correct,84* however romClazz->objectStaticCount must be 0 for this case85* as well as J9ArrayClass can not be hot swapped.86*87* Classes which have been hotswapped by fast HCR still have the ramStatics field88* set. Statics must be walked only once, so only walk them for the most current89* version of the class.90*/91if ((NULL == _staticPtr) || (J9ClassReusedStatics == (J9CLASS_EXTENDED_FLAGS(clazz) & J9ClassReusedStatics))) {92_objectStaticCount = 0;93}94};9596/**97* Fetch the next static field in the class.98* Note that the pointer is volatile. In concurrent applications the mutator may99* change the value in the slot while iteration is in progress.100* @return the next static slot in the class containing an object reference101* @return NULL if there are no more such slots102*/103volatile j9object_t *104nextSlot()105{106j9object_t *slotPtr;107108if (0 == _objectStaticCount) {109return NULL;110}111_objectStaticCount -= 1;112slotPtr = _staticPtr++;113114return slotPtr;115}116};117#endif /* CLASSSTATICSITERATOR_HPP_ */118119120