templateTable_sparc.cpp 121.6 KB
Newer Older
D
duke 已提交
1
/*
2
 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
D
duke 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
19 20 21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
D
duke 已提交
22 23 24
 *
 */

25 26 27 28 29 30 31 32 33 34 35 36
#include "precompiled.hpp"
#include "interpreter/interpreter.hpp"
#include "interpreter/interpreterRuntime.hpp"
#include "interpreter/templateTable.hpp"
#include "memory/universe.inline.hpp"
#include "oops/methodDataOop.hpp"
#include "oops/objArrayKlass.hpp"
#include "oops/oop.inline.hpp"
#include "prims/methodHandles.hpp"
#include "runtime/sharedRuntime.hpp"
#include "runtime/stubRoutines.hpp"
#include "runtime/synchronizer.hpp"
D
duke 已提交
37 38 39 40

#ifndef CC_INTERP
#define __ _masm->

41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
// Misc helpers

// Do an oop store like *(base + index + offset) = val
// index can be noreg,
static void do_oop_store(InterpreterMacroAssembler* _masm,
                         Register base,
                         Register index,
                         int offset,
                         Register val,
                         Register tmp,
                         BarrierSet::Name barrier,
                         bool precise) {
  assert(tmp != val && tmp != base && tmp != index, "register collision");
  assert(index == noreg || offset == 0, "only one offset");
  switch (barrier) {
#ifndef SERIALGC
    case BarrierSet::G1SATBCT:
    case BarrierSet::G1SATBCTLogging:
      {
60 61 62 63 64
        // Load and record the previous value.
        __ g1_write_barrier_pre(base, index, offset,
                                noreg /* pre_val */,
                                tmp, true /*preserve_o_regs*/);

65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
        if (index == noreg ) {
          assert(Assembler::is_simm13(offset), "fix this code");
          __ store_heap_oop(val, base, offset);
        } else {
          __ store_heap_oop(val, base, index);
        }

        // No need for post barrier if storing NULL
        if (val != G0) {
          if (precise) {
            if (index == noreg) {
              __ add(base, offset, base);
            } else {
              __ add(base, index, base);
            }
          }
          __ g1_write_barrier_post(base, val, tmp);
        }
      }
      break;
#endif // SERIALGC
    case BarrierSet::CardTableModRef:
    case BarrierSet::CardTableExtension:
      {
        if (index == noreg ) {
          assert(Assembler::is_simm13(offset), "fix this code");
          __ store_heap_oop(val, base, offset);
        } else {
          __ store_heap_oop(val, base, index);
        }
        // No need for post barrier if storing NULL
        if (val != G0) {
          if (precise) {
            if (index == noreg) {
              __ add(base, offset, base);
            } else {
              __ add(base, index, base);
            }
          }
          __ card_write_barrier_post(base, val, tmp);
        }
      }
      break;
    case BarrierSet::ModRef:
    case BarrierSet::Other:
      ShouldNotReachHere();
      break;
    default      :
      ShouldNotReachHere();

  }
}

D
duke 已提交
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147

//----------------------------------------------------------------------------------------------------
// Platform-dependent initialization

void TemplateTable::pd_initialize() {
  // (none)
}


//----------------------------------------------------------------------------------------------------
// Condition conversion
Assembler::Condition ccNot(TemplateTable::Condition cc) {
  switch (cc) {
    case TemplateTable::equal        : return Assembler::notEqual;
    case TemplateTable::not_equal    : return Assembler::equal;
    case TemplateTable::less         : return Assembler::greaterEqual;
    case TemplateTable::less_equal   : return Assembler::greater;
    case TemplateTable::greater      : return Assembler::lessEqual;
    case TemplateTable::greater_equal: return Assembler::less;
  }
  ShouldNotReachHere();
  return Assembler::zero;
}

//----------------------------------------------------------------------------------------------------
// Miscelaneous helper routines


Address TemplateTable::at_bcp(int offset) {
  assert(_desc->uses_bcp(), "inconsistent uses_bcp information");
148
  return Address(Lbcp, offset);
D
duke 已提交
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
}


void TemplateTable::patch_bytecode(Bytecodes::Code bc, Register Rbyte_code,
                                   Register Rscratch,
                                   bool load_bc_into_scratch /*=true*/) {
  // With sharing on, may need to test methodOop flag.
  if (!RewriteBytecodes) return;
  if (load_bc_into_scratch) __ set(bc, Rbyte_code);
  Label patch_done;
  if (JvmtiExport::can_post_breakpoint()) {
    Label fast_patch;
    __ ldub(at_bcp(0), Rscratch);
    __ cmp(Rscratch, Bytecodes::_breakpoint);
    __ br(Assembler::notEqual, false, Assembler::pt, fast_patch);
    __ delayed()->nop();  // don't bother to hoist the stb here
    // perform the quickening, slowly, in the bowels of the breakpoint table
    __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::set_original_bytecode_at), Lmethod, Lbcp, Rbyte_code);
    __ ba(false, patch_done);
    __ delayed()->nop();
    __ bind(fast_patch);
  }
#ifdef ASSERT
  Bytecodes::Code orig_bytecode =  Bytecodes::java_code(bc);
  Label okay;
  __ ldub(at_bcp(0), Rscratch);
  __ cmp(Rscratch, orig_bytecode);
  __ br(Assembler::equal, false, Assembler::pt, okay);
  __ delayed() ->cmp(Rscratch, Rbyte_code);
  __ br(Assembler::equal, false, Assembler::pt, okay);
  __ delayed()->nop();
  __ stop("Rewriting wrong bytecode location");
  __ bind(okay);
#endif
  __ stb(Rbyte_code, at_bcp(0));
  __ bind(patch_done);
}

//----------------------------------------------------------------------------------------------------
// Individual instructions

void TemplateTable::nop() {
  transition(vtos, vtos);
  // nothing to do
}

void TemplateTable::shouldnotreachhere() {
  transition(vtos, vtos);
  __ stop("shouldnotreachhere bytecode");
}

void TemplateTable::aconst_null() {
  transition(vtos, atos);
  __ clr(Otos_i);
}


void TemplateTable::iconst(int value) {
  transition(vtos, itos);
  __ set(value, Otos_i);
}


void TemplateTable::lconst(int value) {
  transition(vtos, ltos);
  assert(value >= 0, "check this code");
#ifdef _LP64
  __ set(value, Otos_l);
#else
  __ set(value, Otos_l2);
  __ clr( Otos_l1);
#endif
}


void TemplateTable::fconst(int value) {
  transition(vtos, ftos);
  static float zero = 0.0, one = 1.0, two = 2.0;
  float* p;
  switch( value ) {
   default: ShouldNotReachHere();
   case 0:  p = &zero;  break;
   case 1:  p = &one;   break;
   case 2:  p = &two;   break;
  }
234 235 236
  AddressLiteral a(p);
  __ sethi(a, G3_scratch);
  __ ldf(FloatRegisterImpl::S, G3_scratch, a.low10(), Ftos_f);
D
duke 已提交
237 238 239 240 241 242 243 244 245 246 247 248
}


void TemplateTable::dconst(int value) {
  transition(vtos, dtos);
  static double zero = 0.0, one = 1.0;
  double* p;
  switch( value ) {
   default: ShouldNotReachHere();
   case 0:  p = &zero;  break;
   case 1:  p = &one;   break;
  }
249 250 251
  AddressLiteral a(p);
  __ sethi(a, G3_scratch);
  __ ldf(FloatRegisterImpl::D, G3_scratch, a.low10(), Ftos_d);
D
duke 已提交
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
}


// %%%%% Should factore most snippet templates across platforms

void TemplateTable::bipush() {
  transition(vtos, itos);
  __ ldsb( at_bcp(1), Otos_i );
}

void TemplateTable::sipush() {
  transition(vtos, itos);
  __ get_2_byte_integer_at_bcp(1, G3_scratch, Otos_i, InterpreterMacroAssembler::Signed);
}

void TemplateTable::ldc(bool wide) {
  transition(vtos, vtos);
269
  Label call_ldc, notInt, isString, notString, notClass, exit;
D
duke 已提交
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319

  if (wide) {
    __ get_2_byte_integer_at_bcp(1, G3_scratch, O1, InterpreterMacroAssembler::Unsigned);
  } else {
    __ ldub(Lbcp, 1, O1);
  }
  __ get_cpool_and_tags(O0, O2);

  const int base_offset = constantPoolOopDesc::header_size() * wordSize;
  const int tags_offset = typeArrayOopDesc::header_size(T_BYTE) * wordSize;

  // get type from tags
  __ add(O2, tags_offset, O2);
  __ ldub(O2, O1, O2);
  __ cmp(O2, JVM_CONSTANT_UnresolvedString);    // unresolved string? If so, must resolve
  __ brx(Assembler::equal, true, Assembler::pt, call_ldc);
  __ delayed()->nop();

  __ cmp(O2, JVM_CONSTANT_UnresolvedClass);     // unresolved class? If so, must resolve
  __ brx(Assembler::equal, true, Assembler::pt, call_ldc);
  __ delayed()->nop();

  __ cmp(O2, JVM_CONSTANT_UnresolvedClassInError);     // unresolved class in error state
  __ brx(Assembler::equal, true, Assembler::pn, call_ldc);
  __ delayed()->nop();

  __ cmp(O2, JVM_CONSTANT_Class);      // need to call vm to get java mirror of the class
  __ brx(Assembler::notEqual, true, Assembler::pt, notClass);
  __ delayed()->add(O0, base_offset, O0);

  __ bind(call_ldc);
  __ set(wide, O1);
  call_VM(Otos_i, CAST_FROM_FN_PTR(address, InterpreterRuntime::ldc), O1);
  __ push(atos);
  __ ba(false, exit);
  __ delayed()->nop();

  __ bind(notClass);
 // __ add(O0, base_offset, O0);
  __ sll(O1, LogBytesPerWord, O1);
  __ cmp(O2, JVM_CONSTANT_Integer);
  __ brx(Assembler::notEqual, true, Assembler::pt, notInt);
  __ delayed()->cmp(O2, JVM_CONSTANT_String);
  __ ld(O0, O1, Otos_i);
  __ push(itos);
  __ ba(false, exit);
  __ delayed()->nop();

  __ bind(notInt);
 // __ cmp(O2, JVM_CONSTANT_String);
320 321
  __ brx(Assembler::equal, true, Assembler::pt, isString);
  __ delayed()->cmp(O2, JVM_CONSTANT_Object);
D
duke 已提交
322 323
  __ brx(Assembler::notEqual, true, Assembler::pt, notString);
  __ delayed()->ldf(FloatRegisterImpl::S, O0, O1, Ftos_f);
324
  __ bind(isString);
D
duke 已提交
325 326 327 328 329 330 331 332 333 334 335 336 337
  __ ld_ptr(O0, O1, Otos_i);
  __ verify_oop(Otos_i);
  __ push(atos);
  __ ba(false, exit);
  __ delayed()->nop();

  __ bind(notString);
 // __ ldf(FloatRegisterImpl::S, O0, O1, Ftos_f);
  __ push(ftos);

  __ bind(exit);
}

338 339 340 341 342 343
// Fast path for caching oop constants.
// %%% We should use this to handle Class and String constants also.
// %%% It will simplify the ldc/primitive path considerably.
void TemplateTable::fast_aldc(bool wide) {
  transition(vtos, atos);

344 345
  if (!EnableInvokeDynamic) {
    // We should not encounter this bytecode if !EnableInvokeDynamic.
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360
    // The verifier will stop it.  However, if we get past the verifier,
    // this will stop the thread in a reasonable way, without crashing the JVM.
    __ call_VM(noreg, CAST_FROM_FN_PTR(address,
                     InterpreterRuntime::throw_IncompatibleClassChangeError));
    // the call_VM checks for exception, so we should never return here.
    __ should_not_reach_here();
    return;
  }

  Register Rcache = G3_scratch;
  Register Rscratch = G4_scratch;

  resolve_cache_and_index(f1_oop, Otos_i, Rcache, Rscratch, wide ? sizeof(u2) : sizeof(u1));

  __ verify_oop(Otos_i);
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380

  Label L_done;
  const Register Rcon_klass = G3_scratch;  // same as Rcache
  const Register Rarray_klass = G4_scratch;  // same as Rscratch
  __ load_klass(Otos_i, Rcon_klass);
  AddressLiteral array_klass_addr((address)Universe::systemObjArrayKlassObj_addr());
  __ load_contents(array_klass_addr, Rarray_klass);
  __ cmp(Rarray_klass, Rcon_klass);
  __ brx(Assembler::notEqual, false, Assembler::pt, L_done);
  __ delayed()->nop();
  __ ld(Address(Otos_i, arrayOopDesc::length_offset_in_bytes()), Rcon_klass);
  __ tst(Rcon_klass);
  __ brx(Assembler::zero, true, Assembler::pt, L_done);
  __ delayed()->clr(Otos_i);    // executed only if branch is taken

  // Load the exception from the system-array which wraps it:
  __ load_heap_oop(Otos_i, arrayOopDesc::base_offset_in_bytes(T_OBJECT), Otos_i);
  __ throw_if_not_x(Assembler::never, Interpreter::throw_exception_entry(), G3_scratch);

  __ bind(L_done);
381 382
}

D
duke 已提交
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599
void TemplateTable::ldc2_w() {
  transition(vtos, vtos);
  Label retry, resolved, Long, exit;

  __ bind(retry);
  __ get_2_byte_integer_at_bcp(1, G3_scratch, O1, InterpreterMacroAssembler::Unsigned);
  __ get_cpool_and_tags(O0, O2);

  const int base_offset = constantPoolOopDesc::header_size() * wordSize;
  const int tags_offset = typeArrayOopDesc::header_size(T_BYTE) * wordSize;
  // get type from tags
  __ add(O2, tags_offset, O2);
  __ ldub(O2, O1, O2);

  __ sll(O1, LogBytesPerWord, O1);
  __ add(O0, O1, G3_scratch);

  __ cmp(O2, JVM_CONSTANT_Double);
  __ brx(Assembler::notEqual, false, Assembler::pt, Long);
  __ delayed()->nop();
  // A double can be placed at word-aligned locations in the constant pool.
  // Check out Conversions.java for an example.
  // Also constantPoolOopDesc::header_size() is 20, which makes it very difficult
  // to double-align double on the constant pool.  SG, 11/7/97
#ifdef _LP64
  __ ldf(FloatRegisterImpl::D, G3_scratch, base_offset, Ftos_d);
#else
  FloatRegister f = Ftos_d;
  __ ldf(FloatRegisterImpl::S, G3_scratch, base_offset, f);
  __ ldf(FloatRegisterImpl::S, G3_scratch, base_offset + sizeof(jdouble)/2,
         f->successor());
#endif
  __ push(dtos);
  __ ba(false, exit);
  __ delayed()->nop();

  __ bind(Long);
#ifdef _LP64
  __ ldx(G3_scratch, base_offset, Otos_l);
#else
  __ ld(G3_scratch, base_offset, Otos_l);
  __ ld(G3_scratch, base_offset + sizeof(jlong)/2, Otos_l->successor());
#endif
  __ push(ltos);

  __ bind(exit);
}


void TemplateTable::locals_index(Register reg, int offset) {
  __ ldub( at_bcp(offset), reg );
}


void TemplateTable::locals_index_wide(Register reg) {
  // offset is 2, not 1, because Lbcp points to wide prefix code
  __ get_2_byte_integer_at_bcp(2, G4_scratch, reg, InterpreterMacroAssembler::Unsigned);
}

void TemplateTable::iload() {
  transition(vtos, itos);
  // Rewrite iload,iload  pair into fast_iload2
  //         iload,caload pair into fast_icaload
  if (RewriteFrequentPairs) {
    Label rewrite, done;

    // get next byte
    __ ldub(at_bcp(Bytecodes::length_for(Bytecodes::_iload)), G3_scratch);

    // if _iload, wait to rewrite to iload2.  We only want to rewrite the
    // last two iloads in a pair.  Comparing against fast_iload means that
    // the next bytecode is neither an iload or a caload, and therefore
    // an iload pair.
    __ cmp(G3_scratch, (int)Bytecodes::_iload);
    __ br(Assembler::equal, false, Assembler::pn, done);
    __ delayed()->nop();

    __ cmp(G3_scratch, (int)Bytecodes::_fast_iload);
    __ br(Assembler::equal, false, Assembler::pn, rewrite);
    __ delayed()->set(Bytecodes::_fast_iload2, G4_scratch);

    __ cmp(G3_scratch, (int)Bytecodes::_caload);
    __ br(Assembler::equal, false, Assembler::pn, rewrite);
    __ delayed()->set(Bytecodes::_fast_icaload, G4_scratch);

    __ set(Bytecodes::_fast_iload, G4_scratch);  // don't check again
    // rewrite
    // G4_scratch: fast bytecode
    __ bind(rewrite);
    patch_bytecode(Bytecodes::_iload, G4_scratch, G3_scratch, false);
    __ bind(done);
  }

  // Get the local value into tos
  locals_index(G3_scratch);
  __ access_local_int( G3_scratch, Otos_i );
}

void TemplateTable::fast_iload2() {
  transition(vtos, itos);
  locals_index(G3_scratch);
  __ access_local_int( G3_scratch, Otos_i );
  __ push_i();
  locals_index(G3_scratch, 3);  // get next bytecode's local index.
  __ access_local_int( G3_scratch, Otos_i );
}

void TemplateTable::fast_iload() {
  transition(vtos, itos);
  locals_index(G3_scratch);
  __ access_local_int( G3_scratch, Otos_i );
}

void TemplateTable::lload() {
  transition(vtos, ltos);
  locals_index(G3_scratch);
  __ access_local_long( G3_scratch, Otos_l );
}


void TemplateTable::fload() {
  transition(vtos, ftos);
  locals_index(G3_scratch);
  __ access_local_float( G3_scratch, Ftos_f );
}


void TemplateTable::dload() {
  transition(vtos, dtos);
  locals_index(G3_scratch);
  __ access_local_double( G3_scratch, Ftos_d );
}


void TemplateTable::aload() {
  transition(vtos, atos);
  locals_index(G3_scratch);
  __ access_local_ptr( G3_scratch, Otos_i);
}


void TemplateTable::wide_iload() {
  transition(vtos, itos);
  locals_index_wide(G3_scratch);
  __ access_local_int( G3_scratch, Otos_i );
}


void TemplateTable::wide_lload() {
  transition(vtos, ltos);
  locals_index_wide(G3_scratch);
  __ access_local_long( G3_scratch, Otos_l );
}


void TemplateTable::wide_fload() {
  transition(vtos, ftos);
  locals_index_wide(G3_scratch);
  __ access_local_float( G3_scratch, Ftos_f );
}


void TemplateTable::wide_dload() {
  transition(vtos, dtos);
  locals_index_wide(G3_scratch);
  __ access_local_double( G3_scratch, Ftos_d );
}


void TemplateTable::wide_aload() {
  transition(vtos, atos);
  locals_index_wide(G3_scratch);
  __ access_local_ptr( G3_scratch, Otos_i );
  __ verify_oop(Otos_i);
}


