src/cpu/sparc/vm/templateInterpreter_sparc.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File 7063628 Sdiff src/cpu/sparc/vm

src/cpu/sparc/vm/templateInterpreter_sparc.cpp

Print this page




 173     __ srl (G1,  0, O1);
 174     __ srlx(G1, 32, O0);
 175   }
 176 #endif // !_LP64 && COMPILER2
 177 
 178   __ bind(cont);
 179 
 180   // The callee returns with the stack possibly adjusted by adapter transition
 181   // We remove that possible adjustment here.
 182   // All interpreter local registers are untouched. Any result is passed back
 183   // in the O0/O1 or float registers. Before continuing, the arguments must be
 184   // popped from the java expression stack; i.e., Lesp must be adjusted.
 185 
 186   __ mov(Llast_SP, SP);   // Remove any adapter added stack space.
 187 
 188   Label L_got_cache, L_giant_index;
 189   const Register cache = G3_scratch;
 190   const Register size  = G1_scratch;
 191   if (EnableInvokeDynamic) {
 192     __ ldub(Address(Lbcp, 0), G1_scratch);  // Load current bytecode.
 193     __ cmp(G1_scratch, Bytecodes::_invokedynamic);
 194     __ br(Assembler::equal, false, Assembler::pn, L_giant_index);
 195     __ delayed()->nop();
 196   }
 197   __ get_cache_and_index_at_bcp(cache, G1_scratch, 1);
 198   __ bind(L_got_cache);
 199   __ ld_ptr(cache, constantPoolCacheOopDesc::base_offset() +
 200                    ConstantPoolCacheEntry::flags_offset(), size);
 201   __ and3(size, 0xFF, size);                   // argument size in words
 202   __ sll(size, Interpreter::logStackElementSize, size); // each argument size in bytes
 203   __ add(Lesp, size, Lesp);                    // pop arguments
 204   __ dispatch_next(state, step);
 205 
 206   // out of the main line of code...
 207   if (EnableInvokeDynamic) {
 208     __ bind(L_giant_index);
 209     __ get_cache_and_index_at_bcp(cache, G1_scratch, 1, sizeof(u4));
 210     __ ba(false, L_got_cache);
 211     __ delayed()->nop();
 212   }
 213 
 214   return entry;
 215 }
 216 
 217 
 218 address TemplateInterpreterGenerator::generate_deopt_entry_for(TosState state, int step) {
 219   address entry = __ pc();
 220   __ get_constant_pool_cache(LcpoolCache); // load LcpoolCache
 221   { Label L;
 222     Address exception_addr(G2_thread, Thread::pending_exception_offset());
 223     __ ld_ptr(exception_addr, Gtemp);  // Load pending exception.
 224     __ tst(Gtemp);
 225     __ brx(Assembler::equal, false, Assembler::pt, L);
 226     __ delayed()->nop();
 227     __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_pending_exception));
 228     __ should_not_reach_here();
 229     __ bind(L);
 230   }
 231   __ dispatch_next(state, step);
 232   return entry;
 233 }
 234 
 235 // A result handler converts/unboxes a native call result into
 236 // a java interpreter/compiler result. The current frame is an
 237 // interpreter frame. The activation frame unwind code must be
 238 // consistent with that of TemplateTable::_return(...). In the
 239 // case of native methods, the caller's SP was not modified.
 240 address TemplateInterpreterGenerator::generate_result_handler_for(BasicType type) {
 241   address entry = __ pc();
 242   Register Itos_i  = Otos_i ->after_save();
 243   Register Itos_l  = Otos_l ->after_save();
 244   Register Itos_l1 = Otos_l1->after_save();
 245   Register Itos_l2 = Otos_l2->after_save();
 246   switch (type) {


 287 // Helpers for commoning out cases in the various type of method entries.
 288 //
 289 
 290 // increment invocation count & check for overflow
 291 //
 292 // Note: checking for negative value instead of overflow
 293 //       so we have a 'sticky' overflow test
 294 //
 295 // Lmethod: method
 296 // ??: invocation counter
 297 //
 298 void InterpreterGenerator::generate_counter_incr(Label* overflow, Label* profile_method, Label* profile_method_continue) {
 299   // Note: In tiered we increment either counters in methodOop or in MDO depending if we're profiling or not.
 300   if (TieredCompilation) {
 301     const int increment = InvocationCounter::count_increment;
 302     const int mask = ((1 << Tier0InvokeNotifyFreqLog) - 1) << InvocationCounter::count_shift;
 303     Label no_mdo, done;
 304     if (ProfileInterpreter) {
 305       // If no method data exists, go to profile_continue.
 306       __ ld_ptr(Lmethod, methodOopDesc::method_data_offset(), G4_scratch);
 307       __ br_null(G4_scratch, false, Assembler::pn, no_mdo);
 308       __ delayed()->nop();
 309       // Increment counter
 310       Address mdo_invocation_counter(G4_scratch,
 311                                      in_bytes(methodDataOopDesc::invocation_counter_offset()) +
 312                                      in_bytes(InvocationCounter::counter_offset()));
 313       __ increment_mask_and_jump(mdo_invocation_counter, increment, mask,
 314                                  G3_scratch, Lscratch,
 315                                  Assembler::zero, overflow);
 316       __ ba(false, done);
 317       __ delayed()->nop();
 318     }
 319 
 320     // Increment counter in methodOop
 321     __ bind(no_mdo);
 322     Address invocation_counter(Lmethod,
 323                                in_bytes(methodOopDesc::invocation_counter_offset()) +
 324                                in_bytes(InvocationCounter::counter_offset()));
 325     __ increment_mask_and_jump(invocation_counter, increment, mask,
 326                                G3_scratch, Lscratch,
 327                                Assembler::zero, overflow);
 328     __ bind(done);
 329   } else {
 330     // Update standard invocation counters
 331     __ increment_invocation_counter(O0, G3_scratch);
 332     if (ProfileInterpreter) {  // %%% Merge this into methodDataOop
 333       Address interpreter_invocation_counter(Lmethod,in_bytes(methodOopDesc::interpreter_invocation_counter_offset()));
 334       __ ld(interpreter_invocation_counter, G3_scratch);
 335       __ inc(G3_scratch);
 336       __ st(G3_scratch, interpreter_invocation_counter);
 337     }
 338 
 339     if (ProfileInterpreter && profile_method != NULL) {
 340       // Test to see if we should create a method data oop
 341       AddressLiteral profile_limit((address)&InvocationCounter::InterpreterProfileLimit);
 342       __ load_contents(profile_limit, G3_scratch);
 343       __ cmp(O0, G3_scratch);
 344       __ br(Assembler::lessUnsigned, false, Assembler::pn, *profile_method_continue);
 345       __ delayed()->nop();
 346 
 347       // if no method data exists, go to profile_method
 348       __ test_method_data_pointer(*profile_method);
 349     }
 350 
 351     AddressLiteral invocation_limit((address)&InvocationCounter::InterpreterInvocationLimit);
 352     __ load_contents(invocation_limit, G3_scratch);
 353     __ cmp(O0, G3_scratch);
 354     __ br(Assembler::greaterEqualUnsigned, false, Assembler::pn, *overflow);
 355     __ delayed()->nop();
 356   }
 357 
 358 }
 359 
 360 // Allocate monitor and lock method (asm interpreter)
 361 // ebx - methodOop
 362 //
 363 void InterpreterGenerator::lock_method(void) {
 364   __ ld(Lmethod, in_bytes(methodOopDesc::access_flags_offset()), O0);  // Load access flags.
 365 
 366 #ifdef ASSERT
 367  { Label ok;
 368    __ btst(JVM_ACC_SYNCHRONIZED, O0);
 369    __ br( Assembler::notZero, false, Assembler::pt, ok);
 370    __ delayed()->nop();
 371    __ stop("method doesn't need synchronization");
 372    __ bind(ok);
 373   }
 374 #endif // ASSERT


 393 
 394     __ bind(done);
 395   }
 396 
 397   __ add_monitor_to_stack(true, noreg, noreg);  // allocate monitor elem
 398   __ st_ptr( O0, Lmonitors, BasicObjectLock::obj_offset_in_bytes());   // store object
 399   // __ untested("lock_object from method entry");
 400   __ lock_object(Lmonitors, O0);
 401 }
 402 
 403 
 404 void TemplateInterpreterGenerator::generate_stack_overflow_check(Register Rframe_size,
 405                                                          Register Rscratch,
 406                                                          Register Rscratch2) {
 407   const int page_size = os::vm_page_size();
 408   Address saved_exception_pc(G2_thread, JavaThread::saved_exception_pc_offset());
 409   Label after_frame_check;
 410 
 411   assert_different_registers(Rframe_size, Rscratch, Rscratch2);
 412 
 413   __ set( page_size,   Rscratch );
 414   __ cmp( Rframe_size, Rscratch );
 415 
 416   __ br( Assembler::lessEqual, false, Assembler::pt, after_frame_check );
 417   __ delayed()->nop();
 418 
 419   // get the stack base, and in debug, verify it is non-zero
 420   __ ld_ptr( G2_thread, Thread::stack_base_offset(), Rscratch );
 421 #ifdef ASSERT
 422   Label base_not_zero;
 423   __ cmp( Rscratch, G0 );
 424   __ brx( Assembler::notEqual, false, Assembler::pn, base_not_zero );
 425   __ delayed()->nop();
 426   __ stop("stack base is zero in generate_stack_overflow_check");
 427   __ bind(base_not_zero);
 428 #endif
 429 
 430   // get the stack size, and in debug, verify it is non-zero
 431   assert( sizeof(size_t) == sizeof(intptr_t), "wrong load size" );
 432   __ ld_ptr( G2_thread, Thread::stack_size_offset(), Rscratch2 );
 433 #ifdef ASSERT
 434   Label size_not_zero;
 435   __ cmp( Rscratch2, G0 );
 436   __ brx( Assembler::notEqual, false, Assembler::pn, size_not_zero );
 437   __ delayed()->nop();
 438   __ stop("stack size is zero in generate_stack_overflow_check");
 439   __ bind(size_not_zero);
 440 #endif
 441 
 442   // compute the beginning of the protected zone minus the requested frame size
 443   __ sub( Rscratch, Rscratch2,   Rscratch );
 444   __ set( (StackRedPages+StackYellowPages) * page_size, Rscratch2 );
 445   __ add( Rscratch, Rscratch2,   Rscratch );
 446 
 447   // Add in the size of the frame (which is the same as subtracting it from the
 448   // SP, which would take another register
 449   __ add( Rscratch, Rframe_size, Rscratch );
 450 
 451   // the frame is greater than one page in size, so check against
 452   // the bottom of the stack
 453   __ cmp( SP, Rscratch );
 454   __ brx( Assembler::greater, false, Assembler::pt, after_frame_check );
 455   __ delayed()->nop();
 456 
 457   // Save the return address as the exception pc
 458   __ st_ptr(O7, saved_exception_pc);
 459 
 460   // the stack will overflow, throw an exception
 461   __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_StackOverflowError));
 462 
 463   // if you get to here, then there is enough stack space
 464   __ bind( after_frame_check );
 465 }
 466 
 467 
 468 //
 469 // Generate a fixed interpreter frame. This is identical setup for interpreted
 470 // methods and for native methods hence the shared code.
 471 
 472 void TemplateInterpreterGenerator::generate_fixed_frame(bool native_call) {
 473   //
 474   //
 475   // The entry code sets up a new interpreter frame in 4 steps:


 607   }
 608 
 609 }
 610 
 611 // Empty method, generate a very fast return.
 612 
 613 address InterpreterGenerator::generate_empty_entry(void) {
 614 
 615   // A method that does nother but return...
 616 
 617   address entry = __ pc();
 618   Label slow_path;
 619 
 620   __ verify_oop(G5_method);
 621 
 622   // do nothing for empty methods (do not even increment invocation counter)
 623   if ( UseFastEmptyMethods) {
 624     // If we need a safepoint check, generate full interpreter entry.
 625     AddressLiteral sync_state(SafepointSynchronize::address_of_state());
 626     __ set(sync_state, G3_scratch);
 627     __ cmp(G3_scratch, SafepointSynchronize::_not_synchronized);
 628     __ br(Assembler::notEqual, false, Assembler::pn, slow_path);
 629     __ delayed()->nop();
 630 
 631     // Code: _return
 632     __ retl();
 633     __ delayed()->mov(O5_savedSP, SP);
 634 
 635     __ bind(slow_path);
 636     (void) generate_normal_entry(false);
 637 
 638     return entry;
 639   }
 640   return NULL;
 641 }
 642 
 643 // Call an accessor method (assuming it is resolved, otherwise drop into
 644 // vanilla (slow path) entry
 645 
 646 // Generates code to elide accessor methods
 647 // Uses G3_scratch and G1_scratch as scratch
 648 address InterpreterGenerator::generate_accessor_entry(void) {
 649 
 650   // Code: _aload_0, _(i|a)getfield, _(i|a)return or any rewrites thereof;
 651   // parameter size = 1
 652   // Note: We can only use this code if the getfield has been resolved
 653   //       and if we don't have a null-pointer exception => check for
 654   //       these conditions first and use slow path if necessary.
 655   address entry = __ pc();
 656   Label slow_path;
 657 
 658 
 659   // XXX: for compressed oops pointer loading and decoding doesn't fit in
 660   // delay slot and damages G1
 661   if ( UseFastAccessorMethods && !UseCompressedOops ) {
 662     // Check if we need to reach a safepoint and generate full interpreter
 663     // frame if so.
 664     AddressLiteral sync_state(SafepointSynchronize::address_of_state());
 665     __ load_contents(sync_state, G3_scratch);
 666     __ cmp(G3_scratch, SafepointSynchronize::_not_synchronized);
 667     __ br(Assembler::notEqual, false, Assembler::pn, slow_path);
 668     __ delayed()->nop();
 669 
 670     // Check if local 0 != NULL
 671     __ ld_ptr(Gargs, G0, Otos_i ); // get local 0
 672     __ tst(Otos_i);  // check if local 0 == NULL and go the slow path
 673     __ brx(Assembler::zero, false, Assembler::pn, slow_path);
 674     __ delayed()->nop();
 675 
 676 
 677     // read first instruction word and extract bytecode @ 1 and index @ 2
 678     // get first 4 bytes of the bytecodes (big endian!)
 679     __ ld_ptr(G5_method, methodOopDesc::const_offset(), G1_scratch);
 680     __ ld(G1_scratch, constMethodOopDesc::codes_offset(), G1_scratch);
 681 
 682     // move index @ 2 far left then to the right most two bytes.
 683     __ sll(G1_scratch, 2*BitsPerByte, G1_scratch);
 684     __ srl(G1_scratch, 2*BitsPerByte - exact_log2(in_words(
 685                       ConstantPoolCacheEntry::size()) * BytesPerWord), G1_scratch);
 686 
 687     // get constant pool cache
 688     __ ld_ptr(G5_method, methodOopDesc::constants_offset(), G3_scratch);
 689     __ ld_ptr(G3_scratch, constantPoolOopDesc::cache_offset_in_bytes(), G3_scratch);
 690 
 691     // get specific constant pool cache entry
 692     __ add(G3_scratch, G1_scratch, G3_scratch);
 693 
 694     // Check the constant Pool cache entry to see if it has been resolved.
 695     // If not, need the slow path.
 696     ByteSize cp_base_offset = constantPoolCacheOopDesc::base_offset();
 697     __ ld_ptr(G3_scratch, cp_base_offset + ConstantPoolCacheEntry::indices_offset(), G1_scratch);
 698     __ srl(G1_scratch, 2*BitsPerByte, G1_scratch);
 699     __ and3(G1_scratch, 0xFF, G1_scratch);
 700     __ cmp(G1_scratch, Bytecodes::_getfield);
 701     __ br(Assembler::notEqual, false, Assembler::pn, slow_path);
 702     __ delayed()->nop();
 703 
 704     // Get the type and return field offset from the constant pool cache
 705     __ ld_ptr(G3_scratch, cp_base_offset + ConstantPoolCacheEntry::flags_offset(), G1_scratch);
 706     __ ld_ptr(G3_scratch, cp_base_offset + ConstantPoolCacheEntry::f2_offset(), G3_scratch);
 707 
 708     Label xreturn_path;
 709     // Need to differentiate between igetfield, agetfield, bgetfield etc.
 710     // because they are different sizes.
 711     // Get the type from the constant pool cache
 712     __ srl(G1_scratch, ConstantPoolCacheEntry::tosBits, G1_scratch);
 713     // Make sure we don't need to mask G1_scratch for tosBits after the above shift
 714     ConstantPoolCacheEntry::verify_tosBits();
 715     __ cmp(G1_scratch, atos );
 716     __ br(Assembler::equal, true, Assembler::pt, xreturn_path);
 717     __ delayed()->ld_ptr(Otos_i, G3_scratch, Otos_i);
 718     __ cmp(G1_scratch, itos);
 719     __ br(Assembler::equal, true, Assembler::pt, xreturn_path);
 720     __ delayed()->ld(Otos_i, G3_scratch, Otos_i);
 721     __ cmp(G1_scratch, stos);
 722     __ br(Assembler::equal, true, Assembler::pt, xreturn_path);


 770   //   Reference object is null then we obviously cannot fetch the referent
 771   //   and so we don't need to call the G1 pre-barrier. Thus we can use the
 772   //   regular method entry code to generate the NPE.
 773   //
 774   // This code is based on generate_accessor_enty.
 775 
 776   address entry = __ pc();
 777 
 778   const int referent_offset = java_lang_ref_Reference::referent_offset;
 779   guarantee(referent_offset > 0, "referent offset not initialized");
 780 
 781   if (UseG1GC) {
 782      Label slow_path;
 783 
 784     // In the G1 code we don't check if we need to reach a safepoint. We
 785     // continue and the thread will safepoint at the next bytecode dispatch.
 786 
 787     // Check if local 0 != NULL
 788     // If the receiver is null then it is OK to jump to the slow path.
 789     __ ld_ptr(Gargs, G0, Otos_i ); // get local 0
 790     __ tst(Otos_i);  // check if local 0 == NULL and go the slow path
 791     __ brx(Assembler::zero, false, Assembler::pn, slow_path);
 792     __ delayed()->nop();
 793 
 794 
 795     // Load the value of the referent field.
 796     if (Assembler::is_simm13(referent_offset)) {
 797       __ load_heap_oop(Otos_i, referent_offset, Otos_i);
 798     } else {
 799       __ set(referent_offset, G3_scratch);
 800       __ load_heap_oop(Otos_i, G3_scratch, Otos_i);
 801     }
 802 
 803     // Generate the G1 pre-barrier code to log the value of
 804     // the referent field in an SATB buffer. Note with
 805     // these parameters the pre-barrier does not generate
 806     // the load of the previous value
 807 
 808     __ g1_write_barrier_pre(noreg /* obj */, noreg /* index */, 0 /* offset */,
 809                             Otos_i /* pre_val */,
 810                             G3_scratch /* tmp */,
 811                             true /* preserve_o_regs */);
 812 


 935 
 936 
 937   // start execution
 938   __ verify_thread();
 939 
 940   // JVMTI support
 941   __ notify_method_entry();
 942 
 943   // native call
 944 
 945   // (note that O0 is never an oop--at most it is a handle)
 946   // It is important not to smash any handles created by this call,
 947   // until any oop handle in O0 is dereferenced.
 948 
 949   // (note that the space for outgoing params is preallocated)
 950 
 951   // get signature handler
 952   { Label L;
 953     Address signature_handler(Lmethod, methodOopDesc::signature_handler_offset());
 954     __ ld_ptr(signature_handler, G3_scratch);
 955     __ tst(G3_scratch);
 956     __ brx(Assembler::notZero, false, Assembler::pt, L);
 957     __ delayed()->nop();
 958     __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::prepare_native_call), Lmethod);
 959     __ ld_ptr(signature_handler, G3_scratch);
 960     __ bind(L);
 961   }
 962 
 963   // Push a new frame so that the args will really be stored in
 964   // Copy a few locals across so the new frame has the variables
 965   // we need but these values will be dead at the jni call and
 966   // therefore not gc volatile like the values in the current
 967   // frame (Lmethod in particular)
 968 
 969   // Flush the method pointer to the register save area
 970   __ st_ptr(Lmethod, SP, (Lmethod->sp_offset_in_saved_window() * wordSize) + STACK_BIAS);
 971   __ mov(Llocals, O1);
 972 
 973   // calculate where the mirror handle body is allocated in the interpreter frame:
 974   __ add(FP, (frame::interpreter_frame_oop_temp_offset * wordSize) + STACK_BIAS, O2);
 975 
 976   // Calculate current frame size
 977   __ sub(SP, FP, O3);         // Calculate negative of current frame size


1002 
1003   // Reload interpreter frame's Lmethod since slow signature handler may block
1004   __ ld_ptr(FP, (Lmethod->sp_offset_in_saved_window() * wordSize) + STACK_BIAS, Lmethod);
1005 
1006   { Label not_static;
1007 
1008     __ ld(Laccess_flags, O0);
1009     __ btst(JVM_ACC_STATIC, O0);
1010     __ br( Assembler::zero, false, Assembler::pt, not_static);
1011     // get native function entry point(O0 is a good temp until the very end)
1012     __ delayed()->ld_ptr(Lmethod, in_bytes(methodOopDesc::native_function_offset()), O0);
1013     // for static methods insert the mirror argument
1014     const int mirror_offset = klassOopDesc::klass_part_offset_in_bytes() + Klass::java_mirror_offset_in_bytes();
1015 
1016     __ ld_ptr(Lmethod, methodOopDesc:: constants_offset(), O1);
1017     __ ld_ptr(O1, constantPoolOopDesc::pool_holder_offset_in_bytes(), O1);
1018     __ ld_ptr(O1, mirror_offset, O1);
1019 #ifdef ASSERT
1020     if (!PrintSignatureHandlers)  // do not dirty the output with this
1021     { Label L;
1022       __ tst(O1);
1023       __ brx(Assembler::notZero, false, Assembler::pt, L);
1024       __ delayed()->nop();
1025       __ stop("mirror is missing");
1026       __ bind(L);
1027     }
1028 #endif // ASSERT
1029     __ st_ptr(O1, Lscratch2, 0);
1030     __ mov(Lscratch2, O1);
1031     __ bind(not_static);
1032   }
1033 
1034   // At this point, arguments have been copied off of stack into
1035   // their JNI positions, which are O1..O5 and SP[68..].
1036   // Oops are boxed in-place on the stack, with handles copied to arguments.
1037   // The result handler is in Lscratch.  O0 will shortly hold the JNIEnv*.
1038 
1039 #ifdef ASSERT
1040   { Label L;
1041     __ tst(O0);
1042     __ brx(Assembler::notZero, false, Assembler::pt, L);
1043     __ delayed()->nop();
1044     __ stop("native entry point is missing");
1045     __ bind(L);
1046   }
1047 #endif // ASSERT
1048 
1049   //
1050   // setup the frame anchor
1051   //
1052   // The scavenge function only needs to know that the PC of this frame is
1053   // in the interpreter method entry code, it doesn't need to know the exact
1054   // PC and hence we can use O7 which points to the return address from the
1055   // previous call in the code stream (signature handler function)
1056   //
1057   // The other trick is we set last_Java_sp to FP instead of the usual SP because
1058   // we have pushed the extra frame in order to protect the volatile register(s)
1059   // in that frame when we return from the jni call
1060   //
1061 
1062   __ set_last_Java_frame(FP, O7);
1063   __ mov(O7, I7);  // make dummy interpreter frame look like one above,
1064                    // not meaningless information that'll confuse me.
1065 
1066   // flush the windows now. We don't care about the current (protection) frame
1067   // only the outer frames
1068 
1069   __ flush_windows();
1070 
1071   // mark windows as flushed
1072   Address flags(G2_thread, JavaThread::frame_anchor_offset() + JavaFrameAnchor::flags_offset());
1073   __ set(JavaFrameAnchor::flushed, G3_scratch);
1074   __ st(G3_scratch, flags);
1075 
1076   // Transition from _thread_in_Java to _thread_in_native. We are already safepoint ready.
1077 
1078   Address thread_state(G2_thread, JavaThread::thread_state_offset());
1079 #ifdef ASSERT
1080   { Label L;
1081     __ ld(thread_state, G3_scratch);
1082     __ cmp(G3_scratch, _thread_in_Java);
1083     __ br(Assembler::equal, false, Assembler::pt, L);
1084     __ delayed()->nop();
1085     __ stop("Wrong thread state in native stub");
1086     __ bind(L);
1087   }
1088 #endif // ASSERT
1089   __ set(_thread_in_native, G3_scratch);
1090   __ st(G3_scratch, thread_state);
1091 
1092   // Call the jni method, using the delay slot to set the JNIEnv* argument.
1093   __ save_thread(L7_thread_cache); // save Gthread
1094   __ callr(O0, 0);
1095   __ delayed()->
1096      add(L7_thread_cache, in_bytes(JavaThread::jni_environment_offset()), O0);
1097 
1098   // Back from jni method Lmethod in this frame is DEAD, DEAD, DEAD
1099 
1100   __ restore_thread(L7_thread_cache); // restore G2_thread
1101   __ reinit_heapbase();
1102 
1103   // must we block?
1104 


1117     __ set(_thread_in_native_trans, G3_scratch);
1118     __ st(G3_scratch, thread_state);
1119     if(os::is_MP()) {
1120       if (UseMembar) {
1121         // Force this write out before the read below
1122         __ membar(Assembler::StoreLoad);
1123       } else {
1124         // Write serialization page so VM thread can do a pseudo remote membar.
1125         // We use the current thread pointer to calculate a thread specific
1126         // offset to write to within the page. This minimizes bus traffic
1127         // due to cache line collision.
1128         __ serialize_memory(G2_thread, G1_scratch, G3_scratch);
1129       }
1130     }
1131     __ load_contents(sync_state, G3_scratch);
1132     __ cmp(G3_scratch, SafepointSynchronize::_not_synchronized);
1133 
1134     Label L;
1135     __ br(Assembler::notEqual, false, Assembler::pn, L);
1136     __ delayed()->ld(G2_thread, JavaThread::suspend_flags_offset(), G3_scratch);
1137     __ cmp(G3_scratch, 0);
1138     __ br(Assembler::equal, false, Assembler::pt, no_block);
1139     __ delayed()->nop();
1140     __ bind(L);
1141 
1142     // Block.  Save any potential method result value before the operation and
1143     // use a leaf call to leave the last_Java_frame setup undisturbed.
1144     save_native_result();
1145     __ call_VM_leaf(L7_thread_cache,
1146                     CAST_FROM_FN_PTR(address, JavaThread::check_special_condition_for_native_trans),
1147                     G2_thread);
1148 
1149     // Restore any method result value
1150     restore_native_result();
1151     __ bind(no_block);
1152   }
1153 
1154   // Clear the frame anchor now
1155 
1156   __ reset_last_Java_frame();
1157 
1158   // Move the result handler address
1159   __ mov(Lscratch, G3_scratch);


