src/cpu/ppc/vm/templateInterpreter_ppc.cpp

Tue, 01 Apr 2014 09:36:49 +0200

author
roland
date
Tue, 01 Apr 2014 09:36:49 +0200
changeset 6723
0bf37f737702
parent 6660
63c5920a038d
child 6876
710a3c8b516e
child 7132
b384ba33c9a0
permissions
-rw-r--r--

8032410: compiler/uncommontrap/TestStackBangRbp.java times out on Solaris-Sparc V9
Summary: make compiled code bang the stack by the worst case size of the interpreter frame at deoptimization points.
Reviewed-by: twisti, kvn

goetz@6512 1 /*
goetz@6512 2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
goetz@6512 3 * Copyright 2013, 2014 SAP AG. All rights reserved.
goetz@6512 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
goetz@6512 5 *
goetz@6512 6 * This code is free software; you can redistribute it and/or modify it
goetz@6512 7 * under the terms of the GNU General Public License version 2 only, as
goetz@6512 8 * published by the Free Software Foundation.
goetz@6512 9 *
goetz@6512 10 * This code is distributed in the hope that it will be useful, but WITHOUT
goetz@6512 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
goetz@6512 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
goetz@6512 13 * version 2 for more details (a copy is included in the LICENSE file that
goetz@6512 14 * accompanied this code).
goetz@6512 15 *
goetz@6512 16 * You should have received a copy of the GNU General Public License version
goetz@6512 17 * 2 along with this work; if not, write to the Free Software Foundation,
goetz@6512 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
goetz@6512 19 *
goetz@6512 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
goetz@6512 21 * or visit www.oracle.com if you need additional information or have any
goetz@6512 22 * questions.
goetz@6512 23 *
goetz@6512 24 */
goetz@6512 25
goetz@6512 26 #include "precompiled.hpp"
goetz@6512 27 #ifndef CC_INTERP
goetz@6512 28 #include "asm/macroAssembler.inline.hpp"
goetz@6512 29 #include "interpreter/bytecodeHistogram.hpp"
goetz@6512 30 #include "interpreter/interpreter.hpp"
goetz@6512 31 #include "interpreter/interpreterGenerator.hpp"
goetz@6512 32 #include "interpreter/interpreterRuntime.hpp"
goetz@6512 33 #include "interpreter/templateTable.hpp"
goetz@6512 34 #include "oops/arrayOop.hpp"
goetz@6512 35 #include "oops/methodData.hpp"
goetz@6512 36 #include "oops/method.hpp"
goetz@6512 37 #include "oops/oop.inline.hpp"
goetz@6512 38 #include "prims/jvmtiExport.hpp"
goetz@6512 39 #include "prims/jvmtiThreadState.hpp"
goetz@6512 40 #include "runtime/arguments.hpp"
goetz@6512 41 #include "runtime/deoptimization.hpp"
goetz@6512 42 #include "runtime/frame.inline.hpp"
goetz@6512 43 #include "runtime/sharedRuntime.hpp"
goetz@6512 44 #include "runtime/stubRoutines.hpp"
goetz@6512 45 #include "runtime/synchronizer.hpp"
goetz@6512 46 #include "runtime/timer.hpp"
goetz@6512 47 #include "runtime/vframeArray.hpp"
goetz@6512 48 #include "utilities/debug.hpp"
goetz@6512 49 #include "utilities/macros.hpp"
goetz@6512 50
goetz@6512 51 #undef __
goetz@6512 52 #define __ _masm->
goetz@6512 53
goetz@6512 54 #ifdef PRODUCT
goetz@6512 55 #define BLOCK_COMMENT(str) /* nothing */
goetz@6512 56 #else
goetz@6512 57 #define BLOCK_COMMENT(str) __ block_comment(str)
goetz@6512 58 #endif
goetz@6512 59
goetz@6512 60 #define BIND(label) bind(label); BLOCK_COMMENT(#label ":")
goetz@6512 61
goetz@6512 62 //-----------------------------------------------------------------------------
goetz@6512 63
goetz@6512 64 // Actually we should never reach here since we do stack overflow checks before pushing any frame.
goetz@6512 65 address TemplateInterpreterGenerator::generate_StackOverflowError_handler() {
goetz@6512 66 address entry = __ pc();
goetz@6512 67 __ unimplemented("generate_StackOverflowError_handler");
goetz@6512 68 return entry;
goetz@6512 69 }
goetz@6512 70
goetz@6512 71 address TemplateInterpreterGenerator::generate_ArrayIndexOutOfBounds_handler(const char* name) {
goetz@6512 72 address entry = __ pc();
goetz@6512 73 __ empty_expression_stack();
goetz@6512 74 __ load_const_optimized(R4_ARG2, (address) name);
goetz@6512 75 // Index is in R17_tos.
goetz@6512 76 __ mr(R5_ARG3, R17_tos);
goetz@6512 77 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_ArrayIndexOutOfBoundsException));
goetz@6512 78 return entry;
goetz@6512 79 }
goetz@6512 80
goetz@6512 81 #if 0
goetz@6512 82 // Call special ClassCastException constructor taking object to cast
goetz@6512 83 // and target class as arguments.
goetz@6660 84 address TemplateInterpreterGenerator::generate_ClassCastException_verbose_handler() {
goetz@6512 85 address entry = __ pc();
goetz@6512 86
goetz@6512 87 // Expression stack must be empty before entering the VM if an
goetz@6512 88 // exception happened.
goetz@6512 89 __ empty_expression_stack();
goetz@6660 90
goetz@6512 91 // Thread will be loaded to R3_ARG1.
goetz@6660 92 // Target class oop is in register R5_ARG3 by convention!
goetz@6660 93 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_ClassCastException_verbose, R17_tos, R5_ARG3));
goetz@6512 94 // Above call must not return here since exception pending.
goetz@6660 95 DEBUG_ONLY(__ should_not_reach_here();)
goetz@6512 96 return entry;
goetz@6512 97 }
goetz@6512 98 #endif
goetz@6512 99
goetz@6512 100 address TemplateInterpreterGenerator::generate_ClassCastException_handler() {
goetz@6512 101 address entry = __ pc();
goetz@6512 102 // Expression stack must be empty before entering the VM if an
goetz@6512 103 // exception happened.
goetz@6512 104 __ empty_expression_stack();
goetz@6512 105
goetz@6512 106 // Load exception object.
goetz@6512 107 // Thread will be loaded to R3_ARG1.
goetz@6512 108 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_ClassCastException), R17_tos);
goetz@6512 109 #ifdef ASSERT
goetz@6512 110 // Above call must not return here since exception pending.
goetz@6512 111 __ should_not_reach_here();
goetz@6512 112 #endif
goetz@6512 113 return entry;
goetz@6512 114 }
goetz@6512 115
goetz@6512 116 address TemplateInterpreterGenerator::generate_exception_handler_common(const char* name, const char* message, bool pass_oop) {
goetz@6512 117 address entry = __ pc();
goetz@6512 118 //__ untested("generate_exception_handler_common");
goetz@6512 119 Register Rexception = R17_tos;
goetz@6512 120
goetz@6512 121 // Expression stack must be empty before entering the VM if an exception happened.
goetz@6512 122 __ empty_expression_stack();
goetz@6512 123
goetz@6512 124 __ load_const_optimized(R4_ARG2, (address) name, R11_scratch1);
goetz@6512 125 if (pass_oop) {
goetz@6512 126 __ mr(R5_ARG3, Rexception);
goetz@6512 127 __ call_VM(Rexception, CAST_FROM_FN_PTR(address, InterpreterRuntime::create_klass_exception), false);
goetz@6512 128 } else {
goetz@6512 129 __ load_const_optimized(R5_ARG3, (address) message, R11_scratch1);
goetz@6512 130 __ call_VM(Rexception, CAST_FROM_FN_PTR(address, InterpreterRuntime::create_exception), false);
goetz@6512 131 }
goetz@6512 132
goetz@6512 133 // Throw exception.
goetz@6512 134 __ mr(R3_ARG1, Rexception);
goetz@6512 135 __ load_const_optimized(R11_scratch1, Interpreter::throw_exception_entry(), R12_scratch2);
goetz@6512 136 __ mtctr(R11_scratch1);
goetz@6512 137 __ bctr();
goetz@6512 138
goetz@6512 139 return entry;
goetz@6512 140 }
goetz@6512 141
goetz@6512 142 address TemplateInterpreterGenerator::generate_continuation_for(TosState state) {
goetz@6512 143 address entry = __ pc();
goetz@6512 144 __ unimplemented("generate_continuation_for");
goetz@6512 145 return entry;
goetz@6512 146 }
goetz@6512 147
goetz@6512 148 // This entry is returned to when a call returns to the interpreter.
goetz@6512 149 // When we arrive here, we expect that the callee stack frame is already popped.
goetz@6512 150 address TemplateInterpreterGenerator::generate_return_entry_for(TosState state, int step, size_t index_size) {
goetz@6512 151 address entry = __ pc();
goetz@6512 152
goetz@6512 153 // Move the value out of the return register back to the TOS cache of current frame.
goetz@6512 154 switch (state) {
goetz@6512 155 case ltos:
goetz@6512 156 case btos:
goetz@6512 157 case ctos:
goetz@6512 158 case stos:
goetz@6512 159 case atos:
goetz@6512 160 case itos: __ mr(R17_tos, R3_RET); break; // RET -> TOS cache
goetz@6512 161 case ftos:
goetz@6512 162 case dtos: __ fmr(F15_ftos, F1_RET); break; // TOS cache -> GR_FRET
goetz@6512 163 case vtos: break; // Nothing to do, this was a void return.
goetz@6512 164 default : ShouldNotReachHere();
goetz@6512 165 }
goetz@6512 166
goetz@6512 167 __ restore_interpreter_state(R11_scratch1); // Sets R11_scratch1 = fp.
goetz@6512 168 __ ld(R12_scratch2, _ijava_state_neg(top_frame_sp), R11_scratch1);
goetz@6512 169 __ resize_frame_absolute(R12_scratch2, R11_scratch1, R0);
goetz@6512 170
goetz@6512 171 // Compiled code destroys templateTableBase, reload.
goetz@6512 172 __ load_const_optimized(R25_templateTableBase, (address)Interpreter::dispatch_table((TosState)0), R12_scratch2);
goetz@6512 173
goetz@6512 174 const Register cache = R11_scratch1;
goetz@6512 175 const Register size = R12_scratch2;
goetz@6512 176 __ get_cache_and_index_at_bcp(cache, 1, index_size);
goetz@6512 177
goetz@6512 178 // Big Endian (get least significant byte of 64 bit value):
goetz@6512 179 __ lbz(size, in_bytes(ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::flags_offset()) + 7, cache);
goetz@6512 180 __ sldi(size, size, Interpreter::logStackElementSize);
goetz@6512 181 __ add(R15_esp, R15_esp, size);
goetz@6512 182 __ dispatch_next(state, step);
goetz@6512 183 return entry;
goetz@6512 184 }
goetz@6512 185
goetz@6512 186 address TemplateInterpreterGenerator::generate_deopt_entry_for(TosState state, int step) {
goetz@6512 187 address entry = __ pc();
goetz@6512 188 // If state != vtos, we're returning from a native method, which put it's result
goetz@6512 189 // into the result register. So move the value out of the return register back
goetz@6512 190 // to the TOS cache of current frame.
goetz@6512 191
goetz@6512 192 switch (state) {
goetz@6512 193 case ltos:
goetz@6512 194 case btos:
goetz@6512 195 case ctos:
goetz@6512 196 case stos:
goetz@6512 197 case atos:
goetz@6512 198 case itos: __ mr(R17_tos, R3_RET); break; // GR_RET -> TOS cache
goetz@6512 199 case ftos:
goetz@6512 200 case dtos: __ fmr(F15_ftos, F1_RET); break; // TOS cache -> GR_FRET
goetz@6512 201 case vtos: break; // Nothing to do, this was a void return.
goetz@6512 202 default : ShouldNotReachHere();
goetz@6512 203 }
goetz@6512 204
goetz@6512 205 // Load LcpoolCache @@@ should be already set!
goetz@6512 206 __ get_constant_pool_cache(R27_constPoolCache);
goetz@6512 207
goetz@6512 208 // Handle a pending exception, fall through if none.
goetz@6512 209 __ check_and_forward_exception(R11_scratch1, R12_scratch2);
goetz@6512 210
goetz@6512 211 // Start executing bytecodes.
goetz@6512 212 __ dispatch_next(state, step);
goetz@6512 213
goetz@6512 214 return entry;
goetz@6512 215 }
goetz@6512 216
goetz@6512 217 // A result handler converts the native result into java format.
goetz@6512 218 // Use the shared code between c++ and template interpreter.
goetz@6512 219 address TemplateInterpreterGenerator::generate_result_handler_for(BasicType type) {
goetz@6512 220 return AbstractInterpreterGenerator::generate_result_handler_for(type);
goetz@6512 221 }
goetz@6512 222
goetz@6512 223 address TemplateInterpreterGenerator::generate_safept_entry_for(TosState state, address runtime_entry) {
goetz@6512 224 address entry = __ pc();
goetz@6512 225
goetz@6512 226 __ push(state);
goetz@6512 227 __ call_VM(noreg, runtime_entry);
goetz@6512 228 __ dispatch_via(vtos, Interpreter::_normal_table.table_for(vtos));
goetz@6512 229
goetz@6512 230 return entry;
goetz@6512 231 }
goetz@6512 232
goetz@6512 233 // Helpers for commoning out cases in the various type of method entries.
goetz@6512 234
goetz@6512 235 // Increment invocation count & check for overflow.
goetz@6512 236 //
goetz@6512 237 // Note: checking for negative value instead of overflow
goetz@6512 238 // so we have a 'sticky' overflow test.
goetz@6512 239 //
goetz@6512 240 void TemplateInterpreterGenerator::generate_counter_incr(Label* overflow, Label* profile_method, Label* profile_method_continue) {
goetz@6512 241 // Note: In tiered we increment either counters in method or in MDO depending if we're profiling or not.
goetz@6512 242 Register Rscratch1 = R11_scratch1;
goetz@6512 243 Register Rscratch2 = R12_scratch2;
goetz@6512 244 Register R3_counters = R3_ARG1;
goetz@6512 245 Label done;
goetz@6512 246
goetz@6512 247 if (TieredCompilation) {
goetz@6512 248 const int increment = InvocationCounter::count_increment;
goetz@6512 249 const int mask = ((1 << Tier0InvokeNotifyFreqLog) - 1) << InvocationCounter::count_shift;
goetz@6512 250 Label no_mdo;
goetz@6512 251 if (ProfileInterpreter) {
goetz@6512 252 const Register Rmdo = Rscratch1;
goetz@6512 253 // If no method data exists, go to profile_continue.
goetz@6512 254 __ ld(Rmdo, in_bytes(Method::method_data_offset()), R19_method);
goetz@6512 255 __ cmpdi(CCR0, Rmdo, 0);
goetz@6512 256 __ beq(CCR0, no_mdo);
goetz@6512 257
goetz@6512 258 // Increment backedge counter in the MDO.
goetz@6512 259 const int mdo_bc_offs = in_bytes(MethodData::backedge_counter_offset()) + in_bytes(InvocationCounter::counter_offset());
goetz@6512 260 __ lwz(Rscratch2, mdo_bc_offs, Rmdo);
goetz@6512 261 __ addi(Rscratch2, Rscratch2, increment);
goetz@6512 262 __ stw(Rscratch2, mdo_bc_offs, Rmdo);
goetz@6512 263 __ load_const_optimized(Rscratch1, mask, R0);
goetz@6512 264 __ and_(Rscratch1, Rscratch2, Rscratch1);
goetz@6512 265 __ bne(CCR0, done);
goetz@6512 266 __ b(*overflow);
goetz@6512 267 }
goetz@6512 268
goetz@6512 269 // Increment counter in MethodCounters*.
goetz@6512 270 const int mo_bc_offs = in_bytes(MethodCounters::backedge_counter_offset()) + in_bytes(InvocationCounter::counter_offset());
goetz@6512 271 __ bind(no_mdo);
goetz@6512 272 __ get_method_counters(R19_method, R3_counters, done);
goetz@6512 273 __ lwz(Rscratch2, mo_bc_offs, R3_counters);
goetz@6512 274 __ addi(Rscratch2, Rscratch2, increment);
goetz@6512 275 __ stw(Rscratch2, mo_bc_offs, R3_counters);
goetz@6512 276 __ load_const_optimized(Rscratch1, mask, R0);
goetz@6512 277 __ and_(Rscratch1, Rscratch2, Rscratch1);
goetz@6512 278 __ beq(CCR0, *overflow);
goetz@6512 279
goetz@6512 280 __ bind(done);
goetz@6512 281
goetz@6512 282 } else {
goetz@6512 283
goetz@6512 284 // Update standard invocation counters.
goetz@6512 285 Register Rsum_ivc_bec = R4_ARG2;
goetz@6512 286 __ get_method_counters(R19_method, R3_counters, done);
goetz@6512 287 __ increment_invocation_counter(R3_counters, Rsum_ivc_bec, R12_scratch2);
goetz@6512 288 // Increment interpreter invocation counter.
goetz@6512 289 if (ProfileInterpreter) { // %%% Merge this into methodDataOop.
goetz@6512 290 __ lwz(R12_scratch2, in_bytes(MethodCounters::interpreter_invocation_counter_offset()), R3_counters);
goetz@6512 291 __ addi(R12_scratch2, R12_scratch2, 1);
goetz@6512 292 __ stw(R12_scratch2, in_bytes(MethodCounters::interpreter_invocation_counter_offset()), R3_counters);
goetz@6512 293 }
goetz@6512 294 // Check if we must create a method data obj.
goetz@6512 295 if (ProfileInterpreter && profile_method != NULL) {
goetz@6512 296 const Register profile_limit = Rscratch1;
goetz@6512 297 int pl_offs = __ load_const_optimized(profile_limit, &InvocationCounter::InterpreterProfileLimit, R0, true);
goetz@6512 298 __ lwz(profile_limit, pl_offs, profile_limit);
goetz@6512 299 // Test to see if we should create a method data oop.
goetz@6512 300 __ cmpw(CCR0, Rsum_ivc_bec, profile_limit);
goetz@6512 301 __ blt(CCR0, *profile_method_continue);
goetz@6512 302 // If no method data exists, go to profile_method.
goetz@6512 303 __ test_method_data_pointer(*profile_method);
goetz@6512 304 }
goetz@6512 305 // Finally check for counter overflow.
goetz@6512 306 if (overflow) {
goetz@6512 307 const Register invocation_limit = Rscratch1;
goetz@6512 308 int il_offs = __ load_const_optimized(invocation_limit, &InvocationCounter::InterpreterInvocationLimit, R0, true);
goetz@6512 309 __ lwz(invocation_limit, il_offs, invocation_limit);
goetz@6512 310 assert(4 == sizeof(InvocationCounter::InterpreterInvocationLimit), "unexpected field size");
goetz@6512 311 __ cmpw(CCR0, Rsum_ivc_bec, invocation_limit);
goetz@6512 312 __ bge(CCR0, *overflow);
goetz@6512 313 }
goetz@6512 314
goetz@6512 315 __ bind(done);
goetz@6512 316 }
goetz@6512 317 }
goetz@6512 318
goetz@6512 319 // Generate code to initiate compilation on invocation counter overflow.
goetz@6512 320 void TemplateInterpreterGenerator::generate_counter_overflow(Label& continue_entry) {
goetz@6512 321 // Generate code to initiate compilation on the counter overflow.
goetz@6512 322
goetz@6512 323 // InterpreterRuntime::frequency_counter_overflow takes one arguments,
goetz@6512 324 // which indicates if the counter overflow occurs at a backwards branch (NULL bcp)
goetz@6512 325 // We pass zero in.
goetz@6512 326 // The call returns the address of the verified entry point for the method or NULL
goetz@6512 327 // if the compilation did not complete (either went background or bailed out).
goetz@6512 328 //
goetz@6512 329 // Unlike the C++ interpreter above: Check exceptions!
goetz@6512 330 // Assumption: Caller must set the flag "do_not_unlock_if_sychronized" if the monitor of a sync'ed
goetz@6512 331 // method has not yet been created. Thus, no unlocking of a non-existing monitor can occur.
goetz@6512 332
goetz@6512 333 __ li(R4_ARG2, 0);
goetz@6512 334 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::frequency_counter_overflow), R4_ARG2, true);
goetz@6512 335
goetz@6512 336 // Returns verified_entry_point or NULL.
goetz@6512 337 // We ignore it in any case.
goetz@6512 338 __ b(continue_entry);
goetz@6512 339 }
goetz@6512 340
goetz@6512 341 void TemplateInterpreterGenerator::generate_stack_overflow_check(Register Rmem_frame_size, Register Rscratch1) {
goetz@6512 342 assert_different_registers(Rmem_frame_size, Rscratch1);
goetz@6512 343 __ generate_stack_overflow_check_with_compare_and_throw(Rmem_frame_size, Rscratch1);
goetz@6512 344 }
goetz@6512 345
goetz@6512 346 void TemplateInterpreterGenerator::unlock_method(bool check_exceptions) {
goetz@6512 347 __ unlock_object(R26_monitor, check_exceptions);
goetz@6512 348 }
goetz@6512 349
goetz@6512 350 // Lock the current method, interpreter register window must be set up!
goetz@6512 351 void TemplateInterpreterGenerator::lock_method(Register Rflags, Register Rscratch1, Register Rscratch2, bool flags_preloaded) {
goetz@6512 352 const Register Robj_to_lock = Rscratch2;
goetz@6512 353
goetz@6512 354 {
goetz@6512 355 if (!flags_preloaded) {
goetz@6512 356 __ lwz(Rflags, method_(access_flags));
goetz@6512 357 }
goetz@6512 358
goetz@6512 359 #ifdef ASSERT
goetz@6512 360 // Check if methods needs synchronization.
goetz@6512 361 {
goetz@6512 362 Label Lok;
goetz@6512 363 __ testbitdi(CCR0, R0, Rflags, JVM_ACC_SYNCHRONIZED_BIT);
goetz@6512 364 __ btrue(CCR0,Lok);
goetz@6512 365 __ stop("method doesn't need synchronization");
goetz@6512 366 __ bind(Lok);
goetz@6512 367 }
goetz@6512 368 #endif // ASSERT
goetz@6512 369 }
goetz@6512 370
goetz@6512 371 // Get synchronization object to Rscratch2.
goetz@6512 372 {
goetz@6512 373 const int mirror_offset = in_bytes(Klass::java_mirror_offset());
goetz@6512 374 Label Lstatic;
goetz@6512 375 Label Ldone;
goetz@6512 376
goetz@6512 377 __ testbitdi(CCR0, R0, Rflags, JVM_ACC_STATIC_BIT);
goetz@6512 378 __ btrue(CCR0, Lstatic);
goetz@6512 379
goetz@6512 380 // Non-static case: load receiver obj from stack and we're done.
goetz@6512 381 __ ld(Robj_to_lock, R18_locals);
goetz@6512 382 __ b(Ldone);
goetz@6512 383
goetz@6512 384 __ bind(Lstatic); // Static case: Lock the java mirror
goetz@6512 385 __ ld(Robj_to_lock, in_bytes(Method::const_offset()), R19_method);
goetz@6512 386 __ ld(Robj_to_lock, in_bytes(ConstMethod::constants_offset()), Robj_to_lock);
goetz@6512 387 __ ld(Robj_to_lock, ConstantPool::pool_holder_offset_in_bytes(), Robj_to_lock);
goetz@6512 388 __ ld(Robj_to_lock, mirror_offset, Robj_to_lock);
goetz@6512 389
goetz@6512 390 __ bind(Ldone);
goetz@6512 391 __ verify_oop(Robj_to_lock);
goetz@6512 392 }
goetz@6512 393
goetz@6512 394 // Got the oop to lock => execute!
goetz@6512 395 __ add_monitor_to_stack(true, Rscratch1, R0);
goetz@6512 396
goetz@6512 397 __ std(Robj_to_lock, BasicObjectLock::obj_offset_in_bytes(), R26_monitor);
goetz@6512 398 __ lock_object(R26_monitor, Robj_to_lock);
goetz@6512 399 }
goetz@6512 400
goetz@6512 401 // Generate a fixed interpreter frame for pure interpreter
goetz@6512 402 // and I2N native transition frames.
goetz@6512 403 //
goetz@6512 404 // Before (stack grows downwards):
goetz@6512 405 //
goetz@6512 406 // | ... |
goetz@6512 407 // |------------- |
goetz@6512 408 // | java arg0 |
goetz@6512 409 // | ... |
goetz@6512 410 // | java argn |
goetz@6512 411 // | | <- R15_esp
goetz@6512 412 // | |
goetz@6512 413 // |--------------|
goetz@6512 414 // | abi_112 |
goetz@6512 415 // | | <- R1_SP
goetz@6512 416 // |==============|
goetz@6512 417 //
goetz@6512 418 //
goetz@6512 419 // After:
goetz@6512 420 //
goetz@6512 421 // | ... |
goetz@6512 422 // | java arg0 |<- R18_locals
goetz@6512 423 // | ... |
goetz@6512 424 // | java argn |
goetz@6512 425 // |--------------|
goetz@6512 426 // | |
goetz@6512 427 // | java locals |
goetz@6512 428 // | |
goetz@6512 429 // |--------------|
goetz@6512 430 // | abi_48 |
goetz@6512 431 // |==============|
goetz@6512 432 // | |
goetz@6512 433 // | istate |
goetz@6512 434 // | |
goetz@6512 435 // |--------------|
goetz@6512 436 // | monitor |<- R26_monitor
goetz@6512 437 // |--------------|
goetz@6512 438 // | |<- R15_esp
goetz@6512 439 // | expression |
goetz@6512 440 // | stack |
goetz@6512 441 // | |
goetz@6512 442 // |--------------|
goetz@6512 443 // | |
goetz@6512 444 // | abi_112 |<- R1_SP
goetz@6512 445 // |==============|
goetz@6512 446 //
goetz@6512 447 // The top most frame needs an abi space of 112 bytes. This space is needed,
goetz@6512 448 // since we call to c. The c function may spill their arguments to the caller
goetz@6512 449 // frame. When we call to java, we don't need these spill slots. In order to save
goetz@6512 450 // space on the stack, we resize the caller. However, java local reside in
goetz@6512 451 // the caller frame and the frame has to be increased. The frame_size for the
goetz@6512 452 // current frame was calculated based on max_stack as size for the expression
goetz@6512 453 // stack. At the call, just a part of the expression stack might be used.
goetz@6512 454 // We don't want to waste this space and cut the frame back accordingly.
goetz@6512 455 // The resulting amount for resizing is calculated as follows:
goetz@6512 456 // resize = (number_of_locals - number_of_arguments) * slot_size
goetz@6512 457 // + (R1_SP - R15_esp) + 48
goetz@6512 458 //
goetz@6512 459 // The size for the callee frame is calculated:
goetz@6512 460 // framesize = 112 + max_stack + monitor + state_size
goetz@6512 461 //
goetz@6512 462 // maxstack: Max number of slots on the expression stack, loaded from the method.
goetz@6512 463 // monitor: We statically reserve room for one monitor object.
goetz@6512 464 // state_size: We save the current state of the interpreter to this area.
goetz@6512 465 //
goetz@6512 466 void TemplateInterpreterGenerator::generate_fixed_frame(bool native_call, Register Rsize_of_parameters, Register Rsize_of_locals) {
goetz@6512 467 Register parent_frame_resize = R6_ARG4, // Frame will grow by this number of bytes.
goetz@6512 468 top_frame_size = R7_ARG5,
goetz@6512 469 Rconst_method = R8_ARG6;
goetz@6512 470
goetz@6512 471 assert_different_registers(Rsize_of_parameters, Rsize_of_locals, parent_frame_resize, top_frame_size);
goetz@6512 472
goetz@6512 473 __ ld(Rconst_method, method_(const));
goetz@6512 474 __ lhz(Rsize_of_parameters /* number of params */,
goetz@6512 475 in_bytes(ConstMethod::size_of_parameters_offset()), Rconst_method);
goetz@6512 476 if (native_call) {
goetz@6512 477 // If we're calling a native method, we reserve space for the worst-case signature
goetz@6512 478 // handler varargs vector, which is max(Argument::n_register_parameters, parameter_count+2).
goetz@6512 479 // We add two slots to the parameter_count, one for the jni
goetz@6512 480 // environment and one for a possible native mirror.
goetz@6512 481 Label skip_native_calculate_max_stack;
goetz@6512 482 __ addi(top_frame_size, Rsize_of_parameters, 2);
goetz@6512 483 __ cmpwi(CCR0, top_frame_size, Argument::n_register_parameters);
goetz@6512 484 __ bge(CCR0, skip_native_calculate_max_stack);
goetz@6512 485 __ li(top_frame_size, Argument::n_register_parameters);
goetz@6512 486 __ bind(skip_native_calculate_max_stack);
goetz@6512 487 __ sldi(Rsize_of_parameters, Rsize_of_parameters, Interpreter::logStackElementSize);
goetz@6512 488 __ sldi(top_frame_size, top_frame_size, Interpreter::logStackElementSize);
goetz@6512 489 __ sub(parent_frame_resize, R1_SP, R15_esp); // <0, off by Interpreter::stackElementSize!
goetz@6512 490 assert(Rsize_of_locals == noreg, "Rsize_of_locals not initialized"); // Only relevant value is Rsize_of_parameters.
goetz@6512 491 } else {
goetz@6512 492 __ lhz(Rsize_of_locals /* number of params */, in_bytes(ConstMethod::size_of_locals_offset()), Rconst_method);
goetz@6512 493 __ sldi(Rsize_of_parameters, Rsize_of_parameters, Interpreter::logStackElementSize);
goetz@6512 494 __ sldi(Rsize_of_locals, Rsize_of_locals, Interpreter::logStackElementSize);
goetz@6512 495 __ lhz(top_frame_size, in_bytes(ConstMethod::max_stack_offset()), Rconst_method);
goetz@6512 496 __ sub(R11_scratch1, Rsize_of_locals, Rsize_of_parameters); // >=0
goetz@6512 497 __ sub(parent_frame_resize, R1_SP, R15_esp); // <0, off by Interpreter::stackElementSize!
goetz@6512 498 __ sldi(top_frame_size, top_frame_size, Interpreter::logStackElementSize);
goetz@6512 499 __ add(parent_frame_resize, parent_frame_resize, R11_scratch1);
goetz@6512 500 }
goetz@6512 501
goetz@6512 502 // Compute top frame size.
goetz@6512 503 __ addi(top_frame_size, top_frame_size, frame::abi_reg_args_size + frame::ijava_state_size);
goetz@6512 504
goetz@6512 505 // Cut back area between esp and max_stack.
goetz@6512 506 __ addi(parent_frame_resize, parent_frame_resize, frame::abi_minframe_size - Interpreter::stackElementSize);
goetz@6512 507
goetz@6512 508 __ round_to(top_frame_size, frame::alignment_in_bytes);
goetz@6512 509 __ round_to(parent_frame_resize, frame::alignment_in_bytes);
goetz@6512 510 // parent_frame_resize = (locals-parameters) - (ESP-SP-ABI48) Rounded to frame alignment size.
goetz@6512 511 // Enlarge by locals-parameters (not in case of native_call), shrink by ESP-SP-ABI48.
goetz@6512 512
goetz@6512 513 {
goetz@6512 514 // --------------------------------------------------------------------------
goetz@6512 515 // Stack overflow check
goetz@6512 516
goetz@6512 517 Label cont;
goetz@6512 518 __ add(R11_scratch1, parent_frame_resize, top_frame_size);
goetz@6512 519 generate_stack_overflow_check(R11_scratch1, R12_scratch2);
goetz@6512 520 }
goetz@6512 521
goetz@6512 522 // Set up interpreter state registers.
goetz@6512 523
goetz@6512 524 __ add(R18_locals, R15_esp, Rsize_of_parameters);
goetz@6512 525 __ ld(R27_constPoolCache, in_bytes(ConstMethod::constants_offset()), Rconst_method);
goetz@6512 526 __ ld(R27_constPoolCache, ConstantPool::cache_offset_in_bytes(), R27_constPoolCache);
goetz@6512 527
goetz@6512 528 // Set method data pointer.
goetz@6512 529 if (ProfileInterpreter) {
goetz@6512 530 Label zero_continue;
goetz@6512 531 __ ld(R28_mdx, method_(method_data));
goetz@6512 532 __ cmpdi(CCR0, R28_mdx, 0);
goetz@6512 533 __ beq(CCR0, zero_continue);
goetz@6512 534 __ addi(R28_mdx, R28_mdx, in_bytes(MethodData::data_offset()));
goetz@6512 535 __ bind(zero_continue);
goetz@6512 536 }
goetz@6512 537
goetz@6512 538 if (native_call) {
goetz@6512 539 __ li(R14_bcp, 0); // Must initialize.
goetz@6512 540 } else {
goetz@6512 541 __ add(R14_bcp, in_bytes(ConstMethod::codes_offset()), Rconst_method);
goetz@6512 542 }
goetz@6512 543
goetz@6512 544 // Resize parent frame.
goetz@6512 545 __ mflr(R12_scratch2);
goetz@6512 546 __ neg(parent_frame_resize, parent_frame_resize);
goetz@6512 547 __ resize_frame(parent_frame_resize, R11_scratch1);
goetz@6512 548 __ std(R12_scratch2, _abi(lr), R1_SP);
goetz@6512 549
goetz@6512 550 __ addi(R26_monitor, R1_SP, - frame::ijava_state_size);
goetz@6512 551 __ addi(R15_esp, R26_monitor, - Interpreter::stackElementSize);
goetz@6512 552
goetz@6512 553 // Store values.
goetz@6512 554 // R15_esp, R14_bcp, R26_monitor, R28_mdx are saved at java calls
goetz@6512 555 // in InterpreterMacroAssembler::call_from_interpreter.
goetz@6512 556 __ std(R19_method, _ijava_state_neg(method), R1_SP);
goetz@6512 557 __ std(R21_sender_SP, _ijava_state_neg(sender_sp), R1_SP);
goetz@6512 558 __ std(R27_constPoolCache, _ijava_state_neg(cpoolCache), R1_SP);
goetz@6512 559 __ std(R18_locals, _ijava_state_neg(locals), R1_SP);
goetz@6512 560
goetz@6512 561 // Note: esp, bcp, monitor, mdx live in registers. Hence, the correct version can only
goetz@6512 562 // be found in the frame after save_interpreter_state is done. This is always true
goetz@6512 563 // for non-top frames. But when a signal occurs, dumping the top frame can go wrong,
goetz@6512 564 // because e.g. frame::interpreter_frame_bcp() will not access the correct value
goetz@6512 565 // (Enhanced Stack Trace).
goetz@6512 566 // The signal handler does not save the interpreter state into the frame.
goetz@6512 567 __ li(R0, 0);
goetz@6512 568 #ifdef ASSERT
goetz@6512 569 // Fill remaining slots with constants.
goetz@6512 570 __ load_const_optimized(R11_scratch1, 0x5afe);
goetz@6512 571 __ load_const_optimized(R12_scratch2, 0xdead);
goetz@6512 572 #endif
goetz@6512 573 // We have to initialize some frame slots for native calls (accessed by GC).
goetz@6512 574 if (native_call) {
goetz@6512 575 __ std(R26_monitor, _ijava_state_neg(monitors), R1_SP);
goetz@6512 576 __ std(R14_bcp, _ijava_state_neg(bcp), R1_SP);
goetz@6512 577 if (ProfileInterpreter) { __ std(R28_mdx, _ijava_state_neg(mdx), R1_SP); }
goetz@6512 578 }
goetz@6512 579 #ifdef ASSERT
goetz@6512 580 else {
goetz@6512 581 __ std(R12_scratch2, _ijava_state_neg(monitors), R1_SP);
goetz@6512 582 __ std(R12_scratch2, _ijava_state_neg(bcp), R1_SP);
goetz@6512 583 __ std(R12_scratch2, _ijava_state_neg(mdx), R1_SP);
goetz@6512 584 }
goetz@6512 585 __ std(R11_scratch1, _ijava_state_neg(ijava_reserved), R1_SP);
goetz@6512 586 __ std(R12_scratch2, _ijava_state_neg(esp), R1_SP);
goetz@6512 587 __ std(R12_scratch2, _ijava_state_neg(lresult), R1_SP);
goetz@6512 588 __ std(R12_scratch2, _ijava_state_neg(fresult), R1_SP);
goetz@6512 589 #endif
goetz@6512 590 __ subf(R12_scratch2, top_frame_size, R1_SP);
goetz@6512 591 __ std(R0, _ijava_state_neg(oop_tmp), R1_SP);
goetz@6512 592 __ std(R12_scratch2, _ijava_state_neg(top_frame_sp), R1_SP);
goetz@6512 593
goetz@6512 594 // Push top frame.
goetz@6512 595 __ push_frame(top_frame_size, R11_scratch1);
goetz@6512 596 }
goetz@6512 597
goetz@6512 598 // End of helpers
goetz@6512 599
goetz@6512 600 // ============================================================================
goetz@6512 601 // Various method entries
goetz@6512 602 //
goetz@6512 603
goetz@6512 604 // Empty method, generate a very fast return. We must skip this entry if
goetz@6512 605 // someone's debugging, indicated by the flag
goetz@6512 606 // "interp_mode" in the Thread obj.
goetz@6512 607 // Note: empty methods are generated mostly methods that do assertions, which are
goetz@6512 608 // disabled in the "java opt build".
goetz@6512 609 address TemplateInterpreterGenerator::generate_empty_entry(void) {
goetz@6512 610 if (!UseFastEmptyMethods) {
goetz@6512 611 NOT_PRODUCT(__ should_not_reach_here();)
goetz@6512 612 return Interpreter::entry_for_kind(Interpreter::zerolocals);
goetz@6512 613 }
goetz@6512 614
goetz@6512 615 Label Lslow_path;
goetz@6512 616 const Register Rjvmti_mode = R11_scratch1;
goetz@6512 617 address entry = __ pc();
goetz@6512 618
goetz@6512 619 __ lwz(Rjvmti_mode, thread_(interp_only_mode));
goetz@6512 620 __ cmpwi(CCR0, Rjvmti_mode, 0);
goetz@6512 621 __ bne(CCR0, Lslow_path); // jvmti_mode!=0
goetz@6512 622
goetz@6512 623 // Noone's debuggin: Simply return.
goetz@6512 624 // Pop c2i arguments (if any) off when we return.
goetz@6512 625 #ifdef ASSERT
goetz@6512 626 __ ld(R9_ARG7, 0, R1_SP);
goetz@6512 627 __ ld(R10_ARG8, 0, R21_sender_SP);
goetz@6512 628 __ cmpd(CCR0, R9_ARG7, R10_ARG8);
goetz@6512 629 __ asm_assert_eq("backlink", 0x545);
goetz@6512 630 #endif // ASSERT
goetz@6512 631 __ mr(R1_SP, R21_sender_SP); // Cut the stack back to where the caller started.
goetz@6512 632
goetz@6512 633 // And we're done.
goetz@6512 634 __ blr();
goetz@6512 635
goetz@6512 636 __ bind(Lslow_path);
goetz@6512 637 __ branch_to_entry(Interpreter::entry_for_kind(Interpreter::zerolocals), R11_scratch1);
goetz@6512 638 __ flush();
goetz@6512 639
goetz@6512 640 return entry;
goetz@6512 641 }
goetz@6512 642
goetz@6512 643 // Support abs and sqrt like in compiler.
goetz@6512 644 // For others we can use a normal (native) entry.
goetz@6512 645
goetz@6512 646 inline bool math_entry_available(AbstractInterpreter::MethodKind kind) {
goetz@6512 647 // Provide math entry with debugging on demand.
goetz@6512 648 // Note: Debugging changes which code will get executed:
goetz@6512 649 // Debugging or disabled InlineIntrinsics: java method will get interpreted and performs a native call.
goetz@6512 650 // Not debugging and enabled InlineIntrinics: processor instruction will get used.
goetz@6512 651 // Result might differ slightly due to rounding etc.
goetz@6512 652 if (!InlineIntrinsics && (!FLAG_IS_ERGO(InlineIntrinsics))) return false; // Generate a vanilla entry.
goetz@6512 653
goetz@6512 654 return ((kind==Interpreter::java_lang_math_sqrt && VM_Version::has_fsqrt()) ||
goetz@6512 655 (kind==Interpreter::java_lang_math_abs));
goetz@6512 656 }
goetz@6512 657
goetz@6512 658 address TemplateInterpreterGenerator::generate_math_entry(AbstractInterpreter::MethodKind kind) {
goetz@6512 659 if (!math_entry_available(kind)) {
goetz@6512 660 NOT_PRODUCT(__ should_not_reach_here();)
goetz@6512 661 return Interpreter::entry_for_kind(Interpreter::zerolocals);
goetz@6512 662 }
goetz@6512 663
goetz@6512 664 Label Lslow_path;
goetz@6512 665 const Register Rjvmti_mode = R11_scratch1;
goetz@6512 666 address entry = __ pc();
goetz@6512 667
goetz@6512 668 // Provide math entry with debugging on demand.
goetz@6512 669 __ lwz(Rjvmti_mode, thread_(interp_only_mode));
goetz@6512 670 __ cmpwi(CCR0, Rjvmti_mode, 0);
goetz@6512 671 __ bne(CCR0, Lslow_path); // jvmti_mode!=0
goetz@6512 672
goetz@6512 673 __ lfd(F1_RET, Interpreter::stackElementSize, R15_esp);
goetz@6512 674
goetz@6512 675 // Pop c2i arguments (if any) off when we return.
goetz@6512 676 #ifdef ASSERT
goetz@6512 677 __ ld(R9_ARG7, 0, R1_SP);
goetz@6512 678 __ ld(R10_ARG8, 0, R21_sender_SP);
goetz@6512 679 __ cmpd(CCR0, R9_ARG7, R10_ARG8);
goetz@6512 680 __ asm_assert_eq("backlink", 0x545);
goetz@6512 681 #endif // ASSERT
goetz@6512 682 __ mr(R1_SP, R21_sender_SP); // Cut the stack back to where the caller started.
goetz@6512 683
goetz@6512 684 if (kind == Interpreter::java_lang_math_sqrt) {
goetz@6512 685 __ fsqrt(F1_RET, F1_RET);
goetz@6512 686 } else if (kind == Interpreter::java_lang_math_abs) {
goetz@6512 687 __ fabs(F1_RET, F1_RET);
goetz@6512 688 } else {
goetz@6512 689 ShouldNotReachHere();
goetz@6512 690 }
goetz@6512 691
goetz@6512 692 // And we're done.
goetz@6512 693 __ blr();
goetz@6512 694
goetz@6512 695 // Provide slow path for JVMTI case.
goetz@6512 696 __ bind(Lslow_path);
goetz@6512 697 __ branch_to_entry(Interpreter::entry_for_kind(Interpreter::zerolocals), R12_scratch2);
goetz@6512 698 __ flush();
goetz@6512 699
goetz@6512 700 return entry;
goetz@6512 701 }
goetz@6512 702
goetz@6512 703 // Interpreter stub for calling a native method. (asm interpreter)
goetz@6512 704 // This sets up a somewhat different looking stack for calling the
goetz@6512 705 // native method than the typical interpreter frame setup.
goetz@6512 706 //
goetz@6512 707 // On entry:
goetz@6512 708 // R19_method - method
goetz@6512 709 // R16_thread - JavaThread*
goetz@6512 710 // R15_esp - intptr_t* sender tos
goetz@6512 711 //
goetz@6512 712 // abstract stack (grows up)
goetz@6512 713 // [ IJava (caller of JNI callee) ] <-- ASP
goetz@6512 714 // ...
goetz@6512 715 address TemplateInterpreterGenerator::generate_native_entry(bool synchronized) {
goetz@6512 716
goetz@6512 717 address entry = __ pc();
goetz@6512 718
goetz@6512 719 const bool inc_counter = UseCompiler || CountCompiledCalls;
goetz@6512 720
goetz@6512 721 // -----------------------------------------------------------------------------
goetz@6512 722 // Allocate a new frame that represents the native callee (i2n frame).
goetz@6512 723 // This is not a full-blown interpreter frame, but in particular, the
goetz@6512 724 // following registers are valid after this:
goetz@6512 725 // - R19_method
goetz@6512 726 // - R18_local (points to start of argumuments to native function)
goetz@6512 727 //
goetz@6512 728 // abstract stack (grows up)
goetz@6512 729 // [ IJava (caller of JNI callee) ] <-- ASP
goetz@6512 730 // ...
goetz@6512 731
goetz@6512 732 const Register signature_handler_fd = R11_scratch1;
goetz@6512 733 const Register pending_exception = R0;
goetz@6512 734 const Register result_handler_addr = R31;
goetz@6512 735 const Register native_method_fd = R11_scratch1;
goetz@6512 736 const Register access_flags = R22_tmp2;
goetz@6512 737 const Register active_handles = R11_scratch1; // R26_monitor saved to state.
goetz@6512 738 const Register sync_state = R12_scratch2;
goetz@6512 739 const Register sync_state_addr = sync_state; // Address is dead after use.
goetz@6512 740 const Register suspend_flags = R11_scratch1;
goetz@6512 741
goetz@6512 742 //=============================================================================
goetz@6512 743 // Allocate new frame and initialize interpreter state.
goetz@6512 744
goetz@6512 745 Label exception_return;
goetz@6512 746 Label exception_return_sync_check;
goetz@6512 747 Label stack_overflow_return;
goetz@6512 748
goetz@6512 749 // Generate new interpreter state and jump to stack_overflow_return in case of
goetz@6512 750 // a stack overflow.
goetz@6512 751 //generate_compute_interpreter_state(stack_overflow_return);
goetz@6512 752
goetz@6512 753 Register size_of_parameters = R22_tmp2;
goetz@6512 754
goetz@6512 755 generate_fixed_frame(true, size_of_parameters, noreg /* unused */);
goetz@6512 756
goetz@6512 757 //=============================================================================
goetz@6512 758 // Increment invocation counter. On overflow, entry to JNI method
goetz@6512 759 // will be compiled.
goetz@6512 760 Label invocation_counter_overflow, continue_after_compile;
goetz@6512 761 if (inc_counter) {
goetz@6512 762 if (synchronized) {
goetz@6512 763 // Since at this point in the method invocation the exception handler
goetz@6512 764 // would try to exit the monitor of synchronized methods which hasn't
goetz@6512 765 // been entered yet, we set the thread local variable
goetz@6512 766 // _do_not_unlock_if_synchronized to true. If any exception was thrown by
goetz@6512 767 // runtime, exception handling i.e. unlock_if_synchronized_method will
goetz@6512 768 // check this thread local flag.
goetz@6512 769 // This flag has two effects, one is to force an unwind in the topmost
goetz@6512 770 // interpreter frame and not perform an unlock while doing so.
goetz@6512 771 __ li(R0, 1);
goetz@6512 772 __ stb(R0, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()), R16_thread);
goetz@6512 773 }
goetz@6512 774 generate_counter_incr(&invocation_counter_overflow, NULL, NULL);
goetz@6512 775
goetz@6512 776 __ BIND(continue_after_compile);
goetz@6512 777 // Reset the _do_not_unlock_if_synchronized flag.
goetz@6512 778 if (synchronized) {
goetz@6512 779 __ li(R0, 0);
goetz@6512 780 __ stb(R0, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()), R16_thread);
goetz@6512 781 }
goetz@6512 782 }
goetz@6512 783
goetz@6512 784 // access_flags = method->access_flags();
goetz@6512 785 // Load access flags.
goetz@6512 786 assert(access_flags->is_nonvolatile(),
goetz@6512 787 "access_flags must be in a non-volatile register");
goetz@6512 788 // Type check.
goetz@6512 789 assert(4 == sizeof(AccessFlags), "unexpected field size");
goetz@6512 790 __ lwz(access_flags, method_(access_flags));
goetz@6512 791
goetz@6512 792 // We don't want to reload R19_method and access_flags after calls
goetz@6512 793 // to some helper functions.
goetz@6512 794 assert(R19_method->is_nonvolatile(),
goetz@6512 795 "R19_method must be a non-volatile register");
goetz@6512 796
goetz@6512 797 // Check for synchronized methods. Must happen AFTER invocation counter
goetz@6512 798 // check, so method is not locked if counter overflows.
goetz@6512 799
goetz@6512 800 if (synchronized) {
goetz@6512 801 lock_method(access_flags, R11_scratch1, R12_scratch2, true);
goetz@6512 802
goetz@6512 803 // Update monitor in state.
goetz@6512 804 __ ld(R11_scratch1, 0, R1_SP);
goetz@6512 805 __ std(R26_monitor, _ijava_state_neg(monitors), R11_scratch1);
goetz@6512 806 }
goetz@6512 807
goetz@6512 808 // jvmti/jvmpi support
goetz@6512 809 __ notify_method_entry();
goetz@6512 810
goetz@6512 811 //=============================================================================
goetz@6512 812 // Get and call the signature handler.
goetz@6512 813
goetz@6512 814 __ ld(signature_handler_fd, method_(signature_handler));
goetz@6512 815 Label call_signature_handler;
goetz@6512 816
goetz@6512 817 __ cmpdi(CCR0, signature_handler_fd, 0);
goetz@6512 818 __ bne(CCR0, call_signature_handler);
goetz@6512 819
goetz@6512 820 // Method has never been called. Either generate a specialized
goetz@6512 821 // handler or point to the slow one.
goetz@6512 822 //
goetz@6512 823 // Pass parameter 'false' to avoid exception check in call_VM.
goetz@6512 824 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::prepare_native_call), R19_method, false);
goetz@6512 825
goetz@6512 826 // Check for an exception while looking up the target method. If we
goetz@6512 827 // incurred one, bail.
goetz@6512 828 __ ld(pending_exception, thread_(pending_exception));
goetz@6512 829 __ cmpdi(CCR0, pending_exception, 0);
goetz@6512 830 __ bne(CCR0, exception_return_sync_check); // Has pending exception.
goetz@6512 831
goetz@6512 832 // Reload signature handler, it may have been created/assigned in the meanwhile.
goetz@6512 833 __ ld(signature_handler_fd, method_(signature_handler));
goetz@6512 834 __ twi_0(signature_handler_fd); // Order wrt. load of klass mirror and entry point (isync is below).
goetz@6512 835
goetz@6512 836 __ BIND(call_signature_handler);
goetz@6512 837
goetz@6512 838 // Before we call the signature handler we push a new frame to
goetz@6512 839 // protect the interpreter frame volatile registers when we return
goetz@6512 840 // from jni but before we can get back to Java.
goetz@6512 841
goetz@6512 842 // First set the frame anchor while the SP/FP registers are
goetz@6512 843 // convenient and the slow signature handler can use this same frame
goetz@6512 844 // anchor.
goetz@6512 845
goetz@6512 846 // We have a TOP_IJAVA_FRAME here, which belongs to us.
goetz@6512 847 __ set_top_ijava_frame_at_SP_as_last_Java_frame(R1_SP, R12_scratch2/*tmp*/);
goetz@6512 848
goetz@6512 849 // Now the interpreter frame (and its call chain) have been
goetz@6512 850 // invalidated and flushed. We are now protected against eager
goetz@6512 851 // being enabled in native code. Even if it goes eager the
goetz@6512 852 // registers will be reloaded as clean and we will invalidate after
goetz@6512 853 // the call so no spurious flush should be possible.
goetz@6512 854
goetz@6512 855 // Call signature handler and pass locals address.
goetz@6512 856 //
goetz@6512 857 // Our signature handlers copy required arguments to the C stack
goetz@6512 858 // (outgoing C args), R3_ARG1 to R10_ARG8, and FARG1 to FARG13.
goetz@6512 859 __ mr(R3_ARG1, R18_locals);
goetz@6512 860 __ ld(signature_handler_fd, 0, signature_handler_fd);
goetz@6512 861
goetz@6512 862 __ call_stub(signature_handler_fd);
goetz@6512 863
goetz@6512 864 // Remove the register parameter varargs slots we allocated in
goetz@6512 865 // compute_interpreter_state. SP+16 ends up pointing to the ABI
goetz@6512 866 // outgoing argument area.
goetz@6512 867 //
goetz@6512 868 // Not needed on PPC64.
goetz@6512 869 //__ add(SP, SP, Argument::n_register_parameters*BytesPerWord);
goetz@6512 870
goetz@6512 871 assert(result_handler_addr->is_nonvolatile(), "result_handler_addr must be in a non-volatile register");
goetz@6512 872 // Save across call to native method.
goetz@6512 873 __ mr(result_handler_addr, R3_RET);
goetz@6512 874
goetz@6512 875 __ isync(); // Acquire signature handler before trying to fetch the native entry point and klass mirror.
goetz@6512 876
goetz@6512 877 // Set up fixed parameters and call the native method.
goetz@6512 878 // If the method is static, get mirror into R4_ARG2.
goetz@6512 879 {
goetz@6512 880 Label method_is_not_static;
goetz@6512 881 // Access_flags is non-volatile and still, no need to restore it.
goetz@6512 882
goetz@6512 883 // Restore access flags.
goetz@6512 884 __ testbitdi(CCR0, R0, access_flags, JVM_ACC_STATIC_BIT);
goetz@6512 885 __ bfalse(CCR0, method_is_not_static);
goetz@6512 886
goetz@6512 887 // constants = method->constants();
goetz@6512 888 __ ld(R11_scratch1, in_bytes(Method::const_offset()), R19_method);
goetz@6512 889 __ ld(R11_scratch1, in_bytes(ConstMethod::constants_offset()), R11_scratch1);
goetz@6512 890 // pool_holder = method->constants()->pool_holder();
goetz@6512 891 __ ld(R11_scratch1/*pool_holder*/, ConstantPool::pool_holder_offset_in_bytes(),
goetz@6512 892 R11_scratch1/*constants*/);
goetz@6512 893
goetz@6512 894 const int mirror_offset = in_bytes(Klass::java_mirror_offset());
goetz@6512 895
goetz@6512 896 // mirror = pool_holder->klass_part()->java_mirror();
goetz@6512 897 __ ld(R0/*mirror*/, mirror_offset, R11_scratch1/*pool_holder*/);
goetz@6512 898 // state->_native_mirror = mirror;
goetz@6512 899
goetz@6512 900 __ ld(R11_scratch1, 0, R1_SP);
goetz@6512 901 __ std(R0/*mirror*/, _ijava_state_neg(oop_tmp), R11_scratch1);
goetz@6512 902 // R4_ARG2 = &state->_oop_temp;
goetz@6512 903 __ addi(R4_ARG2, R11_scratch1, _ijava_state_neg(oop_tmp));
goetz@6512 904 __ BIND(method_is_not_static);
goetz@6512 905 }
goetz@6512 906
goetz@6512 907 // At this point, arguments have been copied off the stack into
goetz@6512 908 // their JNI positions. Oops are boxed in-place on the stack, with
goetz@6512 909 // handles copied to arguments. The result handler address is in a
goetz@6512 910 // register.
goetz@6512 911
goetz@6512 912 // Pass JNIEnv address as first parameter.
goetz@6512 913 __ addir(R3_ARG1, thread_(jni_environment));
goetz@6512 914
goetz@6512 915 // Load the native_method entry before we change the thread state.
goetz@6512 916 __ ld(native_method_fd, method_(native_function));
goetz@6512 917
goetz@6512 918 //=============================================================================
goetz@6512 919 // Transition from _thread_in_Java to _thread_in_native. As soon as
goetz@6512 920 // we make this change the safepoint code needs to be certain that
goetz@6512 921 // the last Java frame we established is good. The pc in that frame
goetz@6512 922 // just needs to be near here not an actual return address.
goetz@6512 923
goetz@6512 924 // We use release_store_fence to update values like the thread state, where
goetz@6512 925 // we don't want the current thread to continue until all our prior memory
goetz@6512 926 // accesses (including the new thread state) are visible to other threads.
goetz@6512 927 __ li(R0, _thread_in_native);
goetz@6512 928 __ release();
goetz@6512 929
goetz@6512 930 // TODO PPC port assert(4 == JavaThread::sz_thread_state(), "unexpected field size");
goetz@6512 931 __ stw(R0, thread_(thread_state));
goetz@6512 932
goetz@6512 933 if (UseMembar) {
goetz@6512 934 __ fence();
goetz@6512 935 }
goetz@6512 936
goetz@6512 937 //=============================================================================
goetz@6512 938 // Call the native method. Argument registers must not have been
goetz@6512 939 // overwritten since "__ call_stub(signature_handler);" (except for
goetz@6512 940 // ARG1 and ARG2 for static methods).
goetz@6512 941 __ call_c(native_method_fd);
goetz@6512 942
goetz@6512 943 __ li(R0, 0);
goetz@6512 944 __ ld(R11_scratch1, 0, R1_SP);
goetz@6512 945 __ std(R3_RET, _ijava_state_neg(lresult), R11_scratch1);
goetz@6512 946 __ stfd(F1_RET, _ijava_state_neg(fresult), R11_scratch1);
goetz@6512 947 __ std(R0/*mirror*/, _ijava_state_neg(oop_tmp), R11_scratch1); // reset
goetz@6512 948
goetz@6512 949 // Note: C++ interpreter needs the following here:
goetz@6512 950 // The frame_manager_lr field, which we use for setting the last
goetz@6512 951 // java frame, gets overwritten by the signature handler. Restore
goetz@6512 952 // it now.
goetz@6512 953 //__ get_PC_trash_LR(R11_scratch1);
goetz@6512 954 //__ std(R11_scratch1, _top_ijava_frame_abi(frame_manager_lr), R1_SP);
goetz@6512 955
goetz@6512 956 // Because of GC R19_method may no longer be valid.
goetz@6512 957
goetz@6512 958 // Block, if necessary, before resuming in _thread_in_Java state.
goetz@6512 959 // In order for GC to work, don't clear the last_Java_sp until after
goetz@6512 960 // blocking.
goetz@6512 961
goetz@6512 962 //=============================================================================
goetz@6512 963 // Switch thread to "native transition" state before reading the
goetz@6512 964 // synchronization state. This additional state is necessary
goetz@6512 965 // because reading and testing the synchronization state is not
goetz@6512 966 // atomic w.r.t. GC, as this scenario demonstrates: Java thread A,
goetz@6512 967 // in _thread_in_native state, loads _not_synchronized and is
goetz@6512 968 // preempted. VM thread changes sync state to synchronizing and
goetz@6512 969 // suspends threads for GC. Thread A is resumed to finish this
goetz@6512 970 // native method, but doesn't block here since it didn't see any
goetz@6512 971 // synchronization in progress, and escapes.
goetz@6512 972
goetz@6512 973 // We use release_store_fence to update values like the thread state, where
goetz@6512 974 // we don't want the current thread to continue until all our prior memory
goetz@6512 975 // accesses (including the new thread state) are visible to other threads.
goetz@6512 976 __ li(R0/*thread_state*/, _thread_in_native_trans);
goetz@6512 977 __ release();
goetz@6512 978 __ stw(R0/*thread_state*/, thread_(thread_state));
goetz@6512 979 if (UseMembar) {
goetz@6512 980 __ fence();
goetz@6512 981 }
goetz@6512 982 // Write serialization page so that the VM thread can do a pseudo remote
goetz@6512 983 // membar. We use the current thread pointer to calculate a thread
goetz@6512 984 // specific offset to write to within the page. This minimizes bus
goetz@6512 985 // traffic due to cache line collision.
goetz@6512 986 else {
goetz@6512 987 __ serialize_memory(R16_thread, R11_scratch1, R12_scratch2);
goetz@6512 988 }
goetz@6512 989
goetz@6512 990 // Now before we return to java we must look for a current safepoint
goetz@6512 991 // (a new safepoint can not start since we entered native_trans).
goetz@6512 992 // We must check here because a current safepoint could be modifying
goetz@6512 993 // the callers registers right this moment.
goetz@6512 994
goetz@6512 995 // Acquire isn't strictly necessary here because of the fence, but
goetz@6512 996 // sync_state is declared to be volatile, so we do it anyway
goetz@6512 997 // (cmp-br-isync on one path, release (same as acquire on PPC64) on the other path).
goetz@6512 998 int sync_state_offs = __ load_const_optimized(sync_state_addr, SafepointSynchronize::address_of_state(), /*temp*/R0, true);
goetz@6512 999
goetz@6512 1000 // TODO PPC port assert(4 == SafepointSynchronize::sz_state(), "unexpected field size");
goetz@6512 1001 __ lwz(sync_state, sync_state_offs, sync_state_addr);
goetz@6512 1002
goetz@6512 1003 // TODO PPC port assert(4 == Thread::sz_suspend_flags(), "unexpected field size");
goetz@6512 1004 __ lwz(suspend_flags, thread_(suspend_flags));
goetz@6512 1005
goetz@6512 1006 Label sync_check_done;
goetz@6512 1007 Label do_safepoint;
goetz@6512 1008 // No synchronization in progress nor yet synchronized.
goetz@6512 1009 __ cmpwi(CCR0, sync_state, SafepointSynchronize::_not_synchronized);
goetz@6512 1010 // Not suspended.
goetz@6512 1011 __ cmpwi(CCR1, suspend_flags, 0);
goetz@6512 1012
goetz@6512 1013 __ bne(CCR0, do_safepoint);
goetz@6512 1014 __ beq(CCR1, sync_check_done);
goetz@6512 1015 __ bind(do_safepoint);
goetz@6512 1016 __ isync();
goetz@6512 1017 // Block. We do the call directly and leave the current
goetz@6512 1018 // last_Java_frame setup undisturbed. We must save any possible
goetz@6512 1019 // native result across the call. No oop is present.
goetz@6512 1020
goetz@6512 1021 __ mr(R3_ARG1, R16_thread);
goetz@6512 1022 __ call_c(CAST_FROM_FN_PTR(FunctionDescriptor*, JavaThread::check_special_condition_for_native_trans),
goetz@6512 1023 relocInfo::none);
goetz@6512 1024
goetz@6512 1025 __ bind(sync_check_done);
goetz@6512 1026
goetz@6512 1027 //=============================================================================
goetz@6512 1028 // <<<<<< Back in Interpreter Frame >>>>>
goetz@6512 1029
goetz@6512 1030 // We are in thread_in_native_trans here and back in the normal
goetz@6512 1031 // interpreter frame. We don't have to do anything special about
goetz@6512 1032 // safepoints and we can switch to Java mode anytime we are ready.
goetz@6512 1033
goetz@6512 1034 // Note: frame::interpreter_frame_result has a dependency on how the
goetz@6512 1035 // method result is saved across the call to post_method_exit. For
goetz@6512 1036 // native methods it assumes that the non-FPU/non-void result is
goetz@6512 1037 // saved in _native_lresult and a FPU result in _native_fresult. If
goetz@6512 1038 // this changes then the interpreter_frame_result implementation
goetz@6512 1039 // will need to be updated too.
goetz@6512 1040
goetz@6512 1041 // On PPC64, we have stored the result directly after the native call.
goetz@6512 1042
goetz@6512 1043 //=============================================================================
goetz@6512 1044 // Back in Java
goetz@6512 1045
goetz@6512 1046 // We use release_store_fence to update values like the thread state, where
goetz@6512 1047 // we don't want the current thread to continue until all our prior memory
goetz@6512 1048 // accesses (including the new thread state) are visible to other threads.
goetz@6512 1049 __ li(R0/*thread_state*/, _thread_in_Java);
goetz@6512 1050 __ release();
goetz@6512 1051 __ stw(R0/*thread_state*/, thread_(thread_state));
goetz@6512 1052 if (UseMembar) {
goetz@6512 1053 __ fence();
goetz@6512 1054 }
goetz@6512 1055
goetz@6512 1056 __ reset_last_Java_frame();
goetz@6512 1057
goetz@6512 1058 // Jvmdi/jvmpi support. Whether we've got an exception pending or
goetz@6512 1059 // not, and whether unlocking throws an exception or not, we notify
goetz@6512 1060 // on native method exit. If we do have an exception, we'll end up
goetz@6512 1061 // in the caller's context to handle it, so if we don't do the
goetz@6512 1062 // notify here, we'll drop it on the floor.
goetz@6512 1063 __ notify_method_exit(true/*native method*/,
goetz@6512 1064 ilgl /*illegal state (not used for native methods)*/,
goetz@6512 1065 InterpreterMacroAssembler::NotifyJVMTI,
goetz@6512 1066 false /*check_exceptions*/);
goetz@6512 1067
goetz@6512 1068 //=============================================================================
goetz@6512 1069 // Handle exceptions
goetz@6512 1070
goetz@6512 1071 if (synchronized) {
goetz@6512 1072 // Don't check for exceptions since we're still in the i2n frame. Do that
goetz@6512 1073 // manually afterwards.
goetz@6512 1074 unlock_method(false);
goetz@6512 1075 }
goetz@6512 1076
goetz@6512 1077 // Reset active handles after returning from native.
goetz@6512 1078 // thread->active_handles()->clear();
goetz@6512 1079 __ ld(active_handles, thread_(active_handles));
goetz@6512 1080 // TODO PPC port assert(4 == JNIHandleBlock::top_size_in_bytes(), "unexpected field size");
goetz@6512 1081 __ li(R0, 0);
goetz@6512 1082 __ stw(R0, JNIHandleBlock::top_offset_in_bytes(), active_handles);
goetz@6512 1083
goetz@6512 1084 Label exception_return_sync_check_already_unlocked;
goetz@6512 1085 __ ld(R0/*pending_exception*/, thread_(pending_exception));
goetz@6512 1086 __ cmpdi(CCR0, R0/*pending_exception*/, 0);
goetz@6512 1087 __ bne(CCR0, exception_return_sync_check_already_unlocked);
goetz@6512 1088
goetz@6512 1089 //-----------------------------------------------------------------------------
goetz@6512 1090 // No exception pending.
goetz@6512 1091
goetz@6512 1092 // Move native method result back into proper registers and return.
goetz@6512 1093 // Invoke result handler (may unbox/promote).
goetz@6512 1094 __ ld(R11_scratch1, 0, R1_SP);
goetz@6512 1095 __ ld(R3_RET, _ijava_state_neg(lresult), R11_scratch1);
goetz@6512 1096 __ lfd(F1_RET, _ijava_state_neg(fresult), R11_scratch1);
goetz@6512 1097 __ call_stub(result_handler_addr);
goetz@6512 1098
goetz@6512 1099 __ merge_frames(/*top_frame_sp*/ R21_sender_SP, /*return_pc*/ R0, R11_scratch1, R12_scratch2);
goetz@6512 1100
goetz@6512 1101 // Must use the return pc which was loaded from the caller's frame
goetz@6512 1102 // as the VM uses return-pc-patching for deoptimization.
goetz@6512 1103 __ mtlr(R0);
goetz@6512 1104 __ blr();
goetz@6512 1105
goetz@6512 1106 //-----------------------------------------------------------------------------
goetz@6512 1107 // An exception is pending. We call into the runtime only if the
goetz@6512 1108 // caller was not interpreted. If it was interpreted the
goetz@6512 1109 // interpreter will do the correct thing. If it isn't interpreted
goetz@6512 1110 // (call stub/compiled code) we will change our return and continue.
goetz@6512 1111
goetz@6512 1112 __ BIND(exception_return_sync_check);
goetz@6512 1113
goetz@6512 1114 if (synchronized) {
goetz@6512 1115 // Don't check for exceptions since we're still in the i2n frame. Do that
goetz@6512 1116 // manually afterwards.
goetz@6512 1117 unlock_method(false);
goetz@6512 1118 }
goetz@6512 1119 __ BIND(exception_return_sync_check_already_unlocked);
goetz@6512 1120
goetz@6512 1121 const Register return_pc = R31;
goetz@6512 1122
goetz@6512 1123 __ ld(return_pc, 0, R1_SP);
goetz@6512 1124 __ ld(return_pc, _abi(lr), return_pc);
goetz@6512 1125
goetz@6512 1126 // Get the address of the exception handler.
goetz@6512 1127 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::exception_handler_for_return_address),
goetz@6512 1128 R16_thread,
goetz@6512 1129 return_pc /* return pc */);
goetz@6512 1130 __ merge_frames(/*top_frame_sp*/ R21_sender_SP, noreg, R11_scratch1, R12_scratch2);
goetz@6512 1131
goetz@6512 1132 // Load the PC of the the exception handler into LR.
goetz@6512 1133 __ mtlr(R3_RET);
goetz@6512 1134
goetz@6512 1135 // Load exception into R3_ARG1 and clear pending exception in thread.
goetz@6512 1136 __ ld(R3_ARG1/*exception*/, thread_(pending_exception));
goetz@6512 1137 __ li(R4_ARG2, 0);
goetz@6512 1138 __ std(R4_ARG2, thread_(pending_exception));
goetz@6512 1139
goetz@6512 1140 // Load the original return pc into R4_ARG2.
goetz@6512 1141 __ mr(R4_ARG2/*issuing_pc*/, return_pc);
goetz@6512 1142
goetz@6512 1143 // Return to exception handler.
goetz@6512 1144 __ blr();
goetz@6512 1145
goetz@6512 1146 //=============================================================================
goetz@6512 1147 // Counter overflow.
goetz@6512 1148
goetz@6512 1149 if (inc_counter) {
goetz@6512 1150 // Handle invocation counter overflow.
goetz@6512 1151 __ bind(invocation_counter_overflow);
goetz@6512 1152
goetz@6512 1153 generate_counter_overflow(continue_after_compile);
goetz@6512 1154 }
goetz@6512 1155
goetz@6512 1156 return entry;
goetz@6512 1157 }
goetz@6512 1158
goetz@6512 1159 // Generic interpreted method entry to (asm) interpreter.
goetz@6512 1160 //
goetz@6512 1161 address TemplateInterpreterGenerator::generate_normal_entry(bool synchronized) {
goetz@6512 1162 bool inc_counter = UseCompiler || CountCompiledCalls;
goetz@6512 1163 address entry = __ pc();
goetz@6512 1164 // Generate the code to allocate the interpreter stack frame.
goetz@6512 1165 Register Rsize_of_parameters = R4_ARG2, // Written by generate_fixed_frame.
goetz@6512 1166 Rsize_of_locals = R5_ARG3; // Written by generate_fixed_frame.
goetz@6512 1167
goetz@6512 1168 generate_fixed_frame(false, Rsize_of_parameters, Rsize_of_locals);
goetz@6512 1169
goetz@6512 1170 #ifdef FAST_DISPATCH
goetz@6512 1171 __ unimplemented("Fast dispatch in generate_normal_entry");
goetz@6512 1172 #if 0
goetz@6512 1173 __ set((intptr_t)Interpreter::dispatch_table(), IdispatchTables);
goetz@6512 1174 // Set bytecode dispatch table base.
goetz@6512 1175 #endif
goetz@6512 1176 #endif
goetz@6512 1177
goetz@6512 1178 // --------------------------------------------------------------------------
goetz@6512 1179 // Zero out non-parameter locals.
goetz@6512 1180 // Note: *Always* zero out non-parameter locals as Sparc does. It's not
goetz@6512 1181 // worth to ask the flag, just do it.
goetz@6512 1182 Register Rslot_addr = R6_ARG4,
goetz@6512 1183 Rnum = R7_ARG5;
goetz@6512 1184 Label Lno_locals, Lzero_loop;
goetz@6512 1185
goetz@6512 1186 // Set up the zeroing loop.
goetz@6512 1187 __ subf(Rnum, Rsize_of_parameters, Rsize_of_locals);
goetz@6512 1188 __ subf(Rslot_addr, Rsize_of_parameters, R18_locals);
goetz@6512 1189 __ srdi_(Rnum, Rnum, Interpreter::logStackElementSize);
goetz@6512 1190 __ beq(CCR0, Lno_locals);
goetz@6512 1191 __ li(R0, 0);
goetz@6512 1192 __ mtctr(Rnum);
goetz@6512 1193
goetz@6512 1194 // The zero locals loop.
goetz@6512 1195 __ bind(Lzero_loop);
goetz@6512 1196 __ std(R0, 0, Rslot_addr);
goetz@6512 1197 __ addi(Rslot_addr, Rslot_addr, -Interpreter::stackElementSize);
goetz@6512 1198 __ bdnz(Lzero_loop);
goetz@6512 1199
goetz@6512 1200 __ bind(Lno_locals);
goetz@6512 1201
goetz@6512 1202 // --------------------------------------------------------------------------
goetz@6512 1203 // Counter increment and overflow check.
goetz@6512 1204 Label invocation_counter_overflow,
goetz@6512 1205 profile_method,
goetz@6512 1206 profile_method_continue;
goetz@6512 1207 if (inc_counter || ProfileInterpreter) {
goetz@6512 1208
goetz@6512 1209 Register Rdo_not_unlock_if_synchronized_addr = R11_scratch1;
goetz@6512 1210 if (synchronized) {
goetz@6512 1211 // Since at this point in the method invocation the exception handler
goetz@6512 1212 // would try to exit the monitor of synchronized methods which hasn't
goetz@6512 1213 // been entered yet, we set the thread local variable
goetz@6512 1214 // _do_not_unlock_if_synchronized to true. If any exception was thrown by
goetz@6512 1215 // runtime, exception handling i.e. unlock_if_synchronized_method will
goetz@6512 1216 // check this thread local flag.
goetz@6512 1217 // This flag has two effects, one is to force an unwind in the topmost
goetz@6512 1218 // interpreter frame and not perform an unlock while doing so.
goetz@6512 1219 __ li(R0, 1);
goetz@6512 1220 __ stb(R0, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()), R16_thread);
goetz@6512 1221 }
goetz@6512 1222 // Increment invocation counter and check for overflow.
goetz@6512 1223 if (inc_counter) {
goetz@6512 1224 generate_counter_incr(&invocation_counter_overflow, &profile_method, &profile_method_continue);
goetz@6512 1225 }
goetz@6512 1226
goetz@6512 1227 __ bind(profile_method_continue);
goetz@6512 1228
goetz@6512 1229 // Reset the _do_not_unlock_if_synchronized flag.
goetz@6512 1230 if (synchronized) {
goetz@6512 1231 __ li(R0, 0);
goetz@6512 1232 __ stb(R0, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()), R16_thread);
goetz@6512 1233 }
goetz@6512 1234 }
goetz@6512 1235
goetz@6512 1236 // --------------------------------------------------------------------------
goetz@6512 1237 // Locking of synchronized methods. Must happen AFTER invocation_counter
goetz@6512 1238 // check and stack overflow check, so method is not locked if overflows.
goetz@6512 1239 if (synchronized) {
goetz@6512 1240 lock_method(R3_ARG1, R4_ARG2, R5_ARG3);
goetz@6512 1241 }
goetz@6512 1242 #ifdef ASSERT
goetz@6512 1243 else {
goetz@6512 1244 Label Lok;
goetz@6512 1245 __ lwz(R0, in_bytes(Method::access_flags_offset()), R19_method);
goetz@6512 1246 __ andi_(R0, R0, JVM_ACC_SYNCHRONIZED);
goetz@6512 1247 __ asm_assert_eq("method needs synchronization", 0x8521);
goetz@6512 1248 __ bind(Lok);
goetz@6512 1249 }
goetz@6512 1250 #endif // ASSERT
goetz@6512 1251
goetz@6512 1252 __ verify_thread();
goetz@6512 1253
goetz@6512 1254 // --------------------------------------------------------------------------
goetz@6512 1255 // JVMTI support
goetz@6512 1256 __ notify_method_entry();
goetz@6512 1257
goetz@6512 1258 // --------------------------------------------------------------------------
goetz@6512 1259 // Start executing instructions.
goetz@6512 1260 __ dispatch_next(vtos);
goetz@6512 1261
goetz@6512 1262 // --------------------------------------------------------------------------
goetz@6512 1263 // Out of line counter overflow and MDO creation code.
goetz@6512 1264 if (ProfileInterpreter) {
goetz@6512 1265 // We have decided to profile this method in the interpreter.
goetz@6512 1266 __ bind(profile_method);
goetz@6512 1267 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::profile_method));
goetz@6512 1268 __ set_method_data_pointer_for_bcp();
goetz@6512 1269 __ b(profile_method_continue);
goetz@6512 1270 }
goetz@6512 1271
goetz@6512 1272 if (inc_counter) {
goetz@6512 1273 // Handle invocation counter overflow.
goetz@6512 1274 __ bind(invocation_counter_overflow);
goetz@6512 1275 generate_counter_overflow(profile_method_continue);
goetz@6512 1276 }
goetz@6512 1277 return entry;
goetz@6512 1278 }
goetz@6512 1279
goetz@6512 1280 // =============================================================================
goetz@6512 1281 // Entry points
goetz@6512 1282
goetz@6512 1283 address AbstractInterpreterGenerator::generate_method_entry(
goetz@6512 1284 AbstractInterpreter::MethodKind kind) {
goetz@6512 1285 // Determine code generation flags.
goetz@6512 1286 bool synchronized = false;
goetz@6512 1287 address entry_point = NULL;
goetz@6512 1288
goetz@6512 1289 switch (kind) {
goetz@6512 1290 case Interpreter::zerolocals : break;
goetz@6512 1291 case Interpreter::zerolocals_synchronized: synchronized = true; break;
goetz@6512 1292 case Interpreter::native : entry_point = ((InterpreterGenerator*) this)->generate_native_entry(false); break;
goetz@6512 1293 case Interpreter::native_synchronized : entry_point = ((InterpreterGenerator*) this)->generate_native_entry(true); break;
goetz@6512 1294 case Interpreter::empty : entry_point = ((InterpreterGenerator*) this)->generate_empty_entry(); break;
goetz@6512 1295 case Interpreter::accessor : entry_point = ((InterpreterGenerator*) this)->generate_accessor_entry(); break;
goetz@6512 1296 case Interpreter::abstract : entry_point = ((InterpreterGenerator*) this)->generate_abstract_entry(); break;
goetz@6512 1297
goetz@6512 1298 case Interpreter::java_lang_math_sin : // fall thru
goetz@6512 1299 case Interpreter::java_lang_math_cos : // fall thru
goetz@6512 1300 case Interpreter::java_lang_math_tan : // fall thru
goetz@6512 1301 case Interpreter::java_lang_math_abs : // fall thru
goetz@6512 1302 case Interpreter::java_lang_math_log : // fall thru
goetz@6512 1303 case Interpreter::java_lang_math_log10 : // fall thru
goetz@6512 1304 case Interpreter::java_lang_math_sqrt : // fall thru
goetz@6512 1305 case Interpreter::java_lang_math_pow : // fall thru
goetz@6512 1306 case Interpreter::java_lang_math_exp : entry_point = ((InterpreterGenerator*) this)->generate_math_entry(kind); break;
goetz@6512 1307 case Interpreter::java_lang_ref_reference_get
goetz@6512 1308 : entry_point = ((InterpreterGenerator*)this)->generate_Reference_get_entry(); break;
goetz@6512 1309 default : ShouldNotReachHere(); break;
goetz@6512 1310 }
goetz@6512 1311
goetz@6512 1312 if (entry_point) {
goetz@6512 1313 return entry_point;
goetz@6512 1314 }
goetz@6512 1315
goetz@6512 1316 return ((InterpreterGenerator*) this)->generate_normal_entry(synchronized);
goetz@6512 1317 }
goetz@6512 1318
goetz@6512 1319 // These should never be compiled since the interpreter will prefer
goetz@6512 1320 // the compiled version to the intrinsic version.
goetz@6512 1321 bool AbstractInterpreter::can_be_compiled(methodHandle m) {
goetz@6512 1322 return !math_entry_available(method_kind(m));
goetz@6512 1323 }
goetz@6512 1324
goetz@6512 1325 // How much stack a method activation needs in stack slots.
goetz@6512 1326 // We must calc this exactly like in generate_fixed_frame.
goetz@6512 1327 // Note: This returns the conservative size assuming maximum alignment.
goetz@6512 1328 int AbstractInterpreter::size_top_interpreter_activation(Method* method) {
goetz@6512 1329 const int max_alignment_size = 2;
goetz@6512 1330 const int abi_scratch = frame::abi_reg_args_size;
roland@6723 1331 return method->max_locals() + method->max_stack() +
roland@6723 1332 frame::interpreter_frame_monitor_size() + max_alignment_size + abi_scratch;
goetz@6512 1333 }
goetz@6512 1334
roland@6723 1335 // Returns number of stackElementWords needed for the interpreter frame with the
roland@6723 1336 // given sections.
roland@6723 1337 // This overestimates the stack by one slot in case of alignments.
roland@6723 1338 int AbstractInterpreter::size_activation(int max_stack,
roland@6723 1339 int temps,
roland@6723 1340 int extra_args,
roland@6723 1341 int monitors,
roland@6723 1342 int callee_params,
roland@6723 1343 int callee_locals,
roland@6723 1344 bool is_top_frame) {
roland@6723 1345 // Note: This calculation must exactly parallel the frame setup
roland@6723 1346 // in AbstractInterpreterGenerator::generate_method_entry.
roland@6723 1347 assert(Interpreter::stackElementWords == 1, "sanity");
roland@6723 1348 const int max_alignment_space = StackAlignmentInBytes / Interpreter::stackElementSize;
roland@6723 1349 const int abi_scratch = is_top_frame ? (frame::abi_reg_args_size / Interpreter::stackElementSize) :
roland@6723 1350 (frame::abi_minframe_size / Interpreter::stackElementSize);
roland@6723 1351 const int size =
roland@6723 1352 max_stack +
roland@6723 1353 (callee_locals - callee_params) +
roland@6723 1354 monitors * frame::interpreter_frame_monitor_size() +
roland@6723 1355 max_alignment_space +
roland@6723 1356 abi_scratch +
roland@6723 1357 frame::ijava_state_size / Interpreter::stackElementSize;
roland@6723 1358
roland@6723 1359 // Fixed size of an interpreter frame, align to 16-byte.
roland@6723 1360 return (size & -2);
roland@6723 1361 }
roland@6723 1362
roland@6723 1363 // Fills a sceletal interpreter frame generated during deoptimizations.
goetz@6512 1364 //
goetz@6512 1365 // Parameters:
goetz@6512 1366 //
goetz@6512 1367 // interpreter_frame != NULL:
goetz@6512 1368 // set up the method, locals, and monitors.
goetz@6512 1369 // The frame interpreter_frame, if not NULL, is guaranteed to be the
goetz@6512 1370 // right size, as determined by a previous call to this method.
goetz@6512 1371 // It is also guaranteed to be walkable even though it is in a skeletal state
goetz@6512 1372 //
goetz@6512 1373 // is_top_frame == true:
goetz@6512 1374 // We're processing the *oldest* interpreter frame!
goetz@6512 1375 //
goetz@6512 1376 // pop_frame_extra_args:
goetz@6512 1377 // If this is != 0 we are returning to a deoptimized frame by popping
goetz@6512 1378 // off the callee frame. We want to re-execute the call that called the
goetz@6512 1379 // callee interpreted, but since the return to the interpreter would pop
goetz@6512 1380 // the arguments off advance the esp by dummy popframe_extra_args slots.
goetz@6512 1381 // Popping off those will establish the stack layout as it was before the call.
goetz@6512 1382 //
roland@6723 1383 void AbstractInterpreter::layout_activation(Method* method,
roland@6723 1384 int tempcount,
roland@6723 1385 int popframe_extra_args,
roland@6723 1386 int moncount,
roland@6723 1387 int caller_actual_parameters,
roland@6723 1388 int callee_param_count,
roland@6723 1389 int callee_locals_count,
roland@6723 1390 frame* caller,
roland@6723 1391 frame* interpreter_frame,
roland@6723 1392 bool is_top_frame,
roland@6723 1393 bool is_bottom_frame) {
goetz@6512 1394
goetz@6512 1395 const int abi_scratch = is_top_frame ? (frame::abi_reg_args_size / Interpreter::stackElementSize) :
roland@6723 1396 (frame::abi_minframe_size / Interpreter::stackElementSize);
goetz@6512 1397
roland@6723 1398 intptr_t* locals_base = (caller->is_interpreted_frame()) ?
roland@6723 1399 caller->interpreter_frame_esp() + caller_actual_parameters :
roland@6723 1400 caller->sp() + method->max_locals() - 1 + (frame::abi_minframe_size / Interpreter::stackElementSize) ;
goetz@6512 1401
roland@6723 1402 intptr_t* monitor_base = caller->sp() - frame::ijava_state_size / Interpreter::stackElementSize ;
roland@6723 1403 intptr_t* monitor = monitor_base - (moncount * frame::interpreter_frame_monitor_size());
roland@6723 1404 intptr_t* esp_base = monitor - 1;
roland@6723 1405 intptr_t* esp = esp_base - tempcount - popframe_extra_args;
roland@6723 1406 intptr_t* sp = (intptr_t *) (((intptr_t) (esp_base - callee_locals_count + callee_param_count - method->max_stack()- abi_scratch)) & -StackAlignmentInBytes);
roland@6723 1407 intptr_t* sender_sp = caller->sp() + (frame::abi_minframe_size - frame::abi_reg_args_size) / Interpreter::stackElementSize;
roland@6723 1408 intptr_t* top_frame_sp = is_top_frame ? sp : sp + (frame::abi_minframe_size - frame::abi_reg_args_size) / Interpreter::stackElementSize;
goetz@6512 1409
roland@6723 1410 interpreter_frame->interpreter_frame_set_method(method);
roland@6723 1411 interpreter_frame->interpreter_frame_set_locals(locals_base);
roland@6723 1412 interpreter_frame->interpreter_frame_set_cpcache(method->constants()->cache());
roland@6723 1413 interpreter_frame->interpreter_frame_set_esp(esp);
roland@6723 1414 interpreter_frame->interpreter_frame_set_monitor_end((BasicObjectLock *)monitor);
roland@6723 1415 interpreter_frame->interpreter_frame_set_top_frame_sp(top_frame_sp);
roland@6723 1416 if (!is_bottom_frame) {
roland@6723 1417 interpreter_frame->interpreter_frame_set_sender_sp(sender_sp);
goetz@6512 1418 }
goetz@6512 1419 }
goetz@6512 1420
goetz@6512 1421 // =============================================================================
goetz@6512 1422 // Exceptions
goetz@6512 1423
goetz@6512 1424 void TemplateInterpreterGenerator::generate_throw_exception() {
goetz@6512 1425 Register Rexception = R17_tos,
goetz@6512 1426 Rcontinuation = R3_RET;
goetz@6512 1427
goetz@6512 1428 // --------------------------------------------------------------------------
goetz@6512 1429 // Entry point if an method returns with a pending exception (rethrow).
goetz@6512 1430 Interpreter::_rethrow_exception_entry = __ pc();
goetz@6512 1431 {
goetz@6512 1432 __ restore_interpreter_state(R11_scratch1); // Sets R11_scratch1 = fp.
goetz@6512 1433 __ ld(R12_scratch2, _ijava_state_neg(top_frame_sp), R11_scratch1);
goetz@6512 1434 __ resize_frame_absolute(R12_scratch2, R11_scratch1, R0);
goetz@6512 1435
goetz@6512 1436 // Compiled code destroys templateTableBase, reload.
goetz@6512 1437 __ load_const_optimized(R25_templateTableBase, (address)Interpreter::dispatch_table((TosState)0), R11_scratch1);
goetz@6512 1438 }
goetz@6512 1439
goetz@6512 1440 // Entry point if a interpreted method throws an exception (throw).
goetz@6512 1441 Interpreter::_throw_exception_entry = __ pc();
goetz@6512 1442 {
goetz@6512 1443 __ mr(Rexception, R3_RET);
goetz@6512 1444
goetz@6512 1445 __ verify_thread();
goetz@6512 1446 __ verify_oop(Rexception);
goetz@6512 1447
goetz@6512 1448 // Expression stack must be empty before entering the VM in case of an exception.
goetz@6512 1449 __ empty_expression_stack();
goetz@6512 1450 // Find exception handler address and preserve exception oop.
goetz@6512 1451 // Call C routine to find handler and jump to it.
goetz@6512 1452 __ call_VM(Rexception, CAST_FROM_FN_PTR(address, InterpreterRuntime::exception_handler_for_exception), Rexception);
goetz@6512 1453 __ mtctr(Rcontinuation);
goetz@6512 1454 // Push exception for exception handler bytecodes.
goetz@6512 1455 __ push_ptr(Rexception);
goetz@6512 1456
goetz@6512 1457 // Jump to exception handler (may be remove activation entry!).
goetz@6512 1458 __ bctr();
goetz@6512 1459 }
goetz@6512 1460
goetz@6512 1461 // If the exception is not handled in the current frame the frame is
goetz@6512 1462 // removed and the exception is rethrown (i.e. exception
goetz@6512 1463 // continuation is _rethrow_exception).
goetz@6512 1464 //
goetz@6512 1465 // Note: At this point the bci is still the bxi for the instruction
goetz@6512 1466 // which caused the exception and the expression stack is
goetz@6512 1467 // empty. Thus, for any VM calls at this point, GC will find a legal
goetz@6512 1468 // oop map (with empty expression stack).
goetz@6512 1469
goetz@6512 1470 // In current activation
goetz@6512 1471 // tos: exception
goetz@6512 1472 // bcp: exception bcp
goetz@6512 1473
goetz@6512 1474 // --------------------------------------------------------------------------
goetz@6512 1475 // JVMTI PopFrame support
goetz@6512 1476
goetz@6512 1477 Interpreter::_remove_activation_preserving_args_entry = __ pc();
goetz@6512 1478 {
goetz@6512 1479 // Set the popframe_processing bit in popframe_condition indicating that we are
goetz@6512 1480 // currently handling popframe, so that call_VMs that may happen later do not
goetz@6512 1481 // trigger new popframe handling cycles.
goetz@6512 1482 __ lwz(R11_scratch1, in_bytes(JavaThread::popframe_condition_offset()), R16_thread);
goetz@6512 1483 __ ori(R11_scratch1, R11_scratch1, JavaThread::popframe_processing_bit);
goetz@6512 1484 __ stw(R11_scratch1, in_bytes(JavaThread::popframe_condition_offset()), R16_thread);
goetz@6512 1485
goetz@6512 1486 // Empty the expression stack, as in normal exception handling.
goetz@6512 1487 __ empty_expression_stack();
goetz@6512 1488 __ unlock_if_synchronized_method(vtos, /* throw_monitor_exception */ false, /* install_monitor_exception */ false);
goetz@6512 1489
goetz@6512 1490 // Check to see whether we are returning to a deoptimized frame.
goetz@6512 1491 // (The PopFrame call ensures that the caller of the popped frame is
goetz@6512 1492 // either interpreted or compiled and deoptimizes it if compiled.)
goetz@6512 1493 // Note that we don't compare the return PC against the
goetz@6512 1494 // deoptimization blob's unpack entry because of the presence of
goetz@6512 1495 // adapter frames in C2.
goetz@6512 1496 Label Lcaller_not_deoptimized;
goetz@6512 1497 Register return_pc = R3_ARG1;
goetz@6512 1498 __ ld(return_pc, 0, R1_SP);
goetz@6512 1499 __ ld(return_pc, _abi(lr), return_pc);
goetz@6512 1500 __ call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::interpreter_contains), return_pc);
goetz@6512 1501 __ cmpdi(CCR0, R3_RET, 0);
goetz@6512 1502 __ bne(CCR0, Lcaller_not_deoptimized);
goetz@6512 1503
goetz@6512 1504 // The deoptimized case.
goetz@6512 1505 // In this case, we can't call dispatch_next() after the frame is
goetz@6512 1506 // popped, but instead must save the incoming arguments and restore
goetz@6512 1507 // them after deoptimization has occurred.
goetz@6512 1508 __ ld(R4_ARG2, in_bytes(Method::const_offset()), R19_method);
goetz@6512 1509 __ lhz(R4_ARG2 /* number of params */, in_bytes(ConstMethod::size_of_parameters_offset()), R4_ARG2);
goetz@6512 1510 __ slwi(R4_ARG2, R4_ARG2, Interpreter::logStackElementSize);
goetz@6512 1511 __ addi(R5_ARG3, R18_locals, Interpreter::stackElementSize);
goetz@6512 1512 __ subf(R5_ARG3, R4_ARG2, R5_ARG3);
goetz@6512 1513 // Save these arguments.
goetz@6512 1514 __ call_VM_leaf(CAST_FROM_FN_PTR(address, Deoptimization::popframe_preserve_args), R16_thread, R4_ARG2, R5_ARG3);
goetz@6512 1515
goetz@6512 1516 // Inform deoptimization that it is responsible for restoring these arguments.
goetz@6512 1517 __ load_const_optimized(R11_scratch1, JavaThread::popframe_force_deopt_reexecution_bit);
goetz@6512 1518 __ stw(R11_scratch1, in_bytes(JavaThread::popframe_condition_offset()), R16_thread);
goetz@6512 1519
goetz@6512 1520 // Return from the current method into the deoptimization blob. Will eventually
goetz@6512 1521 // end up in the deopt interpeter entry, deoptimization prepared everything that
goetz@6512 1522 // we will reexecute the call that called us.
goetz@6512 1523 __ merge_frames(/*top_frame_sp*/ R21_sender_SP, /*reload return_pc*/ return_pc, R11_scratch1, R12_scratch2);
goetz@6512 1524 __ mtlr(return_pc);
goetz@6512 1525 __ blr();
goetz@6512 1526
goetz@6512 1527 // The non-deoptimized case.
goetz@6512 1528 __ bind(Lcaller_not_deoptimized);
goetz@6512 1529
goetz@6512 1530 // Clear the popframe condition flag.
goetz@6512 1531 __ li(R0, 0);
goetz@6512 1532 __ stw(R0, in_bytes(JavaThread::popframe_condition_offset()), R16_thread);
goetz@6512 1533
goetz@6512 1534 // Get out of the current method and re-execute the call that called us.
goetz@6660 1535 __ merge_frames(/*top_frame_sp*/ R21_sender_SP, /*return_pc*/ noreg, R11_scratch1, R12_scratch2);
goetz@6512 1536 __ restore_interpreter_state(R11_scratch1);
goetz@6512 1537 __ ld(R12_scratch2, _ijava_state_neg(top_frame_sp), R11_scratch1);
goetz@6512 1538 __ resize_frame_absolute(R12_scratch2, R11_scratch1, R0);
goetz@6512 1539 if (ProfileInterpreter) {
goetz@6512 1540 __ set_method_data_pointer_for_bcp();
goetz@6512 1541 }
goetz@6660 1542 #if INCLUDE_JVMTI
goetz@6660 1543 Label L_done;
goetz@6660 1544
goetz@6660 1545 __ lbz(R11_scratch1, 0, R14_bcp);
goetz@6660 1546 __ cmpwi(CCR0, R11_scratch1, Bytecodes::_invokestatic);
goetz@6660 1547 __ bne(CCR0, L_done);
goetz@6660 1548
goetz@6660 1549 // The member name argument must be restored if _invokestatic is re-executed after a PopFrame call.
goetz@6660 1550 // Detect such a case in the InterpreterRuntime function and return the member name argument, or NULL.
goetz@6660 1551 __ ld(R4_ARG2, 0, R18_locals);
goetz@6660 1552 __ call_VM(R11_scratch1, CAST_FROM_FN_PTR(address, InterpreterRuntime::member_name_arg_or_null),
goetz@6660 1553 R4_ARG2, R19_method, R14_bcp);
goetz@6660 1554
goetz@6660 1555 __ cmpdi(CCR0, R11_scratch1, 0);
goetz@6660 1556 __ beq(CCR0, L_done);
goetz@6660 1557
goetz@6660 1558 __ std(R11_scratch1, wordSize, R15_esp);
goetz@6660 1559 __ bind(L_done);
goetz@6660 1560 #endif // INCLUDE_JVMTI
goetz@6512 1561 __ dispatch_next(vtos);
goetz@6512 1562 }
goetz@6512 1563 // end of JVMTI PopFrame support
goetz@6512 1564
goetz@6512 1565 // --------------------------------------------------------------------------
goetz@6512 1566 // Remove activation exception entry.
goetz@6512 1567 // This is jumped to if an interpreted method can't handle an exception itself
goetz@6512 1568 // (we come from the throw/rethrow exception entry above). We're going to call
goetz@6512 1569 // into the VM to find the exception handler in the caller, pop the current
goetz@6512 1570 // frame and return the handler we calculated.
goetz@6512 1571 Interpreter::_remove_activation_entry = __ pc();
goetz@6512 1572 {
goetz@6512 1573 __ pop_ptr(Rexception);
goetz@6512 1574 __ verify_thread();
goetz@6512 1575 __ verify_oop(Rexception);
goetz@6512 1576 __ std(Rexception, in_bytes(JavaThread::vm_result_offset()), R16_thread);
goetz@6512 1577
goetz@6512 1578 __ unlock_if_synchronized_method(vtos, /* throw_monitor_exception */ false, true);
goetz@6512 1579 __ notify_method_exit(false, vtos, InterpreterMacroAssembler::SkipNotifyJVMTI, false);
goetz@6512 1580
goetz@6512 1581 __ get_vm_result(Rexception);
goetz@6512 1582
goetz@6512 1583 // We are done with this activation frame; find out where to go next.
goetz@6512 1584 // The continuation point will be an exception handler, which expects
goetz@6512 1585 // the following registers set up:
goetz@6512 1586 //
goetz@6512 1587 // RET: exception oop
goetz@6512 1588 // ARG2: Issuing PC (see generate_exception_blob()), only used if the caller is compiled.
goetz@6512 1589
goetz@6512 1590 Register return_pc = R31; // Needs to survive the runtime call.
goetz@6512 1591 __ ld(return_pc, 0, R1_SP);
goetz@6512 1592 __ ld(return_pc, _abi(lr), return_pc);
goetz@6512 1593 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::exception_handler_for_return_address), R16_thread, return_pc);
goetz@6512 1594
goetz@6512 1595 // Remove the current activation.
goetz@6512 1596 __ merge_frames(/*top_frame_sp*/ R21_sender_SP, /*return_pc*/ noreg, R11_scratch1, R12_scratch2);
goetz@6512 1597
goetz@6512 1598 __ mr(R4_ARG2, return_pc);
goetz@6512 1599 __ mtlr(R3_RET);
goetz@6512 1600 __ mr(R3_RET, Rexception);
goetz@6512 1601 __ blr();
goetz@6512 1602 }
goetz@6512 1603 }
goetz@6512 1604
goetz@6512 1605 // JVMTI ForceEarlyReturn support.
goetz@6512 1606 // Returns "in the middle" of a method with a "fake" return value.
goetz@6512 1607 address TemplateInterpreterGenerator::generate_earlyret_entry_for(TosState state) {
goetz@6512 1608
goetz@6512 1609 Register Rscratch1 = R11_scratch1,
goetz@6512 1610 Rscratch2 = R12_scratch2;
goetz@6512 1611
goetz@6512 1612 address entry = __ pc();
goetz@6512 1613 __ empty_expression_stack();
goetz@6512 1614
goetz@6512 1615 __ load_earlyret_value(state, Rscratch1);
goetz@6512 1616
goetz@6512 1617 __ ld(Rscratch1, in_bytes(JavaThread::jvmti_thread_state_offset()), R16_thread);
goetz@6512 1618 // Clear the earlyret state.
goetz@6512 1619 __ li(R0, 0);
goetz@6512 1620 __ stw(R0, in_bytes(JvmtiThreadState::earlyret_state_offset()), Rscratch1);
goetz@6512 1621
goetz@6512 1622 __ remove_activation(state, false, false);
goetz@6512 1623 // Copied from TemplateTable::_return.
goetz@6512 1624 // Restoration of lr done by remove_activation.
goetz@6512 1625 switch (state) {
goetz@6512 1626 case ltos:
goetz@6512 1627 case btos:
goetz@6512 1628 case ctos:
goetz@6512 1629 case stos:
goetz@6512 1630 case atos:
goetz@6512 1631 case itos: __ mr(R3_RET, R17_tos); break;
goetz@6512 1632 case ftos:
goetz@6512 1633 case dtos: __ fmr(F1_RET, F15_ftos); break;
goetz@6512 1634 case vtos: // This might be a constructor. Final fields (and volatile fields on PPC64) need
goetz@6512 1635 // to get visible before the reference to the object gets stored anywhere.
goetz@6512 1636 __ membar(Assembler::StoreStore); break;
goetz@6512 1637 default : ShouldNotReachHere();
goetz@6512 1638 }
goetz@6512 1639 __ blr();
goetz@6512 1640
goetz@6512 1641 return entry;
goetz@6512 1642 } // end of ForceEarlyReturn support
goetz@6512 1643
goetz@6512 1644 //-----------------------------------------------------------------------------
goetz@6512 1645 // Helper for vtos entry point generation
goetz@6512 1646
goetz@6512 1647 void TemplateInterpreterGenerator::set_vtos_entry_points(Template* t,
goetz@6512 1648 address& bep,
goetz@6512 1649 address& cep,
goetz@6512 1650 address& sep,
goetz@6512 1651 address& aep,
goetz@6512 1652 address& iep,
goetz@6512 1653 address& lep,
goetz@6512 1654 address& fep,
goetz@6512 1655 address& dep,
goetz@6512 1656 address& vep) {
goetz@6512 1657 assert(t->is_valid() && t->tos_in() == vtos, "illegal template");
goetz@6512 1658 Label L;
goetz@6512 1659
goetz@6512 1660 aep = __ pc(); __ push_ptr(); __ b(L);
goetz@6512 1661 fep = __ pc(); __ push_f(); __ b(L);
goetz@6512 1662 dep = __ pc(); __ push_d(); __ b(L);
goetz@6512 1663 lep = __ pc(); __ push_l(); __ b(L);
goetz@6512 1664 __ align(32, 12, 24); // align L
goetz@6512 1665 bep = cep = sep =
goetz@6512 1666 iep = __ pc(); __ push_i();
goetz@6512 1667 vep = __ pc();
goetz@6512 1668 __ bind(L);
goetz@6512 1669 generate_and_dispatch(t);
goetz@6512 1670 }
goetz@6512 1671
goetz@6512 1672 //-----------------------------------------------------------------------------
goetz@6512 1673 // Generation of individual instructions
goetz@6512 1674
goetz@6512 1675 // helpers for generate_and_dispatch
goetz@6512 1676
goetz@6512 1677 InterpreterGenerator::InterpreterGenerator(StubQueue* code)
goetz@6512 1678 : TemplateInterpreterGenerator(code) {
goetz@6512 1679 generate_all(); // Down here so it can be "virtual".
goetz@6512 1680 }
goetz@6512 1681
goetz@6512 1682 //-----------------------------------------------------------------------------
goetz@6512 1683
goetz@6512 1684 // Non-product code
goetz@6512 1685 #ifndef PRODUCT
goetz@6512 1686 address TemplateInterpreterGenerator::generate_trace_code(TosState state) {
goetz@6512 1687 //__ flush_bundle();
goetz@6512 1688 address entry = __ pc();
goetz@6512 1689
goetz@6556 1690 const char *bname = NULL;
goetz@6512 1691 uint tsize = 0;
goetz@6512 1692 switch(state) {
goetz@6512 1693 case ftos:
goetz@6512 1694 bname = "trace_code_ftos {";
goetz@6512 1695 tsize = 2;
goetz@6512 1696 break;
goetz@6512 1697 case btos:
goetz@6512 1698 bname = "trace_code_btos {";
goetz@6512 1699 tsize = 2;
goetz@6512 1700 break;
goetz@6512 1701 case ctos:
goetz@6512 1702 bname = "trace_code_ctos {";
goetz@6512 1703 tsize = 2;
goetz@6512 1704 break;
goetz@6512 1705 case stos:
goetz@6512 1706 bname = "trace_code_stos {";
goetz@6512 1707 tsize = 2;
goetz@6512 1708 break;
goetz@6512 1709 case itos:
goetz@6512 1710 bname = "trace_code_itos {";
goetz@6512 1711 tsize = 2;
goetz@6512 1712 break;
goetz@6512 1713 case ltos:
goetz@6512 1714 bname = "trace_code_ltos {";
goetz@6512 1715 tsize = 3;
goetz@6512 1716 break;
goetz@6512 1717 case atos:
goetz@6512 1718 bname = "trace_code_atos {";
goetz@6512 1719 tsize = 2;
goetz@6512 1720 break;
goetz@6512 1721 case vtos:
goetz@6512 1722 // Note: In case of vtos, the topmost of stack value could be a int or doubl
goetz@6512 1723 // In case of a double (2 slots) we won't see the 2nd stack value.
goetz@6512 1724 // Maybe we simply should print the topmost 3 stack slots to cope with the problem.
goetz@6512 1725 bname = "trace_code_vtos {";
goetz@6512 1726 tsize = 2;
goetz@6512 1727
goetz@6512 1728 break;
goetz@6512 1729 case dtos:
goetz@6512 1730 bname = "trace_code_dtos {";
goetz@6512 1731 tsize = 3;
goetz@6512 1732 break;
goetz@6512 1733 default:
goetz@6512 1734 ShouldNotReachHere();
goetz@6512 1735 }
goetz@6512 1736 BLOCK_COMMENT(bname);
goetz@6512 1737
goetz@6512 1738 // Support short-cut for TraceBytecodesAt.
goetz@6512 1739 // Don't call into the VM if we don't want to trace to speed up things.
goetz@6512 1740 Label Lskip_vm_call;
goetz@6512 1741 if (TraceBytecodesAt > 0 && TraceBytecodesAt < max_intx) {
goetz@6512 1742 int offs1 = __ load_const_optimized(R11_scratch1, (address) &TraceBytecodesAt, R0, true);
goetz@6512 1743 int offs2 = __ load_const_optimized(R12_scratch2, (address) &BytecodeCounter::_counter_value, R0, true);
goetz@6512 1744 __ ld(R11_scratch1, offs1, R11_scratch1);
goetz@6512 1745 __ lwa(R12_scratch2, offs2, R12_scratch2);
goetz@6512 1746 __ cmpd(CCR0, R12_scratch2, R11_scratch1);
goetz@6512 1747 __ blt(CCR0, Lskip_vm_call);
goetz@6512 1748 }
goetz@6512 1749
goetz@6512 1750 __ push(state);
goetz@6512 1751 // Load 2 topmost expression stack values.
goetz@6512 1752 __ ld(R6_ARG4, tsize*Interpreter::stackElementSize, R15_esp);
goetz@6512 1753 __ ld(R5_ARG3, Interpreter::stackElementSize, R15_esp);
goetz@6512 1754 __ mflr(R31);
goetz@6512 1755 __ call_VM(noreg, CAST_FROM_FN_PTR(address, SharedRuntime::trace_bytecode), /* unused */ R4_ARG2, R5_ARG3, R6_ARG4, false);
goetz@6512 1756 __ mtlr(R31);
goetz@6512 1757 __ pop(state);
goetz@6512 1758
goetz@6512 1759 if (TraceBytecodesAt > 0 && TraceBytecodesAt < max_intx) {
goetz@6512 1760 __ bind(Lskip_vm_call);
goetz@6512 1761 }
goetz@6512 1762 __ blr();
goetz@6512 1763 BLOCK_COMMENT("} trace_code");
goetz@6512 1764 return entry;
goetz@6512 1765 }
goetz@6512 1766
goetz@6512 1767 void TemplateInterpreterGenerator::count_bytecode() {
goetz@6512 1768 int offs = __ load_const_optimized(R11_scratch1, (address) &BytecodeCounter::_counter_value, R12_scratch2, true);
goetz@6512 1769 __ lwz(R12_scratch2, offs, R11_scratch1);
goetz@6512 1770 __ addi(R12_scratch2, R12_scratch2, 1);
goetz@6512 1771 __ stw(R12_scratch2, offs, R11_scratch1);
goetz@6512 1772 }
goetz@6512 1773
goetz@6512 1774 void TemplateInterpreterGenerator::histogram_bytecode(Template* t) {
goetz@6512 1775 int offs = __ load_const_optimized(R11_scratch1, (address) &BytecodeHistogram::_counters[t->bytecode()], R12_scratch2, true);
goetz@6512 1776 __ lwz(R12_scratch2, offs, R11_scratch1);
goetz@6512 1777 __ addi(R12_scratch2, R12_scratch2, 1);
goetz@6512 1778 __ stw(R12_scratch2, offs, R11_scratch1);
goetz@6512 1779 }
goetz@6512 1780
goetz@6512 1781 void TemplateInterpreterGenerator::histogram_bytecode_pair(Template* t) {
goetz@6512 1782 const Register addr = R11_scratch1,
goetz@6512 1783 tmp = R12_scratch2;
goetz@6512 1784 // Get index, shift out old bytecode, bring in new bytecode, and store it.
goetz@6512 1785 // _index = (_index >> log2_number_of_codes) |
goetz@6512 1786 // (bytecode << log2_number_of_codes);
goetz@6512 1787 int offs1 = __ load_const_optimized(addr, (address)&BytecodePairHistogram::_index, tmp, true);
goetz@6512 1788 __ lwz(tmp, offs1, addr);
goetz@6512 1789 __ srwi(tmp, tmp, BytecodePairHistogram::log2_number_of_codes);
goetz@6512 1790 __ ori(tmp, tmp, ((int) t->bytecode()) << BytecodePairHistogram::log2_number_of_codes);
goetz@6512 1791 __ stw(tmp, offs1, addr);
goetz@6512 1792
goetz@6512 1793 // Bump bucket contents.
goetz@6512 1794 // _counters[_index] ++;
goetz@6512 1795 int offs2 = __ load_const_optimized(addr, (address)&BytecodePairHistogram::_counters, R0, true);
goetz@6512 1796 __ sldi(tmp, tmp, LogBytesPerInt);
goetz@6512 1797 __ add(addr, tmp, addr);
goetz@6512 1798 __ lwz(tmp, offs2, addr);
goetz@6512 1799 __ addi(tmp, tmp, 1);
goetz@6512 1800 __ stw(tmp, offs2, addr);
goetz@6512 1801 }
goetz@6512 1802
goetz@6512 1803 void TemplateInterpreterGenerator::trace_bytecode(Template* t) {
goetz@6512 1804 // Call a little run-time stub to avoid blow-up for each bytecode.
goetz@6512 1805 // The run-time runtime saves the right registers, depending on
goetz@6512 1806 // the tosca in-state for the given template.
goetz@6512 1807
goetz@6512 1808 assert(Interpreter::trace_code(t->tos_in()) != NULL,
goetz@6512 1809 "entry must have been generated");
goetz@6512 1810
goetz@6512 1811 // Note: we destroy LR here.
goetz@6512 1812 __ bl(Interpreter::trace_code(t->tos_in()));
goetz@6512 1813 }
goetz@6512 1814
goetz@6512 1815 void TemplateInterpreterGenerator::stop_interpreter_at() {
goetz@6512 1816 Label L;
goetz@6512 1817 int offs1 = __ load_const_optimized(R11_scratch1, (address) &StopInterpreterAt, R0, true);
goetz@6512 1818 int offs2 = __ load_const_optimized(R12_scratch2, (address) &BytecodeCounter::_counter_value, R0, true);
goetz@6512 1819 __ ld(R11_scratch1, offs1, R11_scratch1);
goetz@6512 1820 __ lwa(R12_scratch2, offs2, R12_scratch2);
goetz@6512 1821 __ cmpd(CCR0, R12_scratch2, R11_scratch1);
goetz@6512 1822 __ bne(CCR0, L);
goetz@6512 1823 __ illtrap();
goetz@6512 1824 __ bind(L);
goetz@6512 1825 }
goetz@6512 1826
goetz@6512 1827 #endif // !PRODUCT
goetz@6512 1828 #endif // !CC_INTERP

mercurial