src/share/vm/classfile/stackMapFrame.hpp

Sat, 01 Dec 2007 00:00:00 +0000

author
duke
date
Sat, 01 Dec 2007 00:00:00 +0000
changeset 435
a61af66fc99e
child 1907
c18cbe5936b8
permissions
-rw-r--r--

Initial load

duke@435 1 /*
duke@435 2 * Copyright 2003-2006 Sun Microsystems, Inc. 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 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 // A StackMapFrame represents one frame in the stack map attribute.
duke@435 26
duke@435 27 enum {
duke@435 28 FLAG_THIS_UNINIT = 0x01
duke@435 29 };
duke@435 30
duke@435 31 class StackMapFrame : public ResourceObj {
duke@435 32 private:
duke@435 33 int32_t _offset;
duke@435 34
duke@435 35 // See comment in StackMapTable about _frame_count about why these
duke@435 36 // fields are int32_t instead of u2.
duke@435 37 int32_t _locals_size; // number of valid type elements in _locals
duke@435 38 int32_t _stack_size; // number of valid type elements in _stack
duke@435 39
duke@435 40 int32_t _max_locals;
duke@435 41 int32_t _max_stack;
duke@435 42
duke@435 43 u1 _flags;
duke@435 44 VerificationType* _locals; // local variable type array
duke@435 45 VerificationType* _stack; // operand stack type array
duke@435 46
duke@435 47 ClassVerifier* _verifier; // the verifier verifying this method
duke@435 48
duke@435 49 public:
duke@435 50 // constructors
duke@435 51
duke@435 52 // This constructor is used by the type checker to allocate frames
duke@435 53 // in type state, which have _max_locals and _max_stack array elements
duke@435 54 // in _locals and _stack.
duke@435 55 StackMapFrame(u2 max_locals, u2 max_stack, ClassVerifier* verifier);
duke@435 56
duke@435 57 // This constructor is used to initialize stackmap frames in stackmap table,
duke@435 58 // which have _locals_size and _stack_size array elements in _locals and _stack.
duke@435 59 StackMapFrame(int32_t offset,
duke@435 60 u1 flags,
duke@435 61 u2 locals_size,
duke@435 62 u2 stack_size,
duke@435 63 u2 max_locals,
duke@435 64 u2 max_stack,
duke@435 65 VerificationType* locals,
duke@435 66 VerificationType* stack,
duke@435 67 ClassVerifier* v) : _offset(offset), _flags(flags),
duke@435 68 _locals_size(locals_size),
duke@435 69 _stack_size(stack_size),
duke@435 70 _max_locals(max_locals),
duke@435 71 _max_stack(max_stack),
duke@435 72 _locals(locals), _stack(stack),
duke@435 73 _verifier(v) { }
duke@435 74
duke@435 75 inline void set_offset(int32_t offset) { _offset = offset; }
duke@435 76 inline void set_verifier(ClassVerifier* v) { _verifier = v; }
duke@435 77 inline void set_flags(u1 flags) { _flags = flags; }
duke@435 78 inline void set_locals_size(u2 locals_size) { _locals_size = locals_size; }
duke@435 79 inline void set_stack_size(u2 stack_size) { _stack_size = stack_size; }
duke@435 80 inline void clear_stack() { _stack_size = 0; }
duke@435 81 inline int32_t offset() const { return _offset; }
duke@435 82 inline ClassVerifier* verifier() const { return _verifier; }
duke@435 83 inline u1 flags() const { return _flags; }
duke@435 84 inline int32_t locals_size() const { return _locals_size; }
duke@435 85 inline VerificationType* locals() const { return _locals; }
duke@435 86 inline int32_t stack_size() const { return _stack_size; }
duke@435 87 inline VerificationType* stack() const { return _stack; }
duke@435 88 inline int32_t max_locals() const { return _max_locals; }
duke@435 89 inline int32_t max_stack() const { return _max_stack; }
duke@435 90 inline bool flag_this_uninit() const { return _flags & FLAG_THIS_UNINIT; }
duke@435 91
duke@435 92 // Set locals and stack types to bogus
duke@435 93 inline void reset() {
duke@435 94 int32_t i;
duke@435 95 for (i = 0; i < _max_locals; i++) {
duke@435 96 _locals[i] = VerificationType::bogus_type();
duke@435 97 }
duke@435 98 for (i = 0; i < _max_stack; i++) {
duke@435 99 _stack[i] = VerificationType::bogus_type();
duke@435 100 }
duke@435 101 }
duke@435 102
duke@435 103 // Return a StackMapFrame with the same local variable array and empty stack.
duke@435 104 // Stack array is allocate with unused one element.
duke@435 105 StackMapFrame* frame_in_exception_handler(u1 flags);
duke@435 106
duke@435 107 // Set local variable type array based on m's signature.
duke@435 108 VerificationType set_locals_from_arg(
duke@435 109 const methodHandle m, VerificationType thisKlass, TRAPS);
duke@435 110
duke@435 111 // Search local variable type array and stack type array.
duke@435 112 // Return true if an uninitialized object is found.
duke@435 113 bool has_new_object() const;
duke@435 114
duke@435 115 // Search local variable type array and stack type array.
duke@435 116 // Set every element with type of old_object to new_object.
duke@435 117 void initialize_object(
duke@435 118 VerificationType old_object, VerificationType new_object);
duke@435 119
duke@435 120 // Copy local variable type array in src into this local variable type array.
duke@435 121 void copy_locals(const StackMapFrame* src);
duke@435 122
duke@435 123 // Copy stack type array in src into this stack type array.
duke@435 124 void copy_stack(const StackMapFrame* src);
duke@435 125
duke@435 126 // Return true if this stack map frame is assignable to target.
duke@435 127 bool is_assignable_to(const StackMapFrame* target, TRAPS) const;
duke@435 128
duke@435 129 // Push type into stack type array.
duke@435 130 inline void push_stack(VerificationType type, TRAPS) {
duke@435 131 assert(!type.is_check(), "Must be a real type");
duke@435 132 if (_stack_size >= _max_stack) {
duke@435 133 verifier()->verify_error(_offset, "Operand stack overflow");
duke@435 134 return;
duke@435 135 }
duke@435 136 _stack[_stack_size++] = type;
duke@435 137 }
duke@435 138
duke@435 139 inline void push_stack_2(
duke@435 140 VerificationType type1, VerificationType type2, TRAPS) {
duke@435 141 assert(type1.is_long() || type1.is_double(), "must be long/double");
duke@435 142 assert(type2.is_long2() || type2.is_double2(), "must be long/double_2");
duke@435 143 if (_stack_size >= _max_stack - 1) {
duke@435 144 verifier()->verify_error(_offset, "Operand stack overflow");
duke@435 145 return;
duke@435 146 }
duke@435 147 _stack[_stack_size++] = type1;
duke@435 148 _stack[_stack_size++] = type2;
duke@435 149 }
duke@435 150
duke@435 151 // Pop and return the top type on stack without verifying.
duke@435 152 inline VerificationType pop_stack(TRAPS) {
duke@435 153 if (_stack_size <= 0) {
duke@435 154 verifier()->verify_error(_offset, "Operand stack underflow");
duke@435 155 return VerificationType::bogus_type();
duke@435 156 }
duke@435 157 // Put bogus type to indicate it's no longer valid.
duke@435 158 // Added to make it consistent with the other pop_stack method.
duke@435 159 VerificationType top = _stack[--_stack_size];
duke@435 160 NOT_PRODUCT( _stack[_stack_size] = VerificationType::bogus_type(); )
duke@435 161 return top;
duke@435 162 }
duke@435 163
duke@435 164 // Pop and return the top type on stack type array after verifying it
duke@435 165 // is assignable to type.
duke@435 166 inline VerificationType pop_stack(VerificationType type, TRAPS) {
duke@435 167 if (_stack_size != 0) {
duke@435 168 VerificationType top = _stack[_stack_size - 1];
duke@435 169 bool subtype = type.is_assignable_from(
duke@435 170 top, verifier()->current_class(),
duke@435 171 CHECK_(VerificationType::bogus_type()));
duke@435 172 if (subtype) {
duke@435 173 _stack_size --;
duke@435 174 NOT_PRODUCT( _stack[_stack_size] = VerificationType::bogus_type(); )
duke@435 175 return top;
duke@435 176 }
duke@435 177 }
duke@435 178 return pop_stack_ex(type, THREAD);
duke@435 179 }
duke@435 180
duke@435 181 inline void pop_stack_2(
duke@435 182 VerificationType type1, VerificationType type2, TRAPS) {
duke@435 183 assert(type1.is_long2() || type1.is_double2(), "must be long/double");
duke@435 184 assert(type2.is_long() || type2.is_double(), "must be long/double_2");
duke@435 185 if (_stack_size >= 2) {
duke@435 186 VerificationType top1 = _stack[_stack_size - 1];
duke@435 187 bool subtype1 = type1.is_assignable_from(
duke@435 188 top1, verifier()->current_class(), CHECK);
duke@435 189 VerificationType top2 = _stack[_stack_size - 2];
duke@435 190 bool subtype2 = type2.is_assignable_from(
duke@435 191 top2, verifier()->current_class(), CHECK);
duke@435 192 if (subtype1 && subtype2) {
duke@435 193 _stack_size -= 2;
duke@435 194 NOT_PRODUCT( _stack[_stack_size] = VerificationType::bogus_type(); )
duke@435 195 NOT_PRODUCT( _stack[_stack_size+1] = VerificationType::bogus_type(); )
duke@435 196 return;
duke@435 197 }
duke@435 198 }
duke@435 199 pop_stack_ex(type1, THREAD);
duke@435 200 pop_stack_ex(type2, THREAD);
duke@435 201 }
duke@435 202
duke@435 203 // Uncommon case that throws exceptions.
duke@435 204 VerificationType pop_stack_ex(VerificationType type, TRAPS);
duke@435 205
duke@435 206 // Return the type at index in local variable array after verifying
duke@435 207 // it is assignable to type.
duke@435 208 VerificationType get_local(int32_t index, VerificationType type, TRAPS);
duke@435 209 // For long/double.
duke@435 210 void get_local_2(
duke@435 211 int32_t index, VerificationType type1, VerificationType type2, TRAPS);
duke@435 212
duke@435 213 // Set element at index in local variable array to type.
duke@435 214 void set_local(int32_t index, VerificationType type, TRAPS);
duke@435 215 // For long/double.
duke@435 216 void set_local_2(
duke@435 217 int32_t index, VerificationType type1, VerificationType type2, TRAPS);
duke@435 218
duke@435 219 // Private auxiliary method used only in is_assignable_to(StackMapFrame).
duke@435 220 // Returns true if src is assignable to target.
duke@435 221 bool is_assignable_to(
duke@435 222 VerificationType* src, VerificationType* target, int32_t len, TRAPS) const;
duke@435 223
duke@435 224 // Debugging
duke@435 225 void print() const PRODUCT_RETURN;
duke@435 226 };

mercurial