author | never |
Wed, 25 Jan 2017 19:18:43 -0800 | |
changeset 43484 | 9c95dd31d0da |
parent 42307 | cefc81dc1d52 |
child 43964 | 2f5e556a6037 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
40010 | 2 |
* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5419
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5419
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5419
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#ifndef SHARE_VM_RUNTIME_JAVACALLS_HPP |
26 |
#define SHARE_VM_RUNTIME_JAVACALLS_HPP |
|
27 |
||
28 |
#include "memory/allocation.hpp" |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
10565
diff
changeset
|
29 |
#include "oops/method.hpp" |
7397 | 30 |
#include "runtime/handles.hpp" |
31 |
#include "runtime/javaFrameAnchor.hpp" |
|
37456 | 32 |
#include "runtime/thread.hpp" |
7397 | 33 |
#include "runtime/vmThread.hpp" |
40010 | 34 |
#include "utilities/macros.hpp" |
35 |
||
36 |
#include CPU_HEADER(jniTypes) |
|
7397 | 37 |
|
1 | 38 |
// A JavaCallWrapper is constructed before each JavaCall and destructed after the call. |
39 |
// Its purpose is to allocate/deallocate a new handle block and to save/restore the last |
|
40 |
// Java fp/sp. A pointer to the JavaCallWrapper is stored on the stack. |
|
41 |
||
42 |
class JavaCallWrapper: StackObj { |
|
43 |
friend class VMStructs; |
|
44 |
private: |
|
45 |
JavaThread* _thread; // the thread to which this call belongs |
|
46 |
JNIHandleBlock* _handles; // the saved handle block |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
10565
diff
changeset
|
47 |
Method* _callee_method; // to be able to collect arguments if entry frame is top frame |
1 | 48 |
oop _receiver; // the receiver of the call (if a non-static call) |
49 |
||
50 |
JavaFrameAnchor _anchor; // last thread anchor state that we must restore |
|
51 |
||
52 |
JavaValue* _result; // result value |
|
53 |
||
54 |
public: |
|
55 |
// Construction/destruction |
|
56 |
JavaCallWrapper(methodHandle callee_method, Handle receiver, JavaValue* result, TRAPS); |
|
57 |
~JavaCallWrapper(); |
|
58 |
||
59 |
// Accessors |
|
60 |
JavaThread* thread() const { return _thread; } |
|
61 |
JNIHandleBlock* handles() const { return _handles; } |
|
62 |
||
63 |
JavaFrameAnchor* anchor(void) { return &_anchor; } |
|
64 |
||
65 |
JavaValue* result() const { return _result; } |
|
66 |
// GC support |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
10565
diff
changeset
|
67 |
Method* callee_method() { return _callee_method; } |
1 | 68 |
oop receiver() { return _receiver; } |
69 |
void oops_do(OopClosure* f); |
|
70 |
||
18938
ff8f8cec9434
8016131: nsk/sysdict/vm/stress/chain tests crash the VM in 'entry_frame_is_first()'
rbackman
parents:
14583
diff
changeset
|
71 |
bool is_first_frame() const { return _anchor.last_Java_sp() == NULL; } |
ff8f8cec9434
8016131: nsk/sysdict/vm/stress/chain tests crash the VM in 'entry_frame_is_first()'
rbackman
parents:
14583
diff
changeset
|
72 |
|
1 | 73 |
}; |
74 |
||
75 |
||
76 |
// Encapsulates arguments to a JavaCall (faster, safer, and more convenient than using var-args) |
|
77 |
class JavaCallArguments : public StackObj { |
|
78 |
private: |
|
79 |
enum Constants { |
|
80 |
_default_size = 8 // Must be at least # of arguments in JavaCalls methods |
|
81 |
}; |
|
82 |
||
83 |
intptr_t _value_buffer [_default_size + 1]; |
|
84 |
bool _is_oop_buffer[_default_size + 1]; |
|
85 |
||
86 |
intptr_t* _value; |
|
87 |
bool* _is_oop; |
|
88 |
int _size; |
|
89 |
int _max_size; |
|
90 |
bool _start_at_zero; // Support late setting of receiver |
|
33160
c59f1676d27e
8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
29180
diff
changeset
|
91 |
JVMCI_ONLY(nmethod* _alternative_target;) // Nmethod that should be called instead of normal target |
1 | 92 |
|
93 |
void initialize() { |
|
94 |
// Starts at first element to support set_receiver. |
|
95 |
_value = &_value_buffer[1]; |
|
96 |
_is_oop = &_is_oop_buffer[1]; |
|
97 |
||
98 |
_max_size = _default_size; |
|
99 |
_size = 0; |
|
100 |
_start_at_zero = false; |
|
33160
c59f1676d27e
8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
29180
diff
changeset
|
101 |
JVMCI_ONLY(_alternative_target = NULL;) |
1 | 102 |
} |
103 |
||
104 |
public: |
|
105 |
JavaCallArguments() { initialize(); } |
|
106 |
||
107 |
JavaCallArguments(Handle receiver) { |
|
108 |
initialize(); |
|
109 |
push_oop(receiver); |
|
110 |
} |
|
111 |
||
112 |
JavaCallArguments(int max_size) { |
|
113 |
if (max_size > _default_size) { |
|
114 |
_value = NEW_RESOURCE_ARRAY(intptr_t, max_size + 1); |
|
115 |
_is_oop = NEW_RESOURCE_ARRAY(bool, max_size + 1); |
|
5419 | 116 |
|
1 | 117 |
// Reserve room for potential receiver in value and is_oop |
118 |
_value++; _is_oop++; |
|
5419 | 119 |
|
1 | 120 |
_max_size = max_size; |
121 |
_size = 0; |
|
122 |
_start_at_zero = false; |
|
33160
c59f1676d27e
8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
29180
diff
changeset
|
123 |
JVMCI_ONLY(_alternative_target = NULL;) |
1 | 124 |
} else { |
125 |
initialize(); |
|
126 |
} |
|
127 |
} |
|
128 |
||
33160
c59f1676d27e
8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
29180
diff
changeset
|
129 |
#if INCLUDE_JVMCI |
c59f1676d27e
8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
29180
diff
changeset
|
130 |
void set_alternative_target(nmethod* target) { |
c59f1676d27e
8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
29180
diff
changeset
|
131 |
_alternative_target = target; |
c59f1676d27e
8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
29180
diff
changeset
|
132 |
} |
c59f1676d27e
8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
29180
diff
changeset
|
133 |
|
c59f1676d27e
8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
29180
diff
changeset
|
134 |
nmethod* alternative_target() { |
c59f1676d27e
8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
29180
diff
changeset
|
135 |
return _alternative_target; |
c59f1676d27e
8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
29180
diff
changeset
|
136 |
} |
c59f1676d27e
8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
29180
diff
changeset
|
137 |
#endif |
c59f1676d27e
8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
29180
diff
changeset
|
138 |
|
1 | 139 |
inline void push_oop(Handle h) { _is_oop[_size] = true; |
140 |
JNITypes::put_obj((oop)h.raw_value(), _value, _size); } |
|
141 |
||
142 |
inline void push_int(int i) { _is_oop[_size] = false; |
|
143 |
JNITypes::put_int(i, _value, _size); } |
|
144 |
||
145 |
inline void push_double(double d) { _is_oop[_size] = false; _is_oop[_size + 1] = false; |
|
146 |
JNITypes::put_double(d, _value, _size); } |
|
147 |
||
148 |
inline void push_long(jlong l) { _is_oop[_size] = false; _is_oop[_size + 1] = false; |
|
149 |
JNITypes::put_long(l, _value, _size); } |
|
150 |
||
151 |
inline void push_float(float f) { _is_oop[_size] = false; |
|
152 |
JNITypes::put_float(f, _value, _size); } |
|
153 |
||
154 |
// receiver |
|
155 |
Handle receiver() { |
|
156 |
assert(_size > 0, "must at least be one argument"); |
|
157 |
assert(_is_oop[0], "first argument must be an oop"); |
|
158 |
assert(_value[0] != 0, "receiver must be not-null"); |
|
159 |
return Handle((oop*)_value[0], false); |
|
160 |
} |
|
161 |
||
162 |
void set_receiver(Handle h) { |
|
163 |
assert(_start_at_zero == false, "can only be called once"); |
|
164 |
_start_at_zero = true; |
|
165 |
_is_oop--; |
|
166 |
_value--; |
|
167 |
_size++; |
|
168 |
_is_oop[0] = true; |
|
169 |
_value[0] = (intptr_t)h.raw_value(); |
|
170 |
} |
|
171 |
||
172 |
// Converts all Handles to oops, and returns a reference to parameter vector |
|
173 |
intptr_t* parameters() ; |
|
174 |
int size_of_parameters() const { return _size; } |
|
175 |
||
176 |
// Verify that pushed arguments fits a given method |
|
33593
60764a78fa5c
8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents:
33160
diff
changeset
|
177 |
void verify(const methodHandle& method, BasicType return_type, Thread *thread); |
1 | 178 |
}; |
179 |
||
180 |
// All calls to Java have to go via JavaCalls. Sets up the stack frame |
|
181 |
// and makes sure that the last_Java_frame pointers are chained correctly. |
|
182 |
// |
|
183 |
||
184 |
class JavaCalls: AllStatic { |
|
33593
60764a78fa5c
8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents:
33160
diff
changeset
|
185 |
static void call_helper(JavaValue* result, const methodHandle& method, JavaCallArguments* args, TRAPS); |
1 | 186 |
public: |
187 |
// call_special |
|
188 |
// ------------ |
|
189 |
// The receiver must be first oop in argument list |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
190 |
static void call_special(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS); |
1 | 191 |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
192 |
static void call_special(JavaValue* result, Handle receiver, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS); // No args |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
193 |
static void call_special(JavaValue* result, Handle receiver, KlassHandle klass, Symbol* name, Symbol* signature, Handle arg1, TRAPS); |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
194 |
static void call_special(JavaValue* result, Handle receiver, KlassHandle klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, TRAPS); |
1 | 195 |
|
196 |
// virtual call |
|
197 |
// ------------ |
|
198 |
||
199 |
// The receiver must be first oop in argument list |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
200 |
static void call_virtual(JavaValue* result, KlassHandle spec_klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS); |
1 | 201 |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
202 |
static void call_virtual(JavaValue* result, Handle receiver, KlassHandle spec_klass, Symbol* name, Symbol* signature, TRAPS); // No args |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
203 |
static void call_virtual(JavaValue* result, Handle receiver, KlassHandle spec_klass, Symbol* name, Symbol* signature, Handle arg1, TRAPS); |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
204 |
static void call_virtual(JavaValue* result, Handle receiver, KlassHandle spec_klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, TRAPS); |
1 | 205 |
|
206 |
// Static call |
|
207 |
// ----------- |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
208 |
static void call_static(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS); |
1 | 209 |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
210 |
static void call_static(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, TRAPS); |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
211 |
static void call_static(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, Handle arg1, TRAPS); |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
212 |
static void call_static(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, TRAPS); |
42307
cefc81dc1d52
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40010
diff
changeset
|
213 |
static void call_static(JavaValue* result, KlassHandle klass, Symbol* name, Symbol* signature, Handle arg1, Handle arg2, Handle arg3, TRAPS); |
1 | 214 |
|
215 |
// Low-level interface |
|
33593
60764a78fa5c
8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents:
33160
diff
changeset
|
216 |
static void call(JavaValue* result, const methodHandle& method, JavaCallArguments* args, TRAPS); |
1 | 217 |
}; |
7397 | 218 |
|
219 |
#endif // SHARE_VM_RUNTIME_JAVACALLS_HPP |