1168   // Move result handler to expected register
1169   __ mov(G3_scratch, Lscratch);
1170 
1171   // Back in normal (native) interpreter frame. State is thread_in_native_trans
1172   // switch to thread_in_Java.
1173 
1174   __ set(_thread_in_Java, G3_scratch);
1175   __ st(G3_scratch, thread_state);
1176 
1177   // reset handle block
1178   __ ld_ptr(G2_thread, JavaThread::active_handles_offset(), G3_scratch);
1179   __ st_ptr(G0, G3_scratch, JNIHandleBlock::top_offset_in_bytes());
1180 
1181   // If we have an oop result store it where it will be safe for any further gc
1182   // until we return now that we've released the handle it might be protected by
1183 
1184   {
1185     Label no_oop, store_result;
1186 
1187     __ set((intptr_t)AbstractInterpreter::result_handler(T_OBJECT), G3_scratch);
1188     __ cmp(G3_scratch, Lscratch);
1189     __ brx(Assembler::notEqual, false, Assembler::pt, no_oop);
1190     __ delayed()->nop();
1191     __ addcc(G0, O0, O0);
1192     __ brx(Assembler::notZero, true, Assembler::pt, store_result);     // if result is not NULL:
1193     __ delayed()->ld_ptr(O0, 0, O0);                                   // unbox it
1194     __ mov(G0, O0);
1195 
1196     __ bind(store_result);
1197     // Store it where gc will look for it and result handler expects it.
1198     __ st_ptr(O0, FP, (frame::interpreter_frame_oop_temp_offset*wordSize) + STACK_BIAS);
1199 
1200     __ bind(no_oop);
1201 
1202   }
1203 
1204 
1205   // handle exceptions (exception handling will handle unlocking!)
1206   { Label L;
1207     Address exception_addr(G2_thread, Thread::pending_exception_offset());
1208     __ ld_ptr(exception_addr, Gtemp);
1209     __ tst(Gtemp);
1210     __ brx(Assembler::equal, false, Assembler::pt, L);
1211     __ delayed()->nop();
1212     // Note: This could be handled more efficiently since we know that the native
1213     //       method doesn't have an exception handler. We could directly return
1214     //       to the exception handler for the caller.
1215     __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_pending_exception));
1216     __ should_not_reach_here();
1217     __ bind(L);
1218   }
1219 
1220   // JVMTI support (preserves thread register)
1221   __ notify_method_exit(true, ilgl, InterpreterMacroAssembler::NotifyJVMTI);
1222 
1223   if (synchronized) {
1224     // save and restore any potential method result value around the unlocking operation
1225     save_native_result();
1226 
1227     __ add( __ top_most_monitor(), O1);
1228     __ unlock_object(O1);
1229 
1230     restore_native_result();
1231   }
1232 
1233 #if defined(COMPILER2) && !defined(_LP64)
1234 
1235   // C2 expects long results in G1 we can't tell if we're returning to interpreted
1236   // or compiled so just be safe.
1237 
1238   __ sllx(O0, 32, G1);          // Shift bits into high G1
1239   __ srl (O1, 0, O1);           // Zero extend O1
1240   __ or3 (O1, G1, G1);          // OR 64 bits into G1
1241 
1242 #endif /* COMPILER2 && !_LP64 */
1243 
1244   // dispose of return address and remove activation
1245 #ifdef ASSERT
1246   {
1247     Label ok;
1248     __ cmp(I5_savedSP, FP);
1249     __ brx(Assembler::greaterEqualUnsigned, false, Assembler::pt, ok);
1250     __ delayed()->nop();
1251     __ stop("bad I5_savedSP value");
1252     __ should_not_reach_here();
1253     __ bind(ok);
1254   }
1255 #endif
1256   if (TraceJumps) {
1257     // Move target to register that is recordable
1258     __ mov(Lscratch, G3_scratch);
1259     __ JMP(G3_scratch, 0);
1260   } else {
1261     __ jmp(Lscratch, 0);
1262   }
1263   __ delayed()->nop();
1264 
1265 
1266   if (inc_counter) {
1267     // handle invocation counter overflow
1268     __ bind(invocation_counter_overflow);
1269     generate_counter_overflow(Lcontinue);
1270   }


