src/cpu/mips/vm/metaspaceShared_mips_64.cpp

changeset 1
2d8a650513c2
child 6880
52ea28d233d2
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/cpu/mips/vm/metaspaceShared_mips_64.cpp	Fri Apr 29 00:06:10 2016 +0800
     1.3 @@ -0,0 +1,107 @@
     1.4 +/*
     1.5 + * Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright (c) 2015, 2016, Loongson Technology. All rights reserved.
     1.7 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8 + *
     1.9 + * This code is free software; you can redistribute it and/or modify it
    1.10 + * under the terms of the GNU General Public License version 2 only, as
    1.11 + * published by the Free Software Foundation.
    1.12 + *
    1.13 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.15 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.16 + * version 2 for more details (a copy is included in the LICENSE file that
    1.17 + * accompanied this code).
    1.18 + *
    1.19 + * You should have received a copy of the GNU General Public License version
    1.20 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.21 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.22 + *
    1.23 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.24 + * or visit www.oracle.com if you need additional information or have any
    1.25 + * questions.
    1.26 + *
    1.27 + */
    1.28 +
    1.29 +#include "precompiled.hpp"
    1.30 +#include "asm/macroAssembler.hpp"
    1.31 +#include "asm/codeBuffer.hpp"
    1.32 +#include "memory/metaspaceShared.hpp"
    1.33 +
    1.34 +// Generate the self-patching vtable method:
    1.35 +//
    1.36 +// This method will be called (as any other Klass virtual method) with
    1.37 +// the Klass itself as the first argument.  Example:
    1.38 +//
    1.39 +//      oop obj;
    1.40 +//      int size = obj->klass()->klass_part()->oop_size(this);
    1.41 +//
    1.42 +// for which the virtual method call is Klass::oop_size();
    1.43 +//
    1.44 +// The dummy method is called with the Klass object as the first
    1.45 +// operand, and an object as the second argument.
    1.46 +//
    1.47 +
    1.48 +//=====================================================================
    1.49 +
    1.50 +// All of the dummy methods in the vtable are essentially identical,
    1.51 +// differing only by an ordinal constant, and they bear no releationship
    1.52 +// to the original method which the caller intended. Also, there needs
    1.53 +// to be 'vtbl_list_size' instances of the vtable in order to
    1.54 +// differentiate between the 'vtable_list_size' original Klass objects.
    1.55 +
    1.56 +#define __ masm->
    1.57 +
    1.58 +void MetaspaceShared::generate_vtable_methods(void** vtbl_list,
    1.59 +                                                   void** vtable,
    1.60 +                                                   char** md_top,
    1.61 +                                                   char* md_end,
    1.62 +                                                   char** mc_top,
    1.63 +                                                   char* mc_end) {
    1.64 +
    1.65 +  intptr_t vtable_bytes = (num_virtuals * vtbl_list_size) * sizeof(void*);
    1.66 +  *(intptr_t *)(*md_top) = vtable_bytes;
    1.67 +  *md_top += sizeof(intptr_t);
    1.68 +  void** dummy_vtable = (void**)*md_top;
    1.69 +  *vtable = dummy_vtable;
    1.70 +  *md_top += vtable_bytes;
    1.71 +
    1.72 +  // Get ready to generate dummy methods.
    1.73 +
    1.74 +  CodeBuffer cb((unsigned char*)*mc_top, mc_end - *mc_top);
    1.75 +  MacroAssembler* masm = new MacroAssembler(&cb);
    1.76 +
    1.77 +  Label common_code;
    1.78 +  for (int i = 0; i < vtbl_list_size; ++i) {
    1.79 +    for (int j = 0; j < num_virtuals; ++j) {
    1.80 +      dummy_vtable[num_virtuals * i + j] = (void*)masm->pc();
    1.81 +
    1.82 +      // Load eax with a value indicating vtable/offset pair.
    1.83 +      // -- bits[ 7..0]  (8 bits) which virtual method in table?
    1.84 +      // -- bits[12..8]  (5 bits) which virtual method table?
    1.85 +      // -- must fit in 13-bit instruction immediate field.
    1.86 +      __ move(V0, (i << 8) + j);
    1.87 +      __ b(common_code);
    1.88 +      __ delayed()->nop(); 
    1.89 +    }
    1.90 +  }
    1.91 +
    1.92 +  __ bind(common_code);
    1.93 +
    1.94 +  __ srl(T9, V0, 8);		// isolate vtable identifier.
    1.95 +  __ shl(T9, LogBytesPerWord);
    1.96 +  __ li(AT, (long)vtbl_list);
    1.97 +  __ add(T9, AT, T9);
    1.98 +  __ lw(T9, T9, 0); 		// get correct vtable address.
    1.99 +  __ sw(T9, A0, 0);		// update vtable pointer.
   1.100 +
   1.101 +  __ andi(V0, V0, 0x00ff);	// isolate vtable method index
   1.102 +  __ shl(V0, LogBytesPerWord);
   1.103 +  __ add(T9, T9, V0);		// address of real method pointer.
   1.104 +  __ jr(T9);			// get real method pointer.
   1.105 +  __ delayed()->nop();
   1.106 +
   1.107 +  __ flush();
   1.108 +
   1.109 +  *mc_top = (char*)__ pc();
   1.110 +}

mercurial