Path: blob/master/runtime/gc_include/HeapIteratorAPI.h
5986 views
/*******************************************************************************1* Copyright (c) 1991, 2019 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*******************************************************************************/212223/**24* @file25* @ingroup GC_Include26*/2728#if !defined(HEAPITERATORAPI_H_)29#define HEAPITERATORAPI_H_3031/* @ddr_namespace: default */32#include "j9.h"33#include "j9modron.h"34#include "RootScannerTypes.h"35#include "jvmti.h"3637#ifdef __cplusplus38extern "C" {39#endif4041/**42* Scan Flags43*/44#define SCAN_CLASSES 0x0000145#define SCAN_VM_CLASS_SLOTS 0x0000246#define SCAN_CLASS_LOADERS 0x0000447#define SCAN_THREADS 0x0000848#define SCAN_FINALIZABLE_OBJECTS 0x0001049#define SCAN_JNI_GLOBAL 0x0002050#define SCAN_STRING_TABLE 0x0004051#define SCAN_UNUSED_1 0x0008052#define SCAN_UNUSED_2 0x0010053#define SCAN_UNUSED_3 0x0020054#define SCAN_UNFINALIZABLE 0x0040055#define SCAN_MONITORS 0x0080056#define SCAN_JNI_WEAK 0x0100057#define SCAN_DEBUGGER 0x0200058#define SCAN_DEBUGGER_CLASS_REF 0x0400059#define SCAN_REMEBERED_SET 0x0800060#define SCAN_JVMTI_OBJECT_TAG_TABLE 0x1000061#define SCAN_OWNABLE_SYNCHRONIZER 0x2000062#define SCAN_ALL 0x3FFFF6364#define HEAP_ROOT_SLOT_DESCRIPTOR_OBJECT 065#define HEAP_ROOT_SLOT_DESCRIPTOR_CLASS 16667typedef enum RootScannerEntityReachability {68RootScannerEntityReachability_None = 0,69RootScannerEntityReachability_Strong,70RootScannerEntityReachability_Weak71} RootScannerEntityReachability;7273/**74* Iterator directives (placeholders for now)75*/76typedef enum J9MM_IteratorHeapType {77j9mm_iterator_heap_type_all = 0,78/* ensure 4-byte enum */79j9mm_iterator_heap_type_max = 0x100000080} J9MM_IteratorHeapType;8182typedef enum J9MM_IteratorSpaceType {83j9mm_iterator_space_type_all = 0,84/* ensure 4-byte enum */85j9mm_iterator_space_type_max = 0x100000086} J9MM_IteratorSpaceType;8788typedef enum J9MM_IteratorRegionType {89j9mm_iterator_region_type_all = 0,90/* ensure 4-byte enum */91j9mm_iterator_region_type_max = 0x100000092} J9MM_IteratorRegionType;9394typedef enum J9MM_IteratorObjectType {95j9mm_iterator_object_type_all = 0,96/* ensure 4-byte enum */97j9mm_iterator_object_type_max = 0x100000098} J9MM_IteratorObjectType;99100typedef enum J9MM_IteratorObjectRefType {101j9mm_iterator_object_ref_type_object = 1,102j9mm_iterator_object_ref_type_arraylet_leaf = 2,103/* ensure 4-byte enum */104j9mm_iterator_object_ref_type_max = 0x1000000105} J9MM_IteratorObjectRefType;106107typedef enum J9MM_IteratorFlags {108j9mm_iterator_flag_none = 0,109j9mm_iterator_flag_include_holes = 1, /**< Indicates that holes (unused portions of the region) should be included in the object iterators */110j9mm_iterator_flag_include_arraylet_leaves = 2, /**< Indicates that arraylet leaf pointers should be included in the object ref iterators */111j9mm_iterator_flag_exclude_null_refs = 4, /**< Indicates that NULL pointers should be excluded in the object ref iterators */112j9mm_iterator_flag_regions_read_only = 8, /**< Indicates that it is read only request (no TLH flush and further heap walk) */113j9mm_iterator_flag_max = 0x1000000114} J9MM_IteratorFlags;115116/**117* Descriptor declarations (what is handed to the user functions). None of the strings for identifiers are carved in stone.118* The structure and its contents are only guaranteed for the lifetime of the user function call.119*/120typedef struct J9MM_IterateHeapDescriptor {121const char *name; /**< Name of the Heap */122UDATA id; /**< Unique identifier */123} J9MM_IterateHeapDescriptor;124125typedef struct J9MM_IterateSpaceDescriptor {126const char *name; /**< Name of the space */127UDATA id; /**< Unique identifier */128UDATA classPointerOffset; /**< Offset from the beginning of an object where the class pointer resides */129UDATA classPointerSize; /**< Size of the class pointer, in bytes */130UDATA fobjectPointerScale; /**< Multiplier for compressed pointer decompression */131UDATA fobjectPointerDisplacement; /**< Displacement to add for compressed pointer decompression */132UDATA fobjectSize; /**< sizeof(fj9object_t) */133void* memorySpace; /**< the memory space struct associated with this space, or NULL if none. This is temporary. */134} J9MM_IterateSpaceDescriptor;135136typedef struct J9MM_IterateRegionDescriptor {137const char *name; /**< Name of the Heap */138UDATA id; /**< Unique identifier */139UDATA objectAlignment; /**< Object alignment for this region */140UDATA objectMinimumSize; /**< Object minimum size for this region */141const void *regionStart; /**< Address of the start of the region */142UDATA regionSize; /**< The size (in bytes) of the region */143} J9MM_IterateRegionDescriptor;144145typedef struct J9MM_IterateObjectDescriptor {146UDATA id; /**< Unique identifier */147UDATA size; /**< Size in bytes that the object (or hole) consumes */148j9object_t object; /**< Pointer to the actual J9Object (or hole). This is temporary */149UDATA isObject; /**< TRUE if this is an object, or FALSE if it's a hole */150} J9MM_IterateObjectDescriptor;151152typedef struct J9MM_IterateObjectRefDescriptor {153UDATA id; /**< Unique identifier */154j9object_t object; /**< Pointer to the actual j9object_t. If this value is modified it is stored back into the field once the callback returns */155const fj9object_t *fieldAddress; /**< The address of the field within the object */156J9MM_IteratorObjectRefType type; /**< The type of reference */157} J9MM_IterateObjectRefDescriptor;158159typedef struct J9MM_HeapRootSlotDescriptor {160UDATA slotType; /**< Type of slot */161UDATA scanType; /**< What is being scanned, class or object */162UDATA slotReachability; /**< Reachability of slot */163} J9MM_HeapRootSlotDescriptor;164165typedef jvmtiIterationControl (*rootIteratorCallBackFunc)(void* ptr, J9MM_HeapRootSlotDescriptor *rootDesc, void *userData);166167/**168* Walk the roots within a heap, call user provided function169* @param flags The flags describing the walk (unused currently)170* @param func The function to call on each heap descriptor.171* @param userData Pointer to storage for userData.172*/173jvmtiIterationControl174j9mm_iterate_roots(J9JavaVM *javaVM, J9PortLibrary *portLibrary, UDATA flags, rootIteratorCallBackFunc callBackFunc, void *userData);175176/**177* Walk all heaps, call user provided function.178*179* The caller must have VM access.180*181* This function may acquire locks during its execution to protect the list of heaps.182* These locks may be held while the callback function is executed.183*184* @param flags The flags describing the walk (unused currently)185* @param func The function to call on each heap descriptor.186* @param userData Pointer to storage for userData.187*/188jvmtiIterationControl189j9mm_iterate_heaps(J9JavaVM *vm, J9PortLibrary *portLibrary, UDATA flags, jvmtiIterationControl (*func)(J9JavaVM *vm, J9MM_IterateHeapDescriptor *heapDesc, void *userData), void *userData);190191/**192* Walk all spaces contained in the heap, call user provided function.193*194* The caller must have VM access.195*196* This function may acquire locks during its execution to protect the list of spaces.197* These locks may be held while the callback function is executed.198*199* @param flags The flags describing the walk (unused currently)200* @param func The function to call on each heap descriptor.201* @param userData Pointer to storage for userData.202*/203jvmtiIterationControl204j9mm_iterate_spaces(J9JavaVM *vm, J9PortLibrary *portLibrary, J9MM_IterateHeapDescriptor *heap, UDATA flags, jvmtiIterationControl (*func)(J9JavaVM *vm, J9MM_IterateSpaceDescriptor *spaceDesc, void *userData), void *userData);205206/**207* Walk all regions for the given space, call user provided function.208*209* The caller must have VM access.210*211* This function may acquire locks during its execution to protect the list of regions.212* These locks may be held while the callback function is executed.213*214* @param space The descriptor for the space that should be walked215* @param flags The flags describing the walk (unused currently)216* @param func The function to call on each region descriptor.217* @param userData Pointer to storage for userData.218*/219jvmtiIterationControl220j9mm_iterate_regions(J9JavaVM *vm, J9PortLibrary *portLibrary, J9MM_IterateSpaceDescriptor *space, UDATA flags, jvmtiIterationControl (*func)(J9JavaVM *vm, J9MM_IterateRegionDescriptor *regionDesc, void *userData), void *userData);221222/**223* Walk all objects for the given region, call user provided function.224*225* The caller must have exclusive VM access.226*227* @param region The descriptor for the region that should be walked228* @param flags The flags describing the walk (0 or j9mm_iterator_flag_include_holes)229* @param func The function to call on each object descriptor.230* @param userData Pointer to storage for userData.231*/232jvmtiIterationControl233j9mm_iterate_region_objects(J9JavaVM *vm, J9PortLibrary *portLibrary, J9MM_IterateRegionDescriptor *region, UDATA flags, jvmtiIterationControl (*func)(J9JavaVM *vm, J9MM_IterateObjectDescriptor *objectDesc, void *userData), void *userData);234235/**236* Walk all object slots for the given object, call user provided function.237* @param object The descriptor for the object that should be walked238* @param flags The flags describing the walk (0 or any combination of j9mm_iterator_flag_include_arraylet_leaves and j9mm_iterator_flag_exclude_null_refs)239* @param func The function to call on each object descriptor.240* @param userData Pointer to storage for userData.241*/242jvmtiIterationControl243j9mm_iterate_object_slots(J9JavaVM *javaVM, J9PortLibrary *portLibrary, J9MM_IterateObjectDescriptor *object, UDATA flags, jvmtiIterationControl (*func)(J9JavaVM *javaVM, J9MM_IterateObjectDescriptor *objectDesc, J9MM_IterateObjectRefDescriptor *refDesc, void *userData), void *userData);244245/**246* Initialize a descriptor for the specified object.247* This descriptor may subsequently be used with j9mm_iterate_object_slots or other iterator APIs.248*249* @return descriptor The descriptor to be initialized250* @param object The object to store into the descriptor251*/252void253j9mm_initialize_object_descriptor(J9JavaVM *javaVM, J9MM_IterateObjectDescriptor *descriptor, j9object_t object);254255/**256* Walk all objects for the given VM, call user provided function.257* @param flags The flags describing the walk (0 or j9mm_iterator_flag_include_holes)258* @param func The function to call on each object descriptor.259* @param userData Pointer to storage for userData.260*/261jvmtiIterationControl262j9mm_iterate_all_objects(J9JavaVM *vn, J9PortLibrary *portLibrary, UDATA flags, jvmtiIterationControl (*func)(J9JavaVM *vm, J9MM_IterateObjectDescriptor *object, void *userData), void *userData);263264/**265* Walk all ownable synchronizer object, call user provided function.266* @param flags The flags describing the walk (unused currently)267* @param func The function to call on each object descriptor.268* @param userData Pointer to storage for userData.269* @return return 0 on successfully iterating entire list, return user provided function call if it did not return JVMTI_ITERATION_CONTINUE270*/271jvmtiIterationControl272j9mm_iterate_all_ownable_synchronizer_objects(J9VMThread *vmThread, J9PortLibrary *portLibrary, UDATA flags, jvmtiIterationControl (*func)(J9VMThread *vmThread, J9MM_IterateObjectDescriptor *object, void *userData), void *userData);273274/**275* Shortcut specific for Segregated heap to find the page the pointer belongs to276* This is instead of iterating pages, which may be very time consuming.277* @param objectDescriptor Structure containing pointer to an object278* @param regionDesc Out parameter initialized by the method if the region is found279*/280UDATA281j9mm_find_region_for_pointer(J9JavaVM* javaVM, void *pointer, J9MM_IterateRegionDescriptor *regionDesc);282283/**284* Convert the memory that is currently represented as an object to dark matter.285* This routine is typically used by GC tools such as gccheck and tgc to ensure that only valid (i.e. reachable)286* objects remain on the heap after a sweep. A 'dead' object may contain dangling references to heap addresses287* which no longer contain walkable objects. The problem is solved by converting the invalid objects to dark matter.288*289* @param[in] javaVM the JavaVM290* @param[in] region the region in which the object exists291* @param[in] objectDesc the object to be abandoned292* @return 0 on success, non-0 on failure.293*/294UDATA295j9mm_abandon_object(J9JavaVM *javaVM, J9MM_IterateRegionDescriptor *region, J9MM_IterateObjectDescriptor *objectDesc);296297#ifdef __cplusplus298} /* extern "C" { */299#endif /* __cplusplus */300301#endif /* HEAPITERATORAPI_H_ */302303304