src/cpu/x86/vm/interp_masm_x86_32.cpp

Wed, 07 May 2008 08:06:46 -0700

author
rasbold
date
Wed, 07 May 2008 08:06:46 -0700
changeset 580
f3de1255b035
parent 435
a61af66fc99e
child 739
dc7f315e41f7
permissions
-rw-r--r--

6603011: RFE: Optimize long division
Summary: Transform long division by constant into multiply
Reviewed-by: never, kvn

     1 /*
     2  * Copyright 1997-2007 Sun Microsystems, Inc.  All Rights Reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
    21  * have any questions.
    22  *
    23  */
    25 #include "incls/_precompiled.incl"
    26 #include "incls/_interp_masm_x86_32.cpp.incl"
    29 // Implementation of InterpreterMacroAssembler
    30 #ifdef CC_INTERP
    31 void InterpreterMacroAssembler::get_method(Register reg) {
    32   movl(reg, Address(rbp, -(sizeof(BytecodeInterpreter) + 2 * wordSize)));
    33   movl(reg, Address(reg, byte_offset_of(BytecodeInterpreter, _method)));
    34 }
    35 #endif // CC_INTERP
    38 #ifndef CC_INTERP
    39 void InterpreterMacroAssembler::call_VM_leaf_base(
    40   address entry_point,
    41   int     number_of_arguments
    42 ) {
    43   // interpreter specific
    44   //
    45   // Note: No need to save/restore bcp & locals (rsi & rdi) pointer
    46   //       since these are callee saved registers and no blocking/
    47   //       GC can happen in leaf calls.
    48   // Further Note: DO NOT save/restore bcp/locals. If a caller has
    49   // already saved them so that it can use rsi/rdi as temporaries
    50   // then a save/restore here will DESTROY the copy the caller
    51   // saved! There used to be a save_bcp() that only happened in
    52   // the ASSERT path (no restore_bcp). Which caused bizarre failures
    53   // when jvm built with ASSERTs.
    54 #ifdef ASSERT
    55   { Label L;
    56     cmpl(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), NULL_WORD);
    57     jcc(Assembler::equal, L);
    58     stop("InterpreterMacroAssembler::call_VM_leaf_base: last_sp != NULL");
    59     bind(L);
    60   }
    61 #endif
    62   // super call
    63   MacroAssembler::call_VM_leaf_base(entry_point, number_of_arguments);
    64   // interpreter specific
    66   // Used to ASSERT that rsi/rdi were equal to frame's bcp/locals
    67   // but since they may not have been saved (and we don't want to
    68   // save them here (see note above) the assert is invalid.
    69 }
    72 void InterpreterMacroAssembler::call_VM_base(
    73   Register oop_result,
    74   Register java_thread,
    75   Register last_java_sp,
    76   address  entry_point,
    77   int      number_of_arguments,
    78   bool     check_exceptions
    79 ) {
    80 #ifdef ASSERT
    81   { Label L;
    82     cmpl(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), NULL_WORD);
    83     jcc(Assembler::equal, L);
    84     stop("InterpreterMacroAssembler::call_VM_base: last_sp != NULL");
    85     bind(L);
    86   }
    87 #endif /* ASSERT */
    88   // interpreter specific
    89   //
    90   // Note: Could avoid restoring locals ptr (callee saved) - however doesn't
    91   //       really make a difference for these runtime calls, since they are
    92   //       slow anyway. Btw., bcp must be saved/restored since it may change
    93   //       due to GC.
    94   assert(java_thread == noreg , "not expecting a precomputed java thread");
    95   save_bcp();
    96   // super call
    97   MacroAssembler::call_VM_base(oop_result, java_thread, last_java_sp, entry_point, number_of_arguments, check_exceptions);
    98   // interpreter specific
    99   restore_bcp();
   100   restore_locals();
   101 }
   104 void InterpreterMacroAssembler::check_and_handle_popframe(Register java_thread) {
   105   if (JvmtiExport::can_pop_frame()) {
   106     Label L;
   107     // Initiate popframe handling only if it is not already being processed.  If the flag
   108     // has the popframe_processing bit set, it means that this code is called *during* popframe
   109     // handling - we don't want to reenter.
   110     Register pop_cond = java_thread;  // Not clear if any other register is available...
   111     movl(pop_cond, Address(java_thread, JavaThread::popframe_condition_offset()));
   112     testl(pop_cond, JavaThread::popframe_pending_bit);
   113     jcc(Assembler::zero, L);
   114     testl(pop_cond, JavaThread::popframe_processing_bit);
   115     jcc(Assembler::notZero, L);
   116     // Call Interpreter::remove_activation_preserving_args_entry() to get the
   117     // address of the same-named entrypoint in the generated interpreter code.
   118     call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_preserving_args_entry));
   119     jmp(rax);
   120     bind(L);
   121     get_thread(java_thread);
   122   }
   123 }
   126 void InterpreterMacroAssembler::load_earlyret_value(TosState state) {
   127   get_thread(rcx);
   128   movl(rcx, Address(rcx, JavaThread::jvmti_thread_state_offset()));
   129   const Address tos_addr (rcx, JvmtiThreadState::earlyret_tos_offset());
   130   const Address oop_addr (rcx, JvmtiThreadState::earlyret_oop_offset());
   131   const Address val_addr (rcx, JvmtiThreadState::earlyret_value_offset());
   132   const Address val_addr1(rcx, JvmtiThreadState::earlyret_value_offset()
   133                              + in_ByteSize(wordSize));
   134   switch (state) {
   135     case atos: movl(rax, oop_addr);
   136                movl(oop_addr, NULL_WORD);
   137                verify_oop(rax, state);                break;
   138     case ltos: movl(rdx, val_addr1);               // fall through
   139     case btos:                                     // fall through
   140     case ctos:                                     // fall through
   141     case stos:                                     // fall through
   142     case itos: movl(rax, val_addr);                   break;
   143     case ftos: fld_s(val_addr);                       break;
   144     case dtos: fld_d(val_addr);                       break;
   145     case vtos: /* nothing to do */                    break;
   146     default  : ShouldNotReachHere();
   147   }
   148   // Clean up tos value in the thread object
   149   movl(tos_addr,  (int) ilgl);
   150   movl(val_addr,  NULL_WORD);
   151   movl(val_addr1, NULL_WORD);
   152 }
   155 void InterpreterMacroAssembler::check_and_handle_earlyret(Register java_thread) {
   156   if (JvmtiExport::can_force_early_return()) {
   157     Label L;
   158     Register tmp = java_thread;
   159     movl(tmp, Address(tmp, JavaThread::jvmti_thread_state_offset()));
   160     testl(tmp, tmp);
   161     jcc(Assembler::zero, L); // if (thread->jvmti_thread_state() == NULL) exit;
   163     // Initiate earlyret handling only if it is not already being processed.
   164     // If the flag has the earlyret_processing bit set, it means that this code
   165     // is called *during* earlyret handling - we don't want to reenter.
   166     movl(tmp, Address(tmp, JvmtiThreadState::earlyret_state_offset()));
   167     cmpl(tmp, JvmtiThreadState::earlyret_pending);
   168     jcc(Assembler::notEqual, L);
   170     // Call Interpreter::remove_activation_early_entry() to get the address of the
   171     // same-named entrypoint in the generated interpreter code.
   172     get_thread(java_thread);
   173     movl(tmp, Address(java_thread, JavaThread::jvmti_thread_state_offset()));
   174     pushl(Address(tmp, JvmtiThreadState::earlyret_tos_offset()));
   175     call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_early_entry), 1);
   176     jmp(rax);
   177     bind(L);
   178     get_thread(java_thread);
   179   }
   180 }
   183 void InterpreterMacroAssembler::get_unsigned_2_byte_index_at_bcp(Register reg, int bcp_offset) {
   184   assert(bcp_offset >= 0, "bcp is still pointing to start of bytecode");
   185   movl(reg, Address(rsi, bcp_offset));
   186   bswap(reg);
   187   shrl(reg, 16);
   188 }
   191 void InterpreterMacroAssembler::get_cache_and_index_at_bcp(Register cache, Register index, int bcp_offset) {
   192   assert(bcp_offset > 0, "bcp is still pointing to start of bytecode");
   193   assert(cache != index, "must use different registers");
   194   load_unsigned_word(index, Address(rsi, bcp_offset));
   195   movl(cache, Address(rbp, frame::interpreter_frame_cache_offset * wordSize));
   196   assert(sizeof(ConstantPoolCacheEntry) == 4*wordSize, "adjust code below");
   197   shll(index, 2); // convert from field index to ConstantPoolCacheEntry index
   198 }
   201 void InterpreterMacroAssembler::get_cache_entry_pointer_at_bcp(Register cache, Register tmp, int bcp_offset) {
   202   assert(bcp_offset > 0, "bcp is still pointing to start of bytecode");
   203   assert(cache != tmp, "must use different register");
   204   load_unsigned_word(tmp, Address(rsi, bcp_offset));
   205   assert(sizeof(ConstantPoolCacheEntry) == 4*wordSize, "adjust code below");
   206                                // convert from field index to ConstantPoolCacheEntry index
   207                                // and from word offset to byte offset
   208   shll(tmp, 2 + LogBytesPerWord);
   209   movl(cache, Address(rbp, frame::interpreter_frame_cache_offset * wordSize));
   210                                // skip past the header
   211   addl(cache, in_bytes(constantPoolCacheOopDesc::base_offset()));
   212   addl(cache, tmp);            // construct pointer to cache entry
   213 }
   216   // Generate a subtype check: branch to ok_is_subtype if sub_klass is
   217   // a subtype of super_klass.  EAX holds the super_klass.  Blows ECX.
   218   // Resets EDI to locals.  Register sub_klass cannot be any of the above.
   219 void InterpreterMacroAssembler::gen_subtype_check( Register Rsub_klass, Label &ok_is_subtype ) {
   220   assert( Rsub_klass != rax, "rax, holds superklass" );
   221   assert( Rsub_klass != rcx, "rcx holds 2ndary super array length" );
   222   assert( Rsub_klass != rdi, "rdi holds 2ndary super array scan ptr" );
   223   Label not_subtype, loop;
   225   // Profile the not-null value's klass.
   226   profile_typecheck(rcx, Rsub_klass, rdi); // blows rcx, rdi
   228   // Load the super-klass's check offset into ECX
   229   movl( rcx, Address(rax, sizeof(oopDesc) + Klass::super_check_offset_offset_in_bytes() ) );
   230   // Load from the sub-klass's super-class display list, or a 1-word cache of
   231   // the secondary superclass list, or a failing value with a sentinel offset
   232   // if the super-klass is an interface or exceptionally deep in the Java
   233   // hierarchy and we have to scan the secondary superclass list the hard way.
   234   // See if we get an immediate positive hit
   235   cmpl( rax, Address(Rsub_klass,rcx,Address::times_1) );
   236   jcc( Assembler::equal,ok_is_subtype );
   238   // Check for immediate negative hit
   239   cmpl( rcx, sizeof(oopDesc) + Klass::secondary_super_cache_offset_in_bytes() );
   240   jcc( Assembler::notEqual, not_subtype );
   241   // Check for self
   242   cmpl( Rsub_klass, rax );
   243   jcc( Assembler::equal, ok_is_subtype );
   245   // Now do a linear scan of the secondary super-klass chain.
   246   movl( rdi, Address(Rsub_klass, sizeof(oopDesc) + Klass::secondary_supers_offset_in_bytes()) );
   247   // EDI holds the objArrayOop of secondary supers.
   248   movl( rcx, Address(rdi, arrayOopDesc::length_offset_in_bytes()));// Load the array length
   249   // Skip to start of data; also clear Z flag incase ECX is zero
   250   addl( rdi, arrayOopDesc::base_offset_in_bytes(T_OBJECT) );
   251   // Scan ECX words at [EDI] for occurance of EAX
   252   // Set NZ/Z based on last compare
   253   repne_scan();
   254   restore_locals();           // Restore EDI; Must not blow flags
   255   // Not equal?
   256   jcc( Assembler::notEqual, not_subtype );
   257   // Must be equal but missed in cache.  Update cache.
   258   movl( Address(Rsub_klass, sizeof(oopDesc) + Klass::secondary_super_cache_offset_in_bytes()), rax );
   259   jmp( ok_is_subtype );
   261   bind(not_subtype);
   262   profile_typecheck_failed(rcx); // blows rcx
   263 }
   265 void InterpreterMacroAssembler::f2ieee() {
   266   if (IEEEPrecision) {
   267     fstp_s(Address(rsp, 0));
   268     fld_s(Address(rsp, 0));
   269   }
   270 }
   273 void InterpreterMacroAssembler::d2ieee() {
   274   if (IEEEPrecision) {
   275     fstp_d(Address(rsp, 0));
   276     fld_d(Address(rsp, 0));
   277   }
   278 }
   279 #endif // CC_INTERP
   281 // Java Expression Stack
   283 #ifdef ASSERT
   284 void InterpreterMacroAssembler::verify_stack_tag(frame::Tag t) {
   285   if (TaggedStackInterpreter) {
   286     Label okay;
   287     cmpl(Address(rsp, wordSize), (int)t);
   288     jcc(Assembler::equal, okay);
   289     // Also compare if the stack value is zero, then the tag might
   290     // not have been set coming from deopt.
   291     cmpl(Address(rsp, 0), 0);
   292     jcc(Assembler::equal, okay);
   293     stop("Java Expression stack tag value is bad");
   294     bind(okay);
   295   }
   296 }
   297 #endif // ASSERT
   299 void InterpreterMacroAssembler::pop_ptr(Register r) {
   300   debug_only(verify_stack_tag(frame::TagReference));
   301   popl(r);
   302   if (TaggedStackInterpreter) addl(rsp, 1 * wordSize);
   303 }
   305 void InterpreterMacroAssembler::pop_ptr(Register r, Register tag) {
   306   popl(r);
   307   // Tag may not be reference for jsr, can be returnAddress
   308   if (TaggedStackInterpreter) popl(tag);
   309 }
   311 void InterpreterMacroAssembler::pop_i(Register r) {
   312   debug_only(verify_stack_tag(frame::TagValue));
   313   popl(r);
   314   if (TaggedStackInterpreter) addl(rsp, 1 * wordSize);
   315 }
   317 void InterpreterMacroAssembler::pop_l(Register lo, Register hi) {
   318   debug_only(verify_stack_tag(frame::TagValue));
   319   popl(lo);
   320   if (TaggedStackInterpreter) addl(rsp, 1 * wordSize);
   321   debug_only(verify_stack_tag(frame::TagValue));
   322   popl(hi);
   323   if (TaggedStackInterpreter) addl(rsp, 1 * wordSize);
   324 }
   326 void InterpreterMacroAssembler::pop_f() {
   327   debug_only(verify_stack_tag(frame::TagValue));
   328   fld_s(Address(rsp, 0));
   329   addl(rsp, 1 * wordSize);
   330   if (TaggedStackInterpreter) addl(rsp, 1 * wordSize);
   331 }
   333 void InterpreterMacroAssembler::pop_d() {
   334   // Write double to stack contiguously and load into ST0
   335   pop_dtos_to_rsp();
   336   fld_d(Address(rsp, 0));
   337   addl(rsp, 2 * wordSize);
   338 }
   341 // Pop the top of the java expression stack to execution stack (which
   342 // happens to be the same place).
   343 void InterpreterMacroAssembler::pop_dtos_to_rsp() {
   344   if (TaggedStackInterpreter) {
   345     // Pop double value into scratch registers
   346     debug_only(verify_stack_tag(frame::TagValue));
   347     popl(rax);
   348     addl(rsp, 1* wordSize);
   349     debug_only(verify_stack_tag(frame::TagValue));
   350     popl(rdx);
   351     addl(rsp, 1* wordSize);
   352     pushl(rdx);
   353     pushl(rax);
   354   }
   355 }
   357 void InterpreterMacroAssembler::pop_ftos_to_rsp() {
   358   if (TaggedStackInterpreter) {
   359     debug_only(verify_stack_tag(frame::TagValue));
   360     popl(rax);
   361     addl(rsp, 1 * wordSize);
   362     pushl(rax);  // ftos is at rsp
   363   }
   364 }
   366 void InterpreterMacroAssembler::pop(TosState state) {
   367   switch (state) {
   368     case atos: pop_ptr(rax);                                 break;
   369     case btos:                                               // fall through
   370     case ctos:                                               // fall through
   371     case stos:                                               // fall through
   372     case itos: pop_i(rax);                                   break;
   373     case ltos: pop_l(rax, rdx);                              break;
   374     case ftos: pop_f();                                      break;
   375     case dtos: pop_d();                                      break;
   376     case vtos: /* nothing to do */                           break;
   377     default  : ShouldNotReachHere();
   378   }
   379   verify_oop(rax, state);
   380 }
   382 void InterpreterMacroAssembler::push_ptr(Register r) {
   383   if (TaggedStackInterpreter) pushl(frame::TagReference);
   384   pushl(r);
   385 }
   387 void InterpreterMacroAssembler::push_ptr(Register r, Register tag) {
   388   if (TaggedStackInterpreter) pushl(tag);  // tag first
   389   pushl(r);
   390 }
   392 void InterpreterMacroAssembler::push_i(Register r) {
   393   if (TaggedStackInterpreter) pushl(frame::TagValue);
   394   pushl(r);
   395 }
   397 void InterpreterMacroAssembler::push_l(Register lo, Register hi) {
   398   if (TaggedStackInterpreter) pushl(frame::TagValue);
   399   pushl(hi);
   400   if (TaggedStackInterpreter) pushl(frame::TagValue);
   401   pushl(lo);
   402 }
   404 void InterpreterMacroAssembler::push_f() {
   405   if (TaggedStackInterpreter) pushl(frame::TagValue);
   406   // Do not schedule for no AGI! Never write beyond rsp!
   407   subl(rsp, 1 * wordSize);
   408   fstp_s(Address(rsp, 0));
   409 }
   411 void InterpreterMacroAssembler::push_d(Register r) {
   412   if (TaggedStackInterpreter) {
   413     // Double values are stored as:
   414     //   tag
   415     //   high
   416     //   tag
   417     //   low
   418     pushl(frame::TagValue);
   419     subl(rsp, 3 * wordSize);
   420     fstp_d(Address(rsp, 0));
   421     // move high word up to slot n-1
   422     movl(r, Address(rsp, 1*wordSize));
   423     movl(Address(rsp, 2*wordSize), r);
   424     // move tag
   425     movl(Address(rsp, 1*wordSize), frame::TagValue);
   426   } else {
   427     // Do not schedule for no AGI! Never write beyond rsp!
   428     subl(rsp, 2 * wordSize);
   429     fstp_d(Address(rsp, 0));
   430   }
   431 }
   434 void InterpreterMacroAssembler::push(TosState state) {
   435   verify_oop(rax, state);
   436   switch (state) {
   437     case atos: push_ptr(rax); break;
   438     case btos:                                               // fall through
   439     case ctos:                                               // fall through
   440     case stos:                                               // fall through
   441     case itos: push_i(rax);                                    break;
   442     case ltos: push_l(rax, rdx);                               break;
   443     case ftos: push_f();                                       break;
   444     case dtos: push_d(rax);                                    break;
   445     case vtos: /* nothing to do */                             break;
   446     default  : ShouldNotReachHere();
   447   }
   448 }
   450 #ifndef CC_INTERP
   452 // Tagged stack helpers for swap and dup
   453 void InterpreterMacroAssembler::load_ptr_and_tag(int n, Register val,
   454                                                  Register tag) {
   455   movl(val, Address(rsp, Interpreter::expr_offset_in_bytes(n)));
   456   if (TaggedStackInterpreter) {
   457     movl(tag, Address(rsp, Interpreter::expr_tag_offset_in_bytes(n)));
   458   }
   459 }
   461 void InterpreterMacroAssembler::store_ptr_and_tag(int n, Register val,
   462                                                   Register tag) {
   463   movl(Address(rsp, Interpreter::expr_offset_in_bytes(n)), val);
   464   if (TaggedStackInterpreter) {
   465     movl(Address(rsp, Interpreter::expr_tag_offset_in_bytes(n)), tag);
   466   }
   467 }
   470 // Tagged local support
   471 void InterpreterMacroAssembler::tag_local(frame::Tag tag, int n) {
   472   if (TaggedStackInterpreter) {
   473     if (tag == frame::TagCategory2) {
   474       movl(Address(rdi, Interpreter::local_tag_offset_in_bytes(n+1)), (int)frame::TagValue);
   475       movl(Address(rdi, Interpreter::local_tag_offset_in_bytes(n)), (int)frame::TagValue);
   476     } else {
   477       movl(Address(rdi, Interpreter::local_tag_offset_in_bytes(n)), (int)tag);
   478     }
   479   }
   480 }
   482 void InterpreterMacroAssembler::tag_local(frame::Tag tag, Register idx) {
   483   if (TaggedStackInterpreter) {
   484     if (tag == frame::TagCategory2) {
   485       movl(Address(rdi, idx, Interpreter::stackElementScale(),
   486                   Interpreter::local_tag_offset_in_bytes(1)), (int)frame::TagValue);
   487       movl(Address(rdi, idx, Interpreter::stackElementScale(),
   488                   Interpreter::local_tag_offset_in_bytes(0)), (int)frame::TagValue);
   489     } else {
   490       movl(Address(rdi, idx, Interpreter::stackElementScale(),
   491                              Interpreter::local_tag_offset_in_bytes(0)), (int)tag);
   492     }
   493   }
   494 }
   496 void InterpreterMacroAssembler::tag_local(Register tag, Register idx) {
   497   if (TaggedStackInterpreter) {
   498     // can only be TagValue or TagReference
   499     movl(Address(rdi, idx, Interpreter::stackElementScale(),
   500                            Interpreter::local_tag_offset_in_bytes(0)), tag);
   501   }
   502 }
   505 void InterpreterMacroAssembler::tag_local(Register tag, int n) {
   506   if (TaggedStackInterpreter) {
   507     // can only be TagValue or TagReference
   508     movl(Address(rdi, Interpreter::local_tag_offset_in_bytes(n)), tag);
   509   }
   510 }
   512 #ifdef ASSERT
   513 void InterpreterMacroAssembler::verify_local_tag(frame::Tag tag, int n) {
   514   if (TaggedStackInterpreter) {
   515      frame::Tag t = tag;
   516     if (tag == frame::TagCategory2) {
   517       Label nbl;
   518       t = frame::TagValue;  // change to what is stored in locals
   519       cmpl(Address(rdi, Interpreter::local_tag_offset_in_bytes(n+1)), (int)t);
   520       jcc(Assembler::equal, nbl);
   521       stop("Local tag is bad for long/double");
   522       bind(nbl);
   523     }
   524     Label notBad;
   525     cmpl(Address(rdi, Interpreter::local_tag_offset_in_bytes(n)), (int)t);
   526     jcc(Assembler::equal, notBad);
   527     // Also compare if the local value is zero, then the tag might
   528     // not have been set coming from deopt.
   529     cmpl(Address(rdi, Interpreter::local_offset_in_bytes(n)), 0);
   530     jcc(Assembler::equal, notBad);
   531     stop("Local tag is bad");
   532     bind(notBad);
   533   }
   534 }
   536 void InterpreterMacroAssembler::verify_local_tag(frame::Tag tag, Register idx) {
   537   if (TaggedStackInterpreter) {
   538     frame::Tag t = tag;
   539     if (tag == frame::TagCategory2) {
   540       Label nbl;
   541       t = frame::TagValue;  // change to what is stored in locals
   542       cmpl(Address(rdi, idx, Interpreter::stackElementScale(),
   543                   Interpreter::local_tag_offset_in_bytes(1)), (int)t);
   544       jcc(Assembler::equal, nbl);
   545       stop("Local tag is bad for long/double");
   546       bind(nbl);
   547     }
   548     Label notBad;
   549     cmpl(Address(rdi, idx, Interpreter::stackElementScale(),
   550                   Interpreter::local_tag_offset_in_bytes(0)), (int)t);
   551     jcc(Assembler::equal, notBad);
   552     // Also compare if the local value is zero, then the tag might
   553     // not have been set coming from deopt.
   554     cmpl(Address(rdi, idx, Interpreter::stackElementScale(),
   555                   Interpreter::local_offset_in_bytes(0)), 0);
   556     jcc(Assembler::equal, notBad);
   557     stop("Local tag is bad");
   558     bind(notBad);
   560   }
   561 }
   562 #endif // ASSERT
   564 void InterpreterMacroAssembler::super_call_VM_leaf(address entry_point) {
   565   MacroAssembler::call_VM_leaf_base(entry_point, 0);
   566 }
   569 void InterpreterMacroAssembler::super_call_VM_leaf(address entry_point, Register arg_1) {
   570   pushl(arg_1);
   571   MacroAssembler::call_VM_leaf_base(entry_point, 1);
   572 }
   575 void InterpreterMacroAssembler::super_call_VM_leaf(address entry_point, Register arg_1, Register arg_2) {
   576   pushl(arg_2);
   577   pushl(arg_1);
   578   MacroAssembler::call_VM_leaf_base(entry_point, 2);
   579 }
   582 void InterpreterMacroAssembler::super_call_VM_leaf(address entry_point, Register arg_1, Register arg_2, Register arg_3) {
   583   pushl(arg_3);
   584   pushl(arg_2);
   585   pushl(arg_1);
   586   MacroAssembler::call_VM_leaf_base(entry_point, 3);
   587 }
   590 // Jump to from_interpreted entry of a call unless single stepping is possible
   591 // in this thread in which case we must call the i2i entry
   592 void InterpreterMacroAssembler::jump_from_interpreted(Register method, Register temp) {
   593   // set sender sp
   594   leal(rsi, Address(rsp, wordSize));
   595   // record last_sp
   596   movl(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), rsi);
   598   if (JvmtiExport::can_post_interpreter_events()) {
   599     Label run_compiled_code;
   600     // JVMTI events, such as single-stepping, are implemented partly by avoiding running
   601     // compiled code in threads for which the event is enabled.  Check here for
   602     // interp_only_mode if these events CAN be enabled.
   603     get_thread(temp);
   604     // interp_only is an int, on little endian it is sufficient to test the byte only
   605     // Is a cmpl faster (ce
   606     cmpb(Address(temp, JavaThread::interp_only_mode_offset()), 0);
   607     jcc(Assembler::zero, run_compiled_code);
   608     jmp(Address(method, methodOopDesc::interpreter_entry_offset()));
   609     bind(run_compiled_code);
   610   }
   612   jmp(Address(method, methodOopDesc::from_interpreted_offset()));
   614 }
   617 // The following two routines provide a hook so that an implementation
   618 // can schedule the dispatch in two parts.  Intel does not do this.
   619 void InterpreterMacroAssembler::dispatch_prolog(TosState state, int step) {
   620   // Nothing Intel-specific to be done here.
   621 }
   623 void InterpreterMacroAssembler::dispatch_epilog(TosState state, int step) {
   624   dispatch_next(state, step);
   625 }
   627 void InterpreterMacroAssembler::dispatch_base(TosState state, address* table,
   628                                               bool verifyoop) {
   629   verify_FPU(1, state);
   630   if (VerifyActivationFrameSize) {
   631     Label L;
   632     movl(rcx, rbp);
   633     subl(rcx, rsp);
   634     int min_frame_size = (frame::link_offset - frame::interpreter_frame_initial_sp_offset) * wordSize;
   635     cmpl(rcx, min_frame_size);
   636     jcc(Assembler::greaterEqual, L);
   637     stop("broken stack frame");
   638     bind(L);
   639   }
   640   if (verifyoop) verify_oop(rax, state);
   641   Address index(noreg, rbx, Address::times_4);
   642   ExternalAddress tbl((address)table);
   643   ArrayAddress dispatch(tbl, index);
   644   jump(dispatch);
   645 }
   648 void InterpreterMacroAssembler::dispatch_only(TosState state) {
   649   dispatch_base(state, Interpreter::dispatch_table(state));
   650 }
   653 void InterpreterMacroAssembler::dispatch_only_normal(TosState state) {
   654   dispatch_base(state, Interpreter::normal_table(state));
   655 }
   657 void InterpreterMacroAssembler::dispatch_only_noverify(TosState state) {
   658   dispatch_base(state, Interpreter::normal_table(state), false);
   659 }
   662 void InterpreterMacroAssembler::dispatch_next(TosState state, int step) {
   663   // load next bytecode (load before advancing rsi to prevent AGI)
   664   load_unsigned_byte(rbx, Address(rsi, step));
   665   // advance rsi
   666   increment(rsi, step);
   667   dispatch_base(state, Interpreter::dispatch_table(state));
   668 }
   671 void InterpreterMacroAssembler::dispatch_via(TosState state, address* table) {
   672   // load current bytecode
   673   load_unsigned_byte(rbx, Address(rsi, 0));
   674   dispatch_base(state, table);
   675 }
   677 // remove activation
   678 //
   679 // Unlock the receiver if this is a synchronized method.
   680 // Unlock any Java monitors from syncronized blocks.
   681 // Remove the activation from the stack.
   682 //
   683 // If there are locked Java monitors
   684 //    If throw_monitor_exception
   685 //       throws IllegalMonitorStateException
   686 //    Else if install_monitor_exception
   687 //       installs IllegalMonitorStateException
   688 //    Else
   689 //       no error processing
   690 void InterpreterMacroAssembler::remove_activation(TosState state, Register ret_addr,
   691                                                   bool throw_monitor_exception,
   692                                                   bool install_monitor_exception,
   693                                                   bool notify_jvmdi) {
   694   // Note: Registers rax, rdx and FPU ST(0) may be in use for the result
   695   // check if synchronized method
   696   Label unlocked, unlock, no_unlock;
   698   get_thread(rcx);
   699   const Address do_not_unlock_if_synchronized(rcx,
   700     in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
   702   movbool(rbx, do_not_unlock_if_synchronized);
   703   movl(rdi,rbx);
   704   movbool(do_not_unlock_if_synchronized, false); // reset the flag
   706   movl(rbx, Address(rbp, frame::interpreter_frame_method_offset * wordSize)); // get method access flags
   707   movl(rcx, Address(rbx, methodOopDesc::access_flags_offset()));
   709   testl(rcx, JVM_ACC_SYNCHRONIZED);
   710   jcc(Assembler::zero, unlocked);
   712   // Don't unlock anything if the _do_not_unlock_if_synchronized flag
   713   // is set.
   714   movl(rcx,rdi);
   715   testbool(rcx);
   716   jcc(Assembler::notZero, no_unlock);
   718   // unlock monitor
   719   push(state);                                   // save result
   721   // BasicObjectLock will be first in list, since this is a synchronized method. However, need
   722   // to check that the object has not been unlocked by an explicit monitorexit bytecode.
   723   const Address monitor(rbp, frame::interpreter_frame_initial_sp_offset * wordSize - (int)sizeof(BasicObjectLock));
   724   leal  (rdx, monitor);                          // address of first monitor
   726   movl  (rax, Address(rdx, BasicObjectLock::obj_offset_in_bytes()));
   727   testl (rax, rax);
   728   jcc   (Assembler::notZero, unlock);
   730   pop(state);
   731   if (throw_monitor_exception) {
   732     empty_FPU_stack();  // remove possible return value from FPU-stack, otherwise stack could overflow
   734     // Entry already unlocked, need to throw exception
   735     call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_illegal_monitor_state_exception));
   736     should_not_reach_here();
   737   } else {
   738     // Monitor already unlocked during a stack unroll.
   739     // If requested, install an illegal_monitor_state_exception.
   740     // Continue with stack unrolling.
   741     if (install_monitor_exception) {
   742       empty_FPU_stack();  // remove possible return value from FPU-stack, otherwise stack could overflow
   743       call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::new_illegal_monitor_state_exception));
   744     }
   745     jmp(unlocked);
   746   }
   748   bind(unlock);
   749   unlock_object(rdx);
   750   pop(state);
   752   // Check that for block-structured locking (i.e., that all locked objects has been unlocked)
   753   bind(unlocked);
   755   // rax, rdx: Might contain return value
   757   // Check that all monitors are unlocked
   758   {
   759     Label loop, exception, entry, restart;
   760     const int entry_size               = frame::interpreter_frame_monitor_size()           * wordSize;
   761     const Address monitor_block_top(rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
   762     const Address monitor_block_bot(rbp, frame::interpreter_frame_initial_sp_offset        * wordSize);
   764     bind(restart);
   765     movl(rcx, monitor_block_top);             // points to current entry, starting with top-most entry
   766     leal(rbx, monitor_block_bot);             // points to word before bottom of monitor block
   767     jmp(entry);
   769     // Entry already locked, need to throw exception
   770     bind(exception);
   772     if (throw_monitor_exception) {
   773       empty_FPU_stack();  // remove possible return value from FPU-stack, otherwise stack could overflow
   775       // Throw exception
   776       call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_illegal_monitor_state_exception));
   777       should_not_reach_here();
   778     } else {
   779       // Stack unrolling. Unlock object and install illegal_monitor_exception
   780       // Unlock does not block, so don't have to worry about the frame
   782       push(state);
   783       movl(rdx, rcx);
   784       unlock_object(rdx);
   785       pop(state);
   787       if (install_monitor_exception) {
   788         empty_FPU_stack();  // remove possible return value from FPU-stack, otherwise stack could overflow
   789         call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::new_illegal_monitor_state_exception));
   790       }
   792       jmp(restart);
   793     }
   795     bind(loop);
   796     cmpl(Address(rcx, BasicObjectLock::obj_offset_in_bytes()), NULL_WORD);  // check if current entry is used
   797     jcc(Assembler::notEqual, exception);
   799     addl(rcx, entry_size);                       // otherwise advance to next entry
   800     bind(entry);
   801     cmpl(rcx, rbx);                              // check if bottom reached
   802     jcc(Assembler::notEqual, loop);              // if not at bottom then check this entry
   803   }
   805   bind(no_unlock);
   807   // jvmti support
   808   if (notify_jvmdi) {
   809     notify_method_exit(state, NotifyJVMTI);     // preserve TOSCA
   810   } else {
   811     notify_method_exit(state, SkipNotifyJVMTI); // preserve TOSCA
   812   }
   814   // remove activation
   815   movl(rbx, Address(rbp, frame::interpreter_frame_sender_sp_offset * wordSize)); // get sender sp
   816   leave();                                     // remove frame anchor
   817   popl(ret_addr);                              // get return address
   818   movl(rsp, rbx);                              // set sp to sender sp
   819   if (UseSSE) {
   820     // float and double are returned in xmm register in SSE-mode
   821     if (state == ftos && UseSSE >= 1) {
   822       subl(rsp, wordSize);
   823       fstp_s(Address(rsp, 0));
   824       movflt(xmm0, Address(rsp, 0));
   825       addl(rsp, wordSize);
   826     } else if (state == dtos && UseSSE >= 2) {
   827       subl(rsp, 2*wordSize);
   828       fstp_d(Address(rsp, 0));
   829       movdbl(xmm0, Address(rsp, 0));
   830       addl(rsp, 2*wordSize);
   831     }
   832   }
   833 }
   835 #endif /* !CC_INTERP */
   838 // Lock object
   839 //
   840 // Argument: rdx : Points to BasicObjectLock to be used for locking. Must
   841 // be initialized with object to lock
   842 void InterpreterMacroAssembler::lock_object(Register lock_reg) {
   843   assert(lock_reg == rdx, "The argument is only for looks. It must be rdx");
   845   if (UseHeavyMonitors) {
   846     call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter), lock_reg);
   847   } else {
   849     Label done;
   851     const Register swap_reg = rax;  // Must use rax, for cmpxchg instruction
   852     const Register obj_reg  = rcx;  // Will contain the oop
   854     const int obj_offset = BasicObjectLock::obj_offset_in_bytes();
   855     const int lock_offset = BasicObjectLock::lock_offset_in_bytes ();
   856     const int mark_offset = lock_offset + BasicLock::displaced_header_offset_in_bytes();
   858     Label slow_case;
   860     // Load object pointer into obj_reg %rcx
   861     movl(obj_reg, Address(lock_reg, obj_offset));
   863     if (UseBiasedLocking) {
   864       // Note: we use noreg for the temporary register since it's hard
   865       // to come up with a free register on all incoming code paths
   866       biased_locking_enter(lock_reg, obj_reg, swap_reg, noreg, false, done, &slow_case);
   867     }
   869     // Load immediate 1 into swap_reg %rax,
   870     movl(swap_reg, 1);
   872     // Load (object->mark() | 1) into swap_reg %rax,
   873     orl(swap_reg, Address(obj_reg, 0));
   875     // Save (object->mark() | 1) into BasicLock's displaced header
   876     movl(Address(lock_reg, mark_offset), swap_reg);
   878     assert(lock_offset == 0, "displached header must be first word in BasicObjectLock");
   879     if (os::is_MP()) {
   880       lock();
   881     }
   882     cmpxchg(lock_reg, Address(obj_reg, 0));
   883     if (PrintBiasedLockingStatistics) {
   884       cond_inc32(Assembler::zero,
   885                  ExternalAddress((address) BiasedLocking::fast_path_entry_count_addr()));
   886     }
   887     jcc(Assembler::zero, done);
   889     // Test if the oopMark is an obvious stack pointer, i.e.,
   890     //  1) (mark & 3) == 0, and
   891     //  2) rsp <= mark < mark + os::pagesize()
   892     //
   893     // These 3 tests can be done by evaluating the following
   894     // expression: ((mark - rsp) & (3 - os::vm_page_size())),
   895     // assuming both stack pointer and pagesize have their
   896     // least significant 2 bits clear.
   897     // NOTE: the oopMark is in swap_reg %rax, as the result of cmpxchg
   898     subl(swap_reg, rsp);
   899     andl(swap_reg, 3 - os::vm_page_size());
   901     // Save the test result, for recursive case, the result is zero
   902     movl(Address(lock_reg, mark_offset), swap_reg);
   904     if (PrintBiasedLockingStatistics) {
   905       cond_inc32(Assembler::zero,
   906                  ExternalAddress((address) BiasedLocking::fast_path_entry_count_addr()));
   907     }
   908     jcc(Assembler::zero, done);
   910     bind(slow_case);
   912     // Call the runtime routine for slow case
   913     call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter), lock_reg);
   915     bind(done);
   916   }
   917 }
   920 // Unlocks an object. Used in monitorexit bytecode and remove_activation.
   921 //
   922 // Argument: rdx : Points to BasicObjectLock structure for lock
   923 // Throw an IllegalMonitorException if object is not locked by current thread
   924 //
   925 // Uses: rax, rbx, rcx, rdx
   926 void InterpreterMacroAssembler::unlock_object(Register lock_reg) {
   927   assert(lock_reg == rdx, "The argument is only for looks. It must be rdx");
   929   if (UseHeavyMonitors) {
   930     call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), lock_reg);
   931   } else {
   932     Label done;
   934     const Register swap_reg   = rax;  // Must use rax, for cmpxchg instruction
   935     const Register header_reg = rbx;  // Will contain the old oopMark
   936     const Register obj_reg    = rcx;  // Will contain the oop
   938     save_bcp(); // Save in case of exception
   940     // Convert from BasicObjectLock structure to object and BasicLock structure
   941     // Store the BasicLock address into %rax,
   942     leal(swap_reg, Address(lock_reg, BasicObjectLock::lock_offset_in_bytes()));
   944     // Load oop into obj_reg(%rcx)
   945     movl(obj_reg, Address(lock_reg, BasicObjectLock::obj_offset_in_bytes ()));
   947     // Free entry
   948     movl(Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()), NULL_WORD);
   950     if (UseBiasedLocking) {
   951       biased_locking_exit(obj_reg, header_reg, done);
   952     }
   954     // Load the old header from BasicLock structure
   955     movl(header_reg, Address(swap_reg, BasicLock::displaced_header_offset_in_bytes()));
   957     // Test for recursion
   958     testl(header_reg, header_reg);
   960     // zero for recursive case
   961     jcc(Assembler::zero, done);
   963     // Atomic swap back the old header
   964     if (os::is_MP()) lock();
   965     cmpxchg(header_reg, Address(obj_reg, 0));
   967     // zero for recursive case
   968     jcc(Assembler::zero, done);
   970     // Call the runtime routine for slow case.
   971     movl(Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()), obj_reg); // restore obj
   972     call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), lock_reg);
   974     bind(done);
   976     restore_bcp();
   977   }
   978 }
   981 #ifndef CC_INTERP
   983 // Test ImethodDataPtr.  If it is null, continue at the specified label
   984 void InterpreterMacroAssembler::test_method_data_pointer(Register mdp, Label& zero_continue) {
   985   assert(ProfileInterpreter, "must be profiling interpreter");
   986   movl(mdp, Address(rbp, frame::interpreter_frame_mdx_offset * wordSize));
   987   testl(mdp, mdp);
   988   jcc(Assembler::zero, zero_continue);
   989 }
   992 // Set the method data pointer for the current bcp.
   993 void InterpreterMacroAssembler::set_method_data_pointer_for_bcp() {
   994   assert(ProfileInterpreter, "must be profiling interpreter");
   995   Label zero_continue;
   996   pushl(rax);
   997   pushl(rbx);
   999   get_method(rbx);
  1000   // Test MDO to avoid the call if it is NULL.
  1001   movl(rax, Address(rbx, in_bytes(methodOopDesc::method_data_offset())));
  1002   testl(rax, rax);
  1003   jcc(Assembler::zero, zero_continue);
  1005   // rbx,: method
  1006   // rsi: bcp
  1007   call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::bcp_to_di), rbx, rsi);
  1008   // rax,: mdi
  1010   movl(rbx, Address(rbx, in_bytes(methodOopDesc::method_data_offset())));
  1011   testl(rbx, rbx);
  1012   jcc(Assembler::zero, zero_continue);
  1013   addl(rbx, in_bytes(methodDataOopDesc::data_offset()));
  1014   addl(rbx, rax);
  1015   movl(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), rbx);
  1017   bind(zero_continue);
  1018   popl(rbx);
  1019   popl(rax);
  1022 void InterpreterMacroAssembler::verify_method_data_pointer() {
  1023   assert(ProfileInterpreter, "must be profiling interpreter");
  1024 #ifdef ASSERT
  1025   Label verify_continue;
  1026   pushl(rax);
  1027   pushl(rbx);
  1028   pushl(rcx);
  1029   pushl(rdx);
  1030   test_method_data_pointer(rcx, verify_continue); // If mdp is zero, continue
  1031   get_method(rbx);
  1033   // If the mdp is valid, it will point to a DataLayout header which is
  1034   // consistent with the bcp.  The converse is highly probable also.
  1035   load_unsigned_word(rdx, Address(rcx, in_bytes(DataLayout::bci_offset())));
  1036   addl(rdx, Address(rbx, methodOopDesc::const_offset()));
  1037   leal(rdx, Address(rdx, constMethodOopDesc::codes_offset()));
  1038   cmpl(rdx, rsi);
  1039   jcc(Assembler::equal, verify_continue);
  1040   // rbx,: method
  1041   // rsi: bcp
  1042   // rcx: mdp
  1043   call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::verify_mdp), rbx, rsi, rcx);
  1044   bind(verify_continue);
  1045   popl(rdx);
  1046   popl(rcx);
  1047   popl(rbx);
  1048   popl(rax);
  1049 #endif // ASSERT
  1053 void InterpreterMacroAssembler::set_mdp_data_at(Register mdp_in, int constant, Register value) {
  1054   assert(ProfileInterpreter, "must be profiling interpreter");
  1055   Address data(mdp_in, constant);
  1056   movl(data, value);
  1060 void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in,
  1061                                                       int constant,
  1062                                                       bool decrement) {
  1063   // Counter address
  1064   Address data(mdp_in, constant);
  1066   increment_mdp_data_at(data, decrement);
  1070 void InterpreterMacroAssembler::increment_mdp_data_at(Address data,
  1071                                                       bool decrement) {
  1073   assert( DataLayout::counter_increment==1, "flow-free idiom only works with 1" );
  1074   assert(ProfileInterpreter, "must be profiling interpreter");
  1076   if (decrement) {
  1077     // Decrement the register.  Set condition codes.
  1078     addl(data, -DataLayout::counter_increment);
  1079     // If the decrement causes the counter to overflow, stay negative
  1080     Label L;
  1081     jcc(Assembler::negative, L);
  1082     addl(data, DataLayout::counter_increment);
  1083     bind(L);
  1084   } else {
  1085     assert(DataLayout::counter_increment == 1,
  1086            "flow-free idiom only works with 1");
  1087     // Increment the register.  Set carry flag.
  1088     addl(data, DataLayout::counter_increment);
  1089     // If the increment causes the counter to overflow, pull back by 1.
  1090     sbbl(data, 0);
  1095 void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in,
  1096                                                       Register reg,
  1097                                                       int constant,
  1098                                                       bool decrement) {
  1099   Address data(mdp_in, reg, Address::times_1, constant);
  1101   increment_mdp_data_at(data, decrement);
  1105 void InterpreterMacroAssembler::set_mdp_flag_at(Register mdp_in, int flag_byte_constant) {
  1106   assert(ProfileInterpreter, "must be profiling interpreter");
  1107   int header_offset = in_bytes(DataLayout::header_offset());
  1108   int header_bits = DataLayout::flag_mask_to_header_mask(flag_byte_constant);
  1109   // Set the flag
  1110   orl(Address(mdp_in, header_offset), header_bits);
  1115 void InterpreterMacroAssembler::test_mdp_data_at(Register mdp_in,
  1116                                                  int offset,
  1117                                                  Register value,
  1118                                                  Register test_value_out,
  1119                                                  Label& not_equal_continue) {
  1120   assert(ProfileInterpreter, "must be profiling interpreter");
  1121   if (test_value_out == noreg) {
  1122     cmpl(value, Address(mdp_in, offset));
  1123   } else {
  1124     // Put the test value into a register, so caller can use it:
  1125     movl(test_value_out, Address(mdp_in, offset));
  1126     cmpl(test_value_out, value);
  1128   jcc(Assembler::notEqual, not_equal_continue);
  1132 void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in, int offset_of_disp) {
  1133   assert(ProfileInterpreter, "must be profiling interpreter");
  1134   Address disp_address(mdp_in, offset_of_disp);
  1135   addl(mdp_in,disp_address);
  1136   movl(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), mdp_in);
  1140 void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in, Register reg, int offset_of_disp) {
  1141   assert(ProfileInterpreter, "must be profiling interpreter");
  1142   Address disp_address(mdp_in, reg, Address::times_1, offset_of_disp);
  1143   addl(mdp_in, disp_address);
  1144   movl(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), mdp_in);
  1148 void InterpreterMacroAssembler::update_mdp_by_constant(Register mdp_in, int constant) {
  1149   assert(ProfileInterpreter, "must be profiling interpreter");
  1150   addl(mdp_in, constant);
  1151   movl(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), mdp_in);
  1155 void InterpreterMacroAssembler::update_mdp_for_ret(Register return_bci) {
  1156   assert(ProfileInterpreter, "must be profiling interpreter");
  1157   pushl(return_bci);             // save/restore across call_VM
  1158   call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::update_mdp_for_ret), return_bci);
  1159   popl(return_bci);
  1163 void InterpreterMacroAssembler::profile_taken_branch(Register mdp, Register bumped_count) {
  1164   if (ProfileInterpreter) {
  1165     Label profile_continue;
  1167     // If no method data exists, go to profile_continue.
  1168     // Otherwise, assign to mdp
  1169     test_method_data_pointer(mdp, profile_continue);
  1171     // We are taking a branch.  Increment the taken count.
  1172     // We inline increment_mdp_data_at to return bumped_count in a register
  1173     //increment_mdp_data_at(mdp, in_bytes(JumpData::taken_offset()));
  1174     Address data(mdp, in_bytes(JumpData::taken_offset()));
  1175     movl(bumped_count,data);
  1176     assert( DataLayout::counter_increment==1, "flow-free idiom only works with 1" );
  1177     addl(bumped_count, DataLayout::counter_increment);
  1178     sbbl(bumped_count, 0);
  1179     movl(data,bumped_count);    // Store back out
  1181     // The method data pointer needs to be updated to reflect the new target.
  1182     update_mdp_by_offset(mdp, in_bytes(JumpData::displacement_offset()));
  1183     bind (profile_continue);
  1188 void InterpreterMacroAssembler::profile_not_taken_branch(Register mdp) {
  1189   if (ProfileInterpreter) {
  1190     Label profile_continue;
  1192     // If no method data exists, go to profile_continue.
  1193     test_method_data_pointer(mdp, profile_continue);
  1195     // We are taking a branch.  Increment the not taken count.
  1196     increment_mdp_data_at(mdp, in_bytes(BranchData::not_taken_offset()));
  1198     // The method data pointer needs to be updated to correspond to the next bytecode
  1199     update_mdp_by_constant(mdp, in_bytes(BranchData::branch_data_size()));
  1200     bind (profile_continue);
  1205 void InterpreterMacroAssembler::profile_call(Register mdp) {
  1206   if (ProfileInterpreter) {
  1207     Label profile_continue;
  1209     // If no method data exists, go to profile_continue.
  1210     test_method_data_pointer(mdp, profile_continue);
  1212     // We are making a call.  Increment the count.
  1213     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
  1215     // The method data pointer needs to be updated to reflect the new target.
  1216     update_mdp_by_constant(mdp, in_bytes(CounterData::counter_data_size()));
  1217     bind (profile_continue);
  1222 void InterpreterMacroAssembler::profile_final_call(Register mdp) {
  1223   if (ProfileInterpreter) {
  1224     Label profile_continue;
  1226     // If no method data exists, go to profile_continue.
  1227     test_method_data_pointer(mdp, profile_continue);
  1229     // We are making a call.  Increment the count.
  1230     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
  1232     // The method data pointer needs to be updated to reflect the new target.
  1233     update_mdp_by_constant(mdp, in_bytes(VirtualCallData::virtual_call_data_size()));
  1234     bind (profile_continue);
  1239 void InterpreterMacroAssembler::profile_virtual_call(Register receiver, Register mdp, Register reg2) {
  1240   if (ProfileInterpreter) {
  1241     Label profile_continue;
  1243     // If no method data exists, go to profile_continue.
  1244     test_method_data_pointer(mdp, profile_continue);
  1246     // We are making a call.  Increment the count.
  1247     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
  1249     // Record the receiver type.
  1250     record_klass_in_profile(receiver, mdp, reg2);
  1252     // The method data pointer needs to be updated to reflect the new target.
  1253     update_mdp_by_constant(mdp,
  1254                            in_bytes(VirtualCallData::
  1255                                     virtual_call_data_size()));
  1256     bind(profile_continue);
  1261 void InterpreterMacroAssembler::record_klass_in_profile_helper(
  1262                                         Register receiver, Register mdp,
  1263                                         Register reg2,
  1264                                         int start_row, Label& done) {
  1265   int last_row = VirtualCallData::row_limit() - 1;
  1266   assert(start_row <= last_row, "must be work left to do");
  1267   // Test this row for both the receiver and for null.
  1268   // Take any of three different outcomes:
  1269   //   1. found receiver => increment count and goto done
  1270   //   2. found null => keep looking for case 1, maybe allocate this cell
  1271   //   3. found something else => keep looking for cases 1 and 2
  1272   // Case 3 is handled by a recursive call.
  1273   for (int row = start_row; row <= last_row; row++) {
  1274     Label next_test;
  1275     bool test_for_null_also = (row == start_row);
  1277     // See if the receiver is receiver[n].
  1278     int recvr_offset = in_bytes(VirtualCallData::receiver_offset(row));
  1279     test_mdp_data_at(mdp, recvr_offset, receiver,
  1280                      (test_for_null_also ? reg2 : noreg),
  1281                      next_test);
  1282     // (Reg2 now contains the receiver from the CallData.)
  1284     // The receiver is receiver[n].  Increment count[n].
  1285     int count_offset = in_bytes(VirtualCallData::receiver_count_offset(row));
  1286     increment_mdp_data_at(mdp, count_offset);
  1287     jmp(done);
  1288     bind(next_test);
  1290     if (row == start_row) {
  1291       // Failed the equality check on receiver[n]...  Test for null.
  1292       testl(reg2, reg2);
  1293       if (start_row == last_row) {
  1294         // The only thing left to do is handle the null case.
  1295         jcc(Assembler::notZero, done);
  1296         break;
  1298       // Since null is rare, make it be the branch-taken case.
  1299       Label found_null;
  1300       jcc(Assembler::zero, found_null);
  1302       // Put all the "Case 3" tests here.
  1303       record_klass_in_profile_helper(receiver, mdp, reg2, start_row + 1, done);
  1305       // Found a null.  Keep searching for a matching receiver,
  1306       // but remember that this is an empty (unused) slot.
  1307       bind(found_null);
  1311   // In the fall-through case, we found no matching receiver, but we
  1312   // observed the receiver[start_row] is NULL.
  1314   // Fill in the receiver field and increment the count.
  1315   int recvr_offset = in_bytes(VirtualCallData::receiver_offset(start_row));
  1316   set_mdp_data_at(mdp, recvr_offset, receiver);
  1317   int count_offset = in_bytes(VirtualCallData::receiver_count_offset(start_row));
  1318   movl(reg2, DataLayout::counter_increment);
  1319   set_mdp_data_at(mdp, count_offset, reg2);
  1320   jmp(done);
  1323 void InterpreterMacroAssembler::record_klass_in_profile(Register receiver,
  1324                                                         Register mdp,
  1325                                                         Register reg2) {
  1326   assert(ProfileInterpreter, "must be profiling");
  1327   Label done;
  1329   record_klass_in_profile_helper(receiver, mdp, reg2, 0, done);
  1331   bind (done);
  1334 void InterpreterMacroAssembler::profile_ret(Register return_bci, Register mdp) {
  1335   if (ProfileInterpreter) {
  1336     Label profile_continue;
  1337     uint row;
  1339     // If no method data exists, go to profile_continue.
  1340     test_method_data_pointer(mdp, profile_continue);
  1342     // Update the total ret count.
  1343     increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));
  1345     for (row = 0; row < RetData::row_limit(); row++) {
  1346       Label next_test;
  1348       // See if return_bci is equal to bci[n]:
  1349       test_mdp_data_at(mdp, in_bytes(RetData::bci_offset(row)), return_bci,
  1350                        noreg, next_test);
  1352       // return_bci is equal to bci[n].  Increment the count.
  1353       increment_mdp_data_at(mdp, in_bytes(RetData::bci_count_offset(row)));
  1355       // The method data pointer needs to be updated to reflect the new target.
  1356       update_mdp_by_offset(mdp, in_bytes(RetData::bci_displacement_offset(row)));
  1357       jmp(profile_continue);
  1358       bind(next_test);
  1361     update_mdp_for_ret(return_bci);
  1363     bind (profile_continue);
  1368 void InterpreterMacroAssembler::profile_null_seen(Register mdp) {
  1369   if (ProfileInterpreter) {
  1370     Label profile_continue;
  1372     // If no method data exists, go to profile_continue.
  1373     test_method_data_pointer(mdp, profile_continue);
  1375     // The method data pointer needs to be updated.
  1376     int mdp_delta = in_bytes(BitData::bit_data_size());
  1377     if (TypeProfileCasts) {
  1378       mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
  1380     update_mdp_by_constant(mdp, mdp_delta);
  1382     bind (profile_continue);
  1387 void InterpreterMacroAssembler::profile_typecheck_failed(Register mdp) {
  1388   if (ProfileInterpreter && TypeProfileCasts) {
  1389     Label profile_continue;
  1391     // If no method data exists, go to profile_continue.
  1392     test_method_data_pointer(mdp, profile_continue);
  1394     int count_offset = in_bytes(CounterData::count_offset());
  1395     // Back up the address, since we have already bumped the mdp.
  1396     count_offset -= in_bytes(VirtualCallData::virtual_call_data_size());
  1398     // *Decrement* the counter.  We expect to see zero or small negatives.
  1399     increment_mdp_data_at(mdp, count_offset, true);
  1401     bind (profile_continue);
  1406 void InterpreterMacroAssembler::profile_typecheck(Register mdp, Register klass, Register reg2)
  1408   if (ProfileInterpreter) {
  1409     Label profile_continue;
  1411     // If no method data exists, go to profile_continue.
  1412     test_method_data_pointer(mdp, profile_continue);
  1414     // The method data pointer needs to be updated.
  1415     int mdp_delta = in_bytes(BitData::bit_data_size());
  1416     if (TypeProfileCasts) {
  1417       mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
  1419       // Record the object type.
  1420       record_klass_in_profile(klass, mdp, reg2);
  1421       assert(reg2 == rdi, "we know how to fix this blown reg");
  1422       restore_locals();         // Restore EDI
  1424     update_mdp_by_constant(mdp, mdp_delta);
  1426     bind(profile_continue);
  1431 void InterpreterMacroAssembler::profile_switch_default(Register mdp) {
  1432   if (ProfileInterpreter) {
  1433     Label profile_continue;
  1435     // If no method data exists, go to profile_continue.
  1436     test_method_data_pointer(mdp, profile_continue);
  1438     // Update the default case count
  1439     increment_mdp_data_at(mdp, in_bytes(MultiBranchData::default_count_offset()));
  1441     // The method data pointer needs to be updated.
  1442     update_mdp_by_offset(mdp, in_bytes(MultiBranchData::default_displacement_offset()));
  1444     bind (profile_continue);
  1449 void InterpreterMacroAssembler::profile_switch_case(Register index, Register mdp, Register reg2) {
  1450   if (ProfileInterpreter) {
  1451     Label profile_continue;
  1453     // If no method data exists, go to profile_continue.
  1454     test_method_data_pointer(mdp, profile_continue);
  1456     // Build the base (index * per_case_size_in_bytes()) + case_array_offset_in_bytes()
  1457     movl(reg2, in_bytes(MultiBranchData::per_case_size()));
  1458     imull(index, reg2);
  1459     addl(index, in_bytes(MultiBranchData::case_array_offset()));
  1461     // Update the case count
  1462     increment_mdp_data_at(mdp, index, in_bytes(MultiBranchData::relative_count_offset()));
  1464     // The method data pointer needs to be updated.
  1465     update_mdp_by_offset(mdp, index, in_bytes(MultiBranchData::relative_displacement_offset()));
  1467     bind (profile_continue);
  1471 #endif // !CC_INTERP
  1475 void InterpreterMacroAssembler::verify_oop(Register reg, TosState state) {
  1476   if (state == atos) MacroAssembler::verify_oop(reg);
  1480 #ifndef CC_INTERP
  1481 void InterpreterMacroAssembler::verify_FPU(int stack_depth, TosState state) {
  1482   if (state == ftos || state == dtos) MacroAssembler::verify_FPU(stack_depth);
  1485 #endif /* CC_INTERP */
  1488 void InterpreterMacroAssembler::notify_method_entry() {
  1489   // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to
  1490   // track stack depth.  If it is possible to enter interp_only_mode we add
  1491   // the code to check if the event should be sent.
  1492   if (JvmtiExport::can_post_interpreter_events()) {
  1493     Label L;
  1494     get_thread(rcx);
  1495     movl(rcx, Address(rcx, JavaThread::interp_only_mode_offset()));
  1496     testl(rcx,rcx);
  1497     jcc(Assembler::zero, L);
  1498     call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_entry));
  1499     bind(L);
  1503     SkipIfEqual skip_if(this, &DTraceMethodProbes, 0);
  1504     get_thread(rcx);
  1505     get_method(rbx);
  1506     call_VM_leaf(
  1507       CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry), rcx, rbx);
  1512 void InterpreterMacroAssembler::notify_method_exit(
  1513     TosState state, NotifyMethodExitMode mode) {
  1514   // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to
  1515   // track stack depth.  If it is possible to enter interp_only_mode we add
  1516   // the code to check if the event should be sent.
  1517   if (mode == NotifyJVMTI && JvmtiExport::can_post_interpreter_events()) {
  1518     Label L;
  1519     // Note: frame::interpreter_frame_result has a dependency on how the
  1520     // method result is saved across the call to post_method_exit. If this
  1521     // is changed then the interpreter_frame_result implementation will
  1522     // need to be updated too.
  1524     // For c++ interpreter the result is always stored at a known location in the frame
  1525     // template interpreter will leave it on the top of the stack.
  1526     NOT_CC_INTERP(push(state);)
  1527     get_thread(rcx);
  1528     movl(rcx, Address(rcx, JavaThread::interp_only_mode_offset()));
  1529     testl(rcx,rcx);
  1530     jcc(Assembler::zero, L);
  1531     call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_exit));
  1532     bind(L);
  1533     NOT_CC_INTERP(pop(state);)
  1537     SkipIfEqual skip_if(this, &DTraceMethodProbes, 0);
  1538     push(state);
  1539     get_thread(rbx);
  1540     get_method(rcx);
  1541     call_VM_leaf(
  1542       CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit),
  1543       rbx, rcx);
  1544     pop(state);

mercurial