Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_include/HeapIteratorAPI.h
5986 views
1
/*******************************************************************************
2
* Copyright (c) 1991, 2019 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* 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 and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
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-exception
21
*******************************************************************************/
22
23
24
/**
25
* @file
26
* @ingroup GC_Include
27
*/
28
29
#if !defined(HEAPITERATORAPI_H_)
30
#define HEAPITERATORAPI_H_
31
32
/* @ddr_namespace: default */
33
#include "j9.h"
34
#include "j9modron.h"
35
#include "RootScannerTypes.h"
36
#include "jvmti.h"
37
38
#ifdef __cplusplus
39
extern "C" {
40
#endif
41
42
/**
43
* Scan Flags
44
*/
45
#define SCAN_CLASSES 0x00001
46
#define SCAN_VM_CLASS_SLOTS 0x00002
47
#define SCAN_CLASS_LOADERS 0x00004
48
#define SCAN_THREADS 0x00008
49
#define SCAN_FINALIZABLE_OBJECTS 0x00010
50
#define SCAN_JNI_GLOBAL 0x00020
51
#define SCAN_STRING_TABLE 0x00040
52
#define SCAN_UNUSED_1 0x00080
53
#define SCAN_UNUSED_2 0x00100
54
#define SCAN_UNUSED_3 0x00200
55
#define SCAN_UNFINALIZABLE 0x00400
56
#define SCAN_MONITORS 0x00800
57
#define SCAN_JNI_WEAK 0x01000
58
#define SCAN_DEBUGGER 0x02000
59
#define SCAN_DEBUGGER_CLASS_REF 0x04000
60
#define SCAN_REMEBERED_SET 0x08000
61
#define SCAN_JVMTI_OBJECT_TAG_TABLE 0x10000
62
#define SCAN_OWNABLE_SYNCHRONIZER 0x20000
63
#define SCAN_ALL 0x3FFFF
64
65
#define HEAP_ROOT_SLOT_DESCRIPTOR_OBJECT 0
66
#define HEAP_ROOT_SLOT_DESCRIPTOR_CLASS 1
67
68
typedef enum RootScannerEntityReachability {
69
RootScannerEntityReachability_None = 0,
70
RootScannerEntityReachability_Strong,
71
RootScannerEntityReachability_Weak
72
} RootScannerEntityReachability;
73
74
/**
75
* Iterator directives (placeholders for now)
76
*/
77
typedef enum J9MM_IteratorHeapType {
78
j9mm_iterator_heap_type_all = 0,
79
/* ensure 4-byte enum */
80
j9mm_iterator_heap_type_max = 0x1000000
81
} J9MM_IteratorHeapType;
82
83
typedef enum J9MM_IteratorSpaceType {
84
j9mm_iterator_space_type_all = 0,
85
/* ensure 4-byte enum */
86
j9mm_iterator_space_type_max = 0x1000000
87
} J9MM_IteratorSpaceType;
88
89
typedef enum J9MM_IteratorRegionType {
90
j9mm_iterator_region_type_all = 0,
91
/* ensure 4-byte enum */
92
j9mm_iterator_region_type_max = 0x1000000
93
} J9MM_IteratorRegionType;
94
95
typedef enum J9MM_IteratorObjectType {
96
j9mm_iterator_object_type_all = 0,
97
/* ensure 4-byte enum */
98
j9mm_iterator_object_type_max = 0x1000000
99
} J9MM_IteratorObjectType;
100
101
typedef enum J9MM_IteratorObjectRefType {
102
j9mm_iterator_object_ref_type_object = 1,
103
j9mm_iterator_object_ref_type_arraylet_leaf = 2,
104
/* ensure 4-byte enum */
105
j9mm_iterator_object_ref_type_max = 0x1000000
106
} J9MM_IteratorObjectRefType;
107
108
typedef enum J9MM_IteratorFlags {
109
j9mm_iterator_flag_none = 0,
110
j9mm_iterator_flag_include_holes = 1, /**< Indicates that holes (unused portions of the region) should be included in the object iterators */
111
j9mm_iterator_flag_include_arraylet_leaves = 2, /**< Indicates that arraylet leaf pointers should be included in the object ref iterators */
112
j9mm_iterator_flag_exclude_null_refs = 4, /**< Indicates that NULL pointers should be excluded in the object ref iterators */
113
j9mm_iterator_flag_regions_read_only = 8, /**< Indicates that it is read only request (no TLH flush and further heap walk) */
114
j9mm_iterator_flag_max = 0x1000000
115
} J9MM_IteratorFlags;
116
117
/**
118
* Descriptor declarations (what is handed to the user functions). None of the strings for identifiers are carved in stone.
119
* The structure and its contents are only guaranteed for the lifetime of the user function call.
120
*/
121
typedef struct J9MM_IterateHeapDescriptor {
122
const char *name; /**< Name of the Heap */
123
UDATA id; /**< Unique identifier */
124
} J9MM_IterateHeapDescriptor;
125
126
typedef struct J9MM_IterateSpaceDescriptor {
127
const char *name; /**< Name of the space */
128
UDATA id; /**< Unique identifier */
129
UDATA classPointerOffset; /**< Offset from the beginning of an object where the class pointer resides */
130
UDATA classPointerSize; /**< Size of the class pointer, in bytes */
131
UDATA fobjectPointerScale; /**< Multiplier for compressed pointer decompression */
132
UDATA fobjectPointerDisplacement; /**< Displacement to add for compressed pointer decompression */
133
UDATA fobjectSize; /**< sizeof(fj9object_t) */
134
void* memorySpace; /**< the memory space struct associated with this space, or NULL if none. This is temporary. */
135
} J9MM_IterateSpaceDescriptor;
136
137
typedef struct J9MM_IterateRegionDescriptor {
138
const char *name; /**< Name of the Heap */
139
UDATA id; /**< Unique identifier */
140
UDATA objectAlignment; /**< Object alignment for this region */
141
UDATA objectMinimumSize; /**< Object minimum size for this region */
142
const void *regionStart; /**< Address of the start of the region */
143
UDATA regionSize; /**< The size (in bytes) of the region */
144
} J9MM_IterateRegionDescriptor;
145
146
typedef struct J9MM_IterateObjectDescriptor {
147
UDATA id; /**< Unique identifier */
148
UDATA size; /**< Size in bytes that the object (or hole) consumes */
149
j9object_t object; /**< Pointer to the actual J9Object (or hole). This is temporary */
150
UDATA isObject; /**< TRUE if this is an object, or FALSE if it's a hole */
151
} J9MM_IterateObjectDescriptor;
152
153
typedef struct J9MM_IterateObjectRefDescriptor {
154
UDATA id; /**< Unique identifier */
155
j9object_t object; /**< Pointer to the actual j9object_t. If this value is modified it is stored back into the field once the callback returns */
156
const fj9object_t *fieldAddress; /**< The address of the field within the object */
157
J9MM_IteratorObjectRefType type; /**< The type of reference */
158
} J9MM_IterateObjectRefDescriptor;
159
160
typedef struct J9MM_HeapRootSlotDescriptor {
161
UDATA slotType; /**< Type of slot */
162
UDATA scanType; /**< What is being scanned, class or object */
163
UDATA slotReachability; /**< Reachability of slot */
164
} J9MM_HeapRootSlotDescriptor;
165
166
typedef jvmtiIterationControl (*rootIteratorCallBackFunc)(void* ptr, J9MM_HeapRootSlotDescriptor *rootDesc, void *userData);
167
168
/**
169
* Walk the roots within a heap, call user provided function
170
* @param flags The flags describing the walk (unused currently)
171
* @param func The function to call on each heap descriptor.
172
* @param userData Pointer to storage for userData.
173
*/
174
jvmtiIterationControl
175
j9mm_iterate_roots(J9JavaVM *javaVM, J9PortLibrary *portLibrary, UDATA flags, rootIteratorCallBackFunc callBackFunc, void *userData);
176
177
/**
178
* Walk all heaps, call user provided function.
179
*
180
* The caller must have VM access.
181
*
182
* This function may acquire locks during its execution to protect the list of heaps.
183
* These locks may be held while the callback function is executed.
184
*
185
* @param flags The flags describing the walk (unused currently)
186
* @param func The function to call on each heap descriptor.
187
* @param userData Pointer to storage for userData.
188
*/
189
jvmtiIterationControl
190
j9mm_iterate_heaps(J9JavaVM *vm, J9PortLibrary *portLibrary, UDATA flags, jvmtiIterationControl (*func)(J9JavaVM *vm, J9MM_IterateHeapDescriptor *heapDesc, void *userData), void *userData);
191
192
/**
193
* Walk all spaces contained in the heap, call user provided function.
194
*
195
* The caller must have VM access.
196
*
197
* This function may acquire locks during its execution to protect the list of spaces.
198
* These locks may be held while the callback function is executed.
199
*
200
* @param flags The flags describing the walk (unused currently)
201
* @param func The function to call on each heap descriptor.
202
* @param userData Pointer to storage for userData.
203
*/
204
jvmtiIterationControl
205
j9mm_iterate_spaces(J9JavaVM *vm, J9PortLibrary *portLibrary, J9MM_IterateHeapDescriptor *heap, UDATA flags, jvmtiIterationControl (*func)(J9JavaVM *vm, J9MM_IterateSpaceDescriptor *spaceDesc, void *userData), void *userData);
206
207
/**
208
* Walk all regions for the given space, call user provided function.
209
*
210
* The caller must have VM access.
211
*
212
* This function may acquire locks during its execution to protect the list of regions.
213
* These locks may be held while the callback function is executed.
214
*
215
* @param space The descriptor for the space that should be walked
216
* @param flags The flags describing the walk (unused currently)
217
* @param func The function to call on each region descriptor.
218
* @param userData Pointer to storage for userData.
219
*/
220
jvmtiIterationControl
221
j9mm_iterate_regions(J9JavaVM *vm, J9PortLibrary *portLibrary, J9MM_IterateSpaceDescriptor *space, UDATA flags, jvmtiIterationControl (*func)(J9JavaVM *vm, J9MM_IterateRegionDescriptor *regionDesc, void *userData), void *userData);
222
223
/**
224
* Walk all objects for the given region, call user provided function.
225
*
226
* The caller must have exclusive VM access.
227
*
228
* @param region The descriptor for the region that should be walked
229
* @param flags The flags describing the walk (0 or j9mm_iterator_flag_include_holes)
230
* @param func The function to call on each object descriptor.
231
* @param userData Pointer to storage for userData.
232
*/
233
jvmtiIterationControl
234
j9mm_iterate_region_objects(J9JavaVM *vm, J9PortLibrary *portLibrary, J9MM_IterateRegionDescriptor *region, UDATA flags, jvmtiIterationControl (*func)(J9JavaVM *vm, J9MM_IterateObjectDescriptor *objectDesc, void *userData), void *userData);
235
236
/**
237
* Walk all object slots for the given object, call user provided function.
238
* @param object The descriptor for the object that should be walked
239
* @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)
240
* @param func The function to call on each object descriptor.
241
* @param userData Pointer to storage for userData.
242
*/
243
jvmtiIterationControl
244
j9mm_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);
245
246
/**
247
* Initialize a descriptor for the specified object.
248
* This descriptor may subsequently be used with j9mm_iterate_object_slots or other iterator APIs.
249
*
250
* @return descriptor The descriptor to be initialized
251
* @param object The object to store into the descriptor
252
*/
253
void
254
j9mm_initialize_object_descriptor(J9JavaVM *javaVM, J9MM_IterateObjectDescriptor *descriptor, j9object_t object);
255
256
/**
257
* Walk all objects for the given VM, call user provided function.
258
* @param flags The flags describing the walk (0 or j9mm_iterator_flag_include_holes)
259
* @param func The function to call on each object descriptor.
260
* @param userData Pointer to storage for userData.
261
*/
262
jvmtiIterationControl
263
j9mm_iterate_all_objects(J9JavaVM *vn, J9PortLibrary *portLibrary, UDATA flags, jvmtiIterationControl (*func)(J9JavaVM *vm, J9MM_IterateObjectDescriptor *object, void *userData), void *userData);
264
265
/**
266
* Walk all ownable synchronizer object, call user provided function.
267
* @param flags The flags describing the walk (unused currently)
268
* @param func The function to call on each object descriptor.
269
* @param userData Pointer to storage for userData.
270
* @return return 0 on successfully iterating entire list, return user provided function call if it did not return JVMTI_ITERATION_CONTINUE
271
*/
272
jvmtiIterationControl
273
j9mm_iterate_all_ownable_synchronizer_objects(J9VMThread *vmThread, J9PortLibrary *portLibrary, UDATA flags, jvmtiIterationControl (*func)(J9VMThread *vmThread, J9MM_IterateObjectDescriptor *object, void *userData), void *userData);
274
275
/**
276
* Shortcut specific for Segregated heap to find the page the pointer belongs to
277
* This is instead of iterating pages, which may be very time consuming.
278
* @param objectDescriptor Structure containing pointer to an object
279
* @param regionDesc Out parameter initialized by the method if the region is found
280
*/
281
UDATA
282
j9mm_find_region_for_pointer(J9JavaVM* javaVM, void *pointer, J9MM_IterateRegionDescriptor *regionDesc);
283
284
/**
285
* Convert the memory that is currently represented as an object to dark matter.
286
* This routine is typically used by GC tools such as gccheck and tgc to ensure that only valid (i.e. reachable)
287
* objects remain on the heap after a sweep. A 'dead' object may contain dangling references to heap addresses
288
* which no longer contain walkable objects. The problem is solved by converting the invalid objects to dark matter.
289
*
290
* @param[in] javaVM the JavaVM
291
* @param[in] region the region in which the object exists
292
* @param[in] objectDesc the object to be abandoned
293
* @return 0 on success, non-0 on failure.
294
*/
295
UDATA
296
j9mm_abandon_object(J9JavaVM *javaVM, J9MM_IterateRegionDescriptor *region, J9MM_IterateObjectDescriptor *objectDesc);
297
298
#ifdef __cplusplus
299
} /* extern "C" { */
300
#endif /* __cplusplus */
301
302
#endif /* HEAPITERATORAPI_H_ */
303
304