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