Path: blob/master/runtime/gc_structs/ClassLoaderClassesIterator.cpp
5990 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#include "ClassLoaderClassesIterator.hpp"2930#include "GCExtensionsBase.hpp"3132GC_ClassLoaderClassesIterator::GC_ClassLoaderClassesIterator(MM_GCExtensionsBase *extensions, J9ClassLoader *classLoader) :33_javaVM((J9JavaVM* )extensions->getOmrVM()->_language_vm)34,_classLoader(classLoader)35,_vmSegmentIterator(classLoader, MEMORY_TYPE_RAM_CLASS)36,_vmClassSlotIterator((J9JavaVM* )extensions->getOmrVM()->_language_vm)37,_mode(TABLE_CLASSES)38{3940if ((classLoader->flags & J9CLASSLOADER_ANON_CLASS_LOADER) != 0) {41_mode = ANONYMOUS_CLASSES;42}43_nextClass = firstClass();44}4546J9Class *47GC_ClassLoaderClassesIterator::nextSystemClass()48{49return _vmClassSlotIterator.nextSlot();50}5152J9Class *53GC_ClassLoaderClassesIterator::firstClass()54{55J9Class * result;56if (ANONYMOUS_CLASSES == _mode) {57result = nextAnonymousClass();58} else {59result = _javaVM->internalVMFunctions->hashClassTableStartDo(_classLoader, &_walkState, 0);60if ( (NULL == result) && switchToSystemMode() ) {61result = nextSystemClass();62}63}64return result;65}6667J9Class *68GC_ClassLoaderClassesIterator::nextAnonymousClass()69{70J9Class * result = NULL;71J9MemorySegment *segment;72if (NULL != (segment = _vmSegmentIterator.nextSegment())) {73GC_ClassHeapIterator classHeapIterator(_javaVM, segment);74result = classHeapIterator.nextClass();75}76return result;77}787980J9Class *81GC_ClassLoaderClassesIterator::nextTableClass()82{83J9Class * result = _javaVM->internalVMFunctions->hashClassTableNextDo(&_walkState);84if ( (NULL == result) && switchToSystemMode() ) {85result = nextSystemClass();86}87return result;88}899091bool92GC_ClassLoaderClassesIterator::switchToSystemMode()93{94bool isSystemClassLoader = (_classLoader == _javaVM->systemClassLoader);95if (isSystemClassLoader) {96_mode = SYSTEM_CLASSES;97}98return isSystemClassLoader;99}100101J9Class *102GC_ClassLoaderClassesIterator::nextClass()103{104J9Class * result = _nextClass;105106if (NULL != result) {107if (ANONYMOUS_CLASSES == _mode) {108_nextClass = nextAnonymousClass();109} else {110if ( (result->classLoader == _classLoader) && (NULL != result->arrayClass) ) {111/* this class is defined in the loader, so follow its array classes */112_nextClass = result->arrayClass;113} else if (TABLE_CLASSES == _mode) {114_nextClass = nextTableClass();115} else {116_nextClass = nextSystemClass();117}118}119}120121return result;122}123124125