void TemplateTable::iaload() {
  transition(itos, itos);
  // Otos_i: index
  // tos: array
  __ index_check(O2, Otos_i, LogBytesPerInt, G3_scratch, O3);
  __ ld(O3, arrayOopDesc::base_offset_in_bytes(T_INT), Otos_i);
}


void TemplateTable::laload() {
  transition(itos, ltos);
  // Otos_i: index
  // O2: array
  __ index_check(O2, Otos_i, LogBytesPerLong, G3_scratch, O3);
  __ ld_long(O3, arrayOopDesc::base_offset_in_bytes(T_LONG), Otos_l);
}


void TemplateTable::faload() {
  transition(itos, ftos);
  // Otos_i: index
  // O2: array
  __ index_check(O2, Otos_i, LogBytesPerInt, G3_scratch, O3);
  __ ldf(FloatRegisterImpl::S, O3, arrayOopDesc::base_offset_in_bytes(T_FLOAT), Ftos_f);
}


void TemplateTable::daload() {
  transition(itos, dtos);
  // Otos_i: index
  // O2: array
  __ index_check(O2, Otos_i, LogBytesPerLong, G3_scratch, O3);
  __ ldf(FloatRegisterImpl::D, O3, arrayOopDesc::base_offset_in_bytes(T_DOUBLE), Ftos_d);
}


void TemplateTable::aaload() {
  transition(itos, atos);
  // Otos_i: index
  // tos: array
600 601
  __ index_check(O2, Otos_i, UseCompressedOops ? 2 : LogBytesPerWord, G3_scratch, O3);
  __ load_heap_oop(O3, arrayOopDesc::base_offset_in_bytes(T_OBJECT), Otos_i);
D
duke 已提交
602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766
  __ verify_oop(Otos_i);
}


void TemplateTable::baload() {
  transition(itos, itos);
  // Otos_i: index
  // tos: array
  __ index_check(O2, Otos_i, 0, G3_scratch, O3);
  __ ldsb(O3, arrayOopDesc::base_offset_in_bytes(T_BYTE), Otos_i);
}


void TemplateTable::caload() {
  transition(itos, itos);
  // Otos_i: index
  // tos: array
  __ index_check(O2, Otos_i, LogBytesPerShort, G3_scratch, O3);
  __ lduh(O3, arrayOopDesc::base_offset_in_bytes(T_CHAR), Otos_i);
}

void TemplateTable::fast_icaload() {
  transition(vtos, itos);
  // Otos_i: index
  // tos: array
  locals_index(G3_scratch);
  __ access_local_int( G3_scratch, Otos_i );
  __ index_check(O2, Otos_i, LogBytesPerShort, G3_scratch, O3);
  __ lduh(O3, arrayOopDesc::base_offset_in_bytes(T_CHAR), Otos_i);
}


void TemplateTable::saload() {
  transition(itos, itos);
  // Otos_i: index
  // tos: array
  __ index_check(O2, Otos_i, LogBytesPerShort, G3_scratch, O3);
  __ ldsh(O3, arrayOopDesc::base_offset_in_bytes(T_SHORT), Otos_i);
}


void TemplateTable::iload(int n) {
  transition(vtos, itos);
  __ ld( Llocals, Interpreter::local_offset_in_bytes(n), Otos_i );
}


void TemplateTable::lload(int n) {
  transition(vtos, ltos);
  assert(n+1 < Argument::n_register_parameters, "would need more code");
  __ load_unaligned_long(Llocals, Interpreter::local_offset_in_bytes(n+1), Otos_l);
}


void TemplateTable::fload(int n) {
  transition(vtos, ftos);
  assert(n < Argument::n_register_parameters, "would need more code");
  __ ldf( FloatRegisterImpl::S, Llocals, Interpreter::local_offset_in_bytes(n),     Ftos_f );
}


void TemplateTable::dload(int n) {
  transition(vtos, dtos);
  FloatRegister dst = Ftos_d;
  __ load_unaligned_double(Llocals, Interpreter::local_offset_in_bytes(n+1), dst);
}


void TemplateTable::aload(int n) {
  transition(vtos, atos);
  __ ld_ptr( Llocals, Interpreter::local_offset_in_bytes(n), Otos_i );
}


void TemplateTable::aload_0() {
  transition(vtos, atos);

  // According to bytecode histograms, the pairs:
  //
  // _aload_0, _fast_igetfield (itos)
  // _aload_0, _fast_agetfield (atos)
  // _aload_0, _fast_fgetfield (ftos)
  //
  // occur frequently. If RewriteFrequentPairs is set, the (slow) _aload_0
  // bytecode checks the next bytecode and then rewrites the current
  // bytecode into a pair bytecode; otherwise it rewrites the current
  // bytecode into _fast_aload_0 that doesn't do the pair check anymore.
  //
  if (RewriteFrequentPairs) {
    Label rewrite, done;

    // get next byte
    __ ldub(at_bcp(Bytecodes::length_for(Bytecodes::_aload_0)), G3_scratch);

    // do actual aload_0
    aload(0);

    // if _getfield then wait with rewrite
    __ cmp(G3_scratch, (int)Bytecodes::_getfield);
    __ br(Assembler::equal, false, Assembler::pn, done);
    __ delayed()->nop();

    // if _igetfield then rewrite to _fast_iaccess_0
    assert(Bytecodes::java_code(Bytecodes::_fast_iaccess_0) == Bytecodes::_aload_0, "adjust fast bytecode def");
    __ cmp(G3_scratch, (int)Bytecodes::_fast_igetfield);
    __ br(Assembler::equal, false, Assembler::pn, rewrite);
    __ delayed()->set(Bytecodes::_fast_iaccess_0, G4_scratch);

    // if _agetfield then rewrite to _fast_aaccess_0
    assert(Bytecodes::java_code(Bytecodes::_fast_aaccess_0) == Bytecodes::_aload_0, "adjust fast bytecode def");
    __ cmp(G3_scratch, (int)Bytecodes::_fast_agetfield);
    __ br(Assembler::equal, false, Assembler::pn, rewrite);
    __ delayed()->set(Bytecodes::_fast_aaccess_0, G4_scratch);

    // if _fgetfield then rewrite to _fast_faccess_0
    assert(Bytecodes::java_code(Bytecodes::_fast_faccess_0) == Bytecodes::_aload_0, "adjust fast bytecode def");
    __ cmp(G3_scratch, (int)Bytecodes::_fast_fgetfield);
    __ br(Assembler::equal, false, Assembler::pn, rewrite);
    __ delayed()->set(Bytecodes::_fast_faccess_0, G4_scratch);

    // else rewrite to _fast_aload0
    assert(Bytecodes::java_code(Bytecodes::_fast_aload_0) == Bytecodes::_aload_0, "adjust fast bytecode def");
    __ set(Bytecodes::_fast_aload_0, G4_scratch);

    // rewrite
    // G4_scratch: fast bytecode
    __ bind(rewrite);
    patch_bytecode(Bytecodes::_aload_0, G4_scratch, G3_scratch, false);
    __ bind(done);
  } else {
    aload(0);
  }
}


void TemplateTable::istore() {
  transition(itos, vtos);
  locals_index(G3_scratch);
  __ store_local_int( G3_scratch, Otos_i );
}


void TemplateTable::lstore() {
  transition(ltos, vtos);
  locals_index(G3_scratch);
  __ store_local_long( G3_scratch, Otos_l );
}


void TemplateTable::fstore() {
  transition(ftos, vtos);
  locals_index(G3_scratch);
  __ store_local_float( G3_scratch, Ftos_f );
}


void TemplateTable::dstore() {
  transition(dtos, vtos);
  locals_index(G3_scratch);
  __ store_local_double( G3_scratch, Ftos_d );
}


void TemplateTable::astore() {
  transition(vtos, vtos);
767 768
  __ load_ptr(0, Otos_i);
  __ inc(Lesp, Interpreter::stackElementSize);
D
duke 已提交
769 770
  __ verify_oop_or_return_address(Otos_i, G3_scratch);
  locals_index(G3_scratch);
771
  __ store_local_ptr(G3_scratch, Otos_i);
D
duke 已提交
772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808
}


void TemplateTable::wide_istore() {
  transition(vtos, vtos);
  __ pop_i();
  locals_index_wide(G3_scratch);
  __ store_local_int( G3_scratch, Otos_i );
}


void TemplateTable::wide_lstore() {
  transition(vtos, vtos);
  __ pop_l();
  locals_index_wide(G3_scratch);
  __ store_local_long( G3_scratch, Otos_l );
}


void TemplateTable::wide_fstore() {
  transition(vtos, vtos);
  __ pop_f();
  locals_index_wide(G3_scratch);
  __ store_local_float( G3_scratch, Ftos_f );
}


void TemplateTable::wide_dstore() {
  transition(vtos, vtos);
  __ pop_d();
  locals_index_wide(G3_scratch);
  __ store_local_double( G3_scratch, Ftos_d );
}


void TemplateTable::wide_astore() {
  transition(vtos, vtos);
809 810
  __ load_ptr(0, Otos_i);
  __ inc(Lesp, Interpreter::stackElementSize);
D
duke 已提交
811 812
  __ verify_oop_or_return_address(Otos_i, G3_scratch);
  locals_index_wide(G3_scratch);
813
  __ store_local_ptr(G3_scratch, Otos_i);
D
duke 已提交
814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866
}


void TemplateTable::iastore() {
  transition(itos, vtos);
  __ pop_i(O2); // index
  // Otos_i: val
  // O3: array
  __ index_check(O3, O2, LogBytesPerInt, G3_scratch, O2);
  __ st(Otos_i, O2, arrayOopDesc::base_offset_in_bytes(T_INT));
}


void TemplateTable::lastore() {
  transition(ltos, vtos);
  __ pop_i(O2); // index
  // Otos_l: val
  // O3: array
  __ index_check(O3, O2, LogBytesPerLong, G3_scratch, O2);
  __ st_long(Otos_l, O2, arrayOopDesc::base_offset_in_bytes(T_LONG));
}


void TemplateTable::fastore() {
  transition(ftos, vtos);
  __ pop_i(O2); // index
  // Ftos_f: val
  // O3: array
  __ index_check(O3, O2, LogBytesPerInt, G3_scratch, O2);
  __ stf(FloatRegisterImpl::S, Ftos_f, O2, arrayOopDesc::base_offset_in_bytes(T_FLOAT));
}


void TemplateTable::dastore() {
  transition(dtos, vtos);
  __ pop_i(O2); // index
  // Fos_d: val
  // O3: array
  __ index_check(O3, O2, LogBytesPerLong, G3_scratch, O2);
  __ stf(FloatRegisterImpl::D, Ftos_d, O2, arrayOopDesc::base_offset_in_bytes(T_DOUBLE));
}


void TemplateTable::aastore() {
  Label store_ok, is_null, done;
  transition(vtos, vtos);
  __ ld_ptr(Lesp, Interpreter::expr_offset_in_bytes(0), Otos_i);
  __ ld(Lesp, Interpreter::expr_offset_in_bytes(1), O2);         // get index
  __ ld_ptr(Lesp, Interpreter::expr_offset_in_bytes(2), O3);     // get array
  // Otos_i: val
  // O2: index
  // O3: array
  __ verify_oop(Otos_i);
867
  __ index_check_without_pop(O3, O2, UseCompressedOops ? 2 : LogBytesPerWord, G3_scratch, O1);
D
duke 已提交
868 869 870

  // do array store check - check for NULL value first
  __ br_null( Otos_i, false, Assembler::pn, is_null );
871 872 873 874
  __ delayed()->nop();

  __ load_klass(O3, O4); // get array klass
  __ load_klass(Otos_i, O5); // get value klass
D
duke 已提交
875 876 877 878 879 880 881 882 883 884 885 886 887 888

  // do fast instanceof cache test

  __ ld_ptr(O4,     sizeof(oopDesc) + objArrayKlass::element_klass_offset_in_bytes(),  O4);

  assert(Otos_i == O0, "just checking");

  // Otos_i:    value
  // O1:        addr - offset
  // O2:        index
  // O3:        array
  // O4:        array element klass
  // O5:        value klass

889 890
  // Address element(O1, 0, arrayOopDesc::base_offset_in_bytes(T_OBJECT));

D
duke 已提交
891 892 893 894 895 896 897 898 899
  // Generate a fast subtype check.  Branch to store_ok if no
  // failure.  Throw if failure.
  __ gen_subtype_check( O5, O4, G3_scratch, G4_scratch, G1_scratch, store_ok );

  // Not a subtype; so must throw exception
  __ throw_if_not_x( Assembler::never, Interpreter::_throw_ArrayStoreException_entry, G3_scratch );

  // Store is OK.
  __ bind(store_ok);
900 901
  do_oop_store(_masm, O1, noreg, arrayOopDesc::base_offset_in_bytes(T_OBJECT), Otos_i, G3_scratch, _bs->kind(), true);

D
duke 已提交
902
  __ ba(false,done);
903
  __ delayed()->inc(Lesp, 3* Interpreter::stackElementSize); // adj sp (pops array, index and value)
D
duke 已提交
904 905

  __ bind(is_null);
906 907
  do_oop_store(_masm, O1, noreg, arrayOopDesc::base_offset_in_bytes(T_OBJECT), G0, G4_scratch, _bs->kind(), true);

D
duke 已提交
908
  __ profile_null_seen(G3_scratch);
909
  __ inc(Lesp, 3* Interpreter::stackElementSize);     // adj sp (pops array, index and value)
D
duke 已提交
910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969
  __ bind(done);
}


void TemplateTable::bastore() {
  transition(itos, vtos);
  __ pop_i(O2); // index
  // Otos_i: val
  // O3: array
  __ index_check(O3, O2, 0, G3_scratch, O2);
  __ stb(Otos_i, O2, arrayOopDesc::base_offset_in_bytes(T_BYTE));
}


void TemplateTable::castore() {
  transition(itos, vtos);
  __ pop_i(O2); // index
  // Otos_i: val
  // O3: array
  __ index_check(O3, O2, LogBytesPerShort, G3_scratch, O2);
  __ sth(Otos_i, O2, arrayOopDesc::base_offset_in_bytes(T_CHAR));
}


void TemplateTable::sastore() {
  // %%%%% Factor across platform
  castore();
}


void TemplateTable::istore(int n) {
  transition(itos, vtos);
  __ st(Otos_i, Llocals, Interpreter::local_offset_in_bytes(n));
}


void TemplateTable::lstore(int n) {
  transition(ltos, vtos);
  assert(n+1 < Argument::n_register_parameters, "only handle register cases");
  __ store_unaligned_long(Otos_l, Llocals, Interpreter::local_offset_in_bytes(n+1));

}


void TemplateTable::fstore(int n) {
  transition(ftos, vtos);
  assert(n < Argument::n_register_parameters, "only handle register cases");
  __ stf(FloatRegisterImpl::S, Ftos_f, Llocals, Interpreter::local_offset_in_bytes(n));
}


void TemplateTable::dstore(int n) {
  transition(dtos, vtos);
  FloatRegister src = Ftos_d;
  __ store_unaligned_double(src, Llocals, Interpreter::local_offset_in_bytes(n+1));
}


void TemplateTable::astore(int n) {
  transition(vtos, vtos);
970 971
  __ load_ptr(0, Otos_i);
  __ inc(Lesp, Interpreter::stackElementSize);
D
duke 已提交
972
  __ verify_oop_or_return_address(Otos_i, G3_scratch);
973
  __ store_local_ptr(n, Otos_i);
D
duke 已提交
974 975 976 977 978
}


void TemplateTable::pop() {
  transition(vtos, vtos);
979
  __ inc(Lesp, Interpreter::stackElementSize);
D
duke 已提交
980 981 982 983 984
}


void TemplateTable::pop2() {
  transition(vtos, vtos);
985
  __ inc(Lesp, 2 * Interpreter::stackElementSize);
D
duke 已提交
986 987 988 989 990 991 992
}


void TemplateTable::dup() {
  transition(vtos, vtos);
  // stack: ..., a
  // load a and tag
993 994
  __ load_ptr(0, Otos_i);
  __ push_ptr(Otos_i);
D
duke 已提交
995 996 997 998 999 1000 1001
  // stack: ..., a, a
}


void TemplateTable::dup_x1() {
  transition(vtos, vtos);
  // stack: ..., a, b
1002 1003 1004 1005 1006
  __ load_ptr( 1, G3_scratch);  // get a
  __ load_ptr( 0, Otos_l1);     // get b
  __ store_ptr(1, Otos_l1);     // put b
  __ store_ptr(0, G3_scratch);  // put a - like swap
  __ push_ptr(Otos_l1);         // push b
D
duke 已提交
1007 1008 1009 1010 1011 1012 1013 1014
  // stack: ..., b, a, b
}


void TemplateTable::dup_x2() {
  transition(vtos, vtos);
  // stack: ..., a, b, c
  // get c and push on stack, reuse registers
1015 1016
  __ load_ptr( 0, G3_scratch);  // get c
  __ push_ptr(G3_scratch);      // push c with tag
D
duke 已提交
1017 1018
  // stack: ..., a, b, c, c  (c in reg)  (Lesp - 4)
  // (stack offsets n+1 now)
1019 1020
  __ load_ptr( 3, Otos_l1);     // get a
  __ store_ptr(3, G3_scratch);  // put c at 3
D
duke 已提交
1021
  // stack: ..., c, b, c, c  (a in reg)
1022 1023
  __ load_ptr( 2, G3_scratch);  // get b
  __ store_ptr(2, Otos_l1);     // put a at 2
D
duke 已提交
1024
  // stack: ..., c, a, c, c  (b in reg)
1025
  __ store_ptr(1, G3_scratch);  // put b at 1
D
duke 已提交
1026 1027 1028 1029 1030 1031
  // stack: ..., c, a, b, c
}


void TemplateTable::dup2() {
  transition(vtos, vtos);
1032 1033 1034 1035
  __ load_ptr(1, G3_scratch);  // get a
  __ load_ptr(0, Otos_l1);     // get b
  __ push_ptr(G3_scratch);     // push a
  __ push_ptr(Otos_l1);        // push b
D
duke 已提交
1036 1037 1038 1039 1040 1041 1042
  // stack: ..., a, b, a, b
}


void TemplateTable::dup2_x1() {
  transition(vtos, vtos);
  // stack: ..., a, b, c
1043 1044 1045
  __ load_ptr( 1, Lscratch);    // get b
  __ load_ptr( 2, Otos_l1);     // get a
  __ store_ptr(2, Lscratch);    // put b at a
D
duke 已提交
1046
  // stack: ..., b, b, c
1047 1048
  __ load_ptr( 0, G3_scratch);  // get c
  __ store_ptr(1, G3_scratch);  // put c at b
D
duke 已提交
1049
  // stack: ..., b, c, c
1050
  __ store_ptr(0, Otos_l1);     // put a at c
D
duke 已提交
1051
  // stack: ..., b, c, a
1052 1053
  __ push_ptr(Lscratch);        // push b
  __ push_ptr(G3_scratch);      // push c
D
duke 已提交
1054 1055 1056 1057 1058 1059 1060 1061 1062
  // stack: ..., b, c, a, b, c
}


