src/hotspot/cpu/s390/vtableStubs_s390.cpp
author stefank
Thu, 09 May 2019 14:28:30 +0200
changeset 54786 ebf733a324d4
parent 51618 54b344d9dd4e
child 58554 8c3c39710a08
permissions -rw-r--r--
8223624: Cleanup includes of universe.hpp Reviewed-by: coleenp, lkorinth
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
     1
/*
51618
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
     2
 * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
     3
 * Copyright (c) 2016, 2018 SAP SE. All rights reserved.
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
     4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
     5
 *
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
     6
 * This code is free software; you can redistribute it and/or modify it
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
     7
 * under the terms of the GNU General Public License version 2 only, as
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
     8
 * published by the Free Software Foundation.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
     9
 *
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    14
 * accompanied this code).
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    15
 *
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    19
 *
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    22
 * questions.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    23
 *
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    24
 */
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    25
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    26
#include "precompiled.hpp"
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    27
#include "asm/macroAssembler.inline.hpp"
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    28
#include "code/vtableStubs.hpp"
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    29
#include "interp_masm_s390.hpp"
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    30
#include "memory/resourceArea.hpp"
48585
d9fcb7ba8133 8191907: PPC64 and s390 parts of JDK-8174962: Better interface invocations
mdoerr
parents: 47216
diff changeset
    31