1412   }
1413 
1414   // start execution
1415 
1416   __ verify_thread();
1417 
1418   // jvmti support
1419   __ notify_method_entry();
1420 
1421   // start executing instructions
1422   __ dispatch_next(vtos);
1423 
1424 
1425   if (inc_counter) {
1426     if (ProfileInterpreter) {
1427       // We have decided to profile this method in the interpreter
1428       __ bind(profile_method);
1429 
1430       __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::profile_method));
1431       __ set_method_data_pointer_for_bcp();
1432       __ ba(false, profile_method_continue);
1433       __ delayed()->nop();
1434     }
1435 
1436     // handle invocation counter overflow
1437     __ bind(invocation_counter_overflow);
1438     generate_counter_overflow(Lcontinue);
1439   }
1440 
1441 
1442   return entry;
1443 }
1444 
1445 
1446 //----------------------------------------------------------------------------------------------------
1447 // Entry points & stack frame layout
1448 //
1449 // Here we generate the various kind of entries into the interpreter.
1450 // The two main entry type are generic bytecode methods and native call method.
1451 // These both come in synchronized and non-synchronized versions but the
1452 // frame layout they create is very similar. The other method entry
1453 // types are really just special purpose entries that are really entry


1839   __ or3(G3_scratch, JavaThread::popframe_processing_bit, G3_scratch);
1840   __ stw(G3_scratch, popframe_condition_addr);
1841 
1842   // Empty the expression stack, as in normal exception handling
1843   __ empty_expression_stack();
1844   __ unlock_if_synchronized_method(vtos, /* throw_monitor_exception */ false, /* install_monitor_exception */ false);
1845 
1846   {
1847     // Check to see whether we are returning to a deoptimized frame.
1848     // (The PopFrame call ensures that the caller of the popped frame is
1849     // either interpreted or compiled and deoptimizes it if compiled.)
1850     // In this case, we can't call dispatch_next() after the frame is
1851     // popped, but instead must save the incoming arguments and restore
1852     // them after deoptimization has occurred.
1853     //
1854     // Note that we don't compare the return PC against the
1855     // deoptimization blob's unpack entry because of the presence of
1856     // adapter frames in C2.
1857     Label caller_not_deoptimized;
1858     __ call_VM_leaf(L7_thread_cache, CAST_FROM_FN_PTR(address, InterpreterRuntime::interpreter_contains), I7);
1859     __ tst(O0);
1860     __ brx(Assembler::notEqual, false, Assembler::pt, caller_not_deoptimized);
1861     __ delayed()->nop();
1862 
1863     const Register Gtmp1 = G3_scratch;
1864     const Register Gtmp2 = G1_scratch;
1865 
1866     // Compute size of arguments for saving when returning to deoptimized caller
1867     __ lduh(Lmethod, in_bytes(methodOopDesc::size_of_parameters_offset()), Gtmp1);
1868     __ sll(Gtmp1, Interpreter::logStackElementSize, Gtmp1);
1869     __ sub(Llocals, Gtmp1, Gtmp2);
1870     __ add(Gtmp2, wordSize, Gtmp2);
1871     // Save these arguments
1872     __ call_VM_leaf(L7_thread_cache, CAST_FROM_FN_PTR(address, Deoptimization::popframe_preserve_args), G2_thread, Gtmp1, Gtmp2);
1873     // Inform deoptimization that it is responsible for restoring these arguments
1874     __ set(JavaThread::popframe_force_deopt_reexecution_bit, Gtmp1);
1875     Address popframe_condition_addr(G2_thread, JavaThread::popframe_condition_offset());
1876     __ st(Gtmp1, popframe_condition_addr);
1877 
1878     // Return from the current method
1879     // The caller's SP was adjusted upon method entry to accomodate
1880     // the callee's non-argument locals. Undo that adjustment.
1881     __ ret();


1975 
1976   __ remove_activation(state,
1977                        /* throw_monitor_exception */ false,
1978                        /* install_monitor_exception */ false);
1979 
1980   // The caller's SP was adjusted upon method entry to accomodate
1981   // the callee's non-argument locals. Undo that adjustment.
1982   __ ret();                             // return to caller
1983   __ delayed()->restore(I5_savedSP, G0, SP);
1984 
1985   return entry;
1986 } // end of JVMTI ForceEarlyReturn support
1987 
1988 
1989 //------------------------------------------------------------------------------------------------------------------------
1990 // Helper for vtos entry point generation
1991 
1992 void TemplateInterpreterGenerator::set_vtos_entry_points(Template* t, address& bep, address& cep, address& sep, address& aep, address& iep, address& lep, address& fep, address& dep, address& vep) {
1993   assert(t->is_valid() && t->tos_in() == vtos, "illegal template");
1994   Label L;
1995   aep = __ pc(); __ push_ptr(); __ ba(false, L); __ delayed()->nop();
1996   fep = __ pc(); __ push_f();   __ ba(false, L); __ delayed()->nop();
1997   dep = __ pc(); __ push_d();   __ ba(false, L); __ delayed()->nop();
1998   lep = __ pc(); __ push_l();   __ ba(false, L); __ delayed()->nop();
1999   iep = __ pc(); __ push_i();
2000   bep = cep = sep = iep;                        // there aren't any
2001   vep = __ pc(); __ bind(L);                    // fall through
2002   generate_and_dispatch(t);
2003 }
2004 
2005 // --------------------------------------------------------------------------------
2006 
2007 
2008 InterpreterGenerator::InterpreterGenerator(StubQueue* code)
2009  : TemplateInterpreterGenerator(code) {
2010    generate_all(); // down here so it can be "virtual"
2011 }
2012 
2013 // --------------------------------------------------------------------------------
2014 
2015 // Non-product code
2016 #ifndef PRODUCT
2017 address TemplateInterpreterGenerator::generate_trace_code(TosState state) {
2018   address entry = __ pc();




 173     __ srl (G1,  0, O1);
 174     __ srlx(G1, 32, O0);
 175   }
 176 #endif // !_LP64 && COMPILER2
 177 
 178   __ bind(cont);
 179 
 180   // The callee returns with the stack possibly adjusted by adapter transition
 181   // We remove that possible adjustment here.
 182   // All interpreter local registers are untouched. Any result is passed back
 183   // in the O0/O1 or float registers. Before continuing, the arguments must be
 184   // popped from the java expression stack; i.e., Lesp must be adjusted.
 185 
 186   __ mov(Llast_SP, SP);   // Remove any adapter added stack space.
 187 
 188   Label L_got_cache, L_giant_index;
 189   const Register cache = G3_scratch;
 190   const Register size  = G1_scratch;
 191   if (EnableInvokeDynamic) {
 192     __ ldub(Address(Lbcp, 0), G1_scratch);  // Load current bytecode.
 193     __ cmp_and_br_short(G1_scratch, Bytecodes::_invokedynamic, Assembler::equal, Assembler::pn, L_giant_index);


 194   }
 195   __ get_cache_and_index_at_bcp(cache, G1_scratch, 1);
 196   __ bind(L_got_cache);
 197   __ ld_ptr(cache, constantPoolCacheOopDesc::base_offset() +
 198                    ConstantPoolCacheEntry::flags_offset(), size);
 199   __ and3(size, 0xFF, size);                   // argument size in words
 200   __ sll(size, Interpreter::logStackElementSize, size); // each argument size in bytes
 201   __ add(Lesp, size, Lesp);                    // pop arguments
 202   __ dispatch_next(state, step);
 203 
 204   // out of the main line of code...
 205   if (EnableInvokeDynamic) {
 206     __ bind(L_giant_index);
 207     __ get_cache_and_index_at_bcp(cache, G1_scratch, 1, sizeof(u4));
 208     __ ba_short(L_got_cache);

 209   }
 210 
 211   return entry;
 212 }
 213 
 214 
 215 address TemplateInterpreterGenerator::generate_deopt_entry_for(TosState state, int step) {
 216   address entry = __ pc();
 217   __ get_constant_pool_cache(LcpoolCache); // load LcpoolCache
 218   { Label L;
 219     Address exception_addr(G2_thread, Thread::pending_exception_offset());
 220     __ ld_ptr(exception_addr, Gtemp);  // Load pending exception.
 221     __ br_null_short(Gtemp, Assembler::pt, L);


 222     __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_pending_exception));
 223     __ should_not_reach_here();
 224     __ bind(L);
 225   }
 226   __ dispatch_next(state, step);
 227   return entry;
 228 }
 229 
 230 // A result handler converts/unboxes a native call result into
 231 // a java interpreter/compiler result. The current frame is an
 232 // interpreter frame. The activation frame unwind code must be
 233 // consistent with that of TemplateTable::_return(...). In the
 234 // case of native methods, the caller's SP was not modified.
 235 address TemplateInterpreterGenerator::generate_result_handler_for(BasicType type) {
 236   address entry = __ pc();
 237   Register Itos_i  = Otos_i ->after_save();
 238   Register Itos_l  = Otos_l ->after_save();
 239   Register Itos_l1 = Otos_l1->after_save();
 240   Register Itos_l2 = Otos_l2->after_save();
 241   switch (type) {


 282 // Helpers for commoning out cases in the various type of method entries.
 283 //
 284 
 285 // increment invocation count & check for overflow
 286 //
 287 // Note: checking for negative value instead of overflow
 288 //       so we have a 'sticky' overflow test
 289 //
 290 // Lmethod: method
 291 // ??: invocation counter
 292 //
 293 void InterpreterGenerator::generate_counter_incr(Label* overflow, Label* profile_method, Label* profile_method_continue) {
 294   // Note: In tiered we increment either counters in methodOop or in MDO depending if we're profiling or not.
 295   if (TieredCompilation) {
 296     const int increment = InvocationCounter::count_increment;
 297     const int mask = ((1 << Tier0InvokeNotifyFreqLog) - 1) << InvocationCounter::count_shift;
 298     Label no_mdo, done;
 299     if (ProfileInterpreter) {
 300       // If no method data exists, go to profile_continue.
 301       __ ld_ptr(Lmethod, methodOopDesc::method_data_offset(), G4_scratch);
 302       __ br_null_short(G4_scratch, Assembler::pn, no_mdo);

 303       // Increment counter
 304       Address mdo_invocation_counter(G4_scratch,
 305                                      in_bytes(methodDataOopDesc::invocation_counter_offset()) +
 306                                      in_bytes(InvocationCounter::counter_offset()));
 307       __ increment_mask_and_jump(mdo_invocation_counter, increment, mask,
 308                                  G3_scratch, Lscratch,
 309                                  Assembler::zero, overflow);
 310       __ ba_short(done);

 311     }
 312 
 313     // Increment counter in methodOop
 314     __ bind(no_mdo);
 315     Address invocation_counter(Lmethod,
 316                                in_bytes(methodOopDesc::invocation_counter_offset()) +
 317                                in_bytes(InvocationCounter::counter_offset()));
 318     __ increment_mask_and_jump(invocation_counter, increment, mask,
 319                                G3_scratch, Lscratch,
 320                                Assembler::zero, overflow);
 321     __ bind(done);
 322   } else {
 323     // Update standard invocation counters
 324     __ increment_invocation_counter(O0, G3_scratch);
 325     if (ProfileInterpreter) {  // %%% Merge this into methodDataOop
 326       Address interpreter_invocation_counter(Lmethod,in_bytes(methodOopDesc::interpreter_invocation_counter_offset()));
 327       __ ld(interpreter_invocation_counter, G3_scratch);
 328       __ inc(G3_scratch);
 329       __ st(G3_scratch, interpreter_invocation_counter);
 330     }
 331 
 332     if (ProfileInterpreter && profile_method != NULL) {
 333       // Test to see if we should create a method data oop
 334       AddressLiteral profile_limit((address)&InvocationCounter::InterpreterProfileLimit);
 335       __ load_contents(profile_limit, G3_scratch);
 336       __ cmp_and_br_short(O0, G3_scratch, Assembler::lessUnsigned, Assembler::pn, *profile_method_continue);


 337 
 338       // if no method data exists, go to profile_method
 339       __ test_method_data_pointer(*profile_method);
 340     }
 341 
 342     AddressLiteral invocation_limit((address)&InvocationCounter::InterpreterInvocationLimit);
 343     __ load_contents(invocation_limit, G3_scratch);
 344     __ cmp(O0, G3_scratch);
 345     __ br(Assembler::greaterEqualUnsigned, false, Assembler::pn, *overflow); // Far distance
 346     __ delayed()->nop();
 347   }
 348 
 349 }
 350 
 351 // Allocate monitor and lock method (asm interpreter)
 352 // ebx - methodOop
 353 //
 354 void InterpreterGenerator::lock_method(void) {
 355   __ ld(Lmethod, in_bytes(methodOopDesc::access_flags_offset()), O0);  // Load access flags.
 356 
 357 #ifdef ASSERT
 358  { Label ok;
 359    __ btst(JVM_ACC_SYNCHRONIZED, O0);
 360    __ br( Assembler::notZero, false, Assembler::pt, ok);
 361    __ delayed()->nop();
 362    __ stop("method doesn't need synchronization");
 363    __ bind(ok);
 364   }
 365 #endif // ASSERT


 384 
 385     __ bind(done);
 386   }
 387 
 388   __ add_monitor_to_stack(true, noreg, noreg);  // allocate monitor elem
 389   __ st_ptr( O0, Lmonitors, BasicObjectLock::obj_offset_in_bytes());   // store object
 390   // __ untested("lock_object from method entry");
 391   __ lock_object(Lmonitors, O0);
 392 }
 393 
 394 
 395 void TemplateInterpreterGenerator::generate_stack_overflow_check(Register Rframe_size,
 396                                                          Register Rscratch,
 397                                                          Register Rscratch2) {
 398   const int page_size = os::vm_page_size();
 399   Address saved_exception_pc(G2_thread, JavaThread::saved_exception_pc_offset());
 400   Label after_frame_check;
 401 
 402   assert_different_registers(Rframe_size, Rscratch, Rscratch2);
 403 
 404   __ set(page_size, Rscratch);
 405   __ cmp_and_br_short(Rframe_size, Rscratch, Assembler::lessEqual, Assembler::pt, after_frame_check);
 406 



 407   // get the stack base, and in debug, verify it is non-zero
 408   __ ld_ptr( G2_thread, Thread::stack_base_offset(), Rscratch );
 409 #ifdef ASSERT
 410   Label base_not_zero;
 411   __ br_notnull_short(Rscratch, Assembler::pn, base_not_zero);


 412   __ stop("stack base is zero in generate_stack_overflow_check");
 413   __ bind(base_not_zero);
 414 #endif
 415 
 416   // get the stack size, and in debug, verify it is non-zero
 417   assert( sizeof(size_t) == sizeof(intptr_t), "wrong load size" );
 418   __ ld_ptr( G2_thread, Thread::stack_size_offset(), Rscratch2 );
 419 #ifdef ASSERT
 420   Label size_not_zero;
 421   __ br_notnull_short(Rscratch2, Assembler::pn, size_not_zero);


 422   __ stop("stack size is zero in generate_stack_overflow_check");
 423   __ bind(size_not_zero);
 424 #endif
 425 
 426   // compute the beginning of the protected zone minus the requested frame size
 427   __ sub( Rscratch, Rscratch2,   Rscratch );
 428   __ set( (StackRedPages+StackYellowPages) * page_size, Rscratch2 );
 429   __ add( Rscratch, Rscratch2,   Rscratch );
 430 
 431   // Add in the size of the frame (which is the same as subtracting it from the
 432   // SP, which would take another register
 433   __ add( Rscratch, Rframe_size, Rscratch );
 434 
 435   // the frame is greater than one page in size, so check against
 436   // the bottom of the stack
 437   __ cmp_and_brx_short(SP, Rscratch, Assembler::greater, Assembler::pt, after_frame_check);


 438 
 439   // Save the return address as the exception pc
 440   __ st_ptr(O7, saved_exception_pc);
 441 
 442   // the stack will overflow, throw an exception
 443   __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_StackOverflowError));
 444 
 445   // if you get to here, then there is enough stack space
 446   __ bind( after_frame_check );
 447 }
 448 
 449 
 450 //
 451 // Generate a fixed interpreter frame. This is identical setup for interpreted
 452 // methods and for native methods hence the shared code.
 453 
 454 void TemplateInterpreterGenerator::generate_fixed_frame(bool native_call) {
 455   //
 456   //
 457   // The entry code sets up a new interpreter frame in 4 steps:


 589   }
 590 
 591 }
 592 
 593 // Empty method, generate a very fast return.
 594 
 595 address InterpreterGenerator::generate_empty_entry(void) {
 596 
 597   // A method that does nother but return...
 598 
 599   address entry = __ pc();
 600   Label slow_path;
 601 
 602   __ verify_oop(G5_method);
 603 
 604   // do nothing for empty methods (do not even increment invocation counter)
 605   if ( UseFastEmptyMethods) {
 606     // If we need a safepoint check, generate full interpreter entry.
 607     AddressLiteral sync_state(SafepointSynchronize::address_of_state());
 608     __ set(sync_state, G3_scratch);
 609     __ cmp_and_br_short(G3_scratch, SafepointSynchronize::_not_synchronized, Assembler::notEqual, Assembler::pn, slow_path);


 610 
 611     // Code: _return
 612     __ retl();
 613     __ delayed()->mov(O5_savedSP, SP);
 614 
 615     __ bind(slow_path);
 616     (void) generate_normal_entry(false);
 617 
 618     return entry;
 619   }
 620   return NULL;
 621 }
 622 
 623 // Call an accessor method (assuming it is resolved, otherwise drop into
 624 // vanilla (slow path) entry
 625 
 626 // Generates code to elide accessor methods
 627 // Uses G3_scratch and G1_scratch as scratch
 628 address InterpreterGenerator::generate_accessor_entry(void) {
 629 
 630   // Code: _aload_0, _(i|a)getfield, _(i|a)return or any rewrites thereof;
 631   // parameter size = 1
 632   // Note: We can only use this code if the getfield has been resolved
 633   //       and if we don't have a null-pointer exception => check for
 634   //       these conditions first and use slow path if necessary.
 635   address entry = __ pc();
 636   Label slow_path;
 637 
 638 
 639   // XXX: for compressed oops pointer loading and decoding doesn't fit in
 640   // delay slot and damages G1
 641   if ( UseFastAccessorMethods && !UseCompressedOops ) {
 642     // Check if we need to reach a safepoint and generate full interpreter
 643     // frame if so.
 644     AddressLiteral sync_state(SafepointSynchronize::address_of_state());
 645     __ load_contents(sync_state, G3_scratch);
 646     __ cmp(G3_scratch, SafepointSynchronize::_not_synchronized);
 647     __ cmp_and_br_short(G3_scratch, SafepointSynchronize::_not_synchronized, Assembler::notEqual, Assembler::pn, slow_path);

 648 
 649     // Check if local 0 != NULL
 650     __ ld_ptr(Gargs, G0, Otos_i ); // get local 0
 651     // check if local 0 == NULL and go the slow path
 652     __ br_null_short(Otos_i, Assembler::pn, slow_path);

 653 
 654 
 655     // read first instruction word and extract bytecode @ 1 and index @ 2
 656     // get first 4 bytes of the bytecodes (big endian!)
 657     __ ld_ptr(G5_method, methodOopDesc::const_offset(), G1_scratch);
 658     __ ld(G1_scratch, constMethodOopDesc::codes_offset(), G1_scratch);
 659 
 660     // move index @ 2 far left then to the right most two bytes.
 661     __ sll(G1_scratch, 2*BitsPerByte, G1_scratch);
 662     __ srl(G1_scratch, 2*BitsPerByte - exact_log2(in_words(
 663                       ConstantPoolCacheEntry::size()) * BytesPerWord), G1_scratch);
 664 
 665     // get constant pool cache
 666     __ ld_ptr(G5_method, methodOopDesc::constants_offset(), G3_scratch);
 667     __ ld_ptr(G3_scratch, constantPoolOopDesc::cache_offset_in_bytes(), G3_scratch);
 668 
 669     // get specific constant pool cache entry
 670     __ add(G3_scratch, G1_scratch, G3_scratch);
 671 
 672     // Check the constant Pool cache entry to see if it has been resolved.
 673     // If not, need the slow path.
 674     ByteSize cp_base_offset = constantPoolCacheOopDesc::base_offset();
 675     __ ld_ptr(G3_scratch, cp_base_offset + ConstantPoolCacheEntry::indices_offset(), G1_scratch);
 676     __ srl(G1_scratch, 2*BitsPerByte, G1_scratch);
 677     __ and3(G1_scratch, 0xFF, G1_scratch);
 678     __ cmp_and_br_short(G1_scratch, Bytecodes::_getfield, Assembler::notEqual, Assembler::pn, slow_path);


 679 
 680     // Get the type and return field offset from the constant pool cache
 681     __ ld_ptr(G3_scratch, cp_base_offset + ConstantPoolCacheEntry::flags_offset(), G1_scratch);
 682     __ ld_ptr(G3_scratch, cp_base_offset + ConstantPoolCacheEntry::f2_offset(), G3_scratch);
 683 
 684     Label xreturn_path;
 685     // Need to differentiate between igetfield, agetfield, bgetfield etc.
 686     // because they are different sizes.
 687     // Get the type from the constant pool cache
 688     __ srl(G1_scratch, ConstantPoolCacheEntry::tosBits, G1_scratch);
 689     // Make sure we don't need to mask G1_scratch for tosBits after the above shift
 690     ConstantPoolCacheEntry::verify_tosBits();
 691     __ cmp(G1_scratch, atos );
 692     __ br(Assembler::equal, true, Assembler::pt, xreturn_path);
 693     __ delayed()->ld_ptr(Otos_i, G3_scratch, Otos_i);
 694     __ cmp(G1_scratch, itos);
 695     __ br(Assembler::equal, true, Assembler::pt, xreturn_path);
 696     __ delayed()->ld(Otos_i, G3_scratch, Otos_i);
 697     __ cmp(G1_scratch, stos);
 698     __ br(Assembler::equal, true, Assembler::pt, xreturn_path);


 746   //   Reference object is null then we obviously cannot fetch the referent
 747   //   and so we don't need to call the G1 pre-barrier. Thus we can use the
 748   //   regular method entry code to generate the NPE.
 749   //
 750   // This code is based on generate_accessor_enty.
 751 
 752   address entry = __ pc();
 753 
 754   const int referent_offset = java_lang_ref_Reference::referent_offset;
 755   guarantee(referent_offset > 0, "referent offset not initialized");
 756 
 757   if (UseG1GC) {
 758      Label slow_path;
 759 
 760     // In the G1 code we don't check if we need to reach a safepoint. We
 761     // continue and the thread will safepoint at the next bytecode dispatch.
 762 
 763     // Check if local 0 != NULL
 764     // If the receiver is null then it is OK to jump to the slow path.
 765     __ ld_ptr(Gargs, G0, Otos_i ); // get local 0
 766     // check if local 0 == NULL and go the slow path
 767     __ cmp_and_brx_short(Otos_i, 0, Assembler::equal, Assembler::pn, slow_path);

 768 
 769 
 770     // Load the value of the referent field.
 771     if (Assembler::is_simm13(referent_offset)) {
 772       __ load_heap_oop(Otos_i, referent_offset, Otos_i);
 773     } else {
 774       __ set(referent_offset, G3_scratch);
 775       __ load_heap_oop(Otos_i, G3_scratch, Otos_i);
 776     }
 777 
 778     // Generate the G1 pre-barrier code to log the value of
 779     // the referent field in an SATB buffer. Note with
 780     // these parameters the pre-barrier does not generate
 781     // the load of the previous value
 782 
 783     __ g1_write_barrier_pre(noreg /* obj */, noreg /* index */, 0 /* offset */,
 784                             Otos_i /* pre_val */,
 785                             G3_scratch /* tmp */,
 786                             true /* preserve_o_regs */);
 787 


 910 
 911 
 912   // start execution
 913   __ verify_thread();
 914 
 915   // JVMTI support
 916   __ notify_method_entry();
 917 
 918   // native call
 919 
 920   // (note that O0 is never an oop--at most it is a handle)
 921   // It is important not to smash any handles created by this call,
 922   // until any oop handle in O0 is dereferenced.
 923 
 924   // (note that the space for outgoing params is preallocated)
 925 
 926   // get signature handler
 927   { Label L;
 928     Address signature_handler(Lmethod, methodOopDesc::signature_handler_offset());
 929     __ ld_ptr(signature_handler, G3_scratch);
 930     __ br_notnull_short(G3_scratch, Assembler::pt, L);


 931     __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::prepare_native_call), Lmethod);
 932     __ ld_ptr(signature_handler, G3_scratch);
 933     __ bind(L);
 934   }
 935 
 936   // Push a new frame so that the args will really be stored in
 937   // Copy a few locals across so the new frame has the variables
 938   // we need but these values will be dead at the jni call and
 939   // therefore not gc volatile like the values in the current
 940   // frame (Lmethod in particular)
 941 
 942   // Flush the method pointer to the register save area
 943   __ st_ptr(Lmethod, SP, (Lmethod->sp_offset_in_saved_window() * wordSize) + STACK_BIAS);
 944   __ mov(Llocals, O1);
 945 
 946   // calculate where the mirror handle body is allocated in the interpreter frame:
 947   __ add(FP, (frame::interpreter_frame_oop_temp_offset * wordSize) + STACK_BIAS, O2);
 948 
 949   // Calculate current frame size
 950   __ sub(SP, FP, O3);         // Calculate negative of current frame size


 975 
 976   // Reload interpreter frame's Lmethod since slow signature handler may block
 977   __ ld_ptr(FP, (Lmethod->sp_offset_in_saved_window() * wordSize) + STACK_BIAS, Lmethod);
 978 
 979   { Label not_static;
 980 
 981     __ ld(Laccess_flags, O0);
 982     __ btst(JVM_ACC_STATIC, O0);
 983     __ br( Assembler::zero, false, Assembler::pt, not_static);
 984     // get native function entry point(O0 is a good temp until the very end)
 985     __ delayed()->ld_ptr(Lmethod, in_bytes(methodOopDesc::native_function_offset()), O0);
 986     // for static methods insert the mirror argument
 987     const int mirror_offset = klassOopDesc::klass_part_offset_in_bytes() + Klass::java_mirror_offset_in_bytes();
 988 
 989     __ ld_ptr(Lmethod, methodOopDesc:: constants_offset(), O1);
 990     __ ld_ptr(O1, constantPoolOopDesc::pool_holder_offset_in_bytes(), O1);
 991     __ ld_ptr(O1, mirror_offset, O1);
 992 #ifdef ASSERT
 993     if (!PrintSignatureHandlers)  // do not dirty the output with this
 994     { Label L;
 995       __ br_notnull_short(O1, Assembler::pt, L);


 996       __ stop("mirror is missing");
 997       __ bind(L);
 998     }
 999 #endif // ASSERT
1000     __ st_ptr(O1, Lscratch2, 0);
1001     __ mov(Lscratch2, O1);
1002     __ bind(not_static);
1003   }
1004 
1005   // At this point, arguments have been copied off of stack into
1006   // their JNI positions, which are O1..O5 and SP[68..].
1007   // Oops are boxed in-place on the stack, with handles copied to arguments.
1008   // The result handler is in Lscratch.  O0 will shortly hold the JNIEnv*.
1009 
1010 #ifdef ASSERT
1011   { Label L;
1012     __ br_notnull_short(O0, Assembler::pt, L);


1013     __ stop("native entry point is missing");
1014     __ bind(L);
1015   }
1016 #endif // ASSERT
1017 
1018   //
1019   // setup the frame anchor
1020   //
1021   // The scavenge function only needs to know that the PC of this frame is
1022   // in the interpreter method entry code, it doesn't need to know the exact
1023   // PC and hence we can use O7 which points to the return address from the
1024   // previous call in the code stream (signature handler function)
1025   //
1026   // The other trick is we set last_Java_sp to FP instead of the usual SP because
1027   // we have pushed the extra frame in order to protect the volatile register(s)
1028   // in that frame when we return from the jni call
1029   //
1030 
1031   __ set_last_Java_frame(FP, O7);
1032   __ mov(O7, I7);  // make dummy interpreter frame look like one above,
1033                    // not meaningless information that'll confuse me.
1034 
1035   // flush the windows now. We don't care about the current (protection) frame
1036   // only the outer frames
1037 
1038   __ flush_windows();
1039 
1040   // mark windows as flushed
1041   Address flags(G2_thread, JavaThread::frame_anchor_offset() + JavaFrameAnchor::flags_offset());
1042   __ set(JavaFrameAnchor::flushed, G3_scratch);
1043   __ st(G3_scratch, flags);
1044 
1045   // Transition from _thread_in_Java to _thread_in_native. We are already safepoint ready.
1046 
1047   Address thread_state(G2_thread, JavaThread::thread_state_offset());
1048 #ifdef ASSERT
1049   { Label L;
1050     __ ld(thread_state, G3_scratch);
1051     __ cmp_and_br_short(G3_scratch, _thread_in_Java, Assembler::equal, Assembler::pt, L);


1052     __ stop("Wrong thread state in native stub");
1053     __ bind(L);
1054   }
1055 #endif // ASSERT
1056   __ set(_thread_in_native, G3_scratch);
1057   __ st(G3_scratch, thread_state);
1058 
1059   // Call the jni method, using the delay slot to set the JNIEnv* argument.
1060   __ save_thread(L7_thread_cache); // save Gthread
1061   __ callr(O0, 0);
1062   __ delayed()->
1063      add(L7_thread_cache, in_bytes(JavaThread::jni_environment_offset()), O0);
1064 
1065   // Back from jni method Lmethod in this frame is DEAD, DEAD, DEAD
1066 
1067   __ restore_thread(L7_thread_cache); // restore G2_thread
1068   __ reinit_heapbase();
1069 
1070   // must we block?
1071 


1084     __ set(_thread_in_native_trans, G3_scratch);
1085     __ st(G3_scratch, thread_state);
1086     if(os::is_MP()) {
1087       if (UseMembar) {
1088         // Force this write out before the read below
1089         __ membar(Assembler::StoreLoad);
1090       } else {
1091         // Write serialization page so VM thread can do a pseudo remote membar.
1092         // We use the current thread pointer to calculate a thread specific
1093         // offset to write to within the page. This minimizes bus traffic
1094         // due to cache line collision.
1095         __ serialize_memory(G2_thread, G1_scratch, G3_scratch);
1096       }
1097     }
1098     __ load_contents(sync_state, G3_scratch);
1099     __ cmp(G3_scratch, SafepointSynchronize::_not_synchronized);
1100 
1101     Label L;
1102     __ br(Assembler::notEqual, false, Assembler::pn, L);
1103     __ delayed()->ld(G2_thread, JavaThread::suspend_flags_offset(), G3_scratch);
1104     __ cmp_and_br_short(G3_scratch, 0, Assembler::equal, Assembler::pt, no_block);


1105     __ bind(L);
1106 
1107     // Block.  Save any potential method result value before the operation and
1108     // use a leaf call to leave the last_Java_frame setup undisturbed.
1109     save_native_result();
1110     __ call_VM_leaf(L7_thread_cache,
1111                     CAST_FROM_FN_PTR(address, JavaThread::check_special_condition_for_native_trans),
1112                     G2_thread);
1113 
1114     // Restore any method result value
1115     restore_native_result();
1116     __ bind(no_block);
1117   }
1118 
1119   // Clear the frame anchor now
1120 
1121   __ reset_last_Java_frame();
1122 
1123   // Move the result handler address
1124   __ mov(Lscratch, G3_scratch);


