src/share/vm/classfile/stackMapFrame.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 4526
ab826603e572
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_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"
coleenp@4037 30 #include "oops/method.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
kamg@3992 37 class TypeContext;
kamg@3992 38
duke@435 39 enum {
duke@435 40 FLAG_THIS_UNINIT = 0x01
duke@435 41 };
duke@435 42
duke@435 43 class StackMapFrame : public ResourceObj {
duke@435 44 private:
duke@435 45 int32_t _offset;
duke@435 46
duke@435 47 // See comment in StackMapTable about _frame_count about why these
duke@435 48 // fields are int32_t instead of u2.
duke@435 49 int32_t _locals_size; // number of valid type elements in _locals
duke@435 50 int32_t _stack_size; // number of valid type elements in _stack
duke@435 51
kamg@3992 52 int32_t _stack_mark; // Records the size of the stack prior to an
kamg@3992 53 // instruction modification, to allow rewinding
kamg@3992 54 // when/if an error occurs.
kamg@3992 55
duke@435 56 int32_t _max_locals;
duke@435 57 int32_t _max_stack;
duke@435 58
duke@435 59 u1 _flags;
duke@435 60 VerificationType* _locals; // local variable type array
duke@435 61 VerificationType* _stack; // operand stack type array
duke@435 62
duke@435 63 ClassVerifier* _verifier; // the verifier verifying this method
duke@435 64
kamg@3992 65 StackMapFrame(const StackMapFrame& cp) :
kamg@3992 66 _offset(cp._offset), _locals_size(cp._locals_size),
kamg@3992 67 _stack_size(cp._stack_size), _stack_mark(cp._stack_mark),
kamg@3992 68 _max_locals(cp._max_locals), _max_stack(cp._max_stack),
kamg@3992 69 _flags(cp._flags) {
kamg@3992 70 _locals = NEW_RESOURCE_ARRAY(VerificationType, _max_locals);
kamg@3992 71 for (int i = 0; i < _max_locals; ++i) {
kamg@3992 72 if (i < _locals_size) {
kamg@3992 73 _locals[i] = cp._locals[i];
kamg@3992 74 } else {
kamg@3992 75 _locals[i] = VerificationType::bogus_type();
kamg@3992 76 }
kamg@3992 77 }
kamg@3992 78 int ss = MAX2(_stack_size, _stack_mark);
kamg@3992 79 _stack = NEW_RESOURCE_ARRAY(VerificationType, _max_stack);
kamg@3992 80 for (int i = 0; i < _max_stack; ++i) {
kamg@3992 81 if (i < ss) {
kamg@3992 82 _stack[i] = cp._stack[i];
kamg@3992 83 } else {
kamg@3992 84 _stack[i] = VerificationType::bogus_type();
kamg@3992 85 }
kamg@3992 86 }
kamg@3992 87 _verifier = NULL;
kamg@3992 88 }
kamg@3992 89
duke@435 90 public:
duke@435 91 // constructors
duke@435 92
duke@435 93 // This constructor is used by the type checker to allocate frames
duke@435 94 // in type state, which have _max_locals and _max_stack array elements
duke@435 95 // in _locals and _stack.
duke@435 96 StackMapFrame(u2 max_locals, u2 max_stack, ClassVerifier* verifier);
duke@435 97
duke@435 98 // This constructor is used to initialize stackmap frames in stackmap table,
duke@435 99 // which have _locals_size and _stack_size array elements in _locals and _stack.
duke@435 100 StackMapFrame(int32_t offset,
duke@435 101 u1 flags,
duke@435 102 u2 locals_size,
duke@435 103 u2 stack_size,
duke@435 104 u2 max_locals,
duke@435 105 u2 max_stack,
duke@435 106 VerificationType* locals,
duke@435 107 VerificationType* stack,
duke@435 108 ClassVerifier* v) : _offset(offset), _flags(flags),
duke@435 109 _locals_size(locals_size),
duke@435 110 _stack_size(stack_size),
kamg@3992 111 _stack_mark(-1),
duke@435 112 _max_locals(max_locals),
duke@435 113 _max_stack(max_stack),
duke@435 114 _locals(locals), _stack(stack),
duke@435 115 _verifier(v) { }
duke@435 116
kamg@3992 117 static StackMapFrame* copy(StackMapFrame* smf) {
kamg@3992 118 return new StackMapFrame(*smf);
kamg@3992 119 }
kamg@3992 120
duke@435 121 inline void set_offset(int32_t offset) { _offset = offset; }
duke@435 122 inline void set_verifier(ClassVerifier* v) { _verifier = v; }
duke@435 123 inline void set_flags(u1 flags) { _flags = flags; }
duke@435 124 inline void set_locals_size(u2 locals_size) { _locals_size = locals_size; }
kamg@3992 125 inline void set_stack_size(u2 stack_size) { _stack_size = _stack_mark = stack_size; }
duke@435 126 inline void clear_stack() { _stack_size = 0; }
duke@435 127 inline int32_t offset() const { return _offset; }
duke@435 128 inline ClassVerifier* verifier() const { return _verifier; }
duke@435 129 inline u1 flags() const { return _flags; }
duke@435 130 inline int32_t locals_size() const { return _locals_size; }
duke@435 131 inline VerificationType* locals() const { return _locals; }
duke@435 132 inline int32_t stack_size() const { return _stack_size; }
duke@435 133 inline VerificationType* stack() const { return _stack; }
duke@435 134 inline int32_t max_locals() const { return _max_locals; }
duke@435 135 inline int32_t max_stack() const { return _max_stack; }
duke@435 136 inline bool flag_this_uninit() const { return _flags & FLAG_THIS_UNINIT; }
duke@435 137
duke@435 138 // Set locals and stack types to bogus
duke@435 139 inline void reset() {
duke@435 140 int32_t i;
duke@435 141 for (i = 0; i < _max_locals; i++) {
duke@435 142 _locals[i] = VerificationType::bogus_type();
duke@435 143 }
duke@435 144 for (i = 0; i < _max_stack; i++) {
duke@435 145 _stack[i] = VerificationType::bogus_type();
duke@435 146 }
duke@435 147 }
duke@435 148
duke@435 149 // Return a StackMapFrame with the same local variable array and empty stack.
duke@435 150 // Stack array is allocate with unused one element.
duke@435 151 StackMapFrame* frame_in_exception_handler(u1 flags);
duke@435 152
duke@435 153 // Set local variable type array based on m's signature.
duke@435 154 VerificationType set_locals_from_arg(
duke@435 155 const methodHandle m, VerificationType thisKlass, TRAPS);
duke@435 156
duke@435 157 // Search local variable type array and stack type array.
duke@435 158 // Return true if an uninitialized object is found.
duke@435 159 bool has_new_object() const;
duke@435 160
duke@435 161 // Search local variable type array and stack type array.
duke@435 162 // Set every element with type of old_object to new_object.
duke@435 163 void initialize_object(
duke@435 164 VerificationType old_object, VerificationType new_object);
duke@435 165
duke@435 166 // Copy local variable type array in src into this local variable type array.
duke@435 167 void copy_locals(const StackMapFrame* src);
duke@435 168
duke@435 169 // Copy stack type array in src into this stack type array.
duke@435 170 void copy_stack(const StackMapFrame* src);
duke@435 171
duke@435 172 // Return true if this stack map frame is assignable to target.
kamg@3992 173 bool is_assignable_to(
kamg@3992 174 const StackMapFrame* target, bool is_exception_handler,
kamg@3992 175 ErrorContext* ctx, TRAPS) const;
kamg@3992 176
kamg@3992 177 inline void set_mark() {
kamg@3992 178 #ifdef DEBUG
kamg@3992 179 // Put bogus type to indicate it's no longer valid.
kamg@3992 180 if (_stack_mark != -1) {
kamg@3992 181 for (int i = _stack_mark; i >= _stack_size; --i) {
kamg@3992 182 _stack[i] = VerificationType::bogus_type();
kamg@3992 183 }
kamg@3992 184 }
kamg@3992 185 #endif // def DEBUG
kamg@3992 186 _stack_mark = _stack_size;
kamg@3992 187 }
kamg@3992 188
kamg@3992 189 // Used when an error occurs and we want to reset the stack to the state
kamg@3992 190 // it was before operands were popped off.
kamg@3992 191 void restore() {
kamg@3992 192 if (_stack_mark != -1) {
kamg@3992 193 _stack_size = _stack_mark;
kamg@3992 194 }
kamg@3992 195 }
duke@435 196
duke@435 197 // Push type into stack type array.
duke@435 198 inline void push_stack(VerificationType type, TRAPS) {
duke@435 199 assert(!type.is_check(), "Must be a real type");
duke@435 200 if (_stack_size >= _max_stack) {
kamg@3992 201 verifier()->verify_error(
kamg@3992 202 ErrorContext::stack_overflow(_offset, this),
kamg@3992 203 "Operand stack overflow");
duke@435 204 return;
duke@435 205 }
duke@435 206 _stack[_stack_size++] = type;
duke@435 207 }
duke@435 208
duke@435 209 inline void push_stack_2(
duke@435 210 VerificationType type1, VerificationType type2, TRAPS) {
duke@435 211 assert(type1.is_long() || type1.is_double(), "must be long/double");
duke@435 212 assert(type2.is_long2() || type2.is_double2(), "must be long/double_2");
duke@435 213 if (_stack_size >= _max_stack - 1) {
kamg@3992 214 verifier()->verify_error(
kamg@3992 215 ErrorContext::stack_overflow(_offset, this),
kamg@3992 216 "Operand stack overflow");
duke@435 217 return;
duke@435 218 }
duke@435 219 _stack[_stack_size++] = type1;
duke@435 220 _stack[_stack_size++] = type2;
duke@435 221 }
duke@435 222
duke@435 223 // Pop and return the top type on stack without verifying.
duke@435 224 inline VerificationType pop_stack(TRAPS) {
duke@435 225 if (_stack_size <= 0) {
kamg@3992 226 verifier()->verify_error(
kamg@3992 227 ErrorContext::stack_underflow(_offset, this),
kamg@3992 228 "Operand stack underflow");
duke@435 229 return VerificationType::bogus_type();
duke@435 230 }
duke@435 231 VerificationType top = _stack[--_stack_size];
duke@435 232 return top;
duke@435 233 }
duke@435 234
duke@435 235 // Pop and return the top type on stack type array after verifying it
duke@435 236 // is assignable to type.
duke@435 237 inline VerificationType pop_stack(VerificationType type, TRAPS) {
duke@435 238 if (_stack_size != 0) {
duke@435 239 VerificationType top = _stack[_stack_size - 1];
duke@435 240 bool subtype = type.is_assignable_from(
coleenp@2497 241 top, verifier(), CHECK_(VerificationType::bogus_type()));
duke@435 242 if (subtype) {
kamg@3992 243 --_stack_size;
duke@435 244 return top;
duke@435 245 }
duke@435 246 }
duke@435 247 return pop_stack_ex(type, THREAD);
duke@435 248 }
duke@435 249
duke@435 250 inline void pop_stack_2(
duke@435 251 VerificationType type1, VerificationType type2, TRAPS) {
duke@435 252 assert(type1.is_long2() || type1.is_double2(), "must be long/double");
duke@435 253 assert(type2.is_long() || type2.is_double(), "must be long/double_2");
duke@435 254 if (_stack_size >= 2) {
duke@435 255 VerificationType top1 = _stack[_stack_size - 1];
coleenp@2497 256 bool subtype1 = type1.is_assignable_from(top1, verifier(), CHECK);
duke@435 257 VerificationType top2 = _stack[_stack_size - 2];
coleenp@2497 258 bool subtype2 = type2.is_assignable_from(top2, verifier(), CHECK);
duke@435 259 if (subtype1 && subtype2) {
duke@435 260 _stack_size -= 2;
duke@435 261 return;
duke@435 262 }
duke@435 263 }
duke@435 264 pop_stack_ex(type1, THREAD);
duke@435 265 pop_stack_ex(type2, THREAD);
duke@435 266 }
duke@435 267
kamg@3992 268 VerificationType local_at(int index) {
kamg@3992 269 return _locals[index];
kamg@3992 270 }
kamg@3992 271
kamg@3992 272 VerificationType stack_at(int index) {
kamg@3992 273 return _stack[index];
kamg@3992 274 }
kamg@3992 275
duke@435 276 // Uncommon case that throws exceptions.
duke@435 277 VerificationType pop_stack_ex(VerificationType type, TRAPS);
duke@435 278
duke@435 279 // Return the type at index in local variable array after verifying
duke@435 280 // it is assignable to type.
duke@435 281 VerificationType get_local(int32_t index, VerificationType type, TRAPS);
duke@435 282 // For long/double.
duke@435 283 void get_local_2(
duke@435 284 int32_t index, VerificationType type1, VerificationType type2, TRAPS);
duke@435 285
duke@435 286 // Set element at index in local variable array to type.
duke@435 287 void set_local(int32_t index, VerificationType type, TRAPS);
duke@435 288 // For long/double.
duke@435 289 void set_local_2(
duke@435 290 int32_t index, VerificationType type1, VerificationType type2, TRAPS);
duke@435 291
duke@435 292 // Private auxiliary method used only in is_assignable_to(StackMapFrame).
duke@435 293 // Returns true if src is assignable to target.
kamg@3992 294 int is_assignable_to(
duke@435 295 VerificationType* src, VerificationType* target, int32_t len, TRAPS) const;
duke@435 296
kamg@2585 297 bool has_flag_match_exception(const StackMapFrame* target) const;
kamg@2585 298
kamg@3992 299 TypeOrigin stack_top_ctx();
kamg@3992 300
kamg@3992 301 void print_on(outputStream* str) const;
duke@435 302 };
stefank@2314 303
stefank@2314 304 #endif // SHARE_VM_CLASSFILE_STACKMAPFRAME_HPP

mercurial