Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/runtime/javaCalls.hpp
32285 views
1
/*
2
* Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*
23
*/
24
25
#ifndef SHARE_VM_RUNTIME_JAVACALLS_HPP
26
#define SHARE_VM_RUNTIME_JAVACALLS_HPP
27
28
#include "memory/allocation.hpp"
29
#include "oops/method.hpp"
30
#include "runtime/handles.hpp"
31
#include "runtime/javaFrameAnchor.hpp"
32
#include "runtime/thread.inline.hpp"
33
#include "runtime/vmThread.hpp"
34
#ifdef TARGET_ARCH_x86
35
# include "jniTypes_x86.hpp"
36
#endif
37
#ifdef TARGET_ARCH_aarch32
38
# include "jniTypes_aarch32.hpp"
39
#endif
40
#ifdef TARGET_ARCH_aarch64
41
# include "jniTypes_aarch64.hpp"
42
#endif
43
#ifdef TARGET_ARCH_sparc
44
# include "jniTypes_sparc.hpp"
45
#endif
46
#ifdef TARGET_ARCH_zero
47
# include "jniTypes_zero.hpp"
48
#endif
49
#ifdef TARGET_ARCH_arm
50
# include "jniTypes_arm.hpp"
51
#endif
52
#ifdef TARGET_ARCH_ppc
53
# include "jniTypes_ppc.hpp"
54
#endif
55
56
// A JavaCallWrapper is constructed before each JavaCall and destructed after the call.
57
// Its purpose is to allocate/deallocate a new handle block and to save/restore the last
58
// Java fp/sp. A pointer to the JavaCallWrapper is stored on the stack.
59
60
class JavaCallWrapper: StackObj {
61
friend class VMStructs;
62
private:
63
JavaThread* _thread; // the thread to which this call belongs
64
JNIHandleBlock* _handles; // the saved handle block
65
Method* _callee_method; // to be able to collect arguments if entry frame is top frame
66
oop _receiver; // the receiver of the call (if a non-static call)
67
68
JavaFrameAnchor _anchor; // last thread anchor state that we must restore
69
70
JavaValue* _result; // result value
71
72
public:
73
// Construction/destruction
74
JavaCallWrapper(methodHandle callee_method, Handle receiver, JavaValue* result, TRAPS);
75
~JavaCallWrapper();
76
77
// Accessors
78
JavaThread* thread() const { return _thread; }
79
JNIHandleBlock* handles() const { return _handles; }
80
81
JavaFrameAnchor* anchor(void) { return &_anchor; }
82
83
JavaValue* result() const { return _result; }
84
// GC support
85
Method* callee_method() { return _callee_method; }
86
oop receiver() { return _receiver; }
87
void oops_do(OopClosure* f);
88
89
bool is_first_frame() const { return _anchor.last_Java_sp() == NULL; }
90
91
};
92
93
94
// Encapsulates arguments to a JavaCall (faster, safer, and more convenient than using var-args)
95
class JavaCallArguments : public StackObj {
96
private:
97
enum Constants {
98
_default_size = 8 // Must be at least # of arguments in JavaCalls methods
99
};
100
101
intptr_t _value_buffer [_default_size + 1];
102
u_char _value_state_buffer[_default_size + 1];
103
104
intptr_t* _value;
105
u_char* _value_state;
106
int _size;
107
int _max_size;
108
bool _start_at_zero; // Support late setting of receiver
109
110
void initialize() {
111
// Starts at first element to support set_receiver.
112
_value = &_value_buffer[1];
113
_value_state = &_value_state_buffer[1];
114
115
_max_size = _default_size;
116
_size = 0;
117
_start_at_zero = false;
118
}
119
120
// Helper for push_oop and the like. The value argument is a
121
// "handle" that refers to an oop. We record the address of the
122
// handle rather than the designated oop. The handle is later
123
// resolved to the oop by parameters(). This delays the exposure of
124
// naked oops until it is GC-safe.
125
template<typename T>
126
inline int push_oop_impl(T handle, int size) {
127
// JNITypes::put_obj expects an oop value, so we play fast and
128
// loose with the type system. The cast from handle type to oop
129
// *must* use a C-style cast. In a product build it performs a
130
// reinterpret_cast. In a debug build (more accurately, in a
131
// CHECK_UNHANDLED_OOPS build) it performs a static_cast, invoking
132
// the debug-only oop class's conversion from void* constructor.
133
JNITypes::put_obj((oop)handle, _value, size); // Updates size.
134
return size; // Return the updated size.
135
}
136
137
public:
138
JavaCallArguments() { initialize(); }
139
140
JavaCallArguments(Handle receiver) {
141
initialize();
142
push_oop(receiver);
143
}
144
145
JavaCallArguments(int max_size) {
146
if (max_size > _default_size) {
147
_value = NEW_RESOURCE_ARRAY(intptr_t, max_size + 1);
148
_value_state = NEW_RESOURCE_ARRAY(u_char, max_size + 1);
149
150
// Reserve room for potential receiver in value and state
151
_value++;
152
_value_state++;
153
154
_max_size = max_size;
155
_size = 0;
156
_start_at_zero = false;
157
} else {
158
initialize();
159
}
160
}
161
162
// The possible values for _value_state elements.
163
enum {
164
value_state_primitive,
165
value_state_oop,
166
value_state_handle,
167
value_state_jobject,
168
value_state_limit
169
};
170
171
inline void push_oop(Handle h) {
172
_value_state[_size] = value_state_handle;
173
_size = push_oop_impl(h.raw_value(), _size);
174
}
175
176
inline void push_jobject(jobject h) {
177
_value_state[_size] = value_state_jobject;
178
_size = push_oop_impl(h, _size);
179
}
180
181
inline void push_int(int i) {
182
_value_state[_size] = value_state_primitive;
183
JNITypes::put_int(i, _value, _size);
184
}
185
186
inline void push_double(double d) {
187
_value_state[_size] = value_state_primitive;
188
_value_state[_size + 1] = value_state_primitive;
189
JNITypes::put_double(d, _value, _size);
190
}
191
192
inline void push_long(jlong l) {
193
_value_state[_size] = value_state_primitive;
194
_value_state[_size + 1] = value_state_primitive;
195
JNITypes::put_long(l, _value, _size);
196
}
197
198
inline void push_float(float f) {
199
_value_state[_size] = value_state_primitive;
200
JNITypes::put_float(f, _value, _size);
201
}
202
203
// receiver
204
Handle receiver() {
205
assert(_size > 0, "must at least be one argument");
206
assert(_value_state[0] == value_state_handle,
207
"first argument must be an oop");
208
assert(_value[0] != 0, "receiver must be not-null");
209
return Handle((oop*)_value[0], false);
210
}
211
212
void set_receiver(Handle h) {
213
assert(_start_at_zero == false, "can only be called once");
214
_start_at_zero = true;
215
_value_state--;
216
_value--;
217
_size++;
218
_value_state[0] = value_state_handle;
219
push_oop_impl(h.raw_value(), 0);
220
}
221
222
// Converts all Handles to oops, and returns a reference to parameter vector
223
intptr_t* parameters() ;
224
int size_of_parameters() const { return _size; }
225
226
// Verify that pushed arguments fits a given method
227
void verify(methodHandle method, BasicType return_type);
228
};
229
230
// All calls to Java have to go via JavaCalls. Sets up the stack frame
231
// and makes sure that the last_Java_frame pointers are chained correctly.
232
//
233
234
class JavaCalls: AllStatic {
235
static void call_helper(JavaValue* result, methodHandle* method, JavaCallArguments* args, TRAPS);
236
public:
237
// Optimized Constuctor call
238
static void call_default_constructor(JavaThread* thread, methodHandle method, Handle receiver, TRAPS);
239
240
// call_special
241
// ------------
242
// The receiver must be first oop in argument list
243
static void call_special(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS);
244
245
static void call_special(JavaValue* result, Handle receiver, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS); // No args
246
static void call_special(JavaValue* result, Handle receiver, KlassHandle klass, Symbol* name, Symbol* signature, Handle arg1, TRAPS);
247
static void call_special(JavaValue* result, Handle receiver, KlassHandle klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, TRAPS);
248
249
// virtual call
250
// ------------
251
252
// The receiver must be first oop in argument list
253
static void call_virtual(JavaValue* result, KlassHandle spec_klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS);
254
255
static void call_virtual(JavaValue* result, Handle receiver, KlassHandle spec_klass, Symbol* name, Symbol* signature, TRAPS); // No args
256
static void call_virtual(JavaValue* result, Handle receiver, KlassHandle spec_klass, Symbol* name, Symbol* signature, Handle arg1, TRAPS);
257
static void call_virtual(JavaValue* result, Handle receiver, KlassHandle spec_klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, TRAPS);
258
259
// Static call
260
// -----------
261
static void call_static(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS);
262
263
static void call_static(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS);
264
static void call_static(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, Handle arg1, TRAPS);
265
static void call_static(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, TRAPS);
266
267
// Low-level interface
268
static void call(JavaValue* result, methodHandle method, JavaCallArguments* args, TRAPS);
269
};
270
271
#endif // SHARE_VM_RUNTIME_JAVACALLS_HPP
272
273