src/hotspot/share/classfile/stackMapTable.hpp
author coleenp
Fri, 16 Mar 2018 09:12:13 -0400
changeset 49449 ef5d5d343e2a
parent 47216 71c04702a3d5
child 53244 9807daeb47c4
permissions -rw-r--r--
8199263: Split interfaceSupport.hpp to not require including .inline.hpp files Summary: interfaceSupport.hpp is an inline file so moved to interfaceSupport.inline.hpp and stopped including it in .hpp files Reviewed-by: stefank, rehn, kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
43179
06ccf3bfd0a3 8167104: Additional class construction refinements
hseigel
parents: 25900
diff changeset
     2
 * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 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
#ifndef SHARE_VM_CLASSFILE_STACKMAPTABLE_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#define SHARE_VM_CLASSFILE_STACKMAPTABLE_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "classfile/stackMapFrame.hpp"
13476
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
    29
#include "classfile/verifier.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "memory/allocation.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13476
diff changeset
    31
#include "oops/constantPool.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13476
diff changeset
    32
#include "oops/method.hpp"
25715
d5a8dbdc5150 8049325: Introduce and clean up umbrella headers for the files in the cpu subdirectories.
goetz
parents: 13728
diff changeset
    33
#include "utilities/bytes.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    34
#include "utilities/globalDefinitions.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    35
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
class StackMapReader;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
// StackMapTable class is the StackMap table used by type checker
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
class StackMapTable : public StackObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  // Logically, the _frame_count (as well as many fields in the StackFrame)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  // should be a u2, but if we defined the variable as that type it will
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  // be difficult to detect/recover from overflow or underflow conditions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  // Widening the type and making it signed will help detect these.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  int32_t              _code_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  int32_t              _frame_count;     // Stackmap frame count
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  StackMapFrame**       _frame_array;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  StackMapTable(StackMapReader* reader, StackMapFrame* init_frame,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
                u2 max_locals, u2 max_stack,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
                char* code_data, int code_len, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  inline int32_t get_frame_count() const { return _frame_count; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  inline int get_offset(int index) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    return _frame_array[index]->offset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  // Match and/or update current_frame to the frame in stackmap table with
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  // specified offset. Return true if the two frames match.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  bool match_stackmap(
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    StackMapFrame* current_frame, int32_t offset,
43179
06ccf3bfd0a3 8167104: Additional class construction refinements
hseigel
parents: 25900
diff changeset
    63
    bool match, bool update, ErrorContext* ctx, TRAPS) const;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  // Match and/or update current_frame to the frame in stackmap table with
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  // specified offset and frame index. Return true if the two frames match.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  bool match_stackmap(
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
    StackMapFrame* current_frame, int32_t offset, int32_t frame_index,
43179
06ccf3bfd0a3 8167104: Additional class construction refinements
hseigel
parents: 25900
diff changeset
    68
    bool match, bool update, ErrorContext* ctx, TRAPS) const;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  // Check jump instructions. Make sure there are no uninitialized
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  // instances on backward branch.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  void check_jump_target(StackMapFrame* frame, int32_t target, TRAPS) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  // The following methods are only used inside this class.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  // Returns the frame array index where the frame with offset is stored.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  int get_index_from_offset(int32_t offset) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
13476
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
    79
  void print_on(outputStream* str) const;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
class StackMapStream : StackObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
 private:
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13476
diff changeset
    84
  Array<u1>* _data;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  int _index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
 public:
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13476
diff changeset
    87
  StackMapStream(Array<u1>* ah)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    : _data(ah), _index(0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  u1 get_u1(TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    if (_data == NULL || _index >= _data->length()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
      stackmap_format_error("access beyond the end of attribute", CHECK_0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
    }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13476
diff changeset
    94
    return _data->at(_index++);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  u2 get_u2(TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
    if (_data == NULL || _index >= _data->length() - 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
      stackmap_format_error("access beyond the end of attribute", CHECK_0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
    }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13476
diff changeset
   100
    u2 res = Bytes::get_Java_u2(_data->adr_at(_index));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    _index += 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    return res;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  bool at_end() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
    return (_data == NULL) || (_index == _data->length());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  static void stackmap_format_error(const char* msg, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
class StackMapReader : StackObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  // information about the class and method
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  constantPoolHandle  _cp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  ClassVerifier* _verifier;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  StackMapStream* _stream;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  char* _code_data;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  int32_t _code_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  // information get from the attribute
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  int32_t  _frame_count;       // frame count
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  int32_t chop(VerificationType* locals, int32_t length, int32_t chops);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  VerificationType parse_verification_type(u1* flags, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  void check_verification_type_array_size(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
      int32_t size, int32_t max_size, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
    if (size < 0 || size > max_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
      // Since this error could be caused someone rewriting the method
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
      // but not knowing to update the stackmap data, we call the the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
      // verifier's error method, which may not throw an exception and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
      // failover to the old verifier instead.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
      _verifier->class_format_error(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
        "StackMapTable format error: bad type array size");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  enum {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
    SAME_LOCALS_1_STACK_ITEM_EXTENDED = 247,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
    SAME_EXTENDED = 251,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
    FULL = 255
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  // Constructor
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  StackMapReader(ClassVerifier* v, StackMapStream* stream, char* code_data,
49449
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 47216
diff changeset
   145
                 int32_t code_len, TRAPS);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  inline int32_t get_frame_count() const                { return _frame_count; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  StackMapFrame* next(StackMapFrame* pre_frame, bool first,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
                      u2 max_locals, u2 max_stack, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  void check_end(TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
    if (!_stream->at_end()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
      StackMapStream::stackmap_format_error("wrong attribute size", CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   157
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   158
#endif // SHARE_VM_CLASSFILE_STACKMAPTABLE_HPP