src/cpu/mips/vm/interp_masm_mips_64.cpp

Tue, 26 Jul 2016 17:06:17 +0800

author
fujie
date
Tue, 26 Jul 2016 17:06:17 +0800
changeset 41
d885f8d65c58
parent 29
6c147e7e4605
child 63
d7fbeef71c31
permissions
-rw-r--r--

Add multiply word to GPR instruction (mul) in MIPS assembler.

     1 /*
     2  * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
     3  * Copyright (c) 2015, 2016, Loongson Technology. All rights reserved.
     4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     5  *
     6  * This code is free software; you can redistribute it and/or modify it
     7  * under the terms of the GNU General Public License version 2 only, as
     8  * published by the Free Software Foundation.
     9  *
    10  * This code is distributed in the hope that it will be useful, but WITHOUT
    11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    13  * version 2 for more details (a copy is included in the LICENSE file that
    14  * accompanied this code).
    15  *
    16  * You should have received a copy of the GNU General Public License version
    17  * 2 along with this work; if not, write to the Free Software Foundation,
    18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    19  *
    20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    21  * or visit www.oracle.com if you need additional information or have any
    22  * questions.
    23  *
    24  */
    26 #include "precompiled.hpp"
    27 #include "interp_masm_mips_64.hpp"
    28 #include "interpreter/interpreter.hpp"
    29 #include "interpreter/interpreterRuntime.hpp"
    30 #include "oops/arrayOop.hpp"
    31 #include "oops/markOop.hpp"
    32 #include "oops/methodData.hpp"
    33 #include "oops/method.hpp"
    34 #include "prims/jvmtiExport.hpp"
    35 #include "prims/jvmtiRedefineClassesTrace.hpp"
    36 #include "prims/jvmtiThreadState.hpp"
    37 #include "runtime/basicLock.hpp"
    38 #include "runtime/biasedLocking.hpp"
    39 #include "runtime/sharedRuntime.hpp"
    40 #include "runtime/thread.inline.hpp"
    43 // Implementation of InterpreterMacroAssembler
    45 #ifdef CC_INTERP
    46 void InterpreterMacroAssembler::get_method(Register reg) {
    47 }
    48 #endif // CC_INTERP
    50 void InterpreterMacroAssembler::get_2_byte_integer_at_bcp(Register reg, Register tmp, int offset) {
    51   /* 2016/5/6 Jin: the runtime address of BCP may be unaligned.
    52    *   Refer to the SPARC implementation. */
    53   lbu(reg, BCP, offset+1); 
    54   lbu(tmp, BCP, offset);
    55 #ifdef _LP64
    56   dsll(reg, reg, 8);
    57   daddu(reg, tmp, reg);
    58 #else
    59   sll(reg, reg, 8);
    60   addu(reg, tmp, reg);
    61 #endif
    62 }
    64 void InterpreterMacroAssembler::get_4_byte_integer_at_bcp(Register reg, Register tmp, int offset) {
    65   assert(reg != tmp, "need separate temp register");
    66   if (offset & 3) { // Offset unaligned?
    67     lbu(reg, BCP, offset+3);
    68     lbu(tmp, BCP, offset+2);
    69 #ifdef _LP64
    70     dsll(reg, reg, 8);
    71     daddu(reg, tmp, reg);
    72     lbu(tmp, BCP, offset+1);
    73     dsll(reg, reg, 8);
    74     daddu(reg, tmp, reg);
    75     lbu(tmp, BCP, offset);
    76     dsll(reg, reg, 8);
    77     daddu(reg, tmp, reg);
    78 #else
    79     sll(reg, reg, 8);
    80     addu(reg, tmp, reg);
    81     lbu(tmp, BCP, offset+1);
    82     sll(reg, reg, 8);
    83     addu(reg, tmp, reg);
    84     lbu(tmp, BCP, offset);
    85     sll(reg, reg, 8);
    86     addu(reg, tmp, reg);
    87 #endif
    88   } else {
    89     lwu(reg, BCP, offset);
    90   }
    91 }
    93 #ifndef CC_INTERP
    95 void InterpreterMacroAssembler::call_VM_leaf_base(address entry_point,
    96                                                   int number_of_arguments) {
    97     // interpreter specific
    98     //
    99     // Note: No need to save/restore bcp & locals (r13 & r14) pointer
   100     //       since these are callee saved registers and no blocking/
   101     //       GC can happen in leaf calls.
   102     // Further Note: DO NOT save/restore bcp/locals. If a caller has
   103     // already saved them so that it can use esi/edi as temporaries
   104     // then a save/restore here will DESTROY the copy the caller
   105     // saved! There used to be a save_bcp() that only happened in
   106     // the ASSERT path (no restore_bcp). Which caused bizarre failures
   107     // when jvm built with ASSERTs.
   108     /*
   109   #ifdef ASSERT
   110   {
   111   Label L;
   112   cmpptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD);
   113   jcc(Assembler::equal, L);
   114   stop("InterpreterMacroAssembler::call_VM_leaf_base:"
   115   " last_sp != NULL");
   116   bind(L);
   117   }
   118   #endif
   119   // super call
   120   MacroAssembler::call_VM_leaf_base(entry_point, number_of_arguments);
   121   // interpreter specific
   122   // Used to ASSERT that r13/r14 were equal to frame's bcp/locals
   123   // but since they may not have been saved (and we don't want to
   124   // save thme here (see note above) the assert is invalid.
   125      */
   126   #ifdef ASSERT
   127   save_bcp();
   128   { Label L;
   129     //cmpl(Address(ebp, frame::interpreter_frame_last_sp_offset * wordSize), 
   130     //NULL_WORD);
   131     ld(AT,FP,frame::interpreter_frame_last_sp_offset * wordSize); 
   132     // jcc(Assembler::equal, L);
   133     beq(AT,R0,L);  
   134     delayed()->nop(); 
   135     stop("InterpreterMacroAssembler::call_VM_leaf_base: last_sp != NULL");
   136     bind(L);
   137   }
   138   #endif
   139   // super call
   140   MacroAssembler::call_VM_leaf_base(entry_point, number_of_arguments);
   141   // interpreter specific
   142   #ifdef ASSERT
   143   { Label L;
   144     ld(T3, FP, frame::interpreter_frame_bcx_offset * wordSize);
   145     Assembler::beq(BCP, T3, L);
   146     delayed()->nop();
   147     stop("InterpreterMacroAssembler::call_VM_leaf_base: esi not callee saved?");
   148     bind(L);
   149   }
   150   { Label L;
   151     ld(T3, FP, frame::interpreter_frame_locals_offset * wordSize);
   152     Assembler::beq(LVP, T3, L);
   153     delayed()->nop();
   154     stop("InterpreterMacroAssembler::call_VM_leaf_base: edi not callee saved?");
   155     bind(L);
   156   }
   157   #endif
   158   }
   160 void InterpreterMacroAssembler::call_VM_base(Register oop_result,
   161                                              Register java_thread,
   162                                              Register last_java_sp,
   163                                              address  entry_point,
   164                                              int      number_of_arguments,
   165                                              bool     check_exceptions) {
   166 #if 0
   167 	// interpreter specific
   168   //
   169   // Note: Could avoid restoring locals ptr (callee saved) - however doesn't
   170   //       really make a difference for these runtime calls, since they are
   171   //       slow anyway. Btw., bcp must be saved/restored since it may change
   172   //       due to GC.
   173   // assert(java_thread == noreg , "not expecting a precomputed java thread");
   174   save_bcp();
   175 #ifdef ASSERT
   176   {
   177     Label L;
   178     cmpptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD);
   179     jcc(Assembler::equal, L);
   180     stop("InterpreterMacroAssembler::call_VM_leaf_base:"
   181          " last_sp != NULL");
   182     bind(L);
   183   }
   184 #endif /* ASSERT */
   185   // super call
   186   MacroAssembler::call_VM_base(oop_result, noreg, last_java_sp,
   187                                entry_point, number_of_arguments,
   188                                check_exceptions);
   189   // interpreter specific
   190   restore_bcp();
   191   restore_locals();
   192 #endif
   193 #ifdef ASSERT
   194 	{ Label L;
   195 		//  cmpl(Address(ebp, frame::interpreter_frame_last_sp_offset * wordSize),
   196 		//  NULL_WORD);
   197 		// jcc(Assembler::equal, L);
   198 		ld(AT, FP, frame::interpreter_frame_last_sp_offset * wordSize); 
   199 		beq(AT, R0, L); 
   200 		delayed()->nop(); 
   201 		stop("InterpreterMacroAssembler::call_VM_base: last_sp != NULL");
   202 		bind(L);
   203 	}
   204 #endif /* ASSERT */
   205 	// interpreter specific
   206 	//
   207 	// Note: Could avoid restoring locals ptr (callee saved) - however doesn't
   208 	//       really make a difference for these runtime calls, since they are
   209 	//       slow anyway. Btw., bcp must be saved/restored since it may change
   210 	//       due to GC.
   211 	assert(java_thread == noreg , "not expecting a precomputed java thread");
   212 	save_bcp();
   213 	// super call
   214 	MacroAssembler::call_VM_base(oop_result, java_thread, last_java_sp, entry_point, number_of_arguments, check_exceptions);
   215 	restore_bcp();
   216 	restore_locals();
   217 }
   220 void InterpreterMacroAssembler::check_and_handle_popframe(Register java_thread) {
   221   if (JvmtiExport::can_pop_frame()) {
   222     Label L;
   223     // Initiate popframe handling only if it is not already being
   224     // processed.  If the flag has the popframe_processing bit set, it
   225     // means that this code is called *during* popframe handling - we
   226     // don't want to reenter.
   227     // This method is only called just after the call into the vm in
   228     // call_VM_base, so the arg registers are available.
   229     /*
   230 		movl(c_rarg0, Address(r15_thread, JavaThread::popframe_condition_offset()));
   231     testl(c_rarg0, JavaThread::popframe_pending_bit);
   232     jcc(Assembler::zero, L);
   233     testl(c_rarg0, JavaThread::popframe_processing_bit);
   234     jcc(Assembler::notZero, L);
   235     // Call Interpreter::remove_activation_preserving_args_entry() to get the
   236     // address of the same-named entrypoint in the generated interpreter code.
   237     call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_preserving_args_entry));
   238     jmp(rax);
   239     bind(L);
   240 		*/
   241 		Register pop_cond = java_thread;
   242 		// Not clear if any other register is available...
   243 		lw(pop_cond, java_thread, in_bytes(JavaThread::popframe_condition_offset()));
   244 		andi(AT, pop_cond, JavaThread::popframe_pending_bit);
   245 		beq(AT, R0, L);		
   246 		delayed()->andi(AT, pop_cond, JavaThread::popframe_processing_bit);		
   247 		bne(AT, R0, L);
   248 		delayed()->nop();
   249 		call( CAST_FROM_FN_PTR(address, Interpreter::remove_activation_preserving_args_entry), relocInfo::runtime_call_type);
   250 		delayed()->nop();
   251 		jr(V0);
   252 		delayed()->nop();
   253 		bind(L);
   254 		get_thread(java_thread);
   255   }
   256 }
   259 void InterpreterMacroAssembler::load_earlyret_value(TosState state) {
   260 	//T8, thread
   261 	get_thread(T8);
   262 	ld_ptr(T8, T8,in_bytes(JavaThread::jvmti_thread_state_offset())); 
   263 	/* 
   264 	   const Address tos_addr (ecx, JvmtiThreadState::earlyret_tos_offset());
   265 	   const Address oop_addr (ecx, JvmtiThreadState::earlyret_oop_offset());
   266 	   const Address val_addr (ecx, JvmtiThreadState::earlyret_value_offset());
   267 	   const Address val_addr1(ecx, JvmtiThreadState::earlyret_value_offset()
   268 	   + in_ByteSize(wordSize));
   269 	   */ 
   270 	const Address tos_addr (T8, in_bytes(JvmtiThreadState::earlyret_tos_offset()));
   271 	const Address oop_addr (T8, in_bytes(JvmtiThreadState::earlyret_oop_offset()));
   272 	const Address val_addr (T8, in_bytes(JvmtiThreadState::earlyret_value_offset()));
   273 	//V0, oop_addr,V1,val_addr 
   274 	switch (state) {
   275 		case atos: 
   276 			//movl(eax, oop_addr);
   277 			ld_ptr(V0, oop_addr);
   278 			// movl(oop_addr, NULL_WORD);
   279 			st_ptr(R0, oop_addr);  
   280 			//verify_oop(eax, state);       break;
   281 			verify_oop(V0, state);               
   282 			break;
   283 		case ltos: 
   284 			// movl(edx, val_addr1);               // fall through
   285 			ld_ptr(V0, val_addr);               // fall through
   286 			break;
   287 		case btos:                                     // fall through
   288 		case ctos:                                     // fall through
   289 		case stos:                                     // fall through
   290 		case itos: 
   291 			//	movl(eax, val_addr);               
   292 			lw(V0, val_addr);               
   293 			break;
   294 			//FIXME ,I hava no idear fld store to where @jerome 
   295 		case ftos: 
   296 			//fld_s(val_addr);                       
   297 			lwc1(F0,T8, in_bytes(JvmtiThreadState::earlyret_value_offset()));	
   298 			break;
   299 		case dtos: 
   300 			//fld_d(val_addr);                       
   301 			ldc1(F0,T8, in_bytes(JvmtiThreadState::earlyret_value_offset()));	
   302 			break;
   303 		case vtos: /* nothing to do */                    break;
   304 		default  : ShouldNotReachHere();
   305 	}
   306 	// Clean up tos value in the thread object
   307 	// movl(tos_addr,  (int) ilgl);
   308 	//addi(AT,R0,(int)ilgl); 
   309 	move(AT, (int)ilgl); 
   310 	sw(AT, tos_addr);
   311 	// movl(val_addr,  NULL_WORD);
   312 	sw(R0,T8, in_bytes(JvmtiThreadState::earlyret_value_offset())); 
   313 }
   316 void InterpreterMacroAssembler::check_and_handle_earlyret(Register java_thread) {
   317   if (JvmtiExport::can_force_early_return()) {
   318     Label L;
   319 		Register tmp = T9;
   321     //movptr(c_rarg0, Address(r15_thread, JavaThread::jvmti_thread_state_offset()));
   322 		ld_ptr(AT,java_thread, in_bytes(JavaThread::jvmti_thread_state_offset())); 
   323     //testptr(c_rarg0, c_rarg0);
   324     //jcc(Assembler::zero, L); // if (thread->jvmti_thread_state() == NULL) exit;
   325 		beq(AT,R0,L);
   326 		delayed()->nop(); 
   328     // Initiate earlyret handling only if it is not already being processed.
   329     // If the flag has the earlyret_processing bit set, it means that this code
   330     // is called *during* earlyret handling - we don't want to reenter.
   331     //movl(c_rarg0, Address(c_rarg0, JvmtiThreadState::earlyret_state_offset()));
   332 		lw(AT, AT, in_bytes(JvmtiThreadState::earlyret_state_offset()));
   333     //cmpl(c_rarg0, JvmtiThreadState::earlyret_pending);
   334     //jcc(Assembler::notEqual, L);
   335 		move(tmp, JvmtiThreadState::earlyret_pending); 
   336 		bne(tmp, AT, L); 
   337 		delayed()->nop(); 
   338 		get_thread(java_thread);
   340     // Call Interpreter::remove_activation_early_entry() to get the address of the
   341     // same-named entrypoint in the generated interpreter code.
   342     //movptr(c_rarg0, Address(r15_thread, JavaThread::jvmti_thread_state_offset()));
   343 		ld_ptr(tmp,java_thread, in_bytes(JavaThread::jvmti_thread_state_offset())); 
   344     //movl(c_rarg0, Address(c_rarg0, JvmtiThreadState::earlyret_tos_offset()));
   345 		lw(AT,tmp, in_bytes(JvmtiThreadState::earlyret_tos_offset()));
   346 		move(A0, AT); 
   347 		//push(AT); 
   348 		call(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_early_entry),  
   349 				relocInfo::runtime_call_type);
   350     //call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_early_entry), c_rarg0);
   351     //jmp(rax);
   352     //bind(L);
   353 		jr(V0); 
   354 		delayed()->nop(); 
   355 		bind(L);
   356 		get_thread(java_thread);
   357   }
   358 }
   361 void InterpreterMacroAssembler::get_unsigned_2_byte_index_at_bcp(
   362                                                                  Register reg,
   363                                                                  int bcp_offset) {
   364   assert(bcp_offset >= 0, "bcp is still pointing to start of bytecode");
   365   get_2_byte_integer_at_bcp(reg, AT, bcp_offset);
   366   hswap(reg);
   367 }
   370 void InterpreterMacroAssembler::get_cache_and_index_at_bcp(Register cache,
   371                                                            Register index,
   372                                                            int bcp_offset,
   373                                                            size_t index_size) {
   374   assert_different_registers(cache, index);
   375   get_cache_index_at_bcp(index, bcp_offset, index_size);
   376   ld(cache, FP, frame::interpreter_frame_cache_offset * wordSize);
   377   assert(sizeof(ConstantPoolCacheEntry) == 4 * wordSize, "adjust code below");
   378   assert(exact_log2(in_words(ConstantPoolCacheEntry::size())) == 2, "else change next line");
   379   shl(index, 2);
   380 }
   382 void InterpreterMacroAssembler::get_cache_and_index_and_bytecode_at_bcp(Register cache,
   383                                                                          Register index,
   384                                                                          Register bytecode,
   385                                                                          int byte_no,
   386                                                                          int bcp_offset,
   387                                                                         size_t index_size) {
   388    get_cache_and_index_at_bcp(cache, index, bcp_offset, index_size);
   389    // We use a 32-bit load here since the layout of 64-bit words on
   390    // little-endian machines allow us that.
   391    dsll(AT, index, Address::times_ptr);
   392    dadd(AT, cache, AT);
   393    lw(bytecode, AT, in_bytes(ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::indices_offset()));
   395    const int shift_count = (1 + byte_no) * BitsPerByte;
   396    assert((byte_no == TemplateTable::f1_byte && shift_count == ConstantPoolCacheEntry::bytecode_1_shift) ||
   397           (byte_no == TemplateTable::f2_byte && shift_count == ConstantPoolCacheEntry::bytecode_2_shift),
   398           "correct shift count");
   399    dsrl(bytecode, bytecode, shift_count);
   400    assert(ConstantPoolCacheEntry::bytecode_1_mask == ConstantPoolCacheEntry::bytecode_2_mask, "common mask");
   401    move(AT, ConstantPoolCacheEntry::bytecode_1_mask);
   402    andr(bytecode, bytecode, AT);
   403  }
   405 void InterpreterMacroAssembler::get_cache_entry_pointer_at_bcp(Register cache,
   406 								Register tmp,
   407 								int bcp_offset, size_t index_size) {
   408 	assert(bcp_offset > 0, "bcp is still pointing to start of bytecode");
   409 	assert(cache != tmp, "must use different register");
   411 	get_cache_index_at_bcp(tmp, bcp_offset, index_size);
   412 	assert(sizeof(ConstantPoolCacheEntry) == 4 * wordSize, "adjust code below");
   413 	// convert from field index to ConstantPoolCacheEntry index
   414 	// and from word offset to byte offset
   415 	dsll(tmp, tmp, 2+LogBytesPerWord);
   416 	ld(cache, FP, frame::interpreter_frame_cache_offset * wordSize);
   417 	// skip past the header
   418 	daddi(cache, cache, in_bytes(ConstantPoolCache::base_offset()));
   419 	dadd(cache, cache, AT);
   420 }
   422 void InterpreterMacroAssembler::get_cache_index_at_bcp(Register index,
   423                                                        int bcp_offset,
   424                                                        size_t index_size) {
   425   assert(bcp_offset > 0, "bcp is still pointing to start of bytecode");
   426   if (index_size == sizeof(u2)) {
   427     get_2_byte_integer_at_bcp(index, AT, bcp_offset);
   428   } else if (index_size == sizeof(u4)) {
   429     assert(EnableInvokeDynamic, "giant index used only for JSR 292");
   430     get_4_byte_integer_at_bcp(index, AT, bcp_offset);
   431     // Check if the secondary index definition is still ~x, otherwise
   432     // we have to change the following assembler code to calculate the
   433     // plain index.
   434     assert(ConstantPool::decode_invokedynamic_index(~123) == 123, "else change next line");
   435     nor(index, index, R0);
   436     sll(index, index, 0);
   437   } else if (index_size == sizeof(u1)) {
   438     lbu(index, BCP, bcp_offset);
   439   } else {
   440     ShouldNotReachHere();
   441   }
   442 }
   444 void InterpreterMacroAssembler::get_method_counters(Register method,
   445                                                     Register mcs, Label& skip) {
   446   Label has_counters;
   447   ld(mcs, method, in_bytes(Method::method_counters_offset()));
   448   bne(mcs, R0, has_counters);
   449   nop();
   450   call_VM(noreg, CAST_FROM_FN_PTR(address,
   451           InterpreterRuntime::build_method_counters), method);
   452   ld(mcs, method, in_bytes(Method::method_counters_offset()));
   453   beq(mcs, R0, skip);   // No MethodCounters allocated, OutOfMemory
   454   nop();
   455   bind(has_counters);
   456 }
   458  // Load object from cpool->resolved_references(index)
   459  void InterpreterMacroAssembler::load_resolved_reference_at_index(
   460                                             Register result, Register index) {
   461    assert_different_registers(result, index);
   462    // convert from field index to resolved_references() index and from
   463    // word index to byte offset. Since this is a java object, it can be compressed
   464    Register tmp = index;  // reuse
   465    shl(tmp, LogBytesPerHeapOop);
   467    get_constant_pool(result);
   468    // load pointer for resolved_references[] objArray
   469    ld(result, result, ConstantPool::resolved_references_offset_in_bytes());
   470    // JNIHandles::resolve(obj);
   471    // movptr(result, Address(result, 0));
   472    ld(result, result, 0); //? is needed?
   473    // Add in the index
   474    dadd(result, result, tmp);
   475    load_heap_oop(result, Address(result, arrayOopDesc::base_offset_in_bytes(T_OBJECT)));
   476  }
   478 // Resets LVP to locals.  Register sub_klass cannot be any of the above.
   479 void InterpreterMacroAssembler::gen_subtype_check( Register Rsup_klass, Register Rsub_klass, Label &ok_is_subtype ) {
   480   assert( Rsub_klass != Rsup_klass, "Rsup_klass holds superklass" );
   481   assert( Rsub_klass != T1, "T1 holds 2ndary super array length" );
   482   assert( Rsub_klass != T0, "T0 holds 2ndary super array scan ptr" );
   483  // Profile the not-null value's klass.
   484  // [20130904] Fu: Here T9 and T1 are used as temporary registers.
   485   profile_typecheck(T9, Rsub_klass, T1); // blows rcx, reloads rdi
   487 // Do the check.
   488   check_klass_subtype(Rsub_klass, Rsup_klass, T1, ok_is_subtype); // blows rcx
   490 // Profile the failure of the check.
   491   profile_typecheck_failed(T9); // blows rcx
   492 }
   496 // Java Expression Stack
   498 void InterpreterMacroAssembler::pop_ptr(Register r) {
   499   pop(r);
   500   //if (TaggedStackInterpreter) addptr(rsp, 1 * wordSize);
   501 //	if (TaggedStackInterpreter) addi(SP,SP, 1 * wordSize);
   502 }
   503 /*
   504 void InterpreterMacroAssembler::pop_ptr(Register r, Register tag) {
   505   pop(r);
   506  // if (TaggedStackInterpreter) pop(tag);
   507 }*/
   509 void InterpreterMacroAssembler::pop_i(Register r) {
   510   // XXX can't use pop currently, upper half non clean
   511   //movl(r, Address(rsp, 0));
   512   //addptr(rsp, wordSize);
   513   lw(r, SP, 0);
   514   daddi(SP, SP, 8);
   515 	//if (TaggedStackInterpreter) addptr(rsp, 1 * wordSize);
   516 //	if (TaggedStackInterpreter) addi(SP,SP, 1 * wordSize);
   517 }
   518 /*
   519 void InterpreterMacroAssembler::pop_l(Register r) {
   520   //movq(r, Address(rsp, 0));
   521   //addptr(rsp, 2 * Interpreter::stackElementSize());
   522 	//FIXME, this directly call assembler. by aoqi 
   523 	ld(r, SP, 0);
   524 	addi(SP, SP, 8);
   525 	if (TaggedStackInterpreter) addi(SP,SP, 2 * wordSize);
   526 }
   527 */
   528 //FIXME How many registers do push_l & pop_l use? aoqi
   529 void InterpreterMacroAssembler::pop_l(Register lo, Register hi) {
   530   pop(lo); 
   531   //if (TaggedStackInterpreter) daddi(SP,SP, 1 * wordSize);       
   532   pop(hi); 
   533   //if (TaggedStackInterpreter) daddi(SP,SP, 1 * wordSize);
   534 }
   536 void InterpreterMacroAssembler::pop_f() {
   537   lwc1(FSF, SP, 0); 
   538   daddi(SP, SP, 1 * wordSize);
   539 //  if (TaggedStackInterpreter) addi(SP,SP, 1 * wordSize);
   540 }
   542 void InterpreterMacroAssembler::pop_d() {
   543   pop_dtos_to_esp();
   544   ldc1(FSF, SP, 0); 
   545   daddi(SP, SP, 2 * wordSize);
   546 }
   548 // Pop the top of the java expression stack to execution stack (which
   549 // happens to be the same place).
   550 //FIXME ,I hava no idea which register to use
   551 void InterpreterMacroAssembler::pop_dtos_to_esp() {
   552 /*	if (TaggedStackInterpreter) {
   553 		// Pop double value into scratch registers
   554 		//  popl(eax);
   555 		pop(V0); 
   556 		//addl(esp, 1* wordSize);
   557 		addi(SP,SP, 1* wordSize);
   558 		//popl(edx);
   559 		pop(V1);
   560 		//addl(esp, 1* wordSize);
   561 		addi(SP,SP, 1* wordSize);
   562 		// pushl(edx);
   563 		push(V1);
   564 		//pushl(eax);
   565 		push(V0);
   566 	}*/
   567 }
   569 void InterpreterMacroAssembler::pop_ftos_to_esp() {
   570 /*  if (TaggedStackInterpreter) {
   571 		//  popl(eax);
   572 		pop(V0);
   573 		//addl(esp, 1 * wordSize);
   574 		addi(SP,SP, 1 * wordSize);
   575 		// pushl(eax);  // ftos is at esp
   576 		push(V0);  // ftos is at esp
   577 	}*/
   578 }
   580 void InterpreterMacroAssembler::push_ptr(Register r) {
   581   //if (TaggedStackInterpreter) push(frame::TagReference);
   582 /*	if (TaggedStackInterpreter) {
   583 		move(AT, frame::TagReference); 
   584 		push(AT);
   585 	}//pushl(r);*/
   586   push(r);
   587 }
   588 /*
   589 void InterpreterMacroAssembler::push_ptr(Register r, Register tag) {
   590   //if (TaggedStackInterpreter) push(tag);
   591 	if (TaggedStackInterpreter){
   592 		move(AT, tag);
   593 		push(AT);  // tag first
   594 	} 
   595   push(r);
   596 }*/
   598 void InterpreterMacroAssembler::push_i(Register r) {
   599   //if (TaggedStackInterpreter) push(frame::TagValue);
   600 /*	if (TaggedStackInterpreter) {
   601 		move(AT, frame::TagValue);	
   602 		push(AT);
   603 	}*/
   604   push(r);
   605 }
   606 /*
   607 void InterpreterMacroAssembler::push_l(Register r) {
   608   if (TaggedStackInterpreter) {
   609     //push(frame::TagValue);
   610     //subptr(rsp, 1 * wordSize);
   611     //push(frame::TagValue);
   612     //subptr(rsp, 1 * wordSize);
   613 		move(AT, frame::TagValue);
   614 		push(AT);
   615   } else {
   616     addi(SP, SP, (-2) * wordSize);
   617   }
   618   //movq(Address(rsp, 0), r);
   619 	//FIXME, same as pop_l
   620 	sd(r, SP, 0);
   621 }
   622 */
   623 //FIXME How many registers do push_l & pop_l use? aoqi
   624 void InterpreterMacroAssembler::push_l(Register lo, Register hi) {
   625   //if (TaggedStackInterpreter) pushl(frame::TagValue);
   626   /*if (TaggedStackInterpreter) {
   627     move(AT, frame::TagValue);
   628 		push(AT);
   629 	}*/
   630 	//pushl(hi);
   631 	push(hi);
   632 	//if (TaggedStackInterpreter) pushl(frame::TagValue);
   633 /*	if (TaggedStackInterpreter) {
   634 		move(AT, frame::TagValue);
   635 		push(AT);
   636 	}*/
   637 	//pushl(lo);
   638 	push(lo);
   639 }
   640 //void InterpreterMacroAssembler::push_f(XMMRegister r) {
   641 void InterpreterMacroAssembler::push_f() {
   642  /* if (TaggedStackInterpreter) {
   643     move(AT, frame::TagValue);
   644     push(AT);
   645   }// Do not schedule for no AGI! Never write beyond esp!*/
   646   daddi(SP, SP, (-1) * wordSize);
   647   swc1(FSF, SP, 0 * wordSize);
   648   sw(R0, SP,  4);
   649 }
   651 //FIXME. aoqi
   652 void InterpreterMacroAssembler::push_d(FloatRegister r) {
   653  /* if (TaggedStackInterpreter) {
   654     move(AT, frame::TagValue); 
   655     push(AT);
   656     addi(SP, SP, (-3) * wordSize);
   657     swc1(FSF, SP, 0 * wordSize);
   658     swc1(SSF, SP, 1 * wordSize);
   660     lwc1(r, SP, 1*wordSize);
   661     swc1(r, SP, 2*wordSize);
   662     move(AT, frame::TagValue);
   663     sw(AT, SP, 1*wordSize);
   664   } else {*/
   665     daddi(SP, SP, (-2) * wordSize);
   666     sdc1(FSF, SP, 0 * wordSize);
   667     sdc1(SSF, SP, 1 * wordSize);
   668  // }
   669 }
   671 void InterpreterMacroAssembler::pop(TosState state) {
   672   switch (state) {
   673     case atos: pop(FSR);      break; 
   674     case btos:
   675     case ctos:
   676     case stos:
   677     case itos: 
   678 	       pop_i(FSR);	
   679 	       break;
   680     case ltos: 
   681 	       pop_l(FSR, SSR);
   682 	       break;
   683     case ftos: pop_f();      						break;
   684     case dtos: pop_d();      						break; 
   685     case vtos: /* nothing to do */      break;
   686     default:   ShouldNotReachHere();
   687   }
   688   verify_oop(V0, state);
   689 }
   691 //FSR=V0,SSR=V1
   692 void InterpreterMacroAssembler::push(TosState state) {
   693   verify_oop(V0, state);
   694   switch (state) {
   695     case atos:   push(FSR);    break;
   696     case btos:						     // fall through
   697     case ctos:						     // fall through
   698     case stos:						     // fall through
   699     case itos:
   700 		 push_i(FSR);
   701 		 break;
   702     case ltos:
   703     //FIXME aoqi.
   704 		 daddi(SP, SP, (-2) * wordSize);
   705 		 //sd(SSR, SP, 1 * wordSize);
   706 		 sd(R0, SP, 1 * wordSize);
   707 		 sd(FSR, SP, 0 * wordSize);
   708 		 break;
   709     case ftos: 
   710 		 push_f(); 
   711 		 break;
   712     case dtos: 
   713 		 //FIXME, I have no idea which register to use 
   714 		 push_d(FSF); 
   715 		 break;
   716     case vtos: /* nothing to do */                            break;
   717     default  : ShouldNotReachHere();
   718   }
   719 }
   724 // Tagged stack helpers for swap and dup
   725 void InterpreterMacroAssembler::load_ptr(int n, Register val) {
   726   ld(val, SP, Interpreter::expr_offset_in_bytes(n));
   727   /*if (TaggedStackInterpreter) {
   728     ld(tag, SP, Interpreter::expr_tag_offset_in_bytes(n));
   729   }*/
   730 }
   732 void InterpreterMacroAssembler::store_ptr(int n, Register val) {
   733   sd(val, SP, Interpreter::expr_offset_in_bytes(n));
   734  /* if (TaggedStackInterpreter) {
   735     //movptr(Address(rsp, Interpreter::expr_tag_offset_in_bytes(n)), tag);
   736     sd(tag, SP, Interpreter::expr_tag_offset_in_bytes(n));
   737   }*/
   738 }
   740 /*
   741 // Tagged local support
   742 //LVP=S7, local variable pointer register , FIXME
   743 void InterpreterMacroAssembler::tag_local(frame::Tag tag, int n) {
   744   if (TaggedStackInterpreter) {
   745     if (tag == frame::TagCategory2) {
   746       //movptr(Address(r14, Interpreter::local_tag_offset_in_bytes(n+1)),
   747       //     (int32_t)frame::TagValue);
   748 			move(AT, (int)frame::TagValue); 
   749 			sw(AT,LVP, Interpreter::local_tag_offset_in_bytes(n+1));
   750       //movptr(Address(r14, Interpreter::local_tag_offset_in_bytes(n)),
   751       //     (int32_t)frame::TagValue);
   752 			sw(AT,LVP, Interpreter::local_tag_offset_in_bytes(n));
   753     } else {
   754       //movptr(Address(r14, Interpreter::local_tag_offset_in_bytes(n)), (int32_t)tag);
   755 			move(AT, (int)tag);	   
   756 			sw(AT,LVP, Interpreter::local_tag_offset_in_bytes(n));
   757     }
   758   }
   759 }
   761 void InterpreterMacroAssembler::tag_local(frame::Tag tag, Register idx) {
   762   if (TaggedStackInterpreter) {
   763     if (tag == frame::TagCategory2) {
   764       //movptr(Address(r14, idx, Address::times_8,
   765       //            Interpreter::local_tag_offset_in_bytes(1)), (int32_t)frame::TagValue);
   766       //movptr(Address(r14, idx, Address::times_8,
   767       //            Interpreter::local_tag_offset_in_bytes(0)), (int32_t)frame::TagValue);
   768 			shl(idx, 3); 
   769 			add(idx,LVP,idx); 
   770 			move(AT,(int)frame::TagValue); 
   771 			sw(AT, idx, Interpreter::local_tag_offset_in_bytes(1));	    
   772 			shl(idx, 3); 
   773 			add(idx,LVP,idx); 
   774 			move(AT,(int)frame::TagValue); 
   775 			sw(AT, idx, Interpreter::local_tag_offset_in_bytes(0));	    
   776     } else {
   777       //movptr(Address(r14, idx, Address::times_8, Interpreter::local_tag_offset_in_bytes(0)),
   778       //     (int32_t)tag);
   779 			shl(idx, 3); 
   780 			add(idx,LVP,idx); 
   781 			move(AT,(int)tag); 
   782 			sw(AT, idx, Interpreter::local_tag_offset_in_bytes(0));	    
   783     }
   784   }
   785 }
   787 void InterpreterMacroAssembler::tag_local(Register tag, Register idx) {
   788   if (TaggedStackInterpreter) {
   789     // can only be TagValue or TagReference
   790     //movptr(Address(r14, idx, Address::times_8, Interpreter::local_tag_offset_in_bytes(0)), tag);
   791 		shl(idx, 3); 
   792 		add(idx,LVP,idx); 
   793 		sw(tag, idx, Interpreter::local_tag_offset_in_bytes(0));	    
   794   }
   795 }
   798 void InterpreterMacroAssembler::tag_local(Register tag, int n) {
   799   if (TaggedStackInterpreter) {
   800     // can only be TagValue or TagReference
   801     //movptr(Address(r14, Interpreter::local_tag_offset_in_bytes(n)), tag);
   802 		sw(tag, LVP, Interpreter::local_tag_offset_in_bytes(n)); 
   803   }
   804 }
   806 #ifdef ASSERT
   807 void InterpreterMacroAssembler::verify_local_tag(frame::Tag tag, int n) {
   808   if (TaggedStackInterpreter) {
   809      frame::Tag t = tag;
   810     if (tag == frame::TagCategory2) {
   811       Label nbl;
   812       t = frame::TagValue;  // change to what is stored in locals
   813       //cmpptr(Address(r14, Interpreter::local_tag_offset_in_bytes(n+1)), (int32_t)t);
   814       //jcc(Assembler::equal, nbl);
   815 			lw(AT, LVP, Interpreter::local_tag_offset_in_bytes(n+1)); 
   816 			addi(AT,AT, -(int)t); 
   817 			beq(AT, R0, nbl); 
   818 			delayed()->nop(); 
   819       stop("Local tag is bad for long/double");
   820       bind(nbl);
   821     }
   822     Label notBad;
   823     //cmpq(Address(r14, Interpreter::local_tag_offset_in_bytes(n)), (int32_t)t);
   824     //jcc(Assembler::equal, notBad);
   825 		lw(AT, LVP, Interpreter::local_tag_offset_in_bytes(n)); 
   826 		addi(AT,AT, -(int)t); 
   827 		beq(AT, R0, notBad); 
   828 		delayed()->nop(); 
   830 		// Also compare if the local value is zero, then the tag might
   831     // not have been set coming from deopt.
   832     //cmpptr(Address(r14, Interpreter::local_offset_in_bytes(n)), 0);
   833     //jcc(Assembler::equal, notBad);
   834 		lw(AT, LVP, Interpreter::local_tag_offset_in_bytes(n+1)); 
   835 		beq(AT, R0, notBad); 
   836 		delayed()->nop(); 
   837     stop("Local tag is bad");
   838     bind(notBad);
   839   }
   840 }
   842 void InterpreterMacroAssembler::verify_local_tag(frame::Tag tag, Register idx) {
   843   if (TaggedStackInterpreter) {
   844     frame::Tag t = tag;
   845     if (tag == frame::TagCategory2) {
   846       Label nbl;
   847       t = frame::TagValue;  // change to what is stored in locals
   848       //cmpptr(Address(r14, idx, Address::times_8, Interpreter::local_tag_offset_in_bytes(1)), (int32_t)t);
   849       //jcc(Assembler::equal, nbl);
   850 			shl(idx, 3); 
   851 			add(idx,LVP,idx); 
   852 			lw(AT, idx, Interpreter::local_tag_offset_in_bytes(1));	
   853 			addi(AT,AT, -(int)t); 
   854 			beq(AT,R0, nbl); 
   855 			delayed()->nop(); 
   856       stop("Local tag is bad for long/double");
   857       bind(nbl);
   858     }
   859     Label notBad;
   860     //cmpptr(Address(r14, idx, Address::times_8, Interpreter::local_tag_offset_in_bytes(0)), (int32_t)t);
   861     //jcc(Assembler::equal, notBad);
   862 		shl(idx, 3); 
   863 		add(idx,LVP,idx); 
   864 		lw(AT, idx, Interpreter::local_tag_offset_in_bytes(0));	
   865 		addi(AT,AT, -(int)t); 
   866 		beq(AT,R0, notBad); 
   867 		delayed()->nop(); 
   869     // Also compare if the local value is zero, then the tag might
   870     // not have been set coming from deopt.
   871     //cmpptr(Address(r14, idx, Address::times_8, Interpreter::local_offset_in_bytes(0)), 0);
   872     //jcc(Assembler::equal, notBad);
   873 		shl(idx, 3); 
   874 		add(idx,LVP,idx); 
   875 		lw(AT, idx, Interpreter::local_tag_offset_in_bytes(0));	
   876 		beq(AT,R0, notBad); 
   877 		delayed()->nop(); 
   878     stop("Local tag is bad");
   879     bind(notBad);
   880   }
   881 }
   882 #endif // ASSERT
   883 */
   884 /*
   885 void InterpreterMacroAssembler::super_call_VM_leaf(address entry_point) {
   886   MacroAssembler::call_VM_leaf_base(entry_point, 0);
   887 }
   890 void InterpreterMacroAssembler::super_call_VM_leaf(address entry_point,
   891                                                    Register arg_1) {
   892   if (arg_1 != A0) move(A0, arg_1);
   893   MacroAssembler::call_VM_leaf_base(entry_point, 1);
   894 }
   897 void InterpreterMacroAssembler::super_call_VM_leaf(address entry_point,
   898                                                    Register arg_1,
   899                                                    Register arg_2) {
   900   if (arg_1 != A0) move(A0, arg_1);
   901   if (arg_2 != A1) move(A1, arg_2); assert(arg_2 != A0, "smashed argument");
   902   MacroAssembler::call_VM_leaf_base(entry_point, 2);
   903 }
   905 void InterpreterMacroAssembler::super_call_VM_leaf(address entry_point,
   906                                                    Register arg_1,
   907                                                    Register arg_2,
   908                                                    Register arg_3) {
   909   if (arg_1 != A0) move(A0, arg_1);
   910   if (arg_2 != A1) move(A1, arg_2); assert(arg_2 != A0, "smashed argument");
   911   if (arg_3 != A2) move(A2, arg_3); assert(arg_3 != A0 && arg_3 != A1, "smashed argument");
   912   MacroAssembler::call_VM_leaf_base(entry_point, 3);
   913 }
   914 */
   915 // Jump to from_interpreted entry of a call unless single stepping is possible
   916 // in this thread in which case we must call the i2i entry
   917 void InterpreterMacroAssembler::jump_from_interpreted(Register method, Register temp) {
   918   // record last_sp
   919   move(Rsender, SP);	
   920   sd(SP, FP, frame::interpreter_frame_last_sp_offset * wordSize);
   922   if (JvmtiExport::can_post_interpreter_events()) {
   923     Label run_compiled_code;
   924     // JVMTI events, such as single-stepping, are implemented partly by avoiding running
   925     // compiled code in threads for which the event is enabled.  Check here for
   926     // interp_only_mode if these events CAN be enabled.
   927 #ifndef OPT_THREAD
   928 	get_thread(temp); 
   929 #else
   930 	move(temp, TREG);
   931 #endif
   932     // interp_only is an int, on little endian it is sufficient to test the byte only
   933     // Is a cmpl faster (ce
   934     //cmpb(Address(temp, JavaThread::interp_only_mode_offset()), 0);
   935     //jcc(Assembler::zero, run_compiled_code);
   936     lw(AT, temp, in_bytes(JavaThread::interp_only_mode_offset())); 
   937     beq(AT, R0, run_compiled_code); 
   938     delayed()->nop(); 
   939     //jmp(Address(method, methodOopDesc::interpreter_entry_offset()));
   940     ld(AT, method, in_bytes(Method::interpreter_entry_offset())); 
   941     jr(AT); 
   942     delayed()->nop(); 
   943     bind(run_compiled_code);
   944   }
   946   ld(AT, method, in_bytes(Method::from_interpreted_offset()));
   947   jr(AT); 
   948   delayed()->nop();
   949 }
   952 // The following two routines provide a hook so that an implementation
   953 // can schedule the dispatch in two parts.  amd64 does not do this.
   954 void InterpreterMacroAssembler::dispatch_prolog(TosState state, int step) {
   955   // Nothing amd64 specific to be done here
   956 }
   958 void InterpreterMacroAssembler::dispatch_epilog(TosState state, int step) {
   959   dispatch_next(state, step);
   960 }
   962 // assume the next bytecode in T8. 
   963 void InterpreterMacroAssembler::dispatch_base(TosState state,
   964                                               address* table,
   965                                               bool verifyoop) {
   966   if (VerifyActivationFrameSize) {
   967     Label L;
   969     dsub(T2, FP, SP);
   970     int min_frame_size = (frame::link_offset - 
   971 	frame::interpreter_frame_initial_sp_offset) * wordSize;
   972     daddi(T2, T2,- min_frame_size);
   973     bgez(T2, L);
   974     delayed()->nop();
   975     stop("broken stack frame");
   976     bind(L);
   977   }
   978   // FIXME: I do not know which register should pass to verify_oop
   979   if (verifyoop) verify_oop(FSR, state);
   980   dsll(T2, Rnext, LogBytesPerWord);
   982   if((long)table >= (long)Interpreter::dispatch_table(btos) &&
   983      (long)table <= (long)Interpreter::dispatch_table(vtos)
   984     ) {
   985      int table_size = (long)Interpreter::dispatch_table(ctos) - (long)Interpreter::dispatch_table(btos);
   986      int table_offset = ((int)state - (int)itos) * table_size; 
   988      // 2013/12/17 Fu: GP points to the starting address of Interpreter::dispatch_table(itos).
   989      // See StubGenerator::generate_call_stub(address& return_address) for the initialization of GP.
   990      if(table_offset != 0) {
   991         daddiu(T3, GP, table_offset);
   992         gsldx(T3, T2, T3, 0); // 2013/5/7 Jin: Godson3 extension instruction
   993      } else {
   994         gsldx(T3, T2, GP, 0);
   995      }
   996   } else {
   997      li(T3, (long)table);
   998      gsldx(T3, T2, T3, 0);
   999   }
  1001   jr(T3);
  1002   delayed()->nop();
  1005 void InterpreterMacroAssembler::dispatch_only(TosState state) {
  1006   dispatch_base(state, Interpreter::dispatch_table(state));
  1009 void InterpreterMacroAssembler::dispatch_only_normal(TosState state) {
  1010   dispatch_base(state, Interpreter::normal_table(state));
  1013 void InterpreterMacroAssembler::dispatch_only_noverify(TosState state) {
  1014   dispatch_base(state, Interpreter::normal_table(state), false);
  1018 void InterpreterMacroAssembler::dispatch_next(TosState state, int step) {
  1019   // load next bytecode (load before advancing r13 to prevent AGI)
  1020   lbu(Rnext, BCP, step);
  1021   increment(BCP, step);
  1022   dispatch_base(state, Interpreter::dispatch_table(state));
  1025 void InterpreterMacroAssembler::dispatch_via(TosState state, address* table) {
  1026   // load current bytecode
  1027   lbu(Rnext, BCP, 0);
  1028   dispatch_base(state, table);
  1031 // remove activation
  1032 //
  1033 // Unlock the receiver if this is a synchronized method.
  1034 // Unlock any Java monitors from syncronized blocks.
  1035 // Remove the activation from the stack.
  1036 //
  1037 // If there are locked Java monitors
  1038 //    If throw_monitor_exception
  1039 //       throws IllegalMonitorStateException
  1040 //    Else if install_monitor_exception
  1041 //       installs IllegalMonitorStateException
  1042 //    Else
  1043 //       no error processing
  1044 // used registers : T1, T2, T3, T8
  1045 // T1 : thread, method access flags
  1046 // T2 : monitor entry pointer
  1047 // T3 : method, monitor top
  1048 // T8 : unlock flag
  1049 void InterpreterMacroAssembler::remove_activation(
  1050         TosState state,
  1051         Register ret_addr,
  1052         bool throw_monitor_exception,
  1053         bool install_monitor_exception,
  1054 	bool notify_jvmdi) {
  1055   // Note: Registers V0, V1 and F0, F1 may be in use for the result
  1056   // check if synchronized method  
  1057   Label unlocked, unlock, no_unlock;
  1059   // get the value of _do_not_unlock_if_synchronized into T8
  1060 #ifndef OPT_THREAD
  1061   Register thread = T1;
  1062   get_thread(thread); 
  1063 #else
  1064   Register thread = TREG;
  1065 #endif
  1066   lb(T8, thread, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
  1067   // reset the flag
  1068   sb(R0, thread, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset())); 
  1069   // get method access flags
  1070   ld(T3, FP, frame::interpreter_frame_method_offset * wordSize); 	
  1071   lw(T1, T3, in_bytes(Method::access_flags_offset()));
  1072   andi(T1, T1, JVM_ACC_SYNCHRONIZED);
  1073   beq(T1, R0, unlocked);
  1074   delayed()->nop();
  1076   // Don't unlock anything if the _do_not_unlock_if_synchronized flag is set.
  1077   bne(T8, R0, no_unlock);
  1078   delayed()->nop();
  1079   // unlock monitor
  1080   push(state);     // save result
  1082   // BasicObjectLock will be first in list, 
  1083   // since this is a synchronized method. However, need
  1084   // to check that the object has not been unlocked by an explicit monitorexit bytecode.  
  1085   daddiu(c_rarg0, FP, frame::interpreter_frame_initial_sp_offset * wordSize 
  1086       - (int)sizeof(BasicObjectLock));
  1087   // address of first monitor
  1088   lw(T1, c_rarg0, BasicObjectLock::obj_offset_in_bytes());
  1089   bne(T1, R0, unlock); 
  1090   delayed()->nop(); 
  1091   pop(state);
  1092   if (throw_monitor_exception) {
  1093     // Entry already unlocked, need to throw exception
  1094     //I think mips do not need empty_FPU_stack 
  1095     // remove possible return value from FPU-stack, otherwise stack could overflow
  1097     empty_FPU_stack();	
  1098     call_VM(NOREG, CAST_FROM_FN_PTR(address, 
  1099 	  InterpreterRuntime::throw_illegal_monitor_state_exception));
  1100     should_not_reach_here();
  1101   } else {
  1102     // Monitor already unlocked during a stack unroll. 
  1103     // If requested, install an illegal_monitor_state_exception.
  1104     // Continue with stack unrolling.
  1105     if (install_monitor_exception) {
  1106       // remove possible return value from FPU-stack, 
  1107       // otherwise stack could overflow
  1108       empty_FPU_stack();  		
  1109       call_VM(NOREG, CAST_FROM_FN_PTR(address, 
  1110 	    InterpreterRuntime::new_illegal_monitor_state_exception));
  1114     b(unlocked);
  1115     delayed()->nop();
  1118   bind(unlock);  
  1120   unlock_object(c_rarg0);              
  1121   pop(state);
  1122   // Check that for block-structured locking (i.e., that all locked objects has been unlocked)  
  1123   bind(unlocked);  
  1125   // V0, V1: Might contain return value
  1127   // Check that all monitors are unlocked
  1129     Label loop, exception, entry, restart;
  1130     const int entry_size  = frame::interpreter_frame_monitor_size() * wordSize;
  1131     const Address monitor_block_top(FP, 
  1132 	frame::interpreter_frame_monitor_block_top_offset * wordSize);
  1134     bind(restart);
  1135     // points to current entry, starting with top-most entry (ecx)
  1136     ld(c_rarg0, monitor_block_top); 
  1137     // points to word before bottom of monitor block (ebx)
  1138     daddiu(T3, FP, frame::interpreter_frame_initial_sp_offset * wordSize); 
  1139     //  lw(AT, R0, 12); 
  1140     b(entry);
  1141     delayed()->nop();
  1143     // Entry already locked, need to throw exception
  1144     bind(exception); 
  1146     if (throw_monitor_exception) {
  1147       // Throw exception      
  1148       // remove possible return value from FPU-stack, 
  1149       // otherwise stack could overflow
  1150       empty_FPU_stack();       
  1151       MacroAssembler::call_VM(NOREG, CAST_FROM_FN_PTR(address, 
  1152 	    InterpreterRuntime::throw_illegal_monitor_state_exception));
  1153       should_not_reach_here();
  1154     } else {
  1155       // Stack unrolling. Unlock object and install illegal_monitor_exception
  1156       // Unlock does not block, so don't have to worry about the frame
  1157       // We don't have to preserve eax, edx since we are going to 
  1158       // throw an exception
  1159       unlock_object(c_rarg0);
  1160       if (install_monitor_exception) {
  1161 	empty_FPU_stack();  				
  1162 	call_VM(NOREG, CAST_FROM_FN_PTR(address, 
  1163 	      InterpreterRuntime::new_illegal_monitor_state_exception));
  1166       b(restart);
  1167       delayed()->nop();
  1170     bind(loop);
  1171     //    stop("before object excetpion"); 
  1173     ld(T1, c_rarg0, BasicObjectLock::obj_offset_in_bytes());
  1174     bne(T1, R0, exception);// check if current entry is used
  1175     delayed()->nop();
  1178     daddiu(c_rarg0, c_rarg0, entry_size);// otherwise advance to next entry
  1179     bind(entry);
  1180     bne(c_rarg0, T3, loop);	// check if bottom reached
  1181     delayed()->nop();	// if not at bottom then check this entry
  1184   bind(no_unlock);
  1186   // jvmpi support (jvmdi does not generate MethodExit on exception / popFrame)
  1187   if (notify_jvmdi) {
  1188     //notify_method_exit(state);              // preserve TOSCA
  1189     notify_method_exit(false,state,NotifyJVMTI);    // preserve TOSCA
  1190   } else {
  1191     // notify_jvmpi_method_exit(state);       // preserve TOSCA
  1192     notify_method_exit(false,state,SkipNotifyJVMTI);// preserve TOSCA
  1195   // remove activation
  1196   ld(SP, FP, frame::interpreter_frame_sender_sp_offset * wordSize); 
  1197   ld(ret_addr, FP, frame::interpreter_frame_return_addr_offset * wordSize);
  1198   ld(FP, FP, frame::interpreter_frame_sender_fp_offset * wordSize);
  1201 #endif // C_INTERP
  1203 // Lock object
  1204 //
  1205 // Args:
  1206 //      c_rarg1: BasicObjectLock to be used for locking
  1207 //
  1208 // Kills:
  1209 //      rax
  1210 //      c_rarg0, c_rarg1, c_rarg2, c_rarg3, .. (param regs)
  1211 //      rscratch1, rscratch2 (scratch regs)
  1212 void InterpreterMacroAssembler::lock_object(Register lock_reg) {
  1213   assert(lock_reg == c_rarg0, "The argument is only for looks. It must be c_rarg0");
  1215   if (UseHeavyMonitors) {
  1216     call_VM(NOREG, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter), 
  1217 	lock_reg);
  1218   } else {
  1220     Label done;
  1222     const Register swap_reg = T2;  // Must use eax for cmpxchg instruction
  1223     const Register obj_reg  = T1;  // Will contain the oop
  1225     const int obj_offset = BasicObjectLock::obj_offset_in_bytes();
  1226     const int lock_offset = BasicObjectLock::lock_offset_in_bytes ();
  1227     const int mark_offset = lock_offset 
  1228       + BasicLock::displaced_header_offset_in_bytes(); 
  1230     Label slow_case;
  1231     // Load object pointer into obj_reg %ecx
  1232     ld(obj_reg, lock_reg, obj_offset);
  1233     if (UseBiasedLocking) {
  1234       // Note: we use noreg for the temporary register since it's hard
  1235       // to come up with a free register on all incoming code paths
  1236       biased_locking_enter(lock_reg, obj_reg, swap_reg, noreg, false, 
  1237 	  done, &slow_case);
  1241     // Load (object->mark() | 1) into swap_reg %eax
  1242     ld(AT, obj_reg, 0);
  1243     ori(swap_reg, AT, 1);
  1246     // Save (object->mark() | 1) into BasicLock's displaced header
  1247     sd(swap_reg, lock_reg, mark_offset);
  1249     assert(lock_offset == 0, "displached header must be first word in BasicObjectLock");
  1250     //if (os::is_MP()) {
  1251       //  lock();
  1252     //}
  1253     cmpxchg(lock_reg, Address(obj_reg, 0), swap_reg);
  1255     if (PrintBiasedLockingStatistics) {
  1256       Label L;
  1257       beq(AT, R0, L);
  1258       delayed()->nop();
  1259       push(T0);
  1260       push(T1);
  1261       atomic_inc32((address)BiasedLocking::fast_path_entry_count_addr(), 1, T0, T1);
  1262       pop(T1);
  1263       pop(T0);
  1264       bind(L);
  1267     bne(AT, R0, done);
  1268     delayed()->nop();
  1270     // Test if the oopMark is an obvious stack pointer, i.e.,
  1271     //  1) (mark & 3) == 0, and
  1272     //  2) SP <= mark < SP + os::pagesize()
  1273     //
  1274     // These 3 tests can be done by evaluating the following 
  1275     // expression: ((mark - esp) & (3 - os::vm_page_size())),
  1276     // assuming both stack pointer and pagesize have their
  1277     // least significant 2 bits clear.
  1278     // NOTE: the oopMark is in swap_reg %eax as the result of cmpxchg
  1280     dsub(swap_reg, swap_reg, SP);
  1281     move(AT, 3 - os::vm_page_size());
  1282     andr(swap_reg, swap_reg, AT);
  1283     // Save the test result, for recursive case, the result is zero
  1284     sd(swap_reg, lock_reg, mark_offset);
  1285     if (PrintBiasedLockingStatistics) {
  1286       Label L;
  1287       bne(swap_reg, R0, L);
  1288       delayed()->nop();
  1289       push(T0);
  1290       push(T1);
  1291       atomic_inc32((address)BiasedLocking::fast_path_entry_count_addr(), 1, T0, T1);
  1292       pop(T1);
  1293       pop(T0);
  1294       bind(L);
  1297     beq(swap_reg, R0, done);
  1298     delayed()->nop();
  1299     bind(slow_case);
  1300     // Call the runtime routine for slow case
  1301     call_VM(NOREG, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter), lock_reg);
  1303     bind(done);
  1308 // Unlocks an object. Used in monitorexit bytecode and
  1309 // remove_activation.  Throws an IllegalMonitorException if object is
  1310 // not locked by current thread.
  1311 //
  1312 // Args:
  1313 //      c_rarg1: BasicObjectLock for lock
  1314 //
  1315 // Kills:
  1316 //      rax
  1317 //      c_rarg0, c_rarg1, c_rarg2, c_rarg3, ... (param regs)
  1318 //      rscratch1, rscratch2 (scratch regs)
  1319 // Argument: T6 : Points to BasicObjectLock structure for lock
  1320 // Argument: c_rarg0 : Points to BasicObjectLock structure for lock
  1321 // Throw an IllegalMonitorException if object is not locked by current thread
  1322 void InterpreterMacroAssembler::unlock_object(Register lock_reg) {
  1323   assert(lock_reg == c_rarg0, "The argument is only for looks. It must be c_rarg0");
  1325   if (UseHeavyMonitors) {
  1326     call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), lock_reg);
  1327   } else {
  1328     Label done;
  1330     const Register swap_reg   = T2;  // Must use eax for cmpxchg instruction
  1331     const Register header_reg = T3;  // Will contain the old oopMark
  1332     const Register obj_reg    = T1;  // Will contain the oop
  1334     save_bcp(); // Save in case of exception
  1336     // Convert from BasicObjectLock structure to object and BasicLock structure
  1337     // Store the BasicLock address into %eax
  1338     daddi(swap_reg, lock_reg, BasicObjectLock::lock_offset_in_bytes());
  1340     // Load oop into obj_reg(%ecx)
  1341     ld(obj_reg, lock_reg, BasicObjectLock::obj_offset_in_bytes ());
  1342     //free entry 
  1343     sd(R0, lock_reg, BasicObjectLock::obj_offset_in_bytes());
  1344     if (UseBiasedLocking) {
  1345       biased_locking_exit(obj_reg, header_reg, done);
  1348     // Load the old header from BasicLock structure
  1349     ld(header_reg, swap_reg, BasicLock::displaced_header_offset_in_bytes());
  1350     /*
  1351     // Free entry
  1352     sw(R0, lock_reg, BasicObjectLock::obj_offset_in_bytes());
  1353      */
  1354     // zero for recursive case
  1355     beq(header_reg, R0, done);
  1356     delayed()->nop();
  1358     // Atomic swap back the old header
  1359     if (os::is_MP()); //lock();
  1360     cmpxchg(header_reg, Address(obj_reg, 0), swap_reg);
  1362     // zero for recursive case
  1363     bne(AT, R0, done);
  1364     delayed()->nop();
  1366     // Call the runtime routine for slow case.
  1367     sd(obj_reg, lock_reg, BasicObjectLock::obj_offset_in_bytes()); // restore obj
  1368     call_VM(NOREG, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), 
  1369 	lock_reg);
  1371     bind(done);
  1373     restore_bcp();
  1377 #ifndef CC_INTERP
  1379 void InterpreterMacroAssembler::test_method_data_pointer(Register mdp,
  1380     Label& zero_continue) {
  1381   assert(ProfileInterpreter, "must be profiling interpreter");
  1382   ld(mdp, Address(FP, frame::interpreter_frame_mdx_offset * wordSize));
  1383   beq(mdp, R0, zero_continue);
  1384   delayed()->nop();
  1388 // Set the method data pointer for the current bcp.
  1389 void InterpreterMacroAssembler::set_method_data_pointer_for_bcp() {
  1390         assert(ProfileInterpreter, "must be profiling interpreter");
  1391         Label set_mdp;
  1393         // V0 and T0 will be used as two temporary registers.
  1394         sd(V0, SP, (-1) * wordSize);
  1395         sd(T0, SP, (-2) * wordSize);
  1396         daddiu(SP, SP, (-2) * wordSize);
  1398         get_method(T0);
  1399         // Test MDO to avoid the call if it is NULL.
  1400         ld(V0, T0, in_bytes(Method::method_data_offset()));
  1401         beq(V0, R0, set_mdp);
  1402         delayed()->nop();
  1404         // method: T0
  1405         // bcp: BCP --> S0
  1406         call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::bcp_to_di), T0, BCP);
  1407         // mdi: V0
  1408         // mdo is guaranteed to be non-zero here, we checked for it before the call.
  1409         /* Jin: reload T0 */
  1410         get_method(T0);
  1411         ld(T0, T0, in_bytes(Method::method_data_offset()));
  1412         daddiu(T0, T0, in_bytes(MethodData::data_offset()));
  1413         daddu(V0, T0, V0);
  1415         bind(set_mdp);
  1417         sd(V0, FP, frame::interpreter_frame_mdx_offset * wordSize);
  1419         daddiu(SP, SP, 2 * wordSize);
  1420         ld(V0, SP, (-1) * wordSize);
  1421         ld(T0, SP, (-2) * wordSize);
  1424 void InterpreterMacroAssembler::verify_method_data_pointer() {
  1425 assert(ProfileInterpreter, "must be profiling interpreter");
  1426 #ifdef ASSERT
  1427   Label verify_continue;
  1428   Register method = V0;
  1429   Register mdp = V1;
  1430   Register tmp = A0;
  1431   push(method);
  1432   push(mdp);
  1433   push(tmp);
  1434   test_method_data_pointer(mdp, verify_continue); // If mdp is zero, continue
  1435   get_method(method);
  1437   // If the mdp is valid, it will point to a DataLayout header which is
  1438   // consistent with the bcp.  The converse is highly probable also.
  1439   lhu(tmp, mdp, in_bytes(DataLayout::bci_offset()));
  1440   ld(AT, method, in_bytes(Method::const_offset()));
  1441   daddu(tmp, tmp, AT);
  1442   daddiu(tmp, tmp, in_bytes(ConstMethod::codes_offset()));
  1443   beq(tmp, BCP, verify_continue);
  1444   nop();
  1445   call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::verify_mdp), method, BCP, mdp);
  1446   bind(verify_continue);
  1447   pop(tmp);
  1448   pop(mdp);
  1449   pop(method);
  1450 #endif // ASSERT
  1454 void InterpreterMacroAssembler::set_mdp_data_at(Register mdp_in,
  1455                                                 int constant,
  1456                                                 Register value) {
  1457   assert(ProfileInterpreter, "must be profiling interpreter");
  1458   Address data(mdp_in, constant);
  1459   sd(value, data);
  1463 void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in,
  1464                                                       int constant,
  1465                                                       bool decrement) {
  1466   // Counter address
  1467   Address data(mdp_in, constant);
  1469   increment_mdp_data_at(data, decrement);
  1472 void InterpreterMacroAssembler::increment_mdp_data_at(Address data,
  1473                                                       bool decrement) {
  1474   assert(ProfileInterpreter, "must be profiling interpreter");
  1475   // %%% this does 64bit counters at best it is wasting space
  1476   // at worst it is a rare bug when counters overflow
  1477   Register tmp = S0;
  1478   push(tmp);
  1479   if (decrement) {
  1480     // Decrement the register.
  1481     ld(AT, data);
  1482     daddiu(tmp, AT, (int32_t) -DataLayout::counter_increment);
  1483     // If the decrement causes the counter to overflow, stay negative
  1484     Label L;
  1485     slt(AT, tmp, R0);
  1486     bne(AT, R0, L);
  1487     nop();
  1488     daddi(tmp, tmp, (int32_t) DataLayout::counter_increment);
  1489     bind(L);
  1490     sd(tmp, data);
  1491   } else {
  1492     assert(DataLayout::counter_increment == 1, 
  1493            "flow-free idiom only works with 1");
  1494     ld(AT, data);
  1495     // Increment the register.
  1496     daddiu(tmp, AT, DataLayout::counter_increment);
  1497     // If the increment causes the counter to overflow, pull back by 1.
  1498     slt(AT, tmp, R0);
  1499     dsubu(tmp, tmp, AT);
  1500     sd(tmp, data);
  1502   pop(tmp);
  1506 void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in,
  1507                                                       Register reg,
  1508                                                       int constant,
  1509                                                       bool decrement) {
  1510   Register tmp = S0;
  1511   push(S0);
  1512   if (decrement) {
  1513     // Decrement the register.
  1514     daddu(AT, mdp_in, reg);
  1515     assert(Assembler::is_simm16(constant), "constant is not a simm16 !");
  1516     ld(AT, AT, constant);
  1518     daddiu(tmp, AT, (int32_t) -DataLayout::counter_increment);
  1519     // If the decrement causes the counter to overflow, stay negative
  1520     Label L;
  1521     slt(AT, tmp, R0);
  1522     bne(AT, R0, L);
  1523     nop();
  1524     daddi(tmp, tmp, (int32_t) DataLayout::counter_increment);
  1525     bind(L);
  1527     daddu(AT, mdp_in, reg);
  1528     sd(tmp, AT, constant);
  1529   } else {
  1530     daddu(AT, mdp_in, reg);
  1531     assert(Assembler::is_simm16(constant), "constant is not a simm16 !");
  1532     ld(AT, AT, constant);
  1534     // Increment the register.
  1535     daddiu(tmp, AT, DataLayout::counter_increment);
  1536     // If the increment causes the counter to overflow, pull back by 1.
  1537     slt(AT, tmp, R0);
  1538     dsubu(tmp, tmp, AT);
  1540     daddu(AT, mdp_in, reg);
  1541     sd(tmp, AT, constant);
  1543   pop(S0);
  1546 void InterpreterMacroAssembler::set_mdp_flag_at(Register mdp_in,
  1547                                                 int flag_byte_constant) {
  1548   assert(ProfileInterpreter, "must be profiling interpreter");
  1549   int header_offset = in_bytes(DataLayout::header_offset());
  1550   int header_bits = DataLayout::flag_mask_to_header_mask(flag_byte_constant);
  1551   // Set the flag
  1552   lw(AT, Address(mdp_in, header_offset));
  1553   if(Assembler::is_simm16(header_bits)) {
  1554     ori(AT, AT, header_bits);
  1555   } else {
  1556     push(T8);
  1557     // T8 is used as a temporary register.
  1558     move(T8, header_bits);
  1559     orr(AT, AT, T8);
  1560     pop(T8);
  1562   sw(AT, Address(mdp_in, header_offset));
  1567 void InterpreterMacroAssembler::test_mdp_data_at(Register mdp_in,
  1568                                                  int offset,
  1569                                                  Register value,
  1570                                                  Register test_value_out,
  1571                                                  Label& not_equal_continue) {
  1572   assert(ProfileInterpreter, "must be profiling interpreter");
  1573   if (test_value_out == noreg) {
  1574     ld(AT, Address(mdp_in, offset));
  1575     bne(AT, value, not_equal_continue);
  1576     nop();
  1577   } else {
  1578     // Put the test value into a register, so caller can use it:
  1579     ld(test_value_out, Address(mdp_in, offset));
  1580     bne(value, test_value_out, not_equal_continue);
  1581     nop();
  1586 void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in,
  1587                                                      int offset_of_disp) {
  1588   assert(ProfileInterpreter, "must be profiling interpreter");
  1589   assert(Assembler::is_simm16(offset_of_disp), "offset is not an simm16");
  1590   ld(AT, mdp_in, offset_of_disp);
  1591   daddu(mdp_in, mdp_in, AT);
  1592   sd(mdp_in, Address(FP, frame::interpreter_frame_mdx_offset * wordSize));
  1596 void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in,
  1597                                                      Register reg,
  1598                                                      int offset_of_disp) {
  1599   assert(ProfileInterpreter, "must be profiling interpreter");
  1600 //  Attention: Until now (20121217), we do not support this kind of addressing on Loongson.
  1601 //  Address disp_address(mdp_in, reg, Address::times_1, offset_of_disp);
  1602   daddu(AT, reg, mdp_in);
  1603   assert(Assembler::is_simm16(offset_of_disp), "offset is not an simm16");
  1604   ld(AT, AT, offset_of_disp);
  1605   daddu(mdp_in, mdp_in, AT);
  1606   sd(mdp_in, Address(FP, frame::interpreter_frame_mdx_offset * wordSize));
  1610 void InterpreterMacroAssembler::update_mdp_by_constant(Register mdp_in,
  1611                                                        int constant) {
  1612   assert(ProfileInterpreter, "must be profiling interpreter");
  1613   if(Assembler::is_simm16(constant)) {
  1614     daddiu(mdp_in, mdp_in, constant);
  1615   } else {
  1616     move(AT, constant);
  1617     daddu(mdp_in, mdp_in, AT);
  1619   sd(mdp_in, Address(FP, frame::interpreter_frame_mdx_offset * wordSize));
  1623 void InterpreterMacroAssembler::update_mdp_for_ret(Register return_bci) {
  1624   assert(ProfileInterpreter, "must be profiling interpreter");
  1625   push(return_bci); // save/restore across call_VM
  1626   call_VM(noreg,
  1627           CAST_FROM_FN_PTR(address, InterpreterRuntime::update_mdp_for_ret),
  1628           return_bci);
  1629   pop(return_bci);
  1633 void InterpreterMacroAssembler::profile_taken_branch(Register mdp,
  1634                                                      Register bumped_count) {
  1635   if (ProfileInterpreter) {
  1636     Label profile_continue;
  1638     // If no method data exists, go to profile_continue.
  1639     // Otherwise, assign to mdp
  1640     test_method_data_pointer(mdp, profile_continue);
  1642     // We are taking a branch.  Increment the taken count.
  1643     //increment_mdp_data_at(mdp, in_bytes(JumpData::taken_offset()));
  1644     // We inline increment_mdp_data_at to return bumped_count in a register
  1645     ld(bumped_count, mdp, in_bytes(JumpData::taken_offset()));
  1646     assert(DataLayout::counter_increment == 1, 
  1647            "flow-free idiom only works with 1");
  1648     push(T8);
  1649     // T8 is used as a temporary register.
  1650     daddiu(T8, bumped_count, DataLayout::counter_increment);
  1651     slt(AT, T8, R0);
  1652     dsubu(bumped_count, T8, AT);
  1653     pop(T8);
  1654     sd(bumped_count, mdp, in_bytes(JumpData::taken_offset())); // Store back out
  1655     // The method data pointer needs to be updated to reflect the new target.
  1656     update_mdp_by_offset(mdp, in_bytes(JumpData::displacement_offset()));
  1657     bind(profile_continue);
  1662 void InterpreterMacroAssembler::profile_not_taken_branch(Register mdp) {
  1663   if (ProfileInterpreter) {
  1664     Label profile_continue;
  1666     // If no method data exists, go to profile_continue.
  1667     test_method_data_pointer(mdp, profile_continue);
  1669     // We are taking a branch.  Increment the not taken count.
  1670     increment_mdp_data_at(mdp, in_bytes(BranchData::not_taken_offset()));
  1672     // The method data pointer needs to be updated to correspond to
  1673     // the next bytecode
  1674     update_mdp_by_constant(mdp, in_bytes(BranchData::branch_data_size()));
  1675     bind(profile_continue);
  1680 void InterpreterMacroAssembler::profile_call(Register mdp) {
  1681   if (ProfileInterpreter) {
  1682     Label profile_continue;
  1684     // If no method data exists, go to profile_continue.
  1685     test_method_data_pointer(mdp, profile_continue);
  1687     // We are making a call.  Increment the count.
  1688     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
  1690     // The method data pointer needs to be updated to reflect the new target.
  1691     update_mdp_by_constant(mdp, in_bytes(CounterData::counter_data_size()));
  1692     bind(profile_continue);
  1697 void InterpreterMacroAssembler::profile_final_call(Register mdp) {
  1698   if (ProfileInterpreter) {
  1699     Label profile_continue;
  1701     // If no method data exists, go to profile_continue.
  1702     test_method_data_pointer(mdp, profile_continue);
  1703     // We are making a call.  Increment the count.
  1704     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
  1706     // The method data pointer needs to be updated to reflect the new target.
  1707     update_mdp_by_constant(mdp, in_bytes(VirtualCallData:: virtual_call_data_size()));
  1708     bind(profile_continue);
  1713 void InterpreterMacroAssembler::profile_virtual_call(Register receiver,
  1714                                                      Register mdp,
  1715                                                      Register reg2,
  1716                                                      bool receiver_can_be_null) {
  1717   if (ProfileInterpreter) {
  1718     Label profile_continue;
  1720     // If no method data exists, go to profile_continue.
  1721     test_method_data_pointer(mdp, profile_continue);
  1723     Label skip_receiver_profile;
  1724     if (receiver_can_be_null) {
  1725        Label not_null;
  1726        bne(receiver, R0, not_null);
  1727        nop();
  1728        // We are making a call.  Increment the count.
  1729        increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
  1730        beq(R0, R0, skip_receiver_profile);
  1731        nop();
  1732        bind(not_null);
  1735     // Record the receiver type.
  1736     record_klass_in_profile(receiver, mdp, reg2, true);
  1737     bind(skip_receiver_profile);
  1739     // The method data pointer needs to be updated to reflect the new target.
  1740     update_mdp_by_constant(mdp, in_bytes(VirtualCallData::virtual_call_data_size()));
  1741     bind(profile_continue);
  1745 void InterpreterMacroAssembler::profile_checkcast(bool is_null, Register mdp) {
  1746 // In x86, this method does not exist.
  1747 #ifndef CORE
  1748         if (ProfileInterpreter) {
  1749                 Label profile_continue;
  1751                 // If no method data exists, go to profile_continue.
  1752                 test_method_data_pointer(mdp, profile_continue);
  1754                 if (is_null)                // Set the flag to true.
  1755                         set_mdp_flag_at(mdp, BitData::null_seen_byte_constant());
  1756                         //set_mdp_flag_at(mdp, BitData::null_flag_constant());
  1758                 // The method data pointer needs to be updated.
  1759                 update_mdp_by_constant(mdp, in_bytes(BitData::bit_data_size()));
  1761                 bind (profile_continue);
  1763 #endif // !CORE
  1766 // This routine creates a state machine for updating the multi-row
  1767 // type profile at a virtual call site (or other type-sensitive bytecode).
  1768 // The machine visits each row (of receiver/count) until the receiver type
  1769 // is found, or until it runs out of rows.  At the same time, it remembers
  1770 // the location of the first empty row.  (An empty row records null for its
  1771 // receiver, and can be allocated for a newly-observed receiver type.)
  1772 // Because there are two degrees of freedom in the state, a simple linear
  1773 // search will not work; it must be a decision tree.  Hence this helper
  1774 // function is recursive, to generate the required tree structured code.
  1775 // It's the interpreter, so we are trading off code space for speed.
  1776 // See below for example code.
  1777 void InterpreterMacroAssembler::record_klass_in_profile_helper(
  1778                                         Register receiver, Register mdp,
  1779                                         Register reg2,
  1780                                         int start_row, Label& done, bool is_virtual_call) {
  1781   if (TypeProfileWidth == 0) {
  1782     if (is_virtual_call) {
  1783       increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
  1785     return;
  1788   int last_row = VirtualCallData::row_limit() - 1;
  1789   assert(start_row <= last_row, "must be work left to do");
  1790   // Test this row for both the receiver and for null.
  1791   // Take any of three different outcomes:
  1792   //   1. found receiver => increment count and goto done
  1793   //   2. found null => keep looking for case 1, maybe allocate this cell
  1794   //   3. found something else => keep looking for cases 1 and 2
  1795   // Case 3 is handled by a recursive call.
  1796   for (int row = start_row; row <= last_row; row++) {
  1797     Label next_test;
  1798     bool test_for_null_also = (row == start_row);
  1800     // See if the receiver is receiver[n].
  1801     int recvr_offset = in_bytes(VirtualCallData::receiver_offset(row));
  1802     test_mdp_data_at(mdp, recvr_offset, receiver,
  1803                      (test_for_null_also ? reg2 : noreg),
  1804                      next_test);
  1805     // (Reg2 now contains the receiver from the CallData.)
  1807     // The receiver is receiver[n].  Increment count[n].
  1808     int count_offset = in_bytes(VirtualCallData::receiver_count_offset(row));
  1809     increment_mdp_data_at(mdp, count_offset);
  1810     beq(R0, R0, done);
  1811     nop();
  1812     bind(next_test);
  1814     if (test_for_null_also) {
  1815       Label found_null;
  1816       // Failed the equality check on receiver[n]...  Test for null.
  1817       if (start_row == last_row) {
  1818         // The only thing left to do is handle the null case.
  1819         if (is_virtual_call) {
  1820           beq(reg2, R0, found_null);
  1821           nop();
  1822           // Receiver did not match any saved receiver and there is no empty row for it.
  1823           // Increment total counter to indicate polymorphic case.
  1824           increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
  1825           beq(R0, R0, done);
  1826           nop();
  1827           bind(found_null);
  1828         } else {
  1829           bne(reg2, R0, done);
  1830           nop();
  1832         break;
  1834       // Since null is rare, make it be the branch-taken case.
  1835       beq(reg2, R0, found_null);
  1836       nop();
  1838       // Put all the "Case 3" tests here.
  1839       record_klass_in_profile_helper(receiver, mdp, reg2, start_row + 1, done, is_virtual_call);
  1841       // Found a null.  Keep searching for a matching receiver,
  1842       // but remember that this is an empty (unused) slot.
  1843       bind(found_null);
  1847   // In the fall-through case, we found no matching receiver, but we
  1848   // observed the receiver[start_row] is NULL.
  1850   // Fill in the receiver field and increment the count.
  1851   int recvr_offset = in_bytes(VirtualCallData::receiver_offset(start_row));
  1852   set_mdp_data_at(mdp, recvr_offset, receiver);
  1853   int count_offset = in_bytes(VirtualCallData::receiver_count_offset(start_row));
  1854   move(reg2, DataLayout::counter_increment);
  1855   set_mdp_data_at(mdp, count_offset, reg2);
  1856   if (start_row > 0) {
  1857     beq(R0, R0, done);
  1858     nop();
  1862 // Example state machine code for three profile rows:
  1863 //   // main copy of decision tree, rooted at row[1]
  1864 //   if (row[0].rec == rec) { row[0].incr(); goto done; }
  1865 //   if (row[0].rec != NULL) {
  1866 //     // inner copy of decision tree, rooted at row[1]
  1867 //     if (row[1].rec == rec) { row[1].incr(); goto done; }
  1868 //     if (row[1].rec != NULL) {
  1869 //       // degenerate decision tree, rooted at row[2]
  1870 //       if (row[2].rec == rec) { row[2].incr(); goto done; }
  1871 //       if (row[2].rec != NULL) { goto done; } // overflow
  1872 //       row[2].init(rec); goto done;
  1873 //     } else {
  1874 //       // remember row[1] is empty
  1875 //       if (row[2].rec == rec) { row[2].incr(); goto done; }
  1876 //       row[1].init(rec); goto done;
  1877 //     }
  1878 //   } else {
  1879 //     // remember row[0] is empty
  1880 //     if (row[1].rec == rec) { row[1].incr(); goto done; }
  1881 //     if (row[2].rec == rec) { row[2].incr(); goto done; }
  1882 //     row[0].init(rec); goto done;
  1883 //   }
  1885 void InterpreterMacroAssembler::record_klass_in_profile(Register receiver,
  1886                                                         Register mdp,
  1887                                                         Register reg2, bool is_virtual_call) {
  1888   assert(ProfileInterpreter, "must be profiling");
  1889   Label done;
  1891   record_klass_in_profile_helper(receiver, mdp, reg2, 0, done, is_virtual_call);
  1893   bind (done);
  1896 void InterpreterMacroAssembler::profile_ret(Register return_bci,
  1897                                             Register mdp) {
  1898   if (ProfileInterpreter) {
  1899     Label profile_continue;
  1900     uint row;
  1902     // If no method data exists, go to profile_continue.
  1903     test_method_data_pointer(mdp, profile_continue);
  1905     // Update the total ret count.
  1906     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
  1908     for (row = 0; row < RetData::row_limit(); row++) {
  1909       Label next_test;
  1911       // See if return_bci is equal to bci[n]:
  1912       test_mdp_data_at(mdp,
  1913                        in_bytes(RetData::bci_offset(row)),
  1914                        return_bci, noreg,
  1915                        next_test);
  1917       // return_bci is equal to bci[n].  Increment the count.
  1918       increment_mdp_data_at(mdp, in_bytes(RetData::bci_count_offset(row)));
  1920       // The method data pointer needs to be updated to reflect the new target.
  1921       update_mdp_by_offset(mdp,
  1922                            in_bytes(RetData::bci_displacement_offset(row)));
  1923       beq(R0, R0, profile_continue);
  1924       nop();
  1925       bind(next_test);
  1928     update_mdp_for_ret(return_bci);
  1930     bind(profile_continue);
  1935 void InterpreterMacroAssembler::profile_null_seen(Register mdp) {
  1936   if (ProfileInterpreter) {
  1937     Label profile_continue;
  1939     // If no method data exists, go to profile_continue.
  1940     test_method_data_pointer(mdp, profile_continue);
  1942     set_mdp_flag_at(mdp, BitData::null_seen_byte_constant());
  1944     // The method data pointer needs to be updated.
  1945     int mdp_delta = in_bytes(BitData::bit_data_size());
  1946     if (TypeProfileCasts) {
  1947       mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
  1949     update_mdp_by_constant(mdp, mdp_delta);
  1951     bind(profile_continue);
  1956 void InterpreterMacroAssembler::profile_typecheck_failed(Register mdp) {
  1957   if (ProfileInterpreter && TypeProfileCasts) {
  1958     Label profile_continue;
  1960     // If no method data exists, go to profile_continue.
  1961     test_method_data_pointer(mdp, profile_continue);
  1963     int count_offset = in_bytes(CounterData::count_offset());
  1964     // Back up the address, since we have already bumped the mdp.
  1965     count_offset -= in_bytes(VirtualCallData::virtual_call_data_size());
  1967     // *Decrement* the counter.  We expect to see zero or small negatives.
  1968     increment_mdp_data_at(mdp, count_offset, true);
  1970     bind (profile_continue);
  1975 void InterpreterMacroAssembler::profile_typecheck(Register mdp, Register klass, Register reg2) {
  1976   if (ProfileInterpreter) {
  1977     Label profile_continue;
  1979     // If no method data exists, go to profile_continue.
  1980     test_method_data_pointer(mdp, profile_continue);
  1982     // The method data pointer needs to be updated.
  1983     int mdp_delta = in_bytes(BitData::bit_data_size());
  1984     if (TypeProfileCasts) {
  1986       mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
  1988       // Record the object type.
  1989       record_klass_in_profile(klass, mdp, reg2, false);
  1991     update_mdp_by_constant(mdp, mdp_delta);
  1993     bind(profile_continue);
  1998 void InterpreterMacroAssembler::profile_switch_default(Register mdp) {
  1999   if (ProfileInterpreter) {
  2000     Label profile_continue;
  2002     // If no method data exists, go to profile_continue.
  2003     test_method_data_pointer(mdp, profile_continue);
  2005     // Update the default case count
  2006     increment_mdp_data_at(mdp, in_bytes(MultiBranchData::default_count_offset()));
  2008     // The method data pointer needs to be updated.
  2009     update_mdp_by_offset(mdp, in_bytes(MultiBranchData:: default_displacement_offset()));
  2011     bind(profile_continue);
  2016 void InterpreterMacroAssembler::profile_switch_case(Register index,
  2017                                                     Register mdp,
  2018                                                     Register reg2) {
  2019   if (ProfileInterpreter) {
  2020     Label profile_continue;
  2022     // If no method data exists, go to profile_continue.
  2023     test_method_data_pointer(mdp, profile_continue);
  2025     // Build the base (index * per_case_size_in_bytes()) + case_array_offset_in_bytes()
  2026     move(reg2, in_bytes(MultiBranchData::per_case_size()));
  2027     dmult(index, reg2);
  2028     mflo(index);
  2029 //    addptr(index, in_bytes(MultiBranchData::case_array_offset())); // XXX l ?
  2030     daddiu(index, index, in_bytes(MultiBranchData::case_array_offset()));
  2032     // Update the case count
  2033     increment_mdp_data_at(mdp, index, in_bytes(MultiBranchData::relative_count_offset()));
  2035     // The method data pointer needs to be updated.
  2036     update_mdp_by_offset(mdp, index, in_bytes(MultiBranchData:: relative_displacement_offset()));
  2038     bind(profile_continue);
  2042 void InterpreterMacroAssembler::profile_obj_type(Register obj, const Address& mdo_addr) {
  2043   Label update, next, none;
  2045   verify_oop(obj);
  2047   //testptr(obj, obj);
  2048   //jccb(Assembler::notZero, update);
  2049   bne(obj, R0, update);
  2050   nop();
  2052   //orptr(mdo_addr, TypeEntries::null_seen);
  2053   push(T1);
  2054   if (mdo_addr.index() == noreg) {
  2055     ld(T1, mdo_addr);
  2056   } else {
  2057     guarantee(T1 != mdo_addr.base(), "The base register will be corrupted !");
  2058     guarantee(T1 != mdo_addr.index(), "The index register will be corrupted !");
  2060     dsll(AT, mdo_addr.index(), mdo_addr.scale());
  2061     daddu(AT, AT, mdo_addr.base());
  2062     ld(T1, AT, mdo_addr.disp());
  2064   li(AT, TypeEntries::null_seen);
  2065   orr(AT, T1, AT);
  2066   if (mdo_addr.index() == noreg) {
  2067     sd(AT, mdo_addr);
  2068   } else {
  2069     guarantee(T1 != mdo_addr.base(), "The base register will be corrupted !");
  2070     guarantee(T1 != mdo_addr.index(), "The index register will be corrupted !");
  2072     dsll(T1, mdo_addr.index(), mdo_addr.scale());
  2073     daddu(T1, T1, mdo_addr.base());
  2074     sd(AT, T1, mdo_addr.disp());
  2076   pop(T1);
  2078   //jmpb(next);
  2079   beq(R0, R0, next);
  2080   nop();
  2082   bind(update);
  2083   load_klass(obj, obj);
  2085   //xorptr(obj, mdo_addr);
  2086   if (mdo_addr.index() == noreg) {
  2087     ld(AT, mdo_addr);
  2088   } else {
  2089     dsll(AT, mdo_addr.index(), mdo_addr.scale());
  2090     daddu(AT, AT, mdo_addr.base());
  2091     ld(AT, AT, mdo_addr.disp());
  2093   xorr(obj, obj, AT);
  2095   //testptr(obj, TypeEntries::type_klass_mask);
  2096   //jccb(Assembler::zero, next); // klass seen before, nothing to
  2097                                // do. The unknown bit may have been
  2098                                // set already but no need to check.
  2099   li(AT, TypeEntries::type_klass_mask);
  2100   andr(AT, obj, AT);
  2101   beq(AT, R0, next);
  2102   nop();
  2104   //testptr(obj, TypeEntries::type_unknown);
  2105   //jccb(Assembler::notZero, next); // already unknown. Nothing to do anymore.
  2106   li(AT, TypeEntries::type_unknown);
  2107   andr(AT, AT, obj);
  2108   bne(AT, R0, next);
  2109   nop();
  2111   //cmpptr(mdo_addr, 0);
  2112   //jccb(Assembler::equal, none);
  2113   if (mdo_addr.index() == noreg) {
  2114     ld(AT, mdo_addr);
  2115   } else {
  2116     dsll(AT, mdo_addr.index(), mdo_addr.scale());
  2117     daddu(AT, AT, mdo_addr.base());
  2118     ld(AT, AT, mdo_addr.disp());
  2120   beq(AT, R0, none);
  2121   nop();
  2124   //cmpptr(mdo_addr, TypeEntries::null_seen);
  2125   //jccb(Assembler::equal, none);
  2126   push(T1);
  2127   if (mdo_addr.index() == noreg) {
  2128     ld(T1, mdo_addr);
  2129   } else {
  2130     guarantee(T1 != mdo_addr.base(), "The base register will be corrupted !");
  2131     guarantee(T1 != mdo_addr.index(), "The index register will be corrupted !");
  2133     dsll(AT, mdo_addr.index(), mdo_addr.scale());
  2134     daddu(AT, AT, mdo_addr.base());
  2135     ld(T1, AT, mdo_addr.disp());
  2137   li(AT, TypeEntries::null_seen);
  2138   subu(AT, AT, T1);
  2139   pop(T1);
  2140   beq(AT, R0, none);
  2141   nop();
  2143   // There is a chance that the checks above (re-reading profiling
  2144   // data from memory) fail if another thread has just set the
  2145   // profiling to this obj's klass
  2146   //xorptr(obj, mdo_addr);
  2147   //testptr(obj, TypeEntries::type_klass_mask);
  2148   //jccb(Assembler::zero, next);
  2149   if (mdo_addr.index() == noreg) {
  2150     ld(AT, mdo_addr);
  2151   } else {
  2152     dsll(AT, mdo_addr.index(), mdo_addr.scale());
  2153     daddu(AT, AT, mdo_addr.base());
  2154     ld(AT, AT, mdo_addr.disp());
  2156   xorr(obj, obj, AT);
  2157   li(AT, TypeEntries::type_klass_mask);
  2158   andr(AT, obj, AT);
  2159   beq(AT, R0, next);
  2160   nop();
  2162   // different than before. Cannot keep accurate profile.
  2163   //orptr(mdo_addr, TypeEntries::type_unknown);
  2164   //jmpb(next);
  2165   push(T1);
  2166   if (mdo_addr.index() == noreg) {
  2167     ld(T1, mdo_addr); 
  2168   } else {
  2169     guarantee(T1 != mdo_addr.base(), "The base register will be corrupted !");
  2170     guarantee(T1 != mdo_addr.index(), "The index register will be corrupted !");
  2172     dsll(AT, mdo_addr.index(), mdo_addr.scale());
  2173     daddu(AT, AT, mdo_addr.base());
  2174     ld(T1, AT, mdo_addr.disp());
  2176   li(AT, TypeEntries::type_unknown);
  2177   orr(AT, T1, AT);
  2178   if (mdo_addr.index() == noreg) {
  2179     sd(AT, mdo_addr);
  2180   } else {
  2181     guarantee(T1 != mdo_addr.base(), "The base register will be corrupted !");
  2182     guarantee(T1 != mdo_addr.index(), "The index register will be corrupted !");
  2184     dsll(T1, mdo_addr.index(), mdo_addr.scale());
  2185     daddu(T1, T1, mdo_addr.base());
  2186     sd(AT, T1, mdo_addr.disp());
  2188   pop(T1);
  2189   beq(R0, R0, next);
  2190   nop();
  2193   bind(none);
  2194   // first time here. Set profile type.
  2195   //movptr(mdo_addr, obj);
  2196   if (mdo_addr.index() == noreg) {
  2197     sd(obj, mdo_addr);
  2198   } else {
  2199     dsll(AT, mdo_addr.index(), mdo_addr.scale());
  2200     daddu(AT, AT, mdo_addr.base());
  2201     sd(obj, AT, mdo_addr.disp());
  2204   bind(next);
  2207 void InterpreterMacroAssembler::profile_arguments_type(Register mdp, Register callee, Register tmp, bool is_virtual) {
  2208   if (!ProfileInterpreter) {
  2209     return;
  2212   if (MethodData::profile_arguments() || MethodData::profile_return()) {
  2213     Label profile_continue;
  2215     test_method_data_pointer(mdp, profile_continue);
  2217     int off_to_start = is_virtual ? in_bytes(VirtualCallData::virtual_call_data_size()) : in_bytes(CounterData::counter_data_size());
  2219     //cmpb(Address(mdp, in_bytes(DataLayout::tag_offset()) - off_to_start), is_virtual ? DataLayout::virtual_call_type_data_tag : DataLayout::call_type_data_tag);
  2220     //jcc(Assembler::notEqual, profile_continue);
  2221     lb(AT, mdp, in_bytes(DataLayout::tag_offset()) - off_to_start);
  2222     li(tmp, is_virtual ? DataLayout::virtual_call_type_data_tag : DataLayout::call_type_data_tag);
  2223     bne(tmp, AT, profile_continue);
  2224     nop();
  2227     if (MethodData::profile_arguments()) {
  2228       Label done;
  2229       int off_to_args = in_bytes(TypeEntriesAtCall::args_data_offset());
  2230       //addptr(mdp, off_to_args);
  2231       if (Assembler::is_simm16(off_to_args)) {
  2232         daddiu(mdp, mdp, off_to_args);
  2233       } else {
  2234         move(AT, off_to_args);
  2235         daddu(mdp, mdp, AT);
  2239       for (int i = 0; i < TypeProfileArgsLimit; i++) {
  2240         if (i > 0 || MethodData::profile_return()) {
  2241           // If return value type is profiled we may have no argument to profile
  2242           //movptr(tmp, Address(mdp, in_bytes(TypeEntriesAtCall::cell_count_offset())-off_to_args));
  2243           ld(tmp, mdp, in_bytes(TypeEntriesAtCall::cell_count_offset())-off_to_args);
  2245           //subl(tmp, i*TypeStackSlotEntries::per_arg_count());
  2246           if (Assembler::is_simm16(-1 * i * TypeStackSlotEntries::per_arg_count())) {
  2247             addiu32(tmp, tmp, -1 * i * TypeStackSlotEntries::per_arg_count());
  2248           } else {
  2249             li(AT, i*TypeStackSlotEntries::per_arg_count());
  2250             subu32(tmp, tmp, AT);
  2253           //cmpl(tmp, TypeStackSlotEntries::per_arg_count());
  2254           //jcc(Assembler::less, done);
  2255           li(AT, TypeStackSlotEntries::per_arg_count());
  2256           slt(AT, tmp, AT);
  2257           bne(AT, R0, done);
  2258           nop();
  2260         //movptr(tmp, Address(callee, Method::const_offset()));
  2261         ld(tmp, callee, in_bytes(Method::const_offset())); 
  2263         //load_unsigned_short(tmp, Address(tmp, ConstMethod::size_of_parameters_offset()));
  2264         lhu(tmp, tmp, in_bytes(ConstMethod::size_of_parameters_offset()));
  2266         // stack offset o (zero based) from the start of the argument
  2267         // list, for n arguments translates into offset n - o - 1 from
  2268         // the end of the argument list
  2269         //subptr(tmp, Address(mdp, in_bytes(TypeEntriesAtCall::stack_slot_offset(i))-off_to_args));
  2270         ld(AT, mdp, in_bytes(TypeEntriesAtCall::stack_slot_offset(i))-off_to_args);
  2271         subu(tmp, tmp, AT);
  2273         //subl(tmp, 1);
  2274         addiu32(tmp, tmp, -1);
  2276         Address arg_addr = argument_address(tmp);
  2277         //movptr(tmp, arg_addr);
  2278         ld(tmp, arg_addr);
  2280         Address mdo_arg_addr(mdp, in_bytes(TypeEntriesAtCall::argument_type_offset(i))-off_to_args);
  2281         profile_obj_type(tmp, mdo_arg_addr);
  2283         int to_add = in_bytes(TypeStackSlotEntries::per_arg_size());
  2284         //addptr(mdp, to_add);
  2285         if (Assembler::is_simm16(to_add)) {
  2286           daddiu(mdp, mdp, to_add);
  2287         } else {
  2288           move(AT, to_add);
  2289           daddu(mdp, mdp, AT);
  2292         off_to_args += to_add;
  2295       if (MethodData::profile_return()) {
  2296         //movptr(tmp, Address(mdp, in_bytes(TypeEntriesAtCall::cell_count_offset())-off_to_args));
  2297         ld(tmp, mdp, in_bytes(TypeEntriesAtCall::cell_count_offset())-off_to_args);
  2299         //subl(tmp, TypeProfileArgsLimit*TypeStackSlotEntries::per_arg_count());
  2300         int tmp_arg_counts = TypeProfileArgsLimit*TypeStackSlotEntries::per_arg_count();
  2301         if (Assembler::is_simm16(-1 * tmp_arg_counts)) {
  2302           addiu32(tmp, tmp, -1 * tmp_arg_counts);
  2303         } else {
  2304           move(AT, tmp_arg_counts);
  2305           subu32(mdp, mdp, AT);
  2309       bind(done);
  2311       if (MethodData::profile_return()) {
  2312         // We're right after the type profile for the last
  2313         // argument. tmp is the number of cells left in the
  2314         // CallTypeData/VirtualCallTypeData to reach its end. Non null
  2315         // if there's a return to profile.
  2316         assert(ReturnTypeEntry::static_cell_count() < TypeStackSlotEntries::per_arg_count(), "can't move past ret type");
  2317         //shll(tmp, exact_log2(DataLayout::cell_size));
  2318         //addptr(mdp, tmp);
  2319         sll(tmp, tmp, exact_log2(DataLayout::cell_size));
  2320         daddu(mdp, mdp, tmp);
  2322       //movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), mdp);
  2323       sd(mdp, FP, frame::interpreter_frame_mdx_offset * wordSize);
  2324     } else {
  2325       assert(MethodData::profile_return(), "either profile call args or call ret");
  2326       update_mdp_by_constant(mdp, in_bytes(TypeEntriesAtCall::return_only_size()));
  2329     // mdp points right after the end of the
  2330     // CallTypeData/VirtualCallTypeData, right after the cells for the
  2331     // return value type if there's one
  2333     bind(profile_continue);
  2337 void InterpreterMacroAssembler::profile_return_type(Register mdp, Register ret, Register tmp) {
  2338   assert_different_registers(mdp, ret, tmp, _bcp_register);
  2339   if (ProfileInterpreter && MethodData::profile_return()) {
  2340     Label profile_continue, done;
  2342     test_method_data_pointer(mdp, profile_continue);
  2344     if (MethodData::profile_return_jsr292_only()) {
  2345       // If we don't profile all invoke bytecodes we must make sure
  2346       // it's a bytecode we indeed profile. We can't go back to the
  2347       // begining of the ProfileData we intend to update to check its
  2348       // type because we're right after it and we don't known its
  2349       // length
  2350       Label do_profile;
  2351       //cmpb(Address(_bcp_register, 0), Bytecodes::_invokedynamic);
  2352       //jcc(Assembler::equal, do_profile);
  2353       lb(AT, _bcp_register, 0);
  2354       daddiu(AT, AT, -1 * Bytecodes::_invokedynamic);
  2355       beq(AT, R0, do_profile);
  2356       nop();
  2358       //cmpb(Address(_bcp_register, 0), Bytecodes::_invokehandle);
  2359       //jcc(Assembler::equal, do_profile);
  2360       lb(AT, _bcp_register, 0);
  2361       daddiu(AT, AT, -1 * Bytecodes::_invokehandle);
  2362       beq(AT, R0, do_profile);
  2363       nop();
  2365       get_method(tmp);
  2366       //cmpb(Address(tmp, Method::intrinsic_id_offset_in_bytes()), vmIntrinsics::_compiledLambdaForm);
  2367       //jcc(Assembler::notEqual, profile_continue);
  2368       lb(tmp, tmp, Method::intrinsic_id_offset_in_bytes());
  2369       li(AT, vmIntrinsics::_compiledLambdaForm);
  2370       bne(tmp, AT, profile_continue);
  2371       nop();
  2373       bind(do_profile);
  2376     Address mdo_ret_addr(mdp, -in_bytes(ReturnTypeEntry::size()));
  2377     //mov(tmp, ret);
  2378     daddu(tmp, ret, R0);
  2379     profile_obj_type(tmp, mdo_ret_addr);
  2381     bind(profile_continue);
  2385 void InterpreterMacroAssembler::profile_parameters_type(Register mdp, Register tmp1, Register tmp2) {
  2386   guarantee(T9 == tmp1, "You are reqired to use T9 as the index register for MIPS !");
  2388   if (ProfileInterpreter && MethodData::profile_parameters()) {
  2389     Label profile_continue, done;
  2391     test_method_data_pointer(mdp, profile_continue);
  2393     // Load the offset of the area within the MDO used for
  2394     // parameters. If it's negative we're not profiling any parameters
  2395     //movl(tmp1, Address(mdp, in_bytes(MethodData::parameters_type_data_di_offset()) - in_bytes(MethodData::data_offset())));
  2396     //testl(tmp1, tmp1);
  2397     //jcc(Assembler::negative, profile_continue);
  2398     lw(tmp1, mdp, in_bytes(MethodData::parameters_type_data_di_offset()) - in_bytes(MethodData::data_offset()));
  2399     bltz(tmp1, profile_continue);
  2400     nop();
  2402     // Compute a pointer to the area for parameters from the offset
  2403     // and move the pointer to the slot for the last
  2404     // parameters. Collect profiling from last parameter down.
  2405     // mdo start + parameters offset + array length - 1
  2406     //addptr(mdp, tmp1);
  2407     //movptr(tmp1, Address(mdp, ArrayData::array_len_offset()));
  2408     daddu(mdp, mdp, tmp1);
  2409     ld(tmp1, mdp, in_bytes(ArrayData::array_len_offset()));
  2410     decrement(tmp1, TypeStackSlotEntries::per_arg_count());
  2413     Label loop;
  2414     bind(loop);
  2416     int off_base = in_bytes(ParametersTypeData::stack_slot_offset(0));
  2417     int type_base = in_bytes(ParametersTypeData::type_offset(0));
  2418     Address::ScaleFactor per_arg_scale = Address::times(DataLayout::cell_size);
  2419     //Address arg_off(mdp, tmp1, per_arg_scale, off_base);
  2420     Address arg_type(mdp, tmp1, per_arg_scale, type_base);
  2422     // load offset on the stack from the slot for this parameter
  2423     //movptr(tmp2, arg_off);
  2424     dsll(AT, tmp1, per_arg_scale);
  2425     daddu(AT, AT, mdp);
  2426     ld(tmp2, AT, off_base);
  2428     //negptr(tmp2);
  2429     subu(tmp2, R0, tmp2);
  2431     // read the parameter from the local area
  2432     //movptr(tmp2, Address(_locals_register, tmp2, Interpreter::stackElementScale()));
  2433     dsll(AT, tmp2, Interpreter::stackElementScale());
  2434     daddu(AT, AT, _locals_register);
  2435     ld(tmp2, AT, 0);
  2437     // profile the parameter
  2438     profile_obj_type(tmp2, arg_type);
  2440     // go to next parameter
  2441     decrement(tmp1, TypeStackSlotEntries::per_arg_count());
  2442     //jcc(Assembler::positive, loop);
  2443     bgtz(tmp1, loop);
  2444     nop();
  2446     bind(profile_continue);
  2450 void InterpreterMacroAssembler::verify_oop(Register reg, TosState state) {
  2451   if (state == atos) {
  2452     MacroAssembler::verify_oop(reg);
  2456 void InterpreterMacroAssembler::verify_FPU(int stack_depth, TosState state) {
  2457   // only if +VerifyFPU  && (state == ftos || state == dtos)
  2458   // For now, do nothing.
  2460 #endif // !CC_INTERP
  2463 //FIXME, aoqi:see UltraViolet
  2464 void InterpreterMacroAssembler::notify_method_entry() {
  2465   // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to
  2466   // track stack depth.  If it is possible to enter interp_only_mode we add
  2467   // the code to check if the event should be sent.
  2468   //Register tempreg = Rscratch0;
  2469   Register tempreg = T0;
  2470   if (JvmtiExport::can_post_interpreter_events()) {
  2471     Label L;
  2472     //movl(rdx, Address(r15_thread, JavaThread::interp_only_mode_offset()));
  2473     //testl(rdx, rdx);
  2474     //jcc(Assembler::zero, L);
  2475     //lw(tempreg, in_bytes(JavaThread::interp_only_mode_offset()), Rthread);
  2476     get_thread(AT);
  2477     lw(tempreg, AT, in_bytes(JavaThread::interp_only_mode_offset()));
  2478     beq(tempreg, R0, L);
  2479     delayed()->nop();
  2480     call_VM(noreg, CAST_FROM_FN_PTR(address,
  2481                                     InterpreterRuntime::post_method_entry));
  2482     bind(L);
  2486     //SkipIfEqual skip_if(this, tempreg, R0, &DTraceMethodProbes, 1);
  2487     SkipIfEqual skip_if(this, &DTraceMethodProbes, 0);
  2488     call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry),
  2489 		 //Rthread,
  2490 		 AT,
  2491 		 //Rmethod);
  2492 		 S3);
  2497 //FIXME, aoqi:see UltraViolet
  2498 void InterpreterMacroAssembler::notify_method_exit(
  2499     //TosState state, NotifyMethodExitMode mode) {
  2500     bool is_native_method, TosState state, NotifyMethodExitMode mode) {
  2501   // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to
  2502   // track stack depth.  If it is possible to enter interp_only_mode we add
  2503   // the code to check if the event should be sent.
  2504   //Register tempreg = Rscratch0;
  2505   Register tempreg = T0;
  2506   if (mode == NotifyJVMTI && JvmtiExport::can_post_interpreter_events()) {
  2507     Label skip;
  2508     //lw(tempreg, in_bytes(JavaThread::interp_only_mode_offset()), Rthread);
  2509     get_thread(AT);
  2510     lw(tempreg, AT, in_bytes(JavaThread::interp_only_mode_offset()));
  2511     beq(tempreg, R0, skip);
  2512     delayed()->nop();
  2513     // Note: frame::interpreter_frame_result has a dependency on how the
  2514     // method result is saved across the call to post_method_exit. If this
  2515     // is changed then the interpreter_frame_result implementation will
  2516     // need to be updated too.
  2518     // For c++ interpreter the result is always stored at a known location in the frame
  2519     // template interpreter will leave it on the top of the stack.
  2520     save_return_value(state, is_native_method);
  2521     call_VM(noreg,
  2522             CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_exit));
  2523     restore_return_value(state, is_native_method);
  2524     bind(skip);
  2528     // Dtrace notification
  2529     //SkipIfEqual skip_if(this, tempreg, R0, &DTraceMethodProbes, equal);
  2530     SkipIfEqual skip_if(this, &DTraceMethodProbes, 0);
  2531     save_return_value(state, is_native_method);
  2532     call_VM_leaf(
  2533 		 CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit),
  2534 		 //Rthread, Rmethod);
  2535 		 AT, S3);
  2536     restore_return_value(state, is_native_method);
  2540 //FIXME  yyq native return 64 bits
  2541 void InterpreterMacroAssembler::save_return_value(
  2542     TosState state, bool is_native_call) {
  2543   if (is_native_call) {
  2544     // save any potential method result value
  2545     //sd(V0, frame::interpreter_frame_l_scratch_offset * wordSize, FP);
  2546     //sdc1(F0, frame::interpreter_frame_d_scratch_offset * wordSize, FP);
  2547     sw(V0, FP, (-9) * wordSize);
  2548     swc1(F0, FP, (-10) * wordSize);
  2550 //    sd(V0, FP, (-9) * wordSize);
  2551 //    sdc1(F0, FP, (-10) * wordSize);
  2552   } else {
  2553     push(state);
  2557 //FIXME  yyq native return 64 bits
  2558 void InterpreterMacroAssembler::restore_return_value(
  2559     TosState state, bool is_native_call) {
  2560   if (is_native_call) {
  2561     // Restore any method result value
  2562     //ld(V0, frame::interpreter_frame_l_scratch_offset * wordSize, FP);
  2563     //ldc1(F0, frame::interpreter_frame_d_scratch_offset * wordSize, FP);
  2564     lw(V0, FP, (-9) * wordSize);
  2565     lwc1(F0, FP, (-10) * wordSize);
  2566   } else {
  2567     pop(state);

mercurial