src/cpu/mips/vm/interp_masm_mips_64.cpp

Sat, 07 May 2016 07:38:03 -0400

author
Jin
date
Sat, 07 May 2016 07:38:03 -0400
changeset 4
87ed97bc0867
parent 1
2d8a650513c2
child 14
92759d406e78
permissions
-rw-r--r--

[Interpreter] ProfileInterpreter: fix unaligned lwu

When running compress in debug mode,

/mnt/j2sdk-image/bin/java \
-Xmx68M -Xms68M \
-XX:CompileCommand="compileonly,spec/benchmarks/compress/Decompressor\$SuffixTable.of1" \
-XX:+PrintCompilation \
-XX:-CICompileNatives \
-XX:+ProfileInterpreter \
-XX:-UseTLAB \
-XX:+UseLoopCounter \
-XX:+UseOnStackReplacement \
-XX:+UseSerialGC \
-jar SPECjvm2008.jar -ikv -coe -ict -bt 1 \
compress

Though no method is compiled, the unaligned counter reaches 779990 /s.

This error doesn't exist in product version.

Effect:
- compress + debug + +ProfileInterpreter: 0 unaligned access

     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 #ifndef CC_INTERP
    52 void InterpreterMacroAssembler::call_VM_leaf_base(address entry_point,
    53                                                   int number_of_arguments) {
    54     // interpreter specific
    55     //
    56     // Note: No need to save/restore bcp & locals (r13 & r14) pointer
    57     //       since these are callee saved registers and no blocking/
    58     //       GC can happen in leaf calls.
    59     // Further Note: DO NOT save/restore bcp/locals. If a caller has
    60     // already saved them so that it can use esi/edi as temporaries
    61     // then a save/restore here will DESTROY the copy the caller
    62     // saved! There used to be a save_bcp() that only happened in
    63     // the ASSERT path (no restore_bcp). Which caused bizarre failures
    64     // when jvm built with ASSERTs.
    65     /*
    66   #ifdef ASSERT
    67   {
    68   Label L;
    69   cmpptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD);
    70   jcc(Assembler::equal, L);
    71   stop("InterpreterMacroAssembler::call_VM_leaf_base:"
    72   " last_sp != NULL");
    73   bind(L);
    74   }
    75   #endif
    76   // super call
    77   MacroAssembler::call_VM_leaf_base(entry_point, number_of_arguments);
    78   // interpreter specific
    79   // Used to ASSERT that r13/r14 were equal to frame's bcp/locals
    80   // but since they may not have been saved (and we don't want to
    81   // save thme here (see note above) the assert is invalid.
    82      */
    83   #ifdef ASSERT
    84   save_bcp();
    85   { Label L;
    86     //cmpl(Address(ebp, frame::interpreter_frame_last_sp_offset * wordSize), 
    87     //NULL_WORD);
    88     ld(AT,FP,frame::interpreter_frame_last_sp_offset * wordSize); 
    89     // jcc(Assembler::equal, L);
    90     beq(AT,R0,L);  
    91     delayed()->nop(); 
    92     stop("InterpreterMacroAssembler::call_VM_leaf_base: last_sp != NULL");
    93     bind(L);
    94   }
    95   #endif
    96   // super call
    97   MacroAssembler::call_VM_leaf_base(entry_point, number_of_arguments);
    98   // interpreter specific
    99   #ifdef ASSERT
   100   { Label L;
   101     ld(T3, FP, frame::interpreter_frame_bcx_offset * wordSize);
   102     Assembler::beq(BCP, T3, L);
   103     delayed()->nop();
   104     stop("InterpreterMacroAssembler::call_VM_leaf_base: esi not callee saved?");
   105     bind(L);
   106   }
   107   { Label L;
   108     ld(T3, FP, frame::interpreter_frame_locals_offset * wordSize);
   109     Assembler::beq(LVP, T3, L);
   110     delayed()->nop();
   111     stop("InterpreterMacroAssembler::call_VM_leaf_base: edi not callee saved?");
   112     bind(L);
   113   }
   114   #endif
   115   }
   117 void InterpreterMacroAssembler::call_VM_base(Register oop_result,
   118                                              Register java_thread,
   119                                              Register last_java_sp,
   120                                              address  entry_point,
   121                                              int      number_of_arguments,
   122                                              bool     check_exceptions) {
   123 #if 0
   124 	// interpreter specific
   125   //
   126   // Note: Could avoid restoring locals ptr (callee saved) - however doesn't
   127   //       really make a difference for these runtime calls, since they are
   128   //       slow anyway. Btw., bcp must be saved/restored since it may change
   129   //       due to GC.
   130   // assert(java_thread == noreg , "not expecting a precomputed java thread");
   131   save_bcp();
   132 #ifdef ASSERT
   133   {
   134     Label L;
   135     cmpptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD);
   136     jcc(Assembler::equal, L);
   137     stop("InterpreterMacroAssembler::call_VM_leaf_base:"
   138          " last_sp != NULL");
   139     bind(L);
   140   }
   141 #endif /* ASSERT */
   142   // super call
   143   MacroAssembler::call_VM_base(oop_result, noreg, last_java_sp,
   144                                entry_point, number_of_arguments,
   145                                check_exceptions);
   146   // interpreter specific
   147   restore_bcp();
   148   restore_locals();
   149 #endif
   150 #ifdef ASSERT
   151 	{ Label L;
   152 		//  cmpl(Address(ebp, frame::interpreter_frame_last_sp_offset * wordSize),
   153 		//  NULL_WORD);
   154 		// jcc(Assembler::equal, L);
   155 		ld(AT, FP, frame::interpreter_frame_last_sp_offset * wordSize); 
   156 		beq(AT, R0, L); 
   157 		delayed()->nop(); 
   158 		stop("InterpreterMacroAssembler::call_VM_base: last_sp != NULL");
   159 		bind(L);
   160 	}
   161 #endif /* ASSERT */
   162 	// interpreter specific
   163 	//
   164 	// Note: Could avoid restoring locals ptr (callee saved) - however doesn't
   165 	//       really make a difference for these runtime calls, since they are
   166 	//       slow anyway. Btw., bcp must be saved/restored since it may change
   167 	//       due to GC.
   168 	assert(java_thread == noreg , "not expecting a precomputed java thread");
   169 	save_bcp();
   170 	// super call
   171 	MacroAssembler::call_VM_base(oop_result, java_thread, last_java_sp, entry_point, number_of_arguments, check_exceptions);
   172 	restore_bcp();
   173 	restore_locals();
   174 }
   177 void InterpreterMacroAssembler::check_and_handle_popframe(Register java_thread) {
   178   if (JvmtiExport::can_pop_frame()) {
   179     Label L;
   180     // Initiate popframe handling only if it is not already being
   181     // processed.  If the flag has the popframe_processing bit set, it
   182     // means that this code is called *during* popframe handling - we
   183     // don't want to reenter.
   184     // This method is only called just after the call into the vm in
   185     // call_VM_base, so the arg registers are available.
   186     /*
   187 		movl(c_rarg0, Address(r15_thread, JavaThread::popframe_condition_offset()));
   188     testl(c_rarg0, JavaThread::popframe_pending_bit);
   189     jcc(Assembler::zero, L);
   190     testl(c_rarg0, JavaThread::popframe_processing_bit);
   191     jcc(Assembler::notZero, L);
   192     // Call Interpreter::remove_activation_preserving_args_entry() to get the
   193     // address of the same-named entrypoint in the generated interpreter code.
   194     call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_preserving_args_entry));
   195     jmp(rax);
   196     bind(L);
   197 		*/
   198 		Register pop_cond = java_thread;
   199 		// Not clear if any other register is available...
   200 		lw(pop_cond, java_thread, in_bytes(JavaThread::popframe_condition_offset()));
   201 		andi(AT, pop_cond, JavaThread::popframe_pending_bit);
   202 		beq(AT, R0, L);		
   203 		delayed()->andi(AT, pop_cond, JavaThread::popframe_processing_bit);		
   204 		bne(AT, R0, L);
   205 		delayed()->nop();
   206 		call( CAST_FROM_FN_PTR(address, Interpreter::remove_activation_preserving_args_entry), relocInfo::runtime_call_type);
   207 		delayed()->nop();
   208 		jr(V0);
   209 		delayed()->nop();
   210 		bind(L);
   211 		get_thread(java_thread);
   212   }
   213 }
   216 void InterpreterMacroAssembler::load_earlyret_value(TosState state) {
   217 	//T8, thread
   218 	get_thread(T8);
   219 	ld_ptr(T8, T8,in_bytes(JavaThread::jvmti_thread_state_offset())); 
   220 	/* 
   221 	   const Address tos_addr (ecx, JvmtiThreadState::earlyret_tos_offset());
   222 	   const Address oop_addr (ecx, JvmtiThreadState::earlyret_oop_offset());
   223 	   const Address val_addr (ecx, JvmtiThreadState::earlyret_value_offset());
   224 	   const Address val_addr1(ecx, JvmtiThreadState::earlyret_value_offset()
   225 	   + in_ByteSize(wordSize));
   226 	   */ 
   227 	const Address tos_addr (T8, in_bytes(JvmtiThreadState::earlyret_tos_offset()));
   228 	const Address oop_addr (T8, in_bytes(JvmtiThreadState::earlyret_oop_offset()));
   229 	const Address val_addr (T8, in_bytes(JvmtiThreadState::earlyret_value_offset()));
   230 	//V0, oop_addr,V1,val_addr 
   231 	switch (state) {
   232 		case atos: 
   233 			//movl(eax, oop_addr);
   234 			ld_ptr(V0, oop_addr);
   235 			// movl(oop_addr, NULL_WORD);
   236 			st_ptr(R0, oop_addr);  
   237 			//verify_oop(eax, state);       break;
   238 			verify_oop(V0, state);               
   239 			break;
   240 		case ltos: 
   241 			// movl(edx, val_addr1);               // fall through
   242 			ld_ptr(V0, val_addr);               // fall through
   243 			break;
   244 		case btos:                                     // fall through
   245 		case ctos:                                     // fall through
   246 		case stos:                                     // fall through
   247 		case itos: 
   248 			//	movl(eax, val_addr);               
   249 			lw(V0, val_addr);               
   250 			break;
   251 			//FIXME ,I hava no idear fld store to where @jerome 
   252 		case ftos: 
   253 			//fld_s(val_addr);                       
   254 			lwc1(F0,T8, in_bytes(JvmtiThreadState::earlyret_value_offset()));	
   255 			break;
   256 		case dtos: 
   257 			//fld_d(val_addr);                       
   258 			ldc1(F0,T8, in_bytes(JvmtiThreadState::earlyret_value_offset()));	
   259 			break;
   260 		case vtos: /* nothing to do */                    break;
   261 		default  : ShouldNotReachHere();
   262 	}
   263 	// Clean up tos value in the thread object
   264 	// movl(tos_addr,  (int) ilgl);
   265 	//addi(AT,R0,(int)ilgl); 
   266 	move(AT, (int)ilgl); 
   267 	sw(AT, tos_addr);
   268 	// movl(val_addr,  NULL_WORD);
   269 	sw(R0,T8, in_bytes(JvmtiThreadState::earlyret_value_offset())); 
   270 }
   273 void InterpreterMacroAssembler::check_and_handle_earlyret(Register java_thread) {
   274   if (JvmtiExport::can_force_early_return()) {
   275     Label L;
   276 		Register tmp = T9;
   278     //movptr(c_rarg0, Address(r15_thread, JavaThread::jvmti_thread_state_offset()));
   279 		ld_ptr(AT,java_thread, in_bytes(JavaThread::jvmti_thread_state_offset())); 
   280     //testptr(c_rarg0, c_rarg0);
   281     //jcc(Assembler::zero, L); // if (thread->jvmti_thread_state() == NULL) exit;
   282 		beq(AT,R0,L);
   283 		delayed()->nop(); 
   285     // Initiate earlyret handling only if it is not already being processed.
   286     // If the flag has the earlyret_processing bit set, it means that this code
   287     // is called *during* earlyret handling - we don't want to reenter.
   288     //movl(c_rarg0, Address(c_rarg0, JvmtiThreadState::earlyret_state_offset()));
   289 		lw(AT, AT, in_bytes(JvmtiThreadState::earlyret_state_offset()));
   290     //cmpl(c_rarg0, JvmtiThreadState::earlyret_pending);
   291     //jcc(Assembler::notEqual, L);
   292 		move(tmp, JvmtiThreadState::earlyret_pending); 
   293 		bne(tmp, AT, L); 
   294 		delayed()->nop(); 
   295 		get_thread(java_thread);
   297     // Call Interpreter::remove_activation_early_entry() to get the address of the
   298     // same-named entrypoint in the generated interpreter code.
   299     //movptr(c_rarg0, Address(r15_thread, JavaThread::jvmti_thread_state_offset()));
   300 		ld_ptr(tmp,java_thread, in_bytes(JavaThread::jvmti_thread_state_offset())); 
   301     //movl(c_rarg0, Address(c_rarg0, JvmtiThreadState::earlyret_tos_offset()));
   302 		lw(AT,tmp, in_bytes(JvmtiThreadState::earlyret_tos_offset()));
   303 		move(A0, AT); 
   304 		//push(AT); 
   305 		call(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_early_entry),  
   306 				relocInfo::runtime_call_type);
   307     //call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_early_entry), c_rarg0);
   308     //jmp(rax);
   309     //bind(L);
   310 		jr(V0); 
   311 		delayed()->nop(); 
   312 		bind(L);
   313 		get_thread(java_thread);
   314   }
   315 }
   318 void InterpreterMacroAssembler::get_unsigned_2_byte_index_at_bcp(
   319 							  Register reg,
   320 							  int bcp_offset) {
   321 	assert(bcp_offset >= 0, "bcp is still pointing to start of bytecode");
   322 	load_two_bytes_from_at_bcp(reg, AT, bcp_offset);
   323 	hswap(reg);
   324 }
   327 void InterpreterMacroAssembler::get_cache_and_index_at_bcp(Register cache,
   328                                                            Register index,
   329                                                            int bcp_offset,
   330                                                            size_t index_size) {
   331   assert_different_registers(cache, index);
   332   get_cache_index_at_bcp(index, bcp_offset, index_size);
   333   ld(cache, FP, frame::interpreter_frame_cache_offset * wordSize);
   334   assert(sizeof(ConstantPoolCacheEntry) == 4 * wordSize, "adjust code below");
   335   assert(exact_log2(in_words(ConstantPoolCacheEntry::size())) == 2, "else change next line");
   336   shl(index, 2);
   337 }
   339 void InterpreterMacroAssembler::get_cache_and_index_and_bytecode_at_bcp(Register cache,
   340                                                                          Register index,
   341                                                                          Register bytecode,
   342                                                                          int byte_no,
   343                                                                          int bcp_offset,
   344                                                                         size_t index_size) {
   345    get_cache_and_index_at_bcp(cache, index, bcp_offset, index_size);
   346    // We use a 32-bit load here since the layout of 64-bit words on
   347    // little-endian machines allow us that.
   348    dsll(AT, index, Address::times_ptr);
   349    dadd(AT, cache, AT);
   350    lw(bytecode, AT, in_bytes(ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::indices_offset()));
   352    const int shift_count = (1 + byte_no) * BitsPerByte;
   353    assert((byte_no == TemplateTable::f1_byte && shift_count == ConstantPoolCacheEntry::bytecode_1_shift) ||
   354           (byte_no == TemplateTable::f2_byte && shift_count == ConstantPoolCacheEntry::bytecode_2_shift),
   355           "correct shift count");
   356    dsrl(bytecode, bytecode, shift_count);
   357    assert(ConstantPoolCacheEntry::bytecode_1_mask == ConstantPoolCacheEntry::bytecode_2_mask, "common mask");
   358    move(AT, ConstantPoolCacheEntry::bytecode_1_mask);
   359    andr(bytecode, bytecode, AT);
   360  }
   362 void InterpreterMacroAssembler::get_cache_entry_pointer_at_bcp(Register cache,
   363 								Register tmp,
   364 								int bcp_offset, size_t index_size) {
   365 	assert(bcp_offset > 0, "bcp is still pointing to start of bytecode");
   366 	assert(cache != tmp, "must use different register");
   368 	get_cache_index_at_bcp(tmp, bcp_offset, index_size);
   369 	assert(sizeof(ConstantPoolCacheEntry) == 4 * wordSize, "adjust code below");
   370 	// convert from field index to ConstantPoolCacheEntry index
   371 	// and from word offset to byte offset
   372 	dsll(tmp, tmp, 2+LogBytesPerWord);
   373 	ld(cache, FP, frame::interpreter_frame_cache_offset * wordSize);
   374 	// skip past the header
   375 	daddi(cache, cache, in_bytes(ConstantPoolCache::base_offset()));
   376 	dadd(cache, cache, AT);
   377 }
   379 void InterpreterMacroAssembler::get_cache_index_at_bcp(Register index,
   380                                                        int bcp_offset,
   381                                                        size_t index_size) {
   382   assert(bcp_offset > 0, "bcp is still pointing to start of bytecode");
   383   if (index_size == sizeof(u2)) {
   384     load_two_bytes_from_at_bcp(index, AT, bcp_offset);
   385   } else if (index_size == sizeof(u4)) {
   386     assert(EnableInvokeDynamic, "giant index used only for JSR 292");
   387     lwu(index, BCP, bcp_offset);
   388     // Check if the secondary index definition is still ~x, otherwise
   389     // we have to change the following assembler code to calculate the
   390     // plain index.
   391     assert(ConstantPool::decode_invokedynamic_index(~123) == 123, "else change next line");
   392     nor(index, index, R0);
   393     sll(index, index, 0);
   394   } else if (index_size == sizeof(u1)) {
   395     lbu(index, BCP, bcp_offset);
   396   } else {
   397     ShouldNotReachHere();
   398   }
   399 }
   401 void InterpreterMacroAssembler::get_method_counters(Register method,
   402                                                     Register mcs, Label& skip) {
   403   Label has_counters;
   404   ld(mcs, method, in_bytes(Method::method_counters_offset()));
   405   bne(mcs, R0, has_counters);
   406   nop();
   407   call_VM(noreg, CAST_FROM_FN_PTR(address,
   408           InterpreterRuntime::build_method_counters), method);
   409   ld(mcs, method, in_bytes(Method::method_counters_offset()));
   410   beq(mcs, R0, skip);   // No MethodCounters allocated, OutOfMemory
   411   nop();
   412   bind(has_counters);
   413 }
   415  // Load object from cpool->resolved_references(index)
   416  void InterpreterMacroAssembler::load_resolved_reference_at_index(
   417                                             Register result, Register index) {
   418    assert_different_registers(result, index);
   419    // convert from field index to resolved_references() index and from
   420    // word index to byte offset. Since this is a java object, it can be compressed
   421    Register tmp = index;  // reuse
   422    shl(tmp, LogBytesPerHeapOop);
   424    get_constant_pool(result);
   425    // load pointer for resolved_references[] objArray
   426    ld(result, result, ConstantPool::resolved_references_offset_in_bytes());
   427    // JNIHandles::resolve(obj);
   428    // movptr(result, Address(result, 0));
   429    ld(result, result, 0); //? is needed?
   430    // Add in the index
   431    dadd(result, result, tmp);
   432    load_heap_oop(result, Address(result, arrayOopDesc::base_offset_in_bytes(T_OBJECT)));
   433  }
   435 // Resets LVP to locals.  Register sub_klass cannot be any of the above.
   436 void InterpreterMacroAssembler::gen_subtype_check( Register Rsup_klass, Register Rsub_klass, Label &ok_is_subtype ) {
   437   assert( Rsub_klass != Rsup_klass, "Rsup_klass holds superklass" );
   438   assert( Rsub_klass != T1, "T1 holds 2ndary super array length" );
   439   assert( Rsub_klass != T0, "T0 holds 2ndary super array scan ptr" );
   440  // Profile the not-null value's klass.
   441  // [20130904] Fu: Here T9 and T1 are used as temporary registers.
   442   profile_typecheck(T9, Rsub_klass, T1); // blows rcx, reloads rdi
   444 // Do the check.
   445   check_klass_subtype(Rsub_klass, Rsup_klass, T1, ok_is_subtype); // blows rcx
   447 // Profile the failure of the check.
   448   profile_typecheck_failed(T9); // blows rcx
   449 }
   453 // Java Expression Stack
   455 void InterpreterMacroAssembler::pop_ptr(Register r) {
   456   pop(r);
   457   //if (TaggedStackInterpreter) addptr(rsp, 1 * wordSize);
   458 //	if (TaggedStackInterpreter) addi(SP,SP, 1 * wordSize);
   459 }
   460 /*
   461 void InterpreterMacroAssembler::pop_ptr(Register r, Register tag) {
   462   pop(r);
   463  // if (TaggedStackInterpreter) pop(tag);
   464 }*/
   466 void InterpreterMacroAssembler::pop_i(Register r) {
   467   // XXX can't use pop currently, upper half non clean
   468   //movl(r, Address(rsp, 0));
   469   //addptr(rsp, wordSize);
   470   lw(r, SP, 0);
   471   daddi(SP, SP, 8);
   472 	//if (TaggedStackInterpreter) addptr(rsp, 1 * wordSize);
   473 //	if (TaggedStackInterpreter) addi(SP,SP, 1 * wordSize);
   474 }
   475 /*
   476 void InterpreterMacroAssembler::pop_l(Register r) {
   477   //movq(r, Address(rsp, 0));
   478   //addptr(rsp, 2 * Interpreter::stackElementSize());
   479 	//FIXME, this directly call assembler. by aoqi 
   480 	ld(r, SP, 0);
   481 	addi(SP, SP, 8);
   482 	if (TaggedStackInterpreter) addi(SP,SP, 2 * wordSize);
   483 }
   484 */
   485 //FIXME How many registers do push_l & pop_l use? aoqi
   486 void InterpreterMacroAssembler::pop_l(Register lo, Register hi) {
   487   pop(lo); 
   488   //if (TaggedStackInterpreter) daddi(SP,SP, 1 * wordSize);       
   489   pop(hi); 
   490   //if (TaggedStackInterpreter) daddi(SP,SP, 1 * wordSize);
   491 }
   493 void InterpreterMacroAssembler::pop_f() {
   494   lwc1(FSF, SP, 0); 
   495   daddi(SP, SP, 1 * wordSize);
   496 //  if (TaggedStackInterpreter) addi(SP,SP, 1 * wordSize);
   497 }
   499 void InterpreterMacroAssembler::pop_d() {
   500   pop_dtos_to_esp();
   501   ldc1(FSF, SP, 0); 
   502   daddi(SP, SP, 2 * wordSize);
   503 }
   505 // Pop the top of the java expression stack to execution stack (which
   506 // happens to be the same place).
   507 //FIXME ,I hava no idea which register to use
   508 void InterpreterMacroAssembler::pop_dtos_to_esp() {
   509 /*	if (TaggedStackInterpreter) {
   510 		// Pop double value into scratch registers
   511 		//  popl(eax);
   512 		pop(V0); 
   513 		//addl(esp, 1* wordSize);
   514 		addi(SP,SP, 1* wordSize);
   515 		//popl(edx);
   516 		pop(V1);
   517 		//addl(esp, 1* wordSize);
   518 		addi(SP,SP, 1* wordSize);
   519 		// pushl(edx);
   520 		push(V1);
   521 		//pushl(eax);
   522 		push(V0);
   523 	}*/
   524 }
   526 void InterpreterMacroAssembler::pop_ftos_to_esp() {
   527 /*  if (TaggedStackInterpreter) {
   528 		//  popl(eax);
   529 		pop(V0);
   530 		//addl(esp, 1 * wordSize);
   531 		addi(SP,SP, 1 * wordSize);
   532 		// pushl(eax);  // ftos is at esp
   533 		push(V0);  // ftos is at esp
   534 	}*/
   535 }
   537 void InterpreterMacroAssembler::push_ptr(Register r) {
   538   //if (TaggedStackInterpreter) push(frame::TagReference);
   539 /*	if (TaggedStackInterpreter) {
   540 		move(AT, frame::TagReference); 
   541 		push(AT);
   542 	}//pushl(r);*/
   543   push(r);
   544 }
   545 /*
   546 void InterpreterMacroAssembler::push_ptr(Register r, Register tag) {
   547   //if (TaggedStackInterpreter) push(tag);
   548 	if (TaggedStackInterpreter){
   549 		move(AT, tag);
   550 		push(AT);  // tag first
   551 	} 
   552   push(r);
   553 }*/
   555 void InterpreterMacroAssembler::push_i(Register r) {
   556   //if (TaggedStackInterpreter) push(frame::TagValue);
   557 /*	if (TaggedStackInterpreter) {
   558 		move(AT, frame::TagValue);	
   559 		push(AT);
   560 	}*/
   561   push(r);
   562 }
   563 /*
   564 void InterpreterMacroAssembler::push_l(Register r) {
   565   if (TaggedStackInterpreter) {
   566     //push(frame::TagValue);
   567     //subptr(rsp, 1 * wordSize);
   568     //push(frame::TagValue);
   569     //subptr(rsp, 1 * wordSize);
   570 		move(AT, frame::TagValue);
   571 		push(AT);
   572   } else {
   573     addi(SP, SP, (-2) * wordSize);
   574   }
   575   //movq(Address(rsp, 0), r);
   576 	//FIXME, same as pop_l
   577 	sd(r, SP, 0);
   578 }
   579 */
   580 //FIXME How many registers do push_l & pop_l use? aoqi
   581 void InterpreterMacroAssembler::push_l(Register lo, Register hi) {
   582   //if (TaggedStackInterpreter) pushl(frame::TagValue);
   583   /*if (TaggedStackInterpreter) {
   584     move(AT, frame::TagValue);
   585 		push(AT);
   586 	}*/
   587 	//pushl(hi);
   588 	push(hi);
   589 	//if (TaggedStackInterpreter) pushl(frame::TagValue);
   590 /*	if (TaggedStackInterpreter) {
   591 		move(AT, frame::TagValue);
   592 		push(AT);
   593 	}*/
   594 	//pushl(lo);
   595 	push(lo);
   596 }
   597 //void InterpreterMacroAssembler::push_f(XMMRegister r) {
   598 void InterpreterMacroAssembler::push_f() {
   599  /* if (TaggedStackInterpreter) {
   600     move(AT, frame::TagValue);
   601     push(AT);
   602   }// Do not schedule for no AGI! Never write beyond esp!*/
   603   daddi(SP, SP, (-1) * wordSize);
   604   swc1(FSF, SP, 0 * wordSize);
   605   sw(R0, SP,  4);
   606 }
   608 //FIXME. aoqi
   609 void InterpreterMacroAssembler::push_d(FloatRegister r) {
   610  /* if (TaggedStackInterpreter) {
   611     move(AT, frame::TagValue); 
   612     push(AT);
   613     addi(SP, SP, (-3) * wordSize);
   614     swc1(FSF, SP, 0 * wordSize);
   615     swc1(SSF, SP, 1 * wordSize);
   617     lwc1(r, SP, 1*wordSize);
   618     swc1(r, SP, 2*wordSize);
   619     move(AT, frame::TagValue);
   620     sw(AT, SP, 1*wordSize);
   621   } else {*/
   622     daddi(SP, SP, (-2) * wordSize);
   623     sdc1(FSF, SP, 0 * wordSize);
   624     sdc1(SSF, SP, 1 * wordSize);
   625  // }
   626 }
   628 void InterpreterMacroAssembler::pop(TosState state) {
   629   switch (state) {
   630     case atos: pop(FSR);      break; 
   631     case btos:
   632     case ctos:
   633     case stos:
   634     case itos: 
   635 	       pop_i(FSR);	
   636 	       break;
   637     case ltos: 
   638 	       pop_l(FSR, SSR);
   639 	       break;
   640     case ftos: pop_f();      						break;
   641     case dtos: pop_d();      						break; 
   642     case vtos: /* nothing to do */      break;
   643     default:   ShouldNotReachHere();
   644   }
   645   verify_oop(V0, state);
   646 }
   648 //FSR=V0,SSR=V1
   649 void InterpreterMacroAssembler::push(TosState state) {
   650   verify_oop(V0, state);
   651   switch (state) {
   652     case atos:   push(FSR);    break;
   653     case btos:						     // fall through
   654     case ctos:						     // fall through
   655     case stos:						     // fall through
   656     case itos:
   657 		 push_i(FSR);
   658 		 break;
   659     case ltos:
   660     //FIXME aoqi.
   661 		 daddi(SP, SP, (-2) * wordSize);
   662 		 //sd(SSR, SP, 1 * wordSize);
   663 		 sd(R0, SP, 1 * wordSize);
   664 		 sd(FSR, SP, 0 * wordSize);
   665 		 break;
   666     case ftos: 
   667 		 push_f(); 
   668 		 break;
   669     case dtos: 
   670 		 //FIXME, I have no idea which register to use 
   671 		 push_d(FSF); 
   672 		 break;
   673     case vtos: /* nothing to do */                            break;
   674     default  : ShouldNotReachHere();
   675   }
   676 }
   681 // Tagged stack helpers for swap and dup
   682 void InterpreterMacroAssembler::load_ptr(int n, Register val) {
   683   ld(val, SP, Interpreter::expr_offset_in_bytes(n));
   684   /*if (TaggedStackInterpreter) {
   685     ld(tag, SP, Interpreter::expr_tag_offset_in_bytes(n));
   686   }*/
   687 }
   689 void InterpreterMacroAssembler::store_ptr(int n, Register val) {
   690   sd(val, SP, Interpreter::expr_offset_in_bytes(n));
   691  /* if (TaggedStackInterpreter) {
   692     //movptr(Address(rsp, Interpreter::expr_tag_offset_in_bytes(n)), tag);
   693     sd(tag, SP, Interpreter::expr_tag_offset_in_bytes(n));
   694   }*/
   695 }
   697 /*
   698 // Tagged local support
   699 //LVP=S7, local variable pointer register , FIXME
   700 void InterpreterMacroAssembler::tag_local(frame::Tag tag, int n) {
   701   if (TaggedStackInterpreter) {
   702     if (tag == frame::TagCategory2) {
   703       //movptr(Address(r14, Interpreter::local_tag_offset_in_bytes(n+1)),
   704       //     (int32_t)frame::TagValue);
   705 			move(AT, (int)frame::TagValue); 
   706 			sw(AT,LVP, Interpreter::local_tag_offset_in_bytes(n+1));
   707       //movptr(Address(r14, Interpreter::local_tag_offset_in_bytes(n)),
   708       //     (int32_t)frame::TagValue);
   709 			sw(AT,LVP, Interpreter::local_tag_offset_in_bytes(n));
   710     } else {
   711       //movptr(Address(r14, Interpreter::local_tag_offset_in_bytes(n)), (int32_t)tag);
   712 			move(AT, (int)tag);	   
   713 			sw(AT,LVP, Interpreter::local_tag_offset_in_bytes(n));
   714     }
   715   }
   716 }
   718 void InterpreterMacroAssembler::tag_local(frame::Tag tag, Register idx) {
   719   if (TaggedStackInterpreter) {
   720     if (tag == frame::TagCategory2) {
   721       //movptr(Address(r14, idx, Address::times_8,
   722       //            Interpreter::local_tag_offset_in_bytes(1)), (int32_t)frame::TagValue);
   723       //movptr(Address(r14, idx, Address::times_8,
   724       //            Interpreter::local_tag_offset_in_bytes(0)), (int32_t)frame::TagValue);
   725 			shl(idx, 3); 
   726 			add(idx,LVP,idx); 
   727 			move(AT,(int)frame::TagValue); 
   728 			sw(AT, idx, Interpreter::local_tag_offset_in_bytes(1));	    
   729 			shl(idx, 3); 
   730 			add(idx,LVP,idx); 
   731 			move(AT,(int)frame::TagValue); 
   732 			sw(AT, idx, Interpreter::local_tag_offset_in_bytes(0));	    
   733     } else {
   734       //movptr(Address(r14, idx, Address::times_8, Interpreter::local_tag_offset_in_bytes(0)),
   735       //     (int32_t)tag);
   736 			shl(idx, 3); 
   737 			add(idx,LVP,idx); 
   738 			move(AT,(int)tag); 
   739 			sw(AT, idx, Interpreter::local_tag_offset_in_bytes(0));	    
   740     }
   741   }
   742 }
   744 void InterpreterMacroAssembler::tag_local(Register tag, Register idx) {
   745   if (TaggedStackInterpreter) {
   746     // can only be TagValue or TagReference
   747     //movptr(Address(r14, idx, Address::times_8, Interpreter::local_tag_offset_in_bytes(0)), tag);
   748 		shl(idx, 3); 
   749 		add(idx,LVP,idx); 
   750 		sw(tag, idx, Interpreter::local_tag_offset_in_bytes(0));	    
   751   }
   752 }
   755 void InterpreterMacroAssembler::tag_local(Register tag, int n) {
   756   if (TaggedStackInterpreter) {
   757     // can only be TagValue or TagReference
   758     //movptr(Address(r14, Interpreter::local_tag_offset_in_bytes(n)), tag);
   759 		sw(tag, LVP, Interpreter::local_tag_offset_in_bytes(n)); 
   760   }
   761 }
   763 #ifdef ASSERT
   764 void InterpreterMacroAssembler::verify_local_tag(frame::Tag tag, int n) {
   765   if (TaggedStackInterpreter) {
   766      frame::Tag t = tag;
   767     if (tag == frame::TagCategory2) {
   768       Label nbl;
   769       t = frame::TagValue;  // change to what is stored in locals
   770       //cmpptr(Address(r14, Interpreter::local_tag_offset_in_bytes(n+1)), (int32_t)t);
   771       //jcc(Assembler::equal, nbl);
   772 			lw(AT, LVP, Interpreter::local_tag_offset_in_bytes(n+1)); 
   773 			addi(AT,AT, -(int)t); 
   774 			beq(AT, R0, nbl); 
   775 			delayed()->nop(); 
   776       stop("Local tag is bad for long/double");
   777       bind(nbl);
   778     }
   779     Label notBad;
   780     //cmpq(Address(r14, Interpreter::local_tag_offset_in_bytes(n)), (int32_t)t);
   781     //jcc(Assembler::equal, notBad);
   782 		lw(AT, LVP, Interpreter::local_tag_offset_in_bytes(n)); 
   783 		addi(AT,AT, -(int)t); 
   784 		beq(AT, R0, notBad); 
   785 		delayed()->nop(); 
   787 		// Also compare if the local value is zero, then the tag might
   788     // not have been set coming from deopt.
   789     //cmpptr(Address(r14, Interpreter::local_offset_in_bytes(n)), 0);
   790     //jcc(Assembler::equal, notBad);
   791 		lw(AT, LVP, Interpreter::local_tag_offset_in_bytes(n+1)); 
   792 		beq(AT, R0, notBad); 
   793 		delayed()->nop(); 
   794     stop("Local tag is bad");
   795     bind(notBad);
   796   }
   797 }
   799 void InterpreterMacroAssembler::verify_local_tag(frame::Tag tag, Register idx) {
   800   if (TaggedStackInterpreter) {
   801     frame::Tag t = tag;
   802     if (tag == frame::TagCategory2) {
   803       Label nbl;
   804       t = frame::TagValue;  // change to what is stored in locals
   805       //cmpptr(Address(r14, idx, Address::times_8, Interpreter::local_tag_offset_in_bytes(1)), (int32_t)t);
   806       //jcc(Assembler::equal, nbl);
   807 			shl(idx, 3); 
   808 			add(idx,LVP,idx); 
   809 			lw(AT, idx, Interpreter::local_tag_offset_in_bytes(1));	
   810 			addi(AT,AT, -(int)t); 
   811 			beq(AT,R0, nbl); 
   812 			delayed()->nop(); 
   813       stop("Local tag is bad for long/double");
   814       bind(nbl);
   815     }
   816     Label notBad;
   817     //cmpptr(Address(r14, idx, Address::times_8, Interpreter::local_tag_offset_in_bytes(0)), (int32_t)t);
   818     //jcc(Assembler::equal, notBad);
   819 		shl(idx, 3); 
   820 		add(idx,LVP,idx); 
   821 		lw(AT, idx, Interpreter::local_tag_offset_in_bytes(0));	
   822 		addi(AT,AT, -(int)t); 
   823 		beq(AT,R0, notBad); 
   824 		delayed()->nop(); 
   826     // Also compare if the local value is zero, then the tag might
   827     // not have been set coming from deopt.
   828     //cmpptr(Address(r14, idx, Address::times_8, Interpreter::local_offset_in_bytes(0)), 0);
   829     //jcc(Assembler::equal, notBad);
   830 		shl(idx, 3); 
   831 		add(idx,LVP,idx); 
   832 		lw(AT, idx, Interpreter::local_tag_offset_in_bytes(0));	
   833 		beq(AT,R0, notBad); 
   834 		delayed()->nop(); 
   835     stop("Local tag is bad");
   836     bind(notBad);
   837   }
   838 }
   839 #endif // ASSERT
   840 */
   841 /*
   842 void InterpreterMacroAssembler::super_call_VM_leaf(address entry_point) {
   843   MacroAssembler::call_VM_leaf_base(entry_point, 0);
   844 }
   847 void InterpreterMacroAssembler::super_call_VM_leaf(address entry_point,
   848                                                    Register arg_1) {
   849   if (arg_1 != A0) move(A0, arg_1);
   850   MacroAssembler::call_VM_leaf_base(entry_point, 1);
   851 }
   854 void InterpreterMacroAssembler::super_call_VM_leaf(address entry_point,
   855                                                    Register arg_1,
   856                                                    Register arg_2) {
   857   if (arg_1 != A0) move(A0, arg_1);
   858   if (arg_2 != A1) move(A1, arg_2); assert(arg_2 != A0, "smashed argument");
   859   MacroAssembler::call_VM_leaf_base(entry_point, 2);
   860 }
   862 void InterpreterMacroAssembler::super_call_VM_leaf(address entry_point,
   863                                                    Register arg_1,
   864                                                    Register arg_2,
   865                                                    Register arg_3) {
   866   if (arg_1 != A0) move(A0, arg_1);
   867   if (arg_2 != A1) move(A1, arg_2); assert(arg_2 != A0, "smashed argument");
   868   if (arg_3 != A2) move(A2, arg_3); assert(arg_3 != A0 && arg_3 != A1, "smashed argument");
   869   MacroAssembler::call_VM_leaf_base(entry_point, 3);
   870 }
   871 */
   872 // Jump to from_interpreted entry of a call unless single stepping is possible
   873 // in this thread in which case we must call the i2i entry
   874 void InterpreterMacroAssembler::jump_from_interpreted(Register method, Register temp) {
   875   // record last_sp
   876   move(Rsender, SP);	
   877   sd(SP, FP, frame::interpreter_frame_last_sp_offset * wordSize);
   879   if (JvmtiExport::can_post_interpreter_events()) {
   880     Label run_compiled_code;
   881     // JVMTI events, such as single-stepping, are implemented partly by avoiding running
   882     // compiled code in threads for which the event is enabled.  Check here for
   883     // interp_only_mode if these events CAN be enabled.
   884 #ifndef OPT_THREAD
   885 	get_thread(temp); 
   886 #else
   887 	move(temp, TREG);
   888 #endif
   889     // interp_only is an int, on little endian it is sufficient to test the byte only
   890     // Is a cmpl faster (ce
   891     //cmpb(Address(temp, JavaThread::interp_only_mode_offset()), 0);
   892     //jcc(Assembler::zero, run_compiled_code);
   893     lw(AT, temp, in_bytes(JavaThread::interp_only_mode_offset())); 
   894     beq(AT, R0, run_compiled_code); 
   895     delayed()->nop(); 
   896     //jmp(Address(method, methodOopDesc::interpreter_entry_offset()));
   897     ld(AT, method, in_bytes(Method::interpreter_entry_offset())); 
   898     jr(AT); 
   899     delayed()->nop(); 
   900     bind(run_compiled_code);
   901   }
   903   ld(AT, method, in_bytes(Method::from_interpreted_offset()));
   904   jr(AT); 
   905   delayed()->nop();
   906 }
   909 // The following two routines provide a hook so that an implementation
   910 // can schedule the dispatch in two parts.  amd64 does not do this.
   911 void InterpreterMacroAssembler::dispatch_prolog(TosState state, int step) {
   912   // Nothing amd64 specific to be done here
   913 }
   915 void InterpreterMacroAssembler::dispatch_epilog(TosState state, int step) {
   916   dispatch_next(state, step);
   917 }
   919 // assume the next bytecode in T8. 
   920 void InterpreterMacroAssembler::dispatch_base(TosState state,
   921                                               address* table,
   922                                               bool verifyoop) {
   923   if (VerifyActivationFrameSize) {
   924     Label L;
   926     dsub(T2, FP, SP);
   927     int min_frame_size = (frame::link_offset - 
   928 	frame::interpreter_frame_initial_sp_offset) * wordSize;
   929     daddi(T2, T2,- min_frame_size);
   930     bgez(T2, L);
   931     delayed()->nop();
   932     stop("broken stack frame");
   933     bind(L);
   934   }
   935   // FIXME: I do not know which register should pass to verify_oop
   936   if (verifyoop) verify_oop(FSR, state);
   937   dsll(T2, Rnext, LogBytesPerWord);
   939   if((long)table >= (long)Interpreter::dispatch_table(btos) &&
   940      (long)table <= (long)Interpreter::dispatch_table(vtos)
   941     ) {
   942      int table_size = (long)Interpreter::dispatch_table(ctos) - (long)Interpreter::dispatch_table(btos);
   943      int table_offset = ((int)state - (int)itos) * table_size; 
   945      // 2013/12/17 Fu: GP points to the starting address of Interpreter::dispatch_table(itos).
   946      // See StubGenerator::generate_call_stub(address& return_address) for the initialization of GP.
   947      if(table_offset != 0) {
   948         daddiu(T3, GP, table_offset);
   949         gsldx(T3, T2, T3, 0); // 2013/5/7 Jin: Godson3 extension instruction
   950      } else {
   951         gsldx(T3, T2, GP, 0);
   952      }
   953   } else {
   954      li(T3, (long)table);
   955      gsldx(T3, T2, T3, 0);
   956   }
   958   jr(T3);
   959   delayed()->nop();
   960 }
   962 void InterpreterMacroAssembler::dispatch_only(TosState state) {
   963   dispatch_base(state, Interpreter::dispatch_table(state));
   964 }
   966 void InterpreterMacroAssembler::dispatch_only_normal(TosState state) {
   967   dispatch_base(state, Interpreter::normal_table(state));
   968 }
   970 void InterpreterMacroAssembler::dispatch_only_noverify(TosState state) {
   971   dispatch_base(state, Interpreter::normal_table(state), false);
   972 }
   975 void InterpreterMacroAssembler::dispatch_next(TosState state, int step) {
   976   // load next bytecode (load before advancing r13 to prevent AGI)
   977   lbu(Rnext, BCP, step);
   978   increment(BCP, step);
   979   dispatch_base(state, Interpreter::dispatch_table(state));
   980 }
   982 void InterpreterMacroAssembler::dispatch_via(TosState state, address* table) {
   983   // load current bytecode
   984   lbu(Rnext, BCP, 0);
   985   dispatch_base(state, table);
   986 }
   988 // remove activation
   989 //
   990 // Unlock the receiver if this is a synchronized method.
   991 // Unlock any Java monitors from syncronized blocks.
   992 // Remove the activation from the stack.
   993 //
   994 // If there are locked Java monitors
   995 //    If throw_monitor_exception
   996 //       throws IllegalMonitorStateException
   997 //    Else if install_monitor_exception
   998 //       installs IllegalMonitorStateException
   999 //    Else
  1000 //       no error processing
  1001 // used registers : T1, T2, T3, T8
  1002 // T1 : thread, method access flags
  1003 // T2 : monitor entry pointer
  1004 // T3 : method, monitor top
  1005 // T8 : unlock flag
  1006 void InterpreterMacroAssembler::remove_activation(
  1007         TosState state,
  1008         Register ret_addr,
  1009         bool throw_monitor_exception,
  1010         bool install_monitor_exception,
  1011 	bool notify_jvmdi) {
  1012   // Note: Registers V0, V1 and F0, F1 may be in use for the result
  1013   // check if synchronized method  
  1014   Label unlocked, unlock, no_unlock;
  1016   // get the value of _do_not_unlock_if_synchronized into T8
  1017 #ifndef OPT_THREAD
  1018   Register thread = T1;
  1019   get_thread(thread); 
  1020 #else
  1021   Register thread = TREG;
  1022 #endif
  1023   lb(T8, thread, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
  1024   // reset the flag
  1025   sb(R0, thread, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset())); 
  1026   // get method access flags
  1027   ld(T3, FP, frame::interpreter_frame_method_offset * wordSize); 	
  1028   lw(T1, T3, in_bytes(Method::access_flags_offset()));
  1029   andi(T1, T1, JVM_ACC_SYNCHRONIZED);
  1030   beq(T1, R0, unlocked);
  1031   delayed()->nop();
  1033   // Don't unlock anything if the _do_not_unlock_if_synchronized flag is set.
  1034   bne(T8, R0, no_unlock);
  1035   delayed()->nop();
  1036   // unlock monitor
  1037   push(state);     // save result
  1039   // BasicObjectLock will be first in list, 
  1040   // since this is a synchronized method. However, need
  1041   // to check that the object has not been unlocked by an explicit monitorexit bytecode.  
  1042   daddiu(c_rarg0, FP, frame::interpreter_frame_initial_sp_offset * wordSize 
  1043       - (int)sizeof(BasicObjectLock));
  1044   // address of first monitor
  1045   lw(T1, c_rarg0, BasicObjectLock::obj_offset_in_bytes());
  1046   bne(T1, R0, unlock); 
  1047   delayed()->nop(); 
  1048   pop(state);
  1049   if (throw_monitor_exception) {
  1050     // Entry already unlocked, need to throw exception
  1051     //I think mips do not need empty_FPU_stack 
  1052     // remove possible return value from FPU-stack, otherwise stack could overflow
  1054     empty_FPU_stack();	
  1055     call_VM(NOREG, CAST_FROM_FN_PTR(address, 
  1056 	  InterpreterRuntime::throw_illegal_monitor_state_exception));
  1057     should_not_reach_here();
  1058   } else {
  1059     // Monitor already unlocked during a stack unroll. 
  1060     // If requested, install an illegal_monitor_state_exception.
  1061     // Continue with stack unrolling.
  1062     if (install_monitor_exception) {
  1063       // remove possible return value from FPU-stack, 
  1064       // otherwise stack could overflow
  1065       empty_FPU_stack();  		
  1066       call_VM(NOREG, CAST_FROM_FN_PTR(address, 
  1067 	    InterpreterRuntime::new_illegal_monitor_state_exception));
  1071     b(unlocked);
  1072     delayed()->nop();
  1075   bind(unlock);  
  1077   unlock_object(c_rarg0);              
  1078   pop(state);
  1079   // Check that for block-structured locking (i.e., that all locked objects has been unlocked)  
  1080   bind(unlocked);  
  1082   // V0, V1: Might contain return value
  1084   // Check that all monitors are unlocked
  1086     Label loop, exception, entry, restart;
  1087     const int entry_size  = frame::interpreter_frame_monitor_size() * wordSize;
  1088     const Address monitor_block_top(FP, 
  1089 	frame::interpreter_frame_monitor_block_top_offset * wordSize);
  1091     bind(restart);
  1092     // points to current entry, starting with top-most entry (ecx)
  1093     ld(c_rarg0, monitor_block_top); 
  1094     // points to word before bottom of monitor block (ebx)
  1095     daddiu(T3, FP, frame::interpreter_frame_initial_sp_offset * wordSize); 
  1096     //  lw(AT, R0, 12); 
  1097     b(entry);
  1098     delayed()->nop();
  1100     // Entry already locked, need to throw exception
  1101     bind(exception); 
  1103     if (throw_monitor_exception) {
  1104       // Throw exception      
  1105       // remove possible return value from FPU-stack, 
  1106       // otherwise stack could overflow
  1107       empty_FPU_stack();       
  1108       MacroAssembler::call_VM(NOREG, CAST_FROM_FN_PTR(address, 
  1109 	    InterpreterRuntime::throw_illegal_monitor_state_exception));
  1110       should_not_reach_here();
  1111     } else {
  1112       // Stack unrolling. Unlock object and install illegal_monitor_exception
  1113       // Unlock does not block, so don't have to worry about the frame
  1114       // We don't have to preserve eax, edx since we are going to 
  1115       // throw an exception
  1116       unlock_object(c_rarg0);
  1117       if (install_monitor_exception) {
  1118 	empty_FPU_stack();  				
  1119 	call_VM(NOREG, CAST_FROM_FN_PTR(address, 
  1120 	      InterpreterRuntime::new_illegal_monitor_state_exception));
  1123       b(restart);
  1124       delayed()->nop();
  1127     bind(loop);
  1128     //    stop("before object excetpion"); 
  1130     ld(T1, c_rarg0, BasicObjectLock::obj_offset_in_bytes());
  1131     bne(T1, R0, exception);// check if current entry is used
  1132     delayed()->nop();
  1135     daddiu(c_rarg0, c_rarg0, entry_size);// otherwise advance to next entry
  1136     bind(entry);
  1137     bne(c_rarg0, T3, loop);	// check if bottom reached
  1138     delayed()->nop();	// if not at bottom then check this entry
  1141   bind(no_unlock);
  1143   // jvmpi support (jvmdi does not generate MethodExit on exception / popFrame)
  1144   if (notify_jvmdi) {
  1145     //notify_method_exit(state);              // preserve TOSCA
  1146     notify_method_exit(false,state,NotifyJVMTI);    // preserve TOSCA
  1147   } else {
  1148     // notify_jvmpi_method_exit(state);       // preserve TOSCA
  1149     notify_method_exit(false,state,SkipNotifyJVMTI);// preserve TOSCA
  1152   // remove activation
  1153   ld(SP, FP, frame::interpreter_frame_sender_sp_offset * wordSize); 
  1154   ld(ret_addr, FP, frame::interpreter_frame_return_addr_offset * wordSize);
  1155   ld(FP, FP, frame::interpreter_frame_sender_fp_offset * wordSize);
  1158 #endif // C_INTERP
  1160 // Lock object
  1161 //
  1162 // Args:
  1163 //      c_rarg1: BasicObjectLock to be used for locking
  1164 //
  1165 // Kills:
  1166 //      rax
  1167 //      c_rarg0, c_rarg1, c_rarg2, c_rarg3, .. (param regs)
  1168 //      rscratch1, rscratch2 (scratch regs)
  1169 void InterpreterMacroAssembler::lock_object(Register lock_reg) {
  1170   assert(lock_reg == c_rarg0, "The argument is only for looks. It must be c_rarg0");
  1172   if (UseHeavyMonitors) {
  1173     call_VM(NOREG, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter), 
  1174 	lock_reg);
  1175   } else {
  1177     Label done;
  1179     const Register swap_reg = T2;  // Must use eax for cmpxchg instruction
  1180     const Register obj_reg  = T1;  // Will contain the oop
  1182     const int obj_offset = BasicObjectLock::obj_offset_in_bytes();
  1183     const int lock_offset = BasicObjectLock::lock_offset_in_bytes ();
  1184     const int mark_offset = lock_offset 
  1185       + BasicLock::displaced_header_offset_in_bytes(); 
  1187     Label slow_case;
  1188     // Load object pointer into obj_reg %ecx
  1189     ld(obj_reg, lock_reg, obj_offset);
  1190     if (UseBiasedLocking) {
  1191       // Note: we use noreg for the temporary register since it's hard
  1192       // to come up with a free register on all incoming code paths
  1193       biased_locking_enter(lock_reg, obj_reg, swap_reg, noreg, false, 
  1194 	  done, &slow_case);
  1198     // Load (object->mark() | 1) into swap_reg %eax
  1199     ld(AT, obj_reg, 0);
  1200     ori(swap_reg, AT, 1);
  1203     // Save (object->mark() | 1) into BasicLock's displaced header
  1204     sd(swap_reg, lock_reg, mark_offset);
  1206     assert(lock_offset == 0, "displached header must be first word in BasicObjectLock");
  1207     if (os::is_MP()) {
  1208       //  lock();
  1210     cmpxchg(lock_reg, Address(obj_reg, 0), swap_reg);
  1212     if (PrintBiasedLockingStatistics) {
  1213       //cond_incl(AT, Address((int) BiasedLocking::fast_path_entry_count_addr(), relocInfo::none));
  1216     bne(AT, R0, done);
  1218     // Test if the oopMark is an obvious stack pointer, i.e.,
  1219     //  1) (mark & 3) == 0, and
  1220     //  2) SP <= mark < SP + os::pagesize()
  1221     //
  1222     // These 3 tests can be done by evaluating the following 
  1223     // expression: ((mark - esp) & (3 - os::vm_page_size())),
  1224     // assuming both stack pointer and pagesize have their
  1225     // least significant 2 bits clear.
  1226     // NOTE: the oopMark is in swap_reg %eax as the result of cmpxchg
  1227     delayed()->nop();
  1229     dsub(swap_reg, swap_reg, SP);
  1230     move(AT, 3 - os::vm_page_size());
  1231     andr(swap_reg, swap_reg, AT);
  1232     // Save the test result, for recursive case, the result is zero
  1233     sd(swap_reg, lock_reg, mark_offset);
  1234     if (PrintBiasedLockingStatistics) {
  1235       // cond_incl(AT, Address((int) BiasedLocking::fast_path_entry_count_addr(), relocInfo::none));
  1238     beq(swap_reg, R0, done);
  1239     delayed()->nop();
  1240     bind(slow_case);
  1241     // Call the runtime routine for slow case
  1242     call_VM(NOREG, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter), lock_reg);
  1244     bind(done);
  1249 // Unlocks an object. Used in monitorexit bytecode and
  1250 // remove_activation.  Throws an IllegalMonitorException if object is
  1251 // not locked by current thread.
  1252 //
  1253 // Args:
  1254 //      c_rarg1: BasicObjectLock for lock
  1255 //
  1256 // Kills:
  1257 //      rax
  1258 //      c_rarg0, c_rarg1, c_rarg2, c_rarg3, ... (param regs)
  1259 //      rscratch1, rscratch2 (scratch regs)
  1260 // Argument: T6 : Points to BasicObjectLock structure for lock
  1261 // Argument: c_rarg0 : Points to BasicObjectLock structure for lock
  1262 // Throw an IllegalMonitorException if object is not locked by current thread
  1263 void InterpreterMacroAssembler::unlock_object(Register lock_reg) {
  1264   assert(lock_reg == c_rarg0, "The argument is only for looks. It must be c_rarg0");
  1266   if (UseHeavyMonitors) {
  1267     call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), lock_reg);
  1268   } else {
  1269     Label done;
  1271     const Register swap_reg   = T2;  // Must use eax for cmpxchg instruction
  1272     const Register header_reg = T3;  // Will contain the old oopMark
  1273     const Register obj_reg    = T1;  // Will contain the oop
  1275     save_bcp(); // Save in case of exception
  1277     // Convert from BasicObjectLock structure to object and BasicLock structure
  1278     // Store the BasicLock address into %eax
  1279     daddi(swap_reg, lock_reg, BasicObjectLock::lock_offset_in_bytes());
  1281     // Load oop into obj_reg(%ecx)
  1282     ld(obj_reg, lock_reg, BasicObjectLock::obj_offset_in_bytes ());
  1283     //free entry 
  1284     sd(R0, lock_reg, BasicObjectLock::obj_offset_in_bytes());
  1285     if (UseBiasedLocking) {
  1286       biased_locking_exit(obj_reg, header_reg, done);
  1289     // Load the old header from BasicLock structure
  1290     ld(header_reg, swap_reg, BasicLock::displaced_header_offset_in_bytes());
  1291     /*
  1292     // Free entry
  1293     sw(R0, lock_reg, BasicObjectLock::obj_offset_in_bytes());
  1294      */
  1295     // zero for recursive case
  1296     beq(header_reg, R0, done);
  1297     delayed()->nop();
  1299     // Atomic swap back the old header
  1300     if (os::is_MP()); //lock();
  1301     cmpxchg(header_reg, Address(obj_reg, 0), swap_reg);
  1303     // zero for recursive case
  1304     bne(AT, R0, done);
  1305     delayed()->nop();
  1307     // Call the runtime routine for slow case.
  1308     sd(obj_reg, lock_reg, BasicObjectLock::obj_offset_in_bytes()); // restore obj
  1309     call_VM(NOREG, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), 
  1310 	lock_reg);
  1312     bind(done);
  1314     restore_bcp();
  1318 #ifndef CC_INTERP
  1320 void InterpreterMacroAssembler::test_method_data_pointer(Register mdp,
  1321     Label& zero_continue) {
  1322   assert(ProfileInterpreter, "must be profiling interpreter");
  1323   ld(mdp, Address(FP, frame::interpreter_frame_mdx_offset * wordSize));
  1324   beq(mdp, R0, zero_continue);
  1325   delayed()->nop();
  1329 // Set the method data pointer for the current bcp.
  1330 void InterpreterMacroAssembler::set_method_data_pointer_for_bcp() {
  1331         assert(ProfileInterpreter, "must be profiling interpreter");
  1332         Label set_mdp;
  1334         // V0 and T0 will be used as two temporary registers.
  1335         sd(V0, SP, (-1) * wordSize);
  1336         sd(T0, SP, (-2) * wordSize);
  1337         daddiu(SP, SP, (-2) * wordSize);
  1339         get_method(T0);
  1340         // Test MDO to avoid the call if it is NULL.
  1341         ld(V0, T0, in_bytes(Method::method_data_offset()));
  1342         beq(V0, R0, set_mdp);
  1343         delayed()->nop();
  1345         // method: T0
  1346         // bcp: BCP --> S0
  1347         call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::bcp_to_di), T0, BCP);
  1348         // mdi: V0
  1349         // mdo is guaranteed to be non-zero here, we checked for it before the call.
  1350         /* Jin: reload T0 */
  1351         get_method(T0);
  1352         ld(T0, T0, in_bytes(Method::method_data_offset()));
  1353         daddiu(T0, T0, in_bytes(MethodData::data_offset()));
  1354         daddu(V0, T0, V0);
  1356         bind(set_mdp);
  1358         sd(V0, FP, frame::interpreter_frame_mdx_offset * wordSize);
  1360         daddiu(SP, SP, 2 * wordSize);
  1361         ld(V0, SP, (-1) * wordSize);
  1362         ld(T0, SP, (-2) * wordSize);
  1365 void InterpreterMacroAssembler::verify_method_data_pointer() {
  1366 assert(ProfileInterpreter, "must be profiling interpreter");
  1367 #ifdef ASSERT
  1368   Label verify_continue;
  1369   Register method = V0;
  1370   Register mdp = V1;
  1371   Register tmp = A0;
  1372   push(method);
  1373   push(mdp);
  1374   push(tmp);
  1375   test_method_data_pointer(mdp, verify_continue); // If mdp is zero, continue
  1376   get_method(method);
  1378   // If the mdp is valid, it will point to a DataLayout header which is
  1379   // consistent with the bcp.  The converse is highly probable also.
  1380   lhu(tmp, mdp, in_bytes(DataLayout::bci_offset()));
  1381   ld(AT, method, in_bytes(Method::const_offset()));
  1382   daddu(tmp, tmp, AT);
  1383   daddiu(tmp, tmp, in_bytes(ConstMethod::codes_offset()));
  1384   beq(tmp, BCP, verify_continue);
  1385   nop();
  1386   call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::verify_mdp), method, BCP, mdp);
  1387   bind(verify_continue);
  1388   pop(tmp);
  1389   pop(mdp);
  1390   pop(method);
  1391 #endif // ASSERT
  1395 void InterpreterMacroAssembler::set_mdp_data_at(Register mdp_in,
  1396                                                 int constant,
  1397                                                 Register value) {
  1398   assert(ProfileInterpreter, "must be profiling interpreter");
  1399   Address data(mdp_in, constant);
  1400   sd(value, data);
  1404 void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in,
  1405                                                       int constant,
  1406                                                       bool decrement) {
  1407   // Counter address
  1408   Address data(mdp_in, constant);
  1410   increment_mdp_data_at(data, decrement);
  1413 void InterpreterMacroAssembler::increment_mdp_data_at(Address data,
  1414                                                       bool decrement) {
  1415   assert(ProfileInterpreter, "must be profiling interpreter");
  1416   // %%% this does 64bit counters at best it is wasting space
  1417   // at worst it is a rare bug when counters overflow
  1418   Register tmp = S0;
  1419   push(tmp);
  1420   if (decrement) {
  1421     // Decrement the register.
  1422     ld(AT, data);
  1423     daddiu(tmp, AT, (int32_t) -DataLayout::counter_increment);
  1424     // If the decrement causes the counter to overflow, stay negative
  1425     Label L;
  1426     slt(AT, tmp, R0);
  1427     bne(AT, R0, L);
  1428     nop();
  1429     daddi(tmp, tmp, (int32_t) DataLayout::counter_increment);
  1430     bind(L);
  1431     sd(tmp, data);
  1432   } else {
  1433     assert(DataLayout::counter_increment == 1, 
  1434            "flow-free idiom only works with 1");
  1435     ld(AT, data);
  1436     // Increment the register.
  1437     daddiu(tmp, AT, DataLayout::counter_increment);
  1438     // If the increment causes the counter to overflow, pull back by 1.
  1439     slt(AT, tmp, R0);
  1440     dsubu(tmp, tmp, AT);
  1441     sd(tmp, data);
  1443   pop(tmp);
  1447 void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in,
  1448                                                       Register reg,
  1449                                                       int constant,
  1450                                                       bool decrement) {
  1451   Register tmp = S0;
  1452   push(S0);
  1453   if (decrement) {
  1454     // Decrement the register.
  1455     daddu(AT, mdp_in, reg);
  1456     assert(Assembler::is_simm16(constant), "constant is not a simm16 !");
  1457     ld(AT, AT, constant);
  1459     daddiu(tmp, AT, (int32_t) -DataLayout::counter_increment);
  1460     // If the decrement causes the counter to overflow, stay negative
  1461     Label L;
  1462     slt(AT, tmp, R0);
  1463     bne(AT, R0, L);
  1464     nop();
  1465     daddi(tmp, tmp, (int32_t) DataLayout::counter_increment);
  1466     bind(L);
  1468     daddu(AT, mdp_in, reg);
  1469     sd(tmp, AT, constant);
  1470   } else {
  1471     daddu(AT, mdp_in, reg);
  1472     assert(Assembler::is_simm16(constant), "constant is not a simm16 !");
  1473     ld(AT, AT, constant);
  1475     // Increment the register.
  1476     daddiu(tmp, AT, DataLayout::counter_increment);
  1477     // If the increment causes the counter to overflow, pull back by 1.
  1478     slt(AT, tmp, R0);
  1479     dsubu(tmp, tmp, AT);
  1481     daddu(AT, mdp_in, reg);
  1482     sd(tmp, AT, constant);
  1484   pop(S0);
  1487 void InterpreterMacroAssembler::set_mdp_flag_at(Register mdp_in,
  1488                                                 int flag_byte_constant) {
  1489   assert(ProfileInterpreter, "must be profiling interpreter");
  1490   int header_offset = in_bytes(DataLayout::header_offset());
  1491   int header_bits = DataLayout::flag_mask_to_header_mask(flag_byte_constant);
  1492   // Set the flag
  1493   lw(AT, Address(mdp_in, header_offset));
  1494   if(Assembler::is_simm16(header_bits)) {
  1495     ori(AT, AT, header_bits);
  1496   } else {
  1497     push(T8);
  1498     // T8 is used as a temporary register.
  1499     move(T8, header_bits);
  1500     orr(AT, AT, T8);
  1501     pop(T8);
  1503   sw(AT, Address(mdp_in, header_offset));
  1508 void InterpreterMacroAssembler::test_mdp_data_at(Register mdp_in,
  1509                                                  int offset,
  1510                                                  Register value,
  1511                                                  Register test_value_out,
  1512                                                  Label& not_equal_continue) {
  1513   assert(ProfileInterpreter, "must be profiling interpreter");
  1514   if (test_value_out == noreg) {
  1515     ld(AT, Address(mdp_in, offset));
  1516     bne(AT, value, not_equal_continue);
  1517     nop();
  1518   } else {
  1519     // Put the test value into a register, so caller can use it:
  1520     ld(test_value_out, Address(mdp_in, offset));
  1521     bne(value, test_value_out, not_equal_continue);
  1522     nop();
  1527 void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in,
  1528                                                      int offset_of_disp) {
  1529   assert(ProfileInterpreter, "must be profiling interpreter");
  1530   assert(Assembler::is_simm16(offset_of_disp), "offset is not an simm16");
  1531   ld(AT, mdp_in, offset_of_disp);
  1532   daddu(mdp_in, mdp_in, AT);
  1533   sd(mdp_in, Address(FP, frame::interpreter_frame_mdx_offset * wordSize));
  1537 void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in,
  1538                                                      Register reg,
  1539                                                      int offset_of_disp) {
  1540   assert(ProfileInterpreter, "must be profiling interpreter");
  1541 //  Attention: Until now (20121217), we do not support this kind of addressing on Loongson.
  1542 //  Address disp_address(mdp_in, reg, Address::times_1, offset_of_disp);
  1543   daddu(AT, reg, mdp_in);
  1544   assert(Assembler::is_simm16(offset_of_disp), "offset is not an simm16");
  1545   ld(AT, AT, offset_of_disp);
  1546   daddu(mdp_in, mdp_in, AT);
  1547   sd(mdp_in, Address(FP, frame::interpreter_frame_mdx_offset * wordSize));
  1551 void InterpreterMacroAssembler::update_mdp_by_constant(Register mdp_in,
  1552                                                        int constant) {
  1553   assert(ProfileInterpreter, "must be profiling interpreter");
  1554   if(Assembler::is_simm16(constant)) {
  1555     daddiu(mdp_in, mdp_in, constant);
  1556   } else {
  1557     move(AT, constant);
  1558     daddu(mdp_in, mdp_in, AT);
  1560   sd(mdp_in, Address(FP, frame::interpreter_frame_mdx_offset * wordSize));
  1564 void InterpreterMacroAssembler::update_mdp_for_ret(Register return_bci) {
  1565   assert(ProfileInterpreter, "must be profiling interpreter");
  1566   push(return_bci); // save/restore across call_VM
  1567   call_VM(noreg,
  1568           CAST_FROM_FN_PTR(address, InterpreterRuntime::update_mdp_for_ret),
  1569           return_bci);
  1570   pop(return_bci);
  1574 void InterpreterMacroAssembler::profile_taken_branch(Register mdp,
  1575                                                      Register bumped_count) {
  1576   if (ProfileInterpreter) {
  1577     Label profile_continue;
  1579     // If no method data exists, go to profile_continue.
  1580     // Otherwise, assign to mdp
  1581     test_method_data_pointer(mdp, profile_continue);
  1583     // We are taking a branch.  Increment the taken count.
  1584     //increment_mdp_data_at(mdp, in_bytes(JumpData::taken_offset()));
  1585     // We inline increment_mdp_data_at to return bumped_count in a register
  1586     ld(bumped_count, mdp, in_bytes(JumpData::taken_offset()));
  1587     assert(DataLayout::counter_increment == 1, 
  1588            "flow-free idiom only works with 1");
  1589     push(T8);
  1590     // T8 is used as a temporary register.
  1591     daddiu(T8, bumped_count, DataLayout::counter_increment);
  1592     slt(AT, T8, R0);
  1593     dsubu(bumped_count, T8, AT);
  1594     pop(T8);
  1595     sd(bumped_count, mdp, in_bytes(JumpData::taken_offset())); // Store back out
  1596     // The method data pointer needs to be updated to reflect the new target.
  1597     update_mdp_by_offset(mdp, in_bytes(JumpData::displacement_offset()));
  1598     bind(profile_continue);
  1603 void InterpreterMacroAssembler::profile_not_taken_branch(Register mdp) {
  1604   if (ProfileInterpreter) {
  1605     Label profile_continue;
  1607     // If no method data exists, go to profile_continue.
  1608     test_method_data_pointer(mdp, profile_continue);
  1610     // We are taking a branch.  Increment the not taken count.
  1611     increment_mdp_data_at(mdp, in_bytes(BranchData::not_taken_offset()));
  1613     // The method data pointer needs to be updated to correspond to
  1614     // the next bytecode
  1615     update_mdp_by_constant(mdp, in_bytes(BranchData::branch_data_size()));
  1616     bind(profile_continue);
  1621 void InterpreterMacroAssembler::profile_call(Register mdp) {
  1622   if (ProfileInterpreter) {
  1623     Label profile_continue;
  1625     // If no method data exists, go to profile_continue.
  1626     test_method_data_pointer(mdp, profile_continue);
  1628     // We are making a call.  Increment the count.
  1629     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
  1631     // The method data pointer needs to be updated to reflect the new target.
  1632     update_mdp_by_constant(mdp, in_bytes(CounterData::counter_data_size()));
  1633     bind(profile_continue);
  1638 void InterpreterMacroAssembler::profile_final_call(Register mdp) {
  1639   if (ProfileInterpreter) {
  1640     Label profile_continue;
  1642     // If no method data exists, go to profile_continue.
  1643     test_method_data_pointer(mdp, profile_continue);
  1644     // We are making a call.  Increment the count.
  1645     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
  1647     // The method data pointer needs to be updated to reflect the new target.
  1648     update_mdp_by_constant(mdp, in_bytes(VirtualCallData:: virtual_call_data_size()));
  1649     bind(profile_continue);
  1654 void InterpreterMacroAssembler::profile_virtual_call(Register receiver,
  1655                                                      Register mdp,
  1656                                                      Register reg2,
  1657                                                      bool receiver_can_be_null) {
  1658   if (ProfileInterpreter) {
  1659     Label profile_continue;
  1661     // If no method data exists, go to profile_continue.
  1662     test_method_data_pointer(mdp, profile_continue);
  1664     Label skip_receiver_profile;
  1665     if (receiver_can_be_null) {
  1666        Label not_null;
  1667        bne(receiver, R0, not_null);
  1668        nop();
  1669        // We are making a call.  Increment the count.
  1670        increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
  1671        beq(R0, R0, skip_receiver_profile);
  1672        nop();
  1673        bind(not_null);
  1676     // Record the receiver type.
  1677     record_klass_in_profile(receiver, mdp, reg2, true);
  1678     bind(skip_receiver_profile);
  1680     // The method data pointer needs to be updated to reflect the new target.
  1681     update_mdp_by_constant(mdp, in_bytes(VirtualCallData::virtual_call_data_size()));
  1682     bind(profile_continue);
  1686 void InterpreterMacroAssembler::profile_checkcast(bool is_null, Register mdp) {
  1687 // In x86, this method does not exist.
  1688 #ifndef CORE
  1689         if (ProfileInterpreter) {
  1690                 Label profile_continue;
  1692                 // If no method data exists, go to profile_continue.
  1693                 test_method_data_pointer(mdp, profile_continue);
  1695                 if (is_null)                // Set the flag to true.
  1696                         set_mdp_flag_at(mdp, BitData::null_seen_byte_constant());
  1697                         //set_mdp_flag_at(mdp, BitData::null_flag_constant());
  1699                 // The method data pointer needs to be updated.
  1700                 update_mdp_by_constant(mdp, in_bytes(BitData::bit_data_size()));
  1702                 bind (profile_continue);
  1704 #endif // !CORE
  1707 // This routine creates a state machine for updating the multi-row
  1708 // type profile at a virtual call site (or other type-sensitive bytecode).
  1709 // The machine visits each row (of receiver/count) until the receiver type
  1710 // is found, or until it runs out of rows.  At the same time, it remembers
  1711 // the location of the first empty row.  (An empty row records null for its
  1712 // receiver, and can be allocated for a newly-observed receiver type.)
  1713 // Because there are two degrees of freedom in the state, a simple linear
  1714 // search will not work; it must be a decision tree.  Hence this helper
  1715 // function is recursive, to generate the required tree structured code.
  1716 // It's the interpreter, so we are trading off code space for speed.
  1717 // See below for example code.
  1718 void InterpreterMacroAssembler::record_klass_in_profile_helper(
  1719                                         Register receiver, Register mdp,
  1720                                         Register reg2,
  1721                                         int start_row, Label& done, bool is_virtual_call) {
  1722   if (TypeProfileWidth == 0) {
  1723     if (is_virtual_call) {
  1724       increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
  1726     return;
  1729   int last_row = VirtualCallData::row_limit() - 1;
  1730   assert(start_row <= last_row, "must be work left to do");
  1731   // Test this row for both the receiver and for null.
  1732   // Take any of three different outcomes:
  1733   //   1. found receiver => increment count and goto done
  1734   //   2. found null => keep looking for case 1, maybe allocate this cell
  1735   //   3. found something else => keep looking for cases 1 and 2
  1736   // Case 3 is handled by a recursive call.
  1737   for (int row = start_row; row <= last_row; row++) {
  1738     Label next_test;
  1739     bool test_for_null_also = (row == start_row);
  1741     // See if the receiver is receiver[n].
  1742     int recvr_offset = in_bytes(VirtualCallData::receiver_offset(row));
  1743     test_mdp_data_at(mdp, recvr_offset, receiver,
  1744                      (test_for_null_also ? reg2 : noreg),
  1745                      next_test);
  1746     // (Reg2 now contains the receiver from the CallData.)
  1748     // The receiver is receiver[n].  Increment count[n].
  1749     int count_offset = in_bytes(VirtualCallData::receiver_count_offset(row));
  1750     increment_mdp_data_at(mdp, count_offset);
  1751     beq(R0, R0, done);
  1752     nop();
  1753     bind(next_test);
  1755     if (test_for_null_also) {
  1756       Label found_null;
  1757       // Failed the equality check on receiver[n]...  Test for null.
  1758       if (start_row == last_row) {
  1759         // The only thing left to do is handle the null case.
  1760         if (is_virtual_call) {
  1761           beq(reg2, R0, found_null);
  1762           nop();
  1763           // Receiver did not match any saved receiver and there is no empty row for it.
  1764           // Increment total counter to indicate polymorphic case.
  1765           increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
  1766           beq(R0, R0, done);
  1767           nop();
  1768           bind(found_null);
  1769         } else {
  1770           bne(reg2, R0, done);
  1771           nop();
  1773         break;
  1775       // Since null is rare, make it be the branch-taken case.
  1776       beq(reg2, R0, found_null);
  1777       nop();
  1779       // Put all the "Case 3" tests here.
  1780       record_klass_in_profile_helper(receiver, mdp, reg2, start_row + 1, done, is_virtual_call);
  1782       // Found a null.  Keep searching for a matching receiver,
  1783       // but remember that this is an empty (unused) slot.
  1784       bind(found_null);
  1788   // In the fall-through case, we found no matching receiver, but we
  1789   // observed the receiver[start_row] is NULL.
  1791   // Fill in the receiver field and increment the count.
  1792   int recvr_offset = in_bytes(VirtualCallData::receiver_offset(start_row));
  1793   set_mdp_data_at(mdp, recvr_offset, receiver);
  1794   int count_offset = in_bytes(VirtualCallData::receiver_count_offset(start_row));
  1795   move(reg2, DataLayout::counter_increment);
  1796   set_mdp_data_at(mdp, count_offset, reg2);
  1797   if (start_row > 0) {
  1798     beq(R0, R0, done);
  1799     nop();
  1803 // Example state machine code for three profile rows:
  1804 //   // main copy of decision tree, rooted at row[1]
  1805 //   if (row[0].rec == rec) { row[0].incr(); goto done; }
  1806 //   if (row[0].rec != NULL) {
  1807 //     // inner copy of decision tree, rooted at row[1]
  1808 //     if (row[1].rec == rec) { row[1].incr(); goto done; }
  1809 //     if (row[1].rec != NULL) {
  1810 //       // degenerate decision tree, rooted at row[2]
  1811 //       if (row[2].rec == rec) { row[2].incr(); goto done; }
  1812 //       if (row[2].rec != NULL) { goto done; } // overflow
  1813 //       row[2].init(rec); goto done;
  1814 //     } else {
  1815 //       // remember row[1] is empty
  1816 //       if (row[2].rec == rec) { row[2].incr(); goto done; }
  1817 //       row[1].init(rec); goto done;
  1818 //     }
  1819 //   } else {
  1820 //     // remember row[0] is empty
  1821 //     if (row[1].rec == rec) { row[1].incr(); goto done; }
  1822 //     if (row[2].rec == rec) { row[2].incr(); goto done; }
  1823 //     row[0].init(rec); goto done;
  1824 //   }
  1826 void InterpreterMacroAssembler::record_klass_in_profile(Register receiver,
  1827                                                         Register mdp,
  1828                                                         Register reg2, bool is_virtual_call) {
  1829   assert(ProfileInterpreter, "must be profiling");
  1830   Label done;
  1832   record_klass_in_profile_helper(receiver, mdp, reg2, 0, done, is_virtual_call);
  1834   bind (done);
  1837 void InterpreterMacroAssembler::profile_ret(Register return_bci,
  1838                                             Register mdp) {
  1839   if (ProfileInterpreter) {
  1840     Label profile_continue;
  1841     uint row;
  1843     // If no method data exists, go to profile_continue.
  1844     test_method_data_pointer(mdp, profile_continue);
  1846     // Update the total ret count.
  1847     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
  1849     for (row = 0; row < RetData::row_limit(); row++) {
  1850       Label next_test;
  1852       // See if return_bci is equal to bci[n]:
  1853       test_mdp_data_at(mdp,
  1854                        in_bytes(RetData::bci_offset(row)),
  1855                        return_bci, noreg,
  1856                        next_test);
  1858       // return_bci is equal to bci[n].  Increment the count.
  1859       increment_mdp_data_at(mdp, in_bytes(RetData::bci_count_offset(row)));
  1861       // The method data pointer needs to be updated to reflect the new target.
  1862       update_mdp_by_offset(mdp,
  1863                            in_bytes(RetData::bci_displacement_offset(row)));
  1864       beq(R0, R0, profile_continue);
  1865       nop();
  1866       bind(next_test);
  1869     update_mdp_for_ret(return_bci);
  1871     bind(profile_continue);
  1876 void InterpreterMacroAssembler::profile_null_seen(Register mdp) {
  1877   if (ProfileInterpreter) {
  1878     Label profile_continue;
  1880     // If no method data exists, go to profile_continue.
  1881     test_method_data_pointer(mdp, profile_continue);
  1883     set_mdp_flag_at(mdp, BitData::null_seen_byte_constant());
  1885     // The method data pointer needs to be updated.
  1886     int mdp_delta = in_bytes(BitData::bit_data_size());
  1887     if (TypeProfileCasts) {
  1888       mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
  1890     update_mdp_by_constant(mdp, mdp_delta);
  1892     bind(profile_continue);
  1897 void InterpreterMacroAssembler::profile_typecheck_failed(Register mdp) {
  1898   if (ProfileInterpreter && TypeProfileCasts) {
  1899     Label profile_continue;
  1901     // If no method data exists, go to profile_continue.
  1902     test_method_data_pointer(mdp, profile_continue);
  1904     int count_offset = in_bytes(CounterData::count_offset());
  1905     // Back up the address, since we have already bumped the mdp.
  1906     count_offset -= in_bytes(VirtualCallData::virtual_call_data_size());
  1908     // *Decrement* the counter.  We expect to see zero or small negatives.
  1909     increment_mdp_data_at(mdp, count_offset, true);
  1911     bind (profile_continue);
  1916 void InterpreterMacroAssembler::profile_typecheck(Register mdp, Register klass, Register reg2) {
  1917   if (ProfileInterpreter) {
  1918     Label profile_continue;
  1920     // If no method data exists, go to profile_continue.
  1921     test_method_data_pointer(mdp, profile_continue);
  1923     // The method data pointer needs to be updated.
  1924     int mdp_delta = in_bytes(BitData::bit_data_size());
  1925     if (TypeProfileCasts) {
  1927       mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
  1929       // Record the object type.
  1930       record_klass_in_profile(klass, mdp, reg2, false);
  1932     update_mdp_by_constant(mdp, mdp_delta);
  1934     bind(profile_continue);
  1939 void InterpreterMacroAssembler::profile_switch_default(Register mdp) {
  1940   if (ProfileInterpreter) {
  1941     Label profile_continue;
  1943     // If no method data exists, go to profile_continue.
  1944     test_method_data_pointer(mdp, profile_continue);
  1946     // Update the default case count
  1947     increment_mdp_data_at(mdp, in_bytes(MultiBranchData::default_count_offset()));
  1949     // The method data pointer needs to be updated.
  1950     update_mdp_by_offset(mdp, in_bytes(MultiBranchData:: default_displacement_offset()));
  1952     bind(profile_continue);
  1957 void InterpreterMacroAssembler::profile_switch_case(Register index,
  1958                                                     Register mdp,
  1959                                                     Register reg2) {
  1960   if (ProfileInterpreter) {
  1961     Label profile_continue;
  1963     // If no method data exists, go to profile_continue.
  1964     test_method_data_pointer(mdp, profile_continue);
  1966     // Build the base (index * per_case_size_in_bytes()) + case_array_offset_in_bytes()
  1967     move(reg2, in_bytes(MultiBranchData::per_case_size()));
  1968     dmult(index, reg2);
  1969     mflo(index);
  1970 //    addptr(index, in_bytes(MultiBranchData::case_array_offset())); // XXX l ?
  1971     daddiu(index, index, in_bytes(MultiBranchData::case_array_offset()));
  1973     // Update the case count
  1974     increment_mdp_data_at(mdp, index, in_bytes(MultiBranchData::relative_count_offset()));
  1976     // The method data pointer needs to be updated.
  1977     update_mdp_by_offset(mdp, index, in_bytes(MultiBranchData:: relative_displacement_offset()));
  1979     bind(profile_continue);
  1983 void InterpreterMacroAssembler::profile_obj_type(Register obj, const Address& mdo_addr) {
  1984   Label update, next, none;
  1986   verify_oop(obj);
  1988   //testptr(obj, obj);
  1989   //jccb(Assembler::notZero, update);
  1990   bne(obj, R0, update);
  1991   nop();
  1993   //orptr(mdo_addr, TypeEntries::null_seen);
  1994   push(T1);
  1995   if (mdo_addr.index() == noreg) {
  1996     ld(T1, mdo_addr);
  1997   } else {
  1998     guarantee(T1 != mdo_addr.base(), "The base register will be corrupted !");
  1999     guarantee(T1 != mdo_addr.index(), "The index register will be corrupted !");
  2001     dsll(AT, mdo_addr.index(), mdo_addr.scale());
  2002     daddu(AT, AT, mdo_addr.base());
  2003     ld(T1, AT, mdo_addr.disp());
  2005   li(AT, TypeEntries::null_seen);
  2006   orr(AT, T1, AT);
  2007   if (mdo_addr.index() == noreg) {
  2008     sd(AT, mdo_addr);
  2009   } else {
  2010     guarantee(T1 != mdo_addr.base(), "The base register will be corrupted !");
  2011     guarantee(T1 != mdo_addr.index(), "The index register will be corrupted !");
  2013     dsll(T1, mdo_addr.index(), mdo_addr.scale());
  2014     daddu(T1, T1, mdo_addr.base());
  2015     sd(AT, T1, mdo_addr.disp());
  2017   pop(T1);
  2019   //jmpb(next);
  2020   beq(R0, R0, next);
  2021   nop();
  2023   bind(update);
  2024   load_klass(obj, obj);
  2026   //xorptr(obj, mdo_addr);
  2027   if (mdo_addr.index() == noreg) {
  2028     ld(AT, mdo_addr);
  2029   } else {
  2030     dsll(AT, mdo_addr.index(), mdo_addr.scale());
  2031     daddu(AT, AT, mdo_addr.base());
  2032     ld(AT, AT, mdo_addr.disp());
  2034   xorr(obj, obj, AT);
  2036   //testptr(obj, TypeEntries::type_klass_mask);
  2037   //jccb(Assembler::zero, next); // klass seen before, nothing to
  2038                                // do. The unknown bit may have been
  2039                                // set already but no need to check.
  2040   li(AT, TypeEntries::type_klass_mask);
  2041   andr(AT, obj, AT);
  2042   beq(AT, R0, next);
  2043   nop();
  2045   //testptr(obj, TypeEntries::type_unknown);
  2046   //jccb(Assembler::notZero, next); // already unknown. Nothing to do anymore.
  2047   li(AT, TypeEntries::type_unknown);
  2048   andr(AT, AT, obj);
  2049   bne(AT, R0, next);
  2050   nop();
  2052   //cmpptr(mdo_addr, 0);
  2053   //jccb(Assembler::equal, none);
  2054   if (mdo_addr.index() == noreg) {
  2055     ld(AT, mdo_addr);
  2056   } else {
  2057     dsll(AT, mdo_addr.index(), mdo_addr.scale());
  2058     daddu(AT, AT, mdo_addr.base());
  2059     ld(AT, AT, mdo_addr.disp());
  2061   beq(AT, R0, none);
  2062   nop();
  2065   //cmpptr(mdo_addr, TypeEntries::null_seen);
  2066   //jccb(Assembler::equal, none);
  2067   push(T1);
  2068   if (mdo_addr.index() == noreg) {
  2069     ld(T1, mdo_addr);
  2070   } else {
  2071     guarantee(T1 != mdo_addr.base(), "The base register will be corrupted !");
  2072     guarantee(T1 != mdo_addr.index(), "The index register will be corrupted !");
  2074     dsll(AT, mdo_addr.index(), mdo_addr.scale());
  2075     daddu(AT, AT, mdo_addr.base());
  2076     ld(T1, AT, mdo_addr.disp());
  2078   li(AT, TypeEntries::null_seen);
  2079   subu(AT, AT, T1);
  2080   pop(T1);
  2081   beq(AT, R0, none);
  2082   nop();
  2084   // There is a chance that the checks above (re-reading profiling
  2085   // data from memory) fail if another thread has just set the
  2086   // profiling to this obj's klass
  2087   //xorptr(obj, mdo_addr);
  2088   //testptr(obj, TypeEntries::type_klass_mask);
  2089   //jccb(Assembler::zero, next);
  2090   if (mdo_addr.index() == noreg) {
  2091     ld(AT, mdo_addr);
  2092   } else {
  2093     dsll(AT, mdo_addr.index(), mdo_addr.scale());
  2094     daddu(AT, AT, mdo_addr.base());
  2095     ld(AT, AT, mdo_addr.disp());
  2097   xorr(obj, obj, AT);
  2098   li(AT, TypeEntries::type_klass_mask);
  2099   andr(AT, obj, AT);
  2100   beq(AT, R0, next);
  2101   nop();
  2103   // different than before. Cannot keep accurate profile.
  2104   //orptr(mdo_addr, TypeEntries::type_unknown);
  2105   //jmpb(next);
  2106   push(T1);
  2107   if (mdo_addr.index() == noreg) {
  2108     ld(T1, mdo_addr); 
  2109   } else {
  2110     guarantee(T1 != mdo_addr.base(), "The base register will be corrupted !");
  2111     guarantee(T1 != mdo_addr.index(), "The index register will be corrupted !");
  2113     dsll(AT, mdo_addr.index(), mdo_addr.scale());
  2114     daddu(AT, AT, mdo_addr.base());
  2115     ld(T1, AT, mdo_addr.disp());
  2117   li(AT, TypeEntries::type_unknown);
  2118   orr(AT, T1, AT);
  2119   if (mdo_addr.index() == noreg) {
  2120     sd(AT, mdo_addr);
  2121   } else {
  2122     guarantee(T1 != mdo_addr.base(), "The base register will be corrupted !");
  2123     guarantee(T1 != mdo_addr.index(), "The index register will be corrupted !");
  2125     dsll(T1, mdo_addr.index(), mdo_addr.scale());
  2126     daddu(T1, T1, mdo_addr.base());
  2127     sd(AT, T1, mdo_addr.disp());
  2129   pop(T1);
  2130   beq(R0, R0, next);
  2131   nop();
  2134   bind(none);
  2135   // first time here. Set profile type.
  2136   //movptr(mdo_addr, obj);
  2137   if (mdo_addr.index() == noreg) {
  2138     sd(obj, mdo_addr);
  2139   } else {
  2140     dsll(AT, mdo_addr.index(), mdo_addr.scale());
  2141     daddu(AT, AT, mdo_addr.base());
  2142     sd(obj, AT, mdo_addr.disp());
  2145   bind(next);
  2148 void InterpreterMacroAssembler::profile_arguments_type(Register mdp, Register callee, Register tmp, bool is_virtual) {
  2149   if (!ProfileInterpreter) {
  2150     return;
  2153   if (MethodData::profile_arguments() || MethodData::profile_return()) {
  2154     Label profile_continue;
  2156     test_method_data_pointer(mdp, profile_continue);
  2158     int off_to_start = is_virtual ? in_bytes(VirtualCallData::virtual_call_data_size()) : in_bytes(CounterData::counter_data_size());
  2160     //cmpb(Address(mdp, in_bytes(DataLayout::tag_offset()) - off_to_start), is_virtual ? DataLayout::virtual_call_type_data_tag : DataLayout::call_type_data_tag);
  2161     //jcc(Assembler::notEqual, profile_continue);
  2162     lb(AT, mdp, in_bytes(DataLayout::tag_offset()) - off_to_start);
  2163     li(tmp, is_virtual ? DataLayout::virtual_call_type_data_tag : DataLayout::call_type_data_tag);
  2164     bne(tmp, AT, profile_continue);
  2165     nop();
  2168     if (MethodData::profile_arguments()) {
  2169       Label done;
  2170       int off_to_args = in_bytes(TypeEntriesAtCall::args_data_offset());
  2171       //addptr(mdp, off_to_args);
  2172       if (Assembler::is_simm16(off_to_args)) {
  2173         daddiu(mdp, mdp, off_to_args);
  2174       } else {
  2175         move(AT, off_to_args);
  2176         daddu(mdp, mdp, AT);
  2180       for (int i = 0; i < TypeProfileArgsLimit; i++) {
  2181         if (i > 0 || MethodData::profile_return()) {
  2182           // If return value type is profiled we may have no argument to profile
  2183           //movptr(tmp, Address(mdp, in_bytes(TypeEntriesAtCall::cell_count_offset())-off_to_args));
  2184           ld(tmp, mdp, in_bytes(TypeEntriesAtCall::cell_count_offset())-off_to_args);
  2186           //subl(tmp, i*TypeStackSlotEntries::per_arg_count());
  2187           if (Assembler::is_simm16(-1 * i * TypeStackSlotEntries::per_arg_count())) {
  2188             addiu32(tmp, tmp, -1 * i * TypeStackSlotEntries::per_arg_count());
  2189           } else {
  2190             li(AT, i*TypeStackSlotEntries::per_arg_count());
  2191             subu32(tmp, tmp, AT);
  2194           //cmpl(tmp, TypeStackSlotEntries::per_arg_count());
  2195           //jcc(Assembler::less, done);
  2196           li(AT, TypeStackSlotEntries::per_arg_count());
  2197           slt(AT, tmp, AT);
  2198           bne(AT, R0, done);
  2199           nop();
  2201         //movptr(tmp, Address(callee, Method::const_offset()));
  2202         ld(tmp, callee, in_bytes(Method::const_offset())); 
  2204         //load_unsigned_short(tmp, Address(tmp, ConstMethod::size_of_parameters_offset()));
  2205         lhu(tmp, tmp, in_bytes(ConstMethod::size_of_parameters_offset()));
  2207         // stack offset o (zero based) from the start of the argument
  2208         // list, for n arguments translates into offset n - o - 1 from
  2209         // the end of the argument list
  2210         //subptr(tmp, Address(mdp, in_bytes(TypeEntriesAtCall::stack_slot_offset(i))-off_to_args));
  2211         ld(AT, mdp, in_bytes(TypeEntriesAtCall::stack_slot_offset(i))-off_to_args);
  2212         subu(tmp, tmp, AT);
  2214         //subl(tmp, 1);
  2215         addiu32(tmp, tmp, -1);
  2217         Address arg_addr = argument_address(tmp);
  2218         //movptr(tmp, arg_addr);
  2219         ld(tmp, arg_addr);
  2221         Address mdo_arg_addr(mdp, in_bytes(TypeEntriesAtCall::argument_type_offset(i))-off_to_args);
  2222         profile_obj_type(tmp, mdo_arg_addr);
  2224         int to_add = in_bytes(TypeStackSlotEntries::per_arg_size());
  2225         //addptr(mdp, to_add);
  2226         if (Assembler::is_simm16(to_add)) {
  2227           daddiu(mdp, mdp, to_add);
  2228         } else {
  2229           move(AT, to_add);
  2230           daddu(mdp, mdp, AT);
  2233         off_to_args += to_add;
  2236       if (MethodData::profile_return()) {
  2237         //movptr(tmp, Address(mdp, in_bytes(TypeEntriesAtCall::cell_count_offset())-off_to_args));
  2238         ld(tmp, mdp, in_bytes(TypeEntriesAtCall::cell_count_offset())-off_to_args);
  2240         //subl(tmp, TypeProfileArgsLimit*TypeStackSlotEntries::per_arg_count());
  2241         int tmp_arg_counts = TypeProfileArgsLimit*TypeStackSlotEntries::per_arg_count();
  2242         if (Assembler::is_simm16(-1 * tmp_arg_counts)) {
  2243           addiu32(tmp, tmp, -1 * tmp_arg_counts);
  2244         } else {
  2245           move(AT, tmp_arg_counts);
  2246           subu32(mdp, mdp, AT);
  2250       bind(done);
  2252       if (MethodData::profile_return()) {
  2253         // We're right after the type profile for the last
  2254         // argument. tmp is the number of cells left in the
  2255         // CallTypeData/VirtualCallTypeData to reach its end. Non null
  2256         // if there's a return to profile.
  2257         assert(ReturnTypeEntry::static_cell_count() < TypeStackSlotEntries::per_arg_count(), "can't move past ret type");
  2258         //shll(tmp, exact_log2(DataLayout::cell_size));
  2259         //addptr(mdp, tmp);
  2260         sll(tmp, tmp, exact_log2(DataLayout::cell_size));
  2261         daddu(mdp, mdp, tmp);
  2263       //movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), mdp);
  2264       sd(mdp, FP, frame::interpreter_frame_mdx_offset * wordSize);
  2265     } else {
  2266       assert(MethodData::profile_return(), "either profile call args or call ret");
  2267       update_mdp_by_constant(mdp, in_bytes(TypeEntriesAtCall::return_only_size()));
  2270     // mdp points right after the end of the
  2271     // CallTypeData/VirtualCallTypeData, right after the cells for the
  2272     // return value type if there's one
  2274     bind(profile_continue);
  2278 void InterpreterMacroAssembler::profile_return_type(Register mdp, Register ret, Register tmp) {
  2279   assert_different_registers(mdp, ret, tmp, _bcp_register);
  2280   if (ProfileInterpreter && MethodData::profile_return()) {
  2281     Label profile_continue, done;
  2283     test_method_data_pointer(mdp, profile_continue);
  2285     if (MethodData::profile_return_jsr292_only()) {
  2286       // If we don't profile all invoke bytecodes we must make sure
  2287       // it's a bytecode we indeed profile. We can't go back to the
  2288       // begining of the ProfileData we intend to update to check its
  2289       // type because we're right after it and we don't known its
  2290       // length
  2291       Label do_profile;
  2292       //cmpb(Address(_bcp_register, 0), Bytecodes::_invokedynamic);
  2293       //jcc(Assembler::equal, do_profile);
  2294       lb(AT, _bcp_register, 0);
  2295       daddiu(AT, AT, -1 * Bytecodes::_invokedynamic);
  2296       beq(AT, R0, do_profile);
  2297       nop();
  2299       //cmpb(Address(_bcp_register, 0), Bytecodes::_invokehandle);
  2300       //jcc(Assembler::equal, do_profile);
  2301       lb(AT, _bcp_register, 0);
  2302       daddiu(AT, AT, -1 * Bytecodes::_invokehandle);
  2303       beq(AT, R0, do_profile);
  2304       nop();
  2306       get_method(tmp);
  2307       //cmpb(Address(tmp, Method::intrinsic_id_offset_in_bytes()), vmIntrinsics::_compiledLambdaForm);
  2308       //jcc(Assembler::notEqual, profile_continue);
  2309       lb(tmp, tmp, Method::intrinsic_id_offset_in_bytes());
  2310       li(AT, vmIntrinsics::_compiledLambdaForm);
  2311       bne(tmp, AT, profile_continue);
  2312       nop();
  2314       bind(do_profile);
  2317     Address mdo_ret_addr(mdp, -in_bytes(ReturnTypeEntry::size()));
  2318     //mov(tmp, ret);
  2319     daddu(tmp, ret, R0);
  2320     profile_obj_type(tmp, mdo_ret_addr);
  2322     bind(profile_continue);
  2326 void InterpreterMacroAssembler::profile_parameters_type(Register mdp, Register tmp1, Register tmp2) {
  2327   guarantee(T9 == tmp1, "You are reqired to use T9 as the index register for MIPS !");
  2329   if (ProfileInterpreter && MethodData::profile_parameters()) {
  2330     Label profile_continue, done;
  2332     test_method_data_pointer(mdp, profile_continue);
  2334     // Load the offset of the area within the MDO used for
  2335     // parameters. If it's negative we're not profiling any parameters
  2336     //movl(tmp1, Address(mdp, in_bytes(MethodData::parameters_type_data_di_offset()) - in_bytes(MethodData::data_offset())));
  2337     //testl(tmp1, tmp1);
  2338     //jcc(Assembler::negative, profile_continue);
  2339     lw(tmp1, mdp, in_bytes(MethodData::parameters_type_data_di_offset()) - in_bytes(MethodData::data_offset()));
  2340     bltz(tmp1, profile_continue);
  2341     nop();
  2343     // Compute a pointer to the area for parameters from the offset
  2344     // and move the pointer to the slot for the last
  2345     // parameters. Collect profiling from last parameter down.
  2346     // mdo start + parameters offset + array length - 1
  2347     //addptr(mdp, tmp1);
  2348     //movptr(tmp1, Address(mdp, ArrayData::array_len_offset()));
  2349     daddu(mdp, mdp, tmp1);
  2350     ld(tmp1, mdp, in_bytes(ArrayData::array_len_offset()));
  2351     decrement(tmp1, TypeStackSlotEntries::per_arg_count());
  2354     Label loop;
  2355     bind(loop);
  2357     int off_base = in_bytes(ParametersTypeData::stack_slot_offset(0));
  2358     int type_base = in_bytes(ParametersTypeData::type_offset(0));
  2359     Address::ScaleFactor per_arg_scale = Address::times(DataLayout::cell_size);
  2360     //Address arg_off(mdp, tmp1, per_arg_scale, off_base);
  2361     Address arg_type(mdp, tmp1, per_arg_scale, type_base);
  2363     // load offset on the stack from the slot for this parameter
  2364     //movptr(tmp2, arg_off);
  2365     dsll(AT, tmp1, per_arg_scale);
  2366     daddu(AT, AT, mdp);
  2367     ld(tmp2, AT, off_base);
  2369     //negptr(tmp2);
  2370     subu(tmp2, R0, tmp2);
  2372     // read the parameter from the local area
  2373     //movptr(tmp2, Address(_locals_register, tmp2, Interpreter::stackElementScale()));
  2374     dsll(AT, tmp2, Interpreter::stackElementScale());
  2375     daddu(AT, AT, _locals_register);
  2376     ld(tmp2, AT, 0);
  2378     // profile the parameter
  2379     profile_obj_type(tmp2, arg_type);
  2381     // go to next parameter
  2382     decrement(tmp1, TypeStackSlotEntries::per_arg_count());
  2383     //jcc(Assembler::positive, loop);
  2384     bgtz(tmp1, loop);
  2385     nop();
  2387     bind(profile_continue);
  2391 void InterpreterMacroAssembler::verify_oop(Register reg, TosState state) {
  2392   if (state == atos) {
  2393     MacroAssembler::verify_oop(reg);
  2397 void InterpreterMacroAssembler::verify_FPU(int stack_depth, TosState state) {
  2398   // only if +VerifyFPU  && (state == ftos || state == dtos)
  2399   // For now, do nothing.
  2401 #endif // !CC_INTERP
  2404 //FIXME, aoqi:see UltraViolet
  2405 void InterpreterMacroAssembler::notify_method_entry() {
  2406   // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to
  2407   // track stack depth.  If it is possible to enter interp_only_mode we add
  2408   // the code to check if the event should be sent.
  2409   //Register tempreg = Rscratch0;
  2410   Register tempreg = T0;
  2411   if (JvmtiExport::can_post_interpreter_events()) {
  2412     Label L;
  2413     //movl(rdx, Address(r15_thread, JavaThread::interp_only_mode_offset()));
  2414     //testl(rdx, rdx);
  2415     //jcc(Assembler::zero, L);
  2416     //lw(tempreg, in_bytes(JavaThread::interp_only_mode_offset()), Rthread);
  2417     get_thread(AT);
  2418     lw(tempreg, AT, in_bytes(JavaThread::interp_only_mode_offset()));
  2419     beq(tempreg, R0, L);
  2420     delayed()->nop();
  2421     call_VM(noreg, CAST_FROM_FN_PTR(address,
  2422                                     InterpreterRuntime::post_method_entry));
  2423     bind(L);
  2427     //SkipIfEqual skip_if(this, tempreg, R0, &DTraceMethodProbes, 1);
  2428     SkipIfEqual skip_if(this, &DTraceMethodProbes, 0);
  2429     call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry),
  2430 		 //Rthread,
  2431 		 AT,
  2432 		 //Rmethod);
  2433 		 S3);
  2438 //FIXME, aoqi:see UltraViolet
  2439 void InterpreterMacroAssembler::notify_method_exit(
  2440     //TosState state, NotifyMethodExitMode mode) {
  2441     bool is_native_method, TosState state, NotifyMethodExitMode mode) {
  2442   // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to
  2443   // track stack depth.  If it is possible to enter interp_only_mode we add
  2444   // the code to check if the event should be sent.
  2445   //Register tempreg = Rscratch0;
  2446   Register tempreg = T0;
  2447   if (mode == NotifyJVMTI && JvmtiExport::can_post_interpreter_events()) {
  2448     Label skip;
  2449     //lw(tempreg, in_bytes(JavaThread::interp_only_mode_offset()), Rthread);
  2450     get_thread(AT);
  2451     lw(tempreg, AT, in_bytes(JavaThread::interp_only_mode_offset()));
  2452     beq(tempreg, R0, skip);
  2453     delayed()->nop();
  2454     // Note: frame::interpreter_frame_result has a dependency on how the
  2455     // method result is saved across the call to post_method_exit. If this
  2456     // is changed then the interpreter_frame_result implementation will
  2457     // need to be updated too.
  2459     // For c++ interpreter the result is always stored at a known location in the frame
  2460     // template interpreter will leave it on the top of the stack.
  2461     save_return_value(state, is_native_method);
  2462     call_VM(noreg,
  2463             CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_exit));
  2464     restore_return_value(state, is_native_method);
  2465     bind(skip);
  2469     // Dtrace notification
  2470     //SkipIfEqual skip_if(this, tempreg, R0, &DTraceMethodProbes, equal);
  2471     SkipIfEqual skip_if(this, &DTraceMethodProbes, 0);
  2472     save_return_value(state, is_native_method);
  2473     call_VM_leaf(
  2474 		 CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit),
  2475 		 //Rthread, Rmethod);
  2476 		 AT, S3);
  2477     restore_return_value(state, is_native_method);
  2481 //FIXME  yyq native return 64 bits
  2482 void InterpreterMacroAssembler::save_return_value(
  2483     TosState state, bool is_native_call) {
  2484   if (is_native_call) {
  2485     // save any potential method result value
  2486     //sd(V0, frame::interpreter_frame_l_scratch_offset * wordSize, FP);
  2487     //sdc1(F0, frame::interpreter_frame_d_scratch_offset * wordSize, FP);
  2488     sw(V0, FP, (-9) * wordSize);
  2489     swc1(F0, FP, (-10) * wordSize);
  2491 //    sd(V0, FP, (-9) * wordSize);
  2492 //    sdc1(F0, FP, (-10) * wordSize);
  2493   } else {
  2494     push(state);
  2498 //FIXME  yyq native return 64 bits
  2499 void InterpreterMacroAssembler::restore_return_value(
  2500     TosState state, bool is_native_call) {
  2501   if (is_native_call) {
  2502     // Restore any method result value
  2503     //ld(V0, frame::interpreter_frame_l_scratch_offset * wordSize, FP);
  2504     //ldc1(F0, frame::interpreter_frame_d_scratch_offset * wordSize, FP);
  2505     lw(V0, FP, (-9) * wordSize);
  2506     lwc1(F0, FP, (-10) * wordSize);
  2507   } else {
  2508     pop(state);

mercurial