Wed, 27 Apr 2016 01:25:04 +0800
Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17
1 /*
2 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
3 * Copyright 2007, 2008, 2009, 2010, 2011 Red Hat, Inc.
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 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 *
24 */
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/methodData.hpp"
35 #include "oops/method.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 #include "utilities/macros.hpp"
51 #ifdef SHARK
52 #include "shark/shark_globals.hpp"
53 #endif
55 #ifdef CC_INTERP
57 #define fixup_after_potential_safepoint() \
58 method = istate->method()
60 #define CALL_VM_NOCHECK_NOFIX(func) \
61 thread->set_last_Java_frame(); \
62 func; \
63 thread->reset_last_Java_frame();
65 #define CALL_VM_NOCHECK(func) \
66 CALL_VM_NOCHECK_NOFIX(func) \
67 fixup_after_potential_safepoint()
69 int CppInterpreter::normal_entry(Method* method, intptr_t UNUSED, TRAPS) {
70 JavaThread *thread = (JavaThread *) THREAD;
72 // Allocate and initialize our frame.
73 InterpreterFrame *frame = InterpreterFrame::build(method, CHECK_0);
74 thread->push_zero_frame(frame);
76 // Execute those bytecodes!
77 main_loop(0, THREAD);
79 // No deoptimized frames on the stack
80 return 0;
81 }
83 void CppInterpreter::main_loop(int recurse, TRAPS) {
84 JavaThread *thread = (JavaThread *) THREAD;
85 ZeroStack *stack = thread->zero_stack();
87 // If we are entering from a deopt we may need to call
88 // ourself a few times in order to get to our frame.
89 if (recurse)
90 main_loop(recurse - 1, THREAD);
92 InterpreterFrame *frame = thread->top_zero_frame()->as_interpreter_frame();
93 interpreterState istate = frame->interpreter_state();
94 Method* method = istate->method();
96 intptr_t *result = NULL;
97 int result_slots = 0;
99 while (true) {
100 // We can set up the frame anchor with everything we want at
101 // this point as we are thread_in_Java and no safepoints can
102 // occur until we go to vm mode. We do have to clear flags
103 // on return from vm but that is it.
104 thread->set_last_Java_frame();
106 // Call the interpreter
107 if (JvmtiExport::can_post_interpreter_events())
108 BytecodeInterpreter::runWithChecks(istate);
109 else
110 BytecodeInterpreter::run(istate);
111 fixup_after_potential_safepoint();
113 // Clear the frame anchor
114 thread->reset_last_Java_frame();
116 // Examine the message from the interpreter to decide what to do
117 if (istate->msg() == BytecodeInterpreter::call_method) {
118 Method* callee = istate->callee();
120 // Trim back the stack to put the parameters at the top
121 stack->set_sp(istate->stack() + 1);
123 // Make the call
124 Interpreter::invoke_method(callee, istate->callee_entry_point(), THREAD);
125 fixup_after_potential_safepoint();
127 // Convert the result
128 istate->set_stack(stack->sp() - 1);
130 // Restore the stack
131 stack->set_sp(istate->stack_limit() + 1);
133 // Resume the interpreter
134 istate->set_msg(BytecodeInterpreter::method_resume);
135 }
136 else if (istate->msg() == BytecodeInterpreter::more_monitors) {
137 int monitor_words = frame::interpreter_frame_monitor_size();
139 // Allocate the space
140 stack->overflow_check(monitor_words, THREAD);
141 if (HAS_PENDING_EXCEPTION)
142 break;
143 stack->alloc(monitor_words * wordSize);
145 // Move the expression stack contents
146 for (intptr_t *p = istate->stack() + 1; p < istate->stack_base(); p++)
147 *(p - monitor_words) = *p;
149 // Move the expression stack pointers
150 istate->set_stack_limit(istate->stack_limit() - monitor_words);
151 istate->set_stack(istate->stack() - monitor_words);
152 istate->set_stack_base(istate->stack_base() - monitor_words);
154 // Zero the new monitor so the interpreter can find it.
155 ((BasicObjectLock *) istate->stack_base())->set_obj(NULL);
157 // Resume the interpreter
158 istate->set_msg(BytecodeInterpreter::got_monitors);
159 }
160 else if (istate->msg() == BytecodeInterpreter::return_from_method) {
161 // Copy the result into the caller's frame
162 result_slots = type2size[result_type_of(method)];
163 assert(result_slots >= 0 && result_slots <= 2, "what?");
164 result = istate->stack() + result_slots;
165 break;
166 }
167 else if (istate->msg() == BytecodeInterpreter::throwing_exception) {
168 assert(HAS_PENDING_EXCEPTION, "should do");
169 break;
170 }
171 else if (istate->msg() == BytecodeInterpreter::do_osr) {
172 // Unwind the current frame
173 thread->pop_zero_frame();
175 // Remove any extension of the previous frame
176 int extra_locals = method->max_locals() - method->size_of_parameters();
177 stack->set_sp(stack->sp() + extra_locals);
179 // Jump into the OSR method
180 Interpreter::invoke_osr(
181 method, istate->osr_entry(), istate->osr_buf(), THREAD);
182 return;
183 }
184 else {
185 ShouldNotReachHere();
186 }
187 }
189 // Unwind the current frame
190 thread->pop_zero_frame();
192 // Pop our local variables
193 stack->set_sp(stack->sp() + method->max_locals());
195 // Push our result
196 for (int i = 0; i < result_slots; i++)
197 stack->push(result[-i]);
198 }
200 int CppInterpreter::native_entry(Method* method, intptr_t UNUSED, TRAPS) {
201 // Make sure method is native and not abstract
202 assert(method->is_native() && !method->is_abstract(), "should be");
204 JavaThread *thread = (JavaThread *) THREAD;
205 ZeroStack *stack = thread->zero_stack();
207 // Allocate and initialize our frame
208 InterpreterFrame *frame = InterpreterFrame::build(method, CHECK_0);
209 thread->push_zero_frame(frame);
210 interpreterState istate = frame->interpreter_state();
211 intptr_t *locals = istate->locals();
213 // Update the invocation counter
214 if ((UseCompiler || CountCompiledCalls) && !method->is_synchronized()) {
215 MethodCounters* mcs = method->method_counters();
216 if (mcs == NULL) {
217 CALL_VM_NOCHECK(mcs = InterpreterRuntime::build_method_counters(thread, method));
218 if (HAS_PENDING_EXCEPTION)
219 goto unwind_and_return;
220 }
221 InvocationCounter *counter = mcs->invocation_counter();
222 counter->increment();
223 if (counter->reached_InvocationLimit(mcs->backedge_counter())) {
224 CALL_VM_NOCHECK(
225 InterpreterRuntime::frequency_counter_overflow(thread, NULL));
226 if (HAS_PENDING_EXCEPTION)
227 goto unwind_and_return;
228 }
229 }
231 // Lock if necessary
232 BasicObjectLock *monitor;
233 monitor = NULL;
234 if (method->is_synchronized()) {
235 monitor = (BasicObjectLock*) istate->stack_base();
236 oop lockee = monitor->obj();
237 markOop disp = lockee->mark()->set_unlocked();
239 monitor->lock()->set_displaced_header(disp);
240 if (Atomic::cmpxchg_ptr(monitor, lockee->mark_addr(), disp) != disp) {
241 if (thread->is_lock_owned((address) disp->clear_lock_bits())) {
242 monitor->lock()->set_displaced_header(NULL);
243 }
244 else {
245 CALL_VM_NOCHECK(InterpreterRuntime::monitorenter(thread, monitor));
246 if (HAS_PENDING_EXCEPTION)
247 goto unwind_and_return;
248 }
249 }
250 }
252 // Get the signature handler
253 InterpreterRuntime::SignatureHandler *handler; {
254 address handlerAddr = method->signature_handler();
255 if (handlerAddr == NULL) {
256 CALL_VM_NOCHECK(InterpreterRuntime::prepare_native_call(thread, method));
257 if (HAS_PENDING_EXCEPTION)
258 goto unlock_unwind_and_return;
260 handlerAddr = method->signature_handler();
261 assert(handlerAddr != NULL, "eh?");
262 }
263 if (handlerAddr == (address) InterpreterRuntime::slow_signature_handler) {
264 CALL_VM_NOCHECK(handlerAddr =
265 InterpreterRuntime::slow_signature_handler(thread, method, NULL,NULL));
266 if (HAS_PENDING_EXCEPTION)
267 goto unlock_unwind_and_return;
268 }
269 handler = \
270 InterpreterRuntime::SignatureHandler::from_handlerAddr(handlerAddr);
271 }
273 // Get the native function entry point
274 address function;
275 function = method->native_function();
276 assert(function != NULL, "should be set if signature handler is");
278 // Build the argument list
279 stack->overflow_check(handler->argument_count() * 2, THREAD);
280 if (HAS_PENDING_EXCEPTION)
281 goto unlock_unwind_and_return;
283 void **arguments;
284 void *mirror; {
285 arguments =
286 (void **) stack->alloc(handler->argument_count() * sizeof(void **));
287 void **dst = arguments;
289 void *env = thread->jni_environment();
290 *(dst++) = &env;
292 if (method->is_static()) {
293 istate->set_oop_temp(
294 method->constants()->pool_holder()->java_mirror());
295 mirror = istate->oop_temp_addr();
296 *(dst++) = &mirror;
297 }
299 intptr_t *src = locals;
300 for (int i = dst - arguments; i < handler->argument_count(); i++) {
301 ffi_type *type = handler->argument_type(i);
302 if (type == &ffi_type_pointer) {
303 if (*src) {
304 stack->push((intptr_t) src);
305 *(dst++) = stack->sp();
306 }
307 else {
308 *(dst++) = src;
309 }
310 src--;
311 }
312 else if (type->size == 4) {
313 *(dst++) = src--;
314 }
315 else if (type->size == 8) {
316 src--;
317 *(dst++) = src--;
318 }
319 else {
320 ShouldNotReachHere();
321 }
322 }
323 }
325 // Set up the Java frame anchor
326 thread->set_last_Java_frame();
328 // Change the thread state to _thread_in_native
329 ThreadStateTransition::transition_from_java(thread, _thread_in_native);
331 // Make the call
332 intptr_t result[4 - LogBytesPerWord];
333 ffi_call(handler->cif(), (void (*)()) function, result, arguments);
335 // Change the thread state back to _thread_in_Java.
336 // ThreadStateTransition::transition_from_native() cannot be used
337 // here because it does not check for asynchronous exceptions.
338 // We have to manage the transition ourself.
339 thread->set_thread_state(_thread_in_native_trans);
341 // Make sure new state is visible in the GC thread
342 if (os::is_MP()) {
343 if (UseMembar) {
344 OrderAccess::fence();
345 }
346 else {
347 InterfaceSupport::serialize_memory(thread);
348 }
349 }
351 // Handle safepoint operations, pending suspend requests,
352 // and pending asynchronous exceptions.
353 if (SafepointSynchronize::do_call_back() ||
354 thread->has_special_condition_for_native_trans()) {
355 JavaThread::check_special_condition_for_native_trans(thread);
356 CHECK_UNHANDLED_OOPS_ONLY(thread->clear_unhandled_oops());
357 }
359 // Finally we can change the thread state to _thread_in_Java.
360 thread->set_thread_state(_thread_in_Java);
361 fixup_after_potential_safepoint();
363 // Clear the frame anchor
364 thread->reset_last_Java_frame();
366 // If the result was an oop then unbox it and store it in
367 // oop_temp where the garbage collector can see it before
368 // we release the handle it might be protected by.
369 if (handler->result_type() == &ffi_type_pointer) {
370 if (result[0])
371 istate->set_oop_temp(*(oop *) result[0]);
372 else
373 istate->set_oop_temp(NULL);
374 }
376 // Reset handle block
377 thread->active_handles()->clear();
379 unlock_unwind_and_return:
381 // Unlock if necessary
382 if (monitor) {
383 BasicLock *lock = monitor->lock();
384 markOop header = lock->displaced_header();
385 oop rcvr = monitor->obj();
386 monitor->set_obj(NULL);
388 if (header != NULL) {
389 if (Atomic::cmpxchg_ptr(header, rcvr->mark_addr(), lock) != lock) {
390 monitor->set_obj(rcvr); {
391 HandleMark hm(thread);
392 CALL_VM_NOCHECK(InterpreterRuntime::monitorexit(thread, monitor));
393 }
394 }
395 }
396 }
398 unwind_and_return:
400 // Unwind the current activation
401 thread->pop_zero_frame();
403 // Pop our parameters
404 stack->set_sp(stack->sp() + method->size_of_parameters());
406 // Push our result
407 if (!HAS_PENDING_EXCEPTION) {
408 BasicType type = result_type_of(method);
409 stack->set_sp(stack->sp() - type2size[type]);
411 switch (type) {
412 case T_VOID:
413 break;
415 case T_BOOLEAN:
416 #ifndef VM_LITTLE_ENDIAN
417 result[0] <<= (BitsPerWord - BitsPerByte);
418 #endif
419 SET_LOCALS_INT(*(jboolean *) result != 0, 0);
420 break;
422 case T_CHAR:
423 #ifndef VM_LITTLE_ENDIAN
424 result[0] <<= (BitsPerWord - BitsPerShort);
425 #endif
426 SET_LOCALS_INT(*(jchar *) result, 0);
427 break;
429 case T_BYTE:
430 #ifndef VM_LITTLE_ENDIAN
431 result[0] <<= (BitsPerWord - BitsPerByte);
432 #endif
433 SET_LOCALS_INT(*(jbyte *) result, 0);
434 break;
436 case T_SHORT:
437 #ifndef VM_LITTLE_ENDIAN
438 result[0] <<= (BitsPerWord - BitsPerShort);
439 #endif
440 SET_LOCALS_INT(*(jshort *) result, 0);
441 break;
443 case T_INT:
444 #ifndef VM_LITTLE_ENDIAN
445 result[0] <<= (BitsPerWord - BitsPerInt);
446 #endif
447 SET_LOCALS_INT(*(jint *) result, 0);
448 break;
450 case T_LONG:
451 SET_LOCALS_LONG(*(jlong *) result, 0);
452 break;
454 case T_FLOAT:
455 SET_LOCALS_FLOAT(*(jfloat *) result, 0);
456 break;
458 case T_DOUBLE:
459 SET_LOCALS_DOUBLE(*(jdouble *) result, 0);
460 break;
462 case T_OBJECT:
463 case T_ARRAY:
464 SET_LOCALS_OBJECT(istate->oop_temp(), 0);
465 break;
467 default:
468 ShouldNotReachHere();
469 }
470 }
472 // No deoptimized frames on the stack
473 return 0;
474 }
476 int CppInterpreter::accessor_entry(Method* method, intptr_t UNUSED, TRAPS) {
477 JavaThread *thread = (JavaThread *) THREAD;
478 ZeroStack *stack = thread->zero_stack();
479 intptr_t *locals = stack->sp();
481 // Drop into the slow path if we need a safepoint check
482 if (SafepointSynchronize::do_call_back()) {
483 return normal_entry(method, 0, THREAD);
484 }
486 // Load the object pointer and drop into the slow path
487 // if we have a NullPointerException
488 oop object = LOCALS_OBJECT(0);
489 if (object == NULL) {
490 return normal_entry(method, 0, THREAD);
491 }
493 // Read the field index from the bytecode, which looks like this:
494 // 0: aload_0
495 // 1: getfield
496 // 2: index
497 // 3: index
498 // 4: ireturn/areturn
499 // NB this is not raw bytecode: index is in machine order
500 u1 *code = method->code_base();
501 assert(code[0] == Bytecodes::_aload_0 &&
502 code[1] == Bytecodes::_getfield &&
503 (code[4] == Bytecodes::_ireturn ||
504 code[4] == Bytecodes::_areturn), "should do");
505 u2 index = Bytes::get_native_u2(&code[2]);
507 // Get the entry from the constant pool cache, and drop into
508 // the slow path if it has not been resolved
509 ConstantPoolCache* cache = method->constants()->cache();
510 ConstantPoolCacheEntry* entry = cache->entry_at(index);
511 if (!entry->is_resolved(Bytecodes::_getfield)) {
512 return normal_entry(method, 0, THREAD);
513 }
515 // Get the result and push it onto the stack
516 switch (entry->flag_state()) {
517 case ltos:
518 case dtos:
519 stack->overflow_check(1, CHECK_0);
520 stack->alloc(wordSize);
521 break;
522 }
523 if (entry->is_volatile()) {
524 switch (entry->flag_state()) {
525 case ctos:
526 SET_LOCALS_INT(object->char_field_acquire(entry->f2_as_index()), 0);
527 break;
529 case btos:
530 SET_LOCALS_INT(object->byte_field_acquire(entry->f2_as_index()), 0);
531 break;
533 case stos:
534 SET_LOCALS_INT(object->short_field_acquire(entry->f2_as_index()), 0);
535 break;
537 case itos:
538 SET_LOCALS_INT(object->int_field_acquire(entry->f2_as_index()), 0);
539 break;
541 case ltos:
542 SET_LOCALS_LONG(object->long_field_acquire(entry->f2_as_index()), 0);
543 break;
545 case ftos:
546 SET_LOCALS_FLOAT(object->float_field_acquire(entry->f2_as_index()), 0);
547 break;
549 case dtos:
550 SET_LOCALS_DOUBLE(object->double_field_acquire(entry->f2_as_index()), 0);
551 break;
553 case atos:
554 SET_LOCALS_OBJECT(object->obj_field_acquire(entry->f2_as_index()), 0);
555 break;
557 default:
558 ShouldNotReachHere();
559 }
560 }
561 else {
562 switch (entry->flag_state()) {
563 case ctos:
564 SET_LOCALS_INT(object->char_field(entry->f2_as_index()), 0);
565 break;
567 case btos:
568 SET_LOCALS_INT(object->byte_field(entry->f2_as_index()), 0);
569 break;
571 case stos:
572 SET_LOCALS_INT(object->short_field(entry->f2_as_index()), 0);
573 break;
575 case itos:
576 SET_LOCALS_INT(object->int_field(entry->f2_as_index()), 0);
577 break;
579 case ltos:
580 SET_LOCALS_LONG(object->long_field(entry->f2_as_index()), 0);
581 break;
583 case ftos:
584 SET_LOCALS_FLOAT(object->float_field(entry->f2_as_index()), 0);
585 break;
587 case dtos:
588 SET_LOCALS_DOUBLE(object->double_field(entry->f2_as_index()), 0);
589 break;
591 case atos:
592 SET_LOCALS_OBJECT(object->obj_field(entry->f2_as_index()), 0);
593 break;
595 default:
596 ShouldNotReachHere();
597 }
598 }
600 // No deoptimized frames on the stack
601 return 0;
602 }
604 int CppInterpreter::empty_entry(Method* method, intptr_t UNUSED, TRAPS) {
605 JavaThread *thread = (JavaThread *) THREAD;
606 ZeroStack *stack = thread->zero_stack();
608 // Drop into the slow path if we need a safepoint check
609 if (SafepointSynchronize::do_call_back()) {
610 return normal_entry(method, 0, THREAD);
611 }
613 // Pop our parameters
614 stack->set_sp(stack->sp() + method->size_of_parameters());
616 // No deoptimized frames on the stack
617 return 0;
618 }
620 // The new slots will be inserted before slot insert_before.
621 // Slots < insert_before will have the same slot number after the insert.
622 // Slots >= insert_before will become old_slot + num_slots.
623 void CppInterpreter::insert_vmslots(int insert_before, int num_slots, TRAPS) {
624 JavaThread *thread = (JavaThread *) THREAD;
625 ZeroStack *stack = thread->zero_stack();
627 // Allocate the space
628 stack->overflow_check(num_slots, CHECK);
629 stack->alloc(num_slots * wordSize);
630 intptr_t *vmslots = stack->sp();
632 // Shuffle everything up
633 for (int i = 0; i < insert_before; i++)
634 SET_VMSLOTS_SLOT(VMSLOTS_SLOT(i + num_slots), i);
635 }
637 void CppInterpreter::remove_vmslots(int first_slot, int num_slots, TRAPS) {
638 JavaThread *thread = (JavaThread *) THREAD;
639 ZeroStack *stack = thread->zero_stack();
640 intptr_t *vmslots = stack->sp();
642 // Move everything down
643 for (int i = first_slot - 1; i >= 0; i--)
644 SET_VMSLOTS_SLOT(VMSLOTS_SLOT(i), i + num_slots);
646 // Deallocate the space
647 stack->set_sp(stack->sp() + num_slots);
648 }
650 BasicType CppInterpreter::result_type_of_handle(oop method_handle) {
651 oop method_type = java_lang_invoke_MethodHandle::type(method_handle);
652 oop return_type = java_lang_invoke_MethodType::rtype(method_type);
653 return java_lang_Class::as_BasicType(return_type, (Klass* *) NULL);
654 }
656 intptr_t* CppInterpreter::calculate_unwind_sp(ZeroStack* stack,
657 oop method_handle) {
658 oop method_type = java_lang_invoke_MethodHandle::type(method_handle);
659 int argument_slots = java_lang_invoke_MethodType::ptype_slot_count(method_type);
661 return stack->sp() + argument_slots;
662 }
664 IRT_ENTRY(void, CppInterpreter::throw_exception(JavaThread* thread,
665 Symbol* name,
666 char* message))
667 THROW_MSG(name, message);
668 IRT_END
670 InterpreterFrame *InterpreterFrame::build(Method* const method, TRAPS) {
671 JavaThread *thread = (JavaThread *) THREAD;
672 ZeroStack *stack = thread->zero_stack();
674 // Calculate the size of the frame we'll build, including
675 // any adjustments to the caller's frame that we'll make.
676 int extra_locals = 0;
677 int monitor_words = 0;
678 int stack_words = 0;
680 if (!method->is_native()) {
681 extra_locals = method->max_locals() - method->size_of_parameters();
682 stack_words = method->max_stack();
683 }
684 if (method->is_synchronized()) {
685 monitor_words = frame::interpreter_frame_monitor_size();
686 }
687 stack->overflow_check(
688 extra_locals + header_words + monitor_words + stack_words, CHECK_NULL);
690 // Adjust the caller's stack frame to accomodate any additional
691 // local variables we have contiguously with our parameters.
692 for (int i = 0; i < extra_locals; i++)
693 stack->push(0);
695 intptr_t *locals;
696 if (method->is_native())
697 locals = stack->sp() + (method->size_of_parameters() - 1);
698 else
699 locals = stack->sp() + (method->max_locals() - 1);
701 stack->push(0); // next_frame, filled in later
702 intptr_t *fp = stack->sp();
703 assert(fp - stack->sp() == next_frame_off, "should be");
705 stack->push(INTERPRETER_FRAME);
706 assert(fp - stack->sp() == frame_type_off, "should be");
708 interpreterState istate =
709 (interpreterState) stack->alloc(sizeof(BytecodeInterpreter));
710 assert(fp - stack->sp() == istate_off, "should be");
712 istate->set_locals(locals);
713 istate->set_method(method);
714 istate->set_self_link(istate);
715 istate->set_prev_link(NULL);
716 istate->set_thread(thread);
717 istate->set_bcp(method->is_native() ? NULL : method->code_base());
718 istate->set_constants(method->constants()->cache());
719 istate->set_msg(BytecodeInterpreter::method_entry);
720 istate->set_oop_temp(NULL);
721 istate->set_mdx(NULL);
722 istate->set_callee(NULL);
724 istate->set_monitor_base((BasicObjectLock *) stack->sp());
725 if (method->is_synchronized()) {
726 BasicObjectLock *monitor =
727 (BasicObjectLock *) stack->alloc(monitor_words * wordSize);
728 oop object;
729 if (method->is_static())
730 object = method->constants()->pool_holder()->java_mirror();
731 else
732 object = (oop) locals[0];
733 monitor->set_obj(object);
734 }
736 istate->set_stack_base(stack->sp());
737 istate->set_stack(stack->sp() - 1);
738 if (stack_words)
739 stack->alloc(stack_words * wordSize);
740 istate->set_stack_limit(stack->sp() - 1);
742 return (InterpreterFrame *) fp;
743 }
745 int AbstractInterpreter::BasicType_as_index(BasicType type) {
746 int i = 0;
747 switch (type) {
748 case T_BOOLEAN: i = 0; break;
749 case T_CHAR : i = 1; break;
750 case T_BYTE : i = 2; break;
751 case T_SHORT : i = 3; break;
752 case T_INT : i = 4; break;
753 case T_LONG : i = 5; break;
754 case T_VOID : i = 6; break;
755 case T_FLOAT : i = 7; break;
756 case T_DOUBLE : i = 8; break;
757 case T_OBJECT : i = 9; break;
758 case T_ARRAY : i = 9; break;
759 default : ShouldNotReachHere();
760 }
761 assert(0 <= i && i < AbstractInterpreter::number_of_result_handlers,
762 "index out of bounds");
763 return i;
764 }
766 BasicType CppInterpreter::result_type_of(Method* method) {
767 BasicType t;
768 switch (method->result_index()) {
769 case 0 : t = T_BOOLEAN; break;
770 case 1 : t = T_CHAR; break;
771 case 2 : t = T_BYTE; break;
772 case 3 : t = T_SHORT; break;
773 case 4 : t = T_INT; break;
774 case 5 : t = T_LONG; break;
775 case 6 : t = T_VOID; break;
776 case 7 : t = T_FLOAT; break;
777 case 8 : t = T_DOUBLE; break;
778 case 9 : t = T_OBJECT; break;
779 default: ShouldNotReachHere();
780 }
781 assert(AbstractInterpreter::BasicType_as_index(t) == method->result_index(),
782 "out of step with AbstractInterpreter::BasicType_as_index");
783 return t;
784 }
786 address InterpreterGenerator::generate_empty_entry() {
787 if (!UseFastEmptyMethods)
788 return NULL;
790 return generate_entry((address) CppInterpreter::empty_entry);
791 }
793 address InterpreterGenerator::generate_accessor_entry() {
794 if (!UseFastAccessorMethods)
795 return NULL;
797 return generate_entry((address) CppInterpreter::accessor_entry);
798 }
800 address InterpreterGenerator::generate_Reference_get_entry(void) {
801 #if INCLUDE_ALL_GCS
802 if (UseG1GC) {
803 // We need to generate have a routine that generates code to:
804 // * load the value in the referent field
805 // * passes that value to the pre-barrier.
806 //
807 // In the case of G1 this will record the value of the
808 // referent in an SATB buffer if marking is active.
809 // This will cause concurrent marking to mark the referent
810 // field as live.
811 Unimplemented();
812 }
813 #endif // INCLUDE_ALL_GCS
815 // If G1 is not enabled then attempt to go through the accessor entry point
816 // Reference.get is an accessor
817 return generate_accessor_entry();
818 }
820 address InterpreterGenerator::generate_native_entry(bool synchronized) {
821 assert(synchronized == false, "should be");
823 return generate_entry((address) CppInterpreter::native_entry);
824 }
826 address InterpreterGenerator::generate_normal_entry(bool synchronized) {
827 assert(synchronized == false, "should be");
829 return generate_entry((address) CppInterpreter::normal_entry);
830 }
832 address AbstractInterpreterGenerator::generate_method_entry(
833 AbstractInterpreter::MethodKind kind) {
834 address entry_point = NULL;
836 switch (kind) {
837 case Interpreter::zerolocals:
838 case Interpreter::zerolocals_synchronized:
839 break;
841 case Interpreter::native:
842 entry_point = ((InterpreterGenerator*) this)->generate_native_entry(false);
843 break;
845 case Interpreter::native_synchronized:
846 entry_point = ((InterpreterGenerator*) this)->generate_native_entry(false);
847 break;
849 case Interpreter::empty:
850 entry_point = ((InterpreterGenerator*) this)->generate_empty_entry();
851 break;
853 case Interpreter::accessor:
854 entry_point = ((InterpreterGenerator*) this)->generate_accessor_entry();
855 break;
857 case Interpreter::abstract:
858 entry_point = ((InterpreterGenerator*) this)->generate_abstract_entry();
859 break;
861 case Interpreter::java_lang_math_sin:
862 case Interpreter::java_lang_math_cos:
863 case Interpreter::java_lang_math_tan:
864 case Interpreter::java_lang_math_abs:
865 case Interpreter::java_lang_math_log:
866 case Interpreter::java_lang_math_log10:
867 case Interpreter::java_lang_math_sqrt:
868 case Interpreter::java_lang_math_pow:
869 case Interpreter::java_lang_math_exp:
870 entry_point = ((InterpreterGenerator*) this)->generate_math_entry(kind);
871 break;
873 case Interpreter::java_lang_ref_reference_get:
874 entry_point = ((InterpreterGenerator*)this)->generate_Reference_get_entry();
875 break;
877 default:
878 ShouldNotReachHere();
879 }
881 if (entry_point == NULL)
882 entry_point = ((InterpreterGenerator*) this)->generate_normal_entry(false);
884 return entry_point;
885 }
887 InterpreterGenerator::InterpreterGenerator(StubQueue* code)
888 : CppInterpreterGenerator(code) {
889 generate_all();
890 }
892 // Deoptimization helpers
894 InterpreterFrame *InterpreterFrame::build(int size, TRAPS) {
895 ZeroStack *stack = ((JavaThread *) THREAD)->zero_stack();
897 int size_in_words = size >> LogBytesPerWord;
898 assert(size_in_words * wordSize == size, "unaligned");
899 assert(size_in_words >= header_words, "too small");
900 stack->overflow_check(size_in_words, CHECK_NULL);
902 stack->push(0); // next_frame, filled in later
903 intptr_t *fp = stack->sp();
904 assert(fp - stack->sp() == next_frame_off, "should be");
906 stack->push(INTERPRETER_FRAME);
907 assert(fp - stack->sp() == frame_type_off, "should be");
909 interpreterState istate =
910 (interpreterState) stack->alloc(sizeof(BytecodeInterpreter));
911 assert(fp - stack->sp() == istate_off, "should be");
912 istate->set_self_link(NULL); // mark invalid
914 stack->alloc((size_in_words - header_words) * wordSize);
916 return (InterpreterFrame *) fp;
917 }
919 int AbstractInterpreter::size_activation(int max_stack,
920 int tempcount,
921 int extra_args,
922 int moncount,
923 int callee_param_count,
924 int callee_locals,
925 bool is_top_frame) {
926 int header_words = InterpreterFrame::header_words;
927 int monitor_words = moncount * frame::interpreter_frame_monitor_size();
928 int stack_words = is_top_frame ? max_stack : tempcount;
929 int callee_extra_locals = callee_locals - callee_param_count;
931 return header_words + monitor_words + stack_words + callee_extra_locals;
932 }
934 void AbstractInterpreter::layout_activation(Method* method,
935 int tempcount,
936 int popframe_extra_args,
937 int moncount,
938 int caller_actual_parameters,
939 int callee_param_count,
940 int callee_locals,
941 frame* caller,
942 frame* interpreter_frame,
943 bool is_top_frame,
944 bool is_bottom_frame) {
945 assert(popframe_extra_args == 0, "what to do?");
946 assert(!is_top_frame || (!callee_locals && !callee_param_count),
947 "top frame should have no caller");
949 // This code must exactly match what InterpreterFrame::build
950 // does (the full InterpreterFrame::build, that is, not the
951 // one that creates empty frames for the deoptimizer).
952 //
953 // interpreter_frame will be filled in. It's size is determined by
954 // a previous call to the size_activation() method,
955 //
956 // Note that tempcount is the current size of the expression
957 // stack. For top most frames we will allocate a full sized
958 // expression stack and not the trimmed version that non-top
959 // frames have.
961 int monitor_words = moncount * frame::interpreter_frame_monitor_size();
962 intptr_t *locals = interpreter_frame->fp() + method->max_locals();
963 interpreterState istate = interpreter_frame->get_interpreterState();
964 intptr_t *monitor_base = (intptr_t*) istate;
965 intptr_t *stack_base = monitor_base - monitor_words;
966 intptr_t *stack = stack_base - tempcount - 1;
968 BytecodeInterpreter::layout_interpreterState(istate,
969 caller,
970 NULL,
971 method,
972 locals,
973 stack,
974 stack_base,
975 monitor_base,
976 NULL,
977 is_top_frame);
978 }
980 void BytecodeInterpreter::layout_interpreterState(interpreterState istate,
981 frame* caller,
982 frame* current,
983 Method* method,
984 intptr_t* locals,
985 intptr_t* stack,
986 intptr_t* stack_base,
987 intptr_t* monitor_base,
988 intptr_t* frame_bottom,
989 bool is_top_frame) {
990 istate->set_locals(locals);
991 istate->set_method(method);
992 istate->set_self_link(istate);
993 istate->set_prev_link(NULL);
994 // thread will be set by a hacky repurposing of frame::patch_pc()
995 // bcp will be set by vframeArrayElement::unpack_on_stack()
996 istate->set_constants(method->constants()->cache());
997 istate->set_msg(BytecodeInterpreter::method_resume);
998 istate->set_bcp_advance(0);
999 istate->set_oop_temp(NULL);
1000 istate->set_mdx(NULL);
1001 if (caller->is_interpreted_frame()) {
1002 interpreterState prev = caller->get_interpreterState();
1003 prev->set_callee(method);
1004 if (*prev->bcp() == Bytecodes::_invokeinterface)
1005 prev->set_bcp_advance(5);
1006 else
1007 prev->set_bcp_advance(3);
1008 }
1009 istate->set_callee(NULL);
1010 istate->set_monitor_base((BasicObjectLock *) monitor_base);
1011 istate->set_stack_base(stack_base);
1012 istate->set_stack(stack);
1013 istate->set_stack_limit(stack_base - method->max_stack() - 1);
1014 }
1016 address CppInterpreter::return_entry(TosState state, int length, Bytecodes::Code code) {
1017 ShouldNotCallThis();
1018 return NULL;
1019 }
1021 address CppInterpreter::deopt_entry(TosState state, int length) {
1022 return NULL;
1023 }
1025 // Helper for (runtime) stack overflow checks
1027 int AbstractInterpreter::size_top_interpreter_activation(Method* method) {
1028 return 0;
1029 }
1031 // Helper for figuring out if frames are interpreter frames
1033 bool CppInterpreter::contains(address pc) {
1034 return false; // make frame::print_value_on work
1035 }
1037 // Result handlers and convertors
1039 address CppInterpreterGenerator::generate_result_handler_for(
1040 BasicType type) {
1041 assembler()->advance(1);
1042 return ShouldNotCallThisStub();
1043 }
1045 address CppInterpreterGenerator::generate_tosca_to_stack_converter(
1046 BasicType type) {
1047 assembler()->advance(1);
1048 return ShouldNotCallThisStub();
1049 }
1051 address CppInterpreterGenerator::generate_stack_to_stack_converter(
1052 BasicType type) {
1053 assembler()->advance(1);
1054 return ShouldNotCallThisStub();
1055 }
1057 address CppInterpreterGenerator::generate_stack_to_native_abi_converter(
1058 BasicType type) {
1059 assembler()->advance(1);
1060 return ShouldNotCallThisStub();
1061 }
1063 #endif // CC_INTERP