Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/compiler/aarch64/codegen/ARM64JNILinkage.hpp
6004 views
1
/*******************************************************************************
2
* Copyright (c) 2019, 2021 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
#ifndef ARM64_JNILINKAGE_INCL
24
#define ARM64_JNILINKAGE_INCL
25
26
#include "codegen/ARM64PrivateLinkage.hpp"
27
#include "codegen/Register.hpp"
28
29
namespace J9
30
{
31
32
namespace ARM64
33
{
34
35
class JNILinkage : public PrivateLinkage
36
{
37
public:
38
39
JNILinkage(TR::CodeGenerator *cg);
40
41
/**
42
* @brief Builds method arguments
43
* @param[in] callNode : caller node
44
* @param[in] dependencies : register dependency conditions
45
* @return size of arguments
46
*/
47
virtual int32_t buildArgs(
48
TR::Node *callNode,
49
TR::RegisterDependencyConditions *dependencies);
50
51
/**
52
* @brief Builds direct dispatch to method
53
* @param[in] callNode : caller node
54
* @return register holding return value
55
*/
56
virtual TR::Register *buildDirectDispatch(TR::Node *callNode);
57
58
/**
59
* @brief Builds indirect dispatch to method
60
* @param[in] callNode : caller node
61
* @return register holding return value
62
*/
63
virtual TR::Register *buildIndirectDispatch(TR::Node *callNode);
64
65
/**
66
* @brief Builds virtual dispatch to method
67
* @param[in] callNode : caller node
68
* @param[in] dependencies : register dependency conditions
69
* @param[in] argSize : size of arguments
70
*/
71
virtual void buildVirtualDispatch(
72
TR::Node *callNode,
73
TR::RegisterDependencyConditions *dependencies,
74
uint32_t argSize);
75
76
private:
77
78
/**
79
* @brief Releases VM access before calling into JNI method
80
* @param[in] callNode : caller node
81
* @param[in] vmThreadReg : vm thread register
82
* @param[in] scratchReg0 : scratch register
83
* @param[in] scratchReg1 : scratch register
84
* @param[in] scratchReg2 : scratch register
85
* @param[in] scratchReg3 : scratch register
86
*/
87
void releaseVMAccess(TR::Node *callNode, TR::Register *vmThreadReg, TR::Register *scratchReg0, TR::Register *scratchReg1, TR::Register *scratchReg2, TR::Register *scratchReg3);
88
89
/**
90
* @brief Acquires VM access after returned from JNI method
91
* @param[in] callNode : caller node
92
* @param[in] vmThreadReg : vm thread register
93
* @param[in] scratchReg0 : scratch register
94
* @param[in] scratchReg1 : scratch register
95
* @param[in] scratchReg2 : scratch register
96
*/
97
void acquireVMAccess(TR::Node *callNode, TR::Register *vmThreadReg, TR::Register *scratchReg0, TR::Register *scratchReg1, TR::Register *scratchReg2);
98
99
#ifdef J9VM_INTERP_ATOMIC_FREE_JNI
100
/**
101
* @brief Releases VM access in a way described in OpenJ9 issue 2576
102
* @param[in] callNode : caller Node
103
* @param[in] vmThreadReg : vm thread register
104
* @param[in] scratchReg0 : scratch register
105
* @param[in] scratchReg1 : scratch register
106
*/
107
void releaseVMAccessAtomicFree(TR::Node *callNode, TR::Register *vmThreadReg, TR::Register *scratchReg0, TR::Register *scratchReg1);
108
109
/**
110
* @brief Acquires VM access in a way described in OpenJ9 issue 2576
111
* @param[in] callNode : caller Node
112
* @param[in] vmThreadReg : vm thread register
113
* @param[in] scratchReg0 : scratch register
114
* @param[in] zeroReg : zero register */
115
void acquireVMAccessAtomicFree(TR::Node *callNode, TR::Register *vmThreadReg, TR::Register *scratchReg0, TR::Register *zeroReg);
116
#endif /* J9VM_INTERP_ATOMIC_FREE_JNI */
117
118
/**
119
* @brief Builds JNI call out frame
120
* @param[in] callNode : caller node
121
* @param[in] isWrapperForJNI : true if the current method is simply a wrapper for the JNI call
122
* @param[in] returnAddrLabel : label symbol of return address from JNI method
123
* @param[in] vmThreadReg : vm thread register
124
* @param[in] javaStackReg : java stack register
125
* @param[in] scratchReg0 : scratch register
126
* @param[in] scratchReg1 : scratch register
127
*/
128
void buildJNICallOutFrame(TR::Node *callNode, bool isWrapperForJNI,
129
TR::LabelSymbol *returnAddrLabel, TR::Register *vmThreadReg,
130
TR::Register *javaStackReg, TR::Register *scratchReg0, TR::Register *scratchReg1);
131
132
/**
133
* @brief Restores JNI call out frame
134
* @param[in] callNode : caller node
135
* @param[in] tearDownJNIFrame : true if we need to clean up ref pool
136
* @param[in] vmThreadReg : vm thread register
137
* @param[in] javaStackReg : java stack register
138
* @param[in] scratchReg : scratch register
139
*/
140
void restoreJNICallOutFrame(TR::Node *callNode, bool tearDownJNIFrame, TR::Register *vmThreadReg, TR::Register *javaStackReg, TR::Register *scratchReg);
141
142
/**
143
* @brief Builds JNI method arguments
144
* @param[in] callNode : caller node
145
* @param[in] deps : register dependency conditions
146
* @param[in] passThread : true if we need to pass vm thread as first parameter
147
* @param[in] passReceiver : true if we need to pass receiver to the JNI method
148
* @param[in] killNonVolatileGPRs : true if we need to kill non-volatile GPRs
149
* @return the total size in bytes allocated on stack for parameter passing
150
*/
151
size_t buildJNIArgs(TR::Node *callNode, TR::RegisterDependencyConditions *deps, bool passThread, bool passReceiver, bool killNonVolatileGPRs);
152
153
/**
154
* @brief Returns register holding resturn value
155
* @param[in] callNode : caller node
156
* @param[in] deps : register dependency conditions
157
* @return register holding return value. Null if return type is void.
158
*/
159
TR::Register *getReturnRegisterFromDeps(TR::Node *callNode, TR::RegisterDependencyConditions *deps);
160
161
/**
162
* @brief Pushes a JNI reference argument
163
* @param[in] child : argument node
164
* @return register holding argument
165
*/
166
TR::Register *pushJNIReferenceArg(TR::Node *child);
167
168
/**
169
* @brief Generates a JNI method dispatch instructions
170
* @param[in] callNode : caller node
171
* @param[in] isJNIGCPoint : true if the JNI method dispatch is GC point
172
* @param[in] deps : register dependency conditions
173
* @param[in] targetAddress : address of JNI method
174
* @param[in] scratchReg : scratch register
175
* @return instruction of method dispatch
176
*/
177
TR::Instruction *generateMethodDispatch(TR::Node *callNode, bool isJNIGCPoint, TR::RegisterDependencyConditions *deps, uintptr_t targetAddress, TR::Register *scratchReg);
178
179
/**
180
* @brief Adjusts return value to java semantics
181
* @param[in] callNode : caller node
182
* @param[in] wrapRefs : true if the reference is wrapped
183
* @param[in] returnRegister : register that holds return value
184
*/
185
void adjustReturnValue(TR::Node *callNode, bool wrapRefs, TR::Register *returnRegister);
186
187
/**
188
* @brief Throws exception if it is set in JNI method
189
* @param[in] callNode : caller node
190
* @param[in] vmThreadReg : vm thread register
191
* @param[in] scratchReg : scratch register
192
*/
193
void checkForJNIExceptions(TR::Node *callNode, TR::Register *vmThreadReg, TR::Register *scratchReg);
194
195
TR::Linkage *_systemLinkage;
196
197
198
199
};
200
201
}
202
203
}
204
205
#endif
206
207