src/hotspot/share/c1/c1_FrameMap.cpp
author vlivanov
Tue, 03 Sep 2019 17:45:02 +0300
changeset 57996 bf3fb5465543
parent 47216 71c04702a3d5
permissions -rw-r--r--
8227236: assert(singleton != __null && singleton != declared_interface) failed Reviewed-by: dlong
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
38031
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 25715
diff changeset
     2
 * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1217
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1217
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1217
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6176
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6176
diff changeset
    26
#include "c1/c1_FrameMap.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6176
diff changeset
    27
#include "c1/c1_LIR.hpp"
25715
d5a8dbdc5150 8049325: Introduce and clean up umbrella headers for the files in the cpu subdirectories.
goetz
parents: 22872
diff changeset
    28
#include "code/vmreg.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6176
diff changeset
    29
#include "runtime/sharedRuntime.hpp"
46625
edefffab74e2 8183552: Move align functions to align.hpp
stefank
parents: 46620
diff changeset
    30
#include "utilities/align.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
//-----------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// Convert method signature into an array of BasicTypes for the arguments
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
BasicTypeArray* FrameMap::signature_type_array_for(const ciMethod* method) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  ciSignature* sig = method->signature();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  BasicTypeList* sta = new BasicTypeList(method->arg_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  // add receiver, if any
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  if (!method->is_static()) sta->append(T_OBJECT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  // add remaining arguments
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  for (int i = 0; i < sig->count(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
    ciType* type = sig->type_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
    BasicType t = type->basic_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
    if (t == T_ARRAY) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
      t = T_OBJECT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
    sta->append(t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  // done
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  return sta;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
CallingConvention* FrameMap::java_calling_convention(const BasicTypeArray* signature, bool outgoing) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  // compute the size of the arguments first.  The signature array
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  // that java_calling_convention takes includes a T_VOID after double
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  // work items but our signatures do not.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  int i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  int sizeargs = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  for (i = 0; i < signature->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
    sizeargs += type2size[signature->at(i)];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, sizeargs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  VMRegPair* regs = NEW_RESOURCE_ARRAY(VMRegPair, sizeargs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  int sig_index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  for (i = 0; i < sizeargs; i++, sig_index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
    sig_bt[i] = signature->at(sig_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
    if (sig_bt[i] == T_LONG || sig_bt[i] == T_DOUBLE) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
      sig_bt[i + 1] = T_VOID;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
      i++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  intptr_t out_preserve = SharedRuntime::java_calling_convention(sig_bt, regs, sizeargs, outgoing);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  LIR_OprList* args = new LIR_OprList(signature->length());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  for (i = 0; i < sizeargs;) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
    BasicType t = sig_bt[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    assert(t != T_VOID, "should be skipping these");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
    LIR_Opr opr = map_to_opr(t, regs + i, outgoing);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
    args->append(opr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    if (opr->is_address()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
      LIR_Address* addr = opr->as_address_ptr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
      assert(addr->disp() == (int)addr->disp(), "out of range value");
7717
2c1b91209f0f 7009849: C1: Incorrect frame size computation
iveresov
parents: 7397
diff changeset
    85
      out_preserve = MAX2(out_preserve, (intptr_t)(addr->disp() - STACK_BIAS) / 4);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    i += type2size[t];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  assert(args->length() == signature->length(), "size mismatch");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  out_preserve += SharedRuntime::out_preserve_stack_slots();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  if (outgoing) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
    // update the space reserved for arguments.
6176
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5707
diff changeset
    94
    update_reserved_argument_area_size(out_preserve * BytesPerWord);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  return new CallingConvention(args, out_preserve);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
CallingConvention* FrameMap::c_calling_convention(const BasicTypeArray* signature) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  // compute the size of the arguments first.  The signature array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  // that java_calling_convention takes includes a T_VOID after double
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  // work items but our signatures do not.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  int i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  int sizeargs = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  for (i = 0; i < signature->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    sizeargs += type2size[signature->at(i)];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, sizeargs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  VMRegPair* regs = NEW_RESOURCE_ARRAY(VMRegPair, sizeargs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  int sig_index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  for (i = 0; i < sizeargs; i++, sig_index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
    sig_bt[i] = signature->at(sig_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    if (sig_bt[i] == T_LONG || sig_bt[i] == T_DOUBLE) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
      sig_bt[i + 1] = T_VOID;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
      i++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
22832
03720a5b7595 8024344: PPC64 (part 112): C argument in register AND stack slot.
goetz
parents: 15848
diff changeset
   121
  intptr_t out_preserve = SharedRuntime::c_calling_convention(sig_bt, regs, NULL, sizeargs);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  LIR_OprList* args = new LIR_OprList(signature->length());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  for (i = 0; i < sizeargs;) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
    BasicType t = sig_bt[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
    assert(t != T_VOID, "should be skipping these");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    // C calls are always outgoing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
    bool outgoing = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
    LIR_Opr opr = map_to_opr(t, regs + i, outgoing);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    // they might be of different types if for instance floating point
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    // values are passed in cpu registers, but the sizes must match.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
    assert(type2size[opr->type()] == type2size[t], "type mismatch");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
    args->append(opr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
    if (opr->is_address()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
      LIR_Address* addr = opr->as_address_ptr();
7717
2c1b91209f0f 7009849: C1: Incorrect frame size computation
iveresov
parents: 7397
diff changeset
   136
      out_preserve = MAX2(out_preserve, (intptr_t)(addr->disp() - STACK_BIAS) / 4);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
    i += type2size[t];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  assert(args->length() == signature->length(), "size mismatch");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  out_preserve += SharedRuntime::out_preserve_stack_slots();
6176
4d9030fe341f 6953477: Increase portability and flexibility of building Hotspot
bobv
parents: 5707
diff changeset
   142
  update_reserved_argument_area_size(out_preserve * BytesPerWord);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  return new CallingConvention(args, out_preserve);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
//--------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
//               FrameMap
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
//--------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
bool      FrameMap::_init_done = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
Register  FrameMap::_cpu_rnr2reg [FrameMap::nof_cpu_regs];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
int       FrameMap::_cpu_reg2rnr [FrameMap::nof_cpu_regs];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
FrameMap::FrameMap(ciMethod* method, int monitors, int reserved_argument_area_size) {
5707
6c66849ed24e 6958292: C1: Enable parallel compilation
iveresov
parents: 5547
diff changeset
   157
  assert(_init_done, "should already be completed");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  _framesize = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  _num_spills = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  assert(monitors >= 0, "not set");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  _num_monitors = monitors;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  assert(reserved_argument_area_size >= 0, "not set");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  _reserved_argument_area_size = MAX2(4, reserved_argument_area_size) * BytesPerWord;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  _argcount = method->arg_size();
38031
e0b822facc03 8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents: 25715
diff changeset
   168
  _argument_locations = new intArray(_argcount, _argcount, -1);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  _incoming_arguments = java_calling_convention(signature_type_array_for(method), false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  _oop_map_arg_count = _incoming_arguments->reserved_stack_slots();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  int java_index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  for (int i = 0; i < _incoming_arguments->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
    LIR_Opr opr = _incoming_arguments->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
    if (opr->is_address()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
      LIR_Address* address = opr->as_address_ptr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
      _argument_locations->at_put(java_index, address->disp() - STACK_BIAS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
      _incoming_arguments->args()->at_put(i, LIR_OprFact::stack(java_index, as_BasicType(as_ValueType(address->type()))));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
    java_index += type2size[opr->type()];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
bool FrameMap::finalize_frame(int nof_slots) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  assert(nof_slots >= 0, "must be positive");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  assert(_num_spills == -1, "can only be set once");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  _num_spills = nof_slots;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  assert(_framesize == -1, "should only be calculated once");
46620
750c6edff33b 8178500: Replace usages of round_to and round_down with align_up and align_down
stefank
parents: 38031
diff changeset
   191
  _framesize =  align_up(in_bytes(sp_offset_for_monitor_base(0)) +
750c6edff33b 8178500: Replace usages of round_to and round_down with align_up and align_down
stefank
parents: 38031
diff changeset
   192
                         _num_monitors * (int)sizeof(BasicObjectLock) +
750c6edff33b 8178500: Replace usages of round_to and round_down with align_up and align_down
stefank
parents: 38031
diff changeset
   193
                         (int)sizeof(intptr_t) +                        // offset of deopt orig pc
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
                         frame_pad_in_bytes,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
                         StackAlignmentInBytes) / 4;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  int java_index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  for (int i = 0; i < _incoming_arguments->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
    LIR_Opr opr = _incoming_arguments->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
    if (opr->is_stack()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
      _argument_locations->at_put(java_index, in_bytes(framesize_in_bytes()) +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
                                  _argument_locations->at(java_index));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
    java_index += type2size[opr->type()];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  // make sure it's expressible on the platform
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  return validate_frame();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
VMReg FrameMap::sp_offset2vmreg(ByteSize offset) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  int offset_in_bytes = in_bytes(offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  assert(offset_in_bytes % 4 == 0, "must be multiple of 4 bytes");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  assert(offset_in_bytes / 4 < framesize() + oop_map_arg_count(), "out of range");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  return VMRegImpl::stack2reg(offset_in_bytes / 4);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
bool FrameMap::location_for_sp_offset(ByteSize byte_offset_from_sp,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
                                      Location::Type loc_type,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
                                      Location* loc) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  int offset = in_bytes(byte_offset_from_sp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  assert(offset >= 0, "incorrect offset");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  if (!Location::legal_offset_in_bytes(offset)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  Location tmp_loc = Location::new_stk_loc(loc_type, offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  *loc = tmp_loc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
bool FrameMap::locations_for_slot  (int index, Location::Type loc_type,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
                                     Location* loc, Location* second) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  ByteSize offset_from_sp = sp_offset_for_slot(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  if (!location_for_sp_offset(offset_from_sp, loc_type, loc)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  if (second != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
    // two word item
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
    offset_from_sp = offset_from_sp + in_ByteSize(4);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
    return location_for_sp_offset(offset_from_sp, loc_type, second);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
//////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
// Public accessors //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
//////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
ByteSize FrameMap::sp_offset_for_slot(const int index) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  if (index < argcount()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
    int offset = _argument_locations->at(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
    assert(offset != -1, "not a memory argument");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
    assert(offset >= framesize() * 4, "argument inside of frame");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
    return in_ByteSize(offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  ByteSize offset = sp_offset_for_spill(index - argcount());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
  assert(in_bytes(offset) < framesize() * 4, "spill outside of frame");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  return offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
ByteSize FrameMap::sp_offset_for_double_slot(const int index) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  ByteSize offset = sp_offset_for_slot(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  if (index >= argcount()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
    assert(in_bytes(offset) + 4 < framesize() * 4, "spill outside of frame");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
  return offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
ByteSize FrameMap::sp_offset_for_spill(const int index) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
  assert(index >= 0 && index < _num_spills, "out of range");
46620
750c6edff33b 8178500: Replace usages of round_to and round_down with align_up and align_down
stefank
parents: 38031
diff changeset
   274
  int offset = align_up(first_available_sp_in_frame + _reserved_argument_area_size, (int)sizeof(double)) +
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
    index * spill_slot_size_in_bytes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
  return in_ByteSize(offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
ByteSize FrameMap::sp_offset_for_monitor_base(const int index) const {
46620
750c6edff33b 8178500: Replace usages of round_to and round_down with align_up and align_down
stefank
parents: 38031
diff changeset
   280
  int end_of_spills = align_up(first_available_sp_in_frame + _reserved_argument_area_size, (int)sizeof(double)) +
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
    _num_spills * spill_slot_size_in_bytes;
46620
750c6edff33b 8178500: Replace usages of round_to and round_down with align_up and align_down
stefank
parents: 38031
diff changeset
   282
  int offset = align_up(end_of_spills, HeapWordSize) + index * (int)sizeof(BasicObjectLock);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
  return in_ByteSize(offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
ByteSize FrameMap::sp_offset_for_monitor_lock(int index) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
  check_monitor_index(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  return sp_offset_for_monitor_base(index) + in_ByteSize(BasicObjectLock::lock_offset_in_bytes());;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
ByteSize FrameMap::sp_offset_for_monitor_object(int index) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
  check_monitor_index(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
  return sp_offset_for_monitor_base(index) + in_ByteSize(BasicObjectLock::obj_offset_in_bytes());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
// For OopMaps, map a local variable or spill index to an VMReg.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
// This is the offset from sp() in the frame of the slot for the index,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
// skewed by SharedInfo::stack0 to indicate a stack location (vs.a register.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
//         C ABI size +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
//         framesize +     framesize +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
//         stack0          stack0         stack0          0 <- VMReg->value()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
//            |              |              | <registers> |
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
//  ..........|..............|..............|.............|
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
//    0 1 2 3 | <C ABI area> | 4 5 6 ...... |               <- local indices
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
//    ^                        ^          sp()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
//    |                        |
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
//  arguments            non-argument locals
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
VMReg FrameMap::regname(LIR_Opr opr) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
  if (opr->is_single_cpu()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
    assert(!opr->is_virtual(), "should not see virtual registers here");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
    return opr->as_register()->as_VMReg();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
  } else if (opr->is_single_stack()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
    return sp_offset2vmreg(sp_offset_for_slot(opr->single_stack_ix()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
  } else if (opr->is_address()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
    LIR_Address* addr = opr->as_address_ptr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
    assert(addr->base() == stack_pointer(), "sp based addressing only");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
    return sp_offset2vmreg(in_ByteSize(addr->index()->as_jint()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
  ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
  return VMRegImpl::Bad();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
// ------------ extra spill slots ---------------