1133   // Move result handler to expected register
1134   __ mov(G3_scratch, Lscratch);
1135 
1136   // Back in normal (native) interpreter frame. State is thread_in_native_trans
1137   // switch to thread_in_Java.
1138 
1139   __ set(_thread_in_Java, G3_scratch);
1140   __ st(G3_scratch, thread_state);
1141 
1142   // reset handle block
1143   __ ld_ptr(G2_thread, JavaThread::active_handles_offset(), G3_scratch);
1144   __ st_ptr(G0, G3_scratch, JNIHandleBlock::top_offset_in_bytes());
1145 
1146   // If we have an oop result store it where it will be safe for any further gc
1147   // until we return now that we've released the handle it might be protected by
1148 
1149   {
1150     Label no_oop, store_result;
1151 
1152     __ set((intptr_t)AbstractInterpreter::result_handler(T_OBJECT), G3_scratch);
1153     __ cmp_and_brx_short(G3_scratch, Lscratch, Assembler::notEqual, Assembler::pt, no_oop);


1154     __ addcc(G0, O0, O0);
1155     __ brx(Assembler::notZero, true, Assembler::pt, store_result);     // if result is not NULL:
1156     __ delayed()->ld_ptr(O0, 0, O0);                                   // unbox it
1157     __ mov(G0, O0);
1158 
1159     __ bind(store_result);
1160     // Store it where gc will look for it and result handler expects it.
1161     __ st_ptr(O0, FP, (frame::interpreter_frame_oop_temp_offset*wordSize) + STACK_BIAS);
1162 
1163     __ bind(no_oop);
1164 
1165   }
1166 
1167 
1168   // handle exceptions (exception handling will handle unlocking!)
1169   { Label L;
1170     Address exception_addr(G2_thread, Thread::pending_exception_offset());
1171     __ ld_ptr(exception_addr, Gtemp);
1172     __ br_null_short(Gtemp, Assembler::pt, L);


1173     // Note: This could be handled more efficiently since we know that the native
1174     //       method doesn't have an exception handler. We could directly return
1175     //       to the exception handler for the caller.
1176     __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_pending_exception));
1177     __ should_not_reach_here();
1178     __ bind(L);
1179   }
1180 
1181   // JVMTI support (preserves thread register)
1182   __ notify_method_exit(true, ilgl, InterpreterMacroAssembler::NotifyJVMTI);
1183 
1184   if (synchronized) {
1185     // save and restore any potential method result value around the unlocking operation
1186     save_native_result();
1187 
1188     __ add( __ top_most_monitor(), O1);
1189     __ unlock_object(O1);
1190 
1191     restore_native_result();
1192   }
1193 
1194 #if defined(COMPILER2) && !defined(_LP64)
1195 
1196   // C2 expects long results in G1 we can't tell if we're returning to interpreted
1197   // or compiled so just be safe.
1198 
1199   __ sllx(O0, 32, G1);          // Shift bits into high G1
1200   __ srl (O1, 0, O1);           // Zero extend O1
1201   __ or3 (O1, G1, G1);          // OR 64 bits into G1
1202 
1203 #endif /* COMPILER2 && !_LP64 */
1204 
1205   // dispose of return address and remove activation
1206 #ifdef ASSERT
1207   {
1208     Label ok;
1209     __ cmp_and_brx_short(I5_savedSP, FP, Assembler::greaterEqualUnsigned, Assembler::pt, ok);


1210     __ stop("bad I5_savedSP value");
1211     __ should_not_reach_here();
1212     __ bind(ok);
1213   }
1214 #endif
1215   if (TraceJumps) {
1216     // Move target to register that is recordable
1217     __ mov(Lscratch, G3_scratch);
1218     __ JMP(G3_scratch, 0);
1219   } else {
1220     __ jmp(Lscratch, 0);
1221   }
1222   __ delayed()->nop();
1223 
1224 
1225   if (inc_counter) {
1226     // handle invocation counter overflow
1227     __ bind(invocation_counter_overflow);
1228     generate_counter_overflow(Lcontinue);
1229   }