// The spec says that these types can be a mixture of category 1 (1 word)
// types and/or category 2 types (long and doubles)
void TemplateTable::dup2_x2() {
  transition(vtos, vtos);
  // stack: ..., a, b, c, d
1063 1064 1065 1066
  __ load_ptr( 1, Lscratch);    // get c
  __ load_ptr( 3, Otos_l1);     // get a
  __ store_ptr(3, Lscratch);    // put c at 3
  __ store_ptr(1, Otos_l1);     // put a at 1
D
duke 已提交
1067
  // stack: ..., c, b, a, d
1068 1069 1070 1071
  __ load_ptr( 2, G3_scratch);  // get b
  __ load_ptr( 0, Otos_l1);     // get d
  __ store_ptr(0, G3_scratch);  // put b at 0
  __ store_ptr(2, Otos_l1);     // put d at 2
D
duke 已提交
1072
  // stack: ..., c, d, a, b
1073 1074
  __ push_ptr(Lscratch);        // push c
  __ push_ptr(Otos_l1);         // push d
D
duke 已提交
1075 1076 1077 1078 1079 1080 1081
  // stack: ..., c, d, a, b, c, d
}


void TemplateTable::swap() {
  transition(vtos, vtos);
  // stack: ..., a, b
1082 1083 1084 1085
  __ load_ptr( 1, G3_scratch);  // get a
  __ load_ptr( 0, Otos_l1);     // get b
  __ store_ptr(0, G3_scratch);  // put b
  __ store_ptr(1, Otos_l1);     // put a
D
duke 已提交
1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097
  // stack: ..., b, a
}


void TemplateTable::iop2(Operation op) {
  transition(itos, itos);
  __ pop_i(O1);
  switch (op) {
   case  add:  __  add(O1, Otos_i, Otos_i);  break;
   case  sub:  __  sub(O1, Otos_i, Otos_i);  break;
     // %%%%% Mul may not exist: better to call .mul?
   case  mul:  __ smul(O1, Otos_i, Otos_i);  break;
1098 1099 1100
   case _and:  __ and3(O1, Otos_i, Otos_i);  break;
   case  _or:  __  or3(O1, Otos_i, Otos_i);  break;
   case _xor:  __ xor3(O1, Otos_i, Otos_i);  break;
D
duke 已提交
1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113
   case  shl:  __  sll(O1, Otos_i, Otos_i);  break;
   case  shr:  __  sra(O1, Otos_i, Otos_i);  break;
   case ushr:  __  srl(O1, Otos_i, Otos_i);  break;
   default: ShouldNotReachHere();
  }
}


void TemplateTable::lop2(Operation op) {
  transition(ltos, ltos);
  __ pop_l(O2);
  switch (op) {
#ifdef _LP64
1114 1115 1116 1117 1118
   case  add:  __  add(O2, Otos_l, Otos_l);  break;
   case  sub:  __  sub(O2, Otos_l, Otos_l);  break;
   case _and:  __ and3(O2, Otos_l, Otos_l);  break;
   case  _or:  __  or3(O2, Otos_l, Otos_l);  break;
   case _xor:  __ xor3(O2, Otos_l, Otos_l);  break;
D
duke 已提交
1119 1120 1121
#else
   case  add:  __ addcc(O3, Otos_l2, Otos_l2);  __ addc(O2, Otos_l1, Otos_l1);  break;
   case  sub:  __ subcc(O3, Otos_l2, Otos_l2);  __ subc(O2, Otos_l1, Otos_l1);  break;
1122 1123 1124
   case _and:  __  and3(O3, Otos_l2, Otos_l2);  __ and3(O2, Otos_l1, Otos_l1);  break;
   case  _or:  __   or3(O3, Otos_l2, Otos_l2);  __  or3(O2, Otos_l1, Otos_l1);  break;
   case _xor:  __  xor3(O3, Otos_l2, Otos_l2);  __ xor3(O2, Otos_l1, Otos_l1);  break;
D
duke 已提交
1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359
#endif
   default: ShouldNotReachHere();
  }
}


void TemplateTable::idiv() {
  // %%%%% Later: ForSPARC/V7 call .sdiv library routine,
  // %%%%% Use ldsw...sdivx on pure V9 ABI. 64 bit safe.

  transition(itos, itos);
  __ pop_i(O1); // get 1st op

  // Y contains upper 32 bits of result, set it to 0 or all ones
  __ wry(G0);
  __ mov(~0, G3_scratch);

  __ tst(O1);
     Label neg;
  __ br(Assembler::negative, true, Assembler::pn, neg);
  __ delayed()->wry(G3_scratch);
  __ bind(neg);

     Label ok;
  __ tst(Otos_i);
  __ throw_if_not_icc( Assembler::notZero, Interpreter::_throw_ArithmeticException_entry, G3_scratch );

  const int min_int = 0x80000000;
  Label regular;
  __ cmp(Otos_i, -1);
  __ br(Assembler::notEqual, false, Assembler::pt, regular);
#ifdef _LP64
  // Don't put set in delay slot
  // Set will turn into multiple instructions in 64 bit mode
  __ delayed()->nop();
  __ set(min_int, G4_scratch);
#else
  __ delayed()->set(min_int, G4_scratch);
#endif
  Label done;
  __ cmp(O1, G4_scratch);
  __ br(Assembler::equal, true, Assembler::pt, done);
  __ delayed()->mov(O1, Otos_i);   // (mov only executed if branch taken)

  __ bind(regular);
  __ sdiv(O1, Otos_i, Otos_i); // note: irem uses O1 after this instruction!
  __ bind(done);
}


void TemplateTable::irem() {
  transition(itos, itos);
  __ mov(Otos_i, O2); // save divisor
  idiv();                               // %%%% Hack: exploits fact that idiv leaves dividend in O1
  __ smul(Otos_i, O2, Otos_i);
  __ sub(O1, Otos_i, Otos_i);
}


void TemplateTable::lmul() {
  transition(ltos, ltos);
  __ pop_l(O2);
#ifdef _LP64
  __ mulx(Otos_l, O2, Otos_l);
#else
  __ call_VM_leaf(Lscratch, CAST_FROM_FN_PTR(address, SharedRuntime::lmul));
#endif

}


void TemplateTable::ldiv() {
  transition(ltos, ltos);

  // check for zero
  __ pop_l(O2);
#ifdef _LP64
  __ tst(Otos_l);
  __ throw_if_not_xcc( Assembler::notZero, Interpreter::_throw_ArithmeticException_entry, G3_scratch);
  __ sdivx(O2, Otos_l, Otos_l);
#else
  __ orcc(Otos_l1, Otos_l2, G0);
  __ throw_if_not_icc( Assembler::notZero, Interpreter::_throw_ArithmeticException_entry, G3_scratch);
  __ call_VM_leaf(Lscratch, CAST_FROM_FN_PTR(address, SharedRuntime::ldiv));
#endif
}


void TemplateTable::lrem() {
  transition(ltos, ltos);

  // check for zero
  __ pop_l(O2);
#ifdef _LP64
  __ tst(Otos_l);
  __ throw_if_not_xcc( Assembler::notZero, Interpreter::_throw_ArithmeticException_entry, G3_scratch);
  __ sdivx(O2, Otos_l, Otos_l2);
  __ mulx (Otos_l2, Otos_l, Otos_l2);
  __ sub  (O2, Otos_l2, Otos_l);
#else
  __ orcc(Otos_l1, Otos_l2, G0);
  __ throw_if_not_icc(Assembler::notZero, Interpreter::_throw_ArithmeticException_entry, G3_scratch);
  __ call_VM_leaf(Lscratch, CAST_FROM_FN_PTR(address, SharedRuntime::lrem));
#endif
}


void TemplateTable::lshl() {
  transition(itos, ltos); // %%%% could optimize, fill delay slot or opt for ultra

  __ pop_l(O2);                          // shift value in O2, O3
#ifdef _LP64
  __ sllx(O2, Otos_i, Otos_l);
#else
  __ lshl(O2, O3, Otos_i, Otos_l1, Otos_l2, O4);
#endif
}


void TemplateTable::lshr() {
  transition(itos, ltos); // %%%% see lshl comment

  __ pop_l(O2);                          // shift value in O2, O3
#ifdef _LP64
  __ srax(O2, Otos_i, Otos_l);
#else
  __ lshr(O2, O3, Otos_i, Otos_l1, Otos_l2, O4);
#endif
}



void TemplateTable::lushr() {
  transition(itos, ltos); // %%%% see lshl comment

  __ pop_l(O2);                          // shift value in O2, O3
#ifdef _LP64
  __ srlx(O2, Otos_i, Otos_l);
#else
  __ lushr(O2, O3, Otos_i, Otos_l1, Otos_l2, O4);
#endif
}


void TemplateTable::fop2(Operation op) {
  transition(ftos, ftos);
  switch (op) {
   case  add:  __  pop_f(F4); __ fadd(FloatRegisterImpl::S, F4, Ftos_f, Ftos_f);  break;
   case  sub:  __  pop_f(F4); __ fsub(FloatRegisterImpl::S, F4, Ftos_f, Ftos_f);  break;
   case  mul:  __  pop_f(F4); __ fmul(FloatRegisterImpl::S, F4, Ftos_f, Ftos_f);  break;
   case  div:  __  pop_f(F4); __ fdiv(FloatRegisterImpl::S, F4, Ftos_f, Ftos_f);  break;
   case  rem:
     assert(Ftos_f == F0, "just checking");
#ifdef _LP64
     // LP64 calling conventions use F1, F3 for passing 2 floats
     __ pop_f(F1);
     __ fmov(FloatRegisterImpl::S, Ftos_f, F3);
#else
     __ pop_i(O0);
     __ stf(FloatRegisterImpl::S, Ftos_f, __ d_tmp);
     __ ld( __ d_tmp, O1 );
#endif
     __ call_VM_leaf(Lscratch, CAST_FROM_FN_PTR(address, SharedRuntime::frem));
     assert( Ftos_f == F0, "fix this code" );
     break;

   default: ShouldNotReachHere();
  }
}


void TemplateTable::dop2(Operation op) {
  transition(dtos, dtos);
  switch (op) {
   case  add:  __  pop_d(F4); __ fadd(FloatRegisterImpl::D, F4, Ftos_d, Ftos_d);  break;
   case  sub:  __  pop_d(F4); __ fsub(FloatRegisterImpl::D, F4, Ftos_d, Ftos_d);  break;
   case  mul:  __  pop_d(F4); __ fmul(FloatRegisterImpl::D, F4, Ftos_d, Ftos_d);  break;
   case  div:  __  pop_d(F4); __ fdiv(FloatRegisterImpl::D, F4, Ftos_d, Ftos_d);  break;
   case  rem:
#ifdef _LP64
     // Pass arguments in D0, D2
     __ fmov(FloatRegisterImpl::D, Ftos_f, F2 );
     __ pop_d( F0 );
#else
     // Pass arguments in O0O1, O2O3
     __ stf(FloatRegisterImpl::D, Ftos_f, __ d_tmp);
     __ ldd( __ d_tmp, O2 );
     __ pop_d(Ftos_f);
     __ stf(FloatRegisterImpl::D, Ftos_f, __ d_tmp);
     __ ldd( __ d_tmp, O0 );
#endif
     __ call_VM_leaf(Lscratch, CAST_FROM_FN_PTR(address, SharedRuntime::drem));
     assert( Ftos_d == F0, "fix this code" );
     break;

   default: ShouldNotReachHere();
  }
}


void TemplateTable::ineg() {
  transition(itos, itos);
  __ neg(Otos_i);
}


void TemplateTable::lneg() {
  transition(ltos, ltos);
#ifdef _LP64
  __ sub(G0, Otos_l, Otos_l);
#else
  __ lneg(Otos_l1, Otos_l2);
#endif
}


void TemplateTable::fneg() {
  transition(ftos, ftos);
  __ fneg(FloatRegisterImpl::S, Ftos_f);
}


void TemplateTable::dneg() {
  transition(dtos, dtos);
  // v8 has fnegd if source and dest are the same
  __ fneg(FloatRegisterImpl::D, Ftos_f);
}


void TemplateTable::iinc() {
  transition(vtos, vtos);
  locals_index(G3_scratch);
  __ ldsb(Lbcp, 2, O2);  // load constant
  __ access_local_int(G3_scratch, Otos_i);
  __ add(Otos_i, O2, Otos_i);
1360
  __ st(Otos_i, G3_scratch, 0);    // access_local_int puts E.A. in G3_scratch
D
duke 已提交
1361 1362 1363 1364 1365 1366 1367 1368 1369
}


void TemplateTable::wide_iinc() {
  transition(vtos, vtos);
  locals_index_wide(G3_scratch);
  __ get_2_byte_integer_at_bcp( 4,  O2, O3, InterpreterMacroAssembler::Signed);
  __ access_local_int(G3_scratch, Otos_i);
  __ add(Otos_i, O3, Otos_i);
1370
  __ st(Otos_i, G3_scratch, 0);    // access_local_int puts E.A. in G3_scratch
D
duke 已提交
1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597
}


void TemplateTable::convert() {
// %%%%% Factor this first part accross platforms
  #ifdef ASSERT
    TosState tos_in  = ilgl;
    TosState tos_out = ilgl;
    switch (bytecode()) {
      case Bytecodes::_i2l: // fall through
      case Bytecodes::_i2f: // fall through
      case Bytecodes::_i2d: // fall through
      case Bytecodes::_i2b: // fall through
      case Bytecodes::_i2c: // fall through
      case Bytecodes::_i2s: tos_in = itos; break;
      case Bytecodes::_l2i: // fall through
      case Bytecodes::_l2f: // fall through
      case Bytecodes::_l2d: tos_in = ltos; break;
      case Bytecodes::_f2i: // fall through
      case Bytecodes::_f2l: // fall through
      case Bytecodes::_f2d: tos_in = ftos; break;
      case Bytecodes::_d2i: // fall through
      case Bytecodes::_d2l: // fall through
      case Bytecodes::_d2f: tos_in = dtos; break;
      default             : ShouldNotReachHere();
    }
    switch (bytecode()) {
      case Bytecodes::_l2i: // fall through
      case Bytecodes::_f2i: // fall through
      case Bytecodes::_d2i: // fall through
      case Bytecodes::_i2b: // fall through
      case Bytecodes::_i2c: // fall through
      case Bytecodes::_i2s: tos_out = itos; break;
      case Bytecodes::_i2l: // fall through
      case Bytecodes::_f2l: // fall through
      case Bytecodes::_d2l: tos_out = ltos; break;
      case Bytecodes::_i2f: // fall through
      case Bytecodes::_l2f: // fall through
      case Bytecodes::_d2f: tos_out = ftos; break;
      case Bytecodes::_i2d: // fall through
      case Bytecodes::_l2d: // fall through
      case Bytecodes::_f2d: tos_out = dtos; break;
      default             : ShouldNotReachHere();
    }
    transition(tos_in, tos_out);
  #endif


  // Conversion
  Label done;
  switch (bytecode()) {
   case Bytecodes::_i2l:
#ifdef _LP64
    // Sign extend the 32 bits
    __ sra ( Otos_i, 0, Otos_l );
#else
    __ addcc(Otos_i, 0, Otos_l2);
    __ br(Assembler::greaterEqual, true, Assembler::pt, done);
    __ delayed()->clr(Otos_l1);
    __ set(~0, Otos_l1);
#endif
    break;

   case Bytecodes::_i2f:
    __ st(Otos_i, __ d_tmp );
    __ ldf(FloatRegisterImpl::S,  __ d_tmp, F0);
    __ fitof(FloatRegisterImpl::S, F0, Ftos_f);
    break;

   case Bytecodes::_i2d:
    __ st(Otos_i, __ d_tmp);
    __ ldf(FloatRegisterImpl::S,  __ d_tmp, F0);
    __ fitof(FloatRegisterImpl::D, F0, Ftos_f);
    break;

   case Bytecodes::_i2b:
    __ sll(Otos_i, 24, Otos_i);
    __ sra(Otos_i, 24, Otos_i);
    break;

   case Bytecodes::_i2c:
    __ sll(Otos_i, 16, Otos_i);
    __ srl(Otos_i, 16, Otos_i);
    break;

   case Bytecodes::_i2s:
    __ sll(Otos_i, 16, Otos_i);
    __ sra(Otos_i, 16, Otos_i);
    break;

   case Bytecodes::_l2i:
#ifndef _LP64
    __ mov(Otos_l2, Otos_i);
#else
    // Sign-extend into the high 32 bits
    __ sra(Otos_l, 0, Otos_i);
#endif
    break;

   case Bytecodes::_l2f:
   case Bytecodes::_l2d:
    __ st_long(Otos_l, __ d_tmp);
    __ ldf(FloatRegisterImpl::D, __ d_tmp, Ftos_d);

    if (VM_Version::v9_instructions_work()) {
      if (bytecode() == Bytecodes::_l2f) {
        __ fxtof(FloatRegisterImpl::S, Ftos_d, Ftos_f);
      } else {
        __ fxtof(FloatRegisterImpl::D, Ftos_d, Ftos_d);
      }
    } else {
      __ call_VM_leaf(
        Lscratch,
        bytecode() == Bytecodes::_l2f
          ? CAST_FROM_FN_PTR(address, SharedRuntime::l2f)
          : CAST_FROM_FN_PTR(address, SharedRuntime::l2d)
      );
    }
    break;

  case Bytecodes::_f2i:  {
      Label isNaN;
      // result must be 0 if value is NaN; test by comparing value to itself
      __ fcmp(FloatRegisterImpl::S, Assembler::fcc0, Ftos_f, Ftos_f);
      // According to the v8 manual, you have to have a non-fp instruction
      // between fcmp and fb.
      if (!VM_Version::v9_instructions_work()) {
        __ nop();
      }
      __ fb(Assembler::f_unordered, true, Assembler::pn, isNaN);
      __ delayed()->clr(Otos_i);                                     // NaN
      __ ftoi(FloatRegisterImpl::S, Ftos_f, F30);
      __ stf(FloatRegisterImpl::S, F30, __ d_tmp);
      __ ld(__ d_tmp, Otos_i);
      __ bind(isNaN);
    }
    break;

   case Bytecodes::_f2l:
    // must uncache tos
    __ push_f();
#ifdef _LP64
    __ pop_f(F1);
#else
    __ pop_i(O0);
#endif
    __ call_VM_leaf(Lscratch, CAST_FROM_FN_PTR(address, SharedRuntime::f2l));
    break;

   case Bytecodes::_f2d:
    __ ftof( FloatRegisterImpl::S, FloatRegisterImpl::D, Ftos_f, Ftos_f);
    break;

   case Bytecodes::_d2i:
   case Bytecodes::_d2l:
    // must uncache tos
    __ push_d();
#ifdef _LP64
    // LP64 calling conventions pass first double arg in D0
    __ pop_d( Ftos_d );
#else
    __ pop_i( O0 );
    __ pop_i( O1 );
#endif
    __ call_VM_leaf(Lscratch,
        bytecode() == Bytecodes::_d2i
          ? CAST_FROM_FN_PTR(address, SharedRuntime::d2i)
          : CAST_FROM_FN_PTR(address, SharedRuntime::d2l));
    break;

    case Bytecodes::_d2f:
    if (VM_Version::v9_instructions_work()) {
      __ ftof( FloatRegisterImpl::D, FloatRegisterImpl::S, Ftos_d, Ftos_f);
    }
    else {
      // must uncache tos
      __ push_d();
      __ pop_i(O0);
      __ pop_i(O1);
      __ call_VM_leaf(Lscratch, CAST_FROM_FN_PTR(address, SharedRuntime::d2f));
    }
    break;

    default: ShouldNotReachHere();
  }
  __ bind(done);
}


