Mercurial > hg > graal-jvmci-8
annotate src/cpu/zero/vm/cppInterpreter_zero.cpp @ 3249:e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
Summary: A referent object that is only weakly reachable at the start of concurrent marking but is re-attached to the strongly reachable object graph during marking may not be marked as live. This can cause the reference object to be processed prematurely and leave dangling pointers to the referent object. Implement a read barrier for the java.lang.ref.Reference::referent field by intrinsifying the Reference.get() method, and intercepting accesses though JNI, reflection, and Unsafe, so that when a non-null referent object is read it is also logged in an SATB buffer.
Reviewed-by: kvn, iveresov, never, tonyp, dholmes
author | johnc |
---|---|
date | Thu, 07 Apr 2011 09:53:20 -0700 |
parents | c7f3d0b4570f |
children | 732454aaf5cb |
rev | line source |
---|---|
1010 | 1 /* |
2376
c7f3d0b4570f
7017732: move static fields into Class to prepare for perm gen removal
never
parents:
1972
diff
changeset
|
2 * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. |
1256 | 3 * Copyright 2007, 2008, 2009, 2010 Red Hat, Inc. |
1010 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1514
diff
changeset
|
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1514
diff
changeset
|
21 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1514
diff
changeset
|
22 * questions. |
1010 | 23 * |
24 */ | |
25 | |
1972 | 26 #include "precompiled.hpp" |
27 #include "asm/assembler.hpp" | |
28 #include "interpreter/bytecodeHistogram.hpp" | |
29 #include "interpreter/cppInterpreter.hpp" | |
30 #include "interpreter/interpreter.hpp" | |
31 #include "interpreter/interpreterGenerator.hpp" | |
32 #include "interpreter/interpreterRuntime.hpp" | |
33 #include "oops/arrayOop.hpp" | |
34 #include "oops/methodDataOop.hpp" | |
35 #include "oops/methodOop.hpp" | |
36 #include "oops/oop.inline.hpp" | |
37 #include "prims/jvmtiExport.hpp" | |
38 #include "prims/jvmtiThreadState.hpp" | |
39 #include "runtime/arguments.hpp" | |
40 #include "runtime/deoptimization.hpp" | |
41 #include "runtime/frame.inline.hpp" | |
42 #include "runtime/interfaceSupport.hpp" | |
43 #include "runtime/sharedRuntime.hpp" | |
44 #include "runtime/stubRoutines.hpp" | |
45 #include "runtime/synchronizer.hpp" | |
46 #include "runtime/timer.hpp" | |
47 #include "runtime/vframeArray.hpp" | |
48 #include "stack_zero.inline.hpp" | |
49 #include "utilities/debug.hpp" | |
50 #ifdef SHARK | |
51 #include "shark/shark_globals.hpp" | |
52 #endif | |
1010 | 53 |
54 #ifdef CC_INTERP | |
55 | |
56 #define fixup_after_potential_safepoint() \ | |
57 method = istate->method() | |
58 | |
59 #define CALL_VM_NOCHECK(func) \ | |
60 thread->set_last_Java_frame(); \ | |
61 func; \ | |
62 thread->reset_last_Java_frame(); \ | |
63 fixup_after_potential_safepoint() | |
64 | |
1514 | 65 int CppInterpreter::normal_entry(methodOop method, intptr_t UNUSED, TRAPS) { |
1010 | 66 JavaThread *thread = (JavaThread *) THREAD; |
67 | |
68 // Allocate and initialize our frame. | |
1514 | 69 InterpreterFrame *frame = InterpreterFrame::build(method, CHECK_0); |
1010 | 70 thread->push_zero_frame(frame); |
71 | |
72 // Execute those bytecodes! | |
73 main_loop(0, THREAD); | |
1514 | 74 |
75 // No deoptimized frames on the stack | |
76 return 0; | |
1010 | 77 } |
78 | |
79 void CppInterpreter::main_loop(int recurse, TRAPS) { | |
80 JavaThread *thread = (JavaThread *) THREAD; | |
81 ZeroStack *stack = thread->zero_stack(); | |
82 | |
83 // If we are entering from a deopt we may need to call | |
84 // ourself a few times in order to get to our frame. | |
85 if (recurse) | |
86 main_loop(recurse - 1, THREAD); | |
87 | |
88 InterpreterFrame *frame = thread->top_zero_frame()->as_interpreter_frame(); | |
89 interpreterState istate = frame->interpreter_state(); | |
90 methodOop method = istate->method(); | |
91 | |
92 intptr_t *result = NULL; | |
93 int result_slots = 0; | |
94 | |
95 while (true) { | |
96 // We can set up the frame anchor with everything we want at | |
97 // this point as we are thread_in_Java and no safepoints can | |
98 // occur until we go to vm mode. We do have to clear flags | |
99 // on return from vm but that is it. | |
100 thread->set_last_Java_frame(); | |
101 | |
102 // Call the interpreter | |
103 if (JvmtiExport::can_post_interpreter_events()) | |
104 BytecodeInterpreter::runWithChecks(istate); | |
105 else | |
106 BytecodeInterpreter::run(istate); | |
107 fixup_after_potential_safepoint(); | |
108 | |
109 // Clear the frame anchor | |
110 thread->reset_last_Java_frame(); | |
111 | |
112 // Examine the message from the interpreter to decide what to do | |
113 if (istate->msg() == BytecodeInterpreter::call_method) { | |
114 methodOop callee = istate->callee(); | |
115 | |
116 // Trim back the stack to put the parameters at the top | |
117 stack->set_sp(istate->stack() + 1); | |
118 | |
119 // Make the call | |
120 Interpreter::invoke_method(callee, istate->callee_entry_point(), THREAD); | |
121 fixup_after_potential_safepoint(); | |
122 | |
123 // Convert the result | |
124 istate->set_stack(stack->sp() - 1); | |
125 | |
126 // Restore the stack | |
127 stack->set_sp(istate->stack_limit() + 1); | |
128 | |
129 // Resume the interpreter | |
130 istate->set_msg(BytecodeInterpreter::method_resume); | |
131 } | |
132 else if (istate->msg() == BytecodeInterpreter::more_monitors) { | |
133 int monitor_words = frame::interpreter_frame_monitor_size(); | |
134 | |
135 // Allocate the space | |
1379 | 136 stack->overflow_check(monitor_words, THREAD); |
137 if (HAS_PENDING_EXCEPTION) | |
138 break; | |
1010 | 139 stack->alloc(monitor_words * wordSize); |
140 | |
141 // Move the expression stack contents | |
142 for (intptr_t *p = istate->stack() + 1; p < istate->stack_base(); p++) | |
143 *(p - monitor_words) = *p; | |
144 | |
145 // Move the expression stack pointers | |
146 istate->set_stack_limit(istate->stack_limit() - monitor_words); | |
147 istate->set_stack(istate->stack() - monitor_words); | |
148 istate->set_stack_base(istate->stack_base() - monitor_words); | |
149 | |
150 // Zero the new monitor so the interpreter can find it. | |
151 ((BasicObjectLock *) istate->stack_base())->set_obj(NULL); | |
152 | |
153 // Resume the interpreter | |
154 istate->set_msg(BytecodeInterpreter::got_monitors); | |
155 } | |
156 else if (istate->msg() == BytecodeInterpreter::return_from_method) { | |
157 // Copy the result into the caller's frame | |
1256 | 158 result_slots = type2size[result_type_of(method)]; |
1010 | 159 assert(result_slots >= 0 && result_slots <= 2, "what?"); |
160 result = istate->stack() + result_slots; | |
161 break; | |
162 } | |
163 else if (istate->msg() == BytecodeInterpreter::throwing_exception) { | |
164 assert(HAS_PENDING_EXCEPTION, "should do"); | |
165 break; | |
166 } | |
167 else if (istate->msg() == BytecodeInterpreter::do_osr) { | |
168 // Unwind the current frame | |
169 thread->pop_zero_frame(); | |
170 | |
171 // Remove any extension of the previous frame | |
172 int extra_locals = method->max_locals() - method->size_of_parameters(); | |
173 stack->set_sp(stack->sp() + extra_locals); | |
174 | |
175 // Jump into the OSR method | |
176 Interpreter::invoke_osr( | |
177 method, istate->osr_entry(), istate->osr_buf(), THREAD); | |
178 return; | |
179 } | |
180 else { | |
181 ShouldNotReachHere(); | |
182 } | |
183 } | |
184 | |
185 // Unwind the current frame | |
186 thread->pop_zero_frame(); | |
187 | |
188 // Pop our local variables | |
189 stack->set_sp(stack->sp() + method->max_locals()); | |
190 | |
191 // Push our result | |
192 for (int i = 0; i < result_slots; i++) | |
193 stack->push(result[-i]); | |
194 } | |
195 | |
1514 | 196 int CppInterpreter::native_entry(methodOop method, intptr_t UNUSED, TRAPS) { |
1010 | 197 // Make sure method is native and not abstract |
198 assert(method->is_native() && !method->is_abstract(), "should be"); | |
199 | |
200 JavaThread *thread = (JavaThread *) THREAD; | |
201 ZeroStack *stack = thread->zero_stack(); | |
202 | |
203 // Allocate and initialize our frame | |
1514 | 204 InterpreterFrame *frame = InterpreterFrame::build(method, CHECK_0); |
1010 | 205 thread->push_zero_frame(frame); |
206 interpreterState istate = frame->interpreter_state(); | |
207 intptr_t *locals = istate->locals(); | |
208 | |
1078 | 209 // Update the invocation counter |
210 if ((UseCompiler || CountCompiledCalls) && !method->is_synchronized()) { | |
211 InvocationCounter *counter = method->invocation_counter(); | |
212 counter->increment(); | |
213 if (counter->reached_InvocationLimit()) { | |
214 CALL_VM_NOCHECK( | |
215 InterpreterRuntime::frequency_counter_overflow(thread, NULL)); | |
216 if (HAS_PENDING_EXCEPTION) | |
217 goto unwind_and_return; | |
218 } | |
219 } | |
220 | |
1010 | 221 // Lock if necessary |
222 BasicObjectLock *monitor; | |
223 monitor = NULL; | |
224 if (method->is_synchronized()) { | |
225 monitor = (BasicObjectLock*) istate->stack_base(); | |
226 oop lockee = monitor->obj(); | |
227 markOop disp = lockee->mark()->set_unlocked(); | |
228 | |
229 monitor->lock()->set_displaced_header(disp); | |
230 if (Atomic::cmpxchg_ptr(monitor, lockee->mark_addr(), disp) != disp) { | |
231 if (thread->is_lock_owned((address) disp->clear_lock_bits())) { | |
232 monitor->lock()->set_displaced_header(NULL); | |
233 } | |
234 else { | |
235 CALL_VM_NOCHECK(InterpreterRuntime::monitorenter(thread, monitor)); | |
236 if (HAS_PENDING_EXCEPTION) | |
237 goto unwind_and_return; | |
238 } | |
239 } | |
240 } | |
241 | |
242 // Get the signature handler | |
243 InterpreterRuntime::SignatureHandler *handler; { | |
244 address handlerAddr = method->signature_handler(); | |
245 if (handlerAddr == NULL) { | |
246 CALL_VM_NOCHECK(InterpreterRuntime::prepare_native_call(thread, method)); | |
247 if (HAS_PENDING_EXCEPTION) | |
1139
b6f06e395428
6908267: Zero fails to unlock synchronized native methods on exception
never
parents:
1078
diff
changeset
|
248 goto unlock_unwind_and_return; |
1010 | 249 |
250 handlerAddr = method->signature_handler(); | |
251 assert(handlerAddr != NULL, "eh?"); | |
252 } | |
253 if (handlerAddr == (address) InterpreterRuntime::slow_signature_handler) { | |
254 CALL_VM_NOCHECK(handlerAddr = | |
255 InterpreterRuntime::slow_signature_handler(thread, method, NULL,NULL)); | |
256 if (HAS_PENDING_EXCEPTION) | |
1139
b6f06e395428
6908267: Zero fails to unlock synchronized native methods on exception
never
parents:
1078
diff
changeset
|
257 goto unlock_unwind_and_return; |
1010 | 258 } |
259 handler = \ | |
260 InterpreterRuntime::SignatureHandler::from_handlerAddr(handlerAddr); | |
261 } | |
262 | |
263 // Get the native function entry point | |
264 address function; | |
265 function = method->native_function(); | |
266 assert(function != NULL, "should be set if signature handler is"); | |
267 | |
268 // Build the argument list | |
1379 | 269 stack->overflow_check(handler->argument_count() * 2, THREAD); |
270 if (HAS_PENDING_EXCEPTION) | |
271 goto unlock_unwind_and_return; | |
272 | |
1010 | 273 void **arguments; |
274 void *mirror; { | |
275 arguments = | |
276 (void **) stack->alloc(handler->argument_count() * sizeof(void **)); | |
277 void **dst = arguments; | |
278 | |
279 void *env = thread->jni_environment(); | |
280 *(dst++) = &env; | |
281 | |
282 if (method->is_static()) { | |
283 istate->set_oop_temp( | |
2376
c7f3d0b4570f
7017732: move static fields into Class to prepare for perm gen removal
never
parents:
1972
diff
changeset
|
284 method->constants()->pool_holder()->java_mirror()); |
1010 | 285 mirror = istate->oop_temp_addr(); |
286 *(dst++) = &mirror; | |
287 } | |
288 | |
289 intptr_t *src = locals; | |
290 for (int i = dst - arguments; i < handler->argument_count(); i++) { | |
291 ffi_type *type = handler->argument_type(i); | |
292 if (type == &ffi_type_pointer) { | |
293 if (*src) { | |
294 stack->push((intptr_t) src); | |
295 *(dst++) = stack->sp(); | |
296 } | |
297 else { | |
298 *(dst++) = src; | |
299 } | |
300 src--; | |
301 } | |
302 else if (type->size == 4) { | |
303 *(dst++) = src--; | |
304 } | |
305 else if (type->size == 8) { | |
306 src--; | |
307 *(dst++) = src--; | |
308 } | |
309 else { | |
310 ShouldNotReachHere(); | |
311 } | |
312 } | |
313 } | |
314 | |
315 // Set up the Java frame anchor | |
316 thread->set_last_Java_frame(); | |
317 | |
318 // Change the thread state to _thread_in_native | |
319 ThreadStateTransition::transition_from_java(thread, _thread_in_native); | |
320 | |
321 // Make the call | |
322 intptr_t result[4 - LogBytesPerWord]; | |
323 ffi_call(handler->cif(), (void (*)()) function, result, arguments); | |
324 | |
325 // Change the thread state back to _thread_in_Java. | |
326 // ThreadStateTransition::transition_from_native() cannot be used | |
327 // here because it does not check for asynchronous exceptions. | |
328 // We have to manage the transition ourself. | |
329 thread->set_thread_state(_thread_in_native_trans); | |
330 | |
331 // Make sure new state is visible in the GC thread | |
332 if (os::is_MP()) { | |
333 if (UseMembar) { | |
334 OrderAccess::fence(); | |
335 } | |
336 else { | |
337 InterfaceSupport::serialize_memory(thread); | |
338 } | |
339 } | |
340 | |
341 // Handle safepoint operations, pending suspend requests, | |
342 // and pending asynchronous exceptions. | |
343 if (SafepointSynchronize::do_call_back() || | |
344 thread->has_special_condition_for_native_trans()) { | |
345 JavaThread::check_special_condition_for_native_trans(thread); | |
346 CHECK_UNHANDLED_OOPS_ONLY(thread->clear_unhandled_oops()); | |
347 } | |
348 | |
349 // Finally we can change the thread state to _thread_in_Java. | |
350 thread->set_thread_state(_thread_in_Java); | |
351 fixup_after_potential_safepoint(); | |
352 | |
353 // Clear the frame anchor | |
354 thread->reset_last_Java_frame(); | |
355 | |
356 // If the result was an oop then unbox it and store it in | |
357 // oop_temp where the garbage collector can see it before | |
358 // we release the handle it might be protected by. | |
359 if (handler->result_type() == &ffi_type_pointer) { | |
360 if (result[0]) | |
361 istate->set_oop_temp(*(oop *) result[0]); | |
362 else | |
363 istate->set_oop_temp(NULL); | |
364 } | |
365 | |
366 // Reset handle block | |
367 thread->active_handles()->clear(); | |
368 | |
1139
b6f06e395428
6908267: Zero fails to unlock synchronized native methods on exception
never
parents:
1078
diff
changeset
|
369 unlock_unwind_and_return: |
b6f06e395428
6908267: Zero fails to unlock synchronized native methods on exception
never
parents:
1078
diff
changeset
|
370 |
b6f06e395428
6908267: Zero fails to unlock synchronized native methods on exception
never
parents:
1078
diff
changeset
|
371 // Unlock if necessary |
b6f06e395428
6908267: Zero fails to unlock synchronized native methods on exception
never
parents:
1078
diff
changeset
|
372 if (monitor) { |
1010 | 373 BasicLock *lock = monitor->lock(); |
374 markOop header = lock->displaced_header(); | |
375 oop rcvr = monitor->obj(); | |
376 monitor->set_obj(NULL); | |
377 | |
378 if (header != NULL) { | |
379 if (Atomic::cmpxchg_ptr(header, rcvr->mark_addr(), lock) != lock) { | |
380 monitor->set_obj(rcvr); { | |
381 HandleMark hm(thread); | |
382 CALL_VM_NOCHECK(InterpreterRuntime::monitorexit(thread, monitor)); | |
383 } | |
384 } | |
385 } | |
386 } | |
387 | |
388 unwind_and_return: | |
389 | |
390 // Unwind the current activation | |
391 thread->pop_zero_frame(); | |
392 | |
393 // Pop our parameters | |
394 stack->set_sp(stack->sp() + method->size_of_parameters()); | |
395 | |
396 // Push our result | |
397 if (!HAS_PENDING_EXCEPTION) { | |
1256 | 398 BasicType type = result_type_of(method); |
399 stack->set_sp(stack->sp() - type2size[type]); | |
1010 | 400 |
1256 | 401 switch (type) { |
1010 | 402 case T_VOID: |
403 break; | |
404 | |
405 case T_BOOLEAN: | |
406 #ifndef VM_LITTLE_ENDIAN | |
407 result[0] <<= (BitsPerWord - BitsPerByte); | |
408 #endif | |
409 SET_LOCALS_INT(*(jboolean *) result != 0, 0); | |
410 break; | |
411 | |
412 case T_CHAR: | |
413 #ifndef VM_LITTLE_ENDIAN | |
414 result[0] <<= (BitsPerWord - BitsPerShort); | |
415 #endif | |
416 SET_LOCALS_INT(*(jchar *) result, 0); | |
417 break; | |
418 | |
419 case T_BYTE: | |
420 #ifndef VM_LITTLE_ENDIAN | |
421 result[0] <<= (BitsPerWord - BitsPerByte); | |
422 #endif | |
423 SET_LOCALS_INT(*(jbyte *) result, 0); | |
424 break; | |
425 | |
426 case T_SHORT: | |
427 #ifndef VM_LITTLE_ENDIAN | |
428 result[0] <<= (BitsPerWord - BitsPerShort); | |
429 #endif | |
430 SET_LOCALS_INT(*(jshort *) result, 0); | |
431 break; | |
432 | |
433 case T_INT: | |
434 #ifndef VM_LITTLE_ENDIAN | |
435 result[0] <<= (BitsPerWord - BitsPerInt); | |
436 #endif | |
437 SET_LOCALS_INT(*(jint *) result, 0); | |
438 break; | |
439 | |
440 case T_LONG: | |
441 SET_LOCALS_LONG(*(jlong *) result, 0); | |
442 break; | |
443 | |
444 case T_FLOAT: | |
445 SET_LOCALS_FLOAT(*(jfloat *) result, 0); | |
446 break; | |
447 | |
448 case T_DOUBLE: | |
449 SET_LOCALS_DOUBLE(*(jdouble *) result, 0); | |
450 break; | |
451 | |
452 case T_OBJECT: | |
453 case T_ARRAY: | |
454 SET_LOCALS_OBJECT(istate->oop_temp(), 0); | |
455 break; | |
456 | |
457 default: | |
458 ShouldNotReachHere(); | |
459 } | |
460 } | |
1514 | 461 |
462 // No deoptimized frames on the stack | |
463 return 0; | |
1010 | 464 } |
465 | |
1514 | 466 int CppInterpreter::accessor_entry(methodOop method, intptr_t UNUSED, TRAPS) { |
1010 | 467 JavaThread *thread = (JavaThread *) THREAD; |
468 ZeroStack *stack = thread->zero_stack(); | |
469 intptr_t *locals = stack->sp(); | |
470 | |
471 // Drop into the slow path if we need a safepoint check | |
472 if (SafepointSynchronize::do_call_back()) { | |
1514 | 473 return normal_entry(method, 0, THREAD); |
1010 | 474 } |
475 | |
476 // Load the object pointer and drop into the slow path | |
477 // if we have a NullPointerException | |
478 oop object = LOCALS_OBJECT(0); | |
479 if (object == NULL) { | |
1514 | 480 return normal_entry(method, 0, THREAD); |
1010 | 481 } |
482 | |
483 // Read the field index from the bytecode, which looks like this: | |
484 // 0: aload_0 | |
485 // 1: getfield | |
486 // 2: index | |
487 // 3: index | |
488 // 4: ireturn/areturn | |
489 // NB this is not raw bytecode: index is in machine order | |
490 u1 *code = method->code_base(); | |
491 assert(code[0] == Bytecodes::_aload_0 && | |
492 code[1] == Bytecodes::_getfield && | |
493 (code[4] == Bytecodes::_ireturn || | |
494 code[4] == Bytecodes::_areturn), "should do"); | |
495 u2 index = Bytes::get_native_u2(&code[2]); | |
496 | |
497 // Get the entry from the constant pool cache, and drop into | |
498 // the slow path if it has not been resolved | |
499 constantPoolCacheOop cache = method->constants()->cache(); | |
500 ConstantPoolCacheEntry* entry = cache->entry_at(index); | |
501 if (!entry->is_resolved(Bytecodes::_getfield)) { | |
1514 | 502 return normal_entry(method, 0, THREAD); |
1010 | 503 } |
504 | |
505 // Get the result and push it onto the stack | |
506 switch (entry->flag_state()) { | |
507 case ltos: | |
508 case dtos: | |
1514 | 509 stack->overflow_check(1, CHECK_0); |
1010 | 510 stack->alloc(wordSize); |
511 break; | |
512 } | |
513 if (entry->is_volatile()) { | |
514 switch (entry->flag_state()) { | |
515 case ctos: | |
516 SET_LOCALS_INT(object->char_field_acquire(entry->f2()), 0); | |
517 break; | |
518 | |
519 case btos: | |
520 SET_LOCALS_INT(object->byte_field_acquire(entry->f2()), 0); | |
521 break; | |
522 | |
523 case stos: | |
524 SET_LOCALS_INT(object->short_field_acquire(entry->f2()), 0); | |
525 break; | |
526 | |
527 case itos: | |
528 SET_LOCALS_INT(object->int_field_acquire(entry->f2()), 0); | |
529 break; | |
530 | |
531 case ltos: | |
532 SET_LOCALS_LONG(object->long_field_acquire(entry->f2()), 0); | |
533 break; | |
534 | |
535 case ftos: | |
536 SET_LOCALS_FLOAT(object->float_field_acquire(entry->f2()), 0); | |
537 break; | |
538 | |
539 case dtos: | |
540 SET_LOCALS_DOUBLE(object->double_field_acquire(entry->f2()), 0); | |
541 break; | |
542 | |
543 case atos: | |
544 SET_LOCALS_OBJECT(object->obj_field_acquire(entry->f2()), 0); | |
545 break; | |
546 | |
547 default: | |
548 ShouldNotReachHere(); | |
549 } | |
550 } | |
551 else { | |
552 switch (entry->flag_state()) { | |
553 case ctos: | |
554 SET_LOCALS_INT(object->char_field(entry->f2()), 0); | |
555 break; | |
556 | |
557 case btos: | |
558 SET_LOCALS_INT(object->byte_field(entry->f2()), 0); | |
559 break; | |
560 | |
561 case stos: | |
562 SET_LOCALS_INT(object->short_field(entry->f2()), 0); | |
563 break; | |
564 | |
565 case itos: | |
566 SET_LOCALS_INT(object->int_field(entry->f2()), 0); | |
567 break; | |
568 | |
569 case ltos: | |
570 SET_LOCALS_LONG(object->long_field(entry->f2()), 0); | |
571 break; | |
572 | |
573 case ftos: | |
574 SET_LOCALS_FLOAT(object->float_field(entry->f2()), 0); | |
575 break; | |
576 | |
577 case dtos: | |
578 SET_LOCALS_DOUBLE(object->double_field(entry->f2()), 0); | |
579 break; | |
580 | |
581 case atos: | |
582 SET_LOCALS_OBJECT(object->obj_field(entry->f2()), 0); | |
583 break; | |
584 | |
585 default: | |
586 ShouldNotReachHere(); | |
587 } | |
588 } | |
1514 | 589 |
590 // No deoptimized frames on the stack | |
591 return 0; | |
1010 | 592 } |
593 | |
1514 | 594 int CppInterpreter::empty_entry(methodOop method, intptr_t UNUSED, TRAPS) { |
1010 | 595 JavaThread *thread = (JavaThread *) THREAD; |
596 ZeroStack *stack = thread->zero_stack(); | |
597 | |
598 // Drop into the slow path if we need a safepoint check | |
599 if (SafepointSynchronize::do_call_back()) { | |
1514 | 600 return normal_entry(method, 0, THREAD); |
1010 | 601 } |
602 | |
603 // Pop our parameters | |
604 stack->set_sp(stack->sp() + method->size_of_parameters()); | |
1514 | 605 |
606 // No deoptimized frames on the stack | |
607 return 0; | |
1010 | 608 } |
609 | |
1379 | 610 InterpreterFrame *InterpreterFrame::build(const methodOop method, TRAPS) { |
611 JavaThread *thread = (JavaThread *) THREAD; | |
612 ZeroStack *stack = thread->zero_stack(); | |
613 | |
614 // Calculate the size of the frame we'll build, including | |
615 // any adjustments to the caller's frame that we'll make. | |
616 int extra_locals = 0; | |
617 int monitor_words = 0; | |
618 int stack_words = 0; | |
1010 | 619 |
1379 | 620 if (!method->is_native()) { |
621 extra_locals = method->max_locals() - method->size_of_parameters(); | |
622 stack_words = method->max_stack(); | |
1010 | 623 } |
1379 | 624 if (method->is_synchronized()) { |
625 monitor_words = frame::interpreter_frame_monitor_size(); | |
626 } | |
627 stack->overflow_check( | |
628 extra_locals + header_words + monitor_words + stack_words, CHECK_NULL); | |
1010 | 629 |
1379 | 630 // Adjust the caller's stack frame to accomodate any additional |
631 // local variables we have contiguously with our parameters. | |
632 for (int i = 0; i < extra_locals; i++) | |
633 stack->push(0); | |
1010 | 634 |
635 intptr_t *locals; | |
636 if (method->is_native()) | |
637 locals = stack->sp() + (method->size_of_parameters() - 1); | |
638 else | |
639 locals = stack->sp() + (method->max_locals() - 1); | |
640 | |
641 stack->push(0); // next_frame, filled in later | |
642 intptr_t *fp = stack->sp(); | |
643 assert(fp - stack->sp() == next_frame_off, "should be"); | |
644 | |
645 stack->push(INTERPRETER_FRAME); | |
646 assert(fp - stack->sp() == frame_type_off, "should be"); | |
647 | |
648 interpreterState istate = | |
649 (interpreterState) stack->alloc(sizeof(BytecodeInterpreter)); | |
650 assert(fp - stack->sp() == istate_off, "should be"); | |
651 | |
652 istate->set_locals(locals); | |
653 istate->set_method(method); | |
654 istate->set_self_link(istate); | |
655 istate->set_prev_link(NULL); | |
656 istate->set_thread(thread); | |
657 istate->set_bcp(method->is_native() ? NULL : method->code_base()); | |
658 istate->set_constants(method->constants()->cache()); | |
659 istate->set_msg(BytecodeInterpreter::method_entry); | |
660 istate->set_oop_temp(NULL); | |
661 istate->set_mdx(NULL); | |
662 istate->set_callee(NULL); | |
663 | |
664 istate->set_monitor_base((BasicObjectLock *) stack->sp()); | |
665 if (method->is_synchronized()) { | |
666 BasicObjectLock *monitor = | |
667 (BasicObjectLock *) stack->alloc(monitor_words * wordSize); | |
668 oop object; | |
669 if (method->is_static()) | |
2376
c7f3d0b4570f
7017732: move static fields into Class to prepare for perm gen removal
never
parents:
1972
diff
changeset
|
670 object = method->constants()->pool_holder()->java_mirror(); |
1010 | 671 else |
672 object = (oop) locals[0]; | |
673 monitor->set_obj(object); | |
674 } | |
675 | |
676 istate->set_stack_base(stack->sp()); | |
677 istate->set_stack(stack->sp() - 1); | |
678 if (stack_words) | |
679 stack->alloc(stack_words * wordSize); | |
680 istate->set_stack_limit(stack->sp() - 1); | |
681 | |
682 return (InterpreterFrame *) fp; | |
683 } | |
684 | |
685 int AbstractInterpreter::BasicType_as_index(BasicType type) { | |
686 int i = 0; | |
687 switch (type) { | |
688 case T_BOOLEAN: i = 0; break; | |
689 case T_CHAR : i = 1; break; | |
690 case T_BYTE : i = 2; break; | |
691 case T_SHORT : i = 3; break; | |
692 case T_INT : i = 4; break; | |
693 case T_LONG : i = 5; break; | |
694 case T_VOID : i = 6; break; | |
695 case T_FLOAT : i = 7; break; | |
696 case T_DOUBLE : i = 8; break; | |
697 case T_OBJECT : i = 9; break; | |
698 case T_ARRAY : i = 9; break; | |
699 default : ShouldNotReachHere(); | |
700 } | |
701 assert(0 <= i && i < AbstractInterpreter::number_of_result_handlers, | |
702 "index out of bounds"); | |
703 return i; | |
704 } | |
705 | |
1256 | 706 BasicType CppInterpreter::result_type_of(methodOop method) { |
707 BasicType t; | |
708 switch (method->result_index()) { | |
709 case 0 : t = T_BOOLEAN; break; | |
710 case 1 : t = T_CHAR; break; | |
711 case 2 : t = T_BYTE; break; | |
712 case 3 : t = T_SHORT; break; | |
713 case 4 : t = T_INT; break; | |
714 case 5 : t = T_LONG; break; | |
715 case 6 : t = T_VOID; break; | |
716 case 7 : t = T_FLOAT; break; | |
717 case 8 : t = T_DOUBLE; break; | |
718 case 9 : t = T_OBJECT; break; | |
719 default: ShouldNotReachHere(); | |
720 } | |
721 assert(AbstractInterpreter::BasicType_as_index(t) == method->result_index(), | |
722 "out of step with AbstractInterpreter::BasicType_as_index"); | |
723 return t; | |
724 } | |
725 | |
1010 | 726 address InterpreterGenerator::generate_empty_entry() { |
727 if (!UseFastEmptyMethods) | |
728 return NULL; | |
729 | |
730 return generate_entry((address) CppInterpreter::empty_entry); | |
731 } | |
732 | |
733 address InterpreterGenerator::generate_accessor_entry() { | |
734 if (!UseFastAccessorMethods) | |
735 return NULL; | |
736 | |
737 return generate_entry((address) CppInterpreter::accessor_entry); | |
738 } | |
739 | |
3249
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2376
diff
changeset
|
740 address InterpreterGenerator::generate_Reference_get_entry(void) { |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2376
diff
changeset
|
741 #ifndef SERIALGC |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2376
diff
changeset
|
742 if (UseG1GC) { |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2376
diff
changeset
|
743 // We need to generate have a routine that generates code to: |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2376
diff
changeset
|
744 // * load the value in the referent field |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2376
diff
changeset
|
745 // * passes that value to the pre-barrier. |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2376
diff
changeset
|
746 // |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2376
diff
changeset
|
747 // In the case of G1 this will record the value of the |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2376
diff
changeset
|
748 // referent in an SATB buffer if marking is active. |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2376
diff
changeset
|
749 // This will cause concurrent marking to mark the referent |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2376
diff
changeset
|
750 // field as live. |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2376
diff
changeset
|
751 Unimplemented(); |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2376
diff
changeset
|
752 } |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2376
diff
changeset
|
753 #endif // SERIALGC |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2376
diff
changeset
|
754 |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2376
diff
changeset
|
755 // If G1 is not enabled then attempt to go through the accessor entry point |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2376
diff
changeset
|
756 // Reference.get is an accessor |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2376
diff
changeset
|
757 return generate_accessor_entry(); |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2376
diff
changeset
|
758 } |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2376
diff
changeset
|
759 |
1010 | 760 address InterpreterGenerator::generate_native_entry(bool synchronized) { |
761 assert(synchronized == false, "should be"); | |
762 | |
763 return generate_entry((address) CppInterpreter::native_entry); | |
764 } | |
765 | |
766 address InterpreterGenerator::generate_normal_entry(bool synchronized) { | |
767 assert(synchronized == false, "should be"); | |
768 | |
769 return generate_entry((address) CppInterpreter::normal_entry); | |
770 } | |
771 | |
772 address AbstractInterpreterGenerator::generate_method_entry( | |
773 AbstractInterpreter::MethodKind kind) { | |
774 address entry_point = NULL; | |
775 | |
776 switch (kind) { | |
777 case Interpreter::zerolocals: | |
778 case Interpreter::zerolocals_synchronized: | |
779 break; | |
780 | |
781 case Interpreter::native: | |
782 entry_point = ((InterpreterGenerator*) this)->generate_native_entry(false); | |
783 break; | |
784 | |
785 case Interpreter::native_synchronized: | |
786 entry_point = ((InterpreterGenerator*) this)->generate_native_entry(false); | |
787 break; | |
788 | |
789 case Interpreter::empty: | |
790 entry_point = ((InterpreterGenerator*) this)->generate_empty_entry(); | |
791 break; | |
792 | |
793 case Interpreter::accessor: | |
794 entry_point = ((InterpreterGenerator*) this)->generate_accessor_entry(); | |
795 break; | |
796 | |
797 case Interpreter::abstract: | |
798 entry_point = ((InterpreterGenerator*) this)->generate_abstract_entry(); | |
799 break; | |
800 | |
801 case Interpreter::method_handle: | |
802 entry_point = ((InterpreterGenerator*) this)->generate_method_handle_entry(); | |
803 break; | |
804 | |
805 case Interpreter::java_lang_math_sin: | |
806 case Interpreter::java_lang_math_cos: | |
807 case Interpreter::java_lang_math_tan: | |
808 case Interpreter::java_lang_math_abs: | |
809 case Interpreter::java_lang_math_log: | |
810 case Interpreter::java_lang_math_log10: | |
811 case Interpreter::java_lang_math_sqrt: | |
812 entry_point = ((InterpreterGenerator*) this)->generate_math_entry(kind); | |
813 break; | |
814 | |
3249
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2376
diff
changeset
|
815 case Interpreter::java_lang_ref_reference_get: |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2376
diff
changeset
|
816 entry_point = ((InterpreterGenerator*)this)->generate_Reference_get_entry(); |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2376
diff
changeset
|
817 break; |
e1162778c1c8
7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents:
2376
diff
changeset
|
818 |
1010 | 819 default: |
820 ShouldNotReachHere(); | |
821 } | |
822 | |
823 if (entry_point == NULL) | |
824 entry_point = ((InterpreterGenerator*) this)->generate_normal_entry(false); | |
825 | |
826 return entry_point; | |
827 } | |
828 | |
829 InterpreterGenerator::InterpreterGenerator(StubQueue* code) | |
830 : CppInterpreterGenerator(code) { | |
831 generate_all(); | |
832 } | |
833 | |
834 // Deoptimization helpers | |
835 | |
1379 | 836 InterpreterFrame *InterpreterFrame::build(int size, TRAPS) { |
837 ZeroStack *stack = ((JavaThread *) THREAD)->zero_stack(); | |
838 | |
1010 | 839 int size_in_words = size >> LogBytesPerWord; |
840 assert(size_in_words * wordSize == size, "unaligned"); | |
841 assert(size_in_words >= header_words, "too small"); | |
1379 | 842 stack->overflow_check(size_in_words, CHECK_NULL); |
1010 | 843 |
844 stack->push(0); // next_frame, filled in later | |
845 intptr_t *fp = stack->sp(); | |
846 assert(fp - stack->sp() == next_frame_off, "should be"); | |
847 | |
848 stack->push(INTERPRETER_FRAME); | |
849 assert(fp - stack->sp() == frame_type_off, "should be"); | |
850 | |
851 interpreterState istate = | |
852 (interpreterState) stack->alloc(sizeof(BytecodeInterpreter)); | |
853 assert(fp - stack->sp() == istate_off, "should be"); | |
854 istate->set_self_link(NULL); // mark invalid | |
855 | |
856 stack->alloc((size_in_words - header_words) * wordSize); | |
857 | |
858 return (InterpreterFrame *) fp; | |
859 } | |
860 | |
861 int AbstractInterpreter::layout_activation(methodOop method, | |
862 int tempcount, | |
863 int popframe_extra_args, | |
864 int moncount, | |
865 int callee_param_count, | |
866 int callee_locals, | |
867 frame* caller, | |
868 frame* interpreter_frame, | |
869 bool is_top_frame) { | |
870 assert(popframe_extra_args == 0, "what to do?"); | |
871 assert(!is_top_frame || (!callee_locals && !callee_param_count), | |
1605 | 872 "top frame should have no caller"); |
1010 | 873 |
874 // This code must exactly match what InterpreterFrame::build | |
875 // does (the full InterpreterFrame::build, that is, not the | |
876 // one that creates empty frames for the deoptimizer). | |
877 // | |
878 // If interpreter_frame is not NULL then it will be filled in. | |
879 // It's size is determined by a previous call to this method, | |
880 // so it should be correct. | |
881 // | |
882 // Note that tempcount is the current size of the expression | |
883 // stack. For top most frames we will allocate a full sized | |
884 // expression stack and not the trimmed version that non-top | |
885 // frames have. | |
886 | |
887 int header_words = InterpreterFrame::header_words; | |
888 int monitor_words = moncount * frame::interpreter_frame_monitor_size(); | |
889 int stack_words = is_top_frame ? method->max_stack() : tempcount; | |
890 int callee_extra_locals = callee_locals - callee_param_count; | |
891 | |
892 if (interpreter_frame) { | |
1505 | 893 intptr_t *locals = interpreter_frame->fp() + method->max_locals(); |
1010 | 894 interpreterState istate = interpreter_frame->get_interpreterState(); |
895 intptr_t *monitor_base = (intptr_t*) istate; | |
896 intptr_t *stack_base = monitor_base - monitor_words; | |
897 intptr_t *stack = stack_base - tempcount - 1; | |
898 | |
899 BytecodeInterpreter::layout_interpreterState(istate, | |
900 caller, | |
901 NULL, | |
902 method, | |
903 locals, | |
904 stack, | |
905 stack_base, | |
906 monitor_base, | |
907 NULL, | |
908 is_top_frame); | |
909 } | |
910 return header_words + monitor_words + stack_words + callee_extra_locals; | |
911 } | |
912 | |
913 void BytecodeInterpreter::layout_interpreterState(interpreterState istate, | |
914 frame* caller, | |
915 frame* current, | |
916 methodOop method, | |
917 intptr_t* locals, | |
918 intptr_t* stack, | |
919 intptr_t* stack_base, | |
920 intptr_t* monitor_base, | |
921 intptr_t* frame_bottom, | |
922 bool is_top_frame) { | |
923 istate->set_locals(locals); | |
924 istate->set_method(method); | |
925 istate->set_self_link(istate); | |
926 istate->set_prev_link(NULL); | |
927 // thread will be set by a hacky repurposing of frame::patch_pc() | |
928 // bcp will be set by vframeArrayElement::unpack_on_stack() | |
929 istate->set_constants(method->constants()->cache()); | |
930 istate->set_msg(BytecodeInterpreter::method_resume); | |
931 istate->set_bcp_advance(0); | |
932 istate->set_oop_temp(NULL); | |
933 istate->set_mdx(NULL); | |
934 if (caller->is_interpreted_frame()) { | |
935 interpreterState prev = caller->get_interpreterState(); | |
936 prev->set_callee(method); | |
937 if (*prev->bcp() == Bytecodes::_invokeinterface) | |
938 prev->set_bcp_advance(5); | |
939 else | |
940 prev->set_bcp_advance(3); | |
941 } | |
942 istate->set_callee(NULL); | |
943 istate->set_monitor_base((BasicObjectLock *) monitor_base); | |
944 istate->set_stack_base(stack_base); | |
945 istate->set_stack(stack); | |
946 istate->set_stack_limit(stack_base - method->max_stack() - 1); | |
947 } | |
948 | |
949 address CppInterpreter::return_entry(TosState state, int length) { | |
950 ShouldNotCallThis(); | |
951 } | |
952 | |
953 address CppInterpreter::deopt_entry(TosState state, int length) { | |
954 return NULL; | |
955 } | |
956 | |
957 // Helper for (runtime) stack overflow checks | |
958 | |
959 int AbstractInterpreter::size_top_interpreter_activation(methodOop method) { | |
960 return 0; | |
961 } | |
962 | |
963 // Helper for figuring out if frames are interpreter frames | |
964 | |
965 bool CppInterpreter::contains(address pc) { | |
966 #ifdef PRODUCT | |
967 ShouldNotCallThis(); | |
968 #else | |
969 return false; // make frame::print_value_on work | |
970 #endif // !PRODUCT | |
971 } | |
972 | |
973 // Result handlers and convertors | |
974 | |
975 address CppInterpreterGenerator::generate_result_handler_for( | |
976 BasicType type) { | |
977 assembler()->advance(1); | |
978 return ShouldNotCallThisStub(); | |
979 } | |
980 | |
981 address CppInterpreterGenerator::generate_tosca_to_stack_converter( | |
982 BasicType type) { | |
983 assembler()->advance(1); | |
984 return ShouldNotCallThisStub(); | |
985 } | |
986 | |
987 address CppInterpreterGenerator::generate_stack_to_stack_converter( | |
988 BasicType type) { | |
989 assembler()->advance(1); | |
990 return ShouldNotCallThisStub(); | |
991 } | |
992 | |
993 address CppInterpreterGenerator::generate_stack_to_native_abi_converter( | |
994 BasicType type) { | |
995 assembler()->advance(1); | |
996 return ShouldNotCallThisStub(); | |
997 } | |
998 | |
999 #endif // CC_INTERP |