hotspot/src/share/vm/classfile/stackMapFrame.cpp
author trims
Wed, 23 Dec 2009 03:12:16 -0800
changeset 4499 9b63533d5895
parent 1 489c9b5090e2
child 5547 f4b087cbb361
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2003-2006 Sun Microsystems, Inc.  All Rights Reserved.
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
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
# include "incls/_precompiled.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
# include "incls/_stackMapFrame.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
StackMapFrame::StackMapFrame(u2 max_locals, u2 max_stack, ClassVerifier* v) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
                      _offset(0), _locals_size(0), _stack_size(0), _flags(0),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
                      _max_locals(max_locals), _max_stack(max_stack),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
                      _verifier(v) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
  Thread* thr = v->thread();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
  _locals = NEW_RESOURCE_ARRAY_IN_THREAD(thr, VerificationType, max_locals);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  _stack = NEW_RESOURCE_ARRAY_IN_THREAD(thr, VerificationType, max_stack);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  int32_t i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  for(i = 0; i < max_locals; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
    _locals[i] = VerificationType::bogus_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  for(i = 0; i < max_stack; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
    _stack[i] = VerificationType::bogus_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
StackMapFrame* StackMapFrame::frame_in_exception_handler(u1 flags) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  Thread* thr = _verifier->thread();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  VerificationType* stack = NEW_RESOURCE_ARRAY_IN_THREAD(thr, VerificationType, 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  StackMapFrame* frame = new StackMapFrame(_offset, flags, _locals_size, 0, _max_locals, _max_stack, _locals, stack, _verifier);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  return frame;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
bool StackMapFrame::has_new_object() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  int32_t i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  for (i = 0; i < _max_locals; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
    if (_locals[i].is_uninitialized()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  for (i = 0; i < _stack_size; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
    if (_stack[i].is_uninitialized()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
void StackMapFrame::initialize_object(
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
    VerificationType old_object, VerificationType new_object) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  int32_t i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  for (i = 0; i < _max_locals; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    if (_locals[i].equals(old_object)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
      _locals[i] = new_object;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  for (i = 0; i < _stack_size; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    if (_stack[i].equals(old_object)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
      _stack[i] = new_object;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  if (old_object == VerificationType::uninitialized_this_type()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
    // "this" has been initialized - reset flags
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
    _flags = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
VerificationType StackMapFrame::set_locals_from_arg(
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    const methodHandle m, VerificationType thisKlass, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  symbolHandle signature(THREAD, m->signature());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  SignatureStream ss(signature);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  int init_local_num = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  if (!m->is_static()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    init_local_num++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    // add one extra argument for instance method
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
    if (m->name() == vmSymbols::object_initializer_name() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
       thisKlass.name() != vmSymbols::java_lang_Object()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
      _locals[0] = VerificationType::uninitialized_this_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
      _flags |= FLAG_THIS_UNINIT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
      _locals[0] = thisKlass;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  // local num may be greater than size of parameters because long/double occupies two slots
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  while(!ss.at_return_type()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    init_local_num += _verifier->change_sig_to_verificationType(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
      &ss, &_locals[init_local_num],
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
      CHECK_VERIFY_(verifier(), VerificationType::bogus_type()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    ss.next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  _locals_size = init_local_num;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  switch (ss.type()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    case T_OBJECT:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
    case T_ARRAY:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
    {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
      symbolOop sig = ss.as_symbol(CHECK_(VerificationType::bogus_type()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
      return VerificationType::reference_type(symbolHandle(THREAD, sig));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    case T_INT:     return VerificationType::integer_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    case T_BYTE:    return VerificationType::byte_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    case T_CHAR:    return VerificationType::char_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    case T_SHORT:   return VerificationType::short_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    case T_BOOLEAN: return VerificationType::boolean_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
    case T_FLOAT:   return VerificationType::float_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
    case T_DOUBLE:  return VerificationType::double_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
    case T_LONG:    return VerificationType::long_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
    case T_VOID:    return VerificationType::bogus_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
      ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  return VerificationType::bogus_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
void StackMapFrame::copy_locals(const StackMapFrame* src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  int32_t len = src->locals_size() < _locals_size ?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
    src->locals_size() : _locals_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  for (int32_t i = 0; i < len; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
    _locals[i] = src->locals()[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
void StackMapFrame::copy_stack(const StackMapFrame* src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  int32_t len = src->stack_size() < _stack_size ?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
    src->stack_size() : _stack_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  for (int32_t i = 0; i < len; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
    _stack[i] = src->stack()[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
bool StackMapFrame::is_assignable_to(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
    VerificationType* from, VerificationType* to, int32_t len, TRAPS) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  for (int32_t i = 0; i < len; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
    bool subtype = to[i].is_assignable_from(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
      from[i], verifier()->current_class(), THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
    if (!subtype) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
bool StackMapFrame::is_assignable_to(const StackMapFrame* target, TRAPS) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  if (_max_locals != target->max_locals() || _stack_size != target->stack_size()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  // Only need to compare type elements up to target->locals() or target->stack().
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  // The remaining type elements in this state can be ignored because they are
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  // assignable to bogus type.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  bool match_locals = is_assignable_to(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
    _locals, target->locals(), target->locals_size(), CHECK_false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  bool match_stack = is_assignable_to(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
    _stack, target->stack(), _stack_size, CHECK_false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  bool match_flags = (_flags | target->flags()) == target->flags();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  return (match_locals && match_stack && match_flags);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
VerificationType StackMapFrame::pop_stack_ex(VerificationType type, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  if (_stack_size <= 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
    verifier()->verify_error(_offset, "Operand stack underflow");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
    return VerificationType::bogus_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  VerificationType top = _stack[--_stack_size];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  bool subtype = type.is_assignable_from(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
    top, verifier()->current_class(), CHECK_(VerificationType::bogus_type()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  if (!subtype) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
    verifier()->verify_error(_offset, "Bad type on operand stack");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
    return VerificationType::bogus_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  NOT_PRODUCT( _stack[_stack_size] = VerificationType::bogus_type(); )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  return top;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
VerificationType StackMapFrame::get_local(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
    int32_t index, VerificationType type, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  if (index >= _max_locals) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
    verifier()->verify_error(_offset, "Local variable table overflow");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
    return VerificationType::bogus_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  bool subtype = type.is_assignable_from(_locals[index],
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
    verifier()->current_class(), CHECK_(VerificationType::bogus_type()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  if (!subtype) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
    verifier()->verify_error(_offset, "Bad local variable type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
    return VerificationType::bogus_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  if(index >= _locals_size) { _locals_size = index + 1; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  return _locals[index];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
void StackMapFrame::get_local_2(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
    int32_t index, VerificationType type1, VerificationType type2, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  assert(type1.is_long() || type1.is_double(), "must be long/double");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  assert(type2.is_long2() || type2.is_double2(), "must be long/double_2");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  if (index >= _locals_size - 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
    verifier()->verify_error(_offset, "get long/double overflows locals");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  bool subtype1 = type1.is_assignable_from(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
    _locals[index], verifier()->current_class(), CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  bool subtype2 = type2.is_assignable_from(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
    _locals[index+1], verifier()->current_class(), CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  if (!subtype1 || !subtype2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
    verifier()->verify_error(_offset, "Bad local variable type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
void StackMapFrame::set_local(int32_t index, VerificationType type, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
  assert(!type.is_check(), "Must be a real type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  if (index >= _max_locals) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
    verifier()->verify_error("Local variable table overflow", _offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  // If type at index is double or long, set the next location to be unusable
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  if (_locals[index].is_double() || _locals[index].is_long()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
    assert((index + 1) < _locals_size, "Local variable table overflow");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
    _locals[index + 1] = VerificationType::bogus_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  // If type at index is double_2 or long_2, set the previous location to be unusable
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  if (_locals[index].is_double2() || _locals[index].is_long2()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
    assert(index >= 1, "Local variable table underflow");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
    _locals[index - 1] = VerificationType::bogus_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  _locals[index] = type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  if (index >= _locals_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
    for (int i=_locals_size; i<index; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
      assert(_locals[i] == VerificationType::bogus_type(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
             "holes must be bogus type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
    _locals_size = index + 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
void StackMapFrame::set_local_2(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
    int32_t index, VerificationType type1, VerificationType type2, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  assert(type1.is_long() || type1.is_double(), "must be long/double");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
  assert(type2.is_long2() || type2.is_double2(), "must be long/double_2");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  if (index >= _max_locals - 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
    verifier()->verify_error("Local variable table overflow", _offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
  // If type at index+1 is double or long, set the next location to be unusable
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  if (_locals[index+1].is_double() || _locals[index+1].is_long()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
    assert((index + 2) < _locals_size, "Local variable table overflow");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
    _locals[index + 2] = VerificationType::bogus_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
  // If type at index is double_2 or long_2, set the previous location to be unusable
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
  if (_locals[index].is_double2() || _locals[index].is_long2()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
    assert(index >= 1, "Local variable table underflow");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
    _locals[index - 1] = VerificationType::bogus_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
  _locals[index] = type1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
  _locals[index+1] = type2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
  if (index >= _locals_size - 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
    for (int i=_locals_size; i<index; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
      assert(_locals[i] == VerificationType::bogus_type(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
             "holes must be bogus type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
    _locals_size = index + 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
void StackMapFrame::print() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
  tty->print_cr("stackmap_frame[%d]:", _offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
  tty->print_cr("flags = 0x%x", _flags);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
  tty->print("locals[%d] = { ", _locals_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
  for (int32_t i = 0; i < _locals_size; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
    _locals[i].print_on(tty);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
  tty->print_cr(" }");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  tty->print("stack[%d] = { ", _stack_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
  for (int32_t j = 0; j < _stack_size; j++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
    _stack[j].print_on(tty);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
  tty->print_cr(" }");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
#endif