void TemplateTable::lcmp() {
  transition(ltos, itos);

#ifdef _LP64
  __ pop_l(O1); // pop off value 1, value 2 is in O0
  __ lcmp( O1, Otos_l, Otos_i );
#else
  __ pop_l(O2); // cmp O2,3 to O0,1
  __ lcmp( O2, O3, Otos_l1, Otos_l2, Otos_i );
#endif
}


void TemplateTable::float_cmp(bool is_float, int unordered_result) {

  if (is_float) __ pop_f(F2);
  else          __ pop_d(F2);

  assert(Ftos_f == F0  &&  Ftos_d == F0,  "alias checking:");

  __ float_cmp( is_float, unordered_result, F2, F0, Otos_i );
}

void TemplateTable::branch(bool is_jsr, bool is_wide) {
  // Note: on SPARC, we use InterpreterMacroAssembler::if_cmp also.
  __ verify_oop(Lmethod);
  __ verify_thread();

  const Register O2_bumped_count = O2;
  __ profile_taken_branch(G3_scratch, O2_bumped_count);

  // get (wide) offset to O1_disp
  const Register O1_disp = O1;
  if (is_wide)  __ get_4_byte_integer_at_bcp( 1,  G4_scratch, O1_disp,                                    InterpreterMacroAssembler::set_CC);
  else          __ get_2_byte_integer_at_bcp( 1,  G4_scratch, O1_disp, InterpreterMacroAssembler::Signed, InterpreterMacroAssembler::set_CC);

  // Handle all the JSR stuff here, then exit.
  // It's much shorter and cleaner than intermingling with the
T
twisti 已提交
1598
  // non-JSR normal-branch stuff occurring below.
D
duke 已提交
1599 1600
  if( is_jsr ) {
    // compute return address as bci in Otos_i
1601
    __ ld_ptr(Lmethod, methodOopDesc::const_offset(), G3_scratch);
D
duke 已提交
1602 1603 1604 1605 1606 1607
    __ sub(Lbcp, G3_scratch, G3_scratch);
    __ sub(G3_scratch, in_bytes(constMethodOopDesc::codes_offset()) - (is_wide ? 5 : 3), Otos_i);

    // Bump Lbcp to target of JSR
    __ add(Lbcp, O1_disp, Lbcp);
    // Push returnAddress for "ret" on stack
1608
    __ push_ptr(Otos_i);
D
duke 已提交
1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619
    // And away we go!
    __ dispatch_next(vtos);
    return;
  }

  // Normal (non-jsr) branch handling

  // Save the current Lbcp
  const Register O0_cur_bcp = O0;
  __ mov( Lbcp, O0_cur_bcp );

I
iveresov 已提交
1620

D
duke 已提交
1621 1622 1623 1624 1625 1626 1627 1628
  bool increment_invocation_counter_for_backward_branches = UseCompiler && UseLoopCounter;
  if ( increment_invocation_counter_for_backward_branches ) {
    Label Lforward;
    // check branch direction
    __ br( Assembler::positive, false,  Assembler::pn, Lforward );
    // Bump bytecode pointer by displacement (take the branch)
    __ delayed()->add( O1_disp, Lbcp, Lbcp );     // add to bc addr

I
iveresov 已提交
1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645
    if (TieredCompilation) {
      Label Lno_mdo, Loverflow;
      int increment = InvocationCounter::count_increment;
      int mask = ((1 << Tier0BackedgeNotifyFreqLog) - 1) << InvocationCounter::count_shift;
      if (ProfileInterpreter) {
        // If no method data exists, go to profile_continue.
        __ ld_ptr(Lmethod, methodOopDesc::method_data_offset(), G4_scratch);
        __ br_null(G4_scratch, false, Assembler::pn, Lno_mdo);
        __ delayed()->nop();

        // Increment backedge counter in the MDO
        Address mdo_backedge_counter(G4_scratch, in_bytes(methodDataOopDesc::backedge_counter_offset()) +
                                                 in_bytes(InvocationCounter::counter_offset()));
        __ increment_mask_and_jump(mdo_backedge_counter, increment, mask, G3_scratch, Lscratch,
                                   Assembler::notZero, &Lforward);
        __ ba(false, Loverflow);
        __ delayed()->nop();
D
duke 已提交
1646
      }
I
iveresov 已提交
1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693

      // If there's no MDO, increment counter in methodOop
      __ bind(Lno_mdo);
      Address backedge_counter(Lmethod, in_bytes(methodOopDesc::backedge_counter_offset()) +
                                        in_bytes(InvocationCounter::counter_offset()));
      __ increment_mask_and_jump(backedge_counter, increment, mask, G3_scratch, Lscratch,
                                 Assembler::notZero, &Lforward);
      __ bind(Loverflow);

      // notify point for loop, pass branch bytecode
      __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::frequency_counter_overflow), O0_cur_bcp);

      // Was an OSR adapter generated?
      // O0 = osr nmethod
      __ br_null(O0, false, Assembler::pn, Lforward);
      __ delayed()->nop();

      // Has the nmethod been invalidated already?
      __ ld(O0, nmethod::entry_bci_offset(), O2);
      __ cmp(O2, InvalidOSREntryBci);
      __ br(Assembler::equal, false, Assembler::pn, Lforward);
      __ delayed()->nop();

      // migrate the interpreter frame off of the stack

      __ mov(G2_thread, L7);
      // save nmethod
      __ mov(O0, L6);
      __ set_last_Java_frame(SP, noreg);
      __ call_VM_leaf(noreg, CAST_FROM_FN_PTR(address, SharedRuntime::OSR_migration_begin), L7);
      __ reset_last_Java_frame();
      __ mov(L7, G2_thread);

      // move OSR nmethod to I1
      __ mov(L6, I1);

      // OSR buffer to I0
      __ mov(O0, I0);

      // remove the interpreter frame
      __ restore(I5_savedSP, 0, SP);

      // Jump to the osr code.
      __ ld_ptr(O1, nmethod::osr_entry_point_offset(), O2);
      __ jmp(O2, G0);
      __ delayed()->nop();

D
duke 已提交
1694
    } else {
I
iveresov 已提交
1695 1696 1697 1698
      // Update Backedge branch separately from invocations
      const Register G4_invoke_ctr = G4;
      __ increment_backedge_counter(G4_invoke_ctr, G1_scratch);
      if (ProfileInterpreter) {
1699
        __ test_invocation_counter_for_mdp(G4_invoke_ctr, G3_scratch, Lforward);
I
iveresov 已提交
1700 1701 1702 1703 1704 1705 1706
        if (UseOnStackReplacement) {
          __ test_backedge_count_for_osr(O2_bumped_count, O0_cur_bcp, G3_scratch);
        }
      } else {
        if (UseOnStackReplacement) {
          __ test_backedge_count_for_osr(G4_invoke_ctr, O0_cur_bcp, G3_scratch);
        }
D
duke 已提交
1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785
      }
    }

    __ bind(Lforward);
  } else
    // Bump bytecode pointer by displacement (take the branch)
    __ add( O1_disp, Lbcp, Lbcp );// add to bc addr

  // continue with bytecode @ target
  // %%%%% Like Intel, could speed things up by moving bytecode fetch to code above,
  // %%%%% and changing dispatch_next to dispatch_only
  __ dispatch_next(vtos);
}


// Note Condition in argument is TemplateTable::Condition
// arg scope is within class scope

void TemplateTable::if_0cmp(Condition cc) {
  // no pointers, integer only!
  transition(itos, vtos);
  // assume branch is more often taken than not (loops use backward branches)
  __ cmp( Otos_i, 0);
  __ if_cmp(ccNot(cc), false);
}


void TemplateTable::if_icmp(Condition cc) {
  transition(itos, vtos);
  __ pop_i(O1);
  __ cmp(O1, Otos_i);
  __ if_cmp(ccNot(cc), false);
}


void TemplateTable::if_nullcmp(Condition cc) {
  transition(atos, vtos);
  __ tst(Otos_i);
  __ if_cmp(ccNot(cc), true);
}


void TemplateTable::if_acmp(Condition cc) {
  transition(atos, vtos);
  __ pop_ptr(O1);
  __ verify_oop(O1);
  __ verify_oop(Otos_i);
  __ cmp(O1, Otos_i);
  __ if_cmp(ccNot(cc), true);
}



void TemplateTable::ret() {
  transition(vtos, vtos);
  locals_index(G3_scratch);
  __ access_local_returnAddress(G3_scratch, Otos_i);
  // Otos_i contains the bci, compute the bcp from that

#ifdef _LP64
#ifdef ASSERT
  // jsr result was labeled as an 'itos' not an 'atos' because we cannot GC
  // the result.  The return address (really a BCI) was stored with an
  // 'astore' because JVM specs claim it's a pointer-sized thing.  Hence in
  // the 64-bit build the 32-bit BCI is actually in the low bits of a 64-bit
  // loaded value.
  { Label zzz ;
     __ set (65536, G3_scratch) ;
     __ cmp (Otos_i, G3_scratch) ;
     __ bp( Assembler::lessEqualUnsigned, false, Assembler::xcc, Assembler::pn, zzz);
     __ delayed()->nop();
     __ stop("BCI is in the wrong register half?");
     __ bind (zzz) ;
  }
#endif
#endif

  __ profile_ret(vtos, Otos_i, G4_scratch);

1786
  __ ld_ptr(Lmethod, methodOopDesc::const_offset(), G3_scratch);
D
duke 已提交
1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800
  __ add(G3_scratch, Otos_i, G3_scratch);
  __ add(G3_scratch, in_bytes(constMethodOopDesc::codes_offset()), Lbcp);
  __ dispatch_next(vtos);
}


void TemplateTable::wide_ret() {
  transition(vtos, vtos);
  locals_index_wide(G3_scratch);
  __ access_local_returnAddress(G3_scratch, Otos_i);
  // Otos_i contains the bci, compute the bcp from that

  __ profile_ret(vtos, Otos_i, G4_scratch);

1801
  __ ld_ptr(Lmethod, methodOopDesc::const_offset(), G3_scratch);
D
duke 已提交
1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025
  __ add(G3_scratch, Otos_i, G3_scratch);
  __ add(G3_scratch, in_bytes(constMethodOopDesc::codes_offset()), Lbcp);
  __ dispatch_next(vtos);
}


void TemplateTable::tableswitch() {
  transition(itos, vtos);
  Label default_case, continue_execution;

  // align bcp
  __ add(Lbcp, BytesPerInt, O1);
  __ and3(O1, -BytesPerInt, O1);
  // load lo, hi
  __ ld(O1, 1 * BytesPerInt, O2);       // Low Byte
  __ ld(O1, 2 * BytesPerInt, O3);       // High Byte
#ifdef _LP64
  // Sign extend the 32 bits
  __ sra ( Otos_i, 0, Otos_i );
#endif /* _LP64 */

  // check against lo & hi
  __ cmp( Otos_i, O2);
  __ br( Assembler::less, false, Assembler::pn, default_case);
  __ delayed()->cmp( Otos_i, O3 );
  __ br( Assembler::greater, false, Assembler::pn, default_case);
  // lookup dispatch offset
  __ delayed()->sub(Otos_i, O2, O2);
  __ profile_switch_case(O2, O3, G3_scratch, G4_scratch);
  __ sll(O2, LogBytesPerInt, O2);
  __ add(O2, 3 * BytesPerInt, O2);
  __ ba(false, continue_execution);
  __ delayed()->ld(O1, O2, O2);
  // handle default
  __ bind(default_case);
  __ profile_switch_default(O3);
  __ ld(O1, 0, O2); // get default offset
  // continue execution
  __ bind(continue_execution);
  __ add(Lbcp, O2, Lbcp);
  __ dispatch_next(vtos);
}


void TemplateTable::lookupswitch() {
  transition(itos, itos);
  __ stop("lookupswitch bytecode should have been rewritten");
}

void TemplateTable::fast_linearswitch() {
  transition(itos, vtos);
    Label loop_entry, loop, found, continue_execution;
  // align bcp
  __ add(Lbcp, BytesPerInt, O1);
  __ and3(O1, -BytesPerInt, O1);
 // set counter
  __ ld(O1, BytesPerInt, O2);
  __ sll(O2, LogBytesPerInt + 1, O2); // in word-pairs
  __ add(O1, 2 * BytesPerInt, O3); // set first pair addr
  __ ba(false, loop_entry);
  __ delayed()->add(O3, O2, O2); // counter now points past last pair

  // table search
  __ bind(loop);
  __ cmp(O4, Otos_i);
  __ br(Assembler::equal, true, Assembler::pn, found);
  __ delayed()->ld(O3, BytesPerInt, O4); // offset -> O4
  __ inc(O3, 2 * BytesPerInt);

  __ bind(loop_entry);
  __ cmp(O2, O3);
  __ brx(Assembler::greaterUnsigned, true, Assembler::pt, loop);
  __ delayed()->ld(O3, 0, O4);

  // default case
  __ ld(O1, 0, O4); // get default offset
  if (ProfileInterpreter) {
    __ profile_switch_default(O3);
    __ ba(false, continue_execution);
    __ delayed()->nop();
  }

  // entry found -> get offset
  __ bind(found);
  if (ProfileInterpreter) {
    __ sub(O3, O1, O3);
    __ sub(O3, 2*BytesPerInt, O3);
    __ srl(O3, LogBytesPerInt + 1, O3); // in word-pairs
    __ profile_switch_case(O3, O1, O2, G3_scratch);

    __ bind(continue_execution);
  }
  __ add(Lbcp, O4, Lbcp);
  __ dispatch_next(vtos);
}


void TemplateTable::fast_binaryswitch() {
  transition(itos, vtos);
  // Implementation using the following core algorithm: (copied from Intel)
  //
  // int binary_search(int key, LookupswitchPair* array, int n) {
  //   // Binary search according to "Methodik des Programmierens" by
  //   // Edsger W. Dijkstra and W.H.J. Feijen, Addison Wesley Germany 1985.
  //   int i = 0;
  //   int j = n;
  //   while (i+1 < j) {
  //     // invariant P: 0 <= i < j <= n and (a[i] <= key < a[j] or Q)
  //     // with      Q: for all i: 0 <= i < n: key < a[i]
  //     // where a stands for the array and assuming that the (inexisting)
  //     // element a[n] is infinitely big.
  //     int h = (i + j) >> 1;
  //     // i < h < j
  //     if (key < array[h].fast_match()) {
  //       j = h;
  //     } else {
  //       i = h;
  //     }
  //   }
  //   // R: a[i] <= key < a[i+1] or Q
  //   // (i.e., if key is within array, i is the correct index)
  //   return i;
  // }

  // register allocation
  assert(Otos_i == O0, "alias checking");
  const Register Rkey     = Otos_i;                    // already set (tosca)
  const Register Rarray   = O1;
  const Register Ri       = O2;
  const Register Rj       = O3;
  const Register Rh       = O4;
  const Register Rscratch = O5;

  const int log_entry_size = 3;
  const int entry_size = 1 << log_entry_size;

  Label found;
  // Find Array start
  __ add(Lbcp, 3 * BytesPerInt, Rarray);
  __ and3(Rarray, -BytesPerInt, Rarray);
  // initialize i & j (in delay slot)
  __ clr( Ri );

  // and start
  Label entry;
  __ ba(false, entry);
  __ delayed()->ld( Rarray, -BytesPerInt, Rj);
  // (Rj is already in the native byte-ordering.)

  // binary search loop
  { Label loop;
    __ bind( loop );
    // int h = (i + j) >> 1;
    __ sra( Rh, 1, Rh );
    // if (key < array[h].fast_match()) {
    //   j = h;
    // } else {
    //   i = h;
    // }
    __ sll( Rh, log_entry_size, Rscratch );
    __ ld( Rarray, Rscratch, Rscratch );
    // (Rscratch is already in the native byte-ordering.)
    __ cmp( Rkey, Rscratch );
    if ( VM_Version::v9_instructions_work() ) {
      __ movcc( Assembler::less,         false, Assembler::icc, Rh, Rj );  // j = h if (key <  array[h].fast_match())
      __ movcc( Assembler::greaterEqual, false, Assembler::icc, Rh, Ri );  // i = h if (key >= array[h].fast_match())
    }
    else {
      Label end_of_if;
      __ br( Assembler::less, true, Assembler::pt, end_of_if );
      __ delayed()->mov( Rh, Rj ); // if (<) Rj = Rh
      __ mov( Rh, Ri );            // else i = h
      __ bind(end_of_if);          // }
    }

    // while (i+1 < j)
    __ bind( entry );
    __ add( Ri, 1, Rscratch );
    __ cmp(Rscratch, Rj);
    __ br( Assembler::less, true, Assembler::pt, loop );
    __ delayed()->add( Ri, Rj, Rh ); // start h = i + j  >> 1;
  }

  // end of binary search, result index is i (must check again!)
  Label default_case;
  Label continue_execution;
  if (ProfileInterpreter) {
    __ mov( Ri, Rh );              // Save index in i for profiling
  }
  __ sll( Ri, log_entry_size, Ri );
  __ ld( Rarray, Ri, Rscratch );
  // (Rscratch is already in the native byte-ordering.)
  __ cmp( Rkey, Rscratch );
  __ br( Assembler::notEqual, true, Assembler::pn, default_case );
  __ delayed()->ld( Rarray, -2 * BytesPerInt, Rj ); // load default offset -> j

  // entry found -> j = offset
  __ inc( Ri, BytesPerInt );
  __ profile_switch_case(Rh, Rj, Rscratch, Rkey);
  __ ld( Rarray, Ri, Rj );
  // (Rj is already in the native byte-ordering.)

  if (ProfileInterpreter) {
    __ ba(false, continue_execution);
    __ delayed()->nop();
  }

  __ bind(default_case); // fall through (if not profiling)
  __ profile_switch_default(Ri);

  __ bind(continue_execution);
  __ add( Lbcp, Rj, Lbcp );
  __ dispatch_next( vtos );
}


void TemplateTable::_return(TosState state) {
  transition(state, state);
  assert(_desc->calls_vm(), "inconsistent calls_vm information");

  if (_desc->bytecode() == Bytecodes::_return_register_finalizer) {
    assert(state == vtos, "only valid state");
    __ mov(G0, G3_scratch);
    __ access_local_ptr(G3_scratch, Otos_i);
2026
    __ load_klass(Otos_i, O2);
D
duke 已提交
2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081
    __ set(JVM_ACC_HAS_FINALIZER, G3);
    __ ld(O2, Klass::access_flags_offset_in_bytes() + sizeof(oopDesc), O2);
    __ andcc(G3, O2, G0);
    Label skip_register_finalizer;
    __ br(Assembler::zero, false, Assembler::pn, skip_register_finalizer);
    __ delayed()->nop();

    // Call out to do finalizer registration
    __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::register_finalizer), Otos_i);

    __ bind(skip_register_finalizer);
  }

  __ remove_activation(state, /* throw_monitor_exception */ true);

  // The caller's SP was adjusted upon method entry to accomodate
  // the callee's non-argument locals. Undo that adjustment.
  __ ret();                             // return to caller
  __ delayed()->restore(I5_savedSP, G0, SP);
}


