src/share/vm/classfile/stackMapTable.hpp

Tue, 23 Nov 2010 13:22:55 -0800

author
stefank
date
Tue, 23 Nov 2010 13:22:55 -0800
changeset 2314
f95d63e2154a
parent 1907
c18cbe5936b8
child 2508
b92c45f2bc75
permissions
-rw-r--r--

6989984: Use standard include model for Hospot
Summary: Replaced MakeDeps and the includeDB files with more standardized solutions.
Reviewed-by: coleenp, kvn, kamg

duke@435 1 /*
stefank@2314 2 * Copyright (c) 2003, 2010, 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"
stefank@2314 29 #include "memory/allocation.hpp"
stefank@2314 30 #include "oops/constantPoolOop.hpp"
stefank@2314 31 #include "oops/methodOop.hpp"
stefank@2314 32 #include "utilities/globalDefinitions.hpp"
stefank@2314 33 #ifdef TARGET_ARCH_x86
stefank@2314 34 # include "bytes_x86.hpp"
stefank@2314 35 #endif
stefank@2314 36 #ifdef TARGET_ARCH_sparc
stefank@2314 37 # include "bytes_sparc.hpp"
stefank@2314 38 #endif
stefank@2314 39 #ifdef TARGET_ARCH_zero
stefank@2314 40 # include "bytes_zero.hpp"
stefank@2314 41 #endif
stefank@2314 42
duke@435 43 class StackMapReader;
duke@435 44
duke@435 45 // StackMapTable class is the StackMap table used by type checker
duke@435 46 class StackMapTable : public StackObj {
duke@435 47 private:
duke@435 48 // Logically, the _frame_count (as well as many fields in the StackFrame)
duke@435 49 // should be a u2, but if we defined the variable as that type it will
duke@435 50 // be difficult to detect/recover from overflow or underflow conditions.
duke@435 51 // Widening the type and making it signed will help detect these.
duke@435 52 int32_t _code_length;
duke@435 53 int32_t _frame_count; // Stackmap frame count
duke@435 54 StackMapFrame** _frame_array;
duke@435 55
duke@435 56 public:
duke@435 57 StackMapTable(StackMapReader* reader, StackMapFrame* init_frame,
duke@435 58 u2 max_locals, u2 max_stack,
duke@435 59 char* code_data, int code_len, TRAPS);
duke@435 60
duke@435 61 inline int32_t get_frame_count() const { return _frame_count; }
duke@435 62 inline int get_offset(int index) const {
duke@435 63 return _frame_array[index]->offset();
duke@435 64 }
duke@435 65
duke@435 66 // Match and/or update current_frame to the frame in stackmap table with
duke@435 67 // specified offset. Return true if the two frames match.
duke@435 68 bool match_stackmap(
duke@435 69 StackMapFrame* current_frame, int32_t offset,
duke@435 70 bool match, bool update, TRAPS) const;
duke@435 71 // Match and/or update current_frame to the frame in stackmap table with
duke@435 72 // specified offset and frame index. Return true if the two frames match.
duke@435 73 bool match_stackmap(
duke@435 74 StackMapFrame* current_frame, int32_t offset, int32_t frame_index,
duke@435 75 bool match, bool update, TRAPS) const;
duke@435 76
duke@435 77 // Check jump instructions. Make sure there are no uninitialized
duke@435 78 // instances on backward branch.
duke@435 79 void check_jump_target(StackMapFrame* frame, int32_t target, TRAPS) const;
duke@435 80
duke@435 81 // The following methods are only used inside this class.
duke@435 82
duke@435 83 // Returns the frame array index where the frame with offset is stored.
duke@435 84 int get_index_from_offset(int32_t offset) const;
duke@435 85
duke@435 86 // Make sure that there's no uninitialized object exist on backward branch.
duke@435 87 void check_new_object(
duke@435 88 const StackMapFrame* frame, int32_t target, TRAPS) const;
duke@435 89
duke@435 90 // Debugging
duke@435 91 void print() const PRODUCT_RETURN;
duke@435 92 };
duke@435 93
duke@435 94 class StackMapStream : StackObj {
duke@435 95 private:
duke@435 96 typeArrayHandle _data;
duke@435 97 int _index;
duke@435 98 public:
duke@435 99 StackMapStream(typeArrayHandle ah)
duke@435 100 : _data(ah), _index(0) {
duke@435 101 }
duke@435 102 u1 get_u1(TRAPS) {
duke@435 103 if (_data == NULL || _index >= _data->length()) {
duke@435 104 stackmap_format_error("access beyond the end of attribute", CHECK_0);
duke@435 105 }
duke@435 106 return _data->byte_at(_index++);
duke@435 107 }
duke@435 108 u2 get_u2(TRAPS) {
duke@435 109 if (_data == NULL || _index >= _data->length() - 1) {
duke@435 110 stackmap_format_error("access beyond the end of attribute", CHECK_0);
duke@435 111 }
duke@435 112 u2 res = Bytes::get_Java_u2((u1*)_data->byte_at_addr(_index));
duke@435 113 _index += 2;
duke@435 114 return res;
duke@435 115 }
duke@435 116 bool at_end() {
duke@435 117 return (_data == NULL) || (_index == _data->length());
duke@435 118 }
duke@435 119 static void stackmap_format_error(const char* msg, TRAPS);
duke@435 120 };
duke@435 121
duke@435 122 class StackMapReader : StackObj {
duke@435 123 private:
duke@435 124 // information about the class and method
duke@435 125 constantPoolHandle _cp;
duke@435 126 ClassVerifier* _verifier;
duke@435 127 StackMapStream* _stream;
duke@435 128 char* _code_data;
duke@435 129 int32_t _code_length;
duke@435 130
duke@435 131 // information get from the attribute
duke@435 132 int32_t _frame_count; // frame count
duke@435 133
duke@435 134 int32_t chop(VerificationType* locals, int32_t length, int32_t chops);
duke@435 135 VerificationType parse_verification_type(u1* flags, TRAPS);
duke@435 136 void check_verification_type_array_size(
duke@435 137 int32_t size, int32_t max_size, TRAPS) {
duke@435 138 if (size < 0 || size > max_size) {
duke@435 139 // Since this error could be caused someone rewriting the method
duke@435 140 // but not knowing to update the stackmap data, we call the the
duke@435 141 // verifier's error method, which may not throw an exception and
duke@435 142 // failover to the old verifier instead.
duke@435 143 _verifier->class_format_error(
duke@435 144 "StackMapTable format error: bad type array size");
duke@435 145 }
duke@435 146 }
duke@435 147
duke@435 148 enum {
duke@435 149 SAME_LOCALS_1_STACK_ITEM_EXTENDED = 247,
duke@435 150 SAME_EXTENDED = 251,
duke@435 151 FULL = 255
duke@435 152 };
duke@435 153
duke@435 154 public:
duke@435 155 // Constructor
duke@435 156 StackMapReader(ClassVerifier* v, StackMapStream* stream, char* code_data,
duke@435 157 int32_t code_len, TRAPS) :
duke@435 158 _verifier(v), _stream(stream),
duke@435 159 _code_data(code_data), _code_length(code_len) {
duke@435 160 methodHandle m = v->method();
duke@435 161 if (m->has_stackmap_table()) {
duke@435 162 _cp = constantPoolHandle(THREAD, m->constants());
duke@435 163 _frame_count = _stream->get_u2(CHECK);
duke@435 164 } else {
duke@435 165 // There's no stackmap table present. Frame count and size are 0.
duke@435 166 _frame_count = 0;
duke@435 167 }
duke@435 168 }
duke@435 169
duke@435 170 inline int32_t get_frame_count() const { return _frame_count; }
duke@435 171 StackMapFrame* next(StackMapFrame* pre_frame, bool first,
duke@435 172 u2 max_locals, u2 max_stack, TRAPS);
duke@435 173
duke@435 174 void check_end(TRAPS) {
duke@435 175 if (!_stream->at_end()) {
duke@435 176 StackMapStream::stackmap_format_error("wrong attribute size", CHECK);
duke@435 177 }
duke@435 178 }
duke@435 179 };
stefank@2314 180
stefank@2314 181 #endif // SHARE_VM_CLASSFILE_STACKMAPTABLE_HPP

mercurial