Fri, 06 Jun 2008 13:43:36 -0400
Merge
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 | # include "incls/_precompiled.incl" |
duke@435 | 26 | # include "incls/_stackMapFrame.cpp.incl" |
duke@435 | 27 | |
duke@435 | 28 | StackMapFrame::StackMapFrame(u2 max_locals, u2 max_stack, ClassVerifier* v) : |
duke@435 | 29 | _offset(0), _locals_size(0), _stack_size(0), _flags(0), |
duke@435 | 30 | _max_locals(max_locals), _max_stack(max_stack), |
duke@435 | 31 | _verifier(v) { |
duke@435 | 32 | Thread* thr = v->thread(); |
duke@435 | 33 | _locals = NEW_RESOURCE_ARRAY_IN_THREAD(thr, VerificationType, max_locals); |
duke@435 | 34 | _stack = NEW_RESOURCE_ARRAY_IN_THREAD(thr, VerificationType, max_stack); |
duke@435 | 35 | int32_t i; |
duke@435 | 36 | for(i = 0; i < max_locals; i++) { |
duke@435 | 37 | _locals[i] = VerificationType::bogus_type(); |
duke@435 | 38 | } |
duke@435 | 39 | for(i = 0; i < max_stack; i++) { |
duke@435 | 40 | _stack[i] = VerificationType::bogus_type(); |
duke@435 | 41 | } |
duke@435 | 42 | } |
duke@435 | 43 | |
duke@435 | 44 | StackMapFrame* StackMapFrame::frame_in_exception_handler(u1 flags) { |
duke@435 | 45 | Thread* thr = _verifier->thread(); |
duke@435 | 46 | VerificationType* stack = NEW_RESOURCE_ARRAY_IN_THREAD(thr, VerificationType, 1); |
duke@435 | 47 | StackMapFrame* frame = new StackMapFrame(_offset, flags, _locals_size, 0, _max_locals, _max_stack, _locals, stack, _verifier); |
duke@435 | 48 | return frame; |
duke@435 | 49 | } |
duke@435 | 50 | |
duke@435 | 51 | bool StackMapFrame::has_new_object() const { |
duke@435 | 52 | int32_t i; |
duke@435 | 53 | for (i = 0; i < _max_locals; i++) { |
duke@435 | 54 | if (_locals[i].is_uninitialized()) { |
duke@435 | 55 | return true; |
duke@435 | 56 | } |
duke@435 | 57 | } |
duke@435 | 58 | for (i = 0; i < _stack_size; i++) { |
duke@435 | 59 | if (_stack[i].is_uninitialized()) { |
duke@435 | 60 | return true; |
duke@435 | 61 | } |
duke@435 | 62 | } |
duke@435 | 63 | return false; |
duke@435 | 64 | } |
duke@435 | 65 | |
duke@435 | 66 | void StackMapFrame::initialize_object( |
duke@435 | 67 | VerificationType old_object, VerificationType new_object) { |
duke@435 | 68 | int32_t i; |
duke@435 | 69 | for (i = 0; i < _max_locals; i++) { |
duke@435 | 70 | if (_locals[i].equals(old_object)) { |
duke@435 | 71 | _locals[i] = new_object; |
duke@435 | 72 | } |
duke@435 | 73 | } |
duke@435 | 74 | for (i = 0; i < _stack_size; i++) { |
duke@435 | 75 | if (_stack[i].equals(old_object)) { |
duke@435 | 76 | _stack[i] = new_object; |
duke@435 | 77 | } |
duke@435 | 78 | } |
duke@435 | 79 | if (old_object == VerificationType::uninitialized_this_type()) { |
duke@435 | 80 | // "this" has been initialized - reset flags |
duke@435 | 81 | _flags = 0; |
duke@435 | 82 | } |
duke@435 | 83 | } |
duke@435 | 84 | |
duke@435 | 85 | VerificationType StackMapFrame::set_locals_from_arg( |
duke@435 | 86 | const methodHandle m, VerificationType thisKlass, TRAPS) { |
duke@435 | 87 | symbolHandle signature(THREAD, m->signature()); |
duke@435 | 88 | SignatureStream ss(signature); |
duke@435 | 89 | int init_local_num = 0; |
duke@435 | 90 | if (!m->is_static()) { |
duke@435 | 91 | init_local_num++; |
duke@435 | 92 | // add one extra argument for instance method |
duke@435 | 93 | if (m->name() == vmSymbols::object_initializer_name() && |
duke@435 | 94 | thisKlass.name() != vmSymbols::java_lang_Object()) { |
duke@435 | 95 | _locals[0] = VerificationType::uninitialized_this_type(); |
duke@435 | 96 | _flags |= FLAG_THIS_UNINIT; |
duke@435 | 97 | } else { |
duke@435 | 98 | _locals[0] = thisKlass; |
duke@435 | 99 | } |
duke@435 | 100 | } |
duke@435 | 101 | |
duke@435 | 102 | // local num may be greater than size of parameters because long/double occupies two slots |
duke@435 | 103 | while(!ss.at_return_type()) { |
duke@435 | 104 | init_local_num += _verifier->change_sig_to_verificationType( |
duke@435 | 105 | &ss, &_locals[init_local_num], |
duke@435 | 106 | CHECK_VERIFY_(verifier(), VerificationType::bogus_type())); |
duke@435 | 107 | ss.next(); |
duke@435 | 108 | } |
duke@435 | 109 | _locals_size = init_local_num; |
duke@435 | 110 | |
duke@435 | 111 | switch (ss.type()) { |
duke@435 | 112 | case T_OBJECT: |
duke@435 | 113 | case T_ARRAY: |
duke@435 | 114 | { |
duke@435 | 115 | symbolOop sig = ss.as_symbol(CHECK_(VerificationType::bogus_type())); |
duke@435 | 116 | return VerificationType::reference_type(symbolHandle(THREAD, sig)); |
duke@435 | 117 | } |
duke@435 | 118 | case T_INT: return VerificationType::integer_type(); |
duke@435 | 119 | case T_BYTE: return VerificationType::byte_type(); |
duke@435 | 120 | case T_CHAR: return VerificationType::char_type(); |
duke@435 | 121 | case T_SHORT: return VerificationType::short_type(); |
duke@435 | 122 | case T_BOOLEAN: return VerificationType::boolean_type(); |
duke@435 | 123 | case T_FLOAT: return VerificationType::float_type(); |
duke@435 | 124 | case T_DOUBLE: return VerificationType::double_type(); |
duke@435 | 125 | case T_LONG: return VerificationType::long_type(); |
duke@435 | 126 | case T_VOID: return VerificationType::bogus_type(); |
duke@435 | 127 | default: |
duke@435 | 128 | ShouldNotReachHere(); |
duke@435 | 129 | } |
duke@435 | 130 | return VerificationType::bogus_type(); |
duke@435 | 131 | } |
duke@435 | 132 | |
duke@435 | 133 | void StackMapFrame::copy_locals(const StackMapFrame* src) { |
duke@435 | 134 | int32_t len = src->locals_size() < _locals_size ? |
duke@435 | 135 | src->locals_size() : _locals_size; |
duke@435 | 136 | for (int32_t i = 0; i < len; i++) { |
duke@435 | 137 | _locals[i] = src->locals()[i]; |
duke@435 | 138 | } |
duke@435 | 139 | } |
duke@435 | 140 | |
duke@435 | 141 | void StackMapFrame::copy_stack(const StackMapFrame* src) { |
duke@435 | 142 | int32_t len = src->stack_size() < _stack_size ? |
duke@435 | 143 | src->stack_size() : _stack_size; |
duke@435 | 144 | for (int32_t i = 0; i < len; i++) { |
duke@435 | 145 | _stack[i] = src->stack()[i]; |
duke@435 | 146 | } |
duke@435 | 147 | } |
duke@435 | 148 | |
duke@435 | 149 | |
duke@435 | 150 | bool StackMapFrame::is_assignable_to( |
duke@435 | 151 | VerificationType* from, VerificationType* to, int32_t len, TRAPS) const { |
duke@435 | 152 | for (int32_t i = 0; i < len; i++) { |
duke@435 | 153 | bool subtype = to[i].is_assignable_from( |
duke@435 | 154 | from[i], verifier()->current_class(), THREAD); |
duke@435 | 155 | if (!subtype) { |
duke@435 | 156 | return false; |
duke@435 | 157 | } |
duke@435 | 158 | } |
duke@435 | 159 | return true; |
duke@435 | 160 | } |
duke@435 | 161 | |
duke@435 | 162 | bool StackMapFrame::is_assignable_to(const StackMapFrame* target, TRAPS) const { |
duke@435 | 163 | if (_max_locals != target->max_locals() || _stack_size != target->stack_size()) { |
duke@435 | 164 | return false; |
duke@435 | 165 | } |
duke@435 | 166 | // Only need to compare type elements up to target->locals() or target->stack(). |
duke@435 | 167 | // The remaining type elements in this state can be ignored because they are |
duke@435 | 168 | // assignable to bogus type. |
duke@435 | 169 | bool match_locals = is_assignable_to( |
duke@435 | 170 | _locals, target->locals(), target->locals_size(), CHECK_false); |
duke@435 | 171 | bool match_stack = is_assignable_to( |
duke@435 | 172 | _stack, target->stack(), _stack_size, CHECK_false); |
duke@435 | 173 | bool match_flags = (_flags | target->flags()) == target->flags(); |
duke@435 | 174 | return (match_locals && match_stack && match_flags); |
duke@435 | 175 | } |
duke@435 | 176 | |
duke@435 | 177 | VerificationType StackMapFrame::pop_stack_ex(VerificationType type, TRAPS) { |
duke@435 | 178 | if (_stack_size <= 0) { |
duke@435 | 179 | verifier()->verify_error(_offset, "Operand stack underflow"); |
duke@435 | 180 | return VerificationType::bogus_type(); |
duke@435 | 181 | } |
duke@435 | 182 | VerificationType top = _stack[--_stack_size]; |
duke@435 | 183 | bool subtype = type.is_assignable_from( |
duke@435 | 184 | top, verifier()->current_class(), CHECK_(VerificationType::bogus_type())); |
duke@435 | 185 | if (!subtype) { |
duke@435 | 186 | verifier()->verify_error(_offset, "Bad type on operand stack"); |
duke@435 | 187 | return VerificationType::bogus_type(); |
duke@435 | 188 | } |
duke@435 | 189 | NOT_PRODUCT( _stack[_stack_size] = VerificationType::bogus_type(); ) |
duke@435 | 190 | return top; |
duke@435 | 191 | } |
duke@435 | 192 | |
duke@435 | 193 | VerificationType StackMapFrame::get_local( |
duke@435 | 194 | int32_t index, VerificationType type, TRAPS) { |
duke@435 | 195 | if (index >= _max_locals) { |
duke@435 | 196 | verifier()->verify_error(_offset, "Local variable table overflow"); |
duke@435 | 197 | return VerificationType::bogus_type(); |
duke@435 | 198 | } |
duke@435 | 199 | bool subtype = type.is_assignable_from(_locals[index], |
duke@435 | 200 | verifier()->current_class(), CHECK_(VerificationType::bogus_type())); |
duke@435 | 201 | if (!subtype) { |
duke@435 | 202 | verifier()->verify_error(_offset, "Bad local variable type"); |
duke@435 | 203 | return VerificationType::bogus_type(); |
duke@435 | 204 | } |
duke@435 | 205 | if(index >= _locals_size) { _locals_size = index + 1; } |
duke@435 | 206 | return _locals[index]; |
duke@435 | 207 | } |
duke@435 | 208 | |
duke@435 | 209 | void StackMapFrame::get_local_2( |
duke@435 | 210 | int32_t index, 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 (index >= _locals_size - 1) { |
duke@435 | 214 | verifier()->verify_error(_offset, "get long/double overflows locals"); |
duke@435 | 215 | return; |
duke@435 | 216 | } |
duke@435 | 217 | bool subtype1 = type1.is_assignable_from( |
duke@435 | 218 | _locals[index], verifier()->current_class(), CHECK); |
duke@435 | 219 | bool subtype2 = type2.is_assignable_from( |
duke@435 | 220 | _locals[index+1], verifier()->current_class(), CHECK); |
duke@435 | 221 | if (!subtype1 || !subtype2) { |
duke@435 | 222 | verifier()->verify_error(_offset, "Bad local variable type"); |
duke@435 | 223 | return; |
duke@435 | 224 | } |
duke@435 | 225 | } |
duke@435 | 226 | |
duke@435 | 227 | void StackMapFrame::set_local(int32_t index, VerificationType type, TRAPS) { |
duke@435 | 228 | assert(!type.is_check(), "Must be a real type"); |
duke@435 | 229 | if (index >= _max_locals) { |
duke@435 | 230 | verifier()->verify_error("Local variable table overflow", _offset); |
duke@435 | 231 | return; |
duke@435 | 232 | } |
duke@435 | 233 | // If type at index is double or long, set the next location to be unusable |
duke@435 | 234 | if (_locals[index].is_double() || _locals[index].is_long()) { |
duke@435 | 235 | assert((index + 1) < _locals_size, "Local variable table overflow"); |
duke@435 | 236 | _locals[index + 1] = VerificationType::bogus_type(); |
duke@435 | 237 | } |
duke@435 | 238 | // If type at index is double_2 or long_2, set the previous location to be unusable |
duke@435 | 239 | if (_locals[index].is_double2() || _locals[index].is_long2()) { |
duke@435 | 240 | assert(index >= 1, "Local variable table underflow"); |
duke@435 | 241 | _locals[index - 1] = VerificationType::bogus_type(); |
duke@435 | 242 | } |
duke@435 | 243 | _locals[index] = type; |
duke@435 | 244 | if (index >= _locals_size) { |
duke@435 | 245 | #ifdef ASSERT |
duke@435 | 246 | for (int i=_locals_size; i<index; i++) { |
duke@435 | 247 | assert(_locals[i] == VerificationType::bogus_type(), |
duke@435 | 248 | "holes must be bogus type"); |
duke@435 | 249 | } |
duke@435 | 250 | #endif |
duke@435 | 251 | _locals_size = index + 1; |
duke@435 | 252 | } |
duke@435 | 253 | } |
duke@435 | 254 | |
duke@435 | 255 | void StackMapFrame::set_local_2( |
duke@435 | 256 | int32_t index, VerificationType type1, VerificationType type2, TRAPS) { |
duke@435 | 257 | assert(type1.is_long() || type1.is_double(), "must be long/double"); |
duke@435 | 258 | assert(type2.is_long2() || type2.is_double2(), "must be long/double_2"); |
duke@435 | 259 | if (index >= _max_locals - 1) { |
duke@435 | 260 | verifier()->verify_error("Local variable table overflow", _offset); |
duke@435 | 261 | return; |
duke@435 | 262 | } |
duke@435 | 263 | // If type at index+1 is double or long, set the next location to be unusable |
duke@435 | 264 | if (_locals[index+1].is_double() || _locals[index+1].is_long()) { |
duke@435 | 265 | assert((index + 2) < _locals_size, "Local variable table overflow"); |
duke@435 | 266 | _locals[index + 2] = VerificationType::bogus_type(); |
duke@435 | 267 | } |
duke@435 | 268 | // If type at index is double_2 or long_2, set the previous location to be unusable |
duke@435 | 269 | if (_locals[index].is_double2() || _locals[index].is_long2()) { |
duke@435 | 270 | assert(index >= 1, "Local variable table underflow"); |
duke@435 | 271 | _locals[index - 1] = VerificationType::bogus_type(); |
duke@435 | 272 | } |
duke@435 | 273 | _locals[index] = type1; |
duke@435 | 274 | _locals[index+1] = type2; |
duke@435 | 275 | if (index >= _locals_size - 1) { |
duke@435 | 276 | #ifdef ASSERT |
duke@435 | 277 | for (int i=_locals_size; i<index; i++) { |
duke@435 | 278 | assert(_locals[i] == VerificationType::bogus_type(), |
duke@435 | 279 | "holes must be bogus type"); |
duke@435 | 280 | } |
duke@435 | 281 | #endif |
duke@435 | 282 | _locals_size = index + 2; |
duke@435 | 283 | } |
duke@435 | 284 | } |
duke@435 | 285 | |
duke@435 | 286 | #ifndef PRODUCT |
duke@435 | 287 | |
duke@435 | 288 | void StackMapFrame::print() const { |
duke@435 | 289 | tty->print_cr("stackmap_frame[%d]:", _offset); |
duke@435 | 290 | tty->print_cr("flags = 0x%x", _flags); |
duke@435 | 291 | tty->print("locals[%d] = { ", _locals_size); |
duke@435 | 292 | for (int32_t i = 0; i < _locals_size; i++) { |
duke@435 | 293 | _locals[i].print_on(tty); |
duke@435 | 294 | } |
duke@435 | 295 | tty->print_cr(" }"); |
duke@435 | 296 | tty->print("stack[%d] = { ", _stack_size); |
duke@435 | 297 | for (int32_t j = 0; j < _stack_size; j++) { |
duke@435 | 298 | _stack[j].print_on(tty); |
duke@435 | 299 | } |
duke@435 | 300 | tty->print_cr(" }"); |
duke@435 | 301 | } |
duke@435 | 302 | |
duke@435 | 303 | #endif |