author | coleenp |
Mon, 16 Oct 2017 22:36:06 -0400 | |
changeset 47634 | 6a0c42c40cd1 |
parent 47216 | 71c04702a3d5 |
child 47687 | fb290fd1f9d4 |
permissions | -rw-r--r-- |
4013 | 1 |
/* |
44406
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
2 |
* Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved. |
9136 | 3 |
* Copyright 2007, 2008, 2009, 2010, 2011 Red Hat, Inc. |
4013 | 4 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
5 |
* |
|
6 |
* This code is free software; you can redistribute it and/or modify it |
|
7 |
* under the terms of the GNU General Public License version 2 only, as |
|
8 |
* published by the Free Software Foundation. |
|
9 |
* |
|
10 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
11 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
14 |
* accompanied this code). |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License version |
|
17 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
18 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
19 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5427
diff
changeset
|
20 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5427
diff
changeset
|
21 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5427
diff
changeset
|
22 |
* questions. |
4013 | 23 |
* |
24 |
*/ |
|
25 |
||
7397 | 26 |
#include "precompiled.hpp" |
27 |
#include "asm/assembler.hpp" |
|
28 |
#include "interpreter/bytecodeHistogram.hpp" |
|
29 |
#include "interpreter/cppInterpreter.hpp" |
|
35214 | 30 |
#include "interpreter/cppInterpreterGenerator.hpp" |
7397 | 31 |
#include "interpreter/interpreter.hpp" |
32 |
#include "interpreter/interpreterRuntime.hpp" |
|
33 |
#include "oops/arrayOop.hpp" |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
34 |
#include "oops/methodData.hpp" |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
35 |
#include "oops/method.hpp" |
7397 | 36 |
#include "oops/oop.inline.hpp" |
37 |
#include "prims/jvmtiExport.hpp" |
|
38 |
#include "prims/jvmtiThreadState.hpp" |
|
39 |
#include "runtime/arguments.hpp" |
|
40655
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
38074
diff
changeset
|
40 |
#include "runtime/atomic.hpp" |
7397 | 41 |
#include "runtime/deoptimization.hpp" |
42 |
#include "runtime/frame.inline.hpp" |
|
43 |
#include "runtime/interfaceSupport.hpp" |
|
24351
61b33cc6d3cf
8042195: Introduce umbrella header orderAccess.inline.hpp.
goetz
parents:
24018
diff
changeset
|
44 |
#include "runtime/orderAccess.inline.hpp" |
7397 | 45 |
#include "runtime/sharedRuntime.hpp" |
46 |
#include "runtime/stubRoutines.hpp" |
|
47 |
#include "runtime/synchronizer.hpp" |
|
48 |
#include "runtime/timer.hpp" |
|
49 |
#include "runtime/vframeArray.hpp" |
|
50 |
#include "stack_zero.inline.hpp" |
|
51 |
#include "utilities/debug.hpp" |
|
15482
470d0b0c09f1
8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents:
14622
diff
changeset
|
52 |
#include "utilities/macros.hpp" |
7397 | 53 |
#ifdef SHARK |
54 |
#include "shark/shark_globals.hpp" |
|
55 |
#endif |
|
4013 | 56 |
|
57 |
#ifdef CC_INTERP |
|
58 |
||
59 |
#define fixup_after_potential_safepoint() \ |
|
60 |
method = istate->method() |
|
61 |
||
9136 | 62 |
#define CALL_VM_NOCHECK_NOFIX(func) \ |
4013 | 63 |
thread->set_last_Java_frame(); \ |
64 |
func; \ |
|
9136 | 65 |
thread->reset_last_Java_frame(); |
66 |
||
67 |
#define CALL_VM_NOCHECK(func) \ |
|
68 |
CALL_VM_NOCHECK_NOFIX(func) \ |
|
4013 | 69 |
fixup_after_potential_safepoint() |
70 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
71 |
int CppInterpreter::normal_entry(Method* method, intptr_t UNUSED, TRAPS) { |
4013 | 72 |
JavaThread *thread = (JavaThread *) THREAD; |
73 |
||
74 |
// Allocate and initialize our frame. |
|
5427 | 75 |
InterpreterFrame *frame = InterpreterFrame::build(method, CHECK_0); |
4013 | 76 |
thread->push_zero_frame(frame); |
77 |
||
78 |
// Execute those bytecodes! |
|
79 |
main_loop(0, THREAD); |
|
5427 | 80 |
|
81 |
// No deoptimized frames on the stack |
|
82 |
return 0; |
|
4013 | 83 |
} |
84 |
||
37480 | 85 |
intptr_t narrow(BasicType type, intptr_t result) { |
86 |
// mask integer result to narrower return type. |
|
87 |
switch (type) { |
|
88 |
case T_BOOLEAN: |
|
89 |
return result&1; |
|
90 |
case T_BYTE: |
|
91 |
return (intptr_t)(jbyte)result; |
|
92 |
case T_CHAR: |
|
93 |
return (intptr_t)(uintptr_t)(jchar)result; |
|
94 |
case T_SHORT: |
|
95 |
return (intptr_t)(jshort)result; |
|
96 |
case T_OBJECT: // nothing to do fall through |
|
37481
95af21ea8eb0
8146518: Zero interpreter broken with better byte behaviours
coleenp
parents:
37480
diff
changeset
|
97 |
case T_ARRAY: |
37480 | 98 |
case T_LONG: |
99 |
case T_INT: |
|
100 |
case T_FLOAT: |
|
101 |
case T_DOUBLE: |
|
102 |
case T_VOID: |
|
103 |
return result; |
|
104 |
default : ShouldNotReachHere(); |
|
105 |
} |
|
106 |
} |
|
107 |
||
108 |
||
4013 | 109 |
void CppInterpreter::main_loop(int recurse, TRAPS) { |
110 |
JavaThread *thread = (JavaThread *) THREAD; |
|
111 |
ZeroStack *stack = thread->zero_stack(); |
|
112 |
||
113 |
// If we are entering from a deopt we may need to call |
|
114 |
// ourself a few times in order to get to our frame. |
|
115 |
if (recurse) |
|
116 |
main_loop(recurse - 1, THREAD); |
|
117 |
||
118 |
InterpreterFrame *frame = thread->top_zero_frame()->as_interpreter_frame(); |
|
119 |
interpreterState istate = frame->interpreter_state(); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
120 |
Method* method = istate->method(); |
4013 | 121 |
|
122 |
intptr_t *result = NULL; |
|
123 |
int result_slots = 0; |
|
124 |
||
125 |
while (true) { |
|
126 |
// We can set up the frame anchor with everything we want at |
|
127 |
// this point as we are thread_in_Java and no safepoints can |
|
128 |
// occur until we go to vm mode. We do have to clear flags |
|
129 |
// on return from vm but that is it. |
|
130 |
thread->set_last_Java_frame(); |
|
131 |
||
132 |
// Call the interpreter |
|
133 |
if (JvmtiExport::can_post_interpreter_events()) |
|
134 |
BytecodeInterpreter::runWithChecks(istate); |
|
135 |
else |
|
136 |
BytecodeInterpreter::run(istate); |
|
137 |
fixup_after_potential_safepoint(); |
|
138 |
||
139 |
// Clear the frame anchor |
|
140 |
thread->reset_last_Java_frame(); |
|
141 |
||
142 |
// Examine the message from the interpreter to decide what to do |
|
143 |
if (istate->msg() == BytecodeInterpreter::call_method) { |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
144 |
Method* callee = istate->callee(); |
4013 | 145 |
|
146 |
// Trim back the stack to put the parameters at the top |
|
147 |
stack->set_sp(istate->stack() + 1); |
|
148 |
||
149 |
// Make the call |
|
150 |
Interpreter::invoke_method(callee, istate->callee_entry_point(), THREAD); |
|
151 |
fixup_after_potential_safepoint(); |
|
152 |
||
153 |
// Convert the result |
|
154 |
istate->set_stack(stack->sp() - 1); |
|
155 |
||
156 |
// Restore the stack |
|
157 |
stack->set_sp(istate->stack_limit() + 1); |
|
158 |
||
159 |
// Resume the interpreter |
|
160 |
istate->set_msg(BytecodeInterpreter::method_resume); |
|
161 |
} |
|
162 |
else if (istate->msg() == BytecodeInterpreter::more_monitors) { |
|
163 |
int monitor_words = frame::interpreter_frame_monitor_size(); |
|
164 |
||
165 |
// Allocate the space |
|
5335 | 166 |
stack->overflow_check(monitor_words, THREAD); |
167 |
if (HAS_PENDING_EXCEPTION) |
|
168 |
break; |
|
4013 | 169 |
stack->alloc(monitor_words * wordSize); |
170 |
||
171 |
// Move the expression stack contents |
|
172 |
for (intptr_t *p = istate->stack() + 1; p < istate->stack_base(); p++) |
|
173 |
*(p - monitor_words) = *p; |
|
174 |
||
175 |
// Move the expression stack pointers |
|
176 |
istate->set_stack_limit(istate->stack_limit() - monitor_words); |
|
177 |
istate->set_stack(istate->stack() - monitor_words); |
|
178 |
istate->set_stack_base(istate->stack_base() - monitor_words); |
|
179 |
||
180 |
// Zero the new monitor so the interpreter can find it. |
|
181 |
((BasicObjectLock *) istate->stack_base())->set_obj(NULL); |
|
182 |
||
183 |
// Resume the interpreter |
|
184 |
istate->set_msg(BytecodeInterpreter::got_monitors); |
|
185 |
} |
|
186 |
else if (istate->msg() == BytecodeInterpreter::return_from_method) { |
|
187 |
// Copy the result into the caller's frame |
|
37481
95af21ea8eb0
8146518: Zero interpreter broken with better byte behaviours
coleenp
parents:
37480
diff
changeset
|
188 |
result_slots = type2size[method->result_type()]; |
4013 | 189 |
assert(result_slots >= 0 && result_slots <= 2, "what?"); |
190 |
result = istate->stack() + result_slots; |
|
191 |
break; |
|
192 |
} |
|
193 |
else if (istate->msg() == BytecodeInterpreter::throwing_exception) { |
|
194 |
assert(HAS_PENDING_EXCEPTION, "should do"); |
|
195 |
break; |
|
196 |
} |
|
197 |
else if (istate->msg() == BytecodeInterpreter::do_osr) { |
|
198 |
// Unwind the current frame |
|
199 |
thread->pop_zero_frame(); |
|
200 |
||
201 |
// Remove any extension of the previous frame |
|
202 |
int extra_locals = method->max_locals() - method->size_of_parameters(); |
|
203 |
stack->set_sp(stack->sp() + extra_locals); |
|
204 |
||
205 |
// Jump into the OSR method |
|
206 |
Interpreter::invoke_osr( |
|
207 |
method, istate->osr_entry(), istate->osr_buf(), THREAD); |
|
208 |
return; |
|
209 |
} |
|
210 |
else { |
|
211 |
ShouldNotReachHere(); |
|
212 |
} |
|
213 |
} |
|
214 |
||
215 |
// Unwind the current frame |
|
216 |
thread->pop_zero_frame(); |
|
217 |
||
218 |
// Pop our local variables |
|
219 |
stack->set_sp(stack->sp() + method->max_locals()); |
|
220 |
||
221 |
// Push our result |
|
37480 | 222 |
for (int i = 0; i < result_slots; i++) { |
223 |
// Adjust result to smaller |
|
38063 | 224 |
union { |
225 |
intptr_t res; |
|
226 |
jint res_jint; |
|
227 |
}; |
|
228 |
res = result[-i]; |
|
37480 | 229 |
if (result_slots == 1) { |
38063 | 230 |
BasicType t = method->result_type(); |
231 |
if (is_subword_type(t)) { |
|
232 |
res_jint = (jint)narrow(t, res_jint); |
|
233 |
} |
|
37480 | 234 |
} |
235 |
stack->push(res); |
|
236 |
} |
|
4013 | 237 |
} |
238 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
239 |
int CppInterpreter::native_entry(Method* method, intptr_t UNUSED, TRAPS) { |
4013 | 240 |
// Make sure method is native and not abstract |
241 |
assert(method->is_native() && !method->is_abstract(), "should be"); |
|
242 |
||
243 |
JavaThread *thread = (JavaThread *) THREAD; |
|
244 |
ZeroStack *stack = thread->zero_stack(); |
|
245 |
||
246 |
// Allocate and initialize our frame |
|
5427 | 247 |
InterpreterFrame *frame = InterpreterFrame::build(method, CHECK_0); |
4013 | 248 |
thread->push_zero_frame(frame); |
249 |
interpreterState istate = frame->interpreter_state(); |
|
250 |
intptr_t *locals = istate->locals(); |
|
251 |
||
4448 | 252 |
// Update the invocation counter |
253 |
if ((UseCompiler || CountCompiledCalls) && !method->is_synchronized()) { |
|
17314 | 254 |
MethodCounters* mcs = method->method_counters(); |
255 |
if (mcs == NULL) { |
|
256 |
CALL_VM_NOCHECK(mcs = InterpreterRuntime::build_method_counters(thread, method)); |
|
257 |
if (HAS_PENDING_EXCEPTION) |
|
258 |
goto unwind_and_return; |
|
259 |
} |
|
260 |
InvocationCounter *counter = mcs->invocation_counter(); |
|
4448 | 261 |
counter->increment(); |
22836
e7e511228518
8024468: PPC64 (part 201): cppInterpreter: implement bytecode profiling
goetz
parents:
19336
diff
changeset
|
262 |
if (counter->reached_InvocationLimit(mcs->backedge_counter())) { |
4448 | 263 |
CALL_VM_NOCHECK( |
264 |
InterpreterRuntime::frequency_counter_overflow(thread, NULL)); |
|
265 |
if (HAS_PENDING_EXCEPTION) |
|
266 |
goto unwind_and_return; |
|
267 |
} |
|
268 |
} |
|
269 |
||
4013 | 270 |
// Lock if necessary |
271 |
BasicObjectLock *monitor; |
|
272 |
monitor = NULL; |
|
273 |
if (method->is_synchronized()) { |
|
274 |
monitor = (BasicObjectLock*) istate->stack_base(); |
|
275 |
oop lockee = monitor->obj(); |
|
276 |
markOop disp = lockee->mark()->set_unlocked(); |
|
277 |
||
278 |
monitor->lock()->set_displaced_header(disp); |
|
47634
6a0c42c40cd1
8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents:
47216
diff
changeset
|
279 |
if (Atomic::cmpxchg((markOop)monitor, lockee->mark_addr(), disp) != disp) { |
4013 | 280 |
if (thread->is_lock_owned((address) disp->clear_lock_bits())) { |
281 |
monitor->lock()->set_displaced_header(NULL); |
|
282 |
} |
|
283 |
else { |
|
284 |
CALL_VM_NOCHECK(InterpreterRuntime::monitorenter(thread, monitor)); |
|
285 |
if (HAS_PENDING_EXCEPTION) |
|
286 |
goto unwind_and_return; |
|
287 |
} |
|
288 |
} |
|
289 |
} |
|
290 |
||
291 |
// Get the signature handler |
|
292 |
InterpreterRuntime::SignatureHandler *handler; { |
|
293 |
address handlerAddr = method->signature_handler(); |
|
294 |
if (handlerAddr == NULL) { |
|
295 |
CALL_VM_NOCHECK(InterpreterRuntime::prepare_native_call(thread, method)); |
|
296 |
if (HAS_PENDING_EXCEPTION) |
|
4568
d18b14983811
6908267: Zero fails to unlock synchronized native methods on exception
never
parents:
4448
diff
changeset
|
297 |
goto unlock_unwind_and_return; |
4013 | 298 |
|
299 |
handlerAddr = method->signature_handler(); |
|
300 |
assert(handlerAddr != NULL, "eh?"); |
|
301 |
} |
|
302 |
if (handlerAddr == (address) InterpreterRuntime::slow_signature_handler) { |
|
303 |
CALL_VM_NOCHECK(handlerAddr = |
|
304 |
InterpreterRuntime::slow_signature_handler(thread, method, NULL,NULL)); |
|
305 |
if (HAS_PENDING_EXCEPTION) |
|
4568
d18b14983811
6908267: Zero fails to unlock synchronized native methods on exception
never
parents:
4448
diff
changeset
|
306 |
goto unlock_unwind_and_return; |
4013 | 307 |
} |
308 |
handler = \ |
|
309 |
InterpreterRuntime::SignatureHandler::from_handlerAddr(handlerAddr); |
|
310 |
} |
|
311 |
||
312 |
// Get the native function entry point |
|
313 |
address function; |
|
314 |
function = method->native_function(); |
|
315 |
assert(function != NULL, "should be set if signature handler is"); |
|
316 |
||
317 |
// Build the argument list |
|
5335 | 318 |
stack->overflow_check(handler->argument_count() * 2, THREAD); |
319 |
if (HAS_PENDING_EXCEPTION) |
|
320 |
goto unlock_unwind_and_return; |
|
321 |
||
4013 | 322 |
void **arguments; |
323 |
void *mirror; { |
|
324 |
arguments = |
|
325 |
(void **) stack->alloc(handler->argument_count() * sizeof(void **)); |
|
326 |
void **dst = arguments; |
|
327 |
||
328 |
void *env = thread->jni_environment(); |
|
329 |
*(dst++) = &env; |
|
330 |
||
331 |
if (method->is_static()) { |
|
332 |
istate->set_oop_temp( |
|
8725
8c1e3dd5fe1b
7017732: move static fields into Class to prepare for perm gen removal
never
parents:
7397
diff
changeset
|
333 |
method->constants()->pool_holder()->java_mirror()); |
4013 | 334 |
mirror = istate->oop_temp_addr(); |
335 |
*(dst++) = &mirror; |
|
336 |
} |
|
337 |
||
338 |
intptr_t *src = locals; |
|
339 |
for (int i = dst - arguments; i < handler->argument_count(); i++) { |
|
340 |
ffi_type *type = handler->argument_type(i); |
|
341 |
if (type == &ffi_type_pointer) { |
|
342 |
if (*src) { |
|
343 |
stack->push((intptr_t) src); |
|
344 |
*(dst++) = stack->sp(); |
|
345 |
} |
|
346 |
else { |
|
347 |
*(dst++) = src; |
|
348 |
} |
|
349 |
src--; |
|
350 |
} |
|
351 |
else if (type->size == 4) { |
|
352 |
*(dst++) = src--; |
|
353 |
} |
|
354 |
else if (type->size == 8) { |
|
355 |
src--; |
|
356 |
*(dst++) = src--; |
|
357 |
} |
|
358 |
else { |
|
359 |
ShouldNotReachHere(); |
|
360 |
} |
|
361 |
} |
|
362 |
} |
|
363 |
||
364 |
// Set up the Java frame anchor |
|
365 |
thread->set_last_Java_frame(); |
|
366 |
||
367 |
// Change the thread state to _thread_in_native |
|
368 |
ThreadStateTransition::transition_from_java(thread, _thread_in_native); |
|
369 |
||
370 |
// Make the call |
|
371 |
intptr_t result[4 - LogBytesPerWord]; |
|
372 |
ffi_call(handler->cif(), (void (*)()) function, result, arguments); |
|
373 |
||
374 |
// Change the thread state back to _thread_in_Java. |
|
375 |
// ThreadStateTransition::transition_from_native() cannot be used |
|
376 |
// here because it does not check for asynchronous exceptions. |
|
377 |
// We have to manage the transition ourself. |
|
378 |
thread->set_thread_state(_thread_in_native_trans); |
|
379 |
||
380 |
// Make sure new state is visible in the GC thread |
|
46604
d409276ee40c
8183198: Factor out thread state serialization into a proper helper function
mgerdin
parents:
44406
diff
changeset
|
381 |
InterfaceSupport::serialize_thread_state(thread); |
4013 | 382 |
|
383 |
// Handle safepoint operations, pending suspend requests, |
|
384 |
// and pending asynchronous exceptions. |
|
385 |
if (SafepointSynchronize::do_call_back() || |
|
386 |
thread->has_special_condition_for_native_trans()) { |
|
387 |
JavaThread::check_special_condition_for_native_trans(thread); |
|
388 |
CHECK_UNHANDLED_OOPS_ONLY(thread->clear_unhandled_oops()); |
|
389 |
} |
|
390 |
||
391 |
// Finally we can change the thread state to _thread_in_Java. |
|
392 |
thread->set_thread_state(_thread_in_Java); |
|
393 |
fixup_after_potential_safepoint(); |
|
394 |
||
395 |
// Clear the frame anchor |
|
396 |
thread->reset_last_Java_frame(); |
|
397 |
||
398 |
// If the result was an oop then unbox it and store it in |
|
399 |
// oop_temp where the garbage collector can see it before |
|
400 |
// we release the handle it might be protected by. |
|
401 |
if (handler->result_type() == &ffi_type_pointer) { |
|
44406
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
402 |
if (result[0] == 0) { |
4013 | 403 |
istate->set_oop_temp(NULL); |
44406
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
404 |
} else { |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
405 |
jobject handle = reinterpret_cast<jobject>(result[0]); |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
406 |
istate->set_oop_temp(JNIHandles::resolve(handle)); |
a46a6c4d1dd9
8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents:
44093
diff
changeset
|
407 |
} |
4013 | 408 |
} |
409 |
||
410 |
// Reset handle block |
|
411 |
thread->active_handles()->clear(); |
|
412 |
||
4568
d18b14983811
6908267: Zero fails to unlock synchronized native methods on exception
never
parents:
4448
diff
changeset
|
413 |
unlock_unwind_and_return: |
d18b14983811
6908267: Zero fails to unlock synchronized native methods on exception
never
parents:
4448
diff
changeset
|
414 |
|
d18b14983811
6908267: Zero fails to unlock synchronized native methods on exception
never
parents:
4448
diff
changeset
|
415 |
// Unlock if necessary |
d18b14983811
6908267: Zero fails to unlock synchronized native methods on exception
never
parents:
4448
diff
changeset
|
416 |
if (monitor) { |
4013 | 417 |
BasicLock *lock = monitor->lock(); |
418 |
markOop header = lock->displaced_header(); |
|
419 |
oop rcvr = monitor->obj(); |
|
420 |
monitor->set_obj(NULL); |
|
421 |
||
422 |
if (header != NULL) { |
|
47634
6a0c42c40cd1
8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents:
47216
diff
changeset
|
423 |
markOop old_header = markOopDesc::encode(lock); |
6a0c42c40cd1
8188220: Remove Atomic::*_ptr() uses and overloads from hotspot
coleenp
parents:
47216
diff
changeset
|
424 |
if (rcvr->cas_set_mark(header, old_header) != old_header) { |
4013 | 425 |
monitor->set_obj(rcvr); { |
426 |
HandleMark hm(thread); |
|
427 |
CALL_VM_NOCHECK(InterpreterRuntime::monitorexit(thread, monitor)); |
|
428 |
} |
|
429 |
} |
|
430 |
} |
|
431 |
} |
|
432 |
||
433 |
unwind_and_return: |
|
434 |
||
435 |
// Unwind the current activation |
|
436 |
thread->pop_zero_frame(); |
|
437 |
||
438 |
// Pop our parameters |
|
439 |
stack->set_sp(stack->sp() + method->size_of_parameters()); |
|
440 |
||
441 |
// Push our result |
|
442 |
if (!HAS_PENDING_EXCEPTION) { |
|
37481
95af21ea8eb0
8146518: Zero interpreter broken with better byte behaviours
coleenp
parents:
37480
diff
changeset
|
443 |
BasicType type = method->result_type(); |
4897 | 444 |
stack->set_sp(stack->sp() - type2size[type]); |
4013 | 445 |
|
4897 | 446 |
switch (type) { |
4013 | 447 |
case T_VOID: |
448 |
break; |
|
449 |
||
450 |
case T_BOOLEAN: |
|
451 |
#ifndef VM_LITTLE_ENDIAN |
|
452 |
result[0] <<= (BitsPerWord - BitsPerByte); |
|
453 |
#endif |
|
454 |
SET_LOCALS_INT(*(jboolean *) result != 0, 0); |
|
455 |
break; |
|
456 |
||
457 |
case T_CHAR: |
|
458 |
#ifndef VM_LITTLE_ENDIAN |
|
459 |
result[0] <<= (BitsPerWord - BitsPerShort); |
|
460 |
#endif |
|
461 |
SET_LOCALS_INT(*(jchar *) result, 0); |
|
462 |
break; |
|
463 |
||
464 |
case T_BYTE: |
|
465 |
#ifndef VM_LITTLE_ENDIAN |
|
466 |
result[0] <<= (BitsPerWord - BitsPerByte); |
|
467 |
#endif |
|
468 |
SET_LOCALS_INT(*(jbyte *) result, 0); |
|
469 |
break; |
|
470 |
||
471 |
case T_SHORT: |
|
472 |
#ifndef VM_LITTLE_ENDIAN |
|
473 |
result[0] <<= (BitsPerWord - BitsPerShort); |
|
474 |
#endif |
|
475 |
SET_LOCALS_INT(*(jshort *) result, 0); |
|
476 |
break; |
|
477 |
||
478 |
case T_INT: |
|
479 |
#ifndef VM_LITTLE_ENDIAN |
|
480 |
result[0] <<= (BitsPerWord - BitsPerInt); |
|
481 |
#endif |
|
482 |
SET_LOCALS_INT(*(jint *) result, 0); |
|
483 |
break; |
|
484 |
||
485 |
case T_LONG: |
|
486 |
SET_LOCALS_LONG(*(jlong *) result, 0); |
|
487 |
break; |
|
488 |
||
489 |
case T_FLOAT: |
|
490 |
SET_LOCALS_FLOAT(*(jfloat *) result, 0); |
|
491 |
break; |
|
492 |
||
493 |
case T_DOUBLE: |
|
494 |
SET_LOCALS_DOUBLE(*(jdouble *) result, 0); |
|
495 |
break; |
|
496 |
||
497 |
case T_OBJECT: |
|
498 |
case T_ARRAY: |
|
499 |
SET_LOCALS_OBJECT(istate->oop_temp(), 0); |
|
500 |
break; |
|
501 |
||
502 |
default: |
|
503 |
ShouldNotReachHere(); |
|
504 |
} |
|
505 |
} |
|
5427 | 506 |
|
507 |
// No deoptimized frames on the stack |
|
508 |
return 0; |
|
4013 | 509 |
} |
510 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
511 |
int CppInterpreter::accessor_entry(Method* method, intptr_t UNUSED, TRAPS) { |
4013 | 512 |
JavaThread *thread = (JavaThread *) THREAD; |
513 |
ZeroStack *stack = thread->zero_stack(); |
|
514 |
intptr_t *locals = stack->sp(); |
|
515 |
||
516 |
// Drop into the slow path if we need a safepoint check |
|
517 |
if (SafepointSynchronize::do_call_back()) { |
|
5427 | 518 |
return normal_entry(method, 0, THREAD); |
4013 | 519 |
} |
520 |
||
521 |
// Load the object pointer and drop into the slow path |
|
522 |
// if we have a NullPointerException |
|
523 |
oop object = LOCALS_OBJECT(0); |
|
524 |
if (object == NULL) { |
|
5427 | 525 |
return normal_entry(method, 0, THREAD); |
4013 | 526 |
} |
527 |
||
528 |
// Read the field index from the bytecode, which looks like this: |
|
529 |
// 0: aload_0 |
|
530 |
// 1: getfield |
|
531 |
// 2: index |
|
532 |
// 3: index |
|
34169
b0b7187852b7
8140650: Method::is_accessor should cover getters and setters for all types
shade
parents:
33070
diff
changeset
|
533 |
// 4: ireturn/areturn/freturn/lreturn/dreturn |
4013 | 534 |
// NB this is not raw bytecode: index is in machine order |
535 |
u1 *code = method->code_base(); |
|
536 |
assert(code[0] == Bytecodes::_aload_0 && |
|
537 |
code[1] == Bytecodes::_getfield && |
|
538 |
(code[4] == Bytecodes::_ireturn || |
|
34169
b0b7187852b7
8140650: Method::is_accessor should cover getters and setters for all types
shade
parents:
33070
diff
changeset
|
539 |
code[4] == Bytecodes::_freturn || |
b0b7187852b7
8140650: Method::is_accessor should cover getters and setters for all types
shade
parents:
33070
diff
changeset
|
540 |
code[4] == Bytecodes::_lreturn || |
b0b7187852b7
8140650: Method::is_accessor should cover getters and setters for all types
shade
parents:
33070
diff
changeset
|
541 |
code[4] == Bytecodes::_dreturn || |
4013 | 542 |
code[4] == Bytecodes::_areturn), "should do"); |
543 |
u2 index = Bytes::get_native_u2(&code[2]); |
|
544 |
||
545 |
// Get the entry from the constant pool cache, and drop into |
|
546 |
// the slow path if it has not been resolved |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
547 |
ConstantPoolCache* cache = method->constants()->cache(); |
4013 | 548 |
ConstantPoolCacheEntry* entry = cache->entry_at(index); |
549 |
if (!entry->is_resolved(Bytecodes::_getfield)) { |
|
5427 | 550 |
return normal_entry(method, 0, THREAD); |
4013 | 551 |
} |
552 |
||
553 |
// Get the result and push it onto the stack |
|
554 |
switch (entry->flag_state()) { |
|
555 |
case ltos: |
|
556 |
case dtos: |
|
5427 | 557 |
stack->overflow_check(1, CHECK_0); |
4013 | 558 |
stack->alloc(wordSize); |
559 |
break; |
|
560 |
} |
|
561 |
if (entry->is_volatile()) { |
|
562 |
switch (entry->flag_state()) { |
|
563 |
case ctos: |
|
14294 | 564 |
SET_LOCALS_INT(object->char_field_acquire(entry->f2_as_index()), 0); |
4013 | 565 |
break; |
566 |
||
567 |
case btos: |
|
37480 | 568 |
case ztos: |
14294 | 569 |
SET_LOCALS_INT(object->byte_field_acquire(entry->f2_as_index()), 0); |
4013 | 570 |
break; |
571 |
||
572 |
case stos: |
|
14294 | 573 |
SET_LOCALS_INT(object->short_field_acquire(entry->f2_as_index()), 0); |
4013 | 574 |
break; |
575 |
||
576 |
case itos: |
|
14294 | 577 |
SET_LOCALS_INT(object->int_field_acquire(entry->f2_as_index()), 0); |
4013 | 578 |
break; |
579 |
||
580 |
case ltos: |
|
14294 | 581 |
SET_LOCALS_LONG(object->long_field_acquire(entry->f2_as_index()), 0); |
4013 | 582 |
break; |
583 |
||
584 |
case ftos: |
|
14294 | 585 |
SET_LOCALS_FLOAT(object->float_field_acquire(entry->f2_as_index()), 0); |
4013 | 586 |
break; |
587 |
||
588 |
case dtos: |
|
14294 | 589 |
SET_LOCALS_DOUBLE(object->double_field_acquire(entry->f2_as_index()), 0); |
4013 | 590 |
break; |
591 |
||
592 |
case atos: |
|
14294 | 593 |
SET_LOCALS_OBJECT(object->obj_field_acquire(entry->f2_as_index()), 0); |
4013 | 594 |
break; |
595 |
||
596 |
default: |
|
597 |
ShouldNotReachHere(); |
|
598 |
} |
|
599 |
} |
|
600 |
else { |
|
601 |
switch (entry->flag_state()) { |
|
602 |
case ctos: |
|
14294 | 603 |
SET_LOCALS_INT(object->char_field(entry->f2_as_index()), 0); |
4013 | 604 |
break; |
605 |
||
606 |
case btos: |
|
37480 | 607 |
case ztos: |
14294 | 608 |
SET_LOCALS_INT(object->byte_field(entry->f2_as_index()), 0); |
4013 | 609 |
break; |
610 |
||
611 |
case stos: |
|
14294 | 612 |
SET_LOCALS_INT(object->short_field(entry->f2_as_index()), 0); |
4013 | 613 |
break; |
614 |
||
615 |
case itos: |
|
14294 | 616 |
SET_LOCALS_INT(object->int_field(entry->f2_as_index()), 0); |
4013 | 617 |
break; |
618 |
||
619 |
case ltos: |
|
14294 | 620 |
SET_LOCALS_LONG(object->long_field(entry->f2_as_index()), 0); |
4013 | 621 |
break; |
622 |
||
623 |
case ftos: |
|
14294 | 624 |
SET_LOCALS_FLOAT(object->float_field(entry->f2_as_index()), 0); |
4013 | 625 |
break; |
626 |
||
627 |
case dtos: |
|
14294 | 628 |
SET_LOCALS_DOUBLE(object->double_field(entry->f2_as_index()), 0); |
4013 | 629 |
break; |
630 |
||
631 |
case atos: |
|
14294 | 632 |
SET_LOCALS_OBJECT(object->obj_field(entry->f2_as_index()), 0); |
4013 | 633 |
break; |
634 |
||
635 |
default: |
|
636 |
ShouldNotReachHere(); |
|
637 |
} |
|
638 |
} |
|
5427 | 639 |
|
640 |
// No deoptimized frames on the stack |
|
641 |
return 0; |
|
4013 | 642 |
} |
643 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
644 |
int CppInterpreter::empty_entry(Method* method, intptr_t UNUSED, TRAPS) { |
4013 | 645 |
JavaThread *thread = (JavaThread *) THREAD; |
646 |
ZeroStack *stack = thread->zero_stack(); |
|
647 |
||
648 |
// Drop into the slow path if we need a safepoint check |
|
649 |
if (SafepointSynchronize::do_call_back()) { |
|
5427 | 650 |
return normal_entry(method, 0, THREAD); |
4013 | 651 |
} |
652 |
||
653 |
// Pop our parameters |
|
654 |
stack->set_sp(stack->sp() + method->size_of_parameters()); |
|
5427 | 655 |
|
656 |
// No deoptimized frames on the stack |
|
657 |
return 0; |
|
4013 | 658 |
} |
659 |
||
9136 | 660 |
// The new slots will be inserted before slot insert_before. |
661 |
// Slots < insert_before will have the same slot number after the insert. |
|
662 |
// Slots >= insert_before will become old_slot + num_slots. |
|
663 |
void CppInterpreter::insert_vmslots(int insert_before, int num_slots, TRAPS) { |
|
664 |
JavaThread *thread = (JavaThread *) THREAD; |
|
665 |
ZeroStack *stack = thread->zero_stack(); |
|
666 |
||
667 |
// Allocate the space |
|
668 |
stack->overflow_check(num_slots, CHECK); |
|
669 |
stack->alloc(num_slots * wordSize); |
|
670 |
intptr_t *vmslots = stack->sp(); |
|
671 |
||
672 |
// Shuffle everything up |
|
673 |
for (int i = 0; i < insert_before; i++) |
|
674 |
SET_VMSLOTS_SLOT(VMSLOTS_SLOT(i + num_slots), i); |
|
675 |
} |
|
676 |
||
677 |
void CppInterpreter::remove_vmslots(int first_slot, int num_slots, TRAPS) { |
|
678 |
JavaThread *thread = (JavaThread *) THREAD; |
|
679 |
ZeroStack *stack = thread->zero_stack(); |
|
680 |
intptr_t *vmslots = stack->sp(); |
|
681 |
||
682 |
// Move everything down |
|
683 |
for (int i = first_slot - 1; i >= 0; i--) |
|
684 |
SET_VMSLOTS_SLOT(VMSLOTS_SLOT(i), i + num_slots); |
|
685 |
||
686 |
// Deallocate the space |
|
687 |
stack->set_sp(stack->sp() + num_slots); |
|
688 |
} |
|
689 |
||
690 |
BasicType CppInterpreter::result_type_of_handle(oop method_handle) { |
|
691 |
oop method_type = java_lang_invoke_MethodHandle::type(method_handle); |
|
692 |
oop return_type = java_lang_invoke_MethodType::rtype(method_type); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
693 |
return java_lang_Class::as_BasicType(return_type, (Klass* *) NULL); |
9136 | 694 |
} |
695 |
||
696 |
intptr_t* CppInterpreter::calculate_unwind_sp(ZeroStack* stack, |
|
697 |
oop method_handle) { |
|
698 |
oop method_type = java_lang_invoke_MethodHandle::type(method_handle); |
|
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
12726
diff
changeset
|
699 |
int argument_slots = java_lang_invoke_MethodType::ptype_slot_count(method_type); |
9136 | 700 |
|
701 |
return stack->sp() + argument_slots; |
|
702 |
} |
|
703 |
||
704 |
IRT_ENTRY(void, CppInterpreter::throw_exception(JavaThread* thread, |
|
705 |
Symbol* name, |
|
706 |
char* message)) |
|
707 |
THROW_MSG(name, message); |
|
708 |
IRT_END |
|
709 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
710 |
InterpreterFrame *InterpreterFrame::build(Method* const method, TRAPS) { |
5335 | 711 |
JavaThread *thread = (JavaThread *) THREAD; |
712 |
ZeroStack *stack = thread->zero_stack(); |
|
713 |
||
714 |
// Calculate the size of the frame we'll build, including |
|
715 |
// any adjustments to the caller's frame that we'll make. |
|
716 |
int extra_locals = 0; |
|
717 |
int monitor_words = 0; |
|
718 |
int stack_words = 0; |
|
4013 | 719 |
|
5335 | 720 |
if (!method->is_native()) { |
721 |
extra_locals = method->max_locals() - method->size_of_parameters(); |
|
722 |
stack_words = method->max_stack(); |
|
4013 | 723 |
} |
5335 | 724 |
if (method->is_synchronized()) { |
725 |
monitor_words = frame::interpreter_frame_monitor_size(); |
|
726 |
} |
|
727 |
stack->overflow_check( |
|
728 |
extra_locals + header_words + monitor_words + stack_words, CHECK_NULL); |
|
4013 | 729 |
|
5335 | 730 |
// Adjust the caller's stack frame to accomodate any additional |
731 |
// local variables we have contiguously with our parameters. |
|
732 |
for (int i = 0; i < extra_locals; i++) |
|
733 |
stack->push(0); |
|
4013 | 734 |
|
735 |
intptr_t *locals; |
|
736 |
if (method->is_native()) |
|
737 |
locals = stack->sp() + (method->size_of_parameters() - 1); |
|
738 |
else |
|
739 |
locals = stack->sp() + (method->max_locals() - 1); |
|
740 |
||
741 |
stack->push(0); // next_frame, filled in later |
|
742 |
intptr_t *fp = stack->sp(); |
|
743 |
assert(fp - stack->sp() == next_frame_off, "should be"); |
|
744 |
||
745 |
stack->push(INTERPRETER_FRAME); |
|
746 |
assert(fp - stack->sp() == frame_type_off, "should be"); |
|
747 |
||
748 |
interpreterState istate = |
|
749 |
(interpreterState) stack->alloc(sizeof(BytecodeInterpreter)); |
|
750 |
assert(fp - stack->sp() == istate_off, "should be"); |
|
751 |
||
752 |
istate->set_locals(locals); |
|
753 |
istate->set_method(method); |
|
38074
8475fdc6dcc3
8154580: Save mirror in interpreter frame to enable cleanups of CLDClosure
coleenp
parents:
38063
diff
changeset
|
754 |
istate->set_mirror(method->method_holder()->java_mirror()); |
4013 | 755 |
istate->set_self_link(istate); |
756 |
istate->set_prev_link(NULL); |
|
757 |
istate->set_thread(thread); |
|
758 |
istate->set_bcp(method->is_native() ? NULL : method->code_base()); |
|
759 |
istate->set_constants(method->constants()->cache()); |
|
760 |
istate->set_msg(BytecodeInterpreter::method_entry); |
|
761 |
istate->set_oop_temp(NULL); |
|
762 |
istate->set_mdx(NULL); |
|
763 |
istate->set_callee(NULL); |
|
764 |
||
765 |
istate->set_monitor_base((BasicObjectLock *) stack->sp()); |
|
766 |
if (method->is_synchronized()) { |
|
767 |
BasicObjectLock *monitor = |
|
768 |
(BasicObjectLock *) stack->alloc(monitor_words * wordSize); |
|
769 |
oop object; |
|
770 |
if (method->is_static()) |
|
8725
8c1e3dd5fe1b
7017732: move static fields into Class to prepare for perm gen removal
never
parents:
7397
diff
changeset
|
771 |
object = method->constants()->pool_holder()->java_mirror(); |
4013 | 772 |
else |
26142 | 773 |
object = (oop) (void*)locals[0]; |
4013 | 774 |
monitor->set_obj(object); |
775 |
} |
|
776 |
||
777 |
istate->set_stack_base(stack->sp()); |
|
778 |
istate->set_stack(stack->sp() - 1); |
|
779 |
if (stack_words) |
|
780 |
stack->alloc(stack_words * wordSize); |
|
781 |
istate->set_stack_limit(stack->sp() - 1); |
|
782 |
||
783 |
return (InterpreterFrame *) fp; |
|
784 |
} |
|
785 |
||
5335 | 786 |
InterpreterFrame *InterpreterFrame::build(int size, TRAPS) { |
787 |
ZeroStack *stack = ((JavaThread *) THREAD)->zero_stack(); |
|
788 |
||
4013 | 789 |
int size_in_words = size >> LogBytesPerWord; |
790 |
assert(size_in_words * wordSize == size, "unaligned"); |
|
791 |
assert(size_in_words >= header_words, "too small"); |
|
5335 | 792 |
stack->overflow_check(size_in_words, CHECK_NULL); |
4013 | 793 |
|
794 |
stack->push(0); // next_frame, filled in later |
|
795 |
intptr_t *fp = stack->sp(); |
|
796 |
assert(fp - stack->sp() == next_frame_off, "should be"); |
|
797 |
||
798 |
stack->push(INTERPRETER_FRAME); |
|
799 |
assert(fp - stack->sp() == frame_type_off, "should be"); |
|
800 |
||
801 |
interpreterState istate = |
|
802 |
(interpreterState) stack->alloc(sizeof(BytecodeInterpreter)); |
|
803 |
assert(fp - stack->sp() == istate_off, "should be"); |
|
804 |
istate->set_self_link(NULL); // mark invalid |
|
805 |
||
806 |
stack->alloc((size_in_words - header_words) * wordSize); |
|
807 |
||
808 |
return (InterpreterFrame *) fp; |
|
809 |
} |
|
810 |
||
21198
dd647e8d1d72
8026328: Setting a breakpoint on invokedynamic crashes the JVM
twisti
parents:
19336
diff
changeset
|
811 |
address CppInterpreter::return_entry(TosState state, int length, Bytecodes::Code code) { |
4013 | 812 |
ShouldNotCallThis(); |
19336
ddceb0657500
8022956: Clang: enable return type warnings on BSD
twisti
parents:
17314
diff
changeset
|
813 |
return NULL; |
4013 | 814 |
} |
815 |
||
816 |
address CppInterpreter::deopt_entry(TosState state, int length) { |
|
817 |
return NULL; |
|
818 |
} |
|
819 |
||
820 |
// Helper for figuring out if frames are interpreter frames |
|
821 |
||
822 |
bool CppInterpreter::contains(address pc) { |
|
823 |
return false; // make frame::print_value_on work |
|
824 |
} |
|
825 |
#endif // CC_INTERP |