Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/cpu/sparc/vm/cppInterpreter_sparc.cpp
32285 views
/*1* Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "asm/assembler.hpp"26#include "interpreter/bytecodeHistogram.hpp"27#include "interpreter/cppInterpreter.hpp"28#include "interpreter/interpreter.hpp"29#include "interpreter/interpreterGenerator.hpp"30#include "interpreter/interpreterRuntime.hpp"31#include "oops/arrayOop.hpp"32#include "oops/methodData.hpp"33#include "oops/method.hpp"34#include "oops/oop.inline.hpp"35#include "prims/jvmtiExport.hpp"36#include "prims/jvmtiThreadState.hpp"37#include "runtime/arguments.hpp"38#include "runtime/deoptimization.hpp"39#include "runtime/frame.inline.hpp"40#include "runtime/interfaceSupport.hpp"41#include "runtime/sharedRuntime.hpp"42#include "runtime/stubRoutines.hpp"43#include "runtime/synchronizer.hpp"44#include "runtime/timer.hpp"45#include "runtime/vframeArray.hpp"46#include "utilities/debug.hpp"47#include "utilities/macros.hpp"48#ifdef SHARK49#include "shark/shark_globals.hpp"50#endif5152#ifdef CC_INTERP5354// Routine exists to make tracebacks look decent in debugger55// while "shadow" interpreter frames are on stack. It is also56// used to distinguish interpreter frames.5758extern "C" void RecursiveInterpreterActivation(interpreterState istate) {59ShouldNotReachHere();60}6162bool CppInterpreter::contains(address pc) {63return ( _code->contains(pc) ||64( pc == (CAST_FROM_FN_PTR(address, RecursiveInterpreterActivation) + frame::pc_return_offset)));65}6667#define STATE(field_name) Lstate, in_bytes(byte_offset_of(BytecodeInterpreter, field_name))68#define __ _masm->6970Label frame_manager_entry;71Label fast_accessor_slow_entry_path; // fast accessor methods need to be able to jmp to unsynchronized72// c++ interpreter entry point this holds that entry point label.7374static address unctrap_frame_manager_entry = NULL;7576static address interpreter_return_address = NULL;77static address deopt_frame_manager_return_atos = NULL;78static address deopt_frame_manager_return_btos = NULL;79static address deopt_frame_manager_return_itos = NULL;80static address deopt_frame_manager_return_ltos = NULL;81static address deopt_frame_manager_return_ftos = NULL;82static address deopt_frame_manager_return_dtos = NULL;83static address deopt_frame_manager_return_vtos = NULL;8485const Register prevState = G1_scratch;8687void InterpreterGenerator::save_native_result(void) {88// result potentially in O0/O1: save it across calls89__ stf(FloatRegisterImpl::D, F0, STATE(_native_fresult));90#ifdef _LP6491__ stx(O0, STATE(_native_lresult));92#else93__ std(O0, STATE(_native_lresult));94#endif95}9697void InterpreterGenerator::restore_native_result(void) {9899// Restore any method result value100__ ldf(FloatRegisterImpl::D, STATE(_native_fresult), F0);101#ifdef _LP64102__ ldx(STATE(_native_lresult), O0);103#else104__ ldd(STATE(_native_lresult), O0);105#endif106}107108// A result handler converts/unboxes a native call result into109// a java interpreter/compiler result. The current frame is an110// interpreter frame. The activation frame unwind code must be111// consistent with that of TemplateTable::_return(...). In the112// case of native methods, the caller's SP was not modified.113address CppInterpreterGenerator::generate_result_handler_for(BasicType type) {114address entry = __ pc();115Register Itos_i = Otos_i ->after_save();116Register Itos_l = Otos_l ->after_save();117Register Itos_l1 = Otos_l1->after_save();118Register Itos_l2 = Otos_l2->after_save();119switch (type) {120case T_BOOLEAN: __ subcc(G0, O0, G0); __ addc(G0, 0, Itos_i); break; // !0 => true; 0 => false121case T_CHAR : __ sll(O0, 16, O0); __ srl(O0, 16, Itos_i); break; // cannot use and3, 0xFFFF too big as immediate value!122case T_BYTE : __ sll(O0, 24, O0); __ sra(O0, 24, Itos_i); break;123case T_SHORT : __ sll(O0, 16, O0); __ sra(O0, 16, Itos_i); break;124case T_LONG :125#ifndef _LP64126__ mov(O1, Itos_l2); // move other half of long127#endif // ifdef or no ifdef, fall through to the T_INT case128case T_INT : __ mov(O0, Itos_i); break;129case T_VOID : /* nothing to do */ break;130case T_FLOAT : assert(F0 == Ftos_f, "fix this code" ); break;131case T_DOUBLE : assert(F0 == Ftos_d, "fix this code" ); break;132case T_OBJECT :133__ ld_ptr(STATE(_oop_temp), Itos_i);134__ verify_oop(Itos_i);135break;136default : ShouldNotReachHere();137}138__ ret(); // return from interpreter activation139__ delayed()->restore(I5_savedSP, G0, SP); // remove interpreter frame140NOT_PRODUCT(__ emit_int32(0);) // marker for disassembly141return entry;142}143144// tosca based result to c++ interpreter stack based result.145// Result goes to address in L1_scratch146147address CppInterpreterGenerator::generate_tosca_to_stack_converter(BasicType type) {148// A result is in the native abi result register from a native method call.149// We need to return this result to the interpreter by pushing the result on the interpreter's150// stack. This is relatively simple the destination is in L1_scratch151// i.e. L1_scratch is the first free element on the stack. If we "push" a return value we must152// adjust L1_scratch153address entry = __ pc();154switch (type) {155case T_BOOLEAN:156// !0 => true; 0 => false157__ subcc(G0, O0, G0);158__ addc(G0, 0, O0);159__ st(O0, L1_scratch, 0);160__ sub(L1_scratch, wordSize, L1_scratch);161break;162163// cannot use and3, 0xFFFF too big as immediate value!164case T_CHAR :165__ sll(O0, 16, O0);166__ srl(O0, 16, O0);167__ st(O0, L1_scratch, 0);168__ sub(L1_scratch, wordSize, L1_scratch);169break;170171case T_BYTE :172__ sll(O0, 24, O0);173__ sra(O0, 24, O0);174__ st(O0, L1_scratch, 0);175__ sub(L1_scratch, wordSize, L1_scratch);176break;177178case T_SHORT :179__ sll(O0, 16, O0);180__ sra(O0, 16, O0);181__ st(O0, L1_scratch, 0);182__ sub(L1_scratch, wordSize, L1_scratch);183break;184case T_LONG :185#ifndef _LP64186#if defined(COMPILER2)187// All return values are where we want them, except for Longs. C2 returns188// longs in G1 in the 32-bit build whereas the interpreter wants them in O0/O1.189// Since the interpreter will return longs in G1 and O0/O1 in the 32bit190// build even if we are returning from interpreted we just do a little191// stupid shuffing.192// Note: I tried to make c2 return longs in O0/O1 and G1 so we wouldn't have to193// do this here. Unfortunately if we did a rethrow we'd see an machepilog node194// first which would move g1 -> O0/O1 and destroy the exception we were throwing.195__ stx(G1, L1_scratch, -wordSize);196#else197// native result is in O0, O1198__ st(O1, L1_scratch, 0); // Low order199__ st(O0, L1_scratch, -wordSize); // High order200#endif /* COMPILER2 */201#else202__ stx(O0, L1_scratch, -wordSize);203#endif204__ sub(L1_scratch, 2*wordSize, L1_scratch);205break;206207case T_INT :208__ st(O0, L1_scratch, 0);209__ sub(L1_scratch, wordSize, L1_scratch);210break;211212case T_VOID : /* nothing to do */213break;214215case T_FLOAT :216__ stf(FloatRegisterImpl::S, F0, L1_scratch, 0);217__ sub(L1_scratch, wordSize, L1_scratch);218break;219220case T_DOUBLE :221// Every stack slot is aligned on 64 bit, However is this222// the correct stack slot on 64bit?? QQQ223__ stf(FloatRegisterImpl::D, F0, L1_scratch, -wordSize);224__ sub(L1_scratch, 2*wordSize, L1_scratch);225break;226case T_OBJECT :227__ verify_oop(O0);228__ st_ptr(O0, L1_scratch, 0);229__ sub(L1_scratch, wordSize, L1_scratch);230break;231default : ShouldNotReachHere();232}233__ retl(); // return from interpreter activation234__ delayed()->nop(); // schedule this better235NOT_PRODUCT(__ emit_int32(0);) // marker for disassembly236return entry;237}238239address CppInterpreterGenerator::generate_stack_to_stack_converter(BasicType type) {240// A result is in the java expression stack of the interpreted method that has just241// returned. Place this result on the java expression stack of the caller.242//243// The current interpreter activation in Lstate is for the method just returning its244// result. So we know that the result of this method is on the top of the current245// execution stack (which is pre-pushed) and will be return to the top of the caller246// stack. The top of the callers stack is the bottom of the locals of the current247// activation.248// Because of the way activation are managed by the frame manager the value of esp is249// below both the stack top of the current activation and naturally the stack top250// of the calling activation. This enable this routine to leave the return address251// to the frame manager on the stack and do a vanilla return.252//253// On entry: O0 - points to source (callee stack top)254// O1 - points to destination (caller stack top [i.e. free location])255// destroys O2, O3256//257258address entry = __ pc();259switch (type) {260case T_VOID: break;261break;262case T_FLOAT :263case T_BOOLEAN:264case T_CHAR :265case T_BYTE :266case T_SHORT :267case T_INT :268// 1 word result269__ ld(O0, 0, O2);270__ st(O2, O1, 0);271__ sub(O1, wordSize, O1);272break;273case T_DOUBLE :274case T_LONG :275// return top two words on current expression stack to caller's expression stack276// The caller's expression stack is adjacent to the current frame manager's intepretState277// except we allocated one extra word for this intepretState so we won't overwrite it278// when we return a two word result.279#ifdef _LP64280__ ld_ptr(O0, 0, O2);281__ st_ptr(O2, O1, -wordSize);282#else283__ ld(O0, 0, O2);284__ ld(O0, wordSize, O3);285__ st(O3, O1, 0);286__ st(O2, O1, -wordSize);287#endif288__ sub(O1, 2*wordSize, O1);289break;290case T_OBJECT :291__ ld_ptr(O0, 0, O2);292__ verify_oop(O2); // verify it293__ st_ptr(O2, O1, 0);294__ sub(O1, wordSize, O1);295break;296default : ShouldNotReachHere();297}298__ retl();299__ delayed()->nop(); // QQ schedule this better300return entry;301}302303address CppInterpreterGenerator::generate_stack_to_native_abi_converter(BasicType type) {304// A result is in the java expression stack of the interpreted method that has just305// returned. Place this result in the native abi that the caller expects.306// We are in a new frame registers we set must be in caller (i.e. callstub) frame.307//308// Similar to generate_stack_to_stack_converter above. Called at a similar time from the309// frame manager execept in this situation the caller is native code (c1/c2/call_stub)310// and so rather than return result onto caller's java expression stack we return the311// result in the expected location based on the native abi.312// On entry: O0 - source (stack top)313// On exit result in expected output register314// QQQ schedule this better315316address entry = __ pc();317switch (type) {318case T_VOID: break;319break;320case T_FLOAT :321__ ldf(FloatRegisterImpl::S, O0, 0, F0);322break;323case T_BOOLEAN:324case T_CHAR :325case T_BYTE :326case T_SHORT :327case T_INT :328// 1 word result329__ ld(O0, 0, O0->after_save());330break;331case T_DOUBLE :332__ ldf(FloatRegisterImpl::D, O0, 0, F0);333break;334case T_LONG :335// return top two words on current expression stack to caller's expression stack336// The caller's expression stack is adjacent to the current frame manager's interpretState337// except we allocated one extra word for this intepretState so we won't overwrite it338// when we return a two word result.339#ifdef _LP64340__ ld_ptr(O0, 0, O0->after_save());341#else342__ ld(O0, wordSize, O1->after_save());343__ ld(O0, 0, O0->after_save());344#endif345#if defined(COMPILER2) && !defined(_LP64)346// C2 expects long results in G1 we can't tell if we're returning to interpreted347// or compiled so just be safe use G1 and O0/O1348349// Shift bits into high (msb) of G1350__ sllx(Otos_l1->after_save(), 32, G1);351// Zero extend low bits352__ srl (Otos_l2->after_save(), 0, Otos_l2->after_save());353__ or3 (Otos_l2->after_save(), G1, G1);354#endif /* COMPILER2 */355break;356case T_OBJECT :357__ ld_ptr(O0, 0, O0->after_save());358__ verify_oop(O0->after_save()); // verify it359break;360default : ShouldNotReachHere();361}362__ retl();363__ delayed()->nop();364return entry;365}366367address CppInterpreter::return_entry(TosState state, int length, Bytecodes::Code code) {368// make it look good in the debugger369return CAST_FROM_FN_PTR(address, RecursiveInterpreterActivation) + frame::pc_return_offset;370}371372address CppInterpreter::deopt_entry(TosState state, int length) {373address ret = NULL;374if (length != 0) {375switch (state) {376case atos: ret = deopt_frame_manager_return_atos; break;377case btos: ret = deopt_frame_manager_return_btos; break;378case ctos:379case stos:380case itos: ret = deopt_frame_manager_return_itos; break;381case ltos: ret = deopt_frame_manager_return_ltos; break;382case ftos: ret = deopt_frame_manager_return_ftos; break;383case dtos: ret = deopt_frame_manager_return_dtos; break;384case vtos: ret = deopt_frame_manager_return_vtos; break;385}386} else {387ret = unctrap_frame_manager_entry; // re-execute the bytecode ( e.g. uncommon trap)388}389assert(ret != NULL, "Not initialized");390return ret;391}392393//394// Helpers for commoning out cases in the various type of method entries.395//396397// increment invocation count & check for overflow398//399// Note: checking for negative value instead of overflow400// so we have a 'sticky' overflow test401//402// Lmethod: method403// ??: invocation counter404//405void InterpreterGenerator::generate_counter_incr(Label* overflow, Label* profile_method, Label* profile_method_continue) {406Label done;407const Register Rcounters = G3_scratch;408409__ ld_ptr(STATE(_method), G5_method);410__ get_method_counters(G5_method, Rcounters, done);411412// Update standard invocation counters413__ increment_invocation_counter(Rcounters, O0, G4_scratch);414if (ProfileInterpreter) {415Address interpreter_invocation_counter(Rcounters, 0,416in_bytes(MethodCounters::interpreter_invocation_counter_offset()));417__ ld(interpreter_invocation_counter, G4_scratch);418__ inc(G4_scratch);419__ st(G4_scratch, interpreter_invocation_counter);420}421422Address invocation_limit(G3_scratch, (address)&InvocationCounter::InterpreterInvocationLimit);423__ sethi(invocation_limit);424__ ld(invocation_limit, G3_scratch);425__ cmp(O0, G3_scratch);426__ br(Assembler::greaterEqualUnsigned, false, Assembler::pn, *overflow);427__ delayed()->nop();428__ bind(done);429}430431address InterpreterGenerator::generate_empty_entry(void) {432433// A method that does nothing but return...434435address entry = __ pc();436Label slow_path;437438// do nothing for empty methods (do not even increment invocation counter)439if ( UseFastEmptyMethods) {440// If we need a safepoint check, generate full interpreter entry.441Address sync_state(G3_scratch, SafepointSynchronize::address_of_state());442__ load_contents(sync_state, G3_scratch);443__ cmp(G3_scratch, SafepointSynchronize::_not_synchronized);444__ br(Assembler::notEqual, false, Assembler::pn, frame_manager_entry);445__ delayed()->nop();446447// Code: _return448__ retl();449__ delayed()->mov(O5_savedSP, SP);450return entry;451}452return NULL;453}454455// Call an accessor method (assuming it is resolved, otherwise drop into456// vanilla (slow path) entry457458// Generates code to elide accessor methods459// Uses G3_scratch and G1_scratch as scratch460address InterpreterGenerator::generate_accessor_entry(void) {461462// Code: _aload_0, _(i|a)getfield, _(i|a)return or any rewrites thereof;463// parameter size = 1464// Note: We can only use this code if the getfield has been resolved465// and if we don't have a null-pointer exception => check for466// these conditions first and use slow path if necessary.467address entry = __ pc();468Label slow_path;469470if ( UseFastAccessorMethods) {471// Check if we need to reach a safepoint and generate full interpreter472// frame if so.473Address sync_state(G3_scratch, SafepointSynchronize::address_of_state());474__ load_contents(sync_state, G3_scratch);475__ cmp(G3_scratch, SafepointSynchronize::_not_synchronized);476__ br(Assembler::notEqual, false, Assembler::pn, slow_path);477__ delayed()->nop();478479// Check if local 0 != NULL480__ ld_ptr(Gargs, G0, Otos_i ); // get local 0481__ tst(Otos_i); // check if local 0 == NULL and go the slow path482__ brx(Assembler::zero, false, Assembler::pn, slow_path);483__ delayed()->nop();484485486// read first instruction word and extract bytecode @ 1 and index @ 2487// get first 4 bytes of the bytecodes (big endian!)488__ ld_ptr(Address(G5_method, 0, in_bytes(Method::const_offset())), G1_scratch);489__ ld(Address(G1_scratch, 0, in_bytes(ConstMethod::codes_offset())), G1_scratch);490491// move index @ 2 far left then to the right most two bytes.492__ sll(G1_scratch, 2*BitsPerByte, G1_scratch);493__ srl(G1_scratch, 2*BitsPerByte - exact_log2(in_words(494ConstantPoolCacheEntry::size()) * BytesPerWord), G1_scratch);495496// get constant pool cache497__ ld_ptr(G5_method, in_bytes(Method::const_offset()), G3_scratch);498__ ld_ptr(G3_scratch, in_bytes(ConstMethod::constants_offset()), G3_scratch);499__ ld_ptr(G3_scratch, ConstantPool::cache_offset_in_bytes(), G3_scratch);500501// get specific constant pool cache entry502__ add(G3_scratch, G1_scratch, G3_scratch);503504// Check the constant Pool cache entry to see if it has been resolved.505// If not, need the slow path.506ByteSize cp_base_offset = ConstantPoolCache::base_offset();507__ ld_ptr(G3_scratch, in_bytes(cp_base_offset + ConstantPoolCacheEntry::indices_offset()), G1_scratch);508__ srl(G1_scratch, 2*BitsPerByte, G1_scratch);509__ and3(G1_scratch, 0xFF, G1_scratch);510__ cmp(G1_scratch, Bytecodes::_getfield);511__ br(Assembler::notEqual, false, Assembler::pn, slow_path);512__ delayed()->nop();513514// Get the type and return field offset from the constant pool cache515__ ld_ptr(G3_scratch, in_bytes(cp_base_offset + ConstantPoolCacheEntry::flags_offset()), G1_scratch);516__ ld_ptr(G3_scratch, in_bytes(cp_base_offset + ConstantPoolCacheEntry::f2_offset()), G3_scratch);517518Label xreturn_path;519// Need to differentiate between igetfield, agetfield, bgetfield etc.520// because they are different sizes.521// Get the type from the constant pool cache522__ srl(G1_scratch, ConstantPoolCacheEntry::tos_state_shift, G1_scratch);523// Make sure we don't need to mask G1_scratch after the above shift524ConstantPoolCacheEntry::verify_tos_state_shift();525__ cmp(G1_scratch, atos );526__ br(Assembler::equal, true, Assembler::pt, xreturn_path);527__ delayed()->ld_ptr(Otos_i, G3_scratch, Otos_i);528__ cmp(G1_scratch, itos);529__ br(Assembler::equal, true, Assembler::pt, xreturn_path);530__ delayed()->ld(Otos_i, G3_scratch, Otos_i);531__ cmp(G1_scratch, stos);532__ br(Assembler::equal, true, Assembler::pt, xreturn_path);533__ delayed()->ldsh(Otos_i, G3_scratch, Otos_i);534__ cmp(G1_scratch, ctos);535__ br(Assembler::equal, true, Assembler::pt, xreturn_path);536__ delayed()->lduh(Otos_i, G3_scratch, Otos_i);537#ifdef ASSERT538__ cmp(G1_scratch, btos);539__ br(Assembler::equal, true, Assembler::pt, xreturn_path);540__ delayed()->ldsb(Otos_i, G3_scratch, Otos_i);541__ cmp(G1_scratch, ztos);542__ br(Assembler::equal, true, Assembler::pt, xreturn_path);543__ delayed()->ldsb(Otos_i, G3_scratch, Otos_i);544__ should_not_reach_here();545#endif546__ ldsb(Otos_i, G3_scratch, Otos_i);547__ bind(xreturn_path);548549// _ireturn/_areturn550__ retl(); // return from leaf routine551__ delayed()->mov(O5_savedSP, SP);552553// Generate regular method entry554__ bind(slow_path);555__ ba(fast_accessor_slow_entry_path);556__ delayed()->nop();557return entry;558}559return NULL;560}561562address InterpreterGenerator::generate_Reference_get_entry(void) {563#if INCLUDE_ALL_GCS564if (UseG1GC) {565// We need to generate have a routine that generates code to:566// * load the value in the referent field567// * passes that value to the pre-barrier.568//569// In the case of G1 this will record the value of the570// referent in an SATB buffer if marking is active.571// This will cause concurrent marking to mark the referent572// field as live.573Unimplemented();574}575#endif // INCLUDE_ALL_GCS576577// If G1 is not enabled then attempt to go through the accessor entry point578// Reference.get is an accessor579return generate_accessor_entry();580}581582//583// Interpreter stub for calling a native method. (C++ interpreter)584// This sets up a somewhat different looking stack for calling the native method585// than the typical interpreter frame setup.586//587588address InterpreterGenerator::generate_native_entry(bool synchronized) {589address entry = __ pc();590591// the following temporary registers are used during frame creation592const Register Gtmp1 = G3_scratch ;593const Register Gtmp2 = G1_scratch;594const Register RconstMethod = Gtmp1;595const Address constMethod(G5_method, 0, in_bytes(Method::const_offset()));596const Address size_of_parameters(RconstMethod, 0, in_bytes(ConstMethod::size_of_parameters_offset()));597598bool inc_counter = UseCompiler || CountCompiledCalls;599600// make sure registers are different!601assert_different_registers(G2_thread, G5_method, Gargs, Gtmp1, Gtmp2);602603const Address access_flags (G5_method, 0, in_bytes(Method::access_flags_offset()));604605Label Lentry;606__ bind(Lentry);607608const Register Glocals_size = G3;609assert_different_registers(Glocals_size, G4_scratch, Gframe_size);610611// make sure method is native & not abstract612// rethink these assertions - they can be simplified and shared (gri 2/25/2000)613#ifdef ASSERT614__ ld(access_flags, Gtmp1);615{616Label L;617__ btst(JVM_ACC_NATIVE, Gtmp1);618__ br(Assembler::notZero, false, Assembler::pt, L);619__ delayed()->nop();620__ stop("tried to execute non-native method as native");621__ bind(L);622}623{ Label L;624__ btst(JVM_ACC_ABSTRACT, Gtmp1);625__ br(Assembler::zero, false, Assembler::pt, L);626__ delayed()->nop();627__ stop("tried to execute abstract method as non-abstract");628__ bind(L);629}630#endif // ASSERT631632__ ld_ptr(constMethod, RconstMethod);633__ lduh(size_of_parameters, Gtmp1);634__ sll(Gtmp1, LogBytesPerWord, Gtmp2); // parameter size in bytes635__ add(Gargs, Gtmp2, Gargs); // points to first local + BytesPerWord636// NEW637__ add(Gargs, -wordSize, Gargs); // points to first local[0]638// generate the code to allocate the interpreter stack frame639// NEW FRAME ALLOCATED HERE640// save callers original sp641// __ mov(SP, I5_savedSP->after_restore());642643generate_compute_interpreter_state(Lstate, G0, true);644645// At this point Lstate points to new interpreter state646//647648const Address do_not_unlock_if_synchronized(G2_thread, 0,649in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));650// Since at this point in the method invocation the exception handler651// would try to exit the monitor of synchronized methods which hasn't652// been entered yet, we set the thread local variable653// _do_not_unlock_if_synchronized to true. If any exception was thrown by654// runtime, exception handling i.e. unlock_if_synchronized_method will655// check this thread local flag.656// This flag has two effects, one is to force an unwind in the topmost657// interpreter frame and not perform an unlock while doing so.658659__ movbool(true, G3_scratch);660__ stbool(G3_scratch, do_not_unlock_if_synchronized);661662663// increment invocation counter and check for overflow664//665// Note: checking for negative value instead of overflow666// so we have a 'sticky' overflow test (may be of667// importance as soon as we have true MT/MP)668Label invocation_counter_overflow;669if (inc_counter) {670generate_counter_incr(&invocation_counter_overflow, NULL, NULL);671}672Label Lcontinue;673__ bind(Lcontinue);674675bang_stack_shadow_pages(true);676// reset the _do_not_unlock_if_synchronized flag677__ stbool(G0, do_not_unlock_if_synchronized);678679// check for synchronized methods680// Must happen AFTER invocation_counter check, so method is not locked681// if counter overflows.682683if (synchronized) {684lock_method();685// Don't see how G2_thread is preserved here...686// __ verify_thread(); QQQ destroys L0,L1 can't use687} else {688#ifdef ASSERT689{ Label ok;690__ ld_ptr(STATE(_method), G5_method);691__ ld(access_flags, O0);692__ btst(JVM_ACC_SYNCHRONIZED, O0);693__ br( Assembler::zero, false, Assembler::pt, ok);694__ delayed()->nop();695__ stop("method needs synchronization");696__ bind(ok);697}698#endif // ASSERT699}700701// start execution702703// __ verify_thread(); kills L1,L2 can't use at the moment704705// jvmti/jvmpi support706__ notify_method_entry();707708// native call709710// (note that O0 is never an oop--at most it is a handle)711// It is important not to smash any handles created by this call,712// until any oop handle in O0 is dereferenced.713714// (note that the space for outgoing params is preallocated)715716// get signature handler717718Label pending_exception_present;719720{ Label L;721__ ld_ptr(STATE(_method), G5_method);722__ ld_ptr(Address(G5_method, 0, in_bytes(Method::signature_handler_offset())), G3_scratch);723__ tst(G3_scratch);724__ brx(Assembler::notZero, false, Assembler::pt, L);725__ delayed()->nop();726__ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::prepare_native_call), G5_method, false);727__ ld_ptr(STATE(_method), G5_method);728729Address exception_addr(G2_thread, 0, in_bytes(Thread::pending_exception_offset()));730__ ld_ptr(exception_addr, G3_scratch);731__ br_notnull_short(G3_scratch, Assembler::pn, pending_exception_present);732__ ld_ptr(Address(G5_method, 0, in_bytes(Method::signature_handler_offset())), G3_scratch);733__ bind(L);734}735736// Push a new frame so that the args will really be stored in737// Copy a few locals across so the new frame has the variables738// we need but these values will be dead at the jni call and739// therefore not gc volatile like the values in the current740// frame (Lstate in particular)741742// Flush the state pointer to the register save area743// Which is the only register we need for a stack walk.744__ st_ptr(Lstate, SP, (Lstate->sp_offset_in_saved_window() * wordSize) + STACK_BIAS);745746__ mov(Lstate, O1); // Need to pass the state pointer across the frame747748// Calculate current frame size749__ sub(SP, FP, O3); // Calculate negative of current frame size750__ save(SP, O3, SP); // Allocate an identical sized frame751752__ mov(I1, Lstate); // In the "natural" register.753754// Note I7 has leftover trash. Slow signature handler will fill it in755// should we get there. Normal jni call will set reasonable last_Java_pc756// below (and fix I7 so the stack trace doesn't have a meaningless frame757// in it).758759760// call signature handler761__ ld_ptr(STATE(_method), Lmethod);762__ ld_ptr(STATE(_locals), Llocals);763764__ callr(G3_scratch, 0);765__ delayed()->nop();766__ ld_ptr(STATE(_thread), G2_thread); // restore thread (shouldn't be needed)767768{ Label not_static;769770__ ld_ptr(STATE(_method), G5_method);771__ ld(access_flags, O0);772__ btst(JVM_ACC_STATIC, O0);773__ br( Assembler::zero, false, Assembler::pt, not_static);774__ delayed()->775// get native function entry point(O0 is a good temp until the very end)776ld_ptr(Address(G5_method, 0, in_bytes(Method::native_function_offset())), O0);777// for static methods insert the mirror argument778const int mirror_offset = in_bytes(Klass::java_mirror_offset());779780__ ld_ptr(Address(G5_method, 0, in_bytes(Method:: const_offset())), O1);781__ ld_ptr(Address(O1, 0, in_bytes(ConstMethod::constants_offset())), O1);782__ ld_ptr(Address(O1, 0, ConstantPool::pool_holder_offset_in_bytes()), O1);783__ ld_ptr(O1, mirror_offset, O1);784// where the mirror handle body is allocated:785#ifdef ASSERT786if (!PrintSignatureHandlers) // do not dirty the output with this787{ Label L;788__ tst(O1);789__ brx(Assembler::notZero, false, Assembler::pt, L);790__ delayed()->nop();791__ stop("mirror is missing");792__ bind(L);793}794#endif // ASSERT795__ st_ptr(O1, STATE(_oop_temp));796__ add(STATE(_oop_temp), O1); // this is really an LEA not an add797__ bind(not_static);798}799800// At this point, arguments have been copied off of stack into801// their JNI positions, which are O1..O5 and SP[68..].802// Oops are boxed in-place on the stack, with handles copied to arguments.803// The result handler is in Lscratch. O0 will shortly hold the JNIEnv*.804805#ifdef ASSERT806{ Label L;807__ tst(O0);808__ brx(Assembler::notZero, false, Assembler::pt, L);809__ delayed()->nop();810__ stop("native entry point is missing");811__ bind(L);812}813#endif // ASSERT814815//816// setup the java frame anchor817//818// The scavenge function only needs to know that the PC of this frame is819// in the interpreter method entry code, it doesn't need to know the exact820// PC and hence we can use O7 which points to the return address from the821// previous call in the code stream (signature handler function)822//823// The other trick is we set last_Java_sp to FP instead of the usual SP because824// we have pushed the extra frame in order to protect the volatile register(s)825// in that frame when we return from the jni call826//827828829__ set_last_Java_frame(FP, O7);830__ mov(O7, I7); // make dummy interpreter frame look like one above,831// not meaningless information that'll confuse me.832833// flush the windows now. We don't care about the current (protection) frame834// only the outer frames835836__ flush_windows();837838// mark windows as flushed839Address flags(G2_thread,8400,841in_bytes(JavaThread::frame_anchor_offset()) + in_bytes(JavaFrameAnchor::flags_offset()));842__ set(JavaFrameAnchor::flushed, G3_scratch);843__ st(G3_scratch, flags);844845// Transition from _thread_in_Java to _thread_in_native. We are already safepoint ready.846847Address thread_state(G2_thread, 0, in_bytes(JavaThread::thread_state_offset()));848#ifdef ASSERT849{ Label L;850__ ld(thread_state, G3_scratch);851__ cmp(G3_scratch, _thread_in_Java);852__ br(Assembler::equal, false, Assembler::pt, L);853__ delayed()->nop();854__ stop("Wrong thread state in native stub");855__ bind(L);856}857#endif // ASSERT858__ set(_thread_in_native, G3_scratch);859__ st(G3_scratch, thread_state);860861// Call the jni method, using the delay slot to set the JNIEnv* argument.862__ callr(O0, 0);863__ delayed()->864add(G2_thread, in_bytes(JavaThread::jni_environment_offset()), O0);865__ ld_ptr(STATE(_thread), G2_thread); // restore thread866867// must we block?868869// Block, if necessary, before resuming in _thread_in_Java state.870// In order for GC to work, don't clear the last_Java_sp until after blocking.871{ Label no_block;872Address sync_state(G3_scratch, SafepointSynchronize::address_of_state());873874// Switch thread to "native transition" state before reading the synchronization state.875// This additional state is necessary because reading and testing the synchronization876// state is not atomic w.r.t. GC, as this scenario demonstrates:877// Java thread A, in _thread_in_native state, loads _not_synchronized and is preempted.878// VM thread changes sync state to synchronizing and suspends threads for GC.879// Thread A is resumed to finish this native method, but doesn't block here since it880// didn't see any synchronization is progress, and escapes.881__ set(_thread_in_native_trans, G3_scratch);882__ st(G3_scratch, thread_state);883if(os::is_MP()) {884// Write serialization page so VM thread can do a pseudo remote membar.885// We use the current thread pointer to calculate a thread specific886// offset to write to within the page. This minimizes bus traffic887// due to cache line collision.888__ serialize_memory(G2_thread, G1_scratch, G3_scratch);889}890__ load_contents(sync_state, G3_scratch);891__ cmp(G3_scratch, SafepointSynchronize::_not_synchronized);892893894Label L;895Address suspend_state(G2_thread, 0, in_bytes(JavaThread::suspend_flags_offset()));896__ br(Assembler::notEqual, false, Assembler::pn, L);897__ delayed()->898ld(suspend_state, G3_scratch);899__ cmp(G3_scratch, 0);900__ br(Assembler::equal, false, Assembler::pt, no_block);901__ delayed()->nop();902__ bind(L);903904// Block. Save any potential method result value before the operation and905// use a leaf call to leave the last_Java_frame setup undisturbed.906save_native_result();907__ call_VM_leaf(noreg,908CAST_FROM_FN_PTR(address, JavaThread::check_safepoint_and_suspend_for_native_trans),909G2_thread);910__ ld_ptr(STATE(_thread), G2_thread); // restore thread911// Restore any method result value912restore_native_result();913__ bind(no_block);914}915916// Clear the frame anchor now917918__ reset_last_Java_frame();919920// Move the result handler address921__ mov(Lscratch, G3_scratch);922// return possible result to the outer frame923#ifndef __LP64924__ mov(O0, I0);925__ restore(O1, G0, O1);926#else927__ restore(O0, G0, O0);928#endif /* __LP64 */929930// Move result handler to expected register931__ mov(G3_scratch, Lscratch);932933934// thread state is thread_in_native_trans. Any safepoint blocking has935// happened in the trampoline we are ready to switch to thread_in_Java.936937__ set(_thread_in_Java, G3_scratch);938__ st(G3_scratch, thread_state);939940// If we have an oop result store it where it will be safe for any further gc941// until we return now that we've released the handle it might be protected by942943{944Label no_oop, store_result;945946__ set((intptr_t)AbstractInterpreter::result_handler(T_OBJECT), G3_scratch);947__ cmp(G3_scratch, Lscratch);948__ brx(Assembler::notEqual, false, Assembler::pt, no_oop);949__ delayed()->nop();950__ addcc(G0, O0, O0);951__ brx(Assembler::notZero, true, Assembler::pt, store_result); // if result is not NULL:952__ delayed()->ld_ptr(O0, 0, O0); // unbox it953__ mov(G0, O0);954955__ bind(store_result);956// Store it where gc will look for it and result handler expects it.957__ st_ptr(O0, STATE(_oop_temp));958959__ bind(no_oop);960961}962963// reset handle block964__ ld_ptr(G2_thread, in_bytes(JavaThread::active_handles_offset()), G3_scratch);965__ st(G0, G3_scratch, JNIHandleBlock::top_offset_in_bytes());966967968// handle exceptions (exception handling will handle unlocking!)969{ Label L;970Address exception_addr (G2_thread, 0, in_bytes(Thread::pending_exception_offset()));971972__ ld_ptr(exception_addr, Gtemp);973__ tst(Gtemp);974__ brx(Assembler::equal, false, Assembler::pt, L);975__ delayed()->nop();976__ bind(pending_exception_present);977// With c++ interpreter we just leave it pending caller will do the correct thing. However...978// Like x86 we ignore the result of the native call and leave the method locked. This979// seems wrong to leave things locked.980981__ br(Assembler::always, false, Assembler::pt, StubRoutines::forward_exception_entry(), relocInfo::runtime_call_type);982__ delayed()->restore(I5_savedSP, G0, SP); // remove interpreter frame983984__ bind(L);985}986987// jvmdi/jvmpi support (preserves thread register)988__ notify_method_exit(true, ilgl, InterpreterMacroAssembler::NotifyJVMTI);989990if (synchronized) {991// save and restore any potential method result value around the unlocking operation992save_native_result();993994const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;995// Get the initial monitor we allocated996__ sub(Lstate, entry_size, O1); // initial monitor997__ unlock_object(O1);998restore_native_result();999}10001001#if defined(COMPILER2) && !defined(_LP64)10021003// C2 expects long results in G1 we can't tell if we're returning to interpreted1004// or compiled so just be safe.10051006__ sllx(O0, 32, G1); // Shift bits into high G11007__ srl (O1, 0, O1); // Zero extend O11008__ or3 (O1, G1, G1); // OR 64 bits into G110091010#endif /* COMPILER2 && !_LP64 */10111012#ifdef ASSERT1013{1014Label ok;1015__ cmp(I5_savedSP, FP);1016__ brx(Assembler::greaterEqualUnsigned, false, Assembler::pt, ok);1017__ delayed()->nop();1018__ stop("bad I5_savedSP value");1019__ should_not_reach_here();1020__ bind(ok);1021}1022#endif1023// Calls result handler which POPS FRAME1024if (TraceJumps) {1025// Move target to register that is recordable1026__ mov(Lscratch, G3_scratch);1027__ JMP(G3_scratch, 0);1028} else {1029__ jmp(Lscratch, 0);1030}1031__ delayed()->nop();10321033if (inc_counter) {1034// handle invocation counter overflow1035__ bind(invocation_counter_overflow);1036generate_counter_overflow(Lcontinue);1037}103810391040return entry;1041}10421043void CppInterpreterGenerator::generate_compute_interpreter_state(const Register state,1044const Register prev_state,1045bool native) {10461047// On entry1048// G5_method - caller's method1049// Gargs - points to initial parameters (i.e. locals[0])1050// G2_thread - valid? (C1 only??)1051// "prev_state" - contains any previous frame manager state which we must save a link1052//1053// On return1054// "state" is a pointer to the newly allocated state object. We must allocate and initialize1055// a new interpretState object and the method expression stack.10561057assert_different_registers(state, prev_state);1058assert_different_registers(prev_state, G3_scratch);1059const Register Gtmp = G3_scratch;1060const Address constMethod (G5_method, 0, in_bytes(Method::const_offset()));1061const Address access_flags (G5_method, 0, in_bytes(Method::access_flags_offset()));10621063// slop factor is two extra slots on the expression stack so that1064// we always have room to store a result when returning from a call without parameters1065// that returns a result.10661067const int slop_factor = 2*wordSize;10681069const int fixed_size = ((sizeof(BytecodeInterpreter) + slop_factor) >> LogBytesPerWord) + // what is the slop factor?1070Method::extra_stack_entries() + // extra stack for jsr 2921071frame::memory_parameter_word_sp_offset + // register save area + param window1072(native ? frame::interpreter_frame_extra_outgoing_argument_words : 0); // JNI, class10731074// XXX G5_method valid10751076// Now compute new frame size10771078if (native) {1079const Register RconstMethod = Gtmp;1080const Address size_of_parameters(RconstMethod, 0, in_bytes(ConstMethod::size_of_parameters_offset()));1081__ ld_ptr(constMethod, RconstMethod);1082__ lduh( size_of_parameters, Gtmp );1083__ calc_mem_param_words(Gtmp, Gtmp); // space for native call parameters passed on the stack in words1084} else {1085// Full size expression stack1086__ ld_ptr(constMethod, Gtmp);1087__ lduh(Gtmp, in_bytes(ConstMethod::max_stack_offset()), Gtmp);1088}1089__ add(Gtmp, fixed_size, Gtmp); // plus the fixed portion10901091__ neg(Gtmp); // negative space for stack/parameters in words1092__ and3(Gtmp, -WordsPerLong, Gtmp); // make multiple of 2 (SP must be 2-word aligned)1093__ sll(Gtmp, LogBytesPerWord, Gtmp); // negative space for frame in bytes10941095// Need to do stack size check here before we fault on large frames10961097Label stack_ok;10981099const int max_pages = StackShadowPages > (StackRedPages+StackYellowPages) ? StackShadowPages :1100(StackRedPages+StackYellowPages);110111021103__ ld_ptr(G2_thread, in_bytes(Thread::stack_base_offset()), O0);1104__ ld_ptr(G2_thread, in_bytes(Thread::stack_size_offset()), O1);1105// compute stack bottom1106__ sub(O0, O1, O0);11071108// Avoid touching the guard pages1109// Also a fudge for frame size of BytecodeInterpreter::run1110// It varies from 1k->4k depending on build type1111const int fudge = 6 * K;11121113__ set(fudge + (max_pages * os::vm_page_size()), O1);11141115__ add(O0, O1, O0);1116__ sub(O0, Gtmp, O0);1117__ cmp(SP, O0);1118__ brx(Assembler::greaterUnsigned, false, Assembler::pt, stack_ok);1119__ delayed()->nop();11201121// throw exception return address becomes throwing pc11221123__ call_VM(Oexception, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_StackOverflowError));1124__ stop("never reached");11251126__ bind(stack_ok);11271128__ save(SP, Gtmp, SP); // setup new frame and register window11291130// New window I7 call_stub or previous activation1131// O6 - register save area, BytecodeInterpreter just below it, args/locals just above that1132//1133__ sub(FP, sizeof(BytecodeInterpreter), state); // Point to new Interpreter state1134__ add(state, STACK_BIAS, state ); // Account for 64bit bias11351136#define XXX_STATE(field_name) state, in_bytes(byte_offset_of(BytecodeInterpreter, field_name))11371138// Initialize a new Interpreter state1139// orig_sp - caller's original sp1140// G2_thread - thread1141// Gargs - &locals[0] (unbiased?)1142// G5_method - method1143// SP (biased) - accounts for full size java stack, BytecodeInterpreter object, register save area, and register parameter save window114411451146__ set(0xdead0004, O1);114711481149__ st_ptr(Gargs, XXX_STATE(_locals));1150__ st_ptr(G0, XXX_STATE(_oop_temp));11511152__ st_ptr(state, XXX_STATE(_self_link)); // point to self1153__ st_ptr(prev_state->after_save(), XXX_STATE(_prev_link)); // Chain interpreter states1154__ st_ptr(G2_thread, XXX_STATE(_thread)); // Store javathread11551156if (native) {1157__ st_ptr(G0, XXX_STATE(_bcp));1158} else {1159__ ld_ptr(G5_method, in_bytes(Method::const_offset()), O2); // get ConstMethod*1160__ add(O2, in_bytes(ConstMethod::codes_offset()), O2); // get bcp1161__ st_ptr(O2, XXX_STATE(_bcp));1162}11631164__ st_ptr(G0, XXX_STATE(_mdx));1165__ st_ptr(G5_method, XXX_STATE(_method));11661167__ set((int) BytecodeInterpreter::method_entry, O1);1168__ st(O1, XXX_STATE(_msg));11691170__ ld_ptr(constMethod, O3);1171__ ld_ptr(O3, in_bytes(ConstMethod::constants_offset()), O3);1172__ ld_ptr(O3, ConstantPool::cache_offset_in_bytes(), O2);1173__ st_ptr(O2, XXX_STATE(_constants));11741175__ st_ptr(G0, XXX_STATE(_result._to_call._callee));11761177// Monitor base is just start of BytecodeInterpreter object;1178__ mov(state, O2);1179__ st_ptr(O2, XXX_STATE(_monitor_base));11801181// Do we need a monitor for synchonized method?1182{1183__ ld(access_flags, O1);1184Label done;1185Label got_obj;1186__ btst(JVM_ACC_SYNCHRONIZED, O1);1187__ br( Assembler::zero, false, Assembler::pt, done);11881189const int mirror_offset = in_bytes(Klass::java_mirror_offset());1190__ delayed()->btst(JVM_ACC_STATIC, O1);1191__ ld_ptr(XXX_STATE(_locals), O1);1192__ br( Assembler::zero, true, Assembler::pt, got_obj);1193__ delayed()->ld_ptr(O1, 0, O1); // get receiver for not-static case1194__ ld_ptr(constMethod, O1);1195__ ld_ptr( O1, in_bytes(ConstMethod::constants_offset()), O1);1196__ ld_ptr( O1, ConstantPool::pool_holder_offset_in_bytes(), O1);1197// lock the mirror, not the Klass*1198__ ld_ptr( O1, mirror_offset, O1);11991200__ bind(got_obj);12011202#ifdef ASSERT1203__ tst(O1);1204__ breakpoint_trap(Assembler::zero, Assembler::ptr_cc);1205#endif // ASSERT12061207const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;1208__ sub(SP, entry_size, SP); // account for initial monitor1209__ sub(O2, entry_size, O2); // initial monitor1210__ st_ptr(O1, O2, BasicObjectLock::obj_offset_in_bytes()); // and allocate it for interpreter use1211__ bind(done);1212}12131214// Remember initial frame bottom12151216__ st_ptr(SP, XXX_STATE(_frame_bottom));12171218__ st_ptr(O2, XXX_STATE(_stack_base));12191220__ sub(O2, wordSize, O2); // prepush1221__ st_ptr(O2, XXX_STATE(_stack)); // PREPUSH12221223// Full size expression stack1224__ ld_ptr(constMethod, O3);1225__ lduh(O3, in_bytes(ConstMethod::max_stack_offset()), O3);1226__ inc(O3, Method::extra_stack_entries());1227__ sll(O3, LogBytesPerWord, O3);1228__ sub(O2, O3, O3);1229// __ sub(O3, wordSize, O3); // so prepush doesn't look out of bounds1230__ st_ptr(O3, XXX_STATE(_stack_limit));12311232if (!native) {1233//1234// Code to initialize locals1235//1236Register init_value = noreg; // will be G0 if we must clear locals1237// Now zero locals1238if (true /* zerolocals */ || ClearInterpreterLocals) {1239// explicitly initialize locals1240init_value = G0;1241} else {1242#ifdef ASSERT1243// initialize locals to a garbage pattern for better debugging1244init_value = O3;1245__ set( 0x0F0F0F0F, init_value );1246#endif // ASSERT1247}1248if (init_value != noreg) {1249Label clear_loop;1250const Register RconstMethod = O1;1251const Address size_of_parameters(RconstMethod, 0, in_bytes(ConstMethod::size_of_parameters_offset()));1252const Address size_of_locals (RconstMethod, 0, in_bytes(ConstMethod::size_of_locals_offset()));12531254// NOTE: If you change the frame layout, this code will need to1255// be updated!1256__ ld_ptr( constMethod, RconstMethod );1257__ lduh( size_of_locals, O2 );1258__ lduh( size_of_parameters, O1 );1259__ sll( O2, LogBytesPerWord, O2);1260__ sll( O1, LogBytesPerWord, O1 );1261__ ld_ptr(XXX_STATE(_locals), L2_scratch);1262__ sub( L2_scratch, O2, O2 );1263__ sub( L2_scratch, O1, O1 );12641265__ bind( clear_loop );1266__ inc( O2, wordSize );12671268__ cmp( O2, O1 );1269__ br( Assembler::lessEqualUnsigned, true, Assembler::pt, clear_loop );1270__ delayed()->st_ptr( init_value, O2, 0 );1271}1272}1273}1274// Find preallocated monitor and lock method (C++ interpreter)1275//1276void InterpreterGenerator::lock_method(void) {1277// Lock the current method.1278// Destroys registers L2_scratch, L3_scratch, O01279//1280// Find everything relative to Lstate12811282#ifdef ASSERT1283__ ld_ptr(STATE(_method), L2_scratch);1284__ ld(L2_scratch, in_bytes(Method::access_flags_offset()), O0);12851286{ Label ok;1287__ btst(JVM_ACC_SYNCHRONIZED, O0);1288__ br( Assembler::notZero, false, Assembler::pt, ok);1289__ delayed()->nop();1290__ stop("method doesn't need synchronization");1291__ bind(ok);1292}1293#endif // ASSERT12941295// monitor is already allocated at stack base1296// and the lockee is already present1297__ ld_ptr(STATE(_stack_base), L2_scratch);1298__ ld_ptr(L2_scratch, BasicObjectLock::obj_offset_in_bytes(), O0); // get object1299__ lock_object(L2_scratch, O0);13001301}13021303// Generate code for handling resuming a deopted method1304void CppInterpreterGenerator::generate_deopt_handling() {13051306Label return_from_deopt_common;13071308// deopt needs to jump to here to enter the interpreter (return a result)1309deopt_frame_manager_return_atos = __ pc();13101311// O0/O1 live1312__ ba(return_from_deopt_common);1313__ delayed()->set(AbstractInterpreter::BasicType_as_index(T_OBJECT), L3_scratch); // Result stub address array index131413151316// deopt needs to jump to here to enter the interpreter (return a result)1317deopt_frame_manager_return_btos = __ pc();13181319// O0/O1 live1320__ ba(return_from_deopt_common);1321__ delayed()->set(AbstractInterpreter::BasicType_as_index(T_BOOLEAN), L3_scratch); // Result stub address array index13221323// deopt needs to jump to here to enter the interpreter (return a result)1324deopt_frame_manager_return_itos = __ pc();13251326// O0/O1 live1327__ ba(return_from_deopt_common);1328__ delayed()->set(AbstractInterpreter::BasicType_as_index(T_INT), L3_scratch); // Result stub address array index13291330// deopt needs to jump to here to enter the interpreter (return a result)13311332deopt_frame_manager_return_ltos = __ pc();1333#if !defined(_LP64) && defined(COMPILER2)1334// All return values are where we want them, except for Longs. C2 returns1335// longs in G1 in the 32-bit build whereas the interpreter wants them in O0/O1.1336// Since the interpreter will return longs in G1 and O0/O1 in the 32bit1337// build even if we are returning from interpreted we just do a little1338// stupid shuffing.1339// Note: I tried to make c2 return longs in O0/O1 and G1 so we wouldn't have to1340// do this here. Unfortunately if we did a rethrow we'd see an machepilog node1341// first which would move g1 -> O0/O1 and destroy the exception we were throwing.13421343__ srl (G1, 0,O1);1344__ srlx(G1,32,O0);1345#endif /* !_LP64 && COMPILER2 */1346// O0/O1 live1347__ ba(return_from_deopt_common);1348__ delayed()->set(AbstractInterpreter::BasicType_as_index(T_LONG), L3_scratch); // Result stub address array index13491350// deopt needs to jump to here to enter the interpreter (return a result)13511352deopt_frame_manager_return_ftos = __ pc();1353// O0/O1 live1354__ ba(return_from_deopt_common);1355__ delayed()->set(AbstractInterpreter::BasicType_as_index(T_FLOAT), L3_scratch); // Result stub address array index13561357// deopt needs to jump to here to enter the interpreter (return a result)1358deopt_frame_manager_return_dtos = __ pc();13591360// O0/O1 live1361__ ba(return_from_deopt_common);1362__ delayed()->set(AbstractInterpreter::BasicType_as_index(T_DOUBLE), L3_scratch); // Result stub address array index13631364// deopt needs to jump to here to enter the interpreter (return a result)1365deopt_frame_manager_return_vtos = __ pc();13661367// O0/O1 live1368__ set(AbstractInterpreter::BasicType_as_index(T_VOID), L3_scratch);13691370// Deopt return common1371// an index is present that lets us move any possible result being1372// return to the interpreter's stack1373//1374__ bind(return_from_deopt_common);13751376// Result if any is in native abi result (O0..O1/F0..F1). The java expression1377// stack is in the state that the calling convention left it.1378// Copy the result from native abi result and place it on java expression stack.13791380// Current interpreter state is present in Lstate13811382// Get current pre-pushed top of interpreter stack1383// Any result (if any) is in native abi1384// result type index is in L3_scratch13851386__ ld_ptr(STATE(_stack), L1_scratch); // get top of java expr stack13871388__ set((intptr_t)CppInterpreter::_tosca_to_stack, L4_scratch);1389__ sll(L3_scratch, LogBytesPerWord, L3_scratch);1390__ ld_ptr(L4_scratch, L3_scratch, Lscratch); // get typed result converter address1391__ jmpl(Lscratch, G0, O7); // and convert it1392__ delayed()->nop();13931394// L1_scratch points to top of stack (prepushed)1395__ st_ptr(L1_scratch, STATE(_stack));1396}13971398// Generate the code to handle a more_monitors message from the c++ interpreter1399void CppInterpreterGenerator::generate_more_monitors() {14001401Label entry, loop;1402const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;1403// 1. compute new pointers // esp: old expression stack top1404__ delayed()->ld_ptr(STATE(_stack_base), L4_scratch); // current expression stack bottom1405__ sub(L4_scratch, entry_size, L4_scratch);1406__ st_ptr(L4_scratch, STATE(_stack_base));14071408__ sub(SP, entry_size, SP); // Grow stack1409__ st_ptr(SP, STATE(_frame_bottom));14101411__ ld_ptr(STATE(_stack_limit), L2_scratch);1412__ sub(L2_scratch, entry_size, L2_scratch);1413__ st_ptr(L2_scratch, STATE(_stack_limit));14141415__ ld_ptr(STATE(_stack), L1_scratch); // Get current stack top1416__ sub(L1_scratch, entry_size, L1_scratch);1417__ st_ptr(L1_scratch, STATE(_stack));1418__ ba(entry);1419__ delayed()->add(L1_scratch, wordSize, L1_scratch); // first real entry (undo prepush)14201421// 2. move expression stack14221423__ bind(loop);1424__ st_ptr(L3_scratch, Address(L1_scratch, 0));1425__ add(L1_scratch, wordSize, L1_scratch);1426__ bind(entry);1427__ cmp(L1_scratch, L4_scratch);1428__ br(Assembler::notEqual, false, Assembler::pt, loop);1429__ delayed()->ld_ptr(L1_scratch, entry_size, L3_scratch);14301431// now zero the slot so we can find it.1432__ st_ptr(G0, L4_scratch, BasicObjectLock::obj_offset_in_bytes());14331434}14351436// Initial entry to C++ interpreter from the call_stub.1437// This entry point is called the frame manager since it handles the generation1438// of interpreter activation frames via requests directly from the vm (via call_stub)1439// and via requests from the interpreter. The requests from the call_stub happen1440// directly thru the entry point. Requests from the interpreter happen via returning1441// from the interpreter and examining the message the interpreter has returned to1442// the frame manager. The frame manager can take the following requests:14431444// NO_REQUEST - error, should never happen.1445// MORE_MONITORS - need a new monitor. Shuffle the expression stack on down and1446// allocate a new monitor.1447// CALL_METHOD - setup a new activation to call a new method. Very similar to what1448// happens during entry during the entry via the call stub.1449// RETURN_FROM_METHOD - remove an activation. Return to interpreter or call stub.1450//1451// Arguments:1452//1453// ebx: Method*1454// ecx: receiver - unused (retrieved from stack as needed)1455// esi: previous frame manager state (NULL from the call_stub/c1/c2)1456//1457//1458// Stack layout at entry1459//1460// [ return address ] <--- esp1461// [ parameter n ]1462// ...1463// [ parameter 1 ]1464// [ expression stack ]1465//1466//1467// We are free to blow any registers we like because the call_stub which brought us here1468// initially has preserved the callee save registers already.1469//1470//14711472static address interpreter_frame_manager = NULL;14731474#ifdef ASSERT1475#define VALIDATE_STATE(scratch, marker) \1476{ \1477Label skip; \1478__ ld_ptr(STATE(_self_link), scratch); \1479__ cmp(Lstate, scratch); \1480__ brx(Assembler::equal, false, Assembler::pt, skip); \1481__ delayed()->nop(); \1482__ breakpoint_trap(); \1483__ emit_int32(marker); \1484__ bind(skip); \1485}1486#else1487#define VALIDATE_STATE(scratch, marker)1488#endif /* ASSERT */14891490void CppInterpreterGenerator::adjust_callers_stack(Register args) {1491//1492// Adjust caller's stack so that all the locals can be contiguous with1493// the parameters.1494// Worries about stack overflow make this a pain.1495//1496// Destroys args, G3_scratch, G3_scratch1497// In/Out O5_savedSP (sender's original SP)1498//1499// assert_different_registers(state, prev_state);1500const Register Gtmp = G3_scratch;1501const RconstMethod = G3_scratch;1502const Register tmp = O2;1503const Address constMethod(G5_method, 0, in_bytes(Method::const_offset()));1504const Address size_of_parameters(RconstMethod, 0, in_bytes(ConstMethod::size_of_parameters_offset()));1505const Address size_of_locals (RconstMethod, 0, in_bytes(ConstMethod::size_of_locals_offset()));15061507__ ld_ptr(constMethod, RconstMethod);1508__ lduh(size_of_parameters, tmp);1509__ sll(tmp, LogBytesPerWord, Gargs); // parameter size in bytes1510__ add(args, Gargs, Gargs); // points to first local + BytesPerWord1511// NEW1512__ add(Gargs, -wordSize, Gargs); // points to first local[0]1513// determine extra space for non-argument locals & adjust caller's SP1514// Gtmp1: parameter size in words1515__ lduh(size_of_locals, Gtmp);1516__ compute_extra_locals_size_in_bytes(tmp, Gtmp, Gtmp);15171518#if 11519// c2i adapters place the final interpreter argument in the register save area for O0/I01520// the call_stub will place the final interpreter argument at1521// frame::memory_parameter_word_sp_offset. This is mostly not noticable for either asm1522// or c++ interpreter. However with the c++ interpreter when we do a recursive call1523// and try to make it look good in the debugger we will store the argument to1524// RecursiveInterpreterActivation in the register argument save area. Without allocating1525// extra space for the compiler this will overwrite locals in the local array of the1526// interpreter.1527// QQQ still needed with frameless adapters???15281529const int c2i_adjust_words = frame::memory_parameter_word_sp_offset - frame::callee_register_argument_save_area_sp_offset;15301531__ add(Gtmp, c2i_adjust_words*wordSize, Gtmp);1532#endif // 1153315341535__ sub(SP, Gtmp, SP); // just caller's frame for the additional space we need.1536}15371538address InterpreterGenerator::generate_normal_entry(bool synchronized) {15391540// G5_method: Method*1541// G2_thread: thread (unused)1542// Gargs: bottom of args (sender_sp)1543// O5: sender's sp15441545// A single frame manager is plenty as we don't specialize for synchronized. We could and1546// the code is pretty much ready. Would need to change the test below and for good measure1547// modify generate_interpreter_state to only do the (pre) sync stuff stuff for synchronized1548// routines. Not clear this is worth it yet.15491550if (interpreter_frame_manager) {1551return interpreter_frame_manager;1552}15531554__ bind(frame_manager_entry);15551556// the following temporary registers are used during frame creation1557const Register Gtmp1 = G3_scratch;1558// const Register Lmirror = L1; // native mirror (native calls only)15591560const Address constMethod (G5_method, 0, in_bytes(Method::const_offset()));1561const Address access_flags (G5_method, 0, in_bytes(Method::access_flags_offset()));15621563address entry_point = __ pc();1564__ mov(G0, prevState); // no current activation156515661567Label re_dispatch;15681569__ bind(re_dispatch);15701571// Interpreter needs to have locals completely contiguous. In order to do that1572// We must adjust the caller's stack pointer for any locals beyond just the1573// parameters1574adjust_callers_stack(Gargs);15751576// O5_savedSP still contains sender's sp15771578// NEW FRAME15791580generate_compute_interpreter_state(Lstate, prevState, false);15811582// At this point a new interpreter frame and state object are created and initialized1583// Lstate has the pointer to the new activation1584// Any stack banging or limit check should already be done.15851586Label call_interpreter;15871588__ bind(call_interpreter);158915901591#if 11592__ set(0xdead002, Lmirror);1593__ set(0xdead002, L2_scratch);1594__ set(0xdead003, L3_scratch);1595__ set(0xdead004, L4_scratch);1596__ set(0xdead005, Lscratch);1597__ set(0xdead006, Lscratch2);1598__ set(0xdead007, L7_scratch);15991600__ set(0xdeaf002, O2);1601__ set(0xdeaf003, O3);1602__ set(0xdeaf004, O4);1603__ set(0xdeaf005, O5);1604#endif16051606// Call interpreter (stack bang complete) enter here if message is1607// set and we know stack size is valid16081609Label call_interpreter_2;16101611__ bind(call_interpreter_2);16121613#ifdef ASSERT1614{1615Label skip;1616__ ld_ptr(STATE(_frame_bottom), G3_scratch);1617__ cmp(G3_scratch, SP);1618__ brx(Assembler::equal, false, Assembler::pt, skip);1619__ delayed()->nop();1620__ stop("SP not restored to frame bottom");1621__ bind(skip);1622}1623#endif16241625VALIDATE_STATE(G3_scratch, 4);1626__ set_last_Java_frame(SP, noreg);1627__ mov(Lstate, O0); // (arg) pointer to current state16281629__ call(CAST_FROM_FN_PTR(address,1630JvmtiExport::can_post_interpreter_events() ?1631BytecodeInterpreter::runWithChecks1632: BytecodeInterpreter::run),1633relocInfo::runtime_call_type);16341635__ delayed()->nop();16361637__ ld_ptr(STATE(_thread), G2_thread);1638__ reset_last_Java_frame();16391640// examine msg from interpreter to determine next action1641__ ld_ptr(STATE(_thread), G2_thread); // restore G2_thread16421643__ ld(STATE(_msg), L1_scratch); // Get new message16441645Label call_method;1646Label return_from_interpreted_method;1647Label throw_exception;1648Label do_OSR;1649Label bad_msg;1650Label resume_interpreter;16511652__ cmp(L1_scratch, (int)BytecodeInterpreter::call_method);1653__ br(Assembler::equal, false, Assembler::pt, call_method);1654__ delayed()->cmp(L1_scratch, (int)BytecodeInterpreter::return_from_method);1655__ br(Assembler::equal, false, Assembler::pt, return_from_interpreted_method);1656__ delayed()->cmp(L1_scratch, (int)BytecodeInterpreter::throwing_exception);1657__ br(Assembler::equal, false, Assembler::pt, throw_exception);1658__ delayed()->cmp(L1_scratch, (int)BytecodeInterpreter::do_osr);1659__ br(Assembler::equal, false, Assembler::pt, do_OSR);1660__ delayed()->cmp(L1_scratch, (int)BytecodeInterpreter::more_monitors);1661__ br(Assembler::notEqual, false, Assembler::pt, bad_msg);16621663// Allocate more monitor space, shuffle expression stack....16641665generate_more_monitors();16661667// new monitor slot allocated, resume the interpreter.16681669__ set((int)BytecodeInterpreter::got_monitors, L1_scratch);1670VALIDATE_STATE(G3_scratch, 5);1671__ ba(call_interpreter);1672__ delayed()->st(L1_scratch, STATE(_msg));16731674// uncommon trap needs to jump to here to enter the interpreter (re-execute current bytecode)1675unctrap_frame_manager_entry = __ pc();16761677// QQQ what message do we send16781679__ ba(call_interpreter);1680__ delayed()->ld_ptr(STATE(_frame_bottom), SP); // restore to full stack frame16811682//=============================================================================1683// Returning from a compiled method into a deopted method. The bytecode at the1684// bcp has completed. The result of the bytecode is in the native abi (the tosca1685// for the template based interpreter). Any stack space that was used by the1686// bytecode that has completed has been removed (e.g. parameters for an invoke)1687// so all that we have to do is place any pending result on the expression stack1688// and resume execution on the next bytecode.16891690generate_deopt_handling();16911692// ready to resume the interpreter16931694__ set((int)BytecodeInterpreter::deopt_resume, L1_scratch);1695__ ba(call_interpreter);1696__ delayed()->st(L1_scratch, STATE(_msg));16971698// Current frame has caught an exception we need to dispatch to the1699// handler. We can get here because a native interpreter frame caught1700// an exception in which case there is no handler and we must rethrow1701// If it is a vanilla interpreted frame the we simply drop into the1702// interpreter and let it do the lookup.17031704Interpreter::_rethrow_exception_entry = __ pc();17051706Label return_with_exception;1707Label unwind_and_forward;17081709// O0: exception1710// O7: throwing pc17111712// We want exception in the thread no matter what we ultimately decide about frame type.17131714Address exception_addr (G2_thread, 0, in_bytes(Thread::pending_exception_offset()));1715__ verify_thread();1716__ st_ptr(O0, exception_addr);17171718// get the Method*1719__ ld_ptr(STATE(_method), G5_method);17201721// if this current frame vanilla or native?17221723__ ld(access_flags, Gtmp1);1724__ btst(JVM_ACC_NATIVE, Gtmp1);1725__ br(Assembler::zero, false, Assembler::pt, return_with_exception); // vanilla interpreted frame handle directly1726__ delayed()->nop();17271728// We drop thru to unwind a native interpreted frame with a pending exception1729// We jump here for the initial interpreter frame with exception pending1730// We unwind the current acivation and forward it to our caller.17311732__ bind(unwind_and_forward);17331734// Unwind frame and jump to forward exception. unwinding will place throwing pc in O71735// as expected by forward_exception.17361737__ restore(FP, G0, SP); // unwind interpreter state frame1738__ br(Assembler::always, false, Assembler::pt, StubRoutines::forward_exception_entry(), relocInfo::runtime_call_type);1739__ delayed()->mov(I5_savedSP->after_restore(), SP);17401741// Return point from a call which returns a result in the native abi1742// (c1/c2/jni-native). This result must be processed onto the java1743// expression stack.1744//1745// A pending exception may be present in which case there is no result present17461747address return_from_native_method = __ pc();17481749VALIDATE_STATE(G3_scratch, 6);17501751// Result if any is in native abi result (O0..O1/F0..F1). The java expression1752// stack is in the state that the calling convention left it.1753// Copy the result from native abi result and place it on java expression stack.17541755// Current interpreter state is present in Lstate17561757// Exception pending?17581759__ ld_ptr(STATE(_frame_bottom), SP); // restore to full stack frame1760__ ld_ptr(exception_addr, Lscratch); // get any pending exception1761__ tst(Lscratch); // exception pending?1762__ brx(Assembler::notZero, false, Assembler::pt, return_with_exception);1763__ delayed()->nop();17641765// Process the native abi result to java expression stack17661767__ ld_ptr(STATE(_result._to_call._callee), L4_scratch); // called method1768__ ld_ptr(STATE(_stack), L1_scratch); // get top of java expr stack1769// get parameter size1770__ ld_ptr(L4_scratch, in_bytes(Method::const_offset()), L2_scratch);1771__ lduh(L2_scratch, in_bytes(ConstMethod::size_of_parameters_offset()), L2_scratch);1772__ sll(L2_scratch, LogBytesPerWord, L2_scratch ); // parameter size in bytes1773__ add(L1_scratch, L2_scratch, L1_scratch); // stack destination for result1774__ ld(L4_scratch, in_bytes(Method::result_index_offset()), L3_scratch); // called method result type index17751776// tosca is really just native abi1777__ set((intptr_t)CppInterpreter::_tosca_to_stack, L4_scratch);1778__ sll(L3_scratch, LogBytesPerWord, L3_scratch);1779__ ld_ptr(L4_scratch, L3_scratch, Lscratch); // get typed result converter address1780__ jmpl(Lscratch, G0, O7); // and convert it1781__ delayed()->nop();17821783// L1_scratch points to top of stack (prepushed)17841785__ ba(resume_interpreter);1786__ delayed()->mov(L1_scratch, O1);17871788// An exception is being caught on return to a vanilla interpreter frame.1789// Empty the stack and resume interpreter17901791__ bind(return_with_exception);17921793__ ld_ptr(STATE(_frame_bottom), SP); // restore to full stack frame1794__ ld_ptr(STATE(_stack_base), O1); // empty java expression stack1795__ ba(resume_interpreter);1796__ delayed()->sub(O1, wordSize, O1); // account for prepush17971798// Return from interpreted method we return result appropriate to the caller (i.e. "recursive"1799// interpreter call, or native) and unwind this interpreter activation.1800// All monitors should be unlocked.18011802__ bind(return_from_interpreted_method);18031804VALIDATE_STATE(G3_scratch, 7);18051806Label return_to_initial_caller;18071808// Interpreted result is on the top of the completed activation expression stack.1809// We must return it to the top of the callers stack if caller was interpreted1810// otherwise we convert to native abi result and return to call_stub/c1/c21811// The caller's expression stack was truncated by the call however the current activation1812// has enough stuff on the stack that we have usable space there no matter what. The1813// other thing that makes it easy is that the top of the caller's stack is stored in STATE(_locals)1814// for the current activation18151816__ ld_ptr(STATE(_prev_link), L1_scratch);1817__ ld_ptr(STATE(_method), L2_scratch); // get method just executed1818__ ld(L2_scratch, in_bytes(Method::result_index_offset()), L2_scratch);1819__ tst(L1_scratch);1820__ brx(Assembler::zero, false, Assembler::pt, return_to_initial_caller);1821__ delayed()->sll(L2_scratch, LogBytesPerWord, L2_scratch);18221823// Copy result to callers java stack18241825__ set((intptr_t)CppInterpreter::_stack_to_stack, L4_scratch);1826__ ld_ptr(L4_scratch, L2_scratch, Lscratch); // get typed result converter address1827__ ld_ptr(STATE(_stack), O0); // current top (prepushed)1828__ ld_ptr(STATE(_locals), O1); // stack destination18291830// O0 - will be source, O1 - will be destination (preserved)1831__ jmpl(Lscratch, G0, O7); // and convert it1832__ delayed()->add(O0, wordSize, O0); // get source (top of current expr stack)18331834// O1 == &locals[0]18351836// Result is now on caller's stack. Just unwind current activation and resume18371838Label unwind_recursive_activation;183918401841__ bind(unwind_recursive_activation);18421843// O1 == &locals[0] (really callers stacktop) for activation now returning1844// returning to interpreter method from "recursive" interpreter call1845// result converter left O1 pointing to top of the( prepushed) java stack for method we are returning1846// to. Now all we must do is unwind the state from the completed call18471848// Must restore stack1849VALIDATE_STATE(G3_scratch, 8);18501851// Return to interpreter method after a method call (interpreted/native/c1/c2) has completed.1852// Result if any is already on the caller's stack. All we must do now is remove the now dead1853// frame and tell interpreter to resume.185418551856__ mov(O1, I1); // pass back new stack top across activation1857// POP FRAME HERE ==================================1858__ restore(FP, G0, SP); // unwind interpreter state frame1859__ ld_ptr(STATE(_frame_bottom), SP); // restore to full stack frame186018611862// Resume the interpreter. The current frame contains the current interpreter1863// state object.1864//1865// O1 == new java stack pointer18661867__ bind(resume_interpreter);1868VALIDATE_STATE(G3_scratch, 10);18691870// A frame we have already used before so no need to bang stack so use call_interpreter_2 entry18711872__ set((int)BytecodeInterpreter::method_resume, L1_scratch);1873__ st(L1_scratch, STATE(_msg));1874__ ba(call_interpreter_2);1875__ delayed()->st_ptr(O1, STATE(_stack));187618771878// Fast accessor methods share this entry point.1879// This works because frame manager is in the same codelet1880// This can either be an entry via call_stub/c1/c2 or a recursive interpreter call1881// we need to do a little register fixup here once we distinguish the two of them1882if (UseFastAccessorMethods && !synchronized) {1883// Call stub_return address still in O71884__ bind(fast_accessor_slow_entry_path);1885__ set((intptr_t)return_from_native_method - 8, Gtmp1);1886__ cmp(Gtmp1, O7); // returning to interpreter?1887__ brx(Assembler::equal, true, Assembler::pt, re_dispatch); // yep1888__ delayed()->nop();1889__ ba(re_dispatch);1890__ delayed()->mov(G0, prevState); // initial entry18911892}18931894// interpreter returning to native code (call_stub/c1/c2)1895// convert result and unwind initial activation1896// L2_scratch - scaled result type index18971898__ bind(return_to_initial_caller);18991900__ set((intptr_t)CppInterpreter::_stack_to_native_abi, L4_scratch);1901__ ld_ptr(L4_scratch, L2_scratch, Lscratch); // get typed result converter address1902__ ld_ptr(STATE(_stack), O0); // current top (prepushed)1903__ jmpl(Lscratch, G0, O7); // and convert it1904__ delayed()->add(O0, wordSize, O0); // get source (top of current expr stack)19051906Label unwind_initial_activation;1907__ bind(unwind_initial_activation);19081909// RETURN TO CALL_STUB/C1/C2 code (result if any in I0..I1/(F0/..F1)1910// we can return here with an exception that wasn't handled by interpreted code1911// how does c1/c2 see it on return?19121913// compute resulting sp before/after args popped depending upon calling convention1914// __ ld_ptr(STATE(_saved_sp), Gtmp1);1915//1916// POP FRAME HERE ==================================1917__ restore(FP, G0, SP);1918__ retl();1919__ delayed()->mov(I5_savedSP->after_restore(), SP);19201921// OSR request, unwind the current frame and transfer to the OSR entry1922// and enter OSR nmethod19231924__ bind(do_OSR);1925Label remove_initial_frame;1926__ ld_ptr(STATE(_prev_link), L1_scratch);1927__ ld_ptr(STATE(_result._osr._osr_buf), G1_scratch);19281929// We are going to pop this frame. Is there another interpreter frame underneath1930// it or is it callstub/compiled?19311932__ tst(L1_scratch);1933__ brx(Assembler::zero, false, Assembler::pt, remove_initial_frame);1934__ delayed()->ld_ptr(STATE(_result._osr._osr_entry), G3_scratch);19351936// Frame underneath is an interpreter frame simply unwind1937// POP FRAME HERE ==================================1938__ restore(FP, G0, SP); // unwind interpreter state frame1939__ mov(I5_savedSP->after_restore(), SP);19401941// Since we are now calling native need to change our "return address" from the1942// dummy RecursiveInterpreterActivation to a return from native19431944__ set((intptr_t)return_from_native_method - 8, O7);19451946__ jmpl(G3_scratch, G0, G0);1947__ delayed()->mov(G1_scratch, O0);19481949__ bind(remove_initial_frame);19501951// POP FRAME HERE ==================================1952__ restore(FP, G0, SP);1953__ mov(I5_savedSP->after_restore(), SP);1954__ jmpl(G3_scratch, G0, G0);1955__ delayed()->mov(G1_scratch, O0);19561957// Call a new method. All we do is (temporarily) trim the expression stack1958// push a return address to bring us back to here and leap to the new entry.1959// At this point we have a topmost frame that was allocated by the frame manager1960// which contains the current method interpreted state. We trim this frame1961// of excess java expression stack entries and then recurse.19621963__ bind(call_method);19641965// stack points to next free location and not top element on expression stack1966// method expects sp to be pointing to topmost element19671968__ ld_ptr(STATE(_thread), G2_thread);1969__ ld_ptr(STATE(_result._to_call._callee), G5_method);197019711972// SP already takes in to account the 2 extra words we use for slop1973// when we call a "static long no_params()" method. So if1974// we trim back sp by the amount of unused java expression stack1975// there will be automagically the 2 extra words we need.1976// We also have to worry about keeping SP aligned.19771978__ ld_ptr(STATE(_stack), Gargs);1979__ ld_ptr(STATE(_stack_limit), L1_scratch);19801981// compute the unused java stack size1982__ sub(Gargs, L1_scratch, L2_scratch); // compute unused space19831984// Round down the unused space to that stack is always 16-byte aligned1985// by making the unused space a multiple of the size of two longs.19861987__ and3(L2_scratch, -2*BytesPerLong, L2_scratch);19881989// Now trim the stack1990__ add(SP, L2_scratch, SP);199119921993// Now point to the final argument (account for prepush)1994__ add(Gargs, wordSize, Gargs);1995#ifdef ASSERT1996// Make sure we have space for the window1997__ sub(Gargs, SP, L1_scratch);1998__ cmp(L1_scratch, 16*wordSize);1999{2000Label skip;2001__ brx(Assembler::greaterEqual, false, Assembler::pt, skip);2002__ delayed()->nop();2003__ stop("killed stack");2004__ bind(skip);2005}2006#endif // ASSERT20072008// Create a new frame where we can store values that make it look like the interpreter2009// really recursed.20102011// prepare to recurse or call specialized entry20122013// First link the registers we need20142015// make the pc look good in debugger2016__ set(CAST_FROM_FN_PTR(intptr_t, RecursiveInterpreterActivation), O7);2017// argument too2018__ mov(Lstate, I0);20192020// Record our sending SP2021__ mov(SP, O5_savedSP);20222023__ ld_ptr(STATE(_result._to_call._callee_entry_point), L2_scratch);2024__ set((intptr_t) entry_point, L1_scratch);2025__ cmp(L1_scratch, L2_scratch);2026__ brx(Assembler::equal, false, Assembler::pt, re_dispatch);2027__ delayed()->mov(Lstate, prevState); // link activations20282029// method uses specialized entry, push a return so we look like call stub setup2030// this path will handle fact that result is returned in registers and not2031// on the java stack.20322033__ set((intptr_t)return_from_native_method - 8, O7);2034__ jmpl(L2_scratch, G0, G0); // Do specialized entry2035__ delayed()->nop();20362037//2038// Bad Message from interpreter2039//2040__ bind(bad_msg);2041__ stop("Bad message from interpreter");20422043// Interpreted method "returned" with an exception pass it on...2044// Pass result, unwind activation and continue/return to interpreter/call_stub2045// We handle result (if any) differently based on return to interpreter or call_stub20462047__ bind(throw_exception);2048__ ld_ptr(STATE(_prev_link), L1_scratch);2049__ tst(L1_scratch);2050__ brx(Assembler::zero, false, Assembler::pt, unwind_and_forward);2051__ delayed()->nop();20522053__ ld_ptr(STATE(_locals), O1); // get result of popping callee's args2054__ ba(unwind_recursive_activation);2055__ delayed()->nop();20562057interpreter_frame_manager = entry_point;2058return entry_point;2059}20602061InterpreterGenerator::InterpreterGenerator(StubQueue* code)2062: CppInterpreterGenerator(code) {2063generate_all(); // down here so it can be "virtual"2064}206520662067static int size_activation_helper(int callee_extra_locals, int max_stack, int monitor_size) {20682069// Figure out the size of an interpreter frame (in words) given that we have a fully allocated2070// expression stack, the callee will have callee_extra_locals (so we can account for2071// frame extension) and monitor_size for monitors. Basically we need to calculate2072// this exactly like generate_fixed_frame/generate_compute_interpreter_state.2073//2074//2075// The big complicating thing here is that we must ensure that the stack stays properly2076// aligned. This would be even uglier if monitor size wasn't modulo what the stack2077// needs to be aligned for). We are given that the sp (fp) is already aligned by2078// the caller so we must ensure that it is properly aligned for our callee.2079//2080// Ths c++ interpreter always makes sure that we have a enough extra space on the2081// stack at all times to deal with the "stack long no_params()" method issue. This2082// is "slop_factor" here.2083const int slop_factor = 2;20842085const int fixed_size = sizeof(BytecodeInterpreter)/wordSize + // interpreter state object2086frame::memory_parameter_word_sp_offset; // register save area + param window2087return (round_to(max_stack +2088slop_factor +2089fixed_size +2090monitor_size +2091(callee_extra_locals * Interpreter::stackElementWords), WordsPerLong));20922093}20942095int AbstractInterpreter::size_top_interpreter_activation(Method* method) {20962097// See call_stub code2098int call_stub_size = round_to(7 + frame::memory_parameter_word_sp_offset,2099WordsPerLong); // 7 + register save area21002101// Save space for one monitor to get into the interpreted method in case2102// the method is synchronized2103int monitor_size = method->is_synchronized() ?21041*frame::interpreter_frame_monitor_size() : 0;2105return size_activation_helper(method->max_locals(), method->max_stack(),2106monitor_size) + call_stub_size;2107}21082109void BytecodeInterpreter::layout_interpreterState(interpreterState to_fill,2110frame* caller,2111frame* current,2112Method* method,2113intptr_t* locals,2114intptr_t* stack,2115intptr_t* stack_base,2116intptr_t* monitor_base,2117intptr_t* frame_bottom,2118bool is_top_frame2119)2120{2121// What about any vtable?2122//2123to_fill->_thread = JavaThread::current();2124// This gets filled in later but make it something recognizable for now2125to_fill->_bcp = method->code_base();2126to_fill->_locals = locals;2127to_fill->_constants = method->constants()->cache();2128to_fill->_method = method;2129to_fill->_mdx = NULL;2130to_fill->_stack = stack;2131if (is_top_frame && JavaThread::current()->popframe_forcing_deopt_reexecution() ) {2132to_fill->_msg = deopt_resume2;2133} else {2134to_fill->_msg = method_resume;2135}2136to_fill->_result._to_call._bcp_advance = 0;2137to_fill->_result._to_call._callee_entry_point = NULL; // doesn't matter to anyone2138to_fill->_result._to_call._callee = NULL; // doesn't matter to anyone2139to_fill->_prev_link = NULL;21402141// Fill in the registers for the frame21422143// Need to install _sender_sp. Actually not too hard in C++!2144// When the skeletal frames are layed out we fill in a value2145// for _sender_sp. That value is only correct for the oldest2146// skeletal frame constructed (because there is only a single2147// entry for "caller_adjustment". While the skeletal frames2148// exist that is good enough. We correct that calculation2149// here and get all the frames correct.21502151// to_fill->_sender_sp = locals - (method->size_of_parameters() - 1);21522153*current->register_addr(Lstate) = (intptr_t) to_fill;2154// skeletal already places a useful value here and this doesn't account2155// for alignment so don't bother.2156// *current->register_addr(I5_savedSP) = (intptr_t) locals - (method->size_of_parameters() - 1);21572158if (caller->is_interpreted_frame()) {2159interpreterState prev = caller->get_interpreterState();2160to_fill->_prev_link = prev;2161// Make the prev callee look proper2162prev->_result._to_call._callee = method;2163if (*prev->_bcp == Bytecodes::_invokeinterface) {2164prev->_result._to_call._bcp_advance = 5;2165} else {2166prev->_result._to_call._bcp_advance = 3;2167}2168}2169to_fill->_oop_temp = NULL;2170to_fill->_stack_base = stack_base;2171// Need +1 here because stack_base points to the word just above the first expr stack entry2172// and stack_limit is supposed to point to the word just below the last expr stack entry.2173// See generate_compute_interpreter_state.2174to_fill->_stack_limit = stack_base - (method->max_stack() + 1);2175to_fill->_monitor_base = (BasicObjectLock*) monitor_base;21762177// sparc specific2178to_fill->_frame_bottom = frame_bottom;2179to_fill->_self_link = to_fill;2180#ifdef ASSERT2181to_fill->_native_fresult = 123456.789;2182to_fill->_native_lresult = CONST64(0xdeadcafedeafcafe);2183#endif2184}21852186void BytecodeInterpreter::pd_layout_interpreterState(interpreterState istate, address last_Java_pc, intptr_t* last_Java_fp) {2187istate->_last_Java_pc = (intptr_t*) last_Java_pc;2188}21892190static int frame_size_helper(int max_stack,2191int moncount,2192int callee_param_size,2193int callee_locals_size,2194bool is_top_frame,2195int& monitor_size,2196int& full_frame_words) {2197int extra_locals_size = callee_locals_size - callee_param_size;2198monitor_size = (sizeof(BasicObjectLock) * moncount) / wordSize;2199full_frame_words = size_activation_helper(extra_locals_size, max_stack, monitor_size);2200int short_frame_words = size_activation_helper(extra_locals_size, max_stack, monitor_size);2201int frame_words = is_top_frame ? full_frame_words : short_frame_words;22022203return frame_words;2204}22052206int AbstractInterpreter::size_activation(int max_stack,2207int tempcount,2208int extra_args,2209int moncount,2210int callee_param_size,2211int callee_locals_size,2212bool is_top_frame) {2213assert(extra_args == 0, "NEED TO FIX");2214// NOTE: return size is in words not bytes2215// Calculate the amount our frame will be adjust by the callee. For top frame2216// this is zero.22172218// NOTE: ia64 seems to do this wrong (or at least backwards) in that it2219// calculates the extra locals based on itself. Not what the callee does2220// to it. So it ignores last_frame_adjust value. Seems suspicious as far2221// as getting sender_sp correct.22222223int unused_monitor_size = 0;2224int unused_full_frame_words = 0;2225return frame_size_helper(max_stack, moncount, callee_param_size, callee_locals_size, is_top_frame,2226unused_monitor_size, unused_full_frame_words);2227}2228void AbstractInterpreter::layout_activation(Method* method,2229int tempcount, // Number of slots on java expression stack in use2230int popframe_extra_args,2231int moncount, // Number of active monitors2232int caller_actual_parameters,2233int callee_param_size,2234int callee_locals_size,2235frame* caller,2236frame* interpreter_frame,2237bool is_top_frame,2238bool is_bottom_frame) {2239assert(popframe_extra_args == 0, "NEED TO FIX");2240// NOTE this code must exactly mimic what InterpreterGenerator::generate_compute_interpreter_state()2241// does as far as allocating an interpreter frame.2242// Set up the method, locals, and monitors.2243// The frame interpreter_frame is guaranteed to be the right size,2244// as determined by a previous call to the size_activation() method.2245// It is also guaranteed to be walkable even though it is in a skeletal state2246// NOTE: tempcount is the current size of the java expression stack. For top most2247// frames we will allocate a full sized expression stack and not the curback2248// version that non-top frames have.22492250int monitor_size = 0;2251int full_frame_words = 0;2252int frame_words = frame_size_helper(method->max_stack(), moncount, callee_param_size, callee_locals_size,2253is_top_frame, monitor_size, full_frame_words);22542255/*2256We must now fill in all the pieces of the frame. This means both2257the interpreterState and the registers.2258*/22592260// MUCHO HACK22612262intptr_t* frame_bottom = interpreter_frame->sp() - (full_frame_words - frame_words);2263// 'interpreter_frame->sp()' is unbiased while 'frame_bottom' must be a biased value in 64bit mode.2264assert(((intptr_t)frame_bottom & 0xf) == 0, "SP biased in layout_activation");2265frame_bottom = (intptr_t*)((intptr_t)frame_bottom - STACK_BIAS);22662267/* Now fillin the interpreterState object */22682269interpreterState cur_state = (interpreterState) ((intptr_t)interpreter_frame->fp() - sizeof(BytecodeInterpreter));227022712272intptr_t* locals;22732274// Calculate the postion of locals[0]. This is painful because of2275// stack alignment (same as ia64). The problem is that we can2276// not compute the location of locals from fp(). fp() will account2277// for the extra locals but it also accounts for aligning the stack2278// and we can't determine if the locals[0] was misaligned but max_locals2279// was enough to have the2280// calculate postion of locals. fp already accounts for extra locals.2281// +2 for the static long no_params() issue.22822283if (caller->is_interpreted_frame()) {2284// locals must agree with the caller because it will be used to set the2285// caller's tos when we return.2286interpreterState prev = caller->get_interpreterState();2287// stack() is prepushed.2288locals = prev->stack() + method->size_of_parameters();2289} else {2290// Lay out locals block in the caller adjacent to the register window save area.2291//2292// Compiled frames do not allocate a varargs area which is why this if2293// statement is needed.2294//2295intptr_t* fp = interpreter_frame->fp();2296int local_words = method->max_locals() * Interpreter::stackElementWords;22972298if (caller->is_compiled_frame()) {2299locals = fp + frame::register_save_words + local_words - 1;2300} else {2301locals = fp + frame::memory_parameter_word_sp_offset + local_words - 1;2302}23032304}2305// END MUCHO HACK23062307intptr_t* monitor_base = (intptr_t*) cur_state;2308intptr_t* stack_base = monitor_base - monitor_size;2309/* +1 because stack is always prepushed */2310intptr_t* stack = stack_base - (tempcount + 1);231123122313BytecodeInterpreter::layout_interpreterState(cur_state,2314caller,2315interpreter_frame,2316method,2317locals,2318stack,2319stack_base,2320monitor_base,2321frame_bottom,2322is_top_frame);23232324BytecodeInterpreter::pd_layout_interpreterState(cur_state, interpreter_return_address, interpreter_frame->fp());2325}23262327#endif // CC_INTERP232823292330