src/cpu/ppc/vm/templateInterpreter_ppc.cpp

Wed, 15 Apr 2020 11:49:55 +0800

author
aoqi
date
Wed, 15 Apr 2020 11:49:55 +0800
changeset 9852
70aa912cebe5
parent 9572
624a0741915c
permissions
-rw-r--r--

Merge

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

mercurial