annotate src/cpu/ppc/vm/templateInterpreter_ppc.cpp @ 8979:bcccbecdde63

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