1371   }
1372 
1373   // start execution
1374 
1375   __ verify_thread();
1376 
1377   // jvmti support
1378   __ notify_method_entry();
1379 
1380   // start executing instructions
1381   __ dispatch_next(vtos);
1382 
1383 
1384   if (inc_counter) {
1385     if (ProfileInterpreter) {
1386       // We have decided to profile this method in the interpreter
1387       __ bind(profile_method);
1388 
1389       __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::profile_method));
1390       __ set_method_data_pointer_for_bcp();
1391       __ ba_short(profile_method_continue);

1392     }
1393 
1394     // handle invocation counter overflow
1395     __ bind(invocation_counter_overflow);
1396     generate_counter_overflow(Lcontinue);
1397   }
1398 
1399 
1400   return entry;
1401 }
1402 
1403 
1404 //----------------------------------------------------------------------------------------------------
1405 // Entry points & stack frame layout
1406 //
1407 // Here we generate the various kind of entries into the interpreter.
1408 // The two main entry type are generic bytecode methods and native call method.
1409 // These both come in synchronized and non-synchronized versions but the
1410 // frame layout they create is very similar. The other method entry
1411 // types are really just special purpose entries that are really entry


1797   __ or3(G3_scratch, JavaThread::popframe_processing_bit, G3_scratch);
1798   __ stw(G3_scratch, popframe_condition_addr);
1799 
1800   // Empty the expression stack, as in normal exception handling
1801   __ empty_expression_stack();
1802   __ unlock_if_synchronized_method(vtos, /* throw_monitor_exception */ false, /* install_monitor_exception */ false);
1803 
1804   {
1805     // Check to see whether we are returning to a deoptimized frame.
1806     // (The PopFrame call ensures that the caller of the popped frame is
1807     // either interpreted or compiled and deoptimizes it if compiled.)
1808     // In this case, we can't call dispatch_next() after the frame is
1809     // popped, but instead must save the incoming arguments and restore
1810     // them after deoptimization has occurred.
1811     //
1812     // Note that we don't compare the return PC against the
1813     // deoptimization blob's unpack entry because of the presence of
1814     // adapter frames in C2.
1815     Label caller_not_deoptimized;
1816     __ call_VM_leaf(L7_thread_cache, CAST_FROM_FN_PTR(address, InterpreterRuntime::interpreter_contains), I7);
1817     __ br_notnull_short(O0, Assembler::pt, caller_not_deoptimized);


1818 
1819     const Register Gtmp1 = G3_scratch;
1820     const Register Gtmp2 = G1_scratch;
1821 
1822     // Compute size of arguments for saving when returning to deoptimized caller
1823     __ lduh(Lmethod, in_bytes(methodOopDesc::size_of_parameters_offset()), Gtmp1);
1824     __ sll(Gtmp1, Interpreter::logStackElementSize, Gtmp1);
1825     __ sub(Llocals, Gtmp1, Gtmp2);
1826     __ add(Gtmp2, wordSize, Gtmp2);
1827     // Save these arguments
1828     __ call_VM_leaf(L7_thread_cache, CAST_FROM_FN_PTR(address, Deoptimization::popframe_preserve_args), G2_thread, Gtmp1, Gtmp2);
1829     // Inform deoptimization that it is responsible for restoring these arguments
1830     __ set(JavaThread::popframe_force_deopt_reexecution_bit, Gtmp1);
1831     Address popframe_condition_addr(G2_thread, JavaThread::popframe_condition_offset());
1832     __ st(Gtmp1, popframe_condition_addr);
1833 
1834     // Return from the current method
1835     // The caller's SP was adjusted upon method entry to accomodate
1836     // the callee's non-argument locals. Undo that adjustment.
1837     __ ret();


1931 
1932   __ remove_activation(state,
1933                        /* throw_monitor_exception */ false,
1934                        /* install_monitor_exception */ false);
1935 
1936   // The caller's SP was adjusted upon method entry to accomodate
1937   // the callee's non-argument locals. Undo that adjustment.
1938   __ ret();                             // return to caller
1939   __ delayed()->restore(I5_savedSP, G0, SP);
1940 
1941   return entry;
1942 } // end of JVMTI ForceEarlyReturn support
1943 
1944 
1945 //------------------------------------------------------------------------------------------------------------------------
1946 // Helper for vtos entry point generation
1947 
1948 void TemplateInterpreterGenerator::set_vtos_entry_points(Template* t, address& bep, address& cep, address& sep, address& aep, address& iep, address& lep, address& fep, address& dep, address& vep) {
1949   assert(t->is_valid() && t->tos_in() == vtos, "illegal template");
1950   Label L;
1951   aep = __ pc(); __ push_ptr(); __ ba_short(L);
1952   fep = __ pc(); __ push_f();   __ ba_short(L);
1953   dep = __ pc(); __ push_d();   __ ba_short(L);
1954   lep = __ pc(); __ push_l();   __ ba_short(L);
1955   iep = __ pc(); __ push_i();
1956   bep = cep = sep = iep;                        // there aren't any
1957   vep = __ pc(); __ bind(L);                    // fall through
1958   generate_and_dispatch(t);
1959 }
1960 
1961 // --------------------------------------------------------------------------------
1962 
1963 
1964 InterpreterGenerator::InterpreterGenerator(StubQueue* code)
1965  : TemplateInterpreterGenerator(code) {
1966    generate_all(); // down here so it can be "virtual"
1967 }
1968 
1969 // --------------------------------------------------------------------------------
1970 
1971 // Non-product code
1972 #ifndef PRODUCT
1973 address TemplateInterpreterGenerator::generate_trace_code(TosState state) {
1974   address entry = __ pc();


src/cpu/sparc/vm/templateInterpreter_sparc.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File