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

mercurial