// ----------------------------------------------------------------------------
// Volatile variables demand their effects be made known to all CPU's in
// order.  Store buffers on most chips allow reads & writes to reorder; the
// JMM's ReadAfterWrite.java test fails in -Xint mode without some kind of
// memory barrier (i.e., it's not sufficient that the interpreter does not
// reorder volatile references, the hardware also must not reorder them).
//
// According to the new Java Memory Model (JMM):
// (1) All volatiles are serialized wrt to each other.
// ALSO reads & writes act as aquire & release, so:
// (2) A read cannot let unrelated NON-volatile memory refs that happen after
// the read float up to before the read.  It's OK for non-volatile memory refs
// that happen before the volatile read to float down below it.
// (3) Similar a volatile write cannot let unrelated NON-volatile memory refs
// that happen BEFORE the write float down to after the write.  It's OK for
// non-volatile memory refs that happen after the volatile write to float up
// before it.
//
// We only put in barriers around volatile refs (they are expensive), not
// _between_ memory refs (that would require us to track the flavor of the
// previous memory refs).  Requirements (2) and (3) require some barriers
// before volatile stores and after volatile loads.  These nearly cover
// requirement (1) but miss the volatile-store-volatile-load case.  This final
// case is placed after volatile-stores although it could just as well go
// before volatile-loads.
void TemplateTable::volatile_barrier(Assembler::Membar_mask_bits order_constraint) {
  // Helper function to insert a is-volatile test and memory barrier
  // All current sparc implementations run in TSO, needing only StoreLoad
  if ((order_constraint & Assembler::StoreLoad) == 0) return;
  __ membar( order_constraint );
}

// ----------------------------------------------------------------------------
2082 2083 2084 2085 2086
void TemplateTable::resolve_cache_and_index(int byte_no,
                                            Register result,
                                            Register Rcache,
                                            Register index,
                                            size_t index_size) {
D
duke 已提交
2087 2088 2089
  // Depends on cpCacheOop layout!
  Label resolved;

2090 2091 2092 2093 2094 2095
  __ get_cache_and_index_at_bcp(Rcache, index, 1, index_size);
  if (byte_no == f1_oop) {
    // We are resolved if the f1 field contains a non-null object (CallSite, etc.)
    // This kind of CP cache entry does not need to match the flags byte, because
    // there is a 1-1 relation between bytecode type and CP entry type.
    assert_different_registers(result, Rcache);
T
twisti 已提交
2096
    __ ld_ptr(Rcache, constantPoolCacheOopDesc::base_offset() +
2097 2098
              ConstantPoolCacheEntry::f1_offset(), result);
    __ tst(result);
T
twisti 已提交
2099 2100 2101
    __ br(Assembler::notEqual, false, Assembler::pt, resolved);
    __ delayed()->set((int)bytecode(), O1);
  } else {
2102 2103 2104 2105
    assert(byte_no == f1_byte || byte_no == f2_byte, "byte_no out of range");
    assert(result == noreg, "");  //else change code for setting result
    const int shift_count = (1 + byte_no)*BitsPerByte;

T
twisti 已提交
2106 2107 2108 2109 2110 2111 2112 2113 2114
    __ ld_ptr(Rcache, constantPoolCacheOopDesc::base_offset() +
              ConstantPoolCacheEntry::indices_offset(), Lbyte_code);

    __ srl(  Lbyte_code, shift_count, Lbyte_code );
    __ and3( Lbyte_code,        0xFF, Lbyte_code );
    __ cmp(  Lbyte_code, (int)bytecode());
    __ br(   Assembler::equal, false, Assembler::pt, resolved);
    __ delayed()->set((int)bytecode(), O1);
  }
D
duke 已提交
2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125

  address entry;
  switch (bytecode()) {
    case Bytecodes::_getstatic      : // fall through
    case Bytecodes::_putstatic      : // fall through
    case Bytecodes::_getfield       : // fall through
    case Bytecodes::_putfield       : entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_get_put); break;
    case Bytecodes::_invokevirtual  : // fall through
    case Bytecodes::_invokespecial  : // fall through
    case Bytecodes::_invokestatic   : // fall through
    case Bytecodes::_invokeinterface: entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_invoke);  break;
T
twisti 已提交
2126
    case Bytecodes::_invokedynamic  : entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_invokedynamic);  break;
2127 2128
    case Bytecodes::_fast_aldc      : entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_ldc);     break;
    case Bytecodes::_fast_aldc_w    : entry = CAST_FROM_FN_PTR(address, InterpreterRuntime::resolve_ldc);     break;
D
duke 已提交
2129 2130 2131 2132 2133
    default                         : ShouldNotReachHere();                                 break;
  }
  // first time invocation - must resolve first
  __ call_VM(noreg, entry, O1);
  // Update registers with resolved info
2134 2135 2136 2137
  __ get_cache_and_index_at_bcp(Rcache, index, 1, index_size);
  if (result != noreg)
    __ ld_ptr(Rcache, constantPoolCacheOopDesc::base_offset() +
              ConstantPoolCacheEntry::f1_offset(), result);
D
duke 已提交
2138 2139 2140 2141 2142 2143 2144 2145
  __ bind(resolved);
}

void TemplateTable::load_invoke_cp_cache_entry(int byte_no,
                                               Register Rmethod,
                                               Register Ritable_index,
                                               Register Rflags,
                                               bool is_invokevirtual,
2146 2147
                                               bool is_invokevfinal,
                                               bool is_invokedynamic) {
D
duke 已提交
2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170
  // Uses both G3_scratch and G4_scratch
  Register Rcache = G3_scratch;
  Register Rscratch = G4_scratch;
  assert_different_registers(Rcache, Rmethod, Ritable_index);

  ByteSize cp_base_offset = constantPoolCacheOopDesc::base_offset();

  // determine constant pool cache field offsets
  const int method_offset = in_bytes(
    cp_base_offset +
      (is_invokevirtual
       ? ConstantPoolCacheEntry::f2_offset()
       : ConstantPoolCacheEntry::f1_offset()
      )
    );
  const int flags_offset = in_bytes(cp_base_offset +
                                    ConstantPoolCacheEntry::flags_offset());
  // access constant pool cache fields
  const int index_offset = in_bytes(cp_base_offset +
                                    ConstantPoolCacheEntry::f2_offset());

  if (is_invokevfinal) {
    __ get_cache_and_index_at_bcp(Rcache, Rscratch, 1);
2171 2172 2173 2174
    __ ld_ptr(Rcache, method_offset, Rmethod);
  } else if (byte_no == f1_oop) {
    // Resolved f1_oop goes directly into 'method' register.
    resolve_cache_and_index(byte_no, Rmethod, Rcache, Rscratch, sizeof(u4));
D
duke 已提交
2175
  } else {
2176 2177
    resolve_cache_and_index(byte_no, noreg, Rcache, Rscratch, sizeof(u2));
    __ ld_ptr(Rcache, method_offset, Rmethod);
D
duke 已提交
2178 2179 2180
  }

  if (Ritable_index != noreg) {
2181
    __ ld_ptr(Rcache, index_offset, Ritable_index);
D
duke 已提交
2182
  }
2183
  __ ld_ptr(Rcache, flags_offset, Rflags);
D
duke 已提交
2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196
}

// The Rcache register must be set before call
void TemplateTable::load_field_cp_cache_entry(Register Robj,
                                              Register Rcache,
                                              Register index,
                                              Register Roffset,
                                              Register Rflags,
                                              bool is_static) {
  assert_different_registers(Rcache, Rflags, Roffset);

  ByteSize cp_base_offset = constantPoolCacheOopDesc::base_offset();

2197 2198
  __ ld_ptr(Rcache, cp_base_offset + ConstantPoolCacheEntry::flags_offset(), Rflags);
  __ ld_ptr(Rcache, cp_base_offset + ConstantPoolCacheEntry::f2_offset(), Roffset);
D
duke 已提交
2199
  if (is_static) {
2200
    __ ld_ptr(Rcache, cp_base_offset + ConstantPoolCacheEntry::f1_offset(), Robj);
D
duke 已提交
2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216
  }
}

// The registers Rcache and index expected to be set before call.
// Correct values of the Rcache and index registers are preserved.
void TemplateTable::jvmti_post_field_access(Register Rcache,
                                            Register index,
                                            bool is_static,
                                            bool has_tos) {
  ByteSize cp_base_offset = constantPoolCacheOopDesc::base_offset();

  if (JvmtiExport::can_post_field_access()) {
    // Check to see if a field access watch has been set before we take
    // the time to call into the VM.
    Label Label1;
    assert_different_registers(Rcache, index, G1_scratch);
2217
    AddressLiteral get_field_access_count_addr(JvmtiExport::get_field_access_count_addr());
D
duke 已提交
2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229
    __ load_contents(get_field_access_count_addr, G1_scratch);
    __ tst(G1_scratch);
    __ br(Assembler::zero, false, Assembler::pt, Label1);
    __ delayed()->nop();

    __ add(Rcache, in_bytes(cp_base_offset), Rcache);

    if (is_static) {
      __ clr(Otos_i);
    } else {
      if (has_tos) {
      // save object pointer before call_VM() clobbers it
2230
        __ push_ptr(Otos_i);  // put object on tos where GC wants it.
D
duke 已提交
2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241
      } else {
        // Load top of stack (do not pop the value off the stack);
        __ ld_ptr(Lesp, Interpreter::expr_offset_in_bytes(0), Otos_i);
      }
      __ verify_oop(Otos_i);
    }
    // Otos_i: object pointer or NULL if static
    // Rcache: cache entry pointer
    __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_access),
               Otos_i, Rcache);
    if (!is_static && has_tos) {
2242
      __ pop_ptr(Otos_i);  // restore object pointer
D
duke 已提交
2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259
      __ verify_oop(Otos_i);
    }
    __ get_cache_and_index_at_bcp(Rcache, index, 1);
    __ bind(Label1);
  }
}

void TemplateTable::getfield_or_static(int byte_no, bool is_static) {
  transition(vtos, vtos);

  Register Rcache = G3_scratch;
  Register index  = G4_scratch;
  Register Rclass = Rcache;
  Register Roffset= G4_scratch;
  Register Rflags = G1_scratch;
  ByteSize cp_base_offset = constantPoolCacheOopDesc::base_offset();

2260
  resolve_cache_and_index(byte_no, noreg, Rcache, index, sizeof(u2));
D
duke 已提交
2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294
  jvmti_post_field_access(Rcache, index, is_static, false);
  load_field_cp_cache_entry(Rclass, Rcache, index, Roffset, Rflags, is_static);

  if (!is_static) {
    pop_and_check_object(Rclass);
  } else {
    __ verify_oop(Rclass);
  }

  Label exit;

  Assembler::Membar_mask_bits membar_bits =
    Assembler::Membar_mask_bits(Assembler::LoadLoad | Assembler::LoadStore);

  if (__ membar_has_effect(membar_bits)) {
    // Get volatile flag
    __ set((1 << ConstantPoolCacheEntry::volatileField), Lscratch);
    __ and3(Rflags, Lscratch, Lscratch);
  }

  Label checkVolatile;

  // compute field type
  Label notByte, notInt, notShort, notChar, notLong, notFloat, notObj;
  __ srl(Rflags, ConstantPoolCacheEntry::tosBits, Rflags);
  // Make sure we don't need to mask Rflags for tosBits after the above shift
  ConstantPoolCacheEntry::verify_tosBits();

  // Check atos before itos for getstatic, more likely (in Queens at least)
  __ cmp(Rflags, atos);
  __ br(Assembler::notEqual, false, Assembler::pt, notObj);
  __ delayed() ->cmp(Rflags, itos);

  // atos
2295
  __ load_heap_oop(Rclass, Roffset, Otos_i);
D
duke 已提交
2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437
  __ verify_oop(Otos_i);
  __ push(atos);
  if (!is_static) {
    patch_bytecode(Bytecodes::_fast_agetfield, G3_scratch, G4_scratch);
  }
  __ ba(false, checkVolatile);
  __ delayed()->tst(Lscratch);

  __ bind(notObj);

  // cmp(Rflags, itos);
  __ br(Assembler::notEqual, false, Assembler::pt, notInt);
  __ delayed() ->cmp(Rflags, ltos);

  // itos
  __ ld(Rclass, Roffset, Otos_i);
  __ push(itos);
  if (!is_static) {
    patch_bytecode(Bytecodes::_fast_igetfield, G3_scratch, G4_scratch);
  }
  __ ba(false, checkVolatile);
  __ delayed()->tst(Lscratch);

  __ bind(notInt);

  // cmp(Rflags, ltos);
  __ br(Assembler::notEqual, false, Assembler::pt, notLong);
  __ delayed() ->cmp(Rflags, btos);

  // ltos
  // load must be atomic
  __ ld_long(Rclass, Roffset, Otos_l);
  __ push(ltos);
  if (!is_static) {
    patch_bytecode(Bytecodes::_fast_lgetfield, G3_scratch, G4_scratch);
  }
  __ ba(false, checkVolatile);
  __ delayed()->tst(Lscratch);

  __ bind(notLong);

  // cmp(Rflags, btos);
  __ br(Assembler::notEqual, false, Assembler::pt, notByte);
  __ delayed() ->cmp(Rflags, ctos);

  // btos
  __ ldsb(Rclass, Roffset, Otos_i);
  __ push(itos);
  if (!is_static) {
    patch_bytecode(Bytecodes::_fast_bgetfield, G3_scratch, G4_scratch);
  }
  __ ba(false, checkVolatile);
  __ delayed()->tst(Lscratch);

  __ bind(notByte);

  // cmp(Rflags, ctos);
  __ br(Assembler::notEqual, false, Assembler::pt, notChar);
  __ delayed() ->cmp(Rflags, stos);

  // ctos
  __ lduh(Rclass, Roffset, Otos_i);
  __ push(itos);
  if (!is_static) {
    patch_bytecode(Bytecodes::_fast_cgetfield, G3_scratch, G4_scratch);
  }
  __ ba(false, checkVolatile);
  __ delayed()->tst(Lscratch);

  __ bind(notChar);

  // cmp(Rflags, stos);
  __ br(Assembler::notEqual, false, Assembler::pt, notShort);
  __ delayed() ->cmp(Rflags, ftos);

  // stos
  __ ldsh(Rclass, Roffset, Otos_i);
  __ push(itos);
  if (!is_static) {
    patch_bytecode(Bytecodes::_fast_sgetfield, G3_scratch, G4_scratch);
  }
  __ ba(false, checkVolatile);
  __ delayed()->tst(Lscratch);

  __ bind(notShort);


  // cmp(Rflags, ftos);
  __ br(Assembler::notEqual, false, Assembler::pt, notFloat);
  __ delayed() ->tst(Lscratch);

  // ftos
  __ ldf(FloatRegisterImpl::S, Rclass, Roffset, Ftos_f);
  __ push(ftos);
  if (!is_static) {
    patch_bytecode(Bytecodes::_fast_fgetfield, G3_scratch, G4_scratch);
  }
  __ ba(false, checkVolatile);
  __ delayed()->tst(Lscratch);

  __ bind(notFloat);


  // dtos
  __ ldf(FloatRegisterImpl::D, Rclass, Roffset, Ftos_d);
  __ push(dtos);
  if (!is_static) {
    patch_bytecode(Bytecodes::_fast_dgetfield, G3_scratch, G4_scratch);
  }

  __ bind(checkVolatile);
  if (__ membar_has_effect(membar_bits)) {
    // __ tst(Lscratch); executed in delay slot
    __ br(Assembler::zero, false, Assembler::pt, exit);
    __ delayed()->nop();
    volatile_barrier(membar_bits);
  }

  __ bind(exit);
}


void TemplateTable::getfield(int byte_no) {
  getfield_or_static(byte_no, false);
}

void TemplateTable::getstatic(int byte_no) {
  getfield_or_static(byte_no, true);
}


void TemplateTable::fast_accessfield(TosState state) {
  transition(atos, state);
  Register Rcache  = G3_scratch;
  Register index   = G4_scratch;
  Register Roffset = G4_scratch;
  Register Rflags  = Rcache;
  ByteSize cp_base_offset = constantPoolCacheOopDesc::base_offset();

  __ get_cache_and_index_at_bcp(Rcache, index, 1);
  jvmti_post_field_access(Rcache, index, /*is_static*/false, /*has_tos*/true);

2438
  __ ld_ptr(Rcache, cp_base_offset + ConstantPoolCacheEntry::f2_offset(), Roffset);
D
duke 已提交
2439 2440 2441 2442 2443 2444 2445 2446 2447 2448

  __ null_check(Otos_i);
  __ verify_oop(Otos_i);

  Label exit;

  Assembler::Membar_mask_bits membar_bits =
    Assembler::Membar_mask_bits(Assembler::LoadLoad | Assembler::LoadStore);
  if (__ membar_has_effect(membar_bits)) {
    // Get volatile flag
2449
    __ ld_ptr(Rcache, cp_base_offset + ConstantPoolCacheEntry::f2_offset(), Rflags);
D
duke 已提交
2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475
    __ set((1 << ConstantPoolCacheEntry::volatileField), Lscratch);
  }

  switch (bytecode()) {
    case Bytecodes::_fast_bgetfield:
      __ ldsb(Otos_i, Roffset, Otos_i);
      break;
    case Bytecodes::_fast_cgetfield:
      __ lduh(Otos_i, Roffset, Otos_i);
      break;
    case Bytecodes::_fast_sgetfield:
      __ ldsh(Otos_i, Roffset, Otos_i);
      break;
    case Bytecodes::_fast_igetfield:
      __ ld(Otos_i, Roffset, Otos_i);
      break;
    case Bytecodes::_fast_lgetfield:
      __ ld_long(Otos_i, Roffset, Otos_l);
      break;
    case Bytecodes::_fast_fgetfield:
      __ ldf(FloatRegisterImpl::S, Otos_i, Roffset, Ftos_f);
      break;
    case Bytecodes::_fast_dgetfield:
      __ ldf(FloatRegisterImpl::D, Otos_i, Roffset, Ftos_d);
      break;
    case Bytecodes::_fast_agetfield:
2476
      __ load_heap_oop(Otos_i, Roffset, Otos_i);
D
duke 已提交
2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499
      break;
    default:
      ShouldNotReachHere();
  }

  if (__ membar_has_effect(membar_bits)) {
    __ btst(Lscratch, Rflags);
    __ br(Assembler::zero, false, Assembler::pt, exit);
    __ delayed()->nop();
    volatile_barrier(membar_bits);
    __ bind(exit);
  }

  if (state == atos) {
    __ verify_oop(Otos_i);    // does not blow flags!
  }
}

