Path: blob/master/runtime/gc_structs/ClassLoaderClassesIterator.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(HASHCLASSTABLEITERATOR_HPP_)29#define HASHCLASSTABLEITERATOR_HPP_3031#include "j9.h"32#include "j9protos.h"33#include "modron.h"3435#include "VMClassSlotIterator.hpp"36#include "ClassLoaderSegmentIterator.hpp"37#include "ClassHeapIterator.hpp"3839class MM_GCExtensionsBase;4041/**42* Iterate over all the defined and referenced classes in a ClassLoader.43* Note that this also includes array classes of defined classes as well44* as system classes (Byte.TYPE, [C, ...) for the system class loader.45* Replaced (HCR) classes are not included.46*47* @ingroup GC_Structs48*/49class GC_ClassLoaderClassesIterator50{51private:52J9JavaVM* _javaVM; /**< the JavaVM */53J9ClassLoader *_classLoader; /**< the loader being iterated */54J9Class *_nextClass; /**< the next class to be returned */55J9HashTableState _walkState; /**< an opaque state structure used by VM helpers */56GC_ClassLoaderSegmentIterator _vmSegmentIterator; /**< used for finding anonymous classes for the anonymous loader */57GC_VMClassSlotIterator _vmClassSlotIterator; /**< used for finding system classes for the system loader */58enum ScanModes {59TABLE_CLASSES,60SYSTEM_CLASSES,61ANONYMOUS_CLASSES62};63ScanModes _mode; /**< indicate type of classes to be iterated */6465protected:66public:6768private:69/**70* Find the next class in the JavaVM. This should only be called in SYSTEM_CLASSES mode.71* @return the next system class, or NULL if finished72*/73J9Class *nextSystemClass();7475/**76* Find the first class in the loader's table or first Anonymous class from segment.77* If none, and if this is the system class loader, switch to SYSTEM_CLASSES mode and78* return the first system class.79* @return the first table class, first system class, or NULL if no classes80*/81J9Class *firstClass();8283/**84* Find the next anonymous class from segment85* @return the next anonymous class or NULL if no classes86*/87J9Class *nextAnonymousClass();8889/**90* Find the next class in the loader's table. If none, and if this is the system class91* loader, switch to SYSTEM_CLASSES mode and return the first system class92* @return the next table class, first system class, or NULL if no classes93*/94J9Class *nextTableClass();9596/**97* If this is the system class loader, switch from TABLE_CLASSES to SYSTEM_CLASSES mode.98* @return true if this is the system class loader, false otherwise99*/100bool switchToSystemMode();101102protected:103104public:105/**106* Construct a new iterator for iterating over defined and referenced classes in the107* specified ClassLoader108* @param extensions[in] the GC extensions109* @param classLoader[in] the loader to iterate110*/111GC_ClassLoaderClassesIterator(MM_GCExtensionsBase *extensions, J9ClassLoader *classLoader);112113/**114* Fetch the next defined or referenced class.115* @return the next class, or NULL if finished116*/117J9Class *nextClass();118};119120#endif /* HASHCLASSTABLEITERATOR_HPP_ */121122123124125