src/cpu/sparc/vm/vtableStubs_sparc.cpp

Tue, 24 Jul 2012 10:51:00 -0700

author
twisti
date
Tue, 24 Jul 2012 10:51:00 -0700
changeset 3969
1d7922586cf6
parent 3310
6729bbc1fcd6
child 4037
da91efe96a93
permissions
-rw-r--r--

7023639: JSR 292 method handle invocation needs a fast path for compiled code
6984705: JSR 292 method handle creation should not go through JNI
Summary: remove assembly code for JDK 7 chained method handles
Reviewed-by: jrose, twisti, kvn, mhaupt
Contributed-by: John Rose <john.r.rose@oracle.com>, Christian Thalinger <christian.thalinger@oracle.com>, Michael Haupt <michael.haupt@oracle.com>

     1 /*
     2  * Copyright (c) 1997, 2011, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  *
    23  */
    25 #include "precompiled.hpp"
    26 #include "asm/assembler.hpp"
    27 #include "assembler_sparc.inline.hpp"
    28 #include "code/vtableStubs.hpp"
    29 #include "interp_masm_sparc.hpp"
    30 #include "memory/resourceArea.hpp"
    31 #include "oops/instanceKlass.hpp"
    32 #include "oops/klassVtable.hpp"
    33 #include "runtime/sharedRuntime.hpp"
    34 #include "vmreg_sparc.inline.hpp"
    35 #ifdef COMPILER2
    36 #include "opto/runtime.hpp"
    37 #endif
    39 // machine-dependent part of VtableStubs: create vtableStub of correct size and
    40 // initialize its code
    42 #define __ masm->
    45 #ifndef PRODUCT
    46 extern "C" void bad_compiled_vtable_index(JavaThread* thread, oopDesc* receiver, int index);
    47 #endif
    50 // Used by compiler only; may use only caller saved, non-argument registers
    51 // NOTE:  %%%% if any change is made to this stub make sure that the function
    52 //             pd_code_size_limit is changed to ensure the correct size for VtableStub
    53 VtableStub* VtableStubs::create_vtable_stub(int vtable_index) {
    54   const int sparc_code_length = VtableStub::pd_code_size_limit(true);
    55   VtableStub* s = new(sparc_code_length) VtableStub(true, vtable_index);
    56   ResourceMark rm;
    57   CodeBuffer cb(s->entry_point(), sparc_code_length);
    58   MacroAssembler* masm = new MacroAssembler(&cb);
    60 #ifndef PRODUCT
    61   if (CountCompiledCalls) {
    62     __ inc_counter(SharedRuntime::nof_megamorphic_calls_addr(), G5, G3_scratch);
    63   }
    64 #endif /* PRODUCT */
    66   assert(VtableStub::receiver_location() == O0->as_VMReg(), "receiver expected in O0");
    68   // get receiver klass
    69   address npe_addr = __ pc();
    70   __ load_klass(O0, G3_scratch);
    72   // set methodOop (in case of interpreted method), and destination address
    73 #ifndef PRODUCT
    74   if (DebugVtables) {
    75     Label L;
    76     // check offset vs vtable length
    77     __ ld(G3_scratch, instanceKlass::vtable_length_offset()*wordSize, G5);
    78     __ cmp_and_br_short(G5, vtable_index*vtableEntry::size(), Assembler::greaterUnsigned, Assembler::pt, L);
    79     __ set(vtable_index, O2);
    80     __ call_VM(noreg, CAST_FROM_FN_PTR(address, bad_compiled_vtable_index), O0, O2);
    81     __ bind(L);
    82   }
    83 #endif
    85   __ lookup_virtual_method(G3_scratch, vtable_index, G5_method);
    87 #ifndef PRODUCT
    88   if (DebugVtables) {
    89     Label L;
    90     __ br_notnull_short(G5_method, Assembler::pt, L);
    91     __ stop("Vtable entry is ZERO");
    92     __ bind(L);
    93   }
    94 #endif
    96   address ame_addr = __ pc();  // if the vtable entry is null, the method is abstract
    97                                // NOTE: for vtable dispatches, the vtable entry will never be null.
    99   __ ld_ptr(G5_method, in_bytes(methodOopDesc::from_compiled_offset()), G3_scratch);
   101   // jump to target (either compiled code or c2iadapter)
   102   __ JMP(G3_scratch, 0);
   103   // load methodOop (in case we call c2iadapter)
   104   __ delayed()->nop();
   106   masm->flush();
   108   if (PrintMiscellaneous && (WizardMode || Verbose)) {
   109     tty->print_cr("vtable #%d at "PTR_FORMAT"[%d] left over: %d",
   110                   vtable_index, s->entry_point(),
   111                   (int)(s->code_end() - s->entry_point()),
   112                   (int)(s->code_end() - __ pc()));
   113   }
   114   guarantee(__ pc() <= s->code_end(), "overflowed buffer");
   115   // shut the door on sizing bugs
   116   int slop = 2*BytesPerInstWord;  // 32-bit offset is this much larger than a 13-bit one
   117   assert(vtable_index > 10 || __ pc() + slop <= s->code_end(), "room for sethi;add");
   119   s->set_exception_points(npe_addr, ame_addr);
   120   return s;
   121 }
   124 // NOTE:  %%%% if any change is made to this stub make sure that the function
   125 //             pd_code_size_limit is changed to ensure the correct size for VtableStub
   126 VtableStub* VtableStubs::create_itable_stub(int itable_index) {
   127   const int sparc_code_length = VtableStub::pd_code_size_limit(false);
   128   VtableStub* s = new(sparc_code_length) VtableStub(false, itable_index);
   129   ResourceMark rm;
   130   CodeBuffer cb(s->entry_point(), sparc_code_length);
   131   MacroAssembler* masm = new MacroAssembler(&cb);
   133   Register G3_klassOop = G3_scratch;
   134   Register G5_interface = G5;  // Passed in as an argument
   135   Label search;
   137   // Entry arguments:
   138   //  G5_interface: Interface
   139   //  O0:           Receiver
   140   assert(VtableStub::receiver_location() == O0->as_VMReg(), "receiver expected in O0");
   142   // get receiver klass (also an implicit null-check)
   143   address npe_addr = __ pc();
   144   __ load_klass(O0, G3_klassOop);
   145   __ verify_oop(G3_klassOop);
   147   // Push a new window to get some temp registers.  This chops the head of all
   148   // my 64-bit %o registers in the LION build, but this is OK because no longs
   149   // are passed in the %o registers.  Instead, longs are passed in G1 and G4
   150   // and so those registers are not available here.
   151   __ save(SP,-frame::register_save_words*wordSize,SP);
   153 #ifndef PRODUCT
   154   if (CountCompiledCalls) {
   155     __ inc_counter(SharedRuntime::nof_megamorphic_calls_addr(), L0, L1);
   156   }
   157 #endif /* PRODUCT */
   159   Label throw_icce;
   161   Register L5_method = L5;
   162   __ lookup_interface_method(// inputs: rec. class, interface, itable index
   163                              G3_klassOop, G5_interface, itable_index,
   164                              // outputs: method, scan temp. reg
   165                              L5_method, L2, L3,
   166                              throw_icce);
   168 #ifndef PRODUCT
   169   if (DebugVtables) {
   170     Label L01;
   171     __ br_notnull_short(L5_method, Assembler::pt, L01);
   172     __ stop("methodOop is null");
   173     __ bind(L01);
   174     __ verify_oop(L5_method);
   175   }
   176 #endif
   178   // If the following load is through a NULL pointer, we'll take an OS
   179   // exception that should translate into an AbstractMethodError.  We need the
   180   // window count to be correct at that time.
   181   __ restore(L5_method, 0, G5_method);
   182   // Restore registers *before* the AME point.
   184   address ame_addr = __ pc();   // if the vtable entry is null, the method is abstract
   185   __ ld_ptr(G5_method, in_bytes(methodOopDesc::from_compiled_offset()), G3_scratch);
   187   // G5_method:  methodOop
   188   // O0:         Receiver
   189   // G3_scratch: entry point
   190   __ JMP(G3_scratch, 0);
   191   __ delayed()->nop();
   193   __ bind(throw_icce);
   194   AddressLiteral icce(StubRoutines::throw_IncompatibleClassChangeError_entry());
   195   __ jump_to(icce, G3_scratch);
   196   __ delayed()->restore();
   198   masm->flush();
   200   if (PrintMiscellaneous && (WizardMode || Verbose)) {
   201     tty->print_cr("itable #%d at "PTR_FORMAT"[%d] left over: %d",
   202                   itable_index, s->entry_point(),
   203                   (int)(s->code_end() - s->entry_point()),
   204                   (int)(s->code_end() - __ pc()));
   205   }
   206   guarantee(__ pc() <= s->code_end(), "overflowed buffer");
   207   // shut the door on sizing bugs
   208   int slop = 2*BytesPerInstWord;  // 32-bit offset is this much larger than a 13-bit one
   209   assert(itable_index > 10 || __ pc() + slop <= s->code_end(), "room for sethi;add");
   211   s->set_exception_points(npe_addr, ame_addr);
   212   return s;
   213 }
   216 int VtableStub::pd_code_size_limit(bool is_vtable_stub) {
   217   if (TraceJumps || DebugVtables || CountCompiledCalls || VerifyOops) return 1000;
   218   else {
   219     const int slop = 2*BytesPerInstWord; // sethi;add  (needed for long offsets)
   220     if (is_vtable_stub) {
   221       // ld;ld;ld,jmp,nop
   222       const int basic = 5*BytesPerInstWord +
   223                         // shift;add for load_klass (only shift with zero heap based)
   224                         (UseCompressedOops ?
   225                          ((Universe::narrow_oop_base() == NULL) ? BytesPerInstWord : 2*BytesPerInstWord) : 0);
   226       return basic + slop;
   227     } else {
   228       const int basic = (28 LP64_ONLY(+ 6)) * BytesPerInstWord +
   229                         // shift;add for load_klass (only shift with zero heap based)
   230                         (UseCompressedOops ?
   231                          ((Universe::narrow_oop_base() == NULL) ? BytesPerInstWord : 2*BytesPerInstWord) : 0);
   232       return (basic + slop);
   233     }
   234   }
   236   // In order to tune these parameters, run the JVM with VM options
   237   // +PrintMiscellaneous and +WizardMode to see information about
   238   // actual itable stubs.  Look for lines like this:
   239   //   itable #1 at 0x5551212[116] left over: 8
   240   // Reduce the constants so that the "left over" number is 8
   241   // Do not aim at a left-over number of zero, because a very
   242   // large vtable or itable offset (> 4K) will require an extra
   243   // sethi/or pair of instructions.
   244   //
   245   // The JVM98 app. _202_jess has a megamorphic interface call.
   246   // The itable code looks like this:
   247   // Decoding VtableStub itbl[1]@16
   248   //   ld  [ %o0 + 4 ], %g3
   249   //   save  %sp, -64, %sp
   250   //   ld  [ %g3 + 0xe8 ], %l2
   251   //   sll  %l2, 2, %l2
   252   //   add  %l2, 0x134, %l2
   253   //   and  %l2, -8, %l2        ! NOT_LP64 only
   254   //   add  %g3, %l2, %l2
   255   //   add  %g3, 4, %g3
   256   //   ld  [ %l2 ], %l5
   257   //   brz,pn   %l5, throw_icce
   258   //   cmp  %l5, %g5
   259   //   be  %icc, success
   260   //   add  %l2, 8, %l2
   261   // loop:
   262   //   ld  [ %l2 ], %l5
   263   //   brz,pn   %l5, throw_icce
   264   //   cmp  %l5, %g5
   265   //   bne,pn   %icc, loop
   266   //   add  %l2, 8, %l2
   267   // success:
   268   //   ld  [ %l2 + -4 ], %l2
   269   //   ld  [ %g3 + %l2 ], %l5
   270   //   restore  %l5, 0, %g5
   271   //   ld  [ %g5 + 0x44 ], %g3
   272   //   jmp  %g3
   273   //   nop
   274   // throw_icce:
   275   //   sethi  %hi(throw_ICCE_entry), %g3
   276   //   ! 5 more instructions here, LP64_ONLY
   277   //   jmp  %g3 + %lo(throw_ICCE_entry)
   278   //   restore
   279 }
   282 int VtableStub::pd_code_alignment() {
   283   // UltraSPARC cache line size is 8 instructions:
   284   const unsigned int icache_line_size = 32;
   285   return icache_line_size;
   286 }

mercurial