void TemplateTable::jvmti_post_fast_field_mod() {
  if (JvmtiExport::can_post_field_modification()) {
    // Check to see if a field modification watch has been set before we take
    // the time to call into the VM.
    Label done;
2500
    AddressLiteral get_field_modification_count_addr(JvmtiExport::get_field_modification_count_addr());
D
duke 已提交
2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552
    __ load_contents(get_field_modification_count_addr, G4_scratch);
    __ tst(G4_scratch);
    __ br(Assembler::zero, false, Assembler::pt, done);
    __ delayed()->nop();
    __ pop_ptr(G4_scratch);     // copy the object pointer from tos
    __ verify_oop(G4_scratch);
    __ push_ptr(G4_scratch);    // put the object pointer back on tos
    __ get_cache_entry_pointer_at_bcp(G1_scratch, G3_scratch, 1);
    // Save tos values before call_VM() clobbers them. Since we have
    // to do it for every data type, we use the saved values as the
    // jvalue object.
    switch (bytecode()) {  // save tos values before call_VM() clobbers them
    case Bytecodes::_fast_aputfield: __ push_ptr(Otos_i); break;
    case Bytecodes::_fast_bputfield: // fall through
    case Bytecodes::_fast_sputfield: // fall through
    case Bytecodes::_fast_cputfield: // fall through
    case Bytecodes::_fast_iputfield: __ push_i(Otos_i); break;
    case Bytecodes::_fast_dputfield: __ push_d(Ftos_d); break;
    case Bytecodes::_fast_fputfield: __ push_f(Ftos_f); break;
    // get words in right order for use as jvalue object
    case Bytecodes::_fast_lputfield: __ push_l(Otos_l); break;
    }
    // setup pointer to jvalue object
    __ mov(Lesp, G3_scratch);  __ inc(G3_scratch, wordSize);
    // G4_scratch:  object pointer
    // G1_scratch: cache entry pointer
    // G3_scratch: jvalue object on the stack
    __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_modification), G4_scratch, G1_scratch, G3_scratch);
    switch (bytecode()) {             // restore tos values
    case Bytecodes::_fast_aputfield: __ pop_ptr(Otos_i); break;
    case Bytecodes::_fast_bputfield: // fall through
    case Bytecodes::_fast_sputfield: // fall through
    case Bytecodes::_fast_cputfield: // fall through
    case Bytecodes::_fast_iputfield: __ pop_i(Otos_i); break;
    case Bytecodes::_fast_dputfield: __ pop_d(Ftos_d); break;
    case Bytecodes::_fast_fputfield: __ pop_f(Ftos_f); break;
    case Bytecodes::_fast_lputfield: __ pop_l(Otos_l); break;
    }
    __ bind(done);
  }
}

// The registers Rcache and index expected to be set before call.
// The function may destroy various registers, just not the Rcache and index registers.
void TemplateTable::jvmti_post_field_mod(Register Rcache, Register index, bool is_static) {
  ByteSize cp_base_offset = constantPoolCacheOopDesc::base_offset();

  if (JvmtiExport::can_post_field_modification()) {
    // Check to see if a field modification watch has been set before we take
    // the time to call into the VM.
    Label Label1;
    assert_different_registers(Rcache, index, G1_scratch);
2553
    AddressLiteral get_field_modification_count_addr(JvmtiExport::get_field_modification_count_addr());
D
duke 已提交
2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575
    __ load_contents(get_field_modification_count_addr, G1_scratch);
    __ tst(G1_scratch);
    __ br(Assembler::zero, false, Assembler::pt, Label1);
    __ delayed()->nop();

    // The Rcache and index registers have been already set.
    // This allows to eliminate this call but the Rcache and index
    // registers must be correspondingly used after this line.
    __ get_cache_and_index_at_bcp(G1_scratch, G4_scratch, 1);

    __ add(G1_scratch, in_bytes(cp_base_offset), G3_scratch);
    if (is_static) {
      // Life is simple.  Null out the object pointer.
      __ clr(G4_scratch);
    } else {
      Register Rflags = G1_scratch;
      // Life is harder. The stack holds the value on top, followed by the
      // object.  We don't know the size of the value, though; it could be
      // one or two words depending on its type. As a result, we must find
      // the type to determine where the object is.

      Label two_word, valsizeknown;
2576
      __ ld_ptr(G1_scratch, cp_base_offset + ConstantPoolCacheEntry::flags_offset(), Rflags);
D
duke 已提交
2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624
      __ mov(Lesp, G4_scratch);
      __ srl(Rflags, ConstantPoolCacheEntry::tosBits, Rflags);
      // Make sure we don't need to mask Rflags for tosBits after the above shift
      ConstantPoolCacheEntry::verify_tosBits();
      __ cmp(Rflags, ltos);
      __ br(Assembler::equal, false, Assembler::pt, two_word);
      __ delayed()->cmp(Rflags, dtos);
      __ br(Assembler::equal, false, Assembler::pt, two_word);
      __ delayed()->nop();
      __ inc(G4_scratch, Interpreter::expr_offset_in_bytes(1));
      __ br(Assembler::always, false, Assembler::pt, valsizeknown);
      __ delayed()->nop();
      __ bind(two_word);

      __ inc(G4_scratch, Interpreter::expr_offset_in_bytes(2));

      __ bind(valsizeknown);
      // setup object pointer
      __ ld_ptr(G4_scratch, 0, G4_scratch);
      __ verify_oop(G4_scratch);
    }
    // setup pointer to jvalue object
    __ mov(Lesp, G1_scratch);  __ inc(G1_scratch, wordSize);
    // G4_scratch:  object pointer or NULL if static
    // G3_scratch: cache entry pointer
    // G1_scratch: jvalue object on the stack
    __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_field_modification),
               G4_scratch, G3_scratch, G1_scratch);
    __ get_cache_and_index_at_bcp(Rcache, index, 1);
    __ bind(Label1);
  }
}

void TemplateTable::pop_and_check_object(Register r) {
  __ pop_ptr(r);
  __ null_check(r);  // for field access must check obj.
  __ verify_oop(r);
}

void TemplateTable::putfield_or_static(int byte_no, bool is_static) {
  transition(vtos, vtos);
  Register Rcache = G3_scratch;
  Register index  = G4_scratch;
  Register Rclass = Rcache;
  Register Roffset= G4_scratch;
  Register Rflags = G1_scratch;
  ByteSize cp_base_offset = constantPoolCacheOopDesc::base_offset();

2625
  resolve_cache_and_index(byte_no, noreg, Rcache, index, sizeof(u2));
D
duke 已提交
2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662
  jvmti_post_field_mod(Rcache, index, is_static);
  load_field_cp_cache_entry(Rclass, Rcache, index, Roffset, Rflags, is_static);

  Assembler::Membar_mask_bits read_bits =
    Assembler::Membar_mask_bits(Assembler::LoadStore | Assembler::StoreStore);
  Assembler::Membar_mask_bits write_bits = Assembler::StoreLoad;

  Label notVolatile, checkVolatile, exit;
  if (__ membar_has_effect(read_bits) || __ membar_has_effect(write_bits)) {
    __ set((1 << ConstantPoolCacheEntry::volatileField), Lscratch);
    __ and3(Rflags, Lscratch, Lscratch);

    if (__ membar_has_effect(read_bits)) {
      __ tst(Lscratch);
      __ br(Assembler::zero, false, Assembler::pt, notVolatile);
      __ delayed()->nop();
      volatile_barrier(read_bits);
      __ bind(notVolatile);
    }
  }

  __ srl(Rflags, ConstantPoolCacheEntry::tosBits, Rflags);
  // Make sure we don't need to mask Rflags for tosBits after the above shift
  ConstantPoolCacheEntry::verify_tosBits();

  // compute field type
  Label notInt, notShort, notChar, notObj, notByte, notLong, notFloat;

  if (is_static) {
    // putstatic with object type most likely, check that first
    __ cmp(Rflags, atos );
    __ br(Assembler::notEqual, false, Assembler::pt, notObj);
    __ delayed() ->cmp(Rflags, itos );

    // atos
    __ pop_ptr();
    __ verify_oop(Otos_i);
2663 2664 2665

    do_oop_store(_masm, Rclass, Roffset, 0, Otos_i, G1_scratch, _bs->kind(), false);

D
duke 已提交
2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705
    __ ba(false, checkVolatile);
    __ delayed()->tst(Lscratch);

    __ bind(notObj);

    // cmp(Rflags, itos );
    __ br(Assembler::notEqual, false, Assembler::pt, notInt);
    __ delayed() ->cmp(Rflags, btos );

    // itos
    __ pop_i();
    __ st(Otos_i, Rclass, Roffset);
    __ ba(false, checkVolatile);
    __ delayed()->tst(Lscratch);

    __ bind(notInt);

  } else {
    // putfield with int type most likely, check that first
    __ cmp(Rflags, itos );
    __ br(Assembler::notEqual, false, Assembler::pt, notInt);
    __ delayed() ->cmp(Rflags, atos );

    // itos
    __ pop_i();
    pop_and_check_object(Rclass);
    __ st(Otos_i, Rclass, Roffset);
    patch_bytecode(Bytecodes::_fast_iputfield, G3_scratch, G4_scratch);
    __ ba(false, checkVolatile);
    __ delayed()->tst(Lscratch);

    __ bind(notInt);
    // cmp(Rflags, atos );
    __ br(Assembler::notEqual, false, Assembler::pt, notObj);
    __ delayed() ->cmp(Rflags, btos );

    // atos
    __ pop_ptr();
    pop_and_check_object(Rclass);
    __ verify_oop(Otos_i);
2706 2707 2708

    do_oop_store(_masm, Rclass, Roffset, 0, Otos_i, G1_scratch, _bs->kind(), false);

D
duke 已提交
2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831
    patch_bytecode(Bytecodes::_fast_aputfield, G3_scratch, G4_scratch);
    __ ba(false, checkVolatile);
    __ delayed()->tst(Lscratch);

    __ bind(notObj);
  }

  // cmp(Rflags, btos );
  __ br(Assembler::notEqual, false, Assembler::pt, notByte);
  __ delayed() ->cmp(Rflags, ltos );

  // btos
  __ pop_i();
  if (!is_static) pop_and_check_object(Rclass);
  __ stb(Otos_i, Rclass, Roffset);
  if (!is_static) {
    patch_bytecode(Bytecodes::_fast_bputfield, G3_scratch, G4_scratch);
  }
  __ ba(false, checkVolatile);
  __ delayed()->tst(Lscratch);

  __ bind(notByte);

  // cmp(Rflags, ltos );
  __ br(Assembler::notEqual, false, Assembler::pt, notLong);
  __ delayed() ->cmp(Rflags, ctos );

  // ltos
  __ pop_l();
  if (!is_static) pop_and_check_object(Rclass);
  __ st_long(Otos_l, Rclass, Roffset);
  if (!is_static) {
    patch_bytecode(Bytecodes::_fast_lputfield, G3_scratch, G4_scratch);
  }
  __ ba(false, checkVolatile);
  __ delayed()->tst(Lscratch);

  __ bind(notLong);

  // cmp(Rflags, ctos );
  __ br(Assembler::notEqual, false, Assembler::pt, notChar);
  __ delayed() ->cmp(Rflags, stos );

  // ctos (char)
  __ pop_i();
  if (!is_static) pop_and_check_object(Rclass);
  __ sth(Otos_i, Rclass, Roffset);
  if (!is_static) {
    patch_bytecode(Bytecodes::_fast_cputfield, G3_scratch, G4_scratch);
  }
  __ ba(false, checkVolatile);
  __ delayed()->tst(Lscratch);

  __ bind(notChar);
  // cmp(Rflags, stos );
  __ br(Assembler::notEqual, false, Assembler::pt, notShort);
  __ delayed() ->cmp(Rflags, ftos );

  // stos (char)
  __ pop_i();
  if (!is_static) pop_and_check_object(Rclass);
  __ sth(Otos_i, Rclass, Roffset);
  if (!is_static) {
    patch_bytecode(Bytecodes::_fast_sputfield, G3_scratch, G4_scratch);
  }
  __ ba(false, checkVolatile);
  __ delayed()->tst(Lscratch);

  __ bind(notShort);
  // cmp(Rflags, ftos );
  __ br(Assembler::notZero, false, Assembler::pt, notFloat);
  __ delayed()->nop();

  // ftos
  __ pop_f();
  if (!is_static) pop_and_check_object(Rclass);
  __ stf(FloatRegisterImpl::S, Ftos_f, Rclass, Roffset);
  if (!is_static) {
    patch_bytecode(Bytecodes::_fast_fputfield, G3_scratch, G4_scratch);
  }
  __ ba(false, checkVolatile);
  __ delayed()->tst(Lscratch);

  __ bind(notFloat);

  // dtos
  __ pop_d();
  if (!is_static) pop_and_check_object(Rclass);
  __ stf(FloatRegisterImpl::D, Ftos_d, Rclass, Roffset);
  if (!is_static) {
    patch_bytecode(Bytecodes::_fast_dputfield, G3_scratch, G4_scratch);
  }

  __ bind(checkVolatile);
  __ tst(Lscratch);

  if (__ membar_has_effect(write_bits)) {
    // __ tst(Lscratch); in delay slot
    __ br(Assembler::zero, false, Assembler::pt, exit);
    __ delayed()->nop();
    volatile_barrier(Assembler::StoreLoad);
    __ bind(exit);
  }
}

void TemplateTable::fast_storefield(TosState state) {
  transition(state, vtos);
  Register Rcache = G3_scratch;
  Register Rclass = Rcache;
  Register Roffset= G4_scratch;
  Register Rflags = G1_scratch;
  ByteSize cp_base_offset = constantPoolCacheOopDesc::base_offset();

  jvmti_post_fast_field_mod();

  __ get_cache_and_index_at_bcp(Rcache, G4_scratch, 1);

  Assembler::Membar_mask_bits read_bits =
    Assembler::Membar_mask_bits(Assembler::LoadStore | Assembler::StoreStore);
  Assembler::Membar_mask_bits write_bits = Assembler::StoreLoad;

  Label notVolatile, checkVolatile, exit;
  if (__ membar_has_effect(read_bits) || __ membar_has_effect(write_bits)) {
2832
    __ ld_ptr(Rcache, cp_base_offset + ConstantPoolCacheEntry::flags_offset(), Rflags);
D
duke 已提交
2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843
    __ set((1 << ConstantPoolCacheEntry::volatileField), Lscratch);
    __ and3(Rflags, Lscratch, Lscratch);
    if (__ membar_has_effect(read_bits)) {
      __ tst(Lscratch);
      __ br(Assembler::zero, false, Assembler::pt, notVolatile);
      __ delayed()->nop();
      volatile_barrier(read_bits);
      __ bind(notVolatile);
    }
  }

2844
  __ ld_ptr(Rcache, cp_base_offset + ConstantPoolCacheEntry::f2_offset(), Roffset);
D
duke 已提交
2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859
  pop_and_check_object(Rclass);

  switch (bytecode()) {
    case Bytecodes::_fast_bputfield: __ stb(Otos_i, Rclass, Roffset); break;
    case Bytecodes::_fast_cputfield: /* fall through */
    case Bytecodes::_fast_sputfield: __ sth(Otos_i, Rclass, Roffset); break;
    case Bytecodes::_fast_iputfield: __ st(Otos_i, Rclass, Roffset);  break;
    case Bytecodes::_fast_lputfield: __ st_long(Otos_l, Rclass, Roffset); break;
    case Bytecodes::_fast_fputfield:
      __ stf(FloatRegisterImpl::S, Ftos_f, Rclass, Roffset);
      break;
    case Bytecodes::_fast_dputfield:
      __ stf(FloatRegisterImpl::D, Ftos_d, Rclass, Roffset);
      break;
    case Bytecodes::_fast_aputfield:
2860
      do_oop_store(_masm, Rclass, Roffset, 0, Otos_i, G1_scratch, _bs->kind(), false);
D
duke 已提交
2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891
      break;
    default:
      ShouldNotReachHere();
  }

  if (__ membar_has_effect(write_bits)) {
    __ tst(Lscratch);
    __ br(Assembler::zero, false, Assembler::pt, exit);
    __ delayed()->nop();
    volatile_barrier(Assembler::StoreLoad);
    __ bind(exit);
  }
}


void TemplateTable::putfield(int byte_no) {
  putfield_or_static(byte_no, false);
}

void TemplateTable::putstatic(int byte_no) {
  putfield_or_static(byte_no, true);
}


void TemplateTable::fast_xaccess(TosState state) {
  transition(vtos, state);
  Register Rcache = G3_scratch;
  Register Roffset = G4_scratch;
  Register Rflags  = G4_scratch;
  Register Rreceiver = Lscratch;

2892
  __ ld_ptr(Llocals, 0, Rreceiver);
D
duke 已提交
2893 2894 2895

  // access constant pool cache  (is resolved)
  __ get_cache_and_index_at_bcp(Rcache, G4_scratch, 2);
2896
  __ ld_ptr(Rcache, constantPoolCacheOopDesc::base_offset() + ConstantPoolCacheEntry::f2_offset(), Roffset);
D
duke 已提交
2897 2898 2899 2900 2901
  __ add(Lbcp, 1, Lbcp);       // needed to report exception at the correct bcp

  __ verify_oop(Rreceiver);
  __ null_check(Rreceiver);
  if (state == atos) {
2902
    __ load_heap_oop(Rreceiver, Roffset, Otos_i);
D
duke 已提交
2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915
  } else if (state == itos) {
    __ ld (Rreceiver, Roffset, Otos_i) ;
  } else if (state == ftos) {
    __ ldf(FloatRegisterImpl::S, Rreceiver, Roffset, Ftos_f);
  } else {
    ShouldNotReachHere();
  }

  Assembler::Membar_mask_bits membar_bits =
    Assembler::Membar_mask_bits(Assembler::LoadLoad | Assembler::LoadStore);
  if (__ membar_has_effect(membar_bits)) {

    // Get is_volatile value in Rflags and check if membar is needed
2916
    __ ld_ptr(Rcache, constantPoolCacheOopDesc::base_offset() + ConstantPoolCacheEntry::flags_offset(), Rflags);
D
duke 已提交
2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965

    // Test volatile
    Label notVolatile;
    __ set((1 << ConstantPoolCacheEntry::volatileField), Lscratch);
    __ btst(Rflags, Lscratch);
    __ br(Assembler::zero, false, Assembler::pt, notVolatile);
    __ delayed()->nop();
    volatile_barrier(membar_bits);
    __ bind(notVolatile);
  }

  __ interp_verify_oop(Otos_i, state, __FILE__, __LINE__);
  __ sub(Lbcp, 1, Lbcp);
}

//----------------------------------------------------------------------------------------------------
// Calls

void TemplateTable::count_calls(Register method, Register temp) {
  // implemented elsewhere
  ShouldNotReachHere();
}

void TemplateTable::generate_vtable_call(Register Rrecv, Register Rindex, Register Rret) {
  Register Rtemp = G4_scratch;
  Register Rcall = Rindex;
  assert_different_registers(Rcall, G5_method, Gargs, Rret);

  // get target methodOop & entry point
  const int base = instanceKlass::vtable_start_offset() * wordSize;
  if (vtableEntry::size() % 3 == 0) {
    // scale the vtable index by 12:
    int one_third = vtableEntry::size() / 3;
    __ sll(Rindex, exact_log2(one_third * 1 * wordSize), Rtemp);
    __ sll(Rindex, exact_log2(one_third * 2 * wordSize), Rindex);
    __ add(Rindex, Rtemp, Rindex);
  } else {
    // scale the vtable index by 8:
    __ sll(Rindex, exact_log2(vtableEntry::size() * wordSize), Rindex);
  }

  __ add(Rrecv, Rindex, Rrecv);
  __ ld_ptr(Rrecv, base + vtableEntry::method_offset_in_bytes(), G5_method);

  __ call_from_interpreter(Rcall, Gargs, Rret);
}