#include "oops/compiledICHolder.hpp"
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    32
#include "oops/instanceKlass.hpp"
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    33
#include "oops/klassVtable.hpp"
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    34
#include "runtime/sharedRuntime.hpp"
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    35
#include "vmreg_s390.inline.hpp"
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    36
#ifdef COMPILER2
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    37
#include "opto/runtime.hpp"
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    38
#endif
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    39
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    40
#define __ masm->
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    41
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    42
#ifndef PRODUCT
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    43
extern "C" void bad_compiled_vtable_index(JavaThread* thread, oop receiver, int index);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    44
#endif
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    45
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    46
// Used by compiler only; may use only caller saved, non-argument registers.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    47
VtableStub* VtableStubs::create_vtable_stub(int vtable_index) {
51618
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
    48
  // Read "A word on VtableStub sizing" in share/code/vtableStubs.hpp for details on stub sizing.
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
    49
  const int stub_code_length = code_size_limit(true);
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
    50
  VtableStub* s = new(stub_code_length) VtableStub(true, vtable_index);
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
    51
  // Can be NULL if there is no free space in the code cache.
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
    52
  if (s == NULL) {
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    53
    return NULL;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    54
  }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    55
51618
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
    56
  // Count unused bytes in instruction sequences of variable size.
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
    57
  // We add them to the computed buffer size in order to avoid
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
    58
  // overflow in subsequently generated stubs.
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
    59
  address   start_pc;
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
    60
  int       slop_bytes = 0;
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
    61
  int       slop_delta = 0;
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
    62
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    63
  ResourceMark    rm;
51618
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
    64
  CodeBuffer      cb(s->entry_point(), stub_code_length);
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
    65
  MacroAssembler* masm = new MacroAssembler(&cb);
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    66
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    67
#if (!defined(PRODUCT) && defined(COMPILER2))
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    68
  if (CountCompiledCalls) {
51618
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
    69
    //               worst case             actual size
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
    70
    slop_delta  = __ load_const_size() - __ load_const_optimized_rtn_len(Z_R1_scratch, (long)SharedRuntime::nof_megamorphic_calls_addr(), true);
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
    71
    slop_bytes += slop_delta;
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
    72
    assert(slop_delta >= 0, "negative slop(%d) encountered, adjust code size estimate!", slop_delta);
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    73
    // Use generic emitter for direct memory increment.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    74
    // Abuse Z_method as scratch register for generic emitter.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    75
    // It is loaded further down anyway before it is first used.
51618
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
    76
    // No dynamic code size variance here, increment is 1, always.
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    77
    __ add2mem_32(Address(Z_R1_scratch), 1, Z_method);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    78
  }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    79
#endif
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    80
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    81
  assert(VtableStub::receiver_location() == Z_R2->as_VMReg(), "receiver expected in Z_ARG1");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    82
51618
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
    83
  const Register rcvr_klass   = Z_R1_scratch;
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
    84
  address        npe_addr     = __ pc(); // npe == NULL ptr exception
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
    85
  // check if we must do an explicit check (implicit checks disabled, offset too large).
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    86
  __ null_check(Z_ARG1, Z_R1_scratch, oopDesc::klass_offset_in_bytes());
51618
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
    87
  // Get receiver klass.
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    88
  __ load_klass(rcvr_klass, Z_ARG1);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    89
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    90
#ifndef PRODUCT
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    91
  if (DebugVtables) {
51618
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
    92
    NearLabel L;
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    93
    // Check offset vs vtable length.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    94
    const Register vtable_idx = Z_R0_scratch;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    95
51618
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
    96
    //               worst case             actual size
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
    97
    slop_delta  = __ load_const_size() - __ load_const_optimized_rtn_len(vtable_idx, vtable_index*vtableEntry::size(), true);
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
    98
    slop_bytes += slop_delta;
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
    99
    assert(slop_delta >= 0, "negative slop(%d) encountered, adjust code size estimate!", slop_delta);
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   100
51618
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
   101
    assert(Displacement::is_shortDisp(in_bytes(Klass::vtable_length_offset())), "disp to large");
46280
6eef3d367beb 8175269: [s390] cleanup calls to vtable_start_offset() and vtable_length_offset()
lucy
parents: 42065
diff changeset
   102
    __ z_cl(vtable_idx, in_bytes(Klass::vtable_length_offset()), rcvr_klass);
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   103
    __ z_brl(L);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   104
    __ z_lghi(Z_ARG3, vtable_index);  // Debug code, don't optimize.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   105
    __ call_VM(noreg, CAST_FROM_FN_PTR(address, bad_compiled_vtable_index), Z_ARG1, Z_ARG3, false);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   106
    // Count unused bytes (assume worst case here).
51618
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
   107
    slop_bytes += 12;
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   108
    __ bind(L);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   109
  }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   110
#endif
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   111
51618
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
   112
  int entry_offset = in_bytes(Klass::vtable_start_offset()) +
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
   113
                     vtable_index * vtableEntry::size_in_bytes();
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
   114
  int v_off        = entry_offset + vtableEntry::method_offset_in_bytes();
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   115
51618
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
   116
  // Set method (in case of interpreted method), and destination address.
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   117
  // Duplicate safety code from enc_class Java_Dynamic_Call_dynTOC.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   118
  if (Displacement::is_validDisp(v_off)) {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   119
    __ z_lg(Z_method/*method oop*/, v_off, rcvr_klass/*class oop*/);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   120
    // Account for the load_const in the else path.
51618
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
   121
    slop_delta  = __ load_const_size();
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   122
  } else {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   123
    // Worse case, offset does not fit in displacement field.
51618
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
   124
    //               worst case             actual size
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
   125
    slop_delta  = __ load_const_size() - __ load_const_optimized_rtn_len(Z_method, v_off, true);
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   126
    __ z_lg(Z_method/*method oop*/, 0, Z_method/*method offset*/, rcvr_klass/*class oop*/);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   127
  }
51618
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
   128
  slop_bytes += slop_delta;
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   129
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   130
#ifndef PRODUCT
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   131
  if (DebugVtables) {
51618
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
   132
    NearLabel L;
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   133
    __ z_ltgr(Z_method, Z_method);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   134
    __ z_brne(L);
51618
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
   135
    __ stop("Vtable entry is ZERO", 102);
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   136
    __ bind(L);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   137
  }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   138
#endif
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   139
51618
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
   140
  // Must do an explicit check if offset too large or implicit checks are disabled.
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
   141
  address ame_addr = __ pc();
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   142
  __ null_check(Z_method, Z_R1_scratch, in_bytes(Method::from_compiled_offset()));
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   143
  __ z_lg(Z_R1_scratch, in_bytes(Method::from_compiled_offset()), Z_method);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   144
  __ z_br(Z_R1_scratch);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   145
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   146
  masm->flush();
51618
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
   147
  bookkeeping(masm, tty, s, npe_addr, ame_addr, true, vtable_index, slop_bytes, 0);
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   148
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   149
  return s;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   150
}
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   151
48585
d9fcb7ba8133 8191907: PPC64 and s390 parts of JDK-8174962: Better interface invocations
mdoerr
parents: 47216
diff changeset
   152
