src/share/vm/classfile/stackMapTable.hpp

Sat, 01 Sep 2012 13:25:18 -0400

author
coleenp
date
Sat, 01 Sep 2012 13:25:18 -0400
changeset 4037
da91efe96a93
parent 3992
4ee06e614636
child 6866
2993491d47df
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>

duke@435 1 /*
kamg@3992 2 * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #ifndef SHARE_VM_CLASSFILE_STACKMAPTABLE_HPP
stefank@2314 26 #define SHARE_VM_CLASSFILE_STACKMAPTABLE_HPP
stefank@2314 27
stefank@2314 28 #include "classfile/stackMapFrame.hpp"
kamg@3992 29 #include "classfile/verifier.hpp"
stefank@2314 30 #include "memory/allocation.hpp"
coleenp@4037 31 #include "oops/constantPool.hpp"
coleenp@4037 32 #include "oops/method.hpp"
stefank@2314 33 #include "utilities/globalDefinitions.hpp"
stefank@2314 34 #ifdef TARGET_ARCH_x86
stefank@2314 35 # include "bytes_x86.hpp"
stefank@2314 36 #endif
stefank@2314 37 #ifdef TARGET_ARCH_sparc
stefank@2314 38 # include "bytes_sparc.hpp"
stefank@2314 39 #endif
stefank@2314 40 #ifdef TARGET_ARCH_zero
stefank@2314 41 # include "bytes_zero.hpp"
stefank@2314 42 #endif
bobv@2508 43 #ifdef TARGET_ARCH_arm
bobv@2508 44 # include "bytes_arm.hpp"
bobv@2508 45 #endif
bobv@2508 46 #ifdef TARGET_ARCH_ppc
bobv@2508 47 # include "bytes_ppc.hpp"
bobv@2508 48 #endif
stefank@2314 49
duke@435 50 class StackMapReader;
duke@435 51
duke@435 52 // StackMapTable class is the StackMap table used by type checker
duke@435 53 class StackMapTable : public StackObj {
duke@435 54 private:
duke@435 55 // Logically, the _frame_count (as well as many fields in the StackFrame)
duke@435 56 // should be a u2, but if we defined the variable as that type it will
duke@435 57 // be difficult to detect/recover from overflow or underflow conditions.
duke@435 58 // Widening the type and making it signed will help detect these.
duke@435 59 int32_t _code_length;
duke@435 60 int32_t _frame_count; // Stackmap frame count
duke@435 61 StackMapFrame** _frame_array;
duke@435 62
duke@435 63 public:
duke@435 64 StackMapTable(StackMapReader* reader, StackMapFrame* init_frame,
duke@435 65 u2 max_locals, u2 max_stack,
duke@435 66 char* code_data, int code_len, TRAPS);
duke@435 67
duke@435 68 inline int32_t get_frame_count() const { return _frame_count; }
duke@435 69 inline int get_offset(int index) const {
duke@435 70 return _frame_array[index]->offset();
duke@435 71 }
duke@435 72
duke@435 73 // Match and/or update current_frame to the frame in stackmap table with
duke@435 74 // specified offset. Return true if the two frames match.
duke@435 75 bool match_stackmap(
duke@435 76 StackMapFrame* current_frame, int32_t offset,
kamg@3992 77 bool match, bool update, ErrorContext* ctx, TRAPS) const;
duke@435 78 // Match and/or update current_frame to the frame in stackmap table with
duke@435 79 // specified offset and frame index. Return true if the two frames match.
duke@435 80 bool match_stackmap(
duke@435 81 StackMapFrame* current_frame, int32_t offset, int32_t frame_index,
kamg@3992 82 bool match, bool update, ErrorContext* ctx, TRAPS) const;
duke@435 83
duke@435 84 // Check jump instructions. Make sure there are no uninitialized
duke@435 85 // instances on backward branch.
duke@435 86 void check_jump_target(StackMapFrame* frame, int32_t target, TRAPS) const;
duke@435 87
duke@435 88 // The following methods are only used inside this class.
duke@435 89
duke@435 90 // Returns the frame array index where the frame with offset is stored.
duke@435 91 int get_index_from_offset(int32_t offset) const;
duke@435 92
duke@435 93 // Make sure that there's no uninitialized object exist on backward branch.
duke@435 94 void check_new_object(
duke@435 95 const StackMapFrame* frame, int32_t target, TRAPS) const;
duke@435 96
kamg@3992 97 void print_on(outputStream* str) const;
duke@435 98 };
duke@435 99
duke@435 100 class StackMapStream : StackObj {
duke@435 101 private:
coleenp@4037 102 Array<u1>* _data;
duke@435 103 int _index;
duke@435 104 public:
coleenp@4037 105 StackMapStream(Array<u1>* ah)
duke@435 106 : _data(ah), _index(0) {
duke@435 107 }
duke@435 108 u1 get_u1(TRAPS) {
duke@435 109 if (_data == NULL || _index >= _data->length()) {
duke@435 110 stackmap_format_error("access beyond the end of attribute", CHECK_0);
duke@435 111 }
coleenp@4037 112 return _data->at(_index++);
duke@435 113 }
duke@435 114 u2 get_u2(TRAPS) {
duke@435 115 if (_data == NULL || _index >= _data->length() - 1) {
duke@435 116 stackmap_format_error("access beyond the end of attribute", CHECK_0);
duke@435 117 }
coleenp@4037 118 u2 res = Bytes::get_Java_u2(_data->adr_at(_index));
duke@435 119 _index += 2;
duke@435 120 return res;
duke@435 121 }
duke@435 122 bool at_end() {
duke@435 123 return (_data == NULL) || (_index == _data->length());
duke@435 124 }
duke@435 125 static void stackmap_format_error(const char* msg, TRAPS);
duke@435 126 };
duke@435 127
duke@435 128 class StackMapReader : StackObj {
duke@435 129 private:
duke@435 130 // information about the class and method
duke@435 131 constantPoolHandle _cp;
duke@435 132 ClassVerifier* _verifier;
duke@435 133 StackMapStream* _stream;
duke@435 134 char* _code_data;
duke@435 135 int32_t _code_length;
duke@435 136
duke@435 137 // information get from the attribute
duke@435 138 int32_t _frame_count; // frame count
duke@435 139
duke@435 140 int32_t chop(VerificationType* locals, int32_t length, int32_t chops);
duke@435 141 VerificationType parse_verification_type(u1* flags, TRAPS);
duke@435 142 void check_verification_type_array_size(
duke@435 143 int32_t size, int32_t max_size, TRAPS) {
duke@435 144 if (size < 0 || size > max_size) {
duke@435 145 // Since this error could be caused someone rewriting the method
duke@435 146 // but not knowing to update the stackmap data, we call the the
duke@435 147 // verifier's error method, which may not throw an exception and
duke@435 148 // failover to the old verifier instead.
duke@435 149 _verifier->class_format_error(
duke@435 150 "StackMapTable format error: bad type array size");
duke@435 151 }
duke@435 152 }
duke@435 153
duke@435 154 enum {
duke@435 155 SAME_LOCALS_1_STACK_ITEM_EXTENDED = 247,
duke@435 156 SAME_EXTENDED = 251,
duke@435 157 FULL = 255
duke@435 158 };
duke@435 159
duke@435 160 public:
duke@435 161 // Constructor
duke@435 162 StackMapReader(ClassVerifier* v, StackMapStream* stream, char* code_data,
duke@435 163 int32_t code_len, TRAPS) :
duke@435 164 _verifier(v), _stream(stream),
duke@435 165 _code_data(code_data), _code_length(code_len) {
duke@435 166 methodHandle m = v->method();
duke@435 167 if (m->has_stackmap_table()) {
duke@435 168 _cp = constantPoolHandle(THREAD, m->constants());
duke@435 169 _frame_count = _stream->get_u2(CHECK);
duke@435 170 } else {
duke@435 171 // There's no stackmap table present. Frame count and size are 0.
duke@435 172 _frame_count = 0;
duke@435 173 }
duke@435 174 }
duke@435 175
duke@435 176 inline int32_t get_frame_count() const { return _frame_count; }
duke@435 177 StackMapFrame* next(StackMapFrame* pre_frame, bool first,
duke@435 178 u2 max_locals, u2 max_stack, TRAPS);
duke@435 179
duke@435 180 void check_end(TRAPS) {
duke@435 181 if (!_stream->at_end()) {
duke@435 182 StackMapStream::stackmap_format_error("wrong attribute size", CHECK);
duke@435 183 }
duke@435 184 }
duke@435 185 };
stefank@2314 186
stefank@2314 187 #endif // SHARE_VM_CLASSFILE_STACKMAPTABLE_HPP

mercurial