Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/cpu/zero/vm/cppInterpreter_zero.cpp
32285 views
/*1* Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.2* Copyright 2007, 2008, 2009, 2010, 2011 Red Hat, Inc.3* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.4*5* This code is free software; you can redistribute it and/or modify it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 2 along with this work; if not, write to the Free Software Foundation,17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18*19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*23*/2425#include "precompiled.hpp"26#include "asm/assembler.hpp"27#include "interpreter/bytecodeHistogram.hpp"28#include "interpreter/cppInterpreter.hpp"29#include "interpreter/interpreter.hpp"30#include "interpreter/interpreterGenerator.hpp"31#include "interpreter/interpreterRuntime.hpp"32#include "oops/arrayOop.hpp"33#include "oops/methodData.hpp"34#include "oops/method.hpp"35#include "oops/oop.inline.hpp"36#include "prims/jvmtiExport.hpp"37#include "prims/jvmtiThreadState.hpp"38#include "runtime/arguments.hpp"39#include "runtime/deoptimization.hpp"40#include "runtime/frame.inline.hpp"41#include "runtime/interfaceSupport.hpp"42#include "runtime/orderAccess.inline.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 SHARK52#include "shark/shark_globals.hpp"53#endif5455#ifdef CC_INTERP5657#define fixup_after_potential_safepoint() \58method = istate->method()5960#define CALL_VM_NOCHECK_NOFIX(func) \61thread->set_last_Java_frame(); \62func; \63thread->reset_last_Java_frame();6465#define CALL_VM_NOCHECK(func) \66CALL_VM_NOCHECK_NOFIX(func) \67fixup_after_potential_safepoint()6869int CppInterpreter::normal_entry(Method* method, intptr_t UNUSED, TRAPS) {70JavaThread *thread = (JavaThread *) THREAD;7172// Allocate and initialize our frame.73InterpreterFrame *frame = InterpreterFrame::build(method, CHECK_0);74thread->push_zero_frame(frame);7576// Execute those bytecodes!77main_loop(0, THREAD);7879// No deoptimized frames on the stack80return 0;81}8283intptr_t narrow(BasicType type, intptr_t result) {84// mask integer result to narrower return type.85switch (type) {86case T_BOOLEAN:87return result&1;88case T_BYTE:89return (intptr_t)(jbyte)result;90case T_CHAR:91return (intptr_t)(uintptr_t)(jchar)result;92case T_SHORT:93return (intptr_t)(jshort)result;94case T_OBJECT: // nothing to do fall through95case T_ARRAY:96case T_LONG:97case T_INT:98case T_FLOAT:99case T_DOUBLE:100case T_VOID:101return result;102default:103ShouldNotReachHere();104return result; // silence compiler warnings105}106}107108109void CppInterpreter::main_loop(int recurse, TRAPS) {110JavaThread *thread = (JavaThread *) THREAD;111ZeroStack *stack = thread->zero_stack();112113// If we are entering from a deopt we may need to call114// ourself a few times in order to get to our frame.115if (recurse)116main_loop(recurse - 1, THREAD);117118InterpreterFrame *frame = thread->top_zero_frame()->as_interpreter_frame();119interpreterState istate = frame->interpreter_state();120Method* method = istate->method();121122intptr_t *result = NULL;123int result_slots = 0;124125while (true) {126// We can set up the frame anchor with everything we want at127// this point as we are thread_in_Java and no safepoints can128// occur until we go to vm mode. We do have to clear flags129// on return from vm but that is it.130thread->set_last_Java_frame();131132// Call the interpreter133if (JvmtiExport::can_post_interpreter_events())134BytecodeInterpreter::runWithChecks(istate);135else136BytecodeInterpreter::run(istate);137fixup_after_potential_safepoint();138139// Clear the frame anchor140thread->reset_last_Java_frame();141142// Examine the message from the interpreter to decide what to do143if (istate->msg() == BytecodeInterpreter::call_method) {144Method* callee = istate->callee();145146// Trim back the stack to put the parameters at the top147stack->set_sp(istate->stack() + 1);148149// Make the call150Interpreter::invoke_method(callee, istate->callee_entry_point(), THREAD);151fixup_after_potential_safepoint();152153// Convert the result154istate->set_stack(stack->sp() - 1);155156// Restore the stack157stack->set_sp(istate->stack_limit() + 1);158159// Resume the interpreter160istate->set_msg(BytecodeInterpreter::method_resume);161}162else if (istate->msg() == BytecodeInterpreter::more_monitors) {163int monitor_words = frame::interpreter_frame_monitor_size();164165// Allocate the space166stack->overflow_check(monitor_words, THREAD);167if (HAS_PENDING_EXCEPTION)168break;169stack->alloc(monitor_words * wordSize);170171// Move the expression stack contents172for (intptr_t *p = istate->stack() + 1; p < istate->stack_base(); p++)173*(p - monitor_words) = *p;174175// Move the expression stack pointers176istate->set_stack_limit(istate->stack_limit() - monitor_words);177istate->set_stack(istate->stack() - monitor_words);178istate->set_stack_base(istate->stack_base() - monitor_words);179180// Zero the new monitor so the interpreter can find it.181((BasicObjectLock *) istate->stack_base())->set_obj(NULL);182183// Resume the interpreter184istate->set_msg(BytecodeInterpreter::got_monitors);185}186else if (istate->msg() == BytecodeInterpreter::return_from_method) {187// Copy the result into the caller's frame188result_slots = type2size[method->result_type()];189assert(result_slots >= 0 && result_slots <= 2, "what?");190result = istate->stack() + result_slots;191break;192}193else if (istate->msg() == BytecodeInterpreter::throwing_exception) {194assert(HAS_PENDING_EXCEPTION, "should do");195break;196}197else if (istate->msg() == BytecodeInterpreter::do_osr) {198// Unwind the current frame199thread->pop_zero_frame();200201// Remove any extension of the previous frame202int extra_locals = method->max_locals() - method->size_of_parameters();203stack->set_sp(stack->sp() + extra_locals);204205// Jump into the OSR method206Interpreter::invoke_osr(207method, istate->osr_entry(), istate->osr_buf(), THREAD);208return;209}210else {211ShouldNotReachHere();212}213}214215// Unwind the current frame216thread->pop_zero_frame();217218// Pop our local variables219stack->set_sp(stack->sp() + method->max_locals());220221// Push our result222for (int i = 0; i < result_slots; i++) {223// Adjust result to smaller224union {225intptr_t res;226jint res_jint;227};228res = result[-i];229if (result_slots == 1) {230BasicType t = method->result_type();231if (is_subword_type(t)) {232res_jint = (jint)narrow(t, res_jint);233}234}235stack->push(res);236}237}238239int CppInterpreter::native_entry(Method* method, intptr_t UNUSED, TRAPS) {240// Make sure method is native and not abstract241assert(method->is_native() && !method->is_abstract(), "should be");242243JavaThread *thread = (JavaThread *) THREAD;244ZeroStack *stack = thread->zero_stack();245246// Allocate and initialize our frame247InterpreterFrame *frame = InterpreterFrame::build(method, CHECK_0);248thread->push_zero_frame(frame);249interpreterState istate = frame->interpreter_state();250intptr_t *locals = istate->locals();251252// Update the invocation counter253if ((UseCompiler || CountCompiledCalls) && !method->is_synchronized()) {254MethodCounters* mcs = method->method_counters();255if (mcs == NULL) {256CALL_VM_NOCHECK(mcs = InterpreterRuntime::build_method_counters(thread, method));257if (HAS_PENDING_EXCEPTION)258goto unwind_and_return;259}260InvocationCounter *counter = mcs->invocation_counter();261counter->increment();262if (counter->reached_InvocationLimit(mcs->backedge_counter())) {263CALL_VM_NOCHECK(264InterpreterRuntime::frequency_counter_overflow(thread, NULL));265if (HAS_PENDING_EXCEPTION)266goto unwind_and_return;267}268}269270// Lock if necessary271BasicObjectLock *monitor;272monitor = NULL;273if (method->is_synchronized()) {274monitor = (BasicObjectLock*) istate->stack_base();275oop lockee = monitor->obj();276markOop disp = lockee->mark()->set_unlocked();277278monitor->lock()->set_displaced_header(disp);279if (Atomic::cmpxchg_ptr(monitor, lockee->mark_addr(), disp) != disp) {280if (thread->is_lock_owned((address) disp->clear_lock_bits())) {281monitor->lock()->set_displaced_header(NULL);282}283else {284CALL_VM_NOCHECK(InterpreterRuntime::monitorenter(thread, monitor));285if (HAS_PENDING_EXCEPTION)286goto unwind_and_return;287}288}289}290291// Get the signature handler292InterpreterRuntime::SignatureHandler *handler; {293address handlerAddr = method->signature_handler();294if (handlerAddr == NULL) {295CALL_VM_NOCHECK(InterpreterRuntime::prepare_native_call(thread, method));296if (HAS_PENDING_EXCEPTION)297goto unlock_unwind_and_return;298299handlerAddr = method->signature_handler();300assert(handlerAddr != NULL, "eh?");301}302if (handlerAddr == (address) InterpreterRuntime::slow_signature_handler) {303CALL_VM_NOCHECK(handlerAddr =304InterpreterRuntime::slow_signature_handler(thread, method, NULL,NULL));305if (HAS_PENDING_EXCEPTION)306goto unlock_unwind_and_return;307}308handler = \309InterpreterRuntime::SignatureHandler::from_handlerAddr(handlerAddr);310}311312// Get the native function entry point313address function;314function = method->native_function();315assert(function != NULL, "should be set if signature handler is");316317// Build the argument list318stack->overflow_check(handler->argument_count() * 2, THREAD);319if (HAS_PENDING_EXCEPTION)320goto unlock_unwind_and_return;321322void **arguments;323void *mirror; {324arguments =325(void **) stack->alloc(handler->argument_count() * sizeof(void **));326void **dst = arguments;327328void *env = thread->jni_environment();329*(dst++) = &env;330331if (method->is_static()) {332istate->set_oop_temp(333method->constants()->pool_holder()->java_mirror());334mirror = istate->oop_temp_addr();335*(dst++) = &mirror;336}337338intptr_t *src = locals;339for (int i = dst - arguments; i < handler->argument_count(); i++) {340ffi_type *type = handler->argument_type(i);341if (type == &ffi_type_pointer) {342if (*src) {343stack->push((intptr_t) src);344*(dst++) = stack->sp();345}346else {347*(dst++) = src;348}349src--;350}351else if (type->size == 4) {352*(dst++) = src--;353}354else if (type->size == 8) {355src--;356*(dst++) = src--;357}358else {359ShouldNotReachHere();360}361}362}363364// Set up the Java frame anchor365thread->set_last_Java_frame();366367// Change the thread state to _thread_in_native368ThreadStateTransition::transition_from_java(thread, _thread_in_native);369370// Make the call371intptr_t result[4 - LogBytesPerWord];372ffi_call(handler->cif(), (void (*)()) function, result, arguments);373374// Change the thread state back to _thread_in_Java.375// ThreadStateTransition::transition_from_native() cannot be used376// here because it does not check for asynchronous exceptions.377// We have to manage the transition ourself.378thread->set_thread_state(_thread_in_native_trans);379380// Make sure new state is visible in the GC thread381if (os::is_MP()) {382if (UseMembar) {383OrderAccess::fence();384}385else {386InterfaceSupport::serialize_memory(thread);387}388}389390// Handle safepoint operations, pending suspend requests,391// and pending asynchronous exceptions.392if (SafepointSynchronize::do_call_back() ||393thread->has_special_condition_for_native_trans()) {394JavaThread::check_special_condition_for_native_trans(thread);395CHECK_UNHANDLED_OOPS_ONLY(thread->clear_unhandled_oops());396}397398// Finally we can change the thread state to _thread_in_Java.399thread->set_thread_state(_thread_in_Java);400fixup_after_potential_safepoint();401402// Clear the frame anchor403thread->reset_last_Java_frame();404405// If the result was an oop then unbox it and store it in406// oop_temp where the garbage collector can see it before407// we release the handle it might be protected by.408if (handler->result_type() == &ffi_type_pointer) {409if (result[0] == 0) {410istate->set_oop_temp(NULL);411} else {412jobject handle = reinterpret_cast<jobject>(result[0]);413istate->set_oop_temp(JNIHandles::resolve(handle));414}415}416417// Reset handle block418thread->active_handles()->clear();419420unlock_unwind_and_return:421422// Unlock if necessary423if (monitor) {424BasicLock *lock = monitor->lock();425markOop header = lock->displaced_header();426oop rcvr = monitor->obj();427monitor->set_obj(NULL);428429if (header != NULL) {430if (Atomic::cmpxchg_ptr(header, rcvr->mark_addr(), lock) != lock) {431monitor->set_obj(rcvr); {432HandleMark hm(thread);433CALL_VM_NOCHECK(InterpreterRuntime::monitorexit(thread, monitor));434}435}436}437}438439unwind_and_return:440441// Unwind the current activation442thread->pop_zero_frame();443444// Pop our parameters445stack->set_sp(stack->sp() + method->size_of_parameters());446447// Push our result448if (!HAS_PENDING_EXCEPTION) {449BasicType type = method->result_type();450stack->set_sp(stack->sp() - type2size[type]);451452switch (type) {453case T_VOID:454break;455456case T_BOOLEAN:457#ifndef VM_LITTLE_ENDIAN458result[0] <<= (BitsPerWord - BitsPerByte);459#endif460SET_LOCALS_INT(*(jboolean *) result != 0, 0);461break;462463case T_CHAR:464#ifndef VM_LITTLE_ENDIAN465result[0] <<= (BitsPerWord - BitsPerShort);466#endif467SET_LOCALS_INT(*(jchar *) result, 0);468break;469470case T_BYTE:471#ifndef VM_LITTLE_ENDIAN472result[0] <<= (BitsPerWord - BitsPerByte);473#endif474SET_LOCALS_INT(*(jbyte *) result, 0);475break;476477case T_SHORT:478#ifndef VM_LITTLE_ENDIAN479result[0] <<= (BitsPerWord - BitsPerShort);480#endif481SET_LOCALS_INT(*(jshort *) result, 0);482break;483484case T_INT:485#ifndef VM_LITTLE_ENDIAN486result[0] <<= (BitsPerWord - BitsPerInt);487#endif488SET_LOCALS_INT(*(jint *) result, 0);489break;490491case T_LONG:492SET_LOCALS_LONG(*(jlong *) result, 0);493break;494495case T_FLOAT:496SET_LOCALS_FLOAT(*(jfloat *) result, 0);497break;498499case T_DOUBLE:500SET_LOCALS_DOUBLE(*(jdouble *) result, 0);501break;502503case T_OBJECT:504case T_ARRAY:505SET_LOCALS_OBJECT(istate->oop_temp(), 0);506break;507508default:509ShouldNotReachHere();510}511}512513// No deoptimized frames on the stack514return 0;515}516517int CppInterpreter::accessor_entry(Method* method, intptr_t UNUSED, TRAPS) {518JavaThread *thread = (JavaThread *) THREAD;519ZeroStack *stack = thread->zero_stack();520intptr_t *locals = stack->sp();521522// Drop into the slow path if we need a safepoint check523if (SafepointSynchronize::do_call_back()) {524return normal_entry(method, 0, THREAD);525}526527// Load the object pointer and drop into the slow path528// if we have a NullPointerException529oop object = LOCALS_OBJECT(0);530if (object == NULL) {531return normal_entry(method, 0, THREAD);532}533534// Read the field index from the bytecode, which looks like this:535// 0: aload_0536// 1: getfield537// 2: index538// 3: index539// 4: ireturn/areturn540// NB this is not raw bytecode: index is in machine order541u1 *code = method->code_base();542assert(code[0] == Bytecodes::_aload_0 &&543code[1] == Bytecodes::_getfield &&544(code[4] == Bytecodes::_ireturn ||545code[4] == Bytecodes::_areturn), "should do");546u2 index = Bytes::get_native_u2(&code[2]);547548// Get the entry from the constant pool cache, and drop into549// the slow path if it has not been resolved550ConstantPoolCache* cache = method->constants()->cache();551ConstantPoolCacheEntry* entry = cache->entry_at(index);552if (!entry->is_resolved(Bytecodes::_getfield)) {553return normal_entry(method, 0, THREAD);554}555556// Get the result and push it onto the stack557switch (entry->flag_state()) {558case ltos:559case dtos:560stack->overflow_check(1, CHECK_0);561stack->alloc(wordSize);562break;563}564if (entry->is_volatile()) {565switch (entry->flag_state()) {566case ctos:567SET_LOCALS_INT(object->char_field_acquire(entry->f2_as_index()), 0);568break;569570case btos:571case ztos:572SET_LOCALS_INT(object->byte_field_acquire(entry->f2_as_index()), 0);573break;574575case stos:576SET_LOCALS_INT(object->short_field_acquire(entry->f2_as_index()), 0);577break;578579case itos:580SET_LOCALS_INT(object->int_field_acquire(entry->f2_as_index()), 0);581break;582583case ltos:584SET_LOCALS_LONG(object->long_field_acquire(entry->f2_as_index()), 0);585break;586587case ftos:588SET_LOCALS_FLOAT(object->float_field_acquire(entry->f2_as_index()), 0);589break;590591case dtos:592SET_LOCALS_DOUBLE(object->double_field_acquire(entry->f2_as_index()), 0);593break;594595case atos:596SET_LOCALS_OBJECT(object->obj_field_acquire(entry->f2_as_index()), 0);597break;598599default:600ShouldNotReachHere();601}602}603else {604switch (entry->flag_state()) {605case ctos:606SET_LOCALS_INT(object->char_field(entry->f2_as_index()), 0);607break;608609case btos:610case ztos:611SET_LOCALS_INT(object->byte_field(entry->f2_as_index()), 0);612break;613614case stos:615SET_LOCALS_INT(object->short_field(entry->f2_as_index()), 0);616break;617618case itos:619SET_LOCALS_INT(object->int_field(entry->f2_as_index()), 0);620break;621622case ltos:623SET_LOCALS_LONG(object->long_field(entry->f2_as_index()), 0);624break;625626case ftos:627SET_LOCALS_FLOAT(object->float_field(entry->f2_as_index()), 0);628break;629630case dtos:631SET_LOCALS_DOUBLE(object->double_field(entry->f2_as_index()), 0);632break;633634case atos:635SET_LOCALS_OBJECT(object->obj_field(entry->f2_as_index()), 0);636break;637638default:639ShouldNotReachHere();640}641}642643// No deoptimized frames on the stack644return 0;645}646647int CppInterpreter::empty_entry(Method* method, intptr_t UNUSED, TRAPS) {648JavaThread *thread = (JavaThread *) THREAD;649ZeroStack *stack = thread->zero_stack();650651// Drop into the slow path if we need a safepoint check652if (SafepointSynchronize::do_call_back()) {653return normal_entry(method, 0, THREAD);654}655656// Pop our parameters657stack->set_sp(stack->sp() + method->size_of_parameters());658659// No deoptimized frames on the stack660return 0;661}662663// The new slots will be inserted before slot insert_before.664// Slots < insert_before will have the same slot number after the insert.665// Slots >= insert_before will become old_slot + num_slots.666void CppInterpreter::insert_vmslots(int insert_before, int num_slots, TRAPS) {667JavaThread *thread = (JavaThread *) THREAD;668ZeroStack *stack = thread->zero_stack();669670// Allocate the space671stack->overflow_check(num_slots, CHECK);672stack->alloc(num_slots * wordSize);673intptr_t *vmslots = stack->sp();674675// Shuffle everything up676for (int i = 0; i < insert_before; i++)677SET_VMSLOTS_SLOT(VMSLOTS_SLOT(i + num_slots), i);678}679680void CppInterpreter::remove_vmslots(int first_slot, int num_slots, TRAPS) {681JavaThread *thread = (JavaThread *) THREAD;682ZeroStack *stack = thread->zero_stack();683intptr_t *vmslots = stack->sp();684685// Move everything down686for (int i = first_slot - 1; i >= 0; i--)687SET_VMSLOTS_SLOT(VMSLOTS_SLOT(i), i + num_slots);688689// Deallocate the space690stack->set_sp(stack->sp() + num_slots);691}692693BasicType CppInterpreter::result_type_of_handle(oop method_handle) {694oop method_type = java_lang_invoke_MethodHandle::type(method_handle);695oop return_type = java_lang_invoke_MethodType::rtype(method_type);696return java_lang_Class::as_BasicType(return_type, (Klass* *) NULL);697}698699intptr_t* CppInterpreter::calculate_unwind_sp(ZeroStack* stack,700oop method_handle) {701oop method_type = java_lang_invoke_MethodHandle::type(method_handle);702int argument_slots = java_lang_invoke_MethodType::ptype_slot_count(method_type);703704return stack->sp() + argument_slots;705}706707IRT_ENTRY(void, CppInterpreter::throw_exception(JavaThread* thread,708Symbol* name,709char* message))710THROW_MSG(name, message);711IRT_END712713InterpreterFrame *InterpreterFrame::build(Method* const method, TRAPS) {714JavaThread *thread = (JavaThread *) THREAD;715ZeroStack *stack = thread->zero_stack();716717// Calculate the size of the frame we'll build, including718// any adjustments to the caller's frame that we'll make.719int extra_locals = 0;720int monitor_words = 0;721int stack_words = 0;722723if (!method->is_native()) {724extra_locals = method->max_locals() - method->size_of_parameters();725stack_words = method->max_stack();726}727if (method->is_synchronized()) {728monitor_words = frame::interpreter_frame_monitor_size();729}730stack->overflow_check(731extra_locals + header_words + monitor_words + stack_words, CHECK_NULL);732733// Adjust the caller's stack frame to accomodate any additional734// local variables we have contiguously with our parameters.735for (int i = 0; i < extra_locals; i++)736stack->push(0);737738intptr_t *locals;739if (method->is_native())740locals = stack->sp() + (method->size_of_parameters() - 1);741else742locals = stack->sp() + (method->max_locals() - 1);743744stack->push(0); // next_frame, filled in later745intptr_t *fp = stack->sp();746assert(fp - stack->sp() == next_frame_off, "should be");747748stack->push(INTERPRETER_FRAME);749assert(fp - stack->sp() == frame_type_off, "should be");750751interpreterState istate =752(interpreterState) stack->alloc(sizeof(BytecodeInterpreter));753assert(fp - stack->sp() == istate_off, "should be");754755istate->set_locals(locals);756istate->set_method(method);757istate->set_self_link(istate);758istate->set_prev_link(NULL);759istate->set_thread(thread);760istate->set_bcp(method->is_native() ? NULL : method->code_base());761istate->set_constants(method->constants()->cache());762istate->set_msg(BytecodeInterpreter::method_entry);763istate->set_oop_temp(NULL);764istate->set_mdx(NULL);765istate->set_callee(NULL);766767istate->set_monitor_base((BasicObjectLock *) stack->sp());768if (method->is_synchronized()) {769BasicObjectLock *monitor =770(BasicObjectLock *) stack->alloc(monitor_words * wordSize);771oop object;772if (method->is_static())773object = method->constants()->pool_holder()->java_mirror();774else775object = (oop) (void*)locals[0];776monitor->set_obj(object);777}778779istate->set_stack_base(stack->sp());780istate->set_stack(stack->sp() - 1);781if (stack_words)782stack->alloc(stack_words * wordSize);783istate->set_stack_limit(stack->sp() - 1);784785return (InterpreterFrame *) fp;786}787788int AbstractInterpreter::BasicType_as_index(BasicType type) {789int i = 0;790switch (type) {791case T_BOOLEAN: i = 0; break;792case T_CHAR : i = 1; break;793case T_BYTE : i = 2; break;794case T_SHORT : i = 3; break;795case T_INT : i = 4; break;796case T_LONG : i = 5; break;797case T_VOID : i = 6; break;798case T_FLOAT : i = 7; break;799case T_DOUBLE : i = 8; break;800case T_OBJECT : i = 9; break;801case T_ARRAY : i = 9; break;802default : ShouldNotReachHere();803}804assert(0 <= i && i < AbstractInterpreter::number_of_result_handlers,805"index out of bounds");806return i;807}808809address InterpreterGenerator::generate_empty_entry() {810if (!UseFastEmptyMethods)811return NULL;812813return generate_entry((address) CppInterpreter::empty_entry);814}815816address InterpreterGenerator::generate_accessor_entry() {817if (!UseFastAccessorMethods)818return NULL;819820return generate_entry((address) CppInterpreter::accessor_entry);821}822823address InterpreterGenerator::generate_Reference_get_entry(void) {824#if INCLUDE_ALL_GCS825if (UseG1GC) {826// We need to generate have a routine that generates code to:827// * load the value in the referent field828// * passes that value to the pre-barrier.829//830// In the case of G1 this will record the value of the831// referent in an SATB buffer if marking is active.832// This will cause concurrent marking to mark the referent833// field as live.834Unimplemented();835}836#endif // INCLUDE_ALL_GCS837838// If G1 is not enabled then attempt to go through the accessor entry point839// Reference.get is an accessor840return generate_accessor_entry();841}842843address InterpreterGenerator::generate_native_entry(bool synchronized) {844assert(synchronized == false, "should be");845846return generate_entry((address) CppInterpreter::native_entry);847}848849address InterpreterGenerator::generate_normal_entry(bool synchronized) {850assert(synchronized == false, "should be");851852return generate_entry((address) CppInterpreter::normal_entry);853}854855address AbstractInterpreterGenerator::generate_method_entry(856AbstractInterpreter::MethodKind kind) {857address entry_point = NULL;858859switch (kind) {860case Interpreter::zerolocals:861case Interpreter::zerolocals_synchronized:862break;863864case Interpreter::native:865entry_point = ((InterpreterGenerator*) this)->generate_native_entry(false);866break;867868case Interpreter::native_synchronized:869entry_point = ((InterpreterGenerator*) this)->generate_native_entry(false);870break;871872case Interpreter::empty:873entry_point = ((InterpreterGenerator*) this)->generate_empty_entry();874break;875876case Interpreter::accessor:877entry_point = ((InterpreterGenerator*) this)->generate_accessor_entry();878break;879880case Interpreter::abstract:881entry_point = ((InterpreterGenerator*) this)->generate_abstract_entry();882break;883884case Interpreter::java_lang_math_sin:885case Interpreter::java_lang_math_cos:886case Interpreter::java_lang_math_tan:887case Interpreter::java_lang_math_abs:888case Interpreter::java_lang_math_log:889case Interpreter::java_lang_math_log10:890case Interpreter::java_lang_math_sqrt:891case Interpreter::java_lang_math_pow:892case Interpreter::java_lang_math_exp:893entry_point = ((InterpreterGenerator*) this)->generate_math_entry(kind);894break;895896case Interpreter::java_lang_ref_reference_get:897entry_point = ((InterpreterGenerator*)this)->generate_Reference_get_entry();898break;899900default:901ShouldNotReachHere();902}903904if (entry_point == NULL)905entry_point = ((InterpreterGenerator*) this)->generate_normal_entry(false);906907return entry_point;908}909910InterpreterGenerator::InterpreterGenerator(StubQueue* code)911: CppInterpreterGenerator(code) {912generate_all();913}914915// Deoptimization helpers916917InterpreterFrame *InterpreterFrame::build(int size, TRAPS) {918ZeroStack *stack = ((JavaThread *) THREAD)->zero_stack();919920int size_in_words = size >> LogBytesPerWord;921assert(size_in_words * wordSize == size, "unaligned");922assert(size_in_words >= header_words, "too small");923stack->overflow_check(size_in_words, CHECK_NULL);924925stack->push(0); // next_frame, filled in later926intptr_t *fp = stack->sp();927assert(fp - stack->sp() == next_frame_off, "should be");928929stack->push(INTERPRETER_FRAME);930assert(fp - stack->sp() == frame_type_off, "should be");931932interpreterState istate =933(interpreterState) stack->alloc(sizeof(BytecodeInterpreter));934assert(fp - stack->sp() == istate_off, "should be");935istate->set_self_link(NULL); // mark invalid936937stack->alloc((size_in_words - header_words) * wordSize);938939return (InterpreterFrame *) fp;940}941942int AbstractInterpreter::size_activation(int max_stack,943int tempcount,944int extra_args,945int moncount,946int callee_param_count,947int callee_locals,948bool is_top_frame) {949int header_words = InterpreterFrame::header_words;950int monitor_words = moncount * frame::interpreter_frame_monitor_size();951int stack_words = is_top_frame ? max_stack : tempcount;952int callee_extra_locals = callee_locals - callee_param_count;953954return header_words + monitor_words + stack_words + callee_extra_locals;955}956957void AbstractInterpreter::layout_activation(Method* method,958int tempcount,959int popframe_extra_args,960int moncount,961int caller_actual_parameters,962int callee_param_count,963int callee_locals,964frame* caller,965frame* interpreter_frame,966bool is_top_frame,967bool is_bottom_frame) {968assert(popframe_extra_args == 0, "what to do?");969assert(!is_top_frame || (!callee_locals && !callee_param_count),970"top frame should have no caller");971972// This code must exactly match what InterpreterFrame::build973// does (the full InterpreterFrame::build, that is, not the974// one that creates empty frames for the deoptimizer).975//976// interpreter_frame will be filled in. It's size is determined by977// a previous call to the size_activation() method,978//979// Note that tempcount is the current size of the expression980// stack. For top most frames we will allocate a full sized981// expression stack and not the trimmed version that non-top982// frames have.983984int monitor_words = moncount * frame::interpreter_frame_monitor_size();985intptr_t *locals = interpreter_frame->fp() + method->max_locals();986interpreterState istate = interpreter_frame->get_interpreterState();987intptr_t *monitor_base = (intptr_t*) istate;988intptr_t *stack_base = monitor_base - monitor_words;989intptr_t *stack = stack_base - tempcount - 1;990991BytecodeInterpreter::layout_interpreterState(istate,992caller,993NULL,994method,995locals,996stack,997stack_base,998monitor_base,999NULL,1000is_top_frame);1001}10021003void BytecodeInterpreter::layout_interpreterState(interpreterState istate,1004frame* caller,1005frame* current,1006Method* method,1007intptr_t* locals,1008intptr_t* stack,1009intptr_t* stack_base,1010intptr_t* monitor_base,1011intptr_t* frame_bottom,1012bool is_top_frame) {1013istate->set_locals(locals);1014istate->set_method(method);1015istate->set_self_link(istate);1016istate->set_prev_link(NULL);1017// thread will be set by a hacky repurposing of frame::patch_pc()1018// bcp will be set by vframeArrayElement::unpack_on_stack()1019istate->set_constants(method->constants()->cache());1020istate->set_msg(BytecodeInterpreter::method_resume);1021istate->set_bcp_advance(0);1022istate->set_oop_temp(NULL);1023istate->set_mdx(NULL);1024if (caller->is_interpreted_frame()) {1025interpreterState prev = caller->get_interpreterState();1026prev->set_callee(method);1027if (*prev->bcp() == Bytecodes::_invokeinterface)1028prev->set_bcp_advance(5);1029else1030prev->set_bcp_advance(3);1031}1032istate->set_callee(NULL);1033istate->set_monitor_base((BasicObjectLock *) monitor_base);1034istate->set_stack_base(stack_base);1035istate->set_stack(stack);1036istate->set_stack_limit(stack_base - method->max_stack() - 1);1037}10381039address CppInterpreter::return_entry(TosState state, int length, Bytecodes::Code code) {1040ShouldNotCallThis();1041return NULL;1042}10431044address CppInterpreter::deopt_entry(TosState state, int length) {1045return NULL;1046}10471048// Helper for (runtime) stack overflow checks10491050int AbstractInterpreter::size_top_interpreter_activation(Method* method) {1051return 0;1052}10531054// Helper for figuring out if frames are interpreter frames10551056bool CppInterpreter::contains(address pc) {1057return false; // make frame::print_value_on work1058}10591060// Result handlers and convertors10611062address CppInterpreterGenerator::generate_result_handler_for(1063BasicType type) {1064assembler()->advance(1);1065return ShouldNotCallThisStub();1066}10671068address CppInterpreterGenerator::generate_tosca_to_stack_converter(1069BasicType type) {1070assembler()->advance(1);1071return ShouldNotCallThisStub();1072}10731074address CppInterpreterGenerator::generate_stack_to_stack_converter(1075BasicType type) {1076assembler()->advance(1);1077return ShouldNotCallThisStub();1078}10791080address CppInterpreterGenerator::generate_stack_to_native_abi_converter(1081BasicType type) {1082assembler()->advance(1);1083return ShouldNotCallThisStub();1084}10851086#endif // CC_INTERP108710881089