annotate src/cpu/sparc/vm/templateInterpreter_sparc.cpp @ 2433:2e038ad0c1d0

7009361: JSR 292 Invalid value on stack on solaris-sparc with -Xcomp Reviewed-by: kvn, twisti
author never
date Mon, 02 May 2011 18:53:37 -0700
parents e1162778c1c8
children 3cfb240033d1
rev   line source
duke@0 1 /*
iveresov@2003 2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
duke@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 4 *
duke@0 5 * This code is free software; you can redistribute it and/or modify it
duke@0 6 * under the terms of the GNU General Public License version 2 only, as
duke@0 7 * published by the Free Software Foundation.
duke@0 8 *
duke@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@0 13 * accompanied this code).
duke@0 14 *
duke@0 15 * You should have received a copy of the GNU General Public License version
duke@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 18 *
trims@1472 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1472 20 * or visit www.oracle.com if you need additional information or have any
trims@1472 21 * questions.
duke@0 22 *
duke@0 23 */
duke@0 24
stefank@1879 25 #include "precompiled.hpp"
stefank@1879 26 #include "asm/assembler.hpp"
stefank@1879 27 #include "interpreter/bytecodeHistogram.hpp"
stefank@1879 28 #include "interpreter/interpreter.hpp"
stefank@1879 29 #include "interpreter/interpreterGenerator.hpp"
stefank@1879 30 #include "interpreter/interpreterRuntime.hpp"
stefank@1879 31 #include "interpreter/templateTable.hpp"
stefank@1879 32 #include "oops/arrayOop.hpp"
stefank@1879 33 #include "oops/methodDataOop.hpp"
stefank@1879 34 #include "oops/methodOop.hpp"
stefank@1879 35 #include "oops/oop.inline.hpp"
stefank@1879 36 #include "prims/jvmtiExport.hpp"
stefank@1879 37 #include "prims/jvmtiThreadState.hpp"
stefank@1879 38 #include "runtime/arguments.hpp"
stefank@1879 39 #include "runtime/deoptimization.hpp"
stefank@1879 40 #include "runtime/frame.inline.hpp"
stefank@1879 41 #include "runtime/sharedRuntime.hpp"
stefank@1879 42 #include "runtime/stubRoutines.hpp"
stefank@1879 43 #include "runtime/synchronizer.hpp"
stefank@1879 44 #include "runtime/timer.hpp"
stefank@1879 45 #include "runtime/vframeArray.hpp"
stefank@1879 46 #include "utilities/debug.hpp"
duke@0 47
duke@0 48 #ifndef CC_INTERP
duke@0 49 #ifndef FAST_DISPATCH
duke@0 50 #define FAST_DISPATCH 1
duke@0 51 #endif
duke@0 52 #undef FAST_DISPATCH
duke@0 53
duke@0 54
duke@0 55 // Generation of Interpreter
duke@0 56 //
duke@0 57 // The InterpreterGenerator generates the interpreter into Interpreter::_code.
duke@0 58
duke@0 59
duke@0 60 #define __ _masm->
duke@0 61
duke@0 62
duke@0 63 //----------------------------------------------------------------------------------------------------
duke@0 64
duke@0 65
duke@0 66 void InterpreterGenerator::save_native_result(void) {
duke@0 67 // result potentially in O0/O1: save it across calls
duke@0 68 const Address& l_tmp = InterpreterMacroAssembler::l_tmp;
duke@0 69
duke@0 70 // result potentially in F0/F1: save it across calls
duke@0 71 const Address& d_tmp = InterpreterMacroAssembler::d_tmp;
duke@0 72
duke@0 73 // save and restore any potential method result value around the unlocking operation
duke@0 74 __ stf(FloatRegisterImpl::D, F0, d_tmp);
duke@0 75 #ifdef _LP64
duke@0 76 __ stx(O0, l_tmp);
duke@0 77 #else
duke@0 78 __ std(O0, l_tmp);
duke@0 79 #endif
duke@0 80 }
duke@0 81
duke@0 82 void InterpreterGenerator::restore_native_result(void) {
duke@0 83 const Address& l_tmp = InterpreterMacroAssembler::l_tmp;
duke@0 84 const Address& d_tmp = InterpreterMacroAssembler::d_tmp;
duke@0 85
duke@0 86 // Restore any method result value
duke@0 87 __ ldf(FloatRegisterImpl::D, d_tmp, F0);
duke@0 88 #ifdef _LP64
duke@0 89 __ ldx(l_tmp, O0);
duke@0 90 #else
duke@0 91 __ ldd(l_tmp, O0);
duke@0 92 #endif
duke@0 93 }
duke@0 94
duke@0 95 address TemplateInterpreterGenerator::generate_exception_handler_common(const char* name, const char* message, bool pass_oop) {
duke@0 96 assert(!pass_oop || message == NULL, "either oop or message but not both");
duke@0 97 address entry = __ pc();
duke@0 98 // expression stack must be empty before entering the VM if an exception happened
duke@0 99 __ empty_expression_stack();
duke@0 100 // load exception object
duke@0 101 __ set((intptr_t)name, G3_scratch);
duke@0 102 if (pass_oop) {
duke@0 103 __ call_VM(Oexception, CAST_FROM_FN_PTR(address, InterpreterRuntime::create_klass_exception), G3_scratch, Otos_i);
duke@0 104 } else {
duke@0 105 __ set((intptr_t)message, G4_scratch);
duke@0 106 __ call_VM(Oexception, CAST_FROM_FN_PTR(address, InterpreterRuntime::create_exception), G3_scratch, G4_scratch);
duke@0 107 }
duke@0 108 // throw exception
duke@0 109 assert(Interpreter::throw_exception_entry() != NULL, "generate it first");
twisti@727 110 AddressLiteral thrower(Interpreter::throw_exception_entry());
twisti@727 111 __ jump_to(thrower, G3_scratch);
duke@0 112 __ delayed()->nop();
duke@0 113 return entry;
duke@0 114 }
duke@0 115
duke@0 116 address TemplateInterpreterGenerator::generate_ClassCastException_handler() {
duke@0 117 address entry = __ pc();
duke@0 118 // expression stack must be empty before entering the VM if an exception
duke@0 119 // happened
duke@0 120 __ empty_expression_stack();
duke@0 121 // load exception object
duke@0 122 __ call_VM(Oexception,
duke@0 123 CAST_FROM_FN_PTR(address,
duke@0 124 InterpreterRuntime::throw_ClassCastException),
duke@0 125 Otos_i);
duke@0 126 __ should_not_reach_here();
duke@0 127 return entry;
duke@0 128 }
duke@0 129
duke@0 130
jrose@710 131 // Arguments are: required type in G5_method_type, and
jrose@710 132 // failing object (or NULL) in G3_method_handle.
jrose@710 133 address TemplateInterpreterGenerator::generate_WrongMethodType_handler() {
jrose@710 134 address entry = __ pc();
jrose@710 135 // expression stack must be empty before entering the VM if an exception
jrose@710 136 // happened
jrose@710 137 __ empty_expression_stack();
jrose@710 138 // load exception object
jrose@710 139 __ call_VM(Oexception,
jrose@710 140 CAST_FROM_FN_PTR(address,
jrose@710 141 InterpreterRuntime::throw_WrongMethodTypeException),
jrose@710 142 G5_method_type, // required
jrose@710 143 G3_method_handle); // actual
jrose@710 144 __ should_not_reach_here();
jrose@710 145 return entry;
jrose@710 146 }
jrose@710 147
jrose@710 148
duke@0 149 address TemplateInterpreterGenerator::generate_ArrayIndexOutOfBounds_handler(const char* name) {
duke@0 150 address entry = __ pc();
duke@0 151 // expression stack must be empty before entering the VM if an exception happened
duke@0 152 __ empty_expression_stack();
duke@0 153 // convention: expect aberrant index in register G3_scratch, then shuffle the
duke@0 154 // index to G4_scratch for the VM call
duke@0 155 __ mov(G3_scratch, G4_scratch);
duke@0 156 __ set((intptr_t)name, G3_scratch);
duke@0 157 __ call_VM(Oexception, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_ArrayIndexOutOfBoundsException), G3_scratch, G4_scratch);
duke@0 158 __ should_not_reach_here();
duke@0 159 return entry;
duke@0 160 }
duke@0 161
duke@0 162
duke@0 163 address TemplateInterpreterGenerator::generate_StackOverflowError_handler() {
duke@0 164 address entry = __ pc();
duke@0 165 // expression stack must be empty before entering the VM if an exception happened
duke@0 166 __ empty_expression_stack();
duke@0 167 __ call_VM(Oexception, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_StackOverflowError));
duke@0 168 __ should_not_reach_here();
duke@0 169 return entry;
duke@0 170 }
duke@0 171
duke@0 172
jrose@1059 173 address TemplateInterpreterGenerator::generate_return_entry_for(TosState state, int step) {
twisti@1423 174 TosState incoming_state = state;
twisti@1423 175
twisti@1423 176 Label cont;
duke@0 177 address compiled_entry = __ pc();
duke@0 178
duke@0 179 address entry = __ pc();
duke@0 180 #if !defined(_LP64) && defined(COMPILER2)
duke@0 181 // All return values are where we want them, except for Longs. C2 returns
duke@0 182 // longs in G1 in the 32-bit build whereas the interpreter wants them in O0/O1.
duke@0 183 // Since the interpreter will return longs in G1 and O0/O1 in the 32bit
duke@0 184 // build even if we are returning from interpreted we just do a little
duke@0 185 // stupid shuffing.
duke@0 186 // Note: I tried to make c2 return longs in O0/O1 and G1 so we wouldn't have to
duke@0 187 // do this here. Unfortunately if we did a rethrow we'd see an machepilog node
duke@0 188 // first which would move g1 -> O0/O1 and destroy the exception we were throwing.
duke@0 189
twisti@1423 190 if (incoming_state == ltos) {
twisti@1423 191 __ srl (G1, 0, O1);
twisti@1423 192 __ srlx(G1, 32, O0);
duke@0 193 }
twisti@1423 194 #endif // !_LP64 && COMPILER2
duke@0 195
duke@0 196 __ bind(cont);
duke@0 197
duke@0 198 // The callee returns with the stack possibly adjusted by adapter transition
duke@0 199 // We remove that possible adjustment here.
duke@0 200 // All interpreter local registers are untouched. Any result is passed back
duke@0 201 // in the O0/O1 or float registers. Before continuing, the arguments must be
duke@0 202 // popped from the java expression stack; i.e., Lesp must be adjusted.
duke@0 203
duke@0 204 __ mov(Llast_SP, SP); // Remove any adapter added stack space.
duke@0 205
twisti@1423 206 Label L_got_cache, L_giant_index;
duke@0 207 const Register cache = G3_scratch;
duke@0 208 const Register size = G1_scratch;
twisti@1423 209 if (EnableInvokeDynamic) {
twisti@1423 210 __ ldub(Address(Lbcp, 0), G1_scratch); // Load current bytecode.
twisti@1423 211 __ cmp(G1_scratch, Bytecodes::_invokedynamic);
twisti@1423 212 __ br(Assembler::equal, false, Assembler::pn, L_giant_index);
twisti@1423 213 __ delayed()->nop();
twisti@1423 214 }
duke@0 215 __ get_cache_and_index_at_bcp(cache, G1_scratch, 1);
twisti@1423 216 __ bind(L_got_cache);
twisti@727 217 __ ld_ptr(cache, constantPoolCacheOopDesc::base_offset() +
twisti@727 218 ConstantPoolCacheEntry::flags_offset(), size);
duke@0 219 __ and3(size, 0xFF, size); // argument size in words
twisti@1426 220 __ sll(size, Interpreter::logStackElementSize, size); // each argument size in bytes
duke@0 221 __ add(Lesp, size, Lesp); // pop arguments
duke@0 222 __ dispatch_next(state, step);
duke@0 223
twisti@1423 224 // out of the main line of code...
twisti@1423 225 if (EnableInvokeDynamic) {
twisti@1423 226 __ bind(L_giant_index);
jrose@1485 227 __ get_cache_and_index_at_bcp(cache, G1_scratch, 1, sizeof(u4));
twisti@1423 228 __ ba(false, L_got_cache);
twisti@1423 229 __ delayed()->nop();
twisti@1423 230 }
twisti@1423 231
duke@0 232 return entry;
duke@0 233 }
duke@0 234
duke@0 235
duke@0 236 address TemplateInterpreterGenerator::generate_deopt_entry_for(TosState state, int step) {
duke@0 237 address entry = __ pc();
duke@0 238 __ get_constant_pool_cache(LcpoolCache); // load LcpoolCache
duke@0 239 { Label L;
twisti@727 240 Address exception_addr(G2_thread, Thread::pending_exception_offset());
twisti@727 241 __ ld_ptr(exception_addr, Gtemp); // Load pending exception.
duke@0 242 __ tst(Gtemp);
duke@0 243 __ brx(Assembler::equal, false, Assembler::pt, L);
duke@0 244 __ delayed()->nop();
duke@0 245 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_pending_exception));
duke@0 246 __ should_not_reach_here();
duke@0 247 __ bind(L);
duke@0 248 }
duke@0 249 __ dispatch_next(state, step);
duke@0 250 return entry;
duke@0 251 }
duke@0 252
duke@0 253 // A result handler converts/unboxes a native call result into
duke@0 254 // a java interpreter/compiler result. The current frame is an
duke@0 255 // interpreter frame. The activation frame unwind code must be
duke@0 256 // consistent with that of TemplateTable::_return(...). In the
duke@0 257 // case of native methods, the caller's SP was not modified.
duke@0 258 address TemplateInterpreterGenerator::generate_result_handler_for(BasicType type) {
duke@0 259 address entry = __ pc();
duke@0 260 Register Itos_i = Otos_i ->after_save();
duke@0 261 Register Itos_l = Otos_l ->after_save();
duke@0 262 Register Itos_l1 = Otos_l1->after_save();
duke@0 263 Register Itos_l2 = Otos_l2->after_save();
duke@0 264 switch (type) {
duke@0 265 case T_BOOLEAN: __ subcc(G0, O0, G0); __ addc(G0, 0, Itos_i); break; // !0 => true; 0 => false
duke@0 266 case T_CHAR : __ sll(O0, 16, O0); __ srl(O0, 16, Itos_i); break; // cannot use and3, 0xFFFF too big as immediate value!
duke@0 267 case T_BYTE : __ sll(O0, 24, O0); __ sra(O0, 24, Itos_i); break;
duke@0 268 case T_SHORT : __ sll(O0, 16, O0); __ sra(O0, 16, Itos_i); break;
duke@0 269 case T_LONG :
duke@0 270 #ifndef _LP64
duke@0 271 __ mov(O1, Itos_l2); // move other half of long
duke@0 272 #endif // ifdef or no ifdef, fall through to the T_INT case
duke@0 273 case T_INT : __ mov(O0, Itos_i); break;
duke@0 274 case T_VOID : /* nothing to do */ break;
duke@0 275 case T_FLOAT : assert(F0 == Ftos_f, "fix this code" ); break;
duke@0 276 case T_DOUBLE : assert(F0 == Ftos_d, "fix this code" ); break;
duke@0 277 case T_OBJECT :
duke@0 278 __ ld_ptr(FP, (frame::interpreter_frame_oop_temp_offset*wordSize) + STACK_BIAS, Itos_i);
duke@0 279 __ verify_oop(Itos_i);
duke@0 280 break;
duke@0 281 default : ShouldNotReachHere();
duke@0 282 }
duke@0 283 __ ret(); // return from interpreter activation
duke@0 284 __ delayed()->restore(I5_savedSP, G0, SP); // remove interpreter frame
duke@0 285 NOT_PRODUCT(__ emit_long(0);) // marker for disassembly
duke@0 286 return entry;
duke@0 287 }
duke@0 288
duke@0 289 address TemplateInterpreterGenerator::generate_safept_entry_for(TosState state, address runtime_entry) {
duke@0 290 address entry = __ pc();
duke@0 291 __ push(state);
duke@0 292 __ call_VM(noreg, runtime_entry);
duke@0 293 __ dispatch_via(vtos, Interpreter::normal_table(vtos));
duke@0 294 return entry;
duke@0 295 }
duke@0 296
duke@0 297
duke@0 298 address TemplateInterpreterGenerator::generate_continuation_for(TosState state) {
duke@0 299 address entry = __ pc();
duke@0 300 __ dispatch_next(state);
duke@0 301 return entry;
duke@0 302 }
duke@0 303
duke@0 304 //
duke@0 305 // Helpers for commoning out cases in the various type of method entries.
duke@0 306 //
duke@0 307
duke@0 308 // increment invocation count & check for overflow
duke@0 309 //
duke@0 310 // Note: checking for negative value instead of overflow
duke@0 311 // so we have a 'sticky' overflow test
duke@0 312 //
duke@0 313 // Lmethod: method
duke@0 314 // ??: invocation counter
duke@0 315 //
duke@0 316 void InterpreterGenerator::generate_counter_incr(Label* overflow, Label* profile_method, Label* profile_method_continue) {
iveresov@1703 317 // Note: In tiered we increment either counters in methodOop or in MDO depending if we're profiling or not.
iveresov@1703 318 if (TieredCompilation) {
iveresov@1703 319 const int increment = InvocationCounter::count_increment;
iveresov@1703 320 const int mask = ((1 << Tier0InvokeNotifyFreqLog) - 1) << InvocationCounter::count_shift;
iveresov@1703 321 Label no_mdo, done;
iveresov@1703 322 if (ProfileInterpreter) {
iveresov@1703 323 // If no method data exists, go to profile_continue.
iveresov@1703 324 __ ld_ptr(Lmethod, methodOopDesc::method_data_offset(), G4_scratch);
iveresov@1703 325 __ br_null(G4_scratch, false, Assembler::pn, no_mdo);
iveresov@1703 326 __ delayed()->nop();
iveresov@1703 327 // Increment counter
iveresov@1703 328 Address mdo_invocation_counter(G4_scratch,
iveresov@1703 329 in_bytes(methodDataOopDesc::invocation_counter_offset()) +
iveresov@1703 330 in_bytes(InvocationCounter::counter_offset()));
iveresov@1703 331 __ increment_mask_and_jump(mdo_invocation_counter, increment, mask,
iveresov@1703 332 G3_scratch, Lscratch,
iveresov@1703 333 Assembler::zero, overflow);
iveresov@1703 334 __ ba(false, done);
iveresov@1703 335 __ delayed()->nop();
iveresov@1703 336 }
iveresov@1703 337
iveresov@1703 338 // Increment counter in methodOop
iveresov@1703 339 __ bind(no_mdo);
iveresov@1703 340 Address invocation_counter(Lmethod,
iveresov@1703 341 in_bytes(methodOopDesc::invocation_counter_offset()) +
iveresov@1703 342 in_bytes(InvocationCounter::counter_offset()));
iveresov@1703 343 __ increment_mask_and_jump(invocation_counter, increment, mask,
iveresov@1703 344 G3_scratch, Lscratch,
iveresov@1703 345 Assembler::zero, overflow);
iveresov@1703 346 __ bind(done);
iveresov@1703 347 } else {
iveresov@1703 348 // Update standard invocation counters
iveresov@1703 349 __ increment_invocation_counter(O0, G3_scratch);
iveresov@1703 350 if (ProfileInterpreter) { // %%% Merge this into methodDataOop
iveresov@1703 351 Address interpreter_invocation_counter(Lmethod,in_bytes(methodOopDesc::interpreter_invocation_counter_offset()));
iveresov@1703 352 __ ld(interpreter_invocation_counter, G3_scratch);
iveresov@1703 353 __ inc(G3_scratch);
iveresov@1703 354 __ st(G3_scratch, interpreter_invocation_counter);
iveresov@1703 355 }
iveresov@1703 356
iveresov@1703 357 if (ProfileInterpreter && profile_method != NULL) {
iveresov@1703 358 // Test to see if we should create a method data oop
iveresov@1703 359 AddressLiteral profile_limit((address)&InvocationCounter::InterpreterProfileLimit);
iveresov@1703 360 __ load_contents(profile_limit, G3_scratch);
iveresov@1703 361 __ cmp(O0, G3_scratch);
iveresov@1703 362 __ br(Assembler::lessUnsigned, false, Assembler::pn, *profile_method_continue);
iveresov@1703 363 __ delayed()->nop();
iveresov@1703 364
iveresov@1703 365 // if no method data exists, go to profile_method
iveresov@1703 366 __ test_method_data_pointer(*profile_method);
iveresov@1703 367 }
iveresov@1703 368
iveresov@1703 369 AddressLiteral invocation_limit((address)&InvocationCounter::InterpreterInvocationLimit);
iveresov@1703 370 __ load_contents(invocation_limit, G3_scratch);
iveresov@1703 371 __ cmp(O0, G3_scratch);
iveresov@1703 372 __ br(Assembler::greaterEqualUnsigned, false, Assembler::pn, *overflow);
iveresov@1703 373 __ delayed()->nop();
duke@0 374 }
duke@0 375
duke@0 376 }
duke@0 377
duke@0 378 // Allocate monitor and lock method (asm interpreter)
duke@0 379 // ebx - methodOop
duke@0 380 //
duke@0 381 void InterpreterGenerator::lock_method(void) {
twisti@727 382 __ ld(Lmethod, in_bytes(methodOopDesc::access_flags_offset()), O0); // Load access flags.
duke@0 383
duke@0 384 #ifdef ASSERT
duke@0 385 { Label ok;
duke@0 386 __ btst(JVM_ACC_SYNCHRONIZED, O0);
duke@0 387 __ br( Assembler::notZero, false, Assembler::pt, ok);
duke@0 388 __ delayed()->nop();
duke@0 389 __ stop("method doesn't need synchronization");
duke@0 390 __ bind(ok);
duke@0 391 }
duke@0 392 #endif // ASSERT
duke@0 393
duke@0 394 // get synchronization object to O0
duke@0 395 { Label done;
duke@0 396 const int mirror_offset = klassOopDesc::klass_part_offset_in_bytes() + Klass::java_mirror_offset_in_bytes();
duke@0 397 __ btst(JVM_ACC_STATIC, O0);
duke@0 398 __ br( Assembler::zero, true, Assembler::pt, done);
duke@0 399 __ delayed()->ld_ptr(Llocals, Interpreter::local_offset_in_bytes(0), O0); // get receiver for not-static case
duke@0 400
duke@0 401 __ ld_ptr( Lmethod, in_bytes(methodOopDesc::constants_offset()), O0);
duke@0 402 __ ld_ptr( O0, constantPoolOopDesc::pool_holder_offset_in_bytes(), O0);
duke@0 403
duke@0 404 // lock the mirror, not the klassOop
duke@0 405 __ ld_ptr( O0, mirror_offset, O0);
duke@0 406
duke@0 407 #ifdef ASSERT
duke@0 408 __ tst(O0);
duke@0 409 __ breakpoint_trap(Assembler::zero);
duke@0 410 #endif // ASSERT
duke@0 411
duke@0 412 __ bind(done);
duke@0 413 }
duke@0 414
duke@0 415 __ add_monitor_to_stack(true, noreg, noreg); // allocate monitor elem
duke@0 416 __ st_ptr( O0, Lmonitors, BasicObjectLock::obj_offset_in_bytes()); // store object
duke@0 417 // __ untested("lock_object from method entry");
duke@0 418 __ lock_object(Lmonitors, O0);
duke@0 419 }
duke@0 420
duke@0 421
duke@0 422 void TemplateInterpreterGenerator::generate_stack_overflow_check(Register Rframe_size,
duke@0 423 Register Rscratch,
duke@0 424 Register Rscratch2) {
duke@0 425 const int page_size = os::vm_page_size();
twisti@727 426 Address saved_exception_pc(G2_thread, JavaThread::saved_exception_pc_offset());
duke@0 427 Label after_frame_check;
duke@0 428
duke@0 429 assert_different_registers(Rframe_size, Rscratch, Rscratch2);
duke@0 430
duke@0 431 __ set( page_size, Rscratch );
duke@0 432 __ cmp( Rframe_size, Rscratch );
duke@0 433
duke@0 434 __ br( Assembler::lessEqual, false, Assembler::pt, after_frame_check );
duke@0 435 __ delayed()->nop();
duke@0 436
duke@0 437 // get the stack base, and in debug, verify it is non-zero
twisti@727 438 __ ld_ptr( G2_thread, Thread::stack_base_offset(), Rscratch );
duke@0 439 #ifdef ASSERT
duke@0 440 Label base_not_zero;
duke@0 441 __ cmp( Rscratch, G0 );
duke@0 442 __ brx( Assembler::notEqual, false, Assembler::pn, base_not_zero );
duke@0 443 __ delayed()->nop();
duke@0 444 __ stop("stack base is zero in generate_stack_overflow_check");
duke@0 445 __ bind(base_not_zero);
duke@0 446 #endif
duke@0 447
duke@0 448 // get the stack size, and in debug, verify it is non-zero
duke@0 449 assert( sizeof(size_t) == sizeof(intptr_t), "wrong load size" );
twisti@727 450 __ ld_ptr( G2_thread, Thread::stack_size_offset(), Rscratch2 );
duke@0 451 #ifdef ASSERT
duke@0 452 Label size_not_zero;
duke@0 453 __ cmp( Rscratch2, G0 );
duke@0 454 __ brx( Assembler::notEqual, false, Assembler::pn, size_not_zero );
duke@0 455 __ delayed()->nop();
duke@0 456 __ stop("stack size is zero in generate_stack_overflow_check");
duke@0 457 __ bind(size_not_zero);
duke@0 458 #endif
duke@0 459
duke@0 460 // compute the beginning of the protected zone minus the requested frame size
duke@0 461 __ sub( Rscratch, Rscratch2, Rscratch );
duke@0 462 __ set( (StackRedPages+StackYellowPages) * page_size, Rscratch2 );
duke@0 463 __ add( Rscratch, Rscratch2, Rscratch );
duke@0 464
duke@0 465 // Add in the size of the frame (which is the same as subtracting it from the
duke@0 466 // SP, which would take another register
duke@0 467 __ add( Rscratch, Rframe_size, Rscratch );
duke@0 468
duke@0 469 // the frame is greater than one page in size, so check against
duke@0 470 // the bottom of the stack
duke@0 471 __ cmp( SP, Rscratch );
duke@0 472 __ brx( Assembler::greater, false, Assembler::pt, after_frame_check );
duke@0 473 __ delayed()->nop();
duke@0 474
duke@0 475 // Save the return address as the exception pc
duke@0 476 __ st_ptr(O7, saved_exception_pc);
duke@0 477
duke@0 478 // the stack will overflow, throw an exception
duke@0 479 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_StackOverflowError));
duke@0 480
duke@0 481 // if you get to here, then there is enough stack space
duke@0 482 __ bind( after_frame_check );
duke@0 483 }
duke@0 484
duke@0 485
duke@0 486 //
duke@0 487 // Generate a fixed interpreter frame. This is identical setup for interpreted
duke@0 488 // methods and for native methods hence the shared code.
duke@0 489
duke@0 490 void TemplateInterpreterGenerator::generate_fixed_frame(bool native_call) {
duke@0 491 //
duke@0 492 //
duke@0 493 // The entry code sets up a new interpreter frame in 4 steps:
duke@0 494 //
duke@0 495 // 1) Increase caller's SP by for the extra local space needed:
duke@0 496 // (check for overflow)
duke@0 497 // Efficient implementation of xload/xstore bytecodes requires
duke@0 498 // that arguments and non-argument locals are in a contigously
duke@0 499 // addressable memory block => non-argument locals must be
duke@0 500 // allocated in the caller's frame.
duke@0 501 //
duke@0 502 // 2) Create a new stack frame and register window:
duke@0 503 // The new stack frame must provide space for the standard
duke@0 504 // register save area, the maximum java expression stack size,
duke@0 505 // the monitor slots (0 slots initially), and some frame local
duke@0 506 // scratch locations.
duke@0 507 //
duke@0 508 // 3) The following interpreter activation registers must be setup:
duke@0 509 // Lesp : expression stack pointer
duke@0 510 // Lbcp : bytecode pointer
duke@0 511 // Lmethod : method
duke@0 512 // Llocals : locals pointer
duke@0 513 // Lmonitors : monitor pointer
duke@0 514 // LcpoolCache: constant pool cache
duke@0 515 //
duke@0 516 // 4) Initialize the non-argument locals if necessary:
duke@0 517 // Non-argument locals may need to be initialized to NULL
duke@0 518 // for GC to work. If the oop-map information is accurate
duke@0 519 // (in the absence of the JSR problem), no initialization
duke@0 520 // is necessary.
duke@0 521 //
duke@0 522 // (gri - 2/25/2000)
duke@0 523
duke@0 524
twisti@727 525 const Address size_of_parameters(G5_method, methodOopDesc::size_of_parameters_offset());
twisti@727 526 const Address size_of_locals (G5_method, methodOopDesc::size_of_locals_offset());
twisti@727 527 const Address max_stack (G5_method, methodOopDesc::max_stack_offset());
duke@0 528 int rounded_vm_local_words = round_to( frame::interpreter_frame_vm_local_words, WordsPerLong );
duke@0 529
duke@0 530 const int extra_space =
duke@0 531 rounded_vm_local_words + // frame local scratch space
jrose@710 532 //6815692//methodOopDesc::extra_stack_words() + // extra push slots for MH adapters
duke@0 533 frame::memory_parameter_word_sp_offset + // register save area
duke@0 534 (native_call ? frame::interpreter_frame_extra_outgoing_argument_words : 0);
duke@0 535
duke@0 536 const Register Glocals_size = G3;
duke@0 537 const Register Otmp1 = O3;
duke@0 538 const Register Otmp2 = O4;
duke@0 539 // Lscratch can't be used as a temporary because the call_stub uses
duke@0 540 // it to assert that the stack frame was setup correctly.
duke@0 541
duke@0 542 __ lduh( size_of_parameters, Glocals_size);
duke@0 543
duke@0 544 // Gargs points to first local + BytesPerWord
duke@0 545 // Set the saved SP after the register window save
duke@0 546 //
duke@0 547 assert_different_registers(Gargs, Glocals_size, Gframe_size, O5_savedSP);
twisti@1426 548 __ sll(Glocals_size, Interpreter::logStackElementSize, Otmp1);
duke@0 549 __ add(Gargs, Otmp1, Gargs);
duke@0 550
duke@0 551 if (native_call) {
duke@0 552 __ calc_mem_param_words( Glocals_size, Gframe_size );
duke@0 553 __ add( Gframe_size, extra_space, Gframe_size);
duke@0 554 __ round_to( Gframe_size, WordsPerLong );
duke@0 555 __ sll( Gframe_size, LogBytesPerWord, Gframe_size );
duke@0 556 } else {
duke@0 557
duke@0 558 //
duke@0 559 // Compute number of locals in method apart from incoming parameters
duke@0 560 //
duke@0 561 __ lduh( size_of_locals, Otmp1 );
duke@0 562 __ sub( Otmp1, Glocals_size, Glocals_size );
duke@0 563 __ round_to( Glocals_size, WordsPerLong );
twisti@1426 564 __ sll( Glocals_size, Interpreter::logStackElementSize, Glocals_size );
duke@0 565
duke@0 566 // see if the frame is greater than one page in size. If so,
duke@0 567 // then we need to verify there is enough stack space remaining
duke@0 568 // Frame_size = (max_stack + extra_space) * BytesPerWord;
duke@0 569 __ lduh( max_stack, Gframe_size );
duke@0 570 __ add( Gframe_size, extra_space, Gframe_size );
duke@0 571 __ round_to( Gframe_size, WordsPerLong );
twisti@1426 572 __ sll( Gframe_size, Interpreter::logStackElementSize, Gframe_size);
duke@0 573
duke@0 574 // Add in java locals size for stack overflow check only
duke@0 575 __ add( Gframe_size, Glocals_size, Gframe_size );
duke@0 576
duke@0 577 const Register Otmp2 = O4;
duke@0 578 assert_different_registers(Otmp1, Otmp2, O5_savedSP);
duke@0 579 generate_stack_overflow_check(Gframe_size, Otmp1, Otmp2);
duke@0 580
duke@0 581 __ sub( Gframe_size, Glocals_size, Gframe_size);
duke@0 582
duke@0 583 //
duke@0 584 // bump SP to accomodate the extra locals
duke@0 585 //
duke@0 586 __ sub( SP, Glocals_size, SP );
duke@0 587 }
duke@0 588
duke@0 589 //
duke@0 590 // now set up a stack frame with the size computed above
duke@0 591 //
duke@0 592 __ neg( Gframe_size );
duke@0 593 __ save( SP, Gframe_size, SP );
duke@0 594
duke@0 595 //
duke@0 596 // now set up all the local cache registers
duke@0 597 //
duke@0 598 // NOTE: At this point, Lbyte_code/Lscratch has been modified. Note
duke@0 599 // that all present references to Lbyte_code initialize the register
duke@0 600 // immediately before use
duke@0 601 if (native_call) {
duke@0 602 __ mov(G0, Lbcp);
duke@0 603 } else {
twisti@727 604 __ ld_ptr(G5_method, methodOopDesc::const_offset(), Lbcp);
twisti@727 605 __ add(Lbcp, in_bytes(constMethodOopDesc::codes_offset()), Lbcp);
duke@0 606 }
duke@0 607 __ mov( G5_method, Lmethod); // set Lmethod
duke@0 608 __ get_constant_pool_cache( LcpoolCache ); // set LcpoolCache
duke@0 609 __ sub(FP, rounded_vm_local_words * BytesPerWord, Lmonitors ); // set Lmonitors
duke@0 610 #ifdef _LP64
duke@0 611 __ add( Lmonitors, STACK_BIAS, Lmonitors ); // Account for 64 bit stack bias
duke@0 612 #endif
duke@0 613 __ sub(Lmonitors, BytesPerWord, Lesp); // set Lesp
duke@0 614
duke@0 615 // setup interpreter activation registers
duke@0 616 __ sub(Gargs, BytesPerWord, Llocals); // set Llocals
duke@0 617
duke@0 618 if (ProfileInterpreter) {
duke@0 619 #ifdef FAST_DISPATCH
duke@0 620 // FAST_DISPATCH and ProfileInterpreter are mutually exclusive since
duke@0 621 // they both use I2.
duke@0 622 assert(0, "FAST_DISPATCH and +ProfileInterpreter are mutually exclusive");
duke@0 623 #endif // FAST_DISPATCH
duke@0 624 __ set_method_data_pointer();
duke@0 625 }
duke@0 626
duke@0 627 }
duke@0 628
duke@0 629 // Empty method, generate a very fast return.
duke@0 630
duke@0 631 address InterpreterGenerator::generate_empty_entry(void) {
duke@0 632
duke@0 633 // A method that does nother but return...
duke@0 634
duke@0 635 address entry = __ pc();
duke@0 636 Label slow_path;
duke@0 637
duke@0 638 __ verify_oop(G5_method);
duke@0 639
duke@0 640 // do nothing for empty methods (do not even increment invocation counter)
duke@0 641 if ( UseFastEmptyMethods) {
duke@0 642 // If we need a safepoint check, generate full interpreter entry.
twisti@727 643 AddressLiteral sync_state(SafepointSynchronize::address_of_state());
twisti@727 644 __ set(sync_state, G3_scratch);
duke@0 645 __ cmp(G3_scratch, SafepointSynchronize::_not_synchronized);
duke@0 646 __ br(Assembler::notEqual, false, Assembler::pn, slow_path);
duke@0 647 __ delayed()->nop();
duke@0 648
duke@0 649 // Code: _return
duke@0 650 __ retl();
duke@0 651 __ delayed()->mov(O5_savedSP, SP);
duke@0 652
duke@0 653 __ bind(slow_path);
duke@0 654 (void) generate_normal_entry(false);
duke@0 655
duke@0 656 return entry;
duke@0 657 }
duke@0 658 return NULL;
duke@0 659 }
duke@0 660
duke@0 661 // Call an accessor method (assuming it is resolved, otherwise drop into
duke@0 662 // vanilla (slow path) entry
duke@0 663
duke@0 664 // Generates code to elide accessor methods
duke@0 665 // Uses G3_scratch and G1_scratch as scratch
duke@0 666 address InterpreterGenerator::generate_accessor_entry(void) {
duke@0 667
duke@0 668 // Code: _aload_0, _(i|a)getfield, _(i|a)return or any rewrites thereof;
duke@0 669 // parameter size = 1
duke@0 670 // Note: We can only use this code if the getfield has been resolved
duke@0 671 // and if we don't have a null-pointer exception => check for
duke@0 672 // these conditions first and use slow path if necessary.
duke@0 673 address entry = __ pc();
duke@0 674 Label slow_path;
duke@0 675
coleenp@113 676
coleenp@113 677 // XXX: for compressed oops pointer loading and decoding doesn't fit in
coleenp@113 678 // delay slot and damages G1
coleenp@113 679 if ( UseFastAccessorMethods && !UseCompressedOops ) {
duke@0 680 // Check if we need to reach a safepoint and generate full interpreter
duke@0 681 // frame if so.
twisti@727 682 AddressLiteral sync_state(SafepointSynchronize::address_of_state());
duke@0 683 __ load_contents(sync_state, G3_scratch);
duke@0 684 __ cmp(G3_scratch, SafepointSynchronize::_not_synchronized);
duke@0 685 __ br(Assembler::notEqual, false, Assembler::pn, slow_path);
duke@0 686 __ delayed()->nop();
duke@0 687
duke@0 688 // Check if local 0 != NULL
duke@0 689 __ ld_ptr(Gargs, G0, Otos_i ); // get local 0
duke@0 690 __ tst(Otos_i); // check if local 0 == NULL and go the slow path
duke@0 691 __ brx(Assembler::zero, false, Assembler::pn, slow_path);
duke@0 692 __ delayed()->nop();
duke@0 693
duke@0 694
duke@0 695 // read first instruction word and extract bytecode @ 1 and index @ 2
duke@0 696 // get first 4 bytes of the bytecodes (big endian!)
twisti@727 697 __ ld_ptr(G5_method, methodOopDesc::const_offset(), G1_scratch);
twisti@727 698 __ ld(G1_scratch, constMethodOopDesc::codes_offset(), G1_scratch);
duke@0 699
duke@0 700 // move index @ 2 far left then to the right most two bytes.
duke@0 701 __ sll(G1_scratch, 2*BitsPerByte, G1_scratch);
duke@0 702 __ srl(G1_scratch, 2*BitsPerByte - exact_log2(in_words(
duke@0 703 ConstantPoolCacheEntry::size()) * BytesPerWord), G1_scratch);
duke@0 704
duke@0 705 // get constant pool cache
twisti@727 706 __ ld_ptr(G5_method, methodOopDesc::constants_offset(), G3_scratch);
duke@0 707 __ ld_ptr(G3_scratch, constantPoolOopDesc::cache_offset_in_bytes(), G3_scratch);
duke@0 708
duke@0 709 // get specific constant pool cache entry
duke@0 710 __ add(G3_scratch, G1_scratch, G3_scratch);
duke@0 711
duke@0 712 // Check the constant Pool cache entry to see if it has been resolved.
duke@0 713 // If not, need the slow path.
duke@0 714 ByteSize cp_base_offset = constantPoolCacheOopDesc::base_offset();
twisti@727 715 __ ld_ptr(G3_scratch, cp_base_offset + ConstantPoolCacheEntry::indices_offset(), G1_scratch);
duke@0 716 __ srl(G1_scratch, 2*BitsPerByte, G1_scratch);
duke@0 717 __ and3(G1_scratch, 0xFF, G1_scratch);
duke@0 718 __ cmp(G1_scratch, Bytecodes::_getfield);
duke@0 719 __ br(Assembler::notEqual, false, Assembler::pn, slow_path);
duke@0 720 __ delayed()->nop();
duke@0 721
duke@0 722 // Get the type and return field offset from the constant pool cache
twisti@727 723 __ ld_ptr(G3_scratch, cp_base_offset + ConstantPoolCacheEntry::flags_offset(), G1_scratch);
twisti@727 724 __ ld_ptr(G3_scratch, cp_base_offset + ConstantPoolCacheEntry::f2_offset(), G3_scratch);
duke@0 725
duke@0 726 Label xreturn_path;
duke@0 727 // Need to differentiate between igetfield, agetfield, bgetfield etc.
duke@0 728 // because they are different sizes.
duke@0 729 // Get the type from the constant pool cache
duke@0 730 __ srl(G1_scratch, ConstantPoolCacheEntry::tosBits, G1_scratch);
duke@0 731 // Make sure we don't need to mask G1_scratch for tosBits after the above shift
duke@0 732 ConstantPoolCacheEntry::verify_tosBits();
duke@0 733 __ cmp(G1_scratch, atos );
duke@0 734 __ br(Assembler::equal, true, Assembler::pt, xreturn_path);
duke@0 735 __ delayed()->ld_ptr(Otos_i, G3_scratch, Otos_i);
duke@0 736 __ cmp(G1_scratch, itos);
duke@0 737 __ br(Assembler::equal, true, Assembler::pt, xreturn_path);
duke@0 738 __ delayed()->ld(Otos_i, G3_scratch, Otos_i);
duke@0 739 __ cmp(G1_scratch, stos);
duke@0 740 __ br(Assembler::equal, true, Assembler::pt, xreturn_path);
duke@0 741 __ delayed()->ldsh(Otos_i, G3_scratch, Otos_i);
duke@0 742 __ cmp(G1_scratch, ctos);
duke@0 743 __ br(Assembler::equal, true, Assembler::pt, xreturn_path);
duke@0 744 __ delayed()->lduh(Otos_i, G3_scratch, Otos_i);
duke@0 745 #ifdef ASSERT
duke@0 746 __ cmp(G1_scratch, btos);
duke@0 747 __ br(Assembler::equal, true, Assembler::pt, xreturn_path);
duke@0 748 __ delayed()->ldsb(Otos_i, G3_scratch, Otos_i);
duke@0 749 __ should_not_reach_here();
duke@0 750 #endif
duke@0 751 __ ldsb(Otos_i, G3_scratch, Otos_i);
duke@0 752 __ bind(xreturn_path);
duke@0 753
duke@0 754 // _ireturn/_areturn
duke@0 755 __ retl(); // return from leaf routine
duke@0 756 __ delayed()->mov(O5_savedSP, SP);
duke@0 757
duke@0 758 // Generate regular method entry
duke@0 759 __ bind(slow_path);
duke@0 760 (void) generate_normal_entry(false);
duke@0 761 return entry;
duke@0 762 }
duke@0 763 return NULL;
duke@0 764 }
duke@0 765
johnc@2346 766 // Method entry for java.lang.ref.Reference.get.
johnc@2346 767 address InterpreterGenerator::generate_Reference_get_entry(void) {
johnc@2346 768 #ifndef SERIALGC
johnc@2346 769 // Code: _aload_0, _getfield, _areturn
johnc@2346 770 // parameter size = 1
johnc@2346 771 //
johnc@2346 772 // The code that gets generated by this routine is split into 2 parts:
johnc@2346 773 // 1. The "intrinsified" code for G1 (or any SATB based GC),
johnc@2346 774 // 2. The slow path - which is an expansion of the regular method entry.
johnc@2346 775 //
johnc@2346 776 // Notes:-
johnc@2346 777 // * In the G1 code we do not check whether we need to block for
johnc@2346 778 // a safepoint. If G1 is enabled then we must execute the specialized
johnc@2346 779 // code for Reference.get (except when the Reference object is null)
johnc@2346 780 // so that we can log the value in the referent field with an SATB
johnc@2346 781 // update buffer.
johnc@2346 782 // If the code for the getfield template is modified so that the
johnc@2346 783 // G1 pre-barrier code is executed when the current method is
johnc@2346 784 // Reference.get() then going through the normal method entry
johnc@2346 785 // will be fine.
johnc@2346 786 // * The G1 code can, however, check the receiver object (the instance
johnc@2346 787 // of java.lang.Reference) and jump to the slow path if null. If the
johnc@2346 788 // Reference object is null then we obviously cannot fetch the referent
johnc@2346 789 // and so we don't need to call the G1 pre-barrier. Thus we can use the
johnc@2346 790 // regular method entry code to generate the NPE.
johnc@2346 791 //
johnc@2346 792 // This code is based on generate_accessor_enty.
johnc@2346 793
johnc@2346 794 address entry = __ pc();
johnc@2346 795
johnc@2346 796 const int referent_offset = java_lang_ref_Reference::referent_offset;
johnc@2346 797 guarantee(referent_offset > 0, "referent offset not initialized");
johnc@2346 798
johnc@2346 799 if (UseG1GC) {
johnc@2346 800 Label slow_path;
johnc@2346 801
johnc@2346 802 // In the G1 code we don't check if we need to reach a safepoint. We
johnc@2346 803 // continue and the thread will safepoint at the next bytecode dispatch.
johnc@2346 804
johnc@2346 805 // Check if local 0 != NULL
johnc@2346 806 // If the receiver is null then it is OK to jump to the slow path.
johnc@2346 807 __ ld_ptr(Gargs, G0, Otos_i ); // get local 0
johnc@2346 808 __ tst(Otos_i); // check if local 0 == NULL and go the slow path
johnc@2346 809 __ brx(Assembler::zero, false, Assembler::pn, slow_path);
johnc@2346 810 __ delayed()->nop();
johnc@2346 811
johnc@2346 812
johnc@2346 813 // Load the value of the referent field.
johnc@2346 814 if (Assembler::is_simm13(referent_offset)) {
johnc@2346 815 __ load_heap_oop(Otos_i, referent_offset, Otos_i);
johnc@2346 816 } else {
johnc@2346 817 __ set(referent_offset, G3_scratch);
johnc@2346 818 __ load_heap_oop(Otos_i, G3_scratch, Otos_i);
johnc@2346 819 }
johnc@2346 820
johnc@2346 821 // Generate the G1 pre-barrier code to log the value of
johnc@2346 822 // the referent field in an SATB buffer. Note with
johnc@2346 823 // these parameters the pre-barrier does not generate
johnc@2346 824 // the load of the previous value
johnc@2346 825
johnc@2346 826 __ g1_write_barrier_pre(noreg /* obj */, noreg /* index */, 0 /* offset */,
johnc@2346 827 Otos_i /* pre_val */,
johnc@2346 828 G3_scratch /* tmp */,
johnc@2346 829 true /* preserve_o_regs */);
johnc@2346 830
johnc@2346 831 // _areturn
johnc@2346 832 __ retl(); // return from leaf routine
johnc@2346 833 __ delayed()->mov(O5_savedSP, SP);
johnc@2346 834
johnc@2346 835 // Generate regular method entry
johnc@2346 836 __ bind(slow_path);
johnc@2346 837 (void) generate_normal_entry(false);
johnc@2346 838 return entry;
johnc@2346 839 }
johnc@2346 840 #endif // SERIALGC
johnc@2346 841
johnc@2346 842 // If G1 is not enabled then attempt to go through the accessor entry point
johnc@2346 843 // Reference.get is an accessor
johnc@2346 844 return generate_accessor_entry();
johnc@2346 845 }
johnc@2346 846
duke@0 847 //
duke@0 848 // Interpreter stub for calling a native method. (asm interpreter)
duke@0 849 // This sets up a somewhat different looking stack for calling the native method
duke@0 850 // than the typical interpreter frame setup.
duke@0 851 //
duke@0 852
duke@0 853 address InterpreterGenerator::generate_native_entry(bool synchronized) {
duke@0 854 address entry = __ pc();
duke@0 855
duke@0 856 // the following temporary registers are used during frame creation
duke@0 857 const Register Gtmp1 = G3_scratch ;
duke@0 858 const Register Gtmp2 = G1_scratch;
duke@0 859 bool inc_counter = UseCompiler || CountCompiledCalls;
duke@0 860
duke@0 861 // make sure registers are different!
duke@0 862 assert_different_registers(G2_thread, G5_method, Gargs, Gtmp1, Gtmp2);
duke@0 863
twisti@727 864 const Address Laccess_flags(Lmethod, methodOopDesc::access_flags_offset());
duke@0 865
duke@0 866 __ verify_oop(G5_method);
duke@0 867
duke@0 868 const Register Glocals_size = G3;
duke@0 869 assert_different_registers(Glocals_size, G4_scratch, Gframe_size);
duke@0 870
duke@0 871 // make sure method is native & not abstract
duke@0 872 // rethink these assertions - they can be simplified and shared (gri 2/25/2000)
duke@0 873 #ifdef ASSERT
twisti@727 874 __ ld(G5_method, methodOopDesc::access_flags_offset(), Gtmp1);
duke@0 875 {
duke@0 876 Label L;
duke@0 877 __ btst(JVM_ACC_NATIVE, Gtmp1);
duke@0 878 __ br(Assembler::notZero, false, Assembler::pt, L);
duke@0 879 __ delayed()->nop();
duke@0 880 __ stop("tried to execute non-native method as native");
duke@0 881 __ bind(L);
duke@0 882 }
duke@0 883 { Label L;
duke@0 884 __ btst(JVM_ACC_ABSTRACT, Gtmp1);
duke@0 885 __ br(Assembler::zero, false, Assembler::pt, L);
duke@0 886 __ delayed()->nop();
duke@0 887 __ stop("tried to execute abstract method as non-abstract");
duke@0 888 __ bind(L);
duke@0 889 }
duke@0 890 #endif // ASSERT
duke@0 891
duke@0 892 // generate the code to allocate the interpreter stack frame
duke@0 893 generate_fixed_frame(true);
duke@0 894
duke@0 895 //
duke@0 896 // No locals to initialize for native method
duke@0 897 //
duke@0 898
duke@0 899 // this slot will be set later, we initialize it to null here just in
duke@0 900 // case we get a GC before the actual value is stored later
twisti@727 901 __ st_ptr(G0, FP, (frame::interpreter_frame_oop_temp_offset * wordSize) + STACK_BIAS);
duke@0 902
twisti@727 903 const Address do_not_unlock_if_synchronized(G2_thread,
twisti@727 904 JavaThread::do_not_unlock_if_synchronized_offset());
duke@0 905 // Since at this point in the method invocation the exception handler
duke@0 906 // would try to exit the monitor of synchronized methods which hasn't
duke@0 907 // been entered yet, we set the thread local variable
duke@0 908 // _do_not_unlock_if_synchronized to true. If any exception was thrown by
duke@0 909 // runtime, exception handling i.e. unlock_if_synchronized_method will
duke@0 910 // check this thread local flag.
duke@0 911 // This flag has two effects, one is to force an unwind in the topmost
duke@0 912 // interpreter frame and not perform an unlock while doing so.
duke@0 913
duke@0 914 __ movbool(true, G3_scratch);
duke@0 915 __ stbool(G3_scratch, do_not_unlock_if_synchronized);
duke@0 916
duke@0 917 // increment invocation counter and check for overflow
duke@0 918 //
duke@0 919 // Note: checking for negative value instead of overflow
duke@0 920 // so we have a 'sticky' overflow test (may be of
duke@0 921 // importance as soon as we have true MT/MP)
duke@0 922 Label invocation_counter_overflow;
duke@0 923 Label Lcontinue;
duke@0 924 if (inc_counter) {
duke@0 925 generate_counter_incr(&invocation_counter_overflow, NULL, NULL);
duke@0 926
duke@0 927 }
duke@0 928 __ bind(Lcontinue);
duke@0 929
duke@0 930 bang_stack_shadow_pages(true);
duke@0 931
duke@0 932 // reset the _do_not_unlock_if_synchronized flag
duke@0 933 __ stbool(G0, do_not_unlock_if_synchronized);
duke@0 934
duke@0 935 // check for synchronized methods
duke@0 936 // Must happen AFTER invocation_counter check and stack overflow check,
duke@0 937 // so method is not locked if overflows.
duke@0 938
duke@0 939 if (synchronized) {
duke@0 940 lock_method();
duke@0 941 } else {
duke@0 942 #ifdef ASSERT
duke@0 943 { Label ok;
duke@0 944 __ ld(Laccess_flags, O0);
duke@0 945 __ btst(JVM_ACC_SYNCHRONIZED, O0);
duke@0 946 __ br( Assembler::zero, false, Assembler::pt, ok);
duke@0 947 __ delayed()->nop();
duke@0 948 __ stop("method needs synchronization");
duke@0 949 __ bind(ok);
duke@0 950 }
duke@0 951 #endif // ASSERT
duke@0 952 }
duke@0 953
duke@0 954
duke@0 955 // start execution
duke@0 956 __ verify_thread();
duke@0 957
duke@0 958 // JVMTI support
duke@0 959 __ notify_method_entry();
duke@0 960
duke@0 961 // native call
duke@0 962
duke@0 963 // (note that O0 is never an oop--at most it is a handle)
duke@0 964 // It is important not to smash any handles created by this call,
duke@0 965 // until any oop handle in O0 is dereferenced.
duke@0 966
duke@0 967 // (note that the space for outgoing params is preallocated)
duke@0 968
duke@0 969 // get signature handler
duke@0 970 { Label L;
twisti@727 971 Address signature_handler(Lmethod, methodOopDesc::signature_handler_offset());
twisti@727 972 __ ld_ptr(signature_handler, G3_scratch);
duke@0 973 __ tst(G3_scratch);
duke@0 974 __ brx(Assembler::notZero, false, Assembler::pt, L);
duke@0 975 __ delayed()->nop();
duke@0 976 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::prepare_native_call), Lmethod);
twisti@727 977 __ ld_ptr(signature_handler, G3_scratch);
duke@0 978 __ bind(L);
duke@0 979 }
duke@0 980
duke@0 981 // Push a new frame so that the args will really be stored in
duke@0 982 // Copy a few locals across so the new frame has the variables
duke@0 983 // we need but these values will be dead at the jni call and
duke@0 984 // therefore not gc volatile like the values in the current
duke@0 985 // frame (Lmethod in particular)
duke@0 986
duke@0 987 // Flush the method pointer to the register save area
duke@0 988 __ st_ptr(Lmethod, SP, (Lmethod->sp_offset_in_saved_window() * wordSize) + STACK_BIAS);
duke@0 989 __ mov(Llocals, O1);
twisti@727 990
duke@0 991 // calculate where the mirror handle body is allocated in the interpreter frame:
twisti@727 992 __ add(FP, (frame::interpreter_frame_oop_temp_offset * wordSize) + STACK_BIAS, O2);
duke@0 993
duke@0 994 // Calculate current frame size
duke@0 995 __ sub(SP, FP, O3); // Calculate negative of current frame size
duke@0 996 __ save(SP, O3, SP); // Allocate an identical sized frame
duke@0 997
duke@0 998 // Note I7 has leftover trash. Slow signature handler will fill it in
duke@0 999 // should we get there. Normal jni call will set reasonable last_Java_pc
duke@0 1000 // below (and fix I7 so the stack trace doesn't have a meaningless frame
duke@0 1001 // in it).
duke@0 1002
duke@0 1003 // Load interpreter frame's Lmethod into same register here
duke@0 1004
duke@0 1005 __ ld_ptr(FP, (Lmethod->sp_offset_in_saved_window() * wordSize) + STACK_BIAS, Lmethod);
duke@0 1006
duke@0 1007 __ mov(I1, Llocals);
duke@0 1008 __ mov(I2, Lscratch2); // save the address of the mirror
duke@0 1009
duke@0 1010
duke@0 1011 // ONLY Lmethod and Llocals are valid here!
duke@0 1012
duke@0 1013 // call signature handler, It will move the arg properly since Llocals in current frame
duke@0 1014 // matches that in outer frame
duke@0 1015
duke@0 1016 __ callr(G3_scratch, 0);
duke@0 1017 __ delayed()->nop();
duke@0 1018
duke@0 1019 // Result handler is in Lscratch
duke@0 1020
duke@0 1021 // Reload interpreter frame's Lmethod since slow signature handler may block
duke@0 1022 __ ld_ptr(FP, (Lmethod->sp_offset_in_saved_window() * wordSize) + STACK_BIAS, Lmethod);
duke@0 1023
duke@0 1024 { Label not_static;
duke@0 1025
duke@0 1026 __ ld(Laccess_flags, O0);
duke@0 1027 __ btst(JVM_ACC_STATIC, O0);
duke@0 1028 __ br( Assembler::zero, false, Assembler::pt, not_static);
twisti@727 1029 // get native function entry point(O0 is a good temp until the very end)
twisti@727 1030 __ delayed()->ld_ptr(Lmethod, in_bytes(methodOopDesc::native_function_offset()), O0);
duke@0 1031 // for static methods insert the mirror argument
duke@0 1032 const int mirror_offset = klassOopDesc::klass_part_offset_in_bytes() + Klass::java_mirror_offset_in_bytes();
duke@0 1033
twisti@727 1034 __ ld_ptr(Lmethod, methodOopDesc:: constants_offset(), O1);
twisti@727 1035 __ ld_ptr(O1, constantPoolOopDesc::pool_holder_offset_in_bytes(), O1);
duke@0 1036 __ ld_ptr(O1, mirror_offset, O1);
duke@0 1037 #ifdef ASSERT
duke@0 1038 if (!PrintSignatureHandlers) // do not dirty the output with this
duke@0 1039 { Label L;
duke@0 1040 __ tst(O1);
duke@0 1041 __ brx(Assembler::notZero, false, Assembler::pt, L);
duke@0 1042 __ delayed()->nop();
duke@0 1043 __ stop("mirror is missing");
duke@0 1044 __ bind(L);
duke@0 1045 }
duke@0 1046 #endif // ASSERT
duke@0 1047 __ st_ptr(O1, Lscratch2, 0);
duke@0 1048 __ mov(Lscratch2, O1);
duke@0 1049 __ bind(not_static);
duke@0 1050 }
duke@0 1051
duke@0 1052 // At this point, arguments have been copied off of stack into
duke@0 1053 // their JNI positions, which are O1..O5 and SP[68..].
duke@0 1054 // Oops are boxed in-place on the stack, with handles copied to arguments.
duke@0 1055 // The result handler is in Lscratch. O0 will shortly hold the JNIEnv*.
duke@0 1056
duke@0 1057 #ifdef ASSERT
duke@0 1058 { Label L;
duke@0 1059 __ tst(O0);
duke@0 1060 __ brx(Assembler::notZero, false, Assembler::pt, L);
duke@0 1061 __ delayed()->nop();
duke@0 1062 __ stop("native entry point is missing");
duke@0 1063 __ bind(L);
duke@0 1064 }
duke@0 1065 #endif // ASSERT
duke@0 1066
duke@0 1067 //
duke@0 1068 // setup the frame anchor
duke@0 1069 //
duke@0 1070 // The scavenge function only needs to know that the PC of this frame is
duke@0 1071 // in the interpreter method entry code, it doesn't need to know the exact
duke@0 1072 // PC and hence we can use O7 which points to the return address from the
duke@0 1073 // previous call in the code stream (signature handler function)
duke@0 1074 //
duke@0 1075 // The other trick is we set last_Java_sp to FP instead of the usual SP because
duke@0 1076 // we have pushed the extra frame in order to protect the volatile register(s)
duke@0 1077 // in that frame when we return from the jni call
duke@0 1078 //
duke@0 1079
duke@0 1080 __ set_last_Java_frame(FP, O7);
duke@0 1081 __ mov(O7, I7); // make dummy interpreter frame look like one above,
duke@0 1082 // not meaningless information that'll confuse me.
duke@0 1083
duke@0 1084 // flush the windows now. We don't care about the current (protection) frame
duke@0 1085 // only the outer frames
duke@0 1086
duke@0 1087 __ flush_windows();
duke@0 1088
duke@0 1089 // mark windows as flushed
twisti@727 1090 Address flags(G2_thread, JavaThread::frame_anchor_offset() + JavaFrameAnchor::flags_offset());
duke@0 1091 __ set(JavaFrameAnchor::flushed, G3_scratch);
duke@0 1092 __ st(G3_scratch, flags);
duke@0 1093
duke@0 1094 // Transition from _thread_in_Java to _thread_in_native. We are already safepoint ready.
duke@0 1095
twisti@727 1096 Address thread_state(G2_thread, JavaThread::thread_state_offset());
duke@0 1097 #ifdef ASSERT
duke@0 1098 { Label L;
duke@0 1099 __ ld(thread_state, G3_scratch);
duke@0 1100 __ cmp(G3_scratch, _thread_in_Java);
duke@0 1101 __ br(Assembler::equal, false, Assembler::pt, L);
duke@0 1102 __ delayed()->nop();
duke@0 1103 __ stop("Wrong thread state in native stub");
duke@0 1104 __ bind(L);
duke@0 1105 }
duke@0 1106 #endif // ASSERT
duke@0 1107 __ set(_thread_in_native, G3_scratch);
duke@0 1108 __ st(G3_scratch, thread_state);
duke@0 1109
duke@0 1110 // Call the jni method, using the delay slot to set the JNIEnv* argument.
duke@0 1111 __ save_thread(L7_thread_cache); // save Gthread
duke@0 1112 __ callr(O0, 0);
duke@0 1113 __ delayed()->
duke@0 1114 add(L7_thread_cache, in_bytes(JavaThread::jni_environment_offset()), O0);
duke@0 1115
duke@0 1116 // Back from jni method Lmethod in this frame is DEAD, DEAD, DEAD
duke@0 1117
duke@0 1118 __ restore_thread(L7_thread_cache); // restore G2_thread
coleenp@113 1119 __ reinit_heapbase();
duke@0 1120
duke@0 1121 // must we block?
duke@0 1122
duke@0 1123 // Block, if necessary, before resuming in _thread_in_Java state.
duke@0 1124 // In order for GC to work, don't clear the last_Java_sp until after blocking.
duke@0 1125 { Label no_block;
twisti@727 1126 AddressLiteral sync_state(SafepointSynchronize::address_of_state());
duke@0 1127
duke@0 1128 // Switch thread to "native transition" state before reading the synchronization state.
duke@0 1129 // This additional state is necessary because reading and testing the synchronization
duke@0 1130 // state is not atomic w.r.t. GC, as this scenario demonstrates:
duke@0 1131 // Java thread A, in _thread_in_native state, loads _not_synchronized and is preempted.
duke@0 1132 // VM thread changes sync state to synchronizing and suspends threads for GC.
duke@0 1133 // Thread A is resumed to finish this native method, but doesn't block here since it
duke@0 1134 // didn't see any synchronization is progress, and escapes.
duke@0 1135 __ set(_thread_in_native_trans, G3_scratch);
duke@0 1136 __ st(G3_scratch, thread_state);
duke@0 1137 if(os::is_MP()) {
duke@0 1138 if (UseMembar) {
duke@0 1139 // Force this write out before the read below
duke@0 1140 __ membar(Assembler::StoreLoad);
duke@0 1141 } else {
duke@0 1142 // Write serialization page so VM thread can do a pseudo remote membar.
duke@0 1143 // We use the current thread pointer to calculate a thread specific
duke@0 1144 // offset to write to within the page. This minimizes bus traffic
duke@0 1145 // due to cache line collision.
duke@0 1146 __ serialize_memory(G2_thread, G1_scratch, G3_scratch);
duke@0 1147 }
duke@0 1148 }
duke@0 1149 __ load_contents(sync_state, G3_scratch);
duke@0 1150 __ cmp(G3_scratch, SafepointSynchronize::_not_synchronized);
duke@0 1151
duke@0 1152 Label L;
duke@0 1153 __ br(Assembler::notEqual, false, Assembler::pn, L);
twisti@727 1154 __ delayed()->ld(G2_thread, JavaThread::suspend_flags_offset(), G3_scratch);
duke@0 1155 __ cmp(G3_scratch, 0);
duke@0 1156 __ br(Assembler::equal, false, Assembler::pt, no_block);
duke@0 1157 __ delayed()->nop();
duke@0 1158 __ bind(L);
duke@0 1159
duke@0 1160 // Block. Save any potential method result value before the operation and
duke@0 1161 // use a leaf call to leave the last_Java_frame setup undisturbed.
duke@0 1162 save_native_result();
duke@0 1163 __ call_VM_leaf(L7_thread_cache,
duke@0 1164 CAST_FROM_FN_PTR(address, JavaThread::check_special_condition_for_native_trans),
duke@0 1165 G2_thread);
duke@0 1166
duke@0 1167 // Restore any method result value
duke@0 1168 restore_native_result();
duke@0 1169 __ bind(no_block);
duke@0 1170 }
duke@0 1171
duke@0 1172 // Clear the frame anchor now
duke@0 1173
duke@0 1174 __ reset_last_Java_frame();
duke@0 1175
duke@0 1176 // Move the result handler address
duke@0 1177 __ mov(Lscratch, G3_scratch);
duke@0 1178 // return possible result to the outer frame
duke@0 1179 #ifndef __LP64
duke@0 1180 __ mov(O0, I0);
duke@0 1181 __ restore(O1, G0, O1);
duke@0 1182 #else
duke@0 1183 __ restore(O0, G0, O0);
duke@0 1184 #endif /* __LP64 */
duke@0 1185
duke@0 1186 // Move result handler to expected register
duke@0 1187 __ mov(G3_scratch, Lscratch);
duke@0 1188
duke@0 1189 // Back in normal (native) interpreter frame. State is thread_in_native_trans
duke@0 1190 // switch to thread_in_Java.
duke@0 1191
duke@0 1192 __ set(_thread_in_Java, G3_scratch);
duke@0 1193 __ st(G3_scratch, thread_state);
duke@0 1194
duke@0 1195 // reset handle block
twisti@727 1196 __ ld_ptr(G2_thread, JavaThread::active_handles_offset(), G3_scratch);
duke@0 1197 __ st_ptr(G0, G3_scratch, JNIHandleBlock::top_offset_in_bytes());
duke@0 1198
duke@0 1199 // If we have an oop result store it where it will be safe for any further gc
duke@0 1200 // until we return now that we've released the handle it might be protected by
duke@0 1201
duke@0 1202 {
duke@0 1203 Label no_oop, store_result;
duke@0 1204
duke@0 1205 __ set((intptr_t)AbstractInterpreter::result_handler(T_OBJECT), G3_scratch);
duke@0 1206 __ cmp(G3_scratch, Lscratch);
duke@0 1207 __ brx(Assembler::notEqual, false, Assembler::pt, no_oop);
duke@0 1208 __ delayed()->nop();
duke@0 1209 __ addcc(G0, O0, O0);
duke@0 1210 __ brx(Assembler::notZero, true, Assembler::pt, store_result); // if result is not NULL:
duke@0 1211 __ delayed()->ld_ptr(O0, 0, O0); // unbox it
duke@0 1212 __ mov(G0, O0);
duke@0 1213
duke@0 1214 __ bind(store_result);
duke@0 1215 // Store it where gc will look for it and result handler expects it.
duke@0 1216 __ st_ptr(O0, FP, (frame::interpreter_frame_oop_temp_offset*wordSize) + STACK_BIAS);
duke@0 1217
duke@0 1218 __ bind(no_oop);
duke@0 1219
duke@0 1220 }
duke@0 1221
duke@0 1222
duke@0 1223 // handle exceptions (exception handling will handle unlocking!)
duke@0 1224 { Label L;
twisti@727 1225 Address exception_addr(G2_thread, Thread::pending_exception_offset());
duke@0 1226 __ ld_ptr(exception_addr, Gtemp);
duke@0 1227 __ tst(Gtemp);
duke@0 1228 __ brx(Assembler::equal, false, Assembler::pt, L);
duke@0 1229 __ delayed()->nop();
duke@0 1230 // Note: This could be handled more efficiently since we know that the native
duke@0 1231 // method doesn't have an exception handler. We could directly return
duke@0 1232 // to the exception handler for the caller.
duke@0 1233 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_pending_exception));
duke@0 1234 __ should_not_reach_here();
duke@0 1235 __ bind(L);
duke@0 1236 }
duke@0 1237
duke@0 1238 // JVMTI support (preserves thread register)
duke@0 1239 __ notify_method_exit(true, ilgl, InterpreterMacroAssembler::NotifyJVMTI);
duke@0 1240
duke@0 1241 if (synchronized) {
duke@0 1242 // save and restore any potential method result value around the unlocking operation
duke@0 1243 save_native_result();
duke@0 1244
duke@0 1245 __ add( __ top_most_monitor(), O1);
duke@0 1246 __ unlock_object(O1);
duke@0 1247
duke@0 1248 restore_native_result();
duke@0 1249 }
duke@0 1250
duke@0 1251 #if defined(COMPILER2) && !defined(_LP64)
duke@0 1252
duke@0 1253 // C2 expects long results in G1 we can't tell if we're returning to interpreted
duke@0 1254 // or compiled so just be safe.
duke@0 1255
duke@0 1256 __ sllx(O0, 32, G1); // Shift bits into high G1
duke@0 1257 __ srl (O1, 0, O1); // Zero extend O1
duke@0 1258 __ or3 (O1, G1, G1); // OR 64 bits into G1
duke@0 1259
duke@0 1260 #endif /* COMPILER2 && !_LP64 */
duke@0 1261
duke@0 1262 // dispose of return address and remove activation
duke@0 1263 #ifdef ASSERT
duke@0 1264 {
duke@0 1265 Label ok;
duke@0 1266 __ cmp(I5_savedSP, FP);
duke@0 1267 __ brx(Assembler::greaterEqualUnsigned, false, Assembler::pt, ok);
duke@0 1268 __ delayed()->nop();
duke@0 1269 __ stop("bad I5_savedSP value");
duke@0 1270 __ should_not_reach_here();
duke@0 1271 __ bind(ok);
duke@0 1272 }
duke@0 1273 #endif
duke@0 1274 if (TraceJumps) {
duke@0 1275 // Move target to register that is recordable
duke@0 1276 __ mov(Lscratch, G3_scratch);
duke@0 1277 __ JMP(G3_scratch, 0);
duke@0 1278 } else {
duke@0 1279 __ jmp(Lscratch, 0);
duke@0 1280 }
duke@0 1281 __ delayed()->nop();
duke@0 1282
duke@0 1283
duke@0 1284 if (inc_counter) {
duke@0 1285 // handle invocation counter overflow
duke@0 1286 __ bind(invocation_counter_overflow);
duke@0 1287 generate_counter_overflow(Lcontinue);
duke@0 1288 }
duke@0 1289
duke@0 1290
duke@0 1291
duke@0 1292 return entry;
duke@0 1293 }
duke@0 1294
duke@0 1295
duke@0 1296 // Generic method entry to (asm) interpreter
duke@0 1297 //------------------------------------------------------------------------------------------------------------------------
duke@0 1298 //
duke@0 1299 address InterpreterGenerator::generate_normal_entry(bool synchronized) {
duke@0 1300 address entry = __ pc();
duke@0 1301
duke@0 1302 bool inc_counter = UseCompiler || CountCompiledCalls;
duke@0 1303
duke@0 1304 // the following temporary registers are used during frame creation
duke@0 1305 const Register Gtmp1 = G3_scratch ;
duke@0 1306 const Register Gtmp2 = G1_scratch;
duke@0 1307
duke@0 1308 // make sure registers are different!
duke@0 1309 assert_different_registers(G2_thread, G5_method, Gargs, Gtmp1, Gtmp2);
duke@0 1310
twisti@727 1311 const Address size_of_parameters(G5_method, methodOopDesc::size_of_parameters_offset());
twisti@727 1312 const Address size_of_locals (G5_method, methodOopDesc::size_of_locals_offset());
duke@0 1313 // Seems like G5_method is live at the point this is used. So we could make this look consistent
duke@0 1314 // and use in the asserts.
twisti@727 1315 const Address access_flags (Lmethod, methodOopDesc::access_flags_offset());
duke@0 1316
duke@0 1317 __ verify_oop(G5_method);
duke@0 1318
duke@0 1319 const Register Glocals_size = G3;
duke@0 1320 assert_different_registers(Glocals_size, G4_scratch, Gframe_size);
duke@0 1321
duke@0 1322 // make sure method is not native & not abstract
duke@0 1323 // rethink these assertions - they can be simplified and shared (gri 2/25/2000)
duke@0 1324 #ifdef ASSERT
twisti@727 1325 __ ld(G5_method, methodOopDesc::access_flags_offset(), Gtmp1);
duke@0 1326 {
duke@0 1327 Label L;
duke@0 1328 __ btst(JVM_ACC_NATIVE, Gtmp1);
duke@0 1329 __ br(Assembler::zero, false, Assembler::pt, L);
duke@0 1330 __ delayed()->nop();
duke@0 1331 __ stop("tried to execute native method as non-native");
duke@0 1332 __ bind(L);
duke@0 1333 }
duke@0 1334 { Label L;
duke@0 1335 __ btst(JVM_ACC_ABSTRACT, Gtmp1);
duke@0 1336 __ br(Assembler::zero, false, Assembler::pt, L);
duke@0 1337 __ delayed()->nop();
duke@0 1338 __ stop("tried to execute abstract method as non-abstract");
duke@0 1339 __ bind(L);
duke@0 1340 }
duke@0 1341 #endif // ASSERT
duke@0 1342
duke@0 1343 // generate the code to allocate the interpreter stack frame
duke@0 1344
duke@0 1345 generate_fixed_frame(false);
duke@0 1346
duke@0 1347 #ifdef FAST_DISPATCH
duke@0 1348 __ set((intptr_t)Interpreter::dispatch_table(), IdispatchTables);
duke@0 1349 // set bytecode dispatch table base
duke@0 1350 #endif
duke@0 1351
duke@0 1352 //
duke@0 1353 // Code to initialize the extra (i.e. non-parm) locals
duke@0 1354 //
duke@0 1355 Register init_value = noreg; // will be G0 if we must clear locals
duke@0 1356 // The way the code was setup before zerolocals was always true for vanilla java entries.
duke@0 1357 // It could only be false for the specialized entries like accessor or empty which have
duke@0 1358 // no extra locals so the testing was a waste of time and the extra locals were always
duke@0 1359 // initialized. We removed this extra complication to already over complicated code.
duke@0 1360
duke@0 1361 init_value = G0;
duke@0 1362 Label clear_loop;
duke@0 1363
duke@0 1364 // NOTE: If you change the frame layout, this code will need to
duke@0 1365 // be updated!
duke@0 1366 __ lduh( size_of_locals, O2 );
duke@0 1367 __ lduh( size_of_parameters, O1 );
twisti@1426 1368 __ sll( O2, Interpreter::logStackElementSize, O2);
twisti@1426 1369 __ sll( O1, Interpreter::logStackElementSize, O1 );
duke@0 1370 __ sub( Llocals, O2, O2 );
duke@0 1371 __ sub( Llocals, O1, O1 );
duke@0 1372
duke@0 1373 __ bind( clear_loop );
duke@0 1374 __ inc( O2, wordSize );
duke@0 1375
duke@0 1376 __ cmp( O2, O1 );
duke@0 1377 __ brx( Assembler::lessEqualUnsigned, true, Assembler::pt, clear_loop );
duke@0 1378 __ delayed()->st_ptr( init_value, O2, 0 );
duke@0 1379
twisti@727 1380 const Address do_not_unlock_if_synchronized(G2_thread,
twisti@727 1381 JavaThread::do_not_unlock_if_synchronized_offset());
duke@0 1382 // Since at this point in the method invocation the exception handler
duke@0 1383 // would try to exit the monitor of synchronized methods which hasn't
duke@0 1384 // been entered yet, we set the thread local variable
duke@0 1385 // _do_not_unlock_if_synchronized to true. If any exception was thrown by
duke@0 1386 // runtime, exception handling i.e. unlock_if_synchronized_method will
duke@0 1387 // check this thread local flag.
duke@0 1388 __ movbool(true, G3_scratch);
duke@0 1389 __ stbool(G3_scratch, do_not_unlock_if_synchronized);
duke@0 1390
duke@0 1391 // increment invocation counter and check for overflow
duke@0 1392 //
duke@0 1393 // Note: checking for negative value instead of overflow
duke@0 1394 // so we have a 'sticky' overflow test (may be of
duke@0 1395 // importance as soon as we have true MT/MP)
duke@0 1396 Label invocation_counter_overflow;
duke@0 1397 Label profile_method;
duke@0 1398 Label profile_method_continue;
duke@0 1399 Label Lcontinue;
duke@0 1400 if (inc_counter) {
duke@0 1401 generate_counter_incr(&invocation_counter_overflow, &profile_method, &profile_method_continue);
duke@0 1402 if (ProfileInterpreter) {
duke@0 1403 __ bind(profile_method_continue);
duke@0 1404 }
duke@0 1405 }
duke@0 1406 __ bind(Lcontinue);
duke@0 1407
duke@0 1408 bang_stack_shadow_pages(false);
duke@0 1409
duke@0 1410 // reset the _do_not_unlock_if_synchronized flag
duke@0 1411 __ stbool(G0, do_not_unlock_if_synchronized);
duke@0 1412
duke@0 1413 // check for synchronized methods
duke@0 1414 // Must happen AFTER invocation_counter check and stack overflow check,
duke@0 1415 // so method is not locked if overflows.
duke@0 1416
duke@0 1417 if (synchronized) {
duke@0 1418 lock_method();
duke@0 1419 } else {
duke@0 1420 #ifdef ASSERT
duke@0 1421 { Label ok;
duke@0 1422 __ ld(access_flags, O0);
duke@0 1423 __ btst(JVM_ACC_SYNCHRONIZED, O0);
duke@0 1424 __ br( Assembler::zero, false, Assembler::pt, ok);
duke@0 1425 __ delayed()->nop();
duke@0 1426 __ stop("method needs synchronization");
duke@0 1427 __ bind(ok);
duke@0 1428 }
duke@0 1429 #endif // ASSERT
duke@0 1430 }
duke@0 1431
duke@0 1432 // start execution
duke@0 1433
duke@0 1434 __ verify_thread();
duke@0 1435
duke@0 1436 // jvmti support
duke@0 1437 __ notify_method_entry();
duke@0 1438
duke@0 1439 // start executing instructions
duke@0 1440 __ dispatch_next(vtos);
duke@0 1441
duke@0 1442
duke@0 1443 if (inc_counter) {
duke@0 1444 if (ProfileInterpreter) {
duke@0 1445 // We have decided to profile this method in the interpreter
duke@0 1446 __ bind(profile_method);
duke@0 1447
iveresov@2003 1448 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::profile_method));
iveresov@2003 1449 __ set_method_data_pointer_for_bcp();
duke@0 1450 __ ba(false, profile_method_continue);
duke@0 1451 __ delayed()->nop();
duke@0 1452 }
duke@0 1453
duke@0 1454 // handle invocation counter overflow
duke@0 1455 __ bind(invocation_counter_overflow);
duke@0 1456 generate_counter_overflow(Lcontinue);
duke@0 1457 }
duke@0 1458
duke@0 1459
duke@0 1460 return entry;
duke@0 1461 }
duke@0 1462
duke@0 1463
duke@0 1464 //----------------------------------------------------------------------------------------------------
duke@0 1465 // Entry points & stack frame layout
duke@0 1466 //
duke@0 1467 // Here we generate the various kind of entries into the interpreter.
duke@0 1468 // The two main entry type are generic bytecode methods and native call method.
duke@0 1469 // These both come in synchronized and non-synchronized versions but the
duke@0 1470 // frame layout they create is very similar. The other method entry
duke@0 1471 // types are really just special purpose entries that are really entry
duke@0 1472 // and interpretation all in one. These are for trivial methods like
duke@0 1473 // accessor, empty, or special math methods.
duke@0 1474 //
duke@0 1475 // When control flow reaches any of the entry types for the interpreter
duke@0 1476 // the following holds ->
duke@0 1477 //
duke@0 1478 // C2 Calling Conventions:
duke@0 1479 //
duke@0 1480 // The entry code below assumes that the following registers are set
duke@0 1481 // when coming in:
duke@0 1482 // G5_method: holds the methodOop of the method to call
duke@0 1483 // Lesp: points to the TOS of the callers expression stack
duke@0 1484 // after having pushed all the parameters
duke@0 1485 //
duke@0 1486 // The entry code does the following to setup an interpreter frame
duke@0 1487 // pop parameters from the callers stack by adjusting Lesp
duke@0 1488 // set O0 to Lesp
duke@0 1489 // compute X = (max_locals - num_parameters)
duke@0 1490 // bump SP up by X to accomadate the extra locals
duke@0 1491 // compute X = max_expression_stack
duke@0 1492 // + vm_local_words
duke@0 1493 // + 16 words of register save area
duke@0 1494 // save frame doing a save sp, -X, sp growing towards lower addresses
duke@0 1495 // set Lbcp, Lmethod, LcpoolCache
duke@0 1496 // set Llocals to i0
duke@0 1497 // set Lmonitors to FP - rounded_vm_local_words
duke@0 1498 // set Lesp to Lmonitors - 4
duke@0 1499 //
duke@0 1500 // The frame has now been setup to do the rest of the entry code
duke@0 1501
duke@0 1502 // Try this optimization: Most method entries could live in a
duke@0 1503 // "one size fits all" stack frame without all the dynamic size
duke@0 1504 // calculations. It might be profitable to do all this calculation
duke@0 1505 // statically and approximately for "small enough" methods.
duke@0 1506
duke@0 1507 //-----------------------------------------------------------------------------------------------
duke@0 1508
duke@0 1509 // C1 Calling conventions
duke@0 1510 //
duke@0 1511 // Upon method entry, the following registers are setup:
duke@0 1512 //
duke@0 1513 // g2 G2_thread: current thread
duke@0 1514 // g5 G5_method: method to activate
duke@0 1515 // g4 Gargs : pointer to last argument
duke@0 1516 //
duke@0 1517 //
duke@0 1518 // Stack:
duke@0 1519 //
duke@0 1520 // +---------------+ <--- sp
duke@0 1521 // | |
duke@0 1522 // : reg save area :
duke@0 1523 // | |
duke@0 1524 // +---------------+ <--- sp + 0x40
duke@0 1525 // | |
duke@0 1526 // : extra 7 slots : note: these slots are not really needed for the interpreter (fix later)
duke@0 1527 // | |
duke@0 1528 // +---------------+ <--- sp + 0x5c
duke@0 1529 // | |
duke@0 1530 // : free :
duke@0 1531 // | |
duke@0 1532 // +---------------+ <--- Gargs
duke@0 1533 // | |
duke@0 1534 // : arguments :
duke@0 1535 // | |
duke@0 1536 // +---------------+
duke@0 1537 // | |
duke@0 1538 //
duke@0 1539 //
duke@0 1540 //
duke@0 1541 // AFTER FRAME HAS BEEN SETUP for method interpretation the stack looks like:
duke@0 1542 //
duke@0 1543 // +---------------+ <--- sp
duke@0 1544 // | |
duke@0 1545 // : reg save area :
duke@0 1546 // | |
duke@0 1547 // +---------------+ <--- sp + 0x40
duke@0 1548 // | |
duke@0 1549 // : extra 7 slots : note: these slots are not really needed for the interpreter (fix later)
duke@0 1550 // | |
duke@0 1551 // +---------------+ <--- sp + 0x5c
duke@0 1552 // | |
duke@0 1553 // : :
duke@0 1554 // | | <--- Lesp
duke@0 1555 // +---------------+ <--- Lmonitors (fp - 0x18)
duke@0 1556 // | VM locals |
duke@0 1557 // +---------------+ <--- fp
duke@0 1558 // | |
duke@0 1559 // : reg save area :
duke@0 1560 // | |
duke@0 1561 // +---------------+ <--- fp + 0x40
duke@0 1562 // | |
duke@0 1563 // : extra 7 slots : note: these slots are not really needed for the interpreter (fix later)
duke@0 1564 // | |
duke@0 1565 // +---------------+ <--- fp + 0x5c
duke@0 1566 // | |
duke@0 1567 // : free :
duke@0 1568 // | |
duke@0 1569 // +---------------+
duke@0 1570 // | |
duke@0 1571 // : nonarg locals :
duke@0 1572 // | |
duke@0 1573 // +---------------+
duke@0 1574 // | |
duke@0 1575 // : arguments :
duke@0 1576 // | | <--- Llocals
duke@0 1577 // +---------------+ <--- Gargs
duke@0 1578 // | |
duke@0 1579
duke@0 1580 static int size_activation_helper(int callee_extra_locals, int max_stack, int monitor_size) {
duke@0 1581
duke@0 1582 // Figure out the size of an interpreter frame (in words) given that we have a fully allocated
duke@0 1583 // expression stack, the callee will have callee_extra_locals (so we can account for
duke@0 1584 // frame extension) and monitor_size for monitors. Basically we need to calculate
duke@0 1585 // this exactly like generate_fixed_frame/generate_compute_interpreter_state.
duke@0 1586 //
duke@0 1587 //
duke@0 1588 // The big complicating thing here is that we must ensure that the stack stays properly
duke@0 1589 // aligned. This would be even uglier if monitor size wasn't modulo what the stack
duke@0 1590 // needs to be aligned for). We are given that the sp (fp) is already aligned by
duke@0 1591 // the caller so we must ensure that it is properly aligned for our callee.
duke@0 1592 //
duke@0 1593 const int rounded_vm_local_words =
duke@0 1594 round_to(frame::interpreter_frame_vm_local_words,WordsPerLong);
duke@0 1595 // callee_locals and max_stack are counts, not the size in frame.
duke@0 1596 const int locals_size =
twisti@1426 1597 round_to(callee_extra_locals * Interpreter::stackElementWords, WordsPerLong);
twisti@1426 1598 const int max_stack_words = max_stack * Interpreter::stackElementWords;
duke@0 1599 return (round_to((max_stack_words
jrose@710 1600 //6815692//+ methodOopDesc::extra_stack_words()
duke@0 1601 + rounded_vm_local_words
duke@0 1602 + frame::memory_parameter_word_sp_offset), WordsPerLong)
duke@0 1603 // already rounded
duke@0 1604 + locals_size + monitor_size);
duke@0 1605 }
duke@0 1606
duke@0 1607 // How much stack a method top interpreter activation needs in words.
duke@0 1608 int AbstractInterpreter::size_top_interpreter_activation(methodOop method) {
duke@0 1609
duke@0 1610 // See call_stub code
duke@0 1611 int call_stub_size = round_to(7 + frame::memory_parameter_word_sp_offset,
duke@0 1612 WordsPerLong); // 7 + register save area
duke@0 1613
duke@0 1614 // Save space for one monitor to get into the interpreted method in case
duke@0 1615 // the method is synchronized
duke@0 1616 int monitor_size = method->is_synchronized() ?
duke@0 1617 1*frame::interpreter_frame_monitor_size() : 0;
duke@0 1618 return size_activation_helper(method->max_locals(), method->max_stack(),
duke@0 1619 monitor_size) + call_stub_size;
duke@0 1620 }
duke@0 1621
duke@0 1622 int AbstractInterpreter::layout_activation(methodOop method,
duke@0 1623 int tempcount,
duke@0 1624 int popframe_extra_args,
duke@0 1625 int moncount,
duke@0 1626 int callee_param_count,
duke@0 1627 int callee_local_count,
duke@0 1628 frame* caller,
duke@0 1629 frame* interpreter_frame,
duke@0 1630 bool is_top_frame) {
duke@0 1631 // Note: This calculation must exactly parallel the frame setup
duke@0 1632 // in InterpreterGenerator::generate_fixed_frame.
duke@0 1633 // If f!=NULL, set up the following variables:
duke@0 1634 // - Lmethod
duke@0 1635 // - Llocals
duke@0 1636 // - Lmonitors (to the indicated number of monitors)
duke@0 1637 // - Lesp (to the indicated number of temps)
duke@0 1638 // The frame f (if not NULL) on entry is a description of the caller of the frame
duke@0 1639 // we are about to layout. We are guaranteed that we will be able to fill in a
duke@0 1640 // new interpreter frame as its callee (i.e. the stack space is allocated and
duke@0 1641 // the amount was determined by an earlier call to this method with f == NULL).
duke@0 1642 // On return f (if not NULL) while describe the interpreter frame we just layed out.
duke@0 1643
duke@0 1644 int monitor_size = moncount * frame::interpreter_frame_monitor_size();
duke@0 1645 int rounded_vm_local_words = round_to(frame::interpreter_frame_vm_local_words,WordsPerLong);
duke@0 1646
duke@0 1647 assert(monitor_size == round_to(monitor_size, WordsPerLong), "must align");
duke@0 1648 //
duke@0 1649 // Note: if you look closely this appears to be doing something much different
duke@0 1650 // than generate_fixed_frame. What is happening is this. On sparc we have to do
duke@0 1651 // this dance with interpreter_sp_adjustment because the window save area would
duke@0 1652 // appear just below the bottom (tos) of the caller's java expression stack. Because
duke@0 1653 // the interpreter want to have the locals completely contiguous generate_fixed_frame
duke@0 1654 // will adjust the caller's sp for the "extra locals" (max_locals - parameter_size).
duke@0 1655 // Now in generate_fixed_frame the extension of the caller's sp happens in the callee.
duke@0 1656 // In this code the opposite occurs the caller adjusts it's own stack base on the callee.
duke@0 1657 // This is mostly ok but it does cause a problem when we get to the initial frame (the oldest)
duke@0 1658 // because the oldest frame would have adjust its callers frame and yet that frame
duke@0 1659 // already exists and isn't part of this array of frames we are unpacking. So at first
duke@0 1660 // glance this would seem to mess up that frame. However Deoptimization::fetch_unroll_info_helper()
duke@0 1661 // will after it calculates all of the frame's on_stack_size()'s will then figure out the
duke@0 1662 // amount to adjust the caller of the initial (oldest) frame and the calculation will all
duke@0 1663 // add up. It does seem like it simpler to account for the adjustment here (and remove the
duke@0 1664 // callee... parameters here). However this would mean that this routine would have to take
duke@0 1665 // the caller frame as input so we could adjust its sp (and set it's interpreter_sp_adjustment)
duke@0 1666 // and run the calling loop in the reverse order. This would also would appear to mean making
duke@0 1667 // this code aware of what the interactions are when that initial caller fram was an osr or
duke@0 1668 // other adapter frame. deoptimization is complicated enough and hard enough to debug that
duke@0 1669 // there is no sense in messing working code.
duke@0 1670 //
duke@0 1671
duke@0 1672 int rounded_cls = round_to((callee_local_count - callee_param_count), WordsPerLong);
duke@0 1673 assert(rounded_cls == round_to(rounded_cls, WordsPerLong), "must align");
duke@0 1674
duke@0 1675 int raw_frame_size = size_activation_helper(rounded_cls, method->max_stack(),
duke@0 1676 monitor_size);
duke@0 1677
duke@0 1678 if (interpreter_frame != NULL) {
duke@0 1679 // The skeleton frame must already look like an interpreter frame
duke@0 1680 // even if not fully filled out.
duke@0 1681 assert(interpreter_frame->is_interpreted_frame(), "Must be interpreted frame");
duke@0 1682
duke@0 1683 intptr_t* fp = interpreter_frame->fp();
duke@0 1684
duke@0 1685 JavaThread* thread = JavaThread::current();
duke@0 1686 RegisterMap map(thread, false);
duke@0 1687 // More verification that skeleton frame is properly walkable
duke@0 1688 assert(fp == caller->sp(), "fp must match");
duke@0 1689
duke@0 1690 intptr_t* montop = fp - rounded_vm_local_words;
duke@0 1691
duke@0 1692 // preallocate monitors (cf. __ add_monitor_to_stack)
duke@0 1693 intptr_t* monitors = montop - monitor_size;
duke@0 1694
duke@0 1695 // preallocate stack space
duke@0 1696 intptr_t* esp = monitors - 1 -
twisti@1426 1697 (tempcount * Interpreter::stackElementWords) -
duke@0 1698 popframe_extra_args;
duke@0 1699
twisti@1426 1700 int local_words = method->max_locals() * Interpreter::stackElementWords;
duke@0 1701 intptr_t* locals;
never@2433 1702 if (caller->is_compiled_frame()) {
never@2433 1703 // Compiled frames do not allocate a varargs area so place them
never@2433 1704 // next to the register save area.
never@2433 1705 locals = fp + frame::register_save_words + local_words - 1;
never@2433 1706 // Caller wants his own SP back
never@2433 1707 int caller_frame_size = caller->cb()->frame_size();
never@2433 1708 *interpreter_frame->register_addr(I5_savedSP) = (intptr_t)(caller->fp() - caller_frame_size) - STACK_BIAS;
duke@0 1709 } else {
never@2433 1710 assert(caller->is_interpreted_frame() || caller->is_entry_frame(), "only possible cases");
never@2433 1711 // The entry and interpreter frames are laid out like normal C
never@2433 1712 // frames so place the locals adjacent to the varargs area.
never@2433 1713 locals = fp + frame::memory_parameter_word_sp_offset + local_words - 1;
never@2433 1714 if (caller->is_interpreted_frame()) {
never@2433 1715 *interpreter_frame->register_addr(I5_savedSP) = (intptr_t) (fp + rounded_cls) - STACK_BIAS;
duke@0 1716 }
duke@0 1717 }
duke@0 1718 if (TraceDeoptimization) {
duke@0 1719 if (caller->is_entry_frame()) {
duke@0 1720 // make sure I5_savedSP and the entry frames notion of saved SP
duke@0 1721 // agree. This assertion duplicate a check in entry frame code
duke@0 1722 // but catches the failure earlier.
duke@0 1723 assert(*caller->register_addr(Lscratch) == *interpreter_frame->register_addr(I5_savedSP),
duke@0 1724 "would change callers SP");
duke@0 1725 }
duke@0 1726 if (caller->is_entry_frame()) {
duke@0 1727 tty->print("entry ");
duke@0 1728 }
duke@0 1729 if (caller->is_compiled_frame()) {
duke@0 1730 tty->print("compiled ");
duke@0 1731 if (caller->is_deoptimized_frame()) {
duke@0 1732 tty->print("(deopt) ");
duke@0 1733 }
duke@0 1734 }
duke@0 1735 if (caller->is_interpreted_frame()) {
duke@0 1736 tty->print("interpreted ");
duke@0 1737 }
duke@0 1738 tty->print_cr("caller fp=0x%x sp=0x%x", caller->fp(), caller->sp());
duke@0 1739 tty->print_cr("save area = 0x%x, 0x%x", caller->sp(), caller->sp() + 16);
duke@0 1740 tty->print_cr("save area = 0x%x, 0x%x", caller->fp(), caller->fp() + 16);
duke@0 1741 tty->print_cr("interpreter fp=0x%x sp=0x%x", interpreter_frame->fp(), interpreter_frame->sp());
duke@0 1742 tty->print_cr("save area = 0x%x, 0x%x", interpreter_frame->sp(), interpreter_frame->sp() + 16);
duke@0 1743 tty->print_cr("save area = 0x%x, 0x%x", interpreter_frame->fp(), interpreter_frame->fp() + 16);
duke@0 1744 tty->print_cr("Llocals = 0x%x", locals);
duke@0 1745 tty->print_cr("Lesp = 0x%x", esp);
duke@0 1746 tty->print_cr("Lmonitors = 0x%x", monitors);
duke@0 1747 }
duke@0 1748
duke@0 1749 if (method->max_locals() > 0) {
duke@0 1750 assert(locals < caller->sp() || locals >= (caller->sp() + 16), "locals in save area");
duke@0 1751 assert(locals < caller->fp() || locals > (caller->fp() + 16), "locals in save area");
duke@0 1752 assert(locals < interpreter_frame->sp() || locals > (interpreter_frame->sp() + 16), "locals in save area");
duke@0 1753 assert(locals < interpreter_frame->fp() || locals >= (interpreter_frame->fp() + 16), "locals in save area");
duke@0 1754 }
duke@0 1755 #ifdef _LP64
duke@0 1756 assert(*interpreter_frame->register_addr(I5_savedSP) & 1, "must be odd");
duke@0 1757 #endif
duke@0 1758
duke@0 1759 *interpreter_frame->register_addr(Lmethod) = (intptr_t) method;
duke@0 1760 *interpreter_frame->register_addr(Llocals) = (intptr_t) locals;
duke@0 1761 *interpreter_frame->register_addr(Lmonitors) = (intptr_t) monitors;
duke@0 1762 *interpreter_frame->register_addr(Lesp) = (intptr_t) esp;
duke@0 1763 // Llast_SP will be same as SP as there is no adapter space
duke@0 1764 *interpreter_frame->register_addr(Llast_SP) = (intptr_t) interpreter_frame->sp() - STACK_BIAS;
duke@0 1765 *interpreter_frame->register_addr(LcpoolCache) = (intptr_t) method->constants()->cache();
duke@0 1766 #ifdef FAST_DISPATCH
duke@0 1767 *interpreter_frame->register_addr(IdispatchTables) = (intptr_t) Interpreter::dispatch_table();
duke@0 1768 #endif
duke@0 1769
duke@0 1770
duke@0 1771 #ifdef ASSERT
duke@0 1772 BasicObjectLock* mp = (BasicObjectLock*)monitors;
duke@0 1773
duke@0 1774 assert(interpreter_frame->interpreter_frame_method() == method, "method matches");
twisti@1426 1775 assert(interpreter_frame->interpreter_frame_local_at(9) == (intptr_t *)((intptr_t)locals - (9 * Interpreter::stackElementSize)), "locals match");
duke@0 1776 assert(interpreter_frame->interpreter_frame_monitor_end() == mp, "monitor_end matches");
duke@0 1777 assert(((intptr_t *)interpreter_frame->interpreter_frame_monitor_begin()) == ((intptr_t *)mp)+monitor_size, "monitor_begin matches");
duke@0 1778 assert(interpreter_frame->interpreter_frame_tos_address()-1 == esp, "esp matches");
duke@0 1779
duke@0 1780 // check bounds
duke@0 1781 intptr_t* lo = interpreter_frame->sp() + (frame::memory_parameter_word_sp_offset - 1);
duke@0 1782 intptr_t* hi = interpreter_frame->fp() - rounded_vm_local_words;
duke@0 1783 assert(lo < monitors && montop <= hi, "monitors in bounds");
duke@0 1784 assert(lo <= esp && esp < monitors, "esp in bounds");
duke@0 1785 #endif // ASSERT
duke@0 1786 }
duke@0 1787
duke@0 1788 return raw_frame_size;
duke@0 1789 }
duke@0 1790
duke@0 1791 //----------------------------------------------------------------------------------------------------
duke@0 1792 // Exceptions
duke@0 1793 void TemplateInterpreterGenerator::generate_throw_exception() {
duke@0 1794
duke@0 1795 // Entry point in previous activation (i.e., if the caller was interpreted)
duke@0 1796 Interpreter::_rethrow_exception_entry = __ pc();
duke@0 1797 // O0: exception
duke@0 1798
duke@0 1799 // entry point for exceptions thrown within interpreter code
duke@0 1800 Interpreter::_throw_exception_entry = __ pc();
duke@0 1801 __ verify_thread();
duke@0 1802 // expression stack is undefined here
duke@0 1803 // O0: exception, i.e. Oexception
duke@0 1804 // Lbcp: exception bcx
duke@0 1805 __ verify_oop(Oexception);
duke@0 1806
duke@0 1807
duke@0 1808 // expression stack must be empty before entering the VM in case of an exception
duke@0 1809 __ empty_expression_stack();
duke@0 1810 // find exception handler address and preserve exception oop
duke@0 1811 // call C routine to find handler and jump to it
duke@0 1812 __ call_VM(O1, CAST_FROM_FN_PTR(address, InterpreterRuntime::exception_handler_for_exception), Oexception);
duke@0 1813 __ push_ptr(O1); // push exception for exception handler bytecodes
duke@0 1814
duke@0 1815 __ JMP(O0, 0); // jump to exception handler (may be remove activation entry!)
duke@0 1816 __ delayed()->nop();
duke@0 1817
duke@0 1818
duke@0 1819 // if the exception is not handled in the current frame
duke@0 1820 // the frame is removed and the exception is rethrown
duke@0 1821 // (i.e. exception continuation is _rethrow_exception)
duke@0 1822 //
duke@0 1823 // Note: At this point the bci is still the bxi for the instruction which caused
duke@0 1824 // the exception and the expression stack is empty. Thus, for any VM calls
duke@0 1825 // at this point, GC will find a legal oop map (with empty expression stack).
duke@0 1826
duke@0 1827 // in current activation
duke@0 1828 // tos: exception
duke@0 1829 // Lbcp: exception bcp
duke@0 1830
duke@0 1831 //
duke@0 1832 // JVMTI PopFrame support
duke@0 1833 //
duke@0 1834
duke@0 1835 Interpreter::_remove_activation_preserving_args_entry = __ pc();
twisti@727 1836 Address popframe_condition_addr(G2_thread, JavaThread::popframe_condition_offset());
duke@0 1837 // Set the popframe_processing bit in popframe_condition indicating that we are
duke@0 1838 // currently handling popframe, so that call_VMs that may happen later do not trigger new
duke@0 1839 // popframe handling cycles.
duke@0 1840
duke@0 1841 __ ld(popframe_condition_addr, G3_scratch);
duke@0 1842 __ or3(G3_scratch, JavaThread::popframe_processing_bit, G3_scratch);
duke@0 1843 __ stw(G3_scratch, popframe_condition_addr);
duke@0 1844
duke@0 1845 // Empty the expression stack, as in normal exception handling
duke@0 1846 __ empty_expression_stack();
duke@0 1847 __ unlock_if_synchronized_method(vtos, /* throw_monitor_exception */ false, /* install_monitor_exception */ false);
duke@0 1848
duke@0 1849 {
duke@0 1850 // Check to see whether we are returning to a deoptimized frame.
duke@0 1851 // (The PopFrame call ensures that the caller of the popped frame is
duke@0 1852 // either interpreted or compiled and deoptimizes it if compiled.)
duke@0 1853 // In this case, we can't call dispatch_next() after the frame is
duke@0 1854 // popped, but instead must save the incoming arguments and restore
duke@0 1855 // them after deoptimization has occurred.
duke@0 1856 //
duke@0 1857 // Note that we don't compare the return PC against the
duke@0 1858 // deoptimization blob's unpack entry because of the presence of
duke@0 1859 // adapter frames in C2.
duke@0 1860 Label caller_not_deoptimized;
duke@0 1861 __ call_VM_leaf(L7_thread_cache, CAST_FROM_FN_PTR(address, InterpreterRuntime::interpreter_contains), I7);
duke@0 1862 __ tst(O0);
duke@0 1863 __ brx(Assembler::notEqual, false, Assembler::pt, caller_not_deoptimized);
duke@0 1864 __ delayed()->nop();
duke@0 1865
duke@0 1866 const Register Gtmp1 = G3_scratch;
duke@0 1867 const Register Gtmp2 = G1_scratch;
duke@0 1868
duke@0 1869 // Compute size of arguments for saving when returning to deoptimized caller
duke@0 1870 __ lduh(Lmethod, in_bytes(methodOopDesc::size_of_parameters_offset()), Gtmp1);
twisti@1426 1871 __ sll(Gtmp1, Interpreter::logStackElementSize, Gtmp1);
duke@0 1872 __ sub(Llocals, Gtmp1, Gtmp2);
duke@0 1873 __ add(Gtmp2, wordSize, Gtmp2);
duke@0 1874 // Save these arguments
duke@0 1875 __ call_VM_leaf(L7_thread_cache, CAST_FROM_FN_PTR(address, Deoptimization::popframe_preserve_args), G2_thread, Gtmp1, Gtmp2);
duke@0 1876 // Inform deoptimization that it is responsible for restoring these arguments
duke@0 1877 __ set(JavaThread::popframe_force_deopt_reexecution_bit, Gtmp1);
twisti@727 1878 Address popframe_condition_addr(G2_thread, JavaThread::popframe_condition_offset());
duke@0 1879 __ st(Gtmp1, popframe_condition_addr);
duke@0 1880
duke@0 1881 // Return from the current method
duke@0 1882 // The caller's SP was adjusted upon method entry to accomodate
duke@0 1883 // the callee's non-argument locals. Undo that adjustment.
duke@0 1884 __ ret();
duke@0 1885 __ delayed()->restore(I5_savedSP, G0, SP);
duke@0 1886
duke@0 1887 __ bind(caller_not_deoptimized);
duke@0 1888 }
duke@0 1889
duke@0 1890 // Clear the popframe condition flag
duke@0 1891 __ stw(G0 /* popframe_inactive */, popframe_condition_addr);
duke@0 1892
duke@0 1893 // Get out of the current method (how this is done depends on the particular compiler calling
duke@0 1894 // convention that the interpreter currently follows)
duke@0 1895 // The caller's SP was adjusted upon method entry to accomodate
duke@0 1896 // the callee's non-argument locals. Undo that adjustment.
duke@0 1897 __ restore(I5_savedSP, G0, SP);
duke@0 1898 // The method data pointer was incremented already during
duke@0 1899 // call profiling. We have to restore the mdp for the current bcp.
duke@0 1900 if (ProfileInterpreter) {
duke@0 1901 __ set_method_data_pointer_for_bcp();
duke@0 1902 }
duke@0 1903 // Resume bytecode interpretation at the current bcp
duke@0 1904 __ dispatch_next(vtos);
duke@0 1905 // end of JVMTI PopFrame support
duke@0 1906
duke@0 1907 Interpreter::_remove_activation_entry = __ pc();
duke@0 1908
duke@0 1909 // preserve exception over this code sequence (remove activation calls the vm, but oopmaps are not correct here)
duke@0 1910 __ pop_ptr(Oexception); // get exception
duke@0 1911
duke@0 1912 // Intel has the following comment:
duke@0 1913 //// remove the activation (without doing throws on illegalMonitorExceptions)
duke@0 1914 // They remove the activation without checking for bad monitor state.
duke@0 1915 // %%% We should make sure this is the right semantics before implementing.
duke@0 1916
duke@0 1917 // %%% changed set_vm_result_2 to set_vm_result and get_vm_result_2 to get_vm_result. Is there a bug here?
duke@0 1918 __ set_vm_result(Oexception);
duke@0 1919 __ unlock_if_synchronized_method(vtos, /* throw_monitor_exception */ false);
duke@0 1920
duke@0 1921 __ notify_method_exit(false, vtos, InterpreterMacroAssembler::SkipNotifyJVMTI);
duke@0 1922
duke@0 1923 __ get_vm_result(Oexception);
duke@0 1924 __ verify_oop(Oexception);
duke@0 1925
duke@0 1926 const int return_reg_adjustment = frame::pc_return_offset;
twisti@727 1927 Address issuing_pc_addr(I7, return_reg_adjustment);
duke@0 1928
duke@0 1929 // We are done with this activation frame; find out where to go next.
duke@0 1930 // The continuation point will be an exception handler, which expects
duke@0 1931 // the following registers set up:
duke@0 1932 //
duke@0 1933 // Oexception: exception
duke@0 1934 // Oissuing_pc: the local call that threw exception
duke@0 1935 // Other On: garbage
duke@0 1936 // In/Ln: the contents of the caller's register window
duke@0 1937 //
duke@0 1938 // We do the required restore at the last possible moment, because we
duke@0 1939 // need to preserve some state across a runtime call.
duke@0 1940 // (Remember that the caller activation is unknown--it might not be
duke@0 1941 // interpreted, so things like Lscratch are useless in the caller.)
duke@0 1942
duke@0 1943 // Although the Intel version uses call_C, we can use the more
duke@0 1944 // compact call_VM. (The only real difference on SPARC is a
duke@0 1945 // harmlessly ignored [re]set_last_Java_frame, compared with
duke@0 1946 // the Intel code which lacks this.)
duke@0 1947 __ mov(Oexception, Oexception ->after_save()); // get exception in I0 so it will be on O0 after restore
duke@0 1948 __ add(issuing_pc_addr, Oissuing_pc->after_save()); // likewise set I1 to a value local to the caller
duke@0 1949 __ super_call_VM_leaf(L7_thread_cache,
duke@0 1950 CAST_FROM_FN_PTR(address, SharedRuntime::exception_handler_for_return_address),
twisti@1295 1951 G2_thread, Oissuing_pc->after_save());
duke@0 1952
duke@0 1953 // The caller's SP was adjusted upon method entry to accomodate
duke@0 1954 // the callee's non-argument locals. Undo that adjustment.
duke@0 1955 __ JMP(O0, 0); // return exception handler in caller
duke@0 1956 __ delayed()->restore(I5_savedSP, G0, SP);
duke@0 1957
duke@0 1958 // (same old exception object is already in Oexception; see above)
duke@0 1959 // Note that an "issuing PC" is actually the next PC after the call
duke@0 1960 }
duke@0 1961
duke@0 1962
duke@0 1963 //
duke@0 1964 // JVMTI ForceEarlyReturn support
duke@0 1965 //
duke@0 1966
duke@0 1967 address TemplateInterpreterGenerator::generate_earlyret_entry_for(TosState state) {
duke@0 1968 address entry = __ pc();
duke@0 1969
duke@0 1970 __ empty_expression_stack();
duke@0 1971 __ load_earlyret_value(state);
duke@0 1972
twisti@727 1973 __ ld_ptr(G2_thread, JavaThread::jvmti_thread_state_offset(), G3_scratch);
twisti@727 1974 Address cond_addr(G3_scratch, JvmtiThreadState::earlyret_state_offset());
duke@0 1975
duke@0 1976 // Clear the earlyret state
duke@0 1977 __ stw(G0 /* JvmtiThreadState::earlyret_inactive */, cond_addr);
duke@0 1978
duke@0 1979 __ remove_activation(state,
duke@0 1980 /* throw_monitor_exception */ false,
duke@0 1981 /* install_monitor_exception */ false);
duke@0 1982
duke@0 1983 // The caller's SP was adjusted upon method entry to accomodate
duke@0 1984 // the callee's non-argument locals. Undo that adjustment.
duke@0 1985 __ ret(); // return to caller
duke@0 1986 __ delayed()->restore(I5_savedSP, G0, SP);
duke@0 1987
duke@0 1988 return entry;
duke@0 1989 } // end of JVMTI ForceEarlyReturn support
duke@0 1990
duke@0 1991
duke@0 1992 //------------------------------------------------------------------------------------------------------------------------
duke@0 1993 // Helper for vtos entry point generation
duke@0 1994
duke@0 1995 void TemplateInterpreterGenerator::set_vtos_entry_points(Template* t, address& bep, address& cep, address& sep, address& aep, address& iep, address& lep, address& fep, address& dep, address& vep) {
duke@0 1996 assert(t->is_valid() && t->tos_in() == vtos, "illegal template");
duke@0 1997 Label L;
duke@0 1998 aep = __ pc(); __ push_ptr(); __ ba(false, L); __ delayed()->nop();
duke@0 1999 fep = __ pc(); __ push_f(); __ ba(false, L); __ delayed()->nop();
duke@0 2000 dep = __ pc(); __ push_d(); __ ba(false, L); __ delayed()->nop();
duke@0 2001 lep = __ pc(); __ push_l(); __ ba(false, L); __ delayed()->nop();
duke@0 2002 iep = __ pc(); __ push_i();
duke@0 2003 bep = cep = sep = iep; // there aren't any
duke@0 2004 vep = __ pc(); __ bind(L); // fall through
duke@0 2005 generate_and_dispatch(t);
duke@0 2006 }
duke@0 2007
duke@0 2008 // --------------------------------------------------------------------------------
duke@0 2009
duke@0 2010
duke@0 2011 InterpreterGenerator::InterpreterGenerator(StubQueue* code)
duke@0 2012 : TemplateInterpreterGenerator(code) {
duke@0 2013 generate_all(); // down here so it can be "virtual"
duke@0 2014 }
duke@0 2015
duke@0 2016 // --------------------------------------------------------------------------------
duke@0 2017
duke@0 2018 // Non-product code
duke@0 2019 #ifndef PRODUCT
duke@0 2020 address TemplateInterpreterGenerator::generate_trace_code(TosState state) {
duke@0 2021 address entry = __ pc();
duke@0 2022
duke@0 2023 __ push(state);
duke@0 2024 __ mov(O7, Lscratch); // protect return address within interpreter
duke@0 2025
duke@0 2026 // Pass a 0 (not used in sparc) and the top of stack to the bytecode tracer
duke@0 2027 __ mov( Otos_l2, G3_scratch );
duke@0 2028 __ call_VM(noreg, CAST_FROM_FN_PTR(address, SharedRuntime::trace_bytecode), G0, Otos_l1, G3_scratch);
duke@0 2029 __ mov(Lscratch, O7); // restore return address
duke@0 2030 __ pop(state);
duke@0 2031 __ retl();
duke@0 2032 __ delayed()->nop();
duke@0 2033
duke@0 2034 return entry;
duke@0 2035 }
duke@0 2036
duke@0 2037
duke@0 2038 // helpers for generate_and_dispatch
duke@0 2039
duke@0 2040 void TemplateInterpreterGenerator::count_bytecode() {
twisti@727 2041 __ inc_counter(&BytecodeCounter::_counter_value, G3_scratch, G4_scratch);
duke@0 2042 }
duke@0 2043
duke@0 2044
duke@0 2045 void TemplateInterpreterGenerator::histogram_bytecode(Template* t) {
twisti@727 2046 __ inc_counter(&BytecodeHistogram::_counters[t->bytecode()], G3_scratch, G4_scratch);
duke@0 2047 }
duke@0 2048
duke@0 2049
duke@0 2050 void TemplateInterpreterGenerator::histogram_bytecode_pair(Template* t) {
twisti@727 2051 AddressLiteral index (&BytecodePairHistogram::_index);
twisti@727 2052 AddressLiteral counters((address) &BytecodePairHistogram::_counters);
duke@0 2053
duke@0 2054 // get index, shift out old bytecode, bring in new bytecode, and store it
duke@0 2055 // _index = (_index >> log2_number_of_codes) |
duke@0 2056 // (bytecode << log2_number_of_codes);
duke@0 2057
twisti@727 2058 __ load_contents(index, G4_scratch);
duke@0 2059 __ srl( G4_scratch, BytecodePairHistogram::log2_number_of_codes, G4_scratch );
duke@0 2060 __ set( ((int)t->bytecode()) << BytecodePairHistogram::log2_number_of_codes, G3_scratch );
duke@0 2061 __ or3( G3_scratch, G4_scratch, G4_scratch );
twisti@727 2062 __ store_contents(G4_scratch, index, G3_scratch);
duke@0 2063
duke@0 2064 // bump bucket contents
duke@0 2065 // _counters[_index] ++;
duke@0 2066
twisti@727 2067 __ set(counters, G3_scratch); // loads into G3_scratch
duke@0 2068 __ sll( G4_scratch, LogBytesPerWord, G4_scratch ); // Index is word address
duke@0 2069 __ add (G3_scratch, G4_scratch, G3_scratch); // Add in index
duke@0 2070 __ ld (G3_scratch, 0, G4_scratch);
duke@0 2071 __ inc (G4_scratch);
duke@0 2072 __ st (G4_scratch, 0, G3_scratch);
duke@0 2073 }
duke@0 2074
duke@0 2075
duke@0 2076 void TemplateInterpreterGenerator::trace_bytecode(Template* t) {
duke@0 2077 // Call a little run-time stub to avoid blow-up for each bytecode.
duke@0 2078 // The run-time runtime saves the right registers, depending on
duke@0 2079 // the tosca in-state for the given template.
duke@0 2080 address entry = Interpreter::trace_code(t->tos_in());
duke@0 2081 guarantee(entry != NULL, "entry must have been generated");
duke@0 2082 __ call(entry, relocInfo::none);
duke@0 2083 __ delayed()->nop();
duke@0 2084 }
duke@0 2085
duke@0 2086
duke@0 2087 void TemplateInterpreterGenerator::stop_interpreter_at() {
twisti@727 2088 AddressLiteral counter(&BytecodeCounter::_counter_value);
twisti@727 2089 __ load_contents(counter, G3_scratch);
twisti@727 2090 AddressLiteral stop_at(&StopInterpreterAt);
duke@0 2091 __ load_ptr_contents(stop_at, G4_scratch);
duke@0 2092 __ cmp(G3_scratch, G4_scratch);
duke@0 2093 __ breakpoint_trap(Assembler::equal);
duke@0 2094 }
duke@0 2095 #endif // not PRODUCT
duke@0 2096 #endif // !CC_INTERP