void TemplateTable::invokevirtual(int byte_no) {
  transition(vtos, vtos);
2966
  assert(byte_no == f2_byte, "use this argument");
D
duke 已提交
2967 2968 2969 2970 2971 2972 2973

  Register Rscratch = G3_scratch;
  Register Rtemp = G4_scratch;
  Register Rret = Lscratch;
  Register Rrecv = G5_method;
  Label notFinal;

2974
  load_invoke_cp_cache_entry(byte_no, G5_method, noreg, Rret, true, false, false);
D
duke 已提交
2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994
  __ mov(SP, O5_savedSP); // record SP that we wanted the callee to restore

  // Check for vfinal
  __ set((1 << ConstantPoolCacheEntry::vfinalMethod), G4_scratch);
  __ btst(Rret, G4_scratch);
  __ br(Assembler::zero, false, Assembler::pt, notFinal);
  __ delayed()->and3(Rret, 0xFF, G4_scratch);      // gets number of parameters

  patch_bytecode(Bytecodes::_fast_invokevfinal, Rscratch, Rtemp);

  invokevfinal_helper(Rscratch, Rret);

  __ bind(notFinal);

  __ mov(G5_method, Rscratch);  // better scratch register
  __ load_receiver(G4_scratch, O0);  // gets receiverOop
  // receiver is in O0
  __ verify_oop(O0);

  // get return address
2995 2996
  AddressLiteral table(Interpreter::return_3_addrs_by_index_table());
  __ set(table, Rtemp);
D
duke 已提交
2997 2998 2999 3000 3001 3002 3003 3004
  __ srl(Rret, ConstantPoolCacheEntry::tosBits, Rret);          // get return type
  // Make sure we don't need to mask Rret for tosBits after the above shift
  ConstantPoolCacheEntry::verify_tosBits();
  __ sll(Rret,  LogBytesPerWord, Rret);
  __ ld_ptr(Rtemp, Rret, Rret);         // get return address

  // get receiver klass
  __ null_check(O0, oopDesc::klass_offset_in_bytes());
3005
  __ load_klass(O0, Rrecv);
D
duke 已提交
3006 3007 3008 3009 3010 3011 3012 3013 3014
  __ verify_oop(Rrecv);

  __ profile_virtual_call(Rrecv, O4);

  generate_vtable_call(Rrecv, Rscratch, Rret);
}

void TemplateTable::fast_invokevfinal(int byte_no) {
  transition(vtos, vtos);
3015
  assert(byte_no == f2_byte, "use this argument");
D
duke 已提交
3016 3017

  load_invoke_cp_cache_entry(byte_no, G5_method, noreg, Lscratch, true,
3018
                             /*is_invokevfinal*/true, false);
D
duke 已提交
3019 3020 3021 3022 3023 3024 3025 3026 3027 3028
  __ mov(SP, O5_savedSP); // record SP that we wanted the callee to restore
  invokevfinal_helper(G3_scratch, Lscratch);
}

void TemplateTable::invokevfinal_helper(Register Rscratch, Register Rret) {
  Register Rtemp = G4_scratch;

  __ verify_oop(G5_method);

  // Load receiver from stack slot
3029
  __ lduh(G5_method, in_bytes(methodOopDesc::size_of_parameters_offset()), G4_scratch);
D
duke 已提交
3030 3031 3032 3033 3034 3035 3036 3037
  __ load_receiver(G4_scratch, O0);

  // receiver NULL check
  __ null_check(O0);

  __ profile_final_call(O4);

  // get return address
3038 3039
  AddressLiteral table(Interpreter::return_3_addrs_by_index_table());
  __ set(table, Rtemp);
D
duke 已提交
3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052
  __ srl(Rret, ConstantPoolCacheEntry::tosBits, Rret);          // get return type
  // Make sure we don't need to mask Rret for tosBits after the above shift
  ConstantPoolCacheEntry::verify_tosBits();
  __ sll(Rret,  LogBytesPerWord, Rret);
  __ ld_ptr(Rtemp, Rret, Rret);         // get return address


  // do the call
  __ call_from_interpreter(Rscratch, Gargs, Rret);
}

void TemplateTable::invokespecial(int byte_no) {
  transition(vtos, vtos);
3053
  assert(byte_no == f1_byte, "use this argument");
D
duke 已提交
3054 3055 3056 3057 3058

  Register Rscratch = G3_scratch;
  Register Rtemp = G4_scratch;
  Register Rret = Lscratch;

3059
  load_invoke_cp_cache_entry(byte_no, G5_method, noreg, Rret, /*virtual*/ false, false, false);
D
duke 已提交
3060 3061 3062 3063
  __ mov(SP, O5_savedSP); // record SP that we wanted the callee to restore

  __ verify_oop(G5_method);

3064
  __ lduh(G5_method, in_bytes(methodOopDesc::size_of_parameters_offset()), G4_scratch);
D
duke 已提交
3065 3066 3067 3068 3069 3070 3071 3072
  __ load_receiver(G4_scratch, O0);

  // receiver NULL check
  __ null_check(O0);

  __ profile_call(O4);

  // get return address
3073 3074
  AddressLiteral table(Interpreter::return_3_addrs_by_index_table());
  __ set(table, Rtemp);
D
duke 已提交
3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086
  __ srl(Rret, ConstantPoolCacheEntry::tosBits, Rret);          // get return type
  // Make sure we don't need to mask Rret for tosBits after the above shift
  ConstantPoolCacheEntry::verify_tosBits();
  __ sll(Rret,  LogBytesPerWord, Rret);
  __ ld_ptr(Rtemp, Rret, Rret);         // get return address

  // do the call
  __ call_from_interpreter(Rscratch, Gargs, Rret);
}

void TemplateTable::invokestatic(int byte_no) {
  transition(vtos, vtos);
3087
  assert(byte_no == f1_byte, "use this argument");
D
duke 已提交
3088 3089 3090 3091 3092

  Register Rscratch = G3_scratch;
  Register Rtemp = G4_scratch;
  Register Rret = Lscratch;

3093
  load_invoke_cp_cache_entry(byte_no, G5_method, noreg, Rret, /*virtual*/ false, false, false);
D
duke 已提交
3094 3095 3096 3097 3098 3099 3100
  __ mov(SP, O5_savedSP); // record SP that we wanted the callee to restore

  __ verify_oop(G5_method);

  __ profile_call(O4);

  // get return address
3101 3102
  AddressLiteral table(Interpreter::return_3_addrs_by_index_table());
  __ set(table, Rtemp);
D
duke 已提交
3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145
  __ srl(Rret, ConstantPoolCacheEntry::tosBits, Rret);          // get return type
  // Make sure we don't need to mask Rret for tosBits after the above shift
  ConstantPoolCacheEntry::verify_tosBits();
  __ sll(Rret,  LogBytesPerWord, Rret);
  __ ld_ptr(Rtemp, Rret, Rret);         // get return address

  // do the call
  __ call_from_interpreter(Rscratch, Gargs, Rret);
}


void TemplateTable::invokeinterface_object_method(Register RklassOop,
                                                  Register Rcall,
                                                  Register Rret,
                                                  Register Rflags) {
  Register Rscratch = G4_scratch;
  Register Rindex = Lscratch;

  assert_different_registers(Rscratch, Rindex, Rret);

  Label notFinal;

  // Check for vfinal
  __ set((1 << ConstantPoolCacheEntry::vfinalMethod), Rscratch);
  __ btst(Rflags, Rscratch);
  __ br(Assembler::zero, false, Assembler::pt, notFinal);
  __ delayed()->nop();

  __ profile_final_call(O4);

  // do the call - the index (f2) contains the methodOop
  assert_different_registers(G5_method, Gargs, Rcall);
  __ mov(Rindex, G5_method);
  __ call_from_interpreter(Rcall, Gargs, Rret);
  __ bind(notFinal);

  __ profile_virtual_call(RklassOop, O4);
  generate_vtable_call(RklassOop, Rindex, Rret);
}


void TemplateTable::invokeinterface(int byte_no) {
  transition(vtos, vtos);
3146
  assert(byte_no == f1_byte, "use this argument");
D
duke 已提交
3147 3148 3149 3150 3151 3152 3153 3154 3155

  Register Rscratch = G4_scratch;
  Register Rret = G3_scratch;
  Register Rindex = Lscratch;
  Register Rinterface = G1_scratch;
  Register RklassOop = G5_method;
  Register Rflags = O1;
  assert_different_registers(Rscratch, G5_method);

3156
  load_invoke_cp_cache_entry(byte_no, Rinterface, Rindex, Rflags, /*virtual*/ false, false, false);
D
duke 已提交
3157 3158 3159 3160 3161 3162 3163 3164 3165 3166
  __ mov(SP, O5_savedSP); // record SP that we wanted the callee to restore

  // get receiver
  __ and3(Rflags, 0xFF, Rscratch);       // gets number of parameters
  __ load_receiver(Rscratch, O0);
  __ verify_oop(O0);

  __ mov(Rflags, Rret);

  // get return address
3167 3168
  AddressLiteral table(Interpreter::return_5_addrs_by_index_table());
  __ set(table, Rscratch);
D
duke 已提交
3169 3170 3171 3172 3173 3174 3175 3176
  __ srl(Rret, ConstantPoolCacheEntry::tosBits, Rret);          // get return type
  // Make sure we don't need to mask Rret for tosBits after the above shift
  ConstantPoolCacheEntry::verify_tosBits();
  __ sll(Rret,  LogBytesPerWord, Rret);
  __ ld_ptr(Rscratch, Rret, Rret);      // get return address

  // get receiver klass
  __ null_check(O0, oopDesc::klass_offset_in_bytes());
3177
  __ load_klass(O0, RklassOop);
D
duke 已提交
3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204
  __ verify_oop(RklassOop);

  // Special case of invokeinterface called for virtual method of
  // java.lang.Object.  See cpCacheOop.cpp for details.
  // This code isn't produced by javac, but could be produced by
  // another compliant java compiler.
  Label notMethod;
  __ set((1 << ConstantPoolCacheEntry::methodInterface), Rscratch);
  __ btst(Rflags, Rscratch);
  __ br(Assembler::zero, false, Assembler::pt, notMethod);
  __ delayed()->nop();

  invokeinterface_object_method(RklassOop, Rinterface, Rret, Rflags);

  __ bind(notMethod);

  __ profile_virtual_call(RklassOop, O4);

  //
  // find entry point to call
  //

  // compute start of first itableOffsetEntry (which is at end of vtable)
  const int base = instanceKlass::vtable_start_offset() * wordSize;
  Label search;
  Register Rtemp = Rflags;

3205
  __ ld(RklassOop, instanceKlass::vtable_length_offset() * wordSize, Rtemp);
D
duke 已提交
3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224
  if (align_object_offset(1) > 1) {
    __ round_to(Rtemp, align_object_offset(1));
  }
  __ sll(Rtemp, LogBytesPerWord, Rtemp);   // Rscratch *= 4;
  if (Assembler::is_simm13(base)) {
    __ add(Rtemp, base, Rtemp);
  } else {
    __ set(base, Rscratch);
    __ add(Rscratch, Rtemp, Rtemp);
  }
  __ add(RklassOop, Rtemp, Rscratch);

  __ bind(search);

  __ ld_ptr(Rscratch, itableOffsetEntry::interface_offset_in_bytes(), Rtemp);
  {
    Label ok;

    // Check that entry is non-null.  Null entries are probably a bytecode
T
twisti 已提交
3225
    // problem.  If the interface isn't implemented by the receiver class,
D
duke 已提交
3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270
    // the VM should throw IncompatibleClassChangeError.  linkResolver checks
    // this too but that's only if the entry isn't already resolved, so we
    // need to check again.
    __ br_notnull( Rtemp, false, Assembler::pt, ok);
    __ delayed()->nop();
    call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_IncompatibleClassChangeError));
    __ should_not_reach_here();
    __ bind(ok);
    __ verify_oop(Rtemp);
  }

  __ verify_oop(Rinterface);

  __ cmp(Rinterface, Rtemp);
  __ brx(Assembler::notEqual, true, Assembler::pn, search);
  __ delayed()->add(Rscratch, itableOffsetEntry::size() * wordSize, Rscratch);

  // entry found and Rscratch points to it
  __ ld(Rscratch, itableOffsetEntry::offset_offset_in_bytes(), Rscratch);

  assert(itableMethodEntry::method_offset_in_bytes() == 0, "adjust instruction below");
  __ sll(Rindex, exact_log2(itableMethodEntry::size() * wordSize), Rindex);       // Rindex *= 8;
  __ add(Rscratch, Rindex, Rscratch);
  __ ld_ptr(RklassOop, Rscratch, G5_method);

  // Check for abstract method error.
  {
    Label ok;
    __ tst(G5_method);
    __ brx(Assembler::notZero, false, Assembler::pt, ok);
    __ delayed()->nop();
    call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_AbstractMethodError));
    __ should_not_reach_here();
    __ bind(ok);
  }

  Register Rcall = Rinterface;
  assert_different_registers(Rcall, G5_method, Gargs, Rret);

  __ verify_oop(G5_method);
  __ call_from_interpreter(Rcall, Gargs, Rret);

}


3271 3272
void TemplateTable::invokedynamic(int byte_no) {
  transition(vtos, vtos);
3273
  assert(byte_no == f1_oop, "use this argument");
3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285

  if (!EnableInvokeDynamic) {
    // We should not encounter this bytecode if !EnableInvokeDynamic.
    // The verifier will stop it.  However, if we get past the verifier,
    // this will stop the thread in a reasonable way, without crashing the JVM.
    __ call_VM(noreg, CAST_FROM_FN_PTR(address,
                     InterpreterRuntime::throw_IncompatibleClassChangeError));
    // the call_VM checks for exception, so we should never return here.
    __ should_not_reach_here();
    return;
  }

T
twisti 已提交
3286 3287 3288 3289 3290 3291 3292 3293 3294
  // G5: CallSite object (f1)
  // XX: unused (f2)
  // XX: flags (unused)

  Register G5_callsite = G5_method;
  Register Rscratch    = G3_scratch;
  Register Rtemp       = G1_scratch;
  Register Rret        = Lscratch;

3295 3296
  load_invoke_cp_cache_entry(byte_no, G5_callsite, noreg, Rret,
                             /*virtual*/ false, /*vfinal*/ false, /*indy*/ true);
T
twisti 已提交
3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310
  __ mov(SP, O5_savedSP);  // record SP that we wanted the callee to restore

  // profile this call
  __ profile_call(O4);

  // get return address
  AddressLiteral table(Interpreter::return_5_addrs_by_index_table());
  __ set(table, Rtemp);
  __ srl(Rret, ConstantPoolCacheEntry::tosBits, Rret);  // get return type
  // Make sure we don't need to mask Rret for tosBits after the above shift
  ConstantPoolCacheEntry::verify_tosBits();
  __ sll(Rret, LogBytesPerWord, Rret);
  __ ld_ptr(Rtemp, Rret, Rret);  // get return address

3311
  __ verify_oop(G5_callsite);
3312
  __ load_heap_oop(G5_callsite, __ delayed_value(java_lang_invoke_CallSite::target_offset_in_bytes, Rscratch), G3_method_handle);
T
twisti 已提交
3313
  __ null_check(G3_method_handle);
3314
  __ verify_oop(G3_method_handle);
T
twisti 已提交
3315 3316 3317 3318 3319 3320 3321

  // Adjust Rret first so Llast_SP can be same as Rret
  __ add(Rret, -frame::pc_return_offset, O7);
  __ add(Lesp, BytesPerWord, Gargs);  // setup parameter pointer
  __ jump_to_method_handle_entry(G3_method_handle, Rtemp, /* emit_delayed_nop */ false);
  // Record SP so we can remove any stack space allocated by adapter transition
  __ delayed()->mov(SP, Llast_SP);
3322 3323 3324
}


D
duke 已提交
3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343
//----------------------------------------------------------------------------------------------------
// Allocation

