aoqi@0: /* kevinw@8368: * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved. aoqi@0: * Copyright 2007, 2008, 2009, 2010, 2011 Red Hat, Inc. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #include "precompiled.hpp" aoqi@0: #include "asm/assembler.hpp" aoqi@0: #include "interpreter/bytecodeHistogram.hpp" aoqi@0: #include "interpreter/cppInterpreter.hpp" aoqi@0: #include "interpreter/interpreter.hpp" aoqi@0: #include "interpreter/interpreterGenerator.hpp" aoqi@0: #include "interpreter/interpreterRuntime.hpp" aoqi@0: #include "oops/arrayOop.hpp" aoqi@0: #include "oops/methodData.hpp" aoqi@0: #include "oops/method.hpp" aoqi@0: #include "oops/oop.inline.hpp" aoqi@0: #include "prims/jvmtiExport.hpp" aoqi@0: #include "prims/jvmtiThreadState.hpp" aoqi@0: #include "runtime/arguments.hpp" aoqi@0: #include "runtime/deoptimization.hpp" aoqi@0: #include "runtime/frame.inline.hpp" aoqi@0: #include "runtime/interfaceSupport.hpp" goetz@6911: #include "runtime/orderAccess.inline.hpp" aoqi@0: #include "runtime/sharedRuntime.hpp" aoqi@0: #include "runtime/stubRoutines.hpp" aoqi@0: #include "runtime/synchronizer.hpp" aoqi@0: #include "runtime/timer.hpp" aoqi@0: #include "runtime/vframeArray.hpp" aoqi@0: #include "stack_zero.inline.hpp" aoqi@0: #include "utilities/debug.hpp" aoqi@0: #include "utilities/macros.hpp" aoqi@0: #ifdef SHARK aoqi@0: #include "shark/shark_globals.hpp" aoqi@0: #endif aoqi@0: aoqi@0: #ifdef CC_INTERP aoqi@0: aoqi@0: #define fixup_after_potential_safepoint() \ aoqi@0: method = istate->method() aoqi@0: aoqi@0: #define CALL_VM_NOCHECK_NOFIX(func) \ aoqi@0: thread->set_last_Java_frame(); \ aoqi@0: func; \ aoqi@0: thread->reset_last_Java_frame(); aoqi@0: aoqi@0: #define CALL_VM_NOCHECK(func) \ aoqi@0: CALL_VM_NOCHECK_NOFIX(func) \ aoqi@0: fixup_after_potential_safepoint() aoqi@0: aoqi@0: int CppInterpreter::normal_entry(Method* method, intptr_t UNUSED, TRAPS) { aoqi@0: JavaThread *thread = (JavaThread *) THREAD; aoqi@0: aoqi@0: // Allocate and initialize our frame. aoqi@0: InterpreterFrame *frame = InterpreterFrame::build(method, CHECK_0); aoqi@0: thread->push_zero_frame(frame); aoqi@0: aoqi@0: // Execute those bytecodes! aoqi@0: main_loop(0, THREAD); aoqi@0: aoqi@0: // No deoptimized frames on the stack aoqi@0: return 0; aoqi@0: } aoqi@0: kevinw@8368: intptr_t narrow(BasicType type, intptr_t result) { kevinw@8368: // mask integer result to narrower return type. kevinw@8368: switch (type) { kevinw@8368: case T_BOOLEAN: kevinw@8368: return result&1; kevinw@8368: case T_BYTE: kevinw@8368: return (intptr_t)(jbyte)result; kevinw@8368: case T_CHAR: kevinw@8368: return (intptr_t)(uintptr_t)(jchar)result; kevinw@8368: case T_SHORT: kevinw@8368: return (intptr_t)(jshort)result; kevinw@8368: case T_OBJECT: // nothing to do fall through kevinw@8402: case T_ARRAY: kevinw@8368: case T_LONG: kevinw@8368: case T_INT: kevinw@8368: case T_FLOAT: kevinw@8368: case T_DOUBLE: kevinw@8368: case T_VOID: kevinw@8368: return result; kevinw@8368: default : ShouldNotReachHere(); kevinw@8368: } kevinw@8368: } kevinw@8368: kevinw@8368: aoqi@0: void CppInterpreter::main_loop(int recurse, TRAPS) { aoqi@0: JavaThread *thread = (JavaThread *) THREAD; aoqi@0: ZeroStack *stack = thread->zero_stack(); aoqi@0: aoqi@0: // If we are entering from a deopt we may need to call aoqi@0: // ourself a few times in order to get to our frame. aoqi@0: if (recurse) aoqi@0: main_loop(recurse - 1, THREAD); aoqi@0: aoqi@0: InterpreterFrame *frame = thread->top_zero_frame()->as_interpreter_frame(); aoqi@0: interpreterState istate = frame->interpreter_state(); aoqi@0: Method* method = istate->method(); aoqi@0: aoqi@0: intptr_t *result = NULL; aoqi@0: int result_slots = 0; aoqi@0: aoqi@0: while (true) { aoqi@0: // We can set up the frame anchor with everything we want at aoqi@0: // this point as we are thread_in_Java and no safepoints can aoqi@0: // occur until we go to vm mode. We do have to clear flags aoqi@0: // on return from vm but that is it. aoqi@0: thread->set_last_Java_frame(); aoqi@0: aoqi@0: // Call the interpreter aoqi@0: if (JvmtiExport::can_post_interpreter_events()) aoqi@0: BytecodeInterpreter::runWithChecks(istate); aoqi@0: else aoqi@0: BytecodeInterpreter::run(istate); aoqi@0: fixup_after_potential_safepoint(); aoqi@0: aoqi@0: // Clear the frame anchor aoqi@0: thread->reset_last_Java_frame(); aoqi@0: aoqi@0: // Examine the message from the interpreter to decide what to do aoqi@0: if (istate->msg() == BytecodeInterpreter::call_method) { aoqi@0: Method* callee = istate->callee(); aoqi@0: aoqi@0: // Trim back the stack to put the parameters at the top aoqi@0: stack->set_sp(istate->stack() + 1); aoqi@0: aoqi@0: // Make the call aoqi@0: Interpreter::invoke_method(callee, istate->callee_entry_point(), THREAD); aoqi@0: fixup_after_potential_safepoint(); aoqi@0: aoqi@0: // Convert the result aoqi@0: istate->set_stack(stack->sp() - 1); aoqi@0: aoqi@0: // Restore the stack aoqi@0: stack->set_sp(istate->stack_limit() + 1); aoqi@0: aoqi@0: // Resume the interpreter aoqi@0: istate->set_msg(BytecodeInterpreter::method_resume); aoqi@0: } aoqi@0: else if (istate->msg() == BytecodeInterpreter::more_monitors) { aoqi@0: int monitor_words = frame::interpreter_frame_monitor_size(); aoqi@0: aoqi@0: // Allocate the space aoqi@0: stack->overflow_check(monitor_words, THREAD); aoqi@0: if (HAS_PENDING_EXCEPTION) aoqi@0: break; aoqi@0: stack->alloc(monitor_words * wordSize); aoqi@0: aoqi@0: // Move the expression stack contents aoqi@0: for (intptr_t *p = istate->stack() + 1; p < istate->stack_base(); p++) aoqi@0: *(p - monitor_words) = *p; aoqi@0: aoqi@0: // Move the expression stack pointers aoqi@0: istate->set_stack_limit(istate->stack_limit() - monitor_words); aoqi@0: istate->set_stack(istate->stack() - monitor_words); aoqi@0: istate->set_stack_base(istate->stack_base() - monitor_words); aoqi@0: aoqi@0: // Zero the new monitor so the interpreter can find it. aoqi@0: ((BasicObjectLock *) istate->stack_base())->set_obj(NULL); aoqi@0: aoqi@0: // Resume the interpreter aoqi@0: istate->set_msg(BytecodeInterpreter::got_monitors); aoqi@0: } aoqi@0: else if (istate->msg() == BytecodeInterpreter::return_from_method) { aoqi@0: // Copy the result into the caller's frame kevinw@8402: result_slots = type2size[method->result_type()]; aoqi@0: assert(result_slots >= 0 && result_slots <= 2, "what?"); aoqi@0: result = istate->stack() + result_slots; aoqi@0: break; aoqi@0: } aoqi@0: else if (istate->msg() == BytecodeInterpreter::throwing_exception) { aoqi@0: assert(HAS_PENDING_EXCEPTION, "should do"); aoqi@0: break; aoqi@0: } aoqi@0: else if (istate->msg() == BytecodeInterpreter::do_osr) { aoqi@0: // Unwind the current frame aoqi@0: thread->pop_zero_frame(); aoqi@0: aoqi@0: // Remove any extension of the previous frame aoqi@0: int extra_locals = method->max_locals() - method->size_of_parameters(); aoqi@0: stack->set_sp(stack->sp() + extra_locals); aoqi@0: aoqi@0: // Jump into the OSR method aoqi@0: Interpreter::invoke_osr( aoqi@0: method, istate->osr_entry(), istate->osr_buf(), THREAD); aoqi@0: return; aoqi@0: } aoqi@0: else { aoqi@0: ShouldNotReachHere(); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // Unwind the current frame aoqi@0: thread->pop_zero_frame(); aoqi@0: aoqi@0: // Pop our local variables aoqi@0: stack->set_sp(stack->sp() + method->max_locals()); aoqi@0: aoqi@0: // Push our result kevinw@8368: for (int i = 0; i < result_slots; i++) { kevinw@8368: // Adjust result to smaller aph@8429: union { aph@8429: intptr_t res; aph@8429: jint res_jint; aph@8429: }; aph@8429: res = result[-i]; kevinw@8368: if (result_slots == 1) { aph@8429: BasicType t = method->result_type(); aph@8429: if (is_subword_type(t)) { aph@8429: res_jint = (jint)narrow(t, res_jint); aph@8429: } kevinw@8368: } kevinw@8368: stack->push(res); kevinw@8368: } aoqi@0: } aoqi@0: aoqi@0: int CppInterpreter::native_entry(Method* method, intptr_t UNUSED, TRAPS) { aoqi@0: // Make sure method is native and not abstract aoqi@0: assert(method->is_native() && !method->is_abstract(), "should be"); aoqi@0: aoqi@0: JavaThread *thread = (JavaThread *) THREAD; aoqi@0: ZeroStack *stack = thread->zero_stack(); aoqi@0: aoqi@0: // Allocate and initialize our frame aoqi@0: InterpreterFrame *frame = InterpreterFrame::build(method, CHECK_0); aoqi@0: thread->push_zero_frame(frame); aoqi@0: interpreterState istate = frame->interpreter_state(); aoqi@0: intptr_t *locals = istate->locals(); aoqi@0: aoqi@0: // Update the invocation counter aoqi@0: if ((UseCompiler || CountCompiledCalls) && !method->is_synchronized()) { aoqi@0: MethodCounters* mcs = method->method_counters(); aoqi@0: if (mcs == NULL) { aoqi@0: CALL_VM_NOCHECK(mcs = InterpreterRuntime::build_method_counters(thread, method)); aoqi@0: if (HAS_PENDING_EXCEPTION) aoqi@0: goto unwind_and_return; aoqi@0: } aoqi@0: InvocationCounter *counter = mcs->invocation_counter(); aoqi@0: counter->increment(); aoqi@0: if (counter->reached_InvocationLimit(mcs->backedge_counter())) { aoqi@0: CALL_VM_NOCHECK( aoqi@0: InterpreterRuntime::frequency_counter_overflow(thread, NULL)); aoqi@0: if (HAS_PENDING_EXCEPTION) aoqi@0: goto unwind_and_return; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // Lock if necessary aoqi@0: BasicObjectLock *monitor; aoqi@0: monitor = NULL; aoqi@0: if (method->is_synchronized()) { aoqi@0: monitor = (BasicObjectLock*) istate->stack_base(); aoqi@0: oop lockee = monitor->obj(); aoqi@0: markOop disp = lockee->mark()->set_unlocked(); aoqi@0: aoqi@0: monitor->lock()->set_displaced_header(disp); aoqi@0: if (Atomic::cmpxchg_ptr(monitor, lockee->mark_addr(), disp) != disp) { aoqi@0: if (thread->is_lock_owned((address) disp->clear_lock_bits())) { aoqi@0: monitor->lock()->set_displaced_header(NULL); aoqi@0: } aoqi@0: else { aoqi@0: CALL_VM_NOCHECK(InterpreterRuntime::monitorenter(thread, monitor)); aoqi@0: if (HAS_PENDING_EXCEPTION) aoqi@0: goto unwind_and_return; aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // Get the signature handler aoqi@0: InterpreterRuntime::SignatureHandler *handler; { aoqi@0: address handlerAddr = method->signature_handler(); aoqi@0: if (handlerAddr == NULL) { aoqi@0: CALL_VM_NOCHECK(InterpreterRuntime::prepare_native_call(thread, method)); aoqi@0: if (HAS_PENDING_EXCEPTION) aoqi@0: goto unlock_unwind_and_return; aoqi@0: aoqi@0: handlerAddr = method->signature_handler(); aoqi@0: assert(handlerAddr != NULL, "eh?"); aoqi@0: } aoqi@0: if (handlerAddr == (address) InterpreterRuntime::slow_signature_handler) { aoqi@0: CALL_VM_NOCHECK(handlerAddr = aoqi@0: InterpreterRuntime::slow_signature_handler(thread, method, NULL,NULL)); aoqi@0: if (HAS_PENDING_EXCEPTION) aoqi@0: goto unlock_unwind_and_return; aoqi@0: } aoqi@0: handler = \ aoqi@0: InterpreterRuntime::SignatureHandler::from_handlerAddr(handlerAddr); aoqi@0: } aoqi@0: aoqi@0: // Get the native function entry point aoqi@0: address function; aoqi@0: function = method->native_function(); aoqi@0: assert(function != NULL, "should be set if signature handler is"); aoqi@0: aoqi@0: // Build the argument list aoqi@0: stack->overflow_check(handler->argument_count() * 2, THREAD); aoqi@0: if (HAS_PENDING_EXCEPTION) aoqi@0: goto unlock_unwind_and_return; aoqi@0: aoqi@0: void **arguments; aoqi@0: void *mirror; { aoqi@0: arguments = aoqi@0: (void **) stack->alloc(handler->argument_count() * sizeof(void **)); aoqi@0: void **dst = arguments; aoqi@0: aoqi@0: void *env = thread->jni_environment(); aoqi@0: *(dst++) = &env; aoqi@0: aoqi@0: if (method->is_static()) { aoqi@0: istate->set_oop_temp( aoqi@0: method->constants()->pool_holder()->java_mirror()); aoqi@0: mirror = istate->oop_temp_addr(); aoqi@0: *(dst++) = &mirror; aoqi@0: } aoqi@0: aoqi@0: intptr_t *src = locals; aoqi@0: for (int i = dst - arguments; i < handler->argument_count(); i++) { aoqi@0: ffi_type *type = handler->argument_type(i); aoqi@0: if (type == &ffi_type_pointer) { aoqi@0: if (*src) { aoqi@0: stack->push((intptr_t) src); aoqi@0: *(dst++) = stack->sp(); aoqi@0: } aoqi@0: else { aoqi@0: *(dst++) = src; aoqi@0: } aoqi@0: src--; aoqi@0: } aoqi@0: else if (type->size == 4) { aoqi@0: *(dst++) = src--; aoqi@0: } aoqi@0: else if (type->size == 8) { aoqi@0: src--; aoqi@0: *(dst++) = src--; aoqi@0: } aoqi@0: else { aoqi@0: ShouldNotReachHere(); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // Set up the Java frame anchor aoqi@0: thread->set_last_Java_frame(); aoqi@0: aoqi@0: // Change the thread state to _thread_in_native aoqi@0: ThreadStateTransition::transition_from_java(thread, _thread_in_native); aoqi@0: aoqi@0: // Make the call aoqi@0: intptr_t result[4 - LogBytesPerWord]; aoqi@0: ffi_call(handler->cif(), (void (*)()) function, result, arguments); aoqi@0: aoqi@0: // Change the thread state back to _thread_in_Java. aoqi@0: // ThreadStateTransition::transition_from_native() cannot be used aoqi@0: // here because it does not check for asynchronous exceptions. aoqi@0: // We have to manage the transition ourself. aoqi@0: thread->set_thread_state(_thread_in_native_trans); aoqi@0: aoqi@0: // Make sure new state is visible in the GC thread aoqi@0: if (os::is_MP()) { aoqi@0: if (UseMembar) { aoqi@0: OrderAccess::fence(); aoqi@0: } aoqi@0: else { aoqi@0: InterfaceSupport::serialize_memory(thread); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // Handle safepoint operations, pending suspend requests, aoqi@0: // and pending asynchronous exceptions. aoqi@0: if (SafepointSynchronize::do_call_back() || aoqi@0: thread->has_special_condition_for_native_trans()) { aoqi@0: JavaThread::check_special_condition_for_native_trans(thread); aoqi@0: CHECK_UNHANDLED_OOPS_ONLY(thread->clear_unhandled_oops()); aoqi@0: } aoqi@0: aoqi@0: // Finally we can change the thread state to _thread_in_Java. aoqi@0: thread->set_thread_state(_thread_in_Java); aoqi@0: fixup_after_potential_safepoint(); aoqi@0: aoqi@0: // Clear the frame anchor aoqi@0: thread->reset_last_Java_frame(); aoqi@0: aoqi@0: // If the result was an oop then unbox it and store it in aoqi@0: // oop_temp where the garbage collector can see it before aoqi@0: // we release the handle it might be protected by. aoqi@0: if (handler->result_type() == &ffi_type_pointer) { aoqi@0: if (result[0]) aoqi@0: istate->set_oop_temp(*(oop *) result[0]); aoqi@0: else aoqi@0: istate->set_oop_temp(NULL); aoqi@0: } aoqi@0: aoqi@0: // Reset handle block aoqi@0: thread->active_handles()->clear(); aoqi@0: aoqi@0: unlock_unwind_and_return: aoqi@0: aoqi@0: // Unlock if necessary aoqi@0: if (monitor) { aoqi@0: BasicLock *lock = monitor->lock(); aoqi@0: markOop header = lock->displaced_header(); aoqi@0: oop rcvr = monitor->obj(); aoqi@0: monitor->set_obj(NULL); aoqi@0: aoqi@0: if (header != NULL) { aoqi@0: if (Atomic::cmpxchg_ptr(header, rcvr->mark_addr(), lock) != lock) { aoqi@0: monitor->set_obj(rcvr); { aoqi@0: HandleMark hm(thread); aoqi@0: CALL_VM_NOCHECK(InterpreterRuntime::monitorexit(thread, monitor)); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: unwind_and_return: aoqi@0: aoqi@0: // Unwind the current activation aoqi@0: thread->pop_zero_frame(); aoqi@0: aoqi@0: // Pop our parameters aoqi@0: stack->set_sp(stack->sp() + method->size_of_parameters()); aoqi@0: aoqi@0: // Push our result aoqi@0: if (!HAS_PENDING_EXCEPTION) { kevinw@8402: BasicType type = method->result_type(); aoqi@0: stack->set_sp(stack->sp() - type2size[type]); aoqi@0: aoqi@0: switch (type) { aoqi@0: case T_VOID: aoqi@0: break; aoqi@0: aoqi@0: case T_BOOLEAN: aoqi@0: #ifndef VM_LITTLE_ENDIAN aoqi@0: result[0] <<= (BitsPerWord - BitsPerByte); aoqi@0: #endif aoqi@0: SET_LOCALS_INT(*(jboolean *) result != 0, 0); aoqi@0: break; aoqi@0: aoqi@0: case T_CHAR: aoqi@0: #ifndef VM_LITTLE_ENDIAN aoqi@0: result[0] <<= (BitsPerWord - BitsPerShort); aoqi@0: #endif aoqi@0: SET_LOCALS_INT(*(jchar *) result, 0); aoqi@0: break; aoqi@0: aoqi@0: case T_BYTE: aoqi@0: #ifndef VM_LITTLE_ENDIAN aoqi@0: result[0] <<= (BitsPerWord - BitsPerByte); aoqi@0: #endif aoqi@0: SET_LOCALS_INT(*(jbyte *) result, 0); aoqi@0: break; aoqi@0: aoqi@0: case T_SHORT: aoqi@0: #ifndef VM_LITTLE_ENDIAN aoqi@0: result[0] <<= (BitsPerWord - BitsPerShort); aoqi@0: #endif aoqi@0: SET_LOCALS_INT(*(jshort *) result, 0); aoqi@0: break; aoqi@0: aoqi@0: case T_INT: aoqi@0: #ifndef VM_LITTLE_ENDIAN aoqi@0: result[0] <<= (BitsPerWord - BitsPerInt); aoqi@0: #endif aoqi@0: SET_LOCALS_INT(*(jint *) result, 0); aoqi@0: break; aoqi@0: aoqi@0: case T_LONG: aoqi@0: SET_LOCALS_LONG(*(jlong *) result, 0); aoqi@0: break; aoqi@0: aoqi@0: case T_FLOAT: aoqi@0: SET_LOCALS_FLOAT(*(jfloat *) result, 0); aoqi@0: break; aoqi@0: aoqi@0: case T_DOUBLE: aoqi@0: SET_LOCALS_DOUBLE(*(jdouble *) result, 0); aoqi@0: break; aoqi@0: aoqi@0: case T_OBJECT: aoqi@0: case T_ARRAY: aoqi@0: SET_LOCALS_OBJECT(istate->oop_temp(), 0); aoqi@0: break; aoqi@0: aoqi@0: default: aoqi@0: ShouldNotReachHere(); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // No deoptimized frames on the stack aoqi@0: return 0; aoqi@0: } aoqi@0: aoqi@0: int CppInterpreter::accessor_entry(Method* method, intptr_t UNUSED, TRAPS) { aoqi@0: JavaThread *thread = (JavaThread *) THREAD; aoqi@0: ZeroStack *stack = thread->zero_stack(); aoqi@0: intptr_t *locals = stack->sp(); aoqi@0: aoqi@0: // Drop into the slow path if we need a safepoint check aoqi@0: if (SafepointSynchronize::do_call_back()) { aoqi@0: return normal_entry(method, 0, THREAD); aoqi@0: } aoqi@0: aoqi@0: // Load the object pointer and drop into the slow path aoqi@0: // if we have a NullPointerException aoqi@0: oop object = LOCALS_OBJECT(0); aoqi@0: if (object == NULL) { aoqi@0: return normal_entry(method, 0, THREAD); aoqi@0: } aoqi@0: aoqi@0: // Read the field index from the bytecode, which looks like this: aoqi@0: // 0: aload_0 aoqi@0: // 1: getfield aoqi@0: // 2: index aoqi@0: // 3: index aoqi@0: // 4: ireturn/areturn aoqi@0: // NB this is not raw bytecode: index is in machine order aoqi@0: u1 *code = method->code_base(); aoqi@0: assert(code[0] == Bytecodes::_aload_0 && aoqi@0: code[1] == Bytecodes::_getfield && aoqi@0: (code[4] == Bytecodes::_ireturn || aoqi@0: code[4] == Bytecodes::_areturn), "should do"); aoqi@0: u2 index = Bytes::get_native_u2(&code[2]); aoqi@0: aoqi@0: // Get the entry from the constant pool cache, and drop into aoqi@0: // the slow path if it has not been resolved aoqi@0: ConstantPoolCache* cache = method->constants()->cache(); aoqi@0: ConstantPoolCacheEntry* entry = cache->entry_at(index); aoqi@0: if (!entry->is_resolved(Bytecodes::_getfield)) { aoqi@0: return normal_entry(method, 0, THREAD); aoqi@0: } aoqi@0: aoqi@0: // Get the result and push it onto the stack aoqi@0: switch (entry->flag_state()) { aoqi@0: case ltos: aoqi@0: case dtos: aoqi@0: stack->overflow_check(1, CHECK_0); aoqi@0: stack->alloc(wordSize); aoqi@0: break; aoqi@0: } aoqi@0: if (entry->is_volatile()) { aoqi@0: switch (entry->flag_state()) { aoqi@0: case ctos: aoqi@0: SET_LOCALS_INT(object->char_field_acquire(entry->f2_as_index()), 0); aoqi@0: break; aoqi@0: aoqi@0: case btos: kevinw@8368: case ztos: aoqi@0: SET_LOCALS_INT(object->byte_field_acquire(entry->f2_as_index()), 0); aoqi@0: break; aoqi@0: aoqi@0: case stos: aoqi@0: SET_LOCALS_INT(object->short_field_acquire(entry->f2_as_index()), 0); aoqi@0: break; aoqi@0: aoqi@0: case itos: aoqi@0: SET_LOCALS_INT(object->int_field_acquire(entry->f2_as_index()), 0); aoqi@0: break; aoqi@0: aoqi@0: case ltos: aoqi@0: SET_LOCALS_LONG(object->long_field_acquire(entry->f2_as_index()), 0); aoqi@0: break; aoqi@0: aoqi@0: case ftos: aoqi@0: SET_LOCALS_FLOAT(object->float_field_acquire(entry->f2_as_index()), 0); aoqi@0: break; aoqi@0: aoqi@0: case dtos: aoqi@0: SET_LOCALS_DOUBLE(object->double_field_acquire(entry->f2_as_index()), 0); aoqi@0: break; aoqi@0: aoqi@0: case atos: aoqi@0: SET_LOCALS_OBJECT(object->obj_field_acquire(entry->f2_as_index()), 0); aoqi@0: break; aoqi@0: aoqi@0: default: aoqi@0: ShouldNotReachHere(); aoqi@0: } aoqi@0: } aoqi@0: else { aoqi@0: switch (entry->flag_state()) { aoqi@0: case ctos: aoqi@0: SET_LOCALS_INT(object->char_field(entry->f2_as_index()), 0); aoqi@0: break; aoqi@0: aoqi@0: case btos: kevinw@8368: case ztos: aoqi@0: SET_LOCALS_INT(object->byte_field(entry->f2_as_index()), 0); aoqi@0: break; aoqi@0: aoqi@0: case stos: aoqi@0: SET_LOCALS_INT(object->short_field(entry->f2_as_index()), 0); aoqi@0: break; aoqi@0: aoqi@0: case itos: aoqi@0: SET_LOCALS_INT(object->int_field(entry->f2_as_index()), 0); aoqi@0: break; aoqi@0: aoqi@0: case ltos: aoqi@0: SET_LOCALS_LONG(object->long_field(entry->f2_as_index()), 0); aoqi@0: break; aoqi@0: aoqi@0: case ftos: aoqi@0: SET_LOCALS_FLOAT(object->float_field(entry->f2_as_index()), 0); aoqi@0: break; aoqi@0: aoqi@0: case dtos: aoqi@0: SET_LOCALS_DOUBLE(object->double_field(entry->f2_as_index()), 0); aoqi@0: break; aoqi@0: aoqi@0: case atos: aoqi@0: SET_LOCALS_OBJECT(object->obj_field(entry->f2_as_index()), 0); aoqi@0: break; aoqi@0: aoqi@0: default: aoqi@0: ShouldNotReachHere(); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // No deoptimized frames on the stack aoqi@0: return 0; aoqi@0: } aoqi@0: aoqi@0: int CppInterpreter::empty_entry(Method* method, intptr_t UNUSED, TRAPS) { aoqi@0: JavaThread *thread = (JavaThread *) THREAD; aoqi@0: ZeroStack *stack = thread->zero_stack(); aoqi@0: aoqi@0: // Drop into the slow path if we need a safepoint check aoqi@0: if (SafepointSynchronize::do_call_back()) { aoqi@0: return normal_entry(method, 0, THREAD); aoqi@0: } aoqi@0: aoqi@0: // Pop our parameters aoqi@0: stack->set_sp(stack->sp() + method->size_of_parameters()); aoqi@0: aoqi@0: // No deoptimized frames on the stack aoqi@0: return 0; aoqi@0: } aoqi@0: aoqi@0: // The new slots will be inserted before slot insert_before. aoqi@0: // Slots < insert_before will have the same slot number after the insert. aoqi@0: // Slots >= insert_before will become old_slot + num_slots. aoqi@0: void CppInterpreter::insert_vmslots(int insert_before, int num_slots, TRAPS) { aoqi@0: JavaThread *thread = (JavaThread *) THREAD; aoqi@0: ZeroStack *stack = thread->zero_stack(); aoqi@0: aoqi@0: // Allocate the space aoqi@0: stack->overflow_check(num_slots, CHECK); aoqi@0: stack->alloc(num_slots * wordSize); aoqi@0: intptr_t *vmslots = stack->sp(); aoqi@0: aoqi@0: // Shuffle everything up aoqi@0: for (int i = 0; i < insert_before; i++) aoqi@0: SET_VMSLOTS_SLOT(VMSLOTS_SLOT(i + num_slots), i); aoqi@0: } aoqi@0: aoqi@0: void CppInterpreter::remove_vmslots(int first_slot, int num_slots, TRAPS) { aoqi@0: JavaThread *thread = (JavaThread *) THREAD; aoqi@0: ZeroStack *stack = thread->zero_stack(); aoqi@0: intptr_t *vmslots = stack->sp(); aoqi@0: aoqi@0: // Move everything down aoqi@0: for (int i = first_slot - 1; i >= 0; i--) aoqi@0: SET_VMSLOTS_SLOT(VMSLOTS_SLOT(i), i + num_slots); aoqi@0: aoqi@0: // Deallocate the space aoqi@0: stack->set_sp(stack->sp() + num_slots); aoqi@0: } aoqi@0: aoqi@0: BasicType CppInterpreter::result_type_of_handle(oop method_handle) { aoqi@0: oop method_type = java_lang_invoke_MethodHandle::type(method_handle); aoqi@0: oop return_type = java_lang_invoke_MethodType::rtype(method_type); aoqi@0: return java_lang_Class::as_BasicType(return_type, (Klass* *) NULL); aoqi@0: } aoqi@0: aoqi@0: intptr_t* CppInterpreter::calculate_unwind_sp(ZeroStack* stack, aoqi@0: oop method_handle) { aoqi@0: oop method_type = java_lang_invoke_MethodHandle::type(method_handle); aoqi@0: int argument_slots = java_lang_invoke_MethodType::ptype_slot_count(method_type); aoqi@0: aoqi@0: return stack->sp() + argument_slots; aoqi@0: } aoqi@0: aoqi@0: IRT_ENTRY(void, CppInterpreter::throw_exception(JavaThread* thread, aoqi@0: Symbol* name, aoqi@0: char* message)) aoqi@0: THROW_MSG(name, message); aoqi@0: IRT_END aoqi@0: aoqi@0: InterpreterFrame *InterpreterFrame::build(Method* const method, TRAPS) { aoqi@0: JavaThread *thread = (JavaThread *) THREAD; aoqi@0: ZeroStack *stack = thread->zero_stack(); aoqi@0: aoqi@0: // Calculate the size of the frame we'll build, including aoqi@0: // any adjustments to the caller's frame that we'll make. aoqi@0: int extra_locals = 0; aoqi@0: int monitor_words = 0; aoqi@0: int stack_words = 0; aoqi@0: aoqi@0: if (!method->is_native()) { aoqi@0: extra_locals = method->max_locals() - method->size_of_parameters(); aoqi@0: stack_words = method->max_stack(); aoqi@0: } aoqi@0: if (method->is_synchronized()) { aoqi@0: monitor_words = frame::interpreter_frame_monitor_size(); aoqi@0: } aoqi@0: stack->overflow_check( aoqi@0: extra_locals + header_words + monitor_words + stack_words, CHECK_NULL); aoqi@0: aoqi@0: // Adjust the caller's stack frame to accomodate any additional aoqi@0: // local variables we have contiguously with our parameters. aoqi@0: for (int i = 0; i < extra_locals; i++) aoqi@0: stack->push(0); aoqi@0: aoqi@0: intptr_t *locals; aoqi@0: if (method->is_native()) aoqi@0: locals = stack->sp() + (method->size_of_parameters() - 1); aoqi@0: else aoqi@0: locals = stack->sp() + (method->max_locals() - 1); aoqi@0: aoqi@0: stack->push(0); // next_frame, filled in later aoqi@0: intptr_t *fp = stack->sp(); aoqi@0: assert(fp - stack->sp() == next_frame_off, "should be"); aoqi@0: aoqi@0: stack->push(INTERPRETER_FRAME); aoqi@0: assert(fp - stack->sp() == frame_type_off, "should be"); aoqi@0: aoqi@0: interpreterState istate = aoqi@0: (interpreterState) stack->alloc(sizeof(BytecodeInterpreter)); aoqi@0: assert(fp - stack->sp() == istate_off, "should be"); aoqi@0: aoqi@0: istate->set_locals(locals); aoqi@0: istate->set_method(method); aoqi@0: istate->set_self_link(istate); aoqi@0: istate->set_prev_link(NULL); aoqi@0: istate->set_thread(thread); aoqi@0: istate->set_bcp(method->is_native() ? NULL : method->code_base()); aoqi@0: istate->set_constants(method->constants()->cache()); aoqi@0: istate->set_msg(BytecodeInterpreter::method_entry); aoqi@0: istate->set_oop_temp(NULL); aoqi@0: istate->set_mdx(NULL); aoqi@0: istate->set_callee(NULL); aoqi@0: aoqi@0: istate->set_monitor_base((BasicObjectLock *) stack->sp()); aoqi@0: if (method->is_synchronized()) { aoqi@0: BasicObjectLock *monitor = aoqi@0: (BasicObjectLock *) stack->alloc(monitor_words * wordSize); aoqi@0: oop object; aoqi@0: if (method->is_static()) aoqi@0: object = method->constants()->pool_holder()->java_mirror(); aoqi@0: else coleenp@7675: object = (oop) (void*)locals[0]; aoqi@0: monitor->set_obj(object); aoqi@0: } aoqi@0: aoqi@0: istate->set_stack_base(stack->sp()); aoqi@0: istate->set_stack(stack->sp() - 1); aoqi@0: if (stack_words) aoqi@0: stack->alloc(stack_words * wordSize); aoqi@0: istate->set_stack_limit(stack->sp() - 1); aoqi@0: aoqi@0: return (InterpreterFrame *) fp; aoqi@0: } aoqi@0: aoqi@0: int AbstractInterpreter::BasicType_as_index(BasicType type) { aoqi@0: int i = 0; aoqi@0: switch (type) { aoqi@0: case T_BOOLEAN: i = 0; break; aoqi@0: case T_CHAR : i = 1; break; aoqi@0: case T_BYTE : i = 2; break; aoqi@0: case T_SHORT : i = 3; break; aoqi@0: case T_INT : i = 4; break; aoqi@0: case T_LONG : i = 5; break; aoqi@0: case T_VOID : i = 6; break; aoqi@0: case T_FLOAT : i = 7; break; aoqi@0: case T_DOUBLE : i = 8; break; aoqi@0: case T_OBJECT : i = 9; break; aoqi@0: case T_ARRAY : i = 9; break; aoqi@0: default : ShouldNotReachHere(); aoqi@0: } aoqi@0: assert(0 <= i && i < AbstractInterpreter::number_of_result_handlers, aoqi@0: "index out of bounds"); aoqi@0: return i; aoqi@0: } aoqi@0: aoqi@0: address InterpreterGenerator::generate_empty_entry() { aoqi@0: if (!UseFastEmptyMethods) aoqi@0: return NULL; aoqi@0: aoqi@0: return generate_entry((address) CppInterpreter::empty_entry); aoqi@0: } aoqi@0: aoqi@0: address InterpreterGenerator::generate_accessor_entry() { aoqi@0: if (!UseFastAccessorMethods) aoqi@0: return NULL; aoqi@0: aoqi@0: return generate_entry((address) CppInterpreter::accessor_entry); aoqi@0: } aoqi@0: aoqi@0: address InterpreterGenerator::generate_Reference_get_entry(void) { aoqi@0: #if INCLUDE_ALL_GCS aoqi@0: if (UseG1GC) { aoqi@0: // We need to generate have a routine that generates code to: aoqi@0: // * load the value in the referent field aoqi@0: // * passes that value to the pre-barrier. aoqi@0: // aoqi@0: // In the case of G1 this will record the value of the aoqi@0: // referent in an SATB buffer if marking is active. aoqi@0: // This will cause concurrent marking to mark the referent aoqi@0: // field as live. aoqi@0: Unimplemented(); aoqi@0: } aoqi@0: #endif // INCLUDE_ALL_GCS aoqi@0: aoqi@0: // If G1 is not enabled then attempt to go through the accessor entry point aoqi@0: // Reference.get is an accessor aoqi@0: return generate_accessor_entry(); aoqi@0: } aoqi@0: aoqi@0: address InterpreterGenerator::generate_native_entry(bool synchronized) { aoqi@0: assert(synchronized == false, "should be"); aoqi@0: aoqi@0: return generate_entry((address) CppInterpreter::native_entry); aoqi@0: } aoqi@0: aoqi@0: address InterpreterGenerator::generate_normal_entry(bool synchronized) { aoqi@0: assert(synchronized == false, "should be"); aoqi@0: aoqi@0: return generate_entry((address) CppInterpreter::normal_entry); aoqi@0: } aoqi@0: aoqi@0: address AbstractInterpreterGenerator::generate_method_entry( aoqi@0: AbstractInterpreter::MethodKind kind) { aoqi@0: address entry_point = NULL; aoqi@0: aoqi@0: switch (kind) { aoqi@0: case Interpreter::zerolocals: aoqi@0: case Interpreter::zerolocals_synchronized: aoqi@0: break; aoqi@0: aoqi@0: case Interpreter::native: aoqi@0: entry_point = ((InterpreterGenerator*) this)->generate_native_entry(false); aoqi@0: break; aoqi@0: aoqi@0: case Interpreter::native_synchronized: aoqi@0: entry_point = ((InterpreterGenerator*) this)->generate_native_entry(false); aoqi@0: break; aoqi@0: aoqi@0: case Interpreter::empty: aoqi@0: entry_point = ((InterpreterGenerator*) this)->generate_empty_entry(); aoqi@0: break; aoqi@0: aoqi@0: case Interpreter::accessor: aoqi@0: entry_point = ((InterpreterGenerator*) this)->generate_accessor_entry(); aoqi@0: break; aoqi@0: aoqi@0: case Interpreter::abstract: aoqi@0: entry_point = ((InterpreterGenerator*) this)->generate_abstract_entry(); aoqi@0: break; aoqi@0: aoqi@0: case Interpreter::java_lang_math_sin: aoqi@0: case Interpreter::java_lang_math_cos: aoqi@0: case Interpreter::java_lang_math_tan: aoqi@0: case Interpreter::java_lang_math_abs: aoqi@0: case Interpreter::java_lang_math_log: aoqi@0: case Interpreter::java_lang_math_log10: aoqi@0: case Interpreter::java_lang_math_sqrt: aoqi@0: case Interpreter::java_lang_math_pow: aoqi@0: case Interpreter::java_lang_math_exp: aoqi@0: entry_point = ((InterpreterGenerator*) this)->generate_math_entry(kind); aoqi@0: break; aoqi@0: aoqi@0: case Interpreter::java_lang_ref_reference_get: aoqi@0: entry_point = ((InterpreterGenerator*)this)->generate_Reference_get_entry(); aoqi@0: break; aoqi@0: aoqi@0: default: aoqi@0: ShouldNotReachHere(); aoqi@0: } aoqi@0: aoqi@0: if (entry_point == NULL) aoqi@0: entry_point = ((InterpreterGenerator*) this)->generate_normal_entry(false); aoqi@0: aoqi@0: return entry_point; aoqi@0: } aoqi@0: aoqi@0: InterpreterGenerator::InterpreterGenerator(StubQueue* code) aoqi@0: : CppInterpreterGenerator(code) { aoqi@0: generate_all(); aoqi@0: } aoqi@0: aoqi@0: // Deoptimization helpers aoqi@0: aoqi@0: InterpreterFrame *InterpreterFrame::build(int size, TRAPS) { aoqi@0: ZeroStack *stack = ((JavaThread *) THREAD)->zero_stack(); aoqi@0: aoqi@0: int size_in_words = size >> LogBytesPerWord; aoqi@0: assert(size_in_words * wordSize == size, "unaligned"); aoqi@0: assert(size_in_words >= header_words, "too small"); aoqi@0: stack->overflow_check(size_in_words, CHECK_NULL); aoqi@0: aoqi@0: stack->push(0); // next_frame, filled in later aoqi@0: intptr_t *fp = stack->sp(); aoqi@0: assert(fp - stack->sp() == next_frame_off, "should be"); aoqi@0: aoqi@0: stack->push(INTERPRETER_FRAME); aoqi@0: assert(fp - stack->sp() == frame_type_off, "should be"); aoqi@0: aoqi@0: interpreterState istate = aoqi@0: (interpreterState) stack->alloc(sizeof(BytecodeInterpreter)); aoqi@0: assert(fp - stack->sp() == istate_off, "should be"); aoqi@0: istate->set_self_link(NULL); // mark invalid aoqi@0: aoqi@0: stack->alloc((size_in_words - header_words) * wordSize); aoqi@0: aoqi@0: return (InterpreterFrame *) fp; aoqi@0: } aoqi@0: aoqi@0: int AbstractInterpreter::size_activation(int max_stack, aoqi@0: int tempcount, aoqi@0: int extra_args, aoqi@0: int moncount, aoqi@0: int callee_param_count, aoqi@0: int callee_locals, aoqi@0: bool is_top_frame) { aoqi@0: int header_words = InterpreterFrame::header_words; aoqi@0: int monitor_words = moncount * frame::interpreter_frame_monitor_size(); aoqi@0: int stack_words = is_top_frame ? max_stack : tempcount; aoqi@0: int callee_extra_locals = callee_locals - callee_param_count; aoqi@0: aoqi@0: return header_words + monitor_words + stack_words + callee_extra_locals; aoqi@0: } aoqi@0: aoqi@0: void AbstractInterpreter::layout_activation(Method* method, aoqi@0: int tempcount, aoqi@0: int popframe_extra_args, aoqi@0: int moncount, aoqi@0: int caller_actual_parameters, aoqi@0: int callee_param_count, aoqi@0: int callee_locals, aoqi@0: frame* caller, aoqi@0: frame* interpreter_frame, aoqi@0: bool is_top_frame, aoqi@0: bool is_bottom_frame) { aoqi@0: assert(popframe_extra_args == 0, "what to do?"); aoqi@0: assert(!is_top_frame || (!callee_locals && !callee_param_count), aoqi@0: "top frame should have no caller"); aoqi@0: aoqi@0: // This code must exactly match what InterpreterFrame::build aoqi@0: // does (the full InterpreterFrame::build, that is, not the aoqi@0: // one that creates empty frames for the deoptimizer). aoqi@0: // aoqi@0: // interpreter_frame will be filled in. It's size is determined by aoqi@0: // a previous call to the size_activation() method, aoqi@0: // aoqi@0: // Note that tempcount is the current size of the expression aoqi@0: // stack. For top most frames we will allocate a full sized aoqi@0: // expression stack and not the trimmed version that non-top aoqi@0: // frames have. aoqi@0: aoqi@0: int monitor_words = moncount * frame::interpreter_frame_monitor_size(); aoqi@0: intptr_t *locals = interpreter_frame->fp() + method->max_locals(); aoqi@0: interpreterState istate = interpreter_frame->get_interpreterState(); aoqi@0: intptr_t *monitor_base = (intptr_t*) istate; aoqi@0: intptr_t *stack_base = monitor_base - monitor_words; aoqi@0: intptr_t *stack = stack_base - tempcount - 1; aoqi@0: aoqi@0: BytecodeInterpreter::layout_interpreterState(istate, aoqi@0: caller, aoqi@0: NULL, aoqi@0: method, aoqi@0: locals, aoqi@0: stack, aoqi@0: stack_base, aoqi@0: monitor_base, aoqi@0: NULL, aoqi@0: is_top_frame); aoqi@0: } aoqi@0: aoqi@0: void BytecodeInterpreter::layout_interpreterState(interpreterState istate, aoqi@0: frame* caller, aoqi@0: frame* current, aoqi@0: Method* method, aoqi@0: intptr_t* locals, aoqi@0: intptr_t* stack, aoqi@0: intptr_t* stack_base, aoqi@0: intptr_t* monitor_base, aoqi@0: intptr_t* frame_bottom, aoqi@0: bool is_top_frame) { aoqi@0: istate->set_locals(locals); aoqi@0: istate->set_method(method); aoqi@0: istate->set_self_link(istate); aoqi@0: istate->set_prev_link(NULL); aoqi@0: // thread will be set by a hacky repurposing of frame::patch_pc() aoqi@0: // bcp will be set by vframeArrayElement::unpack_on_stack() aoqi@0: istate->set_constants(method->constants()->cache()); aoqi@0: istate->set_msg(BytecodeInterpreter::method_resume); aoqi@0: istate->set_bcp_advance(0); aoqi@0: istate->set_oop_temp(NULL); aoqi@0: istate->set_mdx(NULL); aoqi@0: if (caller->is_interpreted_frame()) { aoqi@0: interpreterState prev = caller->get_interpreterState(); aoqi@0: prev->set_callee(method); aoqi@0: if (*prev->bcp() == Bytecodes::_invokeinterface) aoqi@0: prev->set_bcp_advance(5); aoqi@0: else aoqi@0: prev->set_bcp_advance(3); aoqi@0: } aoqi@0: istate->set_callee(NULL); aoqi@0: istate->set_monitor_base((BasicObjectLock *) monitor_base); aoqi@0: istate->set_stack_base(stack_base); aoqi@0: istate->set_stack(stack); aoqi@0: istate->set_stack_limit(stack_base - method->max_stack() - 1); aoqi@0: } aoqi@0: aoqi@0: address CppInterpreter::return_entry(TosState state, int length, Bytecodes::Code code) { aoqi@0: ShouldNotCallThis(); aoqi@0: return NULL; aoqi@0: } aoqi@0: aoqi@0: address CppInterpreter::deopt_entry(TosState state, int length) { aoqi@0: return NULL; aoqi@0: } aoqi@0: aoqi@0: // Helper for (runtime) stack overflow checks aoqi@0: aoqi@0: int AbstractInterpreter::size_top_interpreter_activation(Method* method) { aoqi@0: return 0; aoqi@0: } aoqi@0: aoqi@0: // Helper for figuring out if frames are interpreter frames aoqi@0: aoqi@0: bool CppInterpreter::contains(address pc) { aoqi@0: return false; // make frame::print_value_on work aoqi@0: } aoqi@0: aoqi@0: // Result handlers and convertors aoqi@0: aoqi@0: address CppInterpreterGenerator::generate_result_handler_for( aoqi@0: BasicType type) { aoqi@0: assembler()->advance(1); aoqi@0: return ShouldNotCallThisStub(); aoqi@0: } aoqi@0: aoqi@0: address CppInterpreterGenerator::generate_tosca_to_stack_converter( aoqi@0: BasicType type) { aoqi@0: assembler()->advance(1); aoqi@0: return ShouldNotCallThisStub(); aoqi@0: } aoqi@0: aoqi@0: address CppInterpreterGenerator::generate_stack_to_stack_converter( aoqi@0: BasicType type) { aoqi@0: assembler()->advance(1); aoqi@0: return ShouldNotCallThisStub(); aoqi@0: } aoqi@0: aoqi@0: address CppInterpreterGenerator::generate_stack_to_native_abi_converter( aoqi@0: BasicType type) { aoqi@0: assembler()->advance(1); aoqi@0: return ShouldNotCallThisStub(); aoqi@0: } aoqi@0: aoqi@0: #endif // CC_INTERP