hotspot/src/share/vm/classfile/stackMapTable.cpp
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 1 489c9b5090e2
child 5547 f4b087cbb361
permissions -rw-r--r--
Initial load
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/_stackMapTable.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
StackMapTable::StackMapTable(StackMapReader* reader, StackMapFrame* init_frame,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
                             u2 max_locals, u2 max_stack,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
                             char* code_data, int code_len, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
  _code_length = code_len;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
  _frame_count = reader->get_frame_count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
  if (_frame_count > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
    _frame_array = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
                                                StackMapFrame*, _frame_count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
    StackMapFrame* pre_frame = init_frame;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
    for (int32_t i = 0; i < _frame_count; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
      StackMapFrame* frame = reader->next(
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
        pre_frame, i == 0, max_locals, max_stack,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
        CHECK_VERIFY(pre_frame->verifier()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
      _frame_array[i] = frame;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
      int offset = frame->offset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
      if (offset >= code_len || code_data[offset] == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
        frame->verifier()->verify_error("StackMapTable error: bad offset");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
      pre_frame = frame;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  reader->check_end(CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
// This method is only called by method in StackMapTable.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
int StackMapTable::get_index_from_offset(int32_t offset) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  int i = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  for (; i < _frame_count; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    if (_frame_array[i]->offset() == offset) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
      return i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  return i;  // frame with offset doesn't exist in the array
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
bool StackMapTable::match_stackmap(
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    StackMapFrame* frame, int32_t target,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    bool match, bool update, TRAPS) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  int index = get_index_from_offset(target);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  return match_stackmap(
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    frame, target, index, match,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    update, CHECK_VERIFY_(frame->verifier(), false));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
// Match and/or update current_frame to the frame in stackmap table with
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
// specified offset and frame index. Return true if the two frames match.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
// The values of match and update are:                  _match__update_
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
// checking a branch target/exception handler:           true   false
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
// linear bytecode verification following an
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
// unconditional branch:                                 false  true
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
// linear bytecode verification not following an
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
// unconditional branch:                                 true   true
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
bool StackMapTable::match_stackmap(
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    StackMapFrame* frame, int32_t target, int32_t frame_index,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    bool match, bool update, TRAPS) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  if (frame_index < 0 || frame_index >= _frame_count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    frame->verifier()->verify_error(frame->offset(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
      "Expecting a stackmap frame at branch target %d", target);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  bool result = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  StackMapFrame *stackmap_frame = _frame_array[frame_index];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  if (match) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
    // Has direct control flow from last instruction, need to match the two
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
    // frames.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
    result = frame->is_assignable_to(
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
      stackmap_frame, CHECK_VERIFY_(frame->verifier(), false));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  if (update) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    // Use the frame in stackmap table as current frame
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    int lsize = stackmap_frame->locals_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    int ssize = stackmap_frame->stack_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
    if (frame->locals_size() > lsize || frame->stack_size() > ssize) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
      // Make sure unused type array items are all _bogus_type.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
      frame->reset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    frame->set_locals_size(lsize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    frame->copy_locals(stackmap_frame);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    frame->set_stack_size(ssize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    frame->copy_stack(stackmap_frame);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
    frame->set_flags(stackmap_frame->flags());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
void StackMapTable::check_jump_target(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    StackMapFrame* frame, int32_t target, TRAPS) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  bool match = match_stackmap(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    frame, target, true, false, CHECK_VERIFY(frame->verifier()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  if (!match || (target < 0 || target >= _code_length)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
    frame->verifier()->verify_error(frame->offset(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
      "Inconsistent stackmap frames at branch target %d", target);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  // check if uninitialized objects exist on backward branches
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  check_new_object(frame, target, CHECK_VERIFY(frame->verifier()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
void StackMapTable::check_new_object(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
    const StackMapFrame* frame, int32_t target, TRAPS) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  if (frame->offset() > target && frame->has_new_object()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
    frame->verifier()->verify_error(frame->offset(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
      "Uninitialized object exists on backward branch %d", target);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
void StackMapTable::print() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  tty->print_cr("StackMapTable: frame_count = %d", _frame_count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  tty->print_cr("table = { ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  for (int32_t i = 0; i < _frame_count; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
    _frame_array[i]->print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  tty->print_cr(" }");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
int32_t StackMapReader::chop(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
    VerificationType* locals, int32_t length, int32_t chops) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  int32_t pos = length - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  for (int32_t i=0; i<chops; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    if (locals[pos].is_category2_2nd()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
      pos -= 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
      pos --;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
    if (pos<0 && i<(chops-1)) return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  return pos+1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
VerificationType StackMapReader::parse_verification_type(u1* flags, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  u1 tag = _stream->get_u1(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  if (tag < (u1)ITEM_UninitializedThis) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
    return VerificationType::from_tag(tag);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  if (tag == ITEM_Object) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
    u2 class_index = _stream->get_u2(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
    int nconstants = _cp->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
    if ((class_index <= 0 || class_index >= nconstants) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
        (!_cp->tag_at(class_index).is_klass() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
         !_cp->tag_at(class_index).is_unresolved_klass())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
      _stream->stackmap_format_error("bad class index", THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
      return VerificationType::bogus_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
    return VerificationType::reference_type(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
      symbolHandle(THREAD, _cp->klass_name_at(class_index)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  if (tag == ITEM_UninitializedThis) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
    if (flags != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
      *flags |= FLAG_THIS_UNINIT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
    return VerificationType::uninitialized_this_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  if (tag == ITEM_Uninitialized) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
    u2 offset = _stream->get_u2(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
    if (offset >= _code_length ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
        _code_data[offset] != ClassVerifier::NEW_OFFSET) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
      ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
      _verifier->class_format_error(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
        "StackMapTable format error: bad offset for Uninitialized");
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
    return VerificationType::uninitialized_type(offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  _stream->stackmap_format_error("bad verification type", THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  return VerificationType::bogus_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
StackMapFrame* StackMapReader::next(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
    StackMapFrame* pre_frame, bool first, u2 max_locals, u2 max_stack, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  StackMapFrame* frame;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  int offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  VerificationType* locals = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  u1 frame_type = _stream->get_u1(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  if (frame_type < 64) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
    // same_frame
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
    if (first) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
      offset = frame_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
      // Can't share the locals array since that is updated by the verifier.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
      if (pre_frame->locals_size() > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
        locals = NEW_RESOURCE_ARRAY_IN_THREAD(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
          THREAD, VerificationType, pre_frame->locals_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
      offset = pre_frame->offset() + frame_type + 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
      locals = pre_frame->locals();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
    frame = new StackMapFrame(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
      offset, pre_frame->flags(), pre_frame->locals_size(), 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
      max_locals, max_stack, locals, NULL, _verifier);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
    if (first && locals != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
      frame->copy_locals(pre_frame);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
    return frame;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  if (frame_type < 128) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
    // same_locals_1_stack_item_frame
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
    if (first) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
      offset = frame_type - 64;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
      // Can't share the locals array since that is updated by the verifier.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
      if (pre_frame->locals_size() > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
        locals = NEW_RESOURCE_ARRAY_IN_THREAD(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
          THREAD, VerificationType, pre_frame->locals_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
      offset = pre_frame->offset() + frame_type - 63;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
      locals = pre_frame->locals();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
    VerificationType* stack = NEW_RESOURCE_ARRAY_IN_THREAD(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
      THREAD, VerificationType, 2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
    u2 stack_size = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
    stack[0] = parse_verification_type(NULL, CHECK_VERIFY_(_verifier, NULL));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
    if (stack[0].is_category2()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
      stack[1] = stack[0].to_category2_2nd();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
      stack_size = 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
    check_verification_type_array_size(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
      stack_size, max_stack, CHECK_VERIFY_(_verifier, NULL));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
    frame = new StackMapFrame(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
      offset, pre_frame->flags(), pre_frame->locals_size(), stack_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
      max_locals, max_stack, locals, stack, _verifier);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
    if (first && locals != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
      frame->copy_locals(pre_frame);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
    return frame;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  u2 offset_delta = _stream->get_u2(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  if (frame_type < SAME_LOCALS_1_STACK_ITEM_EXTENDED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
    // reserved frame types
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
    _stream->stackmap_format_error(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
      "reserved frame type", CHECK_VERIFY_(_verifier, NULL));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  if (frame_type == SAME_LOCALS_1_STACK_ITEM_EXTENDED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
    // same_locals_1_stack_item_frame_extended
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
    if (first) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
      offset = offset_delta;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
      // Can't share the locals array since that is updated by the verifier.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
      if (pre_frame->locals_size() > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
        locals = NEW_RESOURCE_ARRAY_IN_THREAD(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
          THREAD, VerificationType, pre_frame->locals_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
      offset = pre_frame->offset() + offset_delta + 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
      locals = pre_frame->locals();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
    VerificationType* stack = NEW_RESOURCE_ARRAY_IN_THREAD(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
      THREAD, VerificationType, 2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
    u2 stack_size = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
    stack[0] = parse_verification_type(NULL, CHECK_VERIFY_(_verifier, NULL));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
    if (stack[0].is_category2()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
      stack[1] = stack[0].to_category2_2nd();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
      stack_size = 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
    check_verification_type_array_size(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
      stack_size, max_stack, CHECK_VERIFY_(_verifier, NULL));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
    frame = new StackMapFrame(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
      offset, pre_frame->flags(), pre_frame->locals_size(), stack_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
      max_locals, max_stack, locals, stack, _verifier);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
    if (first && locals != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
      frame->copy_locals(pre_frame);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
    return frame;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
  if (frame_type <= SAME_EXTENDED) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
    // chop_frame or same_frame_extended
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
    locals = pre_frame->locals();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
    int length = pre_frame->locals_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
    int chops = SAME_EXTENDED - frame_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
    int new_length = length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
    u1 flags = pre_frame->flags();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
    if (chops != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
      new_length = chop(locals, length, chops);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
      check_verification_type_array_size(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
        new_length, max_locals, CHECK_VERIFY_(_verifier, NULL));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
      // Recompute flags since uninitializedThis could have been chopped.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
      flags = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
      for (int i=0; i<new_length; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
        if (locals[i].is_uninitialized_this()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
          flags |= FLAG_THIS_UNINIT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
    if (first) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
      offset = offset_delta;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
      // Can't share the locals array since that is updated by the verifier.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
      if (new_length > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
        locals = NEW_RESOURCE_ARRAY_IN_THREAD(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
          THREAD, VerificationType, new_length);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
        locals = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
      offset = pre_frame->offset() + offset_delta + 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
    frame = new StackMapFrame(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
      offset, flags, new_length, 0, max_locals, max_stack,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
      locals, NULL, _verifier);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
    if (first && locals != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
      frame->copy_locals(pre_frame);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
    return frame;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
  } else if (frame_type < SAME_EXTENDED + 4) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
    // append_frame
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
    int appends = frame_type - SAME_EXTENDED;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
    int real_length = pre_frame->locals_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
    int new_length = real_length + appends*2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
    locals = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, VerificationType, new_length);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
    VerificationType* pre_locals = pre_frame->locals();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
    int i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
    for (i=0; i<pre_frame->locals_size(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
      locals[i] = pre_locals[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
    u1 flags = pre_frame->flags();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
    for (i=0; i<appends; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
      locals[real_length] = parse_verification_type(&flags, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
      if (locals[real_length].is_category2()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
        locals[real_length + 1] = locals[real_length].to_category2_2nd();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
        ++real_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
      ++real_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
    check_verification_type_array_size(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
      real_length, max_locals, CHECK_VERIFY_(_verifier, NULL));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
    if (first) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
      offset = offset_delta;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
      offset = pre_frame->offset() + offset_delta + 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
    frame = new StackMapFrame(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
      offset, flags, real_length, 0, max_locals,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
      max_stack, locals, NULL, _verifier);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
    return frame;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
  if (frame_type == FULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
    // full_frame
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
    u1 flags = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
    u2 locals_size = _stream->get_u2(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
    int real_locals_size = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
    if (locals_size > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
      locals = NEW_RESOURCE_ARRAY_IN_THREAD(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
        THREAD, VerificationType, locals_size*2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
    int i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
    for (i=0; i<locals_size; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
      locals[real_locals_size] = parse_verification_type(&flags, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
      if (locals[real_locals_size].is_category2()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
        locals[real_locals_size + 1] =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
          locals[real_locals_size].to_category2_2nd();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
        ++real_locals_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
      ++real_locals_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
    check_verification_type_array_size(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
      real_locals_size, max_locals, CHECK_VERIFY_(_verifier, NULL));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
    u2 stack_size = _stream->get_u2(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
    int real_stack_size = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
    VerificationType* stack = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
    if (stack_size > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
      stack = NEW_RESOURCE_ARRAY_IN_THREAD(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
        THREAD, VerificationType, stack_size*2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
    for (i=0; i<stack_size; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
      stack[real_stack_size] = parse_verification_type(NULL, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
      if (stack[real_stack_size].is_category2()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
        stack[real_stack_size + 1] = stack[real_stack_size].to_category2_2nd();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
        ++real_stack_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
      ++real_stack_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
    check_verification_type_array_size(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
      real_stack_size, max_stack, CHECK_VERIFY_(_verifier, NULL));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
    if (first) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
      offset = offset_delta;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
      offset = pre_frame->offset() + offset_delta + 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
    frame = new StackMapFrame(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
      offset, flags, real_locals_size, real_stack_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
      max_locals, max_stack, locals, stack, _verifier);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
    return frame;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
  _stream->stackmap_format_error(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
    "reserved frame type", CHECK_VERIFY_(pre_frame->verifier(), NULL));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
}