hotspot/src/share/vm/classfile/stackMapTable.hpp
author coleenp
Sat, 01 Sep 2012 13:25:18 -0400
changeset 13728 882756847a04
parent 13476 471200fb94fd
child 25715 d5a8dbdc5150
permissions -rw-r--r--
6964458: Reimplement class meta-data storage to use native memory Summary: Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland Contributed-by: jmasa <jon.masamitsu@oracle.com>, stefank <stefan.karlsson@oracle.com>, mgerdin <mikael.gerdin@oracle.com>, never <tom.rodriguez@oracle.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
13476
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
     2
 * Copyright (c) 2003, 2012, 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"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    33
#include "utilities/globalDefinitions.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    34
#ifdef TARGET_ARCH_x86
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    35
# include "bytes_x86.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    36
#endif
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    37
#ifdef TARGET_ARCH_sparc
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    38
# include "bytes_sparc.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    39
#endif
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    40
#ifdef TARGET_ARCH_zero
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    41
# include "bytes_zero.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    42
#endif
8107
78e5bd944384 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 7397
diff changeset
    43
#ifdef TARGET_ARCH_arm
78e5bd944384 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 7397
diff changeset
    44
# include "bytes_arm.hpp"
78e5bd944384 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 7397
diff changeset
    45
#endif
78e5bd944384 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 7397
diff changeset
    46
#ifdef TARGET_ARCH_ppc
78e5bd944384 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 7397
diff changeset
    47
# include "bytes_ppc.hpp"
78e5bd944384 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 7397
diff changeset
    48
#endif
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    49
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
class StackMapReader;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
// StackMapTable class is the StackMap table used by type checker
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
class StackMapTable : public StackObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  // Logically, the _frame_count (as well as many fields in the StackFrame)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  // should be a u2, but if we defined the variable as that type it will
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  // be difficult to detect/recover from overflow or underflow conditions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  // Widening the type and making it signed will help detect these.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  int32_t              _code_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  int32_t              _frame_count;     // Stackmap frame count
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  StackMapFrame**       _frame_array;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  StackMapTable(StackMapReader* reader, StackMapFrame* init_frame,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
                u2 max_locals, u2 max_stack,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
                char* code_data, int code_len, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  inline int32_t get_frame_count() const { return _frame_count; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  inline int get_offset(int index) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    return _frame_array[index]->offset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  // Match and/or update current_frame to the frame in stackmap table with
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  // specified offset. Return true if the two frames match.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  bool match_stackmap(
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    StackMapFrame* current_frame, int32_t offset,
13476
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
    77
    bool match, bool update, ErrorContext* ctx, TRAPS) const;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  // Match and/or update current_frame to the frame in stackmap table with
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  // specified offset and frame index. Return true if the two frames match.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  bool match_stackmap(
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
    StackMapFrame* current_frame, int32_t offset, int32_t frame_index,
13476
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
    82
    bool match, bool update, ErrorContext* ctx, TRAPS) const;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  // Check jump instructions. Make sure there are no uninitialized
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  // instances on backward branch.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  void check_jump_target(StackMapFrame* frame, int32_t target, TRAPS) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  // The following methods are only used inside this class.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  // Returns the frame array index where the frame with offset is stored.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  int get_index_from_offset(int32_t offset) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  // Make sure that there's no uninitialized object exist on backward branch.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  void check_new_object(
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
    const StackMapFrame* frame, int32_t target, TRAPS) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
13476
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
    97
  void print_on(outputStream* str) const;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
class StackMapStream : StackObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
 private:
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13476
diff changeset
   102
  Array<u1>* _data;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  int _index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
 public:
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13476
diff changeset
   105
  StackMapStream(Array<u1>* ah)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    : _data(ah), _index(0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  u1 get_u1(TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    if (_data == NULL || _index >= _data->length()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
      stackmap_format_error("access beyond the end of attribute", CHECK_0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13476
diff changeset
   112
    return _data->at(_index++);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  u2 get_u2(TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    if (_data == NULL || _index >= _data->length() - 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
      stackmap_format_error("access beyond the end of attribute", CHECK_0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
    }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13476
diff changeset
   118
    u2 res = Bytes::get_Java_u2(_data->adr_at(_index));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    _index += 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    return res;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  bool at_end() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
    return (_data == NULL) || (_index == _data->length());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  static void stackmap_format_error(const char* msg, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
class StackMapReader : StackObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  // information about the class and method
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  constantPoolHandle  _cp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  ClassVerifier* _verifier;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  StackMapStream* _stream;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  char* _code_data;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  int32_t _code_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  // information get from the attribute
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  int32_t  _frame_count;       // frame count
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  int32_t chop(VerificationType* locals, int32_t length, int32_t chops);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  VerificationType parse_verification_type(u1* flags, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  void check_verification_type_array_size(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
      int32_t size, int32_t max_size, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
    if (size < 0 || size > max_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
      // Since this error could be caused someone rewriting the method
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
      // but not knowing to update the stackmap data, we call the the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
      // verifier's error method, which may not throw an exception and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
      // failover to the old verifier instead.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
      _verifier->class_format_error(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
        "StackMapTable format error: bad type array size");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  enum {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
    SAME_LOCALS_1_STACK_ITEM_EXTENDED = 247,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
    SAME_EXTENDED = 251,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    FULL = 255
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  // Constructor
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  StackMapReader(ClassVerifier* v, StackMapStream* stream, char* code_data,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
                 int32_t code_len, TRAPS) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
                 _verifier(v), _stream(stream),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
                 _code_data(code_data), _code_length(code_len) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
    methodHandle m = v->method();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
    if (m->has_stackmap_table()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
      _cp = constantPoolHandle(THREAD, m->constants());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
      _frame_count = _stream->get_u2(CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
      // There's no stackmap table present. Frame count and size are 0.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
      _frame_count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  inline int32_t get_frame_count() const                { return _frame_count; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  StackMapFrame* next(StackMapFrame* pre_frame, bool first,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
                      u2 max_locals, u2 max_stack, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  void check_end(TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
    if (!_stream->at_end()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
      StackMapStream::stackmap_format_error("wrong attribute size", CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   186
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   187
#endif // SHARE_VM_CLASSFILE_STACKMAPTABLE_HPP