Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_glue_java/ObjectModel.cpp
5990 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
#include <string.h>
24
25
#include "ObjectModel.hpp"
26
#include "GCExtensionsBase.hpp"
27
#include "ModronAssertions.h"
28
29
bool
30
GC_ObjectModel::initialize(MM_GCExtensionsBase *extensions)
31
{
32
bool result = true;
33
_javaVM = (J9JavaVM *)extensions->getOmrVM()->_language_vm;
34
35
_mixedObjectModel = &(extensions->mixedObjectModel);
36
_indexableObjectModel = &(extensions->indexableObjectModel);
37
38
#if defined(OMR_GC_COMPRESSED_POINTERS) && defined(OMR_GC_FULL_POINTERS)
39
getObjectModelDelegate()->setCompressObjectReferences(extensions->compressObjectReferences());
40
#endif /* defined(OMR_GC_COMPRESSED_POINTERS) && defined(OMR_GC_FULL_POINTERS) */
41
getObjectModelDelegate()->setMixedObjectModel(_mixedObjectModel);
42
getObjectModelDelegate()->setArrayObjectModel(_indexableObjectModel);
43
44
_classClass = NULL;
45
_classLoaderClass = NULL;
46
_atomicMarkableReferenceClass = NULL;
47
48
J9HookInterface **vmHookInterface = _javaVM->internalVMFunctions->getVMHookInterface(_javaVM);
49
if (NULL == vmHookInterface) {
50
result = false;
51
} else if ((*vmHookInterface)->J9HookRegisterWithCallSite(vmHookInterface, J9HOOK_VM_INTERNAL_CLASS_LOAD, internalClassLoadHook, OMR_GET_CALLSITE(), this)) {
52
result = false;
53
} else if ((*vmHookInterface)->J9HookRegisterWithCallSite(vmHookInterface, J9HOOK_VM_CLASSES_REDEFINED, classesRedefinedHook, OMR_GET_CALLSITE(), this)) {
54
result = false;
55
}
56
57
return result;
58
}
59
60
void
61
GC_ObjectModel::tearDown(MM_GCExtensionsBase *extensions)
62
{
63
J9HookInterface **vmHookInterface = _javaVM->internalVMFunctions->getVMHookInterface(_javaVM);
64
if (NULL != vmHookInterface) {
65
(*vmHookInterface)->J9HookUnregister(vmHookInterface, J9HOOK_VM_INTERNAL_CLASS_LOAD, internalClassLoadHook, this);
66
(*vmHookInterface)->J9HookUnregister(vmHookInterface, J9HOOK_VM_CLASSES_REDEFINED, classesRedefinedHook, this);
67
}
68
}
69
70
GC_ObjectModel::ScanType
71
GC_ObjectModel::getSpecialClassScanType(J9Class *objectClazz)
72
{
73
ScanType result = SCAN_MIXED_OBJECT;
74
75
/*
76
* check if the object is an instance of or an instance or subclass of one of the SPECIAL classes.
77
* Note that these could still be uninitialized objects (no corresponding VM structs)
78
*/
79
if (objectClazz == _classClass) {
80
/* no need to check subclasses of java.lang.Class, since it's final */
81
result = SCAN_CLASS_OBJECT;
82
} else if ((NULL != _classLoaderClass) && isSameOrSuperClassOf(_classLoaderClass, objectClazz)) {
83
result = SCAN_CLASSLOADER_OBJECT;
84
} else if ((NULL != _atomicMarkableReferenceClass) && isSameOrSuperClassOf(_atomicMarkableReferenceClass, objectClazz)) {
85
result = SCAN_ATOMIC_MARKABLE_REFERENCE_OBJECT;
86
} else {
87
/* some unrecognized special class? */
88
result = SCAN_INVALID_OBJECT;
89
}
90
91
return result;
92
}
93
94
void
95
GC_ObjectModel::internalClassLoadHook(J9HookInterface** hook, UDATA eventNum, void* eventData, void* userData)
96
{
97
J9VMInternalClassLoadEvent *classLoadEvent = (J9VMInternalClassLoadEvent*)eventData;
98
GC_ObjectModel *objectModel = (GC_ObjectModel*)userData;
99
J9VMThread *vmThread = classLoadEvent->currentThread;
100
J9Class *clazz = classLoadEvent->clazz;
101
102
/* we're only interested in bootstrap classes */
103
if (clazz->classLoader == vmThread->javaVM->systemClassLoader) {
104
J9ROMClass *romClass = clazz->romClass;
105
J9UTF8* className = J9ROMCLASS_CLASSNAME(romClass);
106
107
const char * const atomicMarkableReference = "java/util/concurrent/atomic/AtomicMarkableReference";
108
const char * const javaLangClassLoader = "java/lang/ClassLoader";
109
const char * const javaLangClass = "java/lang/Class";
110
const char * const abstractOwnableSynchronizer = "java/util/concurrent/locks/AbstractOwnableSynchronizer";
111
112
if (0 == compareUTF8Length(J9UTF8_DATA(className), J9UTF8_LENGTH(className), (U_8*)atomicMarkableReference, strlen(atomicMarkableReference))) {
113
clazz->classDepthAndFlags |= J9AccClassGCSpecial;
114
objectModel->_atomicMarkableReferenceClass = clazz;
115
} else if (0 == compareUTF8Length(J9UTF8_DATA(className), J9UTF8_LENGTH(className), (U_8*)javaLangClassLoader, strlen(javaLangClassLoader))) {
116
clazz->classDepthAndFlags |= J9AccClassGCSpecial;
117
objectModel->_classLoaderClass = clazz;
118
} else if (0 == compareUTF8Length(J9UTF8_DATA(className), J9UTF8_LENGTH(className), (U_8*)javaLangClass, strlen(javaLangClass))) {
119
clazz->classDepthAndFlags |= J9AccClassGCSpecial;
120
objectModel->_classClass = clazz;
121
} else if (0 == compareUTF8Length(J9UTF8_DATA(className), J9UTF8_LENGTH(className), (U_8*)abstractOwnableSynchronizer, strlen(abstractOwnableSynchronizer))) {
122
clazz->classDepthAndFlags |= J9AccClassOwnableSynchronizer;
123
}
124
}
125
}
126
127
void
128
GC_ObjectModel::classesRedefinedHook(J9HookInterface** hook, UDATA eventNum, void* eventData, void* userData)
129
{
130
GC_ObjectModel *objectModel = (GC_ObjectModel*)userData;
131
132
/* update all J9Class pointers to their most current version */
133
if (NULL != objectModel->_atomicMarkableReferenceClass) {
134
objectModel->_atomicMarkableReferenceClass = J9_CURRENT_CLASS(objectModel->_atomicMarkableReferenceClass);
135
}
136
if (NULL != objectModel->_classLoaderClass) {
137
objectModel->_classLoaderClass = J9_CURRENT_CLASS(objectModel->_classLoaderClass);
138
}
139
if (NULL != objectModel->_classClass) {
140
objectModel->_classClass = J9_CURRENT_CLASS(objectModel->_classClass);
141
}
142
}
143
144
145
146