src/hotspot/share/classfile/stackMapFrame.cpp
author lfoltan
Mon, 21 Oct 2019 13:13:16 -0400
changeset 58722 cba8afa5cfed
parent 54847 59ea39bb2809
permissions -rw-r--r--
8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently Summary: Increase the use of type signature constants instead of hard coded characters within the JVM. Reviewed-by: coleenp, dholmes, fparain Contributed-by: lois.foltan@oracle.com, john.r.rose@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
54133
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 51334
diff changeset
     2
 * Copyright (c) 2003, 2019, 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: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
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: 1
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: 5547
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#include "classfile/stackMapFrame.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "classfile/verifier.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "memory/resourceArea.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "oops/oop.inline.hpp"
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    30
#include "oops/symbol.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "runtime/handles.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
#include "utilities/globalDefinitions.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
StackMapFrame::StackMapFrame(u2 max_locals, u2 max_stack, ClassVerifier* v) :
13476
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
    35
                      _offset(0), _locals_size(0), _stack_size(0),
51334
cc2c79d22508 8208671: Runtime, JFR, Serviceability changes to allow enabling -Wreorder
tschatzl
parents: 47216
diff changeset
    36
                      _stack_mark(0), _max_locals(max_locals),
cc2c79d22508 8208671: Runtime, JFR, Serviceability changes to allow enabling -Wreorder
tschatzl
parents: 47216
diff changeset
    37
                      _max_stack(max_stack), _flags(0), _verifier(v) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  Thread* thr = v->thread();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  _locals = NEW_RESOURCE_ARRAY_IN_THREAD(thr, VerificationType, max_locals);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  _stack = NEW_RESOURCE_ARRAY_IN_THREAD(thr, VerificationType, max_stack);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  int32_t i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  for(i = 0; i < max_locals; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
    _locals[i] = VerificationType::bogus_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  for(i = 0; i < max_stack; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
    _stack[i] = VerificationType::bogus_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
StackMapFrame* StackMapFrame::frame_in_exception_handler(u1 flags) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  Thread* thr = _verifier->thread();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  VerificationType* stack = NEW_RESOURCE_ARRAY_IN_THREAD(thr, VerificationType, 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  StackMapFrame* frame = new StackMapFrame(_offset, flags, _locals_size, 0, _max_locals, _max_stack, _locals, stack, _verifier);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  return frame;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
void StackMapFrame::initialize_object(
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    VerificationType old_object, VerificationType new_object) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  int32_t i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  for (i = 0; i < _max_locals; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
    if (_locals[i].equals(old_object)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
      _locals[i] = new_object;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  for (i = 0; i < _stack_size; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    if (_stack[i].equals(old_object)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
      _stack[i] = new_object;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  if (old_object == VerificationType::uninitialized_this_type()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    // "this" has been initialized - reset flags
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    _flags = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
VerificationType StackMapFrame::set_locals_from_arg(
35194
7151995ee79e 8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents: 27022
diff changeset
    77
    const methodHandle& m, VerificationType thisKlass, TRAPS) {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    78
  SignatureStream ss(m->signature());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  int init_local_num = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  if (!m->is_static()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
    init_local_num++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    // add one extra argument for instance method
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
    if (m->name() == vmSymbols::object_initializer_name() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
       thisKlass.name() != vmSymbols::java_lang_Object()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
      _locals[0] = VerificationType::uninitialized_this_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
      _flags |= FLAG_THIS_UNINIT;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
      _locals[0] = thisKlass;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  // local num may be greater than size of parameters because long/double occupies two slots
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  while(!ss.at_return_type()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
    init_local_num += _verifier->change_sig_to_verificationType(
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54133
diff changeset
    95
      &ss, &_locals[init_local_num]);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
    ss.next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  _locals_size = init_local_num;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  switch (ss.type()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    case T_OBJECT:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    case T_ARRAY:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    {
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54133
diff changeset
   104
      Symbol* sig = ss.as_symbol();
54133
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 51334
diff changeset
   105
      if (!sig->is_permanent()) {
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 51334
diff changeset
   106
        // Create another symbol to save as signature stream unreferences
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 51334
diff changeset
   107
        // this symbol.
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 51334
diff changeset
   108
        Symbol *sig_copy =
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54133
diff changeset
   109
          verifier()->create_temporary_symbol(sig, 0, sig->utf8_length());
54133
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 51334
diff changeset
   110
        assert(sig_copy == sig, "symbols don't match");
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 51334
diff changeset
   111
        sig = sig_copy;
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 51334
diff changeset
   112
      }
829bf950287e 8220366: Optimize Symbol handling in ClassVerifier and SignatureStream
redestad
parents: 51334
diff changeset
   113
      return VerificationType::reference_type(sig);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    case T_INT:     return VerificationType::integer_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
    case T_BYTE:    return VerificationType::byte_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
    case T_CHAR:    return VerificationType::char_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    case T_SHORT:   return VerificationType::short_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    case T_BOOLEAN: return VerificationType::boolean_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    case T_FLOAT:   return VerificationType::float_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    case T_DOUBLE:  return VerificationType::double_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    case T_LONG:    return VerificationType::long_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
    case T_VOID:    return VerificationType::bogus_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
      ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  return VerificationType::bogus_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
void StackMapFrame::copy_locals(const StackMapFrame* src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  int32_t len = src->locals_size() < _locals_size ?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
    src->locals_size() : _locals_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  for (int32_t i = 0; i < len; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
    _locals[i] = src->locals()[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
void StackMapFrame::copy_stack(const StackMapFrame* src) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  int32_t len = src->stack_size() < _stack_size ?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
    src->stack_size() : _stack_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  for (int32_t i = 0; i < len; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
    _stack[i] = src->stack()[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
13476
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   146
// Returns the location of the first mismatch, or 'len' if there are no
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   147
// mismatches
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   148
int StackMapFrame::is_assignable_to(
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
    VerificationType* from, VerificationType* to, int32_t len, TRAPS) const {
13476
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   150
  int32_t i = 0;
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   151
  for (i = 0; i < len; i++) {
27022
2db6fe33afc2 8036533: Method for correct defaults
hseigel
parents: 25900
diff changeset
   152
    if (!to[i].is_assignable_from(from[i], verifier(), false, THREAD)) {
13476
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   153
      break;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  }
13476
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   156
  return i;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
9128
c8ed9bf1b236 7030388: JCK test failed to reject invalid class check01304m10n.
kamg
parents: 8477
diff changeset
   159
bool StackMapFrame::is_assignable_to(
43179
06ccf3bfd0a3 8167104: Additional class construction refinements
hseigel
parents: 35194
diff changeset
   160
    const StackMapFrame* target, ErrorContext* ctx, TRAPS) const {
13476
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   161
  if (_max_locals != target->max_locals()) {
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   162
    *ctx = ErrorContext::locals_size_mismatch(
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   163
        _offset, (StackMapFrame*)this, (StackMapFrame*)target);
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   164
    return false;
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   165
  }
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   166
  if (_stack_size != target->stack_size()) {
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   167
    *ctx = ErrorContext::stack_size_mismatch(
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   168
        _offset, (StackMapFrame*)this, (StackMapFrame*)target);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  // Only need to compare type elements up to target->locals() or target->stack().
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  // The remaining type elements in this state can be ignored because they are
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  // assignable to bogus type.
13476
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   174
  int mismatch_loc;
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   175
  mismatch_loc = is_assignable_to(
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   176
    _locals, target->locals(), target->locals_size(), THREAD);
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   177
  if (mismatch_loc != target->locals_size()) {
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   178
    *ctx = ErrorContext::bad_type(target->offset(),
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   179
        TypeOrigin::local(mismatch_loc, (StackMapFrame*)this),
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   180
        TypeOrigin::sm_local(mismatch_loc, (StackMapFrame*)target));
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   181
    return false;
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   182
  }
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   183
  mismatch_loc = is_assignable_to(_stack, target->stack(), _stack_size, THREAD);
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   184
  if (mismatch_loc != _stack_size) {
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   185
    *ctx = ErrorContext::bad_type(target->offset(),
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   186
        TypeOrigin::stack(mismatch_loc, (StackMapFrame*)this),
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   187
        TypeOrigin::sm_stack(mismatch_loc, (StackMapFrame*)target));
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   188
    return false;
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   189
  }
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   190
43179
06ccf3bfd0a3 8167104: Additional class construction refinements
hseigel
parents: 35194
diff changeset
   191
  if ((_flags | target->flags()) == target->flags()) {
13476
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   192
    return true;
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   193
  } else {
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   194
    *ctx = ErrorContext::bad_flags(target->offset(),
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   195
        (StackMapFrame*)this, (StackMapFrame*)target);
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   196
    return false;
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   197
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
VerificationType StackMapFrame::pop_stack_ex(VerificationType type, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  if (_stack_size <= 0) {
13476
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   202
    verifier()->verify_error(
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   203
        ErrorContext::stack_underflow(_offset, this),
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   204
        "Operand stack underflow");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
    return VerificationType::bogus_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  VerificationType top = _stack[--_stack_size];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  bool subtype = type.is_assignable_from(
27022
2db6fe33afc2 8036533: Method for correct defaults
hseigel
parents: 25900
diff changeset
   209
    top, verifier(), false, CHECK_(VerificationType::bogus_type()));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  if (!subtype) {
13476
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   211
    verifier()->verify_error(
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   212
        ErrorContext::bad_type(_offset, stack_top_ctx(),
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   213
            TypeOrigin::implicit(type)),
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   214
        "Bad type on operand stack");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
    return VerificationType::bogus_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  return top;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
VerificationType StackMapFrame::get_local(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
    int32_t index, VerificationType type, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  if (index >= _max_locals) {
13476
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   223
    verifier()->verify_error(
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   224
        ErrorContext::bad_local_index(_offset, index),
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   225
        "Local variable table overflow");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
    return VerificationType::bogus_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
  bool subtype = type.is_assignable_from(_locals[index],
27022
2db6fe33afc2 8036533: Method for correct defaults
hseigel
parents: 25900
diff changeset
   229
    verifier(), false, CHECK_(VerificationType::bogus_type()));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  if (!subtype) {
13476
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   231
    verifier()->verify_error(
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   232
        ErrorContext::bad_type(_offset,
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   233
          TypeOrigin::local(index, this),
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   234
          TypeOrigin::implicit(type)),
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   235
        "Bad local variable type");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
    return VerificationType::bogus_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  if(index >= _locals_size) { _locals_size = index + 1; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  return _locals[index];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
void StackMapFrame::get_local_2(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
    int32_t index, VerificationType type1, VerificationType type2, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  assert(type1.is_long() || type1.is_double(), "must be long/double");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  assert(type2.is_long2() || type2.is_double2(), "must be long/double_2");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
  if (index >= _locals_size - 1) {
13476
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   247
    verifier()->verify_error(
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   248
        ErrorContext::bad_local_index(_offset, index),
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   249
        "get long/double overflows locals");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  }
27022
2db6fe33afc2 8036533: Method for correct defaults
hseigel
parents: 25900
diff changeset
   252
  bool subtype = type1.is_assignable_from(_locals[index], verifier(), false, CHECK);
13476
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   253
  if (!subtype) {
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   254
    verifier()->verify_error(
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   255
        ErrorContext::bad_type(_offset,
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   256
            TypeOrigin::local(index, this), TypeOrigin::implicit(type1)),
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   257
        "Bad local variable type");
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   258
  } else {
27022
2db6fe33afc2 8036533: Method for correct defaults
hseigel
parents: 25900
diff changeset
   259
    subtype = type2.is_assignable_from(_locals[index + 1], verifier(), false, CHECK);
13476
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   260
    if (!subtype) {
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   261
      /* Unreachable? All local store routines convert a split long or double
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   262
       * into a TOP during the store.  So we should never end up seeing an
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   263
       * orphaned half.  */
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   264
      verifier()->verify_error(
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   265
          ErrorContext::bad_type(_offset,
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   266
              TypeOrigin::local(index + 1, this), TypeOrigin::implicit(type2)),
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   267
          "Bad local variable type");
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   268
    }
1
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
void StackMapFrame::set_local(int32_t index, VerificationType type, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
  assert(!type.is_check(), "Must be a real type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
  if (index >= _max_locals) {
13476
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   275
    verifier()->verify_error(
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   276
        ErrorContext::bad_local_index(_offset, index),
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   277
        "Local variable table overflow");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
  // If type at index is double or long, set the next location to be unusable
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
  if (_locals[index].is_double() || _locals[index].is_long()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
    assert((index + 1) < _locals_size, "Local variable table overflow");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
    _locals[index + 1] = VerificationType::bogus_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
  // If type at index is double_2 or long_2, set the previous location to be unusable
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
  if (_locals[index].is_double2() || _locals[index].is_long2()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
    assert(index >= 1, "Local variable table underflow");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
    _locals[index - 1] = VerificationType::bogus_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
  _locals[index] = type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
  if (index >= _locals_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
    for (int i=_locals_size; i<index; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
      assert(_locals[i] == VerificationType::bogus_type(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
             "holes must be bogus type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
    _locals_size = index + 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
void StackMapFrame::set_local_2(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
    int32_t index, VerificationType type1, VerificationType type2, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
  assert(type1.is_long() || type1.is_double(), "must be long/double");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
  assert(type2.is_long2() || type2.is_double2(), "must be long/double_2");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  if (index >= _max_locals - 1) {
13476
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   307
    verifier()->verify_error(
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   308
        ErrorContext::bad_local_index(_offset, index),
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   309
        "Local variable table overflow");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
  // If type at index+1 is double or long, set the next location to be unusable
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
  if (_locals[index+1].is_double() || _locals[index+1].is_long()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
    assert((index + 2) < _locals_size, "Local variable table overflow");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
    _locals[index + 2] = VerificationType::bogus_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  // If type at index is double_2 or long_2, set the previous location to be unusable
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
  if (_locals[index].is_double2() || _locals[index].is_long2()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
    assert(index >= 1, "Local variable table underflow");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
    _locals[index - 1] = VerificationType::bogus_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
  _locals[index] = type1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
  _locals[index+1] = type2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
  if (index >= _locals_size - 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
    for (int i=_locals_size; i<index; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
      assert(_locals[i] == VerificationType::bogus_type(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
             "holes must be bogus type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
    _locals_size = index + 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
13476
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   335
TypeOrigin StackMapFrame::stack_top_ctx() {
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   336
  return TypeOrigin::stack(_stack_size, this);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
13476
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   339
void StackMapFrame::print_on(outputStream* str) const {
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   340
  str->indent().print_cr("bci: @%d", _offset);
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   341
  str->indent().print_cr("flags: {%s }",
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   342
      flag_this_uninit() ? " flagThisUninit" : "");
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   343
  str->indent().print("locals: {");
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   344
  for (int32_t i = 0; i < _locals_size; ++i) {
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   345
    str->print(" ");
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   346
    _locals[i].print_on(str);
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   347
    if (i != _locals_size - 1) {
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   348
      str->print(",");
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   349
    }
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   350
  }
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   351
  str->print_cr(" }");
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   352
  str->indent().print("stack: {");
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   353
  for (int32_t j = 0; j < _stack_size; ++j) {
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   354
    str->print(" ");
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   355
    _stack[j].print_on(str);
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   356
    if (j != _stack_size - 1) {
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   357
      str->print(",");
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   358
    }
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   359
  }
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   360
  str->print_cr(" }");
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 9133
diff changeset
   361
}