void TemplateTable::_new() {
  transition(vtos, atos);

  Label slow_case;
  Label done;
  Label initialize_header;
  Label initialize_object;  // including clearing the fields

  Register RallocatedObject = Otos_i;
  Register RinstanceKlass = O1;
  Register Roffset = O3;
  Register Rscratch = O4;

  __ get_2_byte_integer_at_bcp(1, Rscratch, Roffset, InterpreterMacroAssembler::Unsigned);
  __ get_cpool_and_tags(Rscratch, G3_scratch);
  // make sure the class we're about to instantiate has been resolved
3344 3345
  // This is done before loading instanceKlass to be consistent with the order
  // how Constant Pool is updated (see constantPoolOopDesc::klass_at_put)
D
duke 已提交
3346 3347 3348 3349 3350
  __ add(G3_scratch, typeArrayOopDesc::header_size(T_BYTE) * wordSize, G3_scratch);
  __ ldub(G3_scratch, Roffset, G3_scratch);
  __ cmp(G3_scratch, JVM_CONSTANT_Class);
  __ br(Assembler::notEqual, false, Assembler::pn, slow_case);
  __ delayed()->sll(Roffset, LogBytesPerWord, Roffset);
3351
  // get instanceKlass
D
duke 已提交
3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402
  //__ sll(Roffset, LogBytesPerWord, Roffset);        // executed in delay slot
  __ add(Roffset, sizeof(constantPoolOopDesc), Roffset);
  __ ld_ptr(Rscratch, Roffset, RinstanceKlass);

  // make sure klass is fully initialized:
  __ ld(RinstanceKlass, instanceKlass::init_state_offset_in_bytes() + sizeof(oopDesc), G3_scratch);
  __ cmp(G3_scratch, instanceKlass::fully_initialized);
  __ br(Assembler::notEqual, false, Assembler::pn, slow_case);
  __ delayed()->ld(RinstanceKlass, Klass::layout_helper_offset_in_bytes() + sizeof(oopDesc), Roffset);

  // get instance_size in instanceKlass (already aligned)
  //__ ld(RinstanceKlass, Klass::layout_helper_offset_in_bytes() + sizeof(oopDesc), Roffset);

  // make sure klass does not have has_finalizer, or is abstract, or interface or java/lang/Class
  __ btst(Klass::_lh_instance_slow_path_bit, Roffset);
  __ br(Assembler::notZero, false, Assembler::pn, slow_case);
  __ delayed()->nop();

  // allocate the instance
  // 1) Try to allocate in the TLAB
  // 2) if fail, and the TLAB is not full enough to discard, allocate in the shared Eden
  // 3) if the above fails (or is not applicable), go to a slow case
  // (creates a new TLAB, etc.)

  const bool allow_shared_alloc =
    Universe::heap()->supports_inline_contig_alloc() && !CMSIncrementalMode;

  if(UseTLAB) {
    Register RoldTopValue = RallocatedObject;
    Register RtopAddr = G3_scratch, RtlabWasteLimitValue = G3_scratch;
    Register RnewTopValue = G1_scratch;
    Register RendValue = Rscratch;
    Register RfreeValue = RnewTopValue;

    // check if we can allocate in the TLAB
    __ ld_ptr(G2_thread, in_bytes(JavaThread::tlab_top_offset()), RoldTopValue); // sets up RalocatedObject
    __ ld_ptr(G2_thread, in_bytes(JavaThread::tlab_end_offset()), RendValue);
    __ add(RoldTopValue, Roffset, RnewTopValue);

    // if there is enough space, we do not CAS and do not clear
    __ cmp(RnewTopValue, RendValue);
    if(ZeroTLAB) {
      // the fields have already been cleared
      __ brx(Assembler::lessEqualUnsigned, true, Assembler::pt, initialize_header);
    } else {
      // initialize both the header and fields
      __ brx(Assembler::lessEqualUnsigned, true, Assembler::pt, initialize_object);
    }
    __ delayed()->st_ptr(RnewTopValue, G2_thread, in_bytes(JavaThread::tlab_top_offset()));

    if (allow_shared_alloc) {
3403 3404 3405
      // Check if tlab should be discarded (refill_waste_limit >= free)
      __ ld_ptr(G2_thread, in_bytes(JavaThread::tlab_refill_waste_limit_offset()), RtlabWasteLimitValue);
      __ sub(RendValue, RoldTopValue, RfreeValue);
D
duke 已提交
3406
#ifdef _LP64
3407
      __ srlx(RfreeValue, LogHeapWordSize, RfreeValue);
D
duke 已提交
3408
#else
3409
      __ srl(RfreeValue, LogHeapWordSize, RfreeValue);
D
duke 已提交
3410
#endif
3411 3412 3413
      __ cmp(RtlabWasteLimitValue, RfreeValue);
      __ brx(Assembler::greaterEqualUnsigned, false, Assembler::pt, slow_case); // tlab waste is small
      __ delayed()->nop();
D
duke 已提交
3414

3415 3416 3417
      // increment waste limit to prevent getting stuck on this slow path
      __ add(RtlabWasteLimitValue, ThreadLocalAllocBuffer::refill_waste_limit_increment(), RtlabWasteLimitValue);
      __ st_ptr(RtlabWasteLimitValue, G2_thread, in_bytes(JavaThread::tlab_refill_waste_limit_offset()));
D
duke 已提交
3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454
    } else {
      // No allocation in the shared eden.
      __ br(Assembler::always, false, Assembler::pt, slow_case);
      __ delayed()->nop();
    }
  }

  // Allocation in the shared Eden
  if (allow_shared_alloc) {
    Register RoldTopValue = G1_scratch;
    Register RtopAddr = G3_scratch;
    Register RnewTopValue = RallocatedObject;
    Register RendValue = Rscratch;

    __ set((intptr_t)Universe::heap()->top_addr(), RtopAddr);

    Label retry;
    __ bind(retry);
    __ set((intptr_t)Universe::heap()->end_addr(), RendValue);
    __ ld_ptr(RendValue, 0, RendValue);
    __ ld_ptr(RtopAddr, 0, RoldTopValue);
    __ add(RoldTopValue, Roffset, RnewTopValue);

    // RnewTopValue contains the top address after the new object
    // has been allocated.
    __ cmp(RnewTopValue, RendValue);
    __ brx(Assembler::greaterUnsigned, false, Assembler::pn, slow_case);
    __ delayed()->nop();

    __ casx_under_lock(RtopAddr, RoldTopValue, RnewTopValue,
      VM_Version::v9_instructions_work() ? NULL :
      (address)StubRoutines::Sparc::atomic_memory_operation_lock_addr());

    // if someone beat us on the allocation, try again, otherwise continue
    __ cmp(RoldTopValue, RnewTopValue);
    __ brx(Assembler::notEqual, false, Assembler::pn, retry);
    __ delayed()->nop();
3455 3456

    // bump total bytes allocated by this thread
3457 3458
    // RoldTopValue and RtopAddr are dead, so can use G1 and G3
    __ incr_allocated_bytes(Roffset, G1_scratch, G3_scratch);
D
duke 已提交
3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499
  }

  if (UseTLAB || Universe::heap()->supports_inline_contig_alloc()) {
    // clear object fields
    __ bind(initialize_object);
    __ deccc(Roffset, sizeof(oopDesc));
    __ br(Assembler::zero, false, Assembler::pt, initialize_header);
    __ delayed()->add(RallocatedObject, sizeof(oopDesc), G3_scratch);

    // initialize remaining object fields
    { Label loop;
      __ subcc(Roffset, wordSize, Roffset);
      __ bind(loop);
      //__ subcc(Roffset, wordSize, Roffset);      // executed above loop or in delay slot
      __ st_ptr(G0, G3_scratch, Roffset);
      __ br(Assembler::notEqual, false, Assembler::pt, loop);
      __ delayed()->subcc(Roffset, wordSize, Roffset);
    }
    __ br(Assembler::always, false, Assembler::pt, initialize_header);
    __ delayed()->nop();
  }

  // slow case
  __ bind(slow_case);
  __ get_2_byte_integer_at_bcp(1, G3_scratch, O2, InterpreterMacroAssembler::Unsigned);
  __ get_constant_pool(O1);

  call_VM(Otos_i, CAST_FROM_FN_PTR(address, InterpreterRuntime::_new), O1, O2);

  __ ba(false, done);
  __ delayed()->nop();

  // Initialize the header: mark, klass
  __ bind(initialize_header);

  if (UseBiasedLocking) {
    __ ld_ptr(RinstanceKlass, Klass::prototype_header_offset_in_bytes() + sizeof(oopDesc), G4_scratch);
  } else {
    __ set((intptr_t)markOopDesc::prototype(), G4_scratch);
  }
  __ st_ptr(G4_scratch, RallocatedObject, oopDesc::mark_offset_in_bytes());       // mark
3500 3501
  __ store_klass_gap(G0, RallocatedObject);         // klass gap if compressed
  __ store_klass(RinstanceKlass, RallocatedObject); // klass (last for cms)
D
duke 已提交
3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556

  {
    SkipIfEqual skip_if(
      _masm, G4_scratch, &DTraceAllocProbes, Assembler::zero);
    // Trigger dtrace event
    __ push(atos);
    __ call_VM_leaf(noreg,
       CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_object_alloc), O0);
    __ pop(atos);
  }

  // continue
  __ bind(done);
}



void TemplateTable::newarray() {
  transition(itos, atos);
  __ ldub(Lbcp, 1, O1);
     call_VM(Otos_i, CAST_FROM_FN_PTR(address, InterpreterRuntime::newarray), O1, Otos_i);
}


void TemplateTable::anewarray() {
  transition(itos, atos);
  __ get_constant_pool(O1);
  __ get_2_byte_integer_at_bcp(1, G4_scratch, O2, InterpreterMacroAssembler::Unsigned);
     call_VM(Otos_i, CAST_FROM_FN_PTR(address, InterpreterRuntime::anewarray), O1, O2, Otos_i);
}


void TemplateTable::arraylength() {
  transition(atos, itos);
  Label ok;
  __ verify_oop(Otos_i);
  __ tst(Otos_i);
  __ throw_if_not_1_x( Assembler::notZero, ok );
  __ delayed()->ld(Otos_i, arrayOopDesc::length_offset_in_bytes(), Otos_i);
  __ throw_if_not_2( Interpreter::_throw_NullPointerException_entry, G3_scratch, ok);
}


void TemplateTable::checkcast() {
  transition(atos, atos);
  Label done, is_null, quicked, cast_ok, resolved;
  Register Roffset = G1_scratch;
  Register RobjKlass = O5;
  Register RspecifiedKlass = O4;

  // Check for casting a NULL
  __ br_null(Otos_i, false, Assembler::pn, is_null);
  __ delayed()->nop();

  // Get value klass in RobjKlass
3557
  __ load_klass(Otos_i, RobjKlass); // get value klass
D
duke 已提交
3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574

  // Get constant pool tag
  __ get_2_byte_integer_at_bcp(1, Lscratch, Roffset, InterpreterMacroAssembler::Unsigned);

  // See if the checkcast has been quickened
  __ get_cpool_and_tags(Lscratch, G3_scratch);
  __ add(G3_scratch, typeArrayOopDesc::header_size(T_BYTE) * wordSize, G3_scratch);
  __ ldub(G3_scratch, Roffset, G3_scratch);
  __ cmp(G3_scratch, JVM_CONSTANT_Class);
  __ br(Assembler::equal, true, Assembler::pt, quicked);
  __ delayed()->sll(Roffset, LogBytesPerWord, Roffset);

  __ push_ptr(); // save receiver for result, and for GC
  call_VM(RspecifiedKlass, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc) );
  __ pop_ptr(Otos_i, G3_scratch); // restore receiver

  __ br(Assembler::always, false, Assembler::pt, resolved);
3575
  __ delayed()->nop();
D
duke 已提交
3576 3577 3578 3579 3580 3581

  // Extract target class from constant pool
  __ bind(quicked);
  __ add(Roffset, sizeof(constantPoolOopDesc), Roffset);
  __ ld_ptr(Lscratch, Roffset, RspecifiedKlass);
  __ bind(resolved);
3582
  __ load_klass(Otos_i, RobjKlass); // get value klass
D
duke 已提交
3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614

  // Generate a fast subtype check.  Branch to cast_ok if no
  // failure.  Throw exception if failure.
  __ gen_subtype_check( RobjKlass, RspecifiedKlass, G3_scratch, G4_scratch, G1_scratch, cast_ok );

  // Not a subtype; so must throw exception
  __ throw_if_not_x( Assembler::never, Interpreter::_throw_ClassCastException_entry, G3_scratch );

  __ bind(cast_ok);

  if (ProfileInterpreter) {
    __ ba(false, done);
    __ delayed()->nop();
  }
  __ bind(is_null);
  __ profile_null_seen(G3_scratch);
  __ bind(done);
}


void TemplateTable::instanceof() {
  Label done, is_null, quicked, resolved;
  transition(atos, itos);
  Register Roffset = G1_scratch;
  Register RobjKlass = O5;
  Register RspecifiedKlass = O4;

  // Check for casting a NULL
  __ br_null(Otos_i, false, Assembler::pt, is_null);
  __ delayed()->nop();

  // Get value klass in RobjKlass
3615
  __ load_klass(Otos_i, RobjKlass); // get value klass
D
duke 已提交
3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632

  // Get constant pool tag
  __ get_2_byte_integer_at_bcp(1, Lscratch, Roffset, InterpreterMacroAssembler::Unsigned);

  // See if the checkcast has been quickened
  __ get_cpool_and_tags(Lscratch, G3_scratch);
  __ add(G3_scratch, typeArrayOopDesc::header_size(T_BYTE) * wordSize, G3_scratch);
  __ ldub(G3_scratch, Roffset, G3_scratch);
  __ cmp(G3_scratch, JVM_CONSTANT_Class);
  __ br(Assembler::equal, true, Assembler::pt, quicked);
  __ delayed()->sll(Roffset, LogBytesPerWord, Roffset);

  __ push_ptr(); // save receiver for result, and for GC
  call_VM(RspecifiedKlass, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc) );
  __ pop_ptr(Otos_i, G3_scratch); // restore receiver

  __ br(Assembler::always, false, Assembler::pt, resolved);
3633
  __ delayed()->nop();
D
duke 已提交
3634 3635 3636 3637 3638 3639 3640 3641


  // Extract target class from constant pool
  __ bind(quicked);
  __ add(Roffset, sizeof(constantPoolOopDesc), Roffset);
  __ get_constant_pool(Lscratch);
  __ ld_ptr(Lscratch, Roffset, RspecifiedKlass);
  __ bind(resolved);
3642
  __ load_klass(Otos_i, RobjKlass); // get value klass
D
duke 已提交
3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829

  // Generate a fast subtype check.  Branch to cast_ok if no
  // failure.  Return 0 if failure.
  __ or3(G0, 1, Otos_i);      // set result assuming quick tests succeed
  __ gen_subtype_check( RobjKlass, RspecifiedKlass, G3_scratch, G4_scratch, G1_scratch, done );
  // Not a subtype; return 0;
  __ clr( Otos_i );

  if (ProfileInterpreter) {
    __ ba(false, done);
    __ delayed()->nop();
  }
  __ bind(is_null);
  __ profile_null_seen(G3_scratch);
  __ bind(done);
}

void TemplateTable::_breakpoint() {

   // Note: We get here even if we are single stepping..
   // jbug inists on setting breakpoints at every bytecode
   // even if we are in single step mode.

   transition(vtos, vtos);
   // get the unpatched byte code
   __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::get_original_bytecode_at), Lmethod, Lbcp);
   __ mov(O0, Lbyte_code);

   // post the breakpoint event
   __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::_breakpoint), Lmethod, Lbcp);

   // complete the execution of original bytecode
   __ dispatch_normal(vtos);
}


//----------------------------------------------------------------------------------------------------
// Exceptions

void TemplateTable::athrow() {
  transition(atos, vtos);

  // This works because exception is cached in Otos_i which is same as O0,
  // which is same as what throw_exception_entry_expects
  assert(Otos_i == Oexception, "see explanation above");

  __ verify_oop(Otos_i);
  __ null_check(Otos_i);
  __ throw_if_not_x(Assembler::never, Interpreter::throw_exception_entry(), G3_scratch);
}


//----------------------------------------------------------------------------------------------------
// Synchronization


// See frame_sparc.hpp for monitor block layout.
// Monitor elements are dynamically allocated by growing stack as needed.

void TemplateTable::monitorenter() {
  transition(atos, vtos);
  __ verify_oop(Otos_i);
  // Try to acquire a lock on the object
  // Repeat until succeeded (i.e., until
  // monitorenter returns true).

  {   Label ok;
    __ tst(Otos_i);
    __ throw_if_not_1_x( Assembler::notZero,  ok);
    __ delayed()->mov(Otos_i, Lscratch); // save obj
    __ throw_if_not_2( Interpreter::_throw_NullPointerException_entry, G3_scratch, ok);
  }

  assert(O0 == Otos_i, "Be sure where the object to lock is");

  // find a free slot in the monitor block


  // initialize entry pointer
  __ clr(O1); // points to free slot or NULL

  {
    Label entry, loop, exit;
    __ add( __ top_most_monitor(), O2 ); // last one to check
    __ ba( false, entry );
    __ delayed()->mov( Lmonitors, O3 ); // first one to check


    __ bind( loop );

    __ verify_oop(O4);          // verify each monitor's oop
    __ tst(O4); // is this entry unused?
    if (VM_Version::v9_instructions_work())
      __ movcc( Assembler::zero, false, Assembler::ptr_cc, O3, O1);
    else {
      Label L;
      __ br( Assembler::zero, true, Assembler::pn, L );
      __ delayed()->mov(O3, O1); // rememeber this one if match
      __ bind(L);
    }

    __ cmp(O4, O0); // check if current entry is for same object
    __ brx( Assembler::equal, false, Assembler::pn, exit );
    __ delayed()->inc( O3, frame::interpreter_frame_monitor_size() * wordSize ); // check next one

    __ bind( entry );

    __ cmp( O3, O2 );
    __ brx( Assembler::lessEqualUnsigned, true, Assembler::pt, loop );
    __ delayed()->ld_ptr(O3, BasicObjectLock::obj_offset_in_bytes(), O4);

    __ bind( exit );
  }

  { Label allocated;

    // found free slot?
    __ br_notnull(O1, false, Assembler::pn, allocated);
    __ delayed()->nop();

    __ add_monitor_to_stack( false, O2, O3 );
    __ mov(Lmonitors, O1);

    __ bind(allocated);
  }

  // Increment bcp to point to the next bytecode, so exception handling for async. exceptions work correctly.
  // The object has already been poped from the stack, so the expression stack looks correct.
  __ inc(Lbcp);

  __ st_ptr(O0, O1, BasicObjectLock::obj_offset_in_bytes()); // store object
  __ lock_object(O1, O0);

  // check if there's enough space on the stack for the monitors after locking
  __ generate_stack_overflow_check(0);

  // The bcp has already been incremented. Just need to dispatch to next instruction.
  __ dispatch_next(vtos);
}


void TemplateTable::monitorexit() {
  transition(atos, vtos);
  __ verify_oop(Otos_i);
  __ tst(Otos_i);
  __ throw_if_not_x( Assembler::notZero, Interpreter::_throw_NullPointerException_entry, G3_scratch );

  assert(O0 == Otos_i, "just checking");

  { Label entry, loop, found;
    __ add( __ top_most_monitor(), O2 ); // last one to check
    __ ba(false, entry );
    // use Lscratch to hold monitor elem to check, start with most recent monitor,
    // By using a local it survives the call to the C routine.
    __ delayed()->mov( Lmonitors, Lscratch );

    __ bind( loop );

    __ verify_oop(O4);          // verify each monitor's oop
    __ cmp(O4, O0); // check if current entry is for desired object
    __ brx( Assembler::equal, true, Assembler::pt, found );
    __ delayed()->mov(Lscratch, O1); // pass found entry as argument to monitorexit

    __ inc( Lscratch, frame::interpreter_frame_monitor_size() * wordSize ); // advance to next

    __ bind( entry );

    __ cmp( Lscratch, O2 );
    __ brx( Assembler::lessEqualUnsigned, true, Assembler::pt, loop );
    __ delayed()->ld_ptr(Lscratch, BasicObjectLock::obj_offset_in_bytes(), O4);

    call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_illegal_monitor_state_exception));
    __ should_not_reach_here();

    __ bind(found);
  }
  __ unlock_object(O1);
}


//----------------------------------------------------------------------------------------------------
// Wide instructions

void TemplateTable::wide() {
  transition(vtos, vtos);
  __ ldub(Lbcp, 1, G3_scratch);// get next bc
  __ sll(G3_scratch, LogBytesPerWord, G3_scratch);
3830 3831 3832
  AddressLiteral ep(Interpreter::_wentry_point);
  __ set(ep, G4_scratch);
  __ ld_ptr(G4_scratch, G3_scratch, G3_scratch);
D
duke 已提交
3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845
  __ jmp(G3_scratch, G0);
  __ delayed()->nop();
  // Note: the Lbcp increment step is part of the individual wide bytecode implementations
}


//----------------------------------------------------------------------------------------------------
// Multi arrays

void TemplateTable::multianewarray() {
  transition(vtos, atos);
     // put ndims * wordSize into Lscratch
  __ ldub( Lbcp,     3,               Lscratch);
3846
  __ sll(  Lscratch, Interpreter::logStackElementSize, Lscratch);
D
duke 已提交
3847 3848 3849 3850 3851 3852
     // Lesp points past last_dim, so set to O1 to first_dim address
  __ add(  Lesp,     Lscratch,        O1);
     call_VM(Otos_i, CAST_FROM_FN_PTR(address, InterpreterRuntime::multianewarray), O1);
  __ add(  Lesp,     Lscratch,        Lesp); // pop all dimensions off the stack
}
#endif /* !CC_INTERP */