VtableStub* VtableStubs::create_itable_stub(int itable_index) {
51618
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
   153
  // Read "A word on VtableStub sizing" in share/code/vtableStubs.hpp for details on stub sizing.
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
   154
  const int stub_code_length = code_size_limit(false);
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
   155
  VtableStub* s = new(stub_code_length) VtableStub(false, itable_index);
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
   156
  // Can be NULL if there is no free space in the code cache.
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
   157
  if (s == NULL) {
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   158
    return NULL;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   159
  }
51618
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
   160
  // Count unused bytes in instruction sequences of variable size.
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
   161
  // We add them to the computed buffer size in order to avoid
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
   162
  // overflow in subsequently generated stubs.
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
   163
  address   start_pc;
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
   164
  int       slop_bytes = 0;
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
   165
  int       slop_delta = 0;
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   166
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   167
  ResourceMark    rm;
51618
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
   168
  CodeBuffer      cb(s->entry_point(), stub_code_length);
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
   169
  MacroAssembler* masm = new MacroAssembler(&cb);
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   170
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   171
#if (!defined(PRODUCT) && defined(COMPILER2))
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   172
  if (CountCompiledCalls) {
51618
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
   173
    //               worst case             actual size
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
   174
    slop_delta  = __ load_const_size() - __ load_const_optimized_rtn_len(Z_R1_scratch, (long)SharedRuntime::nof_megamorphic_calls_addr(), true);
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
   175
    slop_bytes += slop_delta;
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
   176
    assert(slop_delta >= 0, "negative slop(%d) encountered, adjust code size estimate!", slop_delta);
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   177
    // Use generic emitter for direct memory increment.
51618
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
   178
    // Abuse Z_method as scratch register for generic emitter.
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
   179
    // It is loaded further down anyway before it is first used.
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
   180
    // No dynamic code size variance here, increment is 1, always.
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
   181
    __ add2mem_32(Address(Z_R1_scratch), 1, Z_method);
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   182
  }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   183
#endif
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   184
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   185
  assert(VtableStub::receiver_location() == Z_R2->as_VMReg(), "receiver expected in Z_ARG1");
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   186
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   187
  // Entry arguments:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   188
  //  Z_method: Interface
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   189
  //  Z_ARG1:   Receiver
48585
d9fcb7ba8133 8191907: PPC64 and s390 parts of JDK-8174962: Better interface invocations
mdoerr
parents: 47216
diff changeset
   190
  NearLabel no_such_interface;
d9fcb7ba8133 8191907: PPC64 and s390 parts of JDK-8174962: Better interface invocations
mdoerr
parents: 47216
diff changeset
   191
  const Register rcvr_klass = Z_tmp_1,
d9fcb7ba8133 8191907: PPC64 and s390 parts of JDK-8174962: Better interface invocations
mdoerr
parents: 47216
diff changeset
   192
                 interface  = Z_tmp_2;
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   193
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   194
  // Get receiver klass.
51618
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
   195
  // Must do an explicit check if offset too large or implicit checks are disabled.
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   196
  address npe_addr = __ pc(); // npe == NULL ptr exception
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   197
  __ null_check(Z_ARG1, Z_R1_scratch, oopDesc::klass_offset_in_bytes());
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   198
  __ load_klass(rcvr_klass, Z_ARG1);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   199
48585
d9fcb7ba8133 8191907: PPC64 and s390 parts of JDK-8174962: Better interface invocations
mdoerr
parents: 47216
diff changeset
   200
  // Receiver subtype check against REFC.
d9fcb7ba8133 8191907: PPC64 and s390 parts of JDK-8174962: Better interface invocations
mdoerr
parents: 47216
diff changeset
   201
  __ z_lg(interface, Address(Z_method, CompiledICHolder::holder_klass_offset()));
d9fcb7ba8133 8191907: PPC64 and s390 parts of JDK-8174962: Better interface invocations
mdoerr
parents: 47216
diff changeset
   202
  __ lookup_interface_method(rcvr_klass, interface, noreg,
d9fcb7ba8133 8191907: PPC64 and s390 parts of JDK-8174962: Better interface invocations
mdoerr
parents: 47216
diff changeset
   203
                             noreg, Z_R1, no_such_interface, /*return_method=*/ false);
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   204
48585
d9fcb7ba8133 8191907: PPC64 and s390 parts of JDK-8174962: Better interface invocations
mdoerr
parents: 47216
diff changeset
   205
  // Get Method* and entrypoint for compiler
d9fcb7ba8133 8191907: PPC64 and s390 parts of JDK-8174962: Better interface invocations
mdoerr
parents: 47216
diff changeset
   206
  __ z_lg(interface, Address(Z_method, CompiledICHolder::holder_metadata_offset()));
d9fcb7ba8133 8191907: PPC64 and s390 parts of JDK-8174962: Better interface invocations
mdoerr
parents: 47216
diff changeset
   207
  __ lookup_interface_method(rcvr_klass, interface, itable_index,
d9fcb7ba8133 8191907: PPC64 and s390 parts of JDK-8174962: Better interface invocations
mdoerr
parents: 47216
diff changeset
   208
                             Z_method, Z_R1, no_such_interface, /*return_method=*/ true);
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   209
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   210
#ifndef PRODUCT
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   211
  if (DebugVtables) {
51618
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
   212
    NearLabel ok1;
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   213
    __ z_ltgr(Z_method, Z_method);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   214
    __ z_brne(ok1);
51618
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
   215
    __ stop("method is null", 103);
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   216
    __ bind(ok1);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   217
  }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   218
#endif
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   219
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   220
  address ame_addr = __ pc();
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   221
  // Must do an explicit check if implicit checks are disabled.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   222
  if (!ImplicitNullChecks) {
48585
d9fcb7ba8133 8191907: PPC64 and s390 parts of JDK-8174962: Better interface invocations
mdoerr
parents: 47216
diff changeset
   223
    __ compare64_and_branch(Z_method, (intptr_t) 0, Assembler::bcondEqual, no_such_interface);
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   224
  }
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   225
  __ z_lg(Z_R1_scratch, in_bytes(Method::from_compiled_offset()), Z_method);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   226
  __ z_br(Z_R1_scratch);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   227
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   228
  // Handle IncompatibleClassChangeError in itable stubs.
48585
d9fcb7ba8133 8191907: PPC64 and s390 parts of JDK-8174962: Better interface invocations
mdoerr
parents: 47216
diff changeset
   229
  __ bind(no_such_interface);
51618
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
   230
  // more detailed IncompatibleClassChangeError
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
   231
  // we force re-resolving of the call site by jumping to
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
   232
  // the "handle wrong method" stub, thus letting the
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   233
  // interpreter runtime do all the dirty work.
51618
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
   234
  //               worst case          actual size
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
   235
  slop_delta  = __ load_const_size() - __ load_const_optimized_rtn_len(Z_R1_scratch, (long)SharedRuntime::get_handle_wrong_method_stub(), true);
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
   236
  slop_bytes += slop_delta;
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
   237
  assert(slop_delta >= 0, "negative slop(%d) encountered, adjust code size estimate!", slop_delta);
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   238
  __ z_br(Z_R1_scratch);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   239
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   240
  masm->flush();
51618
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
   241
  bookkeeping(masm, tty, s, npe_addr, ame_addr, false, itable_index, slop_bytes, 0);
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   242
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   243
  return s;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   244
}
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   245
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   246
int VtableStub::pd_code_alignment() {
51618
54b344d9dd4e 8207343: Automate vtable/itable stub size calculation
lucy
parents: 48585
diff changeset
   247
  // System z cache line size is 256 bytes, but octoword-alignment is quite ok.
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   248
  const unsigned int icache_line_size = 32;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   249
  return icache_line_size;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   250
}