src/cpu/mips/vm/vtableStubs_mips_64.cpp

Thu, 07 Sep 2017 09:12:16 +0800

author
aoqi
date
Thu, 07 Sep 2017 09:12:16 +0800
changeset 6880
52ea28d233d2
parent 1
2d8a650513c2
child 9043
7519f4bf92b5
permissions
-rw-r--r--

#5745 [Code Reorganization] code cleanup and code style fix
This is a huge patch, but only code cleanup, code style fix and useless code deletion are included, for example:
tab -> two spaces, deleted spacees at the end of a line, delete useless comments.

This patch also included:
Declaration and definition of class MacroAssembler is moved from assembler_mips.h/cpp to macroAssembler_mips.h/cpp

     1 /*
     2  * Copyright (c) 2003, 2014, 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 "asm/macroAssembler.hpp"
    28 #include "code/vtableStubs.hpp"
    29 #include "interp_masm_mips_64.hpp"
    30 #include "memory/resourceArea.hpp"
    31 //#include "oops/InstanceKlass.hpp"
    32 #include "oops/klassVtable.hpp"
    33 #include "runtime/sharedRuntime.hpp"
    34 #include "vmreg_mips.inline.hpp"
    35 #ifdef COMPILER2
    36 #include "opto/runtime.hpp"
    37 #endif
    40 // machine-dependent part of VtableStubs: create VtableStub of correct size and
    41 // initialize its code
    43 #define __ masm->
    45 #ifndef PRODUCT
    46 extern "C" void bad_compiled_vtable_index(JavaThread* thread,
    47                                           oop receiver,
    48                                           int index);
    49 #endif
    51 // used by compiler only;  reciever in T0.
    52 // used registers :
    53 // Rmethod : receiver klass & method
    54 // NOTE: If this code is used by the C1, the receiver_location is always 0.
    55 // when reach here, receiver in T0, klass in T8
    56 VtableStub* VtableStubs::create_vtable_stub(int vtable_index) {
    57   const int gs2_code_length = VtableStub::pd_code_size_limit(true);
    58   VtableStub* s = new(gs2_code_length) VtableStub(true, vtable_index);
    59   ResourceMark rm;
    60   CodeBuffer cb(s->entry_point(), gs2_code_length);
    61   MacroAssembler* masm = new MacroAssembler(&cb);
    62   Register t1 = T8, t2 = Rmethod;
    63 #ifndef PRODUCT
    64   if (CountCompiledCalls) {
    65     __ li(AT, SharedRuntime::nof_megamorphic_calls_addr());
    66     __ lw(t1, AT , 0);
    67     __ addiu(t1, t1, 1);
    68     __ sw(t1, AT,0);
    69   }
    70 #endif
    72   // get receiver (need to skip return address on top of stack)
    73   //assert(receiver_location == T0->as_VMReg(), "receiver expected in T0");
    75   // get receiver klass
    76   address npe_addr = __ pc();
    77   //add for compressedoops
    78   __ load_klass(t1, T0);
    79   // compute entry offset (in words)
    80   int entry_offset = InstanceKlass::vtable_start_offset() + vtable_index*vtableEntry::size();
    81 #ifndef PRODUCT
    82   if (DebugVtables) {
    83     Label L;
    84     // check offset vs vtable length
    85     __ lw(t2, t1, InstanceKlass::vtable_length_offset()*wordSize);
    86     assert(Assembler::is_simm16(vtable_index*vtableEntry::size()), "change this code");
    87     __ move(AT, vtable_index*vtableEntry::size());
    88     __ slt(AT, AT, t2);
    89     __ bne(AT, R0, L);
    90     __ delayed()->nop();
    91     __ move(A2, vtable_index);
    92     __ move(A1, A0);
    93     __ call_VM(noreg, CAST_FROM_FN_PTR(address, bad_compiled_vtable_index), A1, A2);
    94     __ bind(L);
    95   }
    96 #endif // PRODUCT
    97   // load methodOop and target address
    98   const Register method = Rmethod;
    99   __ ld_ptr(method, t1,  entry_offset*wordSize + vtableEntry::method_offset_in_bytes());
   100   if (DebugVtables) {
   101     Label L;
   102     __ beq(method, R0, L);
   103     __ delayed()->nop();
   104     __ lw(AT, method,in_bytes(Method::from_compiled_offset()));
   105     __ bne(AT, R0, L);
   106     __ delayed()->nop();
   107     __ stop("Vtable entry is NULL");
   108     __ bind(L);
   109   }
   110   // T8: receiver klass
   111   // T0: receiver
   112   // Rmethod: methodOop
   113   // T9: entry
   114   address ame_addr = __ pc();
   115   __ ld_ptr(T9, method,in_bytes(Method::from_compiled_offset()));
   116   __ jr(T9);
   117   __ delayed()->nop();
   118   masm->flush();
   119   s->set_exception_points(npe_addr, ame_addr);
   120   return s;
   121 }
   124 // i am not sure which register to contain Interface, now i just assume A1. FIXME
   125 // used registers :
   126 //  T1 T2
   127 // when reach here, the receiver in T0, klass in T1
   128 VtableStub* VtableStubs::create_itable_stub(int vtable_index) {
   129   // Note well: pd_code_size_limit is the absolute minimum we can get
   130   // away with.  If you add code here, bump the code stub size
   131   // returned by pd_code_size_limit!
   132   const int gs2_code_length = VtableStub::pd_code_size_limit(false);
   133   VtableStub* s = new(gs2_code_length) VtableStub(false, vtable_index);
   134   ResourceMark rm;
   135   CodeBuffer cb(s->entry_point(), gs2_code_length);
   136   MacroAssembler* masm = new MacroAssembler(&cb);
   137   // we T8,T9 as temparary register, they are free from register allocator
   138   Register t1 = T8, t2 = T2;
   139   // Entry arguments:
   140   //  T1: Interface
   141   //  T0: Receiver
   143 #ifndef PRODUCT
   144   if (CountCompiledCalls) {
   145     __ li(AT, SharedRuntime::nof_megamorphic_calls_addr());
   146     __ lw(T8, AT, 0);
   147     __ addi(T8, T8,1);
   148     __ sw(T8, AT, 0);
   149   }
   150 #endif /* PRODUCT */
   151   address npe_addr = __ pc();
   152   //add for compressedoops
   153   __ load_klass(t1, T0);
   154   // compute itable entry offset (in words)
   155   const int base = InstanceKlass::vtable_start_offset() * wordSize;
   156   assert(vtableEntry::size() * wordSize == 8, "adjust the scaling in the code below");
   157   assert(Assembler::is_simm16(base), "change this code");
   158   __ daddi(t2, t1, base);
   159   assert(Assembler::is_simm16(InstanceKlass::vtable_length_offset() * wordSize), "change this code");
   160   __ lw(AT, t1, InstanceKlass::vtable_length_offset() * wordSize);
   161   __ dsll(AT, AT, Address::times_8);
   162   __ dadd(t2, t2, AT);
   163   if (HeapWordsPerLong > 1) {
   164     __ round_to(t2, BytesPerLong);
   165   }
   167   Label hit, entry;
   168   assert(Assembler::is_simm16(itableOffsetEntry::size() * wordSize), "change this code");
   169   __ bind(entry);
   171 #ifdef ASSERT
   172   // Check that the entry is non-null
   173   if (DebugVtables) {
   174     Label L;
   175     assert(Assembler::is_simm16(itableOffsetEntry::interface_offset_in_bytes()), "change this code");
   176     __ lw(AT, t1, itableOffsetEntry::interface_offset_in_bytes());
   177     __ bne(AT, R0, L);
   178     __ delayed()->nop();
   179     __ stop("null entry point found in itable's offset table");
   180     __ bind(L);
   181   }
   182 #endif
   183   assert(Assembler::is_simm16(itableOffsetEntry::interface_offset_in_bytes()), "change this code");
   184   __ ld_ptr(AT, t2, itableOffsetEntry::interface_offset_in_bytes());
   185   __ bne(AT, T1, entry);
   186   __ delayed()->addi(t2, t2, itableOffsetEntry::size() * wordSize);
   188   // We found a hit, move offset into T9
   189   __ ld_ptr(t2, t2, itableOffsetEntry::offset_offset_in_bytes() - itableOffsetEntry::size() * wordSize);
   191   // Compute itableMethodEntry.
   192   const int method_offset = (itableMethodEntry::size() * wordSize * vtable_index) +
   193     itableMethodEntry::method_offset_in_bytes();
   195   // Get methodOop and entrypoint for compiler
   196   //  const Register method = ebx;
   197   const Register method = Rmethod;
   198   __ dsll(AT, t2, Address::times_1);
   199   __ add(AT, AT, t1 );
   200   __ ld_ptr(method, AT,  method_offset);
   204 #ifdef ASSERT
   205   if (DebugVtables) {
   206     Label L1;
   207     __ beq(method, R0, L1);
   208     __ delayed()->nop();
   209     __ lw(AT, method,in_bytes(Method::from_compiled_offset()));
   210     __ bne(AT, R0, L1);
   211     __ delayed()->nop();
   212     __ stop("methodOop is null");
   213     __ bind(L1);
   214   }
   215 #endif // ASSERT
   216 /*
   217   // Rmethod: methodOop
   218   // T0: receiver
   219   // T9: entry point
   220   __ jmp(T9);
   221 #endif // COMPILER2
   222 */
   223   address ame_addr = __ pc();
   224   __ ld_ptr(T9, method,in_bytes(Method::from_compiled_offset()));
   225   __ jr(T9);
   226   __ delayed()->nop();
   227   masm->flush();
   228   s->set_exception_points(npe_addr, ame_addr);
   229   return s;
   230 }
   232 // NOTE : whenever you change the code above, dont forget to change the const here
   233 int VtableStub::pd_code_size_limit(bool is_vtable_stub) {
   234   if (is_vtable_stub) {
   235     return ( DebugVtables ? 600 : 28) + (CountCompiledCalls ? 24 : 0)+
   236            (UseCompressedOops ? 16 : 0);
   237   } else {
   238     return  ( DebugVtables ? 636 : 72) + (CountCompiledCalls ? 24 : 0)+
   239             (UseCompressedOops ? 32 : 0);
   240   }
   241 }
   243 int VtableStub::pd_code_alignment() {
   244   return wordSize;
   245 }

mercurial