Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_structs/ClassLoaderClassesIterator.cpp
5990 views
1
2
/*******************************************************************************
3
* Copyright (c) 1991, 2021 IBM Corp. and others
4
*
5
* This program and the accompanying materials are made available under
6
* the terms of the Eclipse Public License 2.0 which accompanies this
7
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
8
* or the Apache License, Version 2.0 which accompanies this distribution and
9
* is available at https://www.apache.org/licenses/LICENSE-2.0.
10
*
11
* This Source Code may also be made available under the following
12
* Secondary Licenses when the conditions for such availability set
13
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
14
* General Public License, version 2 with the GNU Classpath
15
* Exception [1] and GNU General Public License, version 2 with the
16
* OpenJDK Assembly Exception [2].
17
*
18
* [1] https://www.gnu.org/software/classpath/license.html
19
* [2] http://openjdk.java.net/legal/assembly-exception.html
20
*
21
* 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
22
*******************************************************************************/
23
24
/**
25
* @file
26
* @ingroup GC_Structs
27
*/
28
29
#include "ClassLoaderClassesIterator.hpp"
30
31
#include "GCExtensionsBase.hpp"
32
33
GC_ClassLoaderClassesIterator::GC_ClassLoaderClassesIterator(MM_GCExtensionsBase *extensions, J9ClassLoader *classLoader) :
34
_javaVM((J9JavaVM* )extensions->getOmrVM()->_language_vm)
35
,_classLoader(classLoader)
36
,_vmSegmentIterator(classLoader, MEMORY_TYPE_RAM_CLASS)
37
,_vmClassSlotIterator((J9JavaVM* )extensions->getOmrVM()->_language_vm)
38
,_mode(TABLE_CLASSES)
39
{
40
41
if ((classLoader->flags & J9CLASSLOADER_ANON_CLASS_LOADER) != 0) {
42
_mode = ANONYMOUS_CLASSES;
43
}
44
_nextClass = firstClass();
45
}
46
47
J9Class *
48
GC_ClassLoaderClassesIterator::nextSystemClass()
49
{
50
return _vmClassSlotIterator.nextSlot();
51
}
52
53
J9Class *
54
GC_ClassLoaderClassesIterator::firstClass()
55
{
56
J9Class * result;
57
if (ANONYMOUS_CLASSES == _mode) {
58
result = nextAnonymousClass();
59
} else {
60
result = _javaVM->internalVMFunctions->hashClassTableStartDo(_classLoader, &_walkState, 0);
61
if ( (NULL == result) && switchToSystemMode() ) {
62
result = nextSystemClass();
63
}
64
}
65
return result;
66
}
67
68
J9Class *
69
GC_ClassLoaderClassesIterator::nextAnonymousClass()
70
{
71
J9Class * result = NULL;
72
J9MemorySegment *segment;
73
if (NULL != (segment = _vmSegmentIterator.nextSegment())) {
74
GC_ClassHeapIterator classHeapIterator(_javaVM, segment);
75
result = classHeapIterator.nextClass();
76
}
77
return result;
78
}
79
80
81
J9Class *
82
GC_ClassLoaderClassesIterator::nextTableClass()
83
{
84
J9Class * result = _javaVM->internalVMFunctions->hashClassTableNextDo(&_walkState);
85
if ( (NULL == result) && switchToSystemMode() ) {
86
result = nextSystemClass();
87
}
88
return result;
89
}
90
91
92
bool
93
GC_ClassLoaderClassesIterator::switchToSystemMode()
94
{
95
bool isSystemClassLoader = (_classLoader == _javaVM->systemClassLoader);
96
if (isSystemClassLoader) {
97
_mode = SYSTEM_CLASSES;
98
}
99
return isSystemClassLoader;
100
}
101
102
J9Class *
103
GC_ClassLoaderClassesIterator::nextClass()
104
{
105
J9Class * result = _nextClass;
106
107
if (NULL != result) {
108
if (ANONYMOUS_CLASSES == _mode) {
109
_nextClass = nextAnonymousClass();
110
} else {
111
if ( (result->classLoader == _classLoader) && (NULL != result->arrayClass) ) {
112
/* this class is defined in the loader, so follow its array classes */
113
_nextClass = result->arrayClass;
114
} else if (TABLE_CLASSES == _mode) {
115
_nextClass = nextTableClass();
116
} else {
117
_nextClass = nextSystemClass();
118
}
119
}
120
}
121
122
return result;
123
}
124
125