src/share/vm/classfile/stackMapTable.hpp

Thu, 24 May 2018 18:41:44 +0800

author
aoqi
date
Thu, 24 May 2018 18:41:44 +0800
changeset 8856
ac27a9c85bea
parent 8703
02a3d0dcbedd
parent 6876
710a3c8b516e
permissions
-rw-r--r--

Merge

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

mercurial