Path: blob/master/runtime/gc_api/HeapRootScanner.hpp
5990 views
/*******************************************************************************1* Copyright (c) 2001, 2021 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*******************************************************************************/21#if !defined(HEAPROOTSCANNER_HPP_)22#define HEAPROOTSCANNER_HPP_2324#include "j9.h"25#include "j9cfg.h"2627#include "BaseVirtual.hpp"2829#include "Debug.hpp"30#include "EnvironmentBase.hpp"31#include "GCExtensions.hpp"32#include "HeapIteratorAPI.h"33#include "ModronTypes.hpp"3435class MM_HeapRootScanner : public MM_BaseVirtual36{37protected:38MM_GCExtensions *_extensions;39J9JavaVM *_javaVM;4041bool _stringTableAsRoot; /**< Treat the string table as a hard root */42bool _singleThread; /**< Should the iterator operate in single threaded mode */4344bool _nurseryReferencesOnly; /**< Should the iterator only scan structures that currently contain nursery references */45bool _nurseryReferencesPossibly; /**< Should the iterator only scan structures that may contain nursery references */46bool _includeStackFrameClassReferences; /**< Should the iterator include Classes which have a method running on the stack */47#if defined(J9VM_GC_MODRON_SCAVENGER)48bool _includeRememberedSetReferences; /**< Should the iterator include references in the Remembered Set (if applicable) */49#endif /* J9VM_GC_MODRON_SCAVENGER */50bool _classDataAsRoots; /**< Should all classes (and class loaders) be treated as roots. Default true, should set to false when class unloading */51bool _includeJVMTIObjectTagTables; /**< Should the iterator include the JVMTIObjectTagTables. Default true, should set to false when doing JVMTI object walks */52bool _trackVisibleStackFrameDepth; /**< Should the stack walker be told to track the visible frame depth. Default false, should set to true when doing JVMTI walks that report stack slots */5354RootScannerEntity _scanningEntity; /**< The root scanner entity that is currently being scanned. Defaults to RootScannerEntity_None. */55RootScannerEntity _lastScannedEntity; /**< The root scanner entity that was last scanned. Defaults to RootScannerEntity_None. */5657RootScannerEntityReachability _scanningEntityReachability;/**< Reachability of the root scanner entity that is currently being scanned. */5859/**60* Sets the currently scanned root entity to scanningEntity. This is mainly for61* debug purposes.62* @param scanningEntity The entity for which scanning has begun.63*/64MMINLINE void65reportScanningStarted(RootScannerEntity scanningEntity)66{67/* Ensures reportScanningEnded was called previously. */68assume0(RootScannerEntity_None == _scanningEntity);69_scanningEntity = scanningEntity;70}7172/**73* Sets the currently scanned root entity to scanningEntity. This is mainly for74* debug purposes.75* @param scanningEntity The entity for which scanning has begun.76*/77MMINLINE void78setReachability(RootScannerEntityReachability reachability)79{80_scanningEntityReachability = reachability;81}8283/**84* Sets the currently scanned root entity to None and sets the last scanned root85* entity to scannedEntity. This is mainly for debug purposes.86* @param scannedEntity The entity for which scanning has ended.87*/88MMINLINE void89reportScanningEnded(RootScannerEntity scannedEntity)90{91/* Ensures scanning ended for the currently scanned entity. */92assume0(_scanningEntity == scannedEntity);93_lastScannedEntity = _scanningEntity;94_scanningEntity = RootScannerEntity_None;95_scanningEntityReachability = RootScannerEntityReachability_None;96}9798public:99MM_HeapRootScanner(J9JavaVM* javaVM, bool singleThread = false) :100_extensions(MM_GCExtensions::getExtensions(javaVM)),101_javaVM(javaVM),102_stringTableAsRoot(true),103_singleThread(singleThread),104_nurseryReferencesOnly(false),105_nurseryReferencesPossibly(false),106_includeStackFrameClassReferences(true),107#if defined(J9VM_GC_MODRON_SCAVENGER)108_includeRememberedSetReferences(false),109#endif /* J9VM_GC_MODRON_SCAVENGER */110_classDataAsRoots(true),111_includeJVMTIObjectTagTables(true),112_trackVisibleStackFrameDepth(false),113_scanningEntity(RootScannerEntity_None),114_lastScannedEntity(RootScannerEntity_None)115{116_typeId = __FUNCTION__;117}118119#if defined(J9VM_GC_MODRON_SCAVENGER)120/** Set whether the iterator will only scan structures which contain nursery references */121void setNurseryReferencesOnly(bool nurseryReferencesOnly) {122_nurseryReferencesOnly = nurseryReferencesOnly;123}124125/** Set whether the iterator will only scan structures which may contain nursery references */126void setNurseryReferencesPossibly(bool nurseryReferencesPossibly) {127_nurseryReferencesPossibly = nurseryReferencesPossibly;128}129130/** Set whether the iterator will scan the remembered set references (if applicable to the scan type) */131void setIncludeRememberedSetReferences(bool includeRememberedSetReferences) {132_includeRememberedSetReferences = includeRememberedSetReferences;133}134#endif /* J9VM_GC_MODRON_SCAVENGER */135136/** Set whether the iterator will scan stack frames for the classes of running methods */137void setIncludeStackFrameClassReferences(bool includeStackFrameClassReferences) {138_includeStackFrameClassReferences = includeStackFrameClassReferences;139}140141#if defined(J9VM_OPT_JVMTI)142/** Set whether the iterator will scan the JVMTIObjectTagTables (if applicable to the scan type) */143void setIncludeJVMTIObjectTagTables(bool includeJVMTIObjectTagTables) {144_includeJVMTIObjectTagTables = includeJVMTIObjectTagTables;145}146#endif /* J9VM_OPT_JVMTI */147148/** Set whether the iterator will scan the JVMTIObjectTagTables (if applicable to the scan type) */149void setTrackVisibleStackFrameDepth(bool trackVisibleStackFrameDepth) {150_trackVisibleStackFrameDepth = trackVisibleStackFrameDepth;151}152153/** General object slot handler to be reimplemented by specializing class. This handler is called for every reference to a J9Object. */154virtual void doSlot(J9Object** slotPtr) = 0;155156/** General class slot handler to be reimplemented by specializing class. This handler is called for every reference to a J9Class. */157virtual void doClassSlot(J9Class *classPtr);158159/** General class handler to be reimplemented by specializing class. This handler is called once per class. */160virtual void doClass(J9Class *clazz) = 0;161162virtual void doObject(J9Object* slotPtr) = 0;163164#if defined(J9VM_GC_MODRON_SCAVENGER)165virtual void scanRememberedSet();166#endif /* J9VM_GC_MODRON_SCAVENGER */167168virtual void scanClasses();169virtual void scanVMClassSlots();170171virtual bool scanOneThread(J9VMThread* walkThread);172173virtual void scanClassLoaders();174virtual void scanThreads();175#if defined(J9VM_GC_FINALIZATION)176void scanFinalizableObjects();177virtual void scanUnfinalizedObjects();178#endif /* J9VM_GC_FINALIZATION */179/**180* @todo Provide function documentation181*182* @NOTE this code is not thread safe and assumes it is called in a single threaded183* manner.184*185* @NOTE this can only be used as a READ-ONLY version of the ownableSynchronizerObjectList.186* If you need to modify elements with-in the list you will need to provide your own functionality.187* See MM_MarkingScheme::scanOwnableSynchronizerObjects(MM_EnvironmentStandard *env) as an example188* which modifies elements with-in the list.189*/190virtual void scanOwnableSynchronizerObjects();191void scanStringTable();192void scanJNIGlobalReferences();193void scanJNIWeakGlobalReferences();194195virtual void scanMonitorReferences();196197#if defined(J9VM_OPT_JVMTI)198void scanJVMTIObjectTagTables();199#endif /* J9VM_OPT_JVMTI */200201virtual void doClassLoader(J9ClassLoader *classLoader);202203#if defined(J9VM_GC_FINALIZATION)204virtual void doFinalizableObject(J9Object *objectPtr);205virtual void doUnfinalizedObject(J9Object *objectPtr);206#endif /* J9VM_GC_FINALIZATION */207/**208* @todo Provide function documentation209*/210virtual void doOwnableSynchronizerObject(J9Object *objectPtr);211212virtual void doMonitorReference(J9ObjectMonitor *objectMonitor, GC_HashTableIterator *monitorReferenceIterator);213214virtual void doJNIWeakGlobalReference(J9Object **slotPtr);215virtual void doJNIGlobalReferenceSlot(J9Object **slotPtr, GC_JNIGlobalReferenceIterator *jniGlobalReferenceIterator);216217#if defined(J9VM_GC_MODRON_SCAVENGER)218virtual void doRememberedSetSlot(J9Object **slotPtr, GC_RememberedSetSlotIterator *rememberedSetSlotIterator);219#endif /* defined(J9VM_GC_MODRON_SCAVENGER) */220221#if defined(J9VM_OPT_JVMTI)222virtual void doJVMTIObjectTagSlot(J9Object **slotPtr, GC_JVMTIObjectTagTableIterator *objectTagTableIterator);223#endif /* J9VM_OPT_JVMTI */224225virtual void doStringTableSlot(J9Object **slotPtr, GC_StringTableIterator *stringTableIterator);226virtual void doVMClassSlot(J9Class *classPtr);227virtual void doVMThreadSlot(J9Object **slotPtr, GC_VMThreadIterator *vmThreadIterator);228};229230231#endif /* HEAPROOTSCANNER_HPP_ */232233234