annotate src/share/vm/classfile/stackMapFrame.cpp @ 1838:3b2dea75431e

6984311: JSR 292 needs optional bootstrap method parameters Summary: Allow CONSTANT_InvokeDynamic nodes to have any number of extra operands. Reviewed-by: twisti
author jrose
date Sat, 30 Oct 2010 13:08:23 -0700
parents a61af66fc99e
children f95d63e2154a
rev   line source
duke@0 1 /*
trims@1472 2 * Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved.
duke@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 4 *
duke@0 5 * This code is free software; you can redistribute it and/or modify it
duke@0 6 * under the terms of the GNU General Public License version 2 only, as
duke@0 7 * published by the Free Software Foundation.
duke@0 8 *
duke@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@0 13 * accompanied this code).
duke@0 14 *
duke@0 15 * You should have received a copy of the GNU General Public License version
duke@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 18 *
trims@1472 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1472 20 * or visit www.oracle.com if you need additional information or have any
trims@1472 21 * questions.
duke@0 22 *
duke@0 23 */
duke@0 24
duke@0 25 # include "incls/_precompiled.incl"
duke@0 26 # include "incls/_stackMapFrame.cpp.incl"
duke@0 27
duke@0 28 StackMapFrame::StackMapFrame(u2 max_locals, u2 max_stack, ClassVerifier* v) :
duke@0 29 _offset(0), _locals_size(0), _stack_size(0), _flags(0),
duke@0 30 _max_locals(max_locals), _max_stack(max_stack),
duke@0 31 _verifier(v) {
duke@0 32 Thread* thr = v->thread();
duke@0 33 _locals = NEW_RESOURCE_ARRAY_IN_THREAD(thr, VerificationType, max_locals);
duke@0 34 _stack = NEW_RESOURCE_ARRAY_IN_THREAD(thr, VerificationType, max_stack);
duke@0 35 int32_t i;
duke@0 36 for(i = 0; i < max_locals; i++) {
duke@0 37 _locals[i] = VerificationType::bogus_type();
duke@0 38 }
duke@0 39 for(i = 0; i < max_stack; i++) {
duke@0 40 _stack[i] = VerificationType::bogus_type();
duke@0 41 }
duke@0 42 }
duke@0 43
duke@0 44 StackMapFrame* StackMapFrame::frame_in_exception_handler(u1 flags) {
duke@0 45 Thread* thr = _verifier->thread();
duke@0 46 VerificationType* stack = NEW_RESOURCE_ARRAY_IN_THREAD(thr, VerificationType, 1);
duke@0 47 StackMapFrame* frame = new StackMapFrame(_offset, flags, _locals_size, 0, _max_locals, _max_stack, _locals, stack, _verifier);
duke@0 48 return frame;
duke@0 49 }
duke@0 50
duke@0 51 bool StackMapFrame::has_new_object() const {
duke@0 52 int32_t i;
duke@0 53 for (i = 0; i < _max_locals; i++) {
duke@0 54 if (_locals[i].is_uninitialized()) {
duke@0 55 return true;
duke@0 56 }
duke@0 57 }
duke@0 58 for (i = 0; i < _stack_size; i++) {
duke@0 59 if (_stack[i].is_uninitialized()) {
duke@0 60 return true;
duke@0 61 }
duke@0 62 }
duke@0 63 return false;
duke@0 64 }
duke@0 65
duke@0 66 void StackMapFrame::initialize_object(
duke@0 67 VerificationType old_object, VerificationType new_object) {
duke@0 68 int32_t i;
duke@0 69 for (i = 0; i < _max_locals; i++) {
duke@0 70 if (_locals[i].equals(old_object)) {
duke@0 71 _locals[i] = new_object;
duke@0 72 }
duke@0 73 }
duke@0 74 for (i = 0; i < _stack_size; i++) {
duke@0 75 if (_stack[i].equals(old_object)) {
duke@0 76 _stack[i] = new_object;
duke@0 77 }
duke@0 78 }
duke@0 79 if (old_object == VerificationType::uninitialized_this_type()) {
duke@0 80 // "this" has been initialized - reset flags
duke@0 81 _flags = 0;
duke@0 82 }
duke@0 83 }
duke@0 84
duke@0 85 VerificationType StackMapFrame::set_locals_from_arg(
duke@0 86 const methodHandle m, VerificationType thisKlass, TRAPS) {
duke@0 87 symbolHandle signature(THREAD, m->signature());
duke@0 88 SignatureStream ss(signature);
duke@0 89 int init_local_num = 0;
duke@0 90 if (!m->is_static()) {
duke@0 91 init_local_num++;
duke@0 92 // add one extra argument for instance method
duke@0 93 if (m->name() == vmSymbols::object_initializer_name() &&
duke@0 94 thisKlass.name() != vmSymbols::java_lang_Object()) {
duke@0 95 _locals[0] = VerificationType::uninitialized_this_type();
duke@0 96 _flags |= FLAG_THIS_UNINIT;
duke@0 97 } else {
duke@0 98 _locals[0] = thisKlass;
duke@0 99 }
duke@0 100 }
duke@0 101
duke@0 102 // local num may be greater than size of parameters because long/double occupies two slots
duke@0 103 while(!ss.at_return_type()) {
duke@0 104 init_local_num += _verifier->change_sig_to_verificationType(
duke@0 105 &ss, &_locals[init_local_num],
duke@0 106 CHECK_VERIFY_(verifier(), VerificationType::bogus_type()));
duke@0 107 ss.next();
duke@0 108 }
duke@0 109 _locals_size = init_local_num;
duke@0 110
duke@0 111 switch (ss.type()) {
duke@0 112 case T_OBJECT:
duke@0 113 case T_ARRAY:
duke@0 114 {
duke@0 115 symbolOop sig = ss.as_symbol(CHECK_(VerificationType::bogus_type()));
duke@0 116 return VerificationType::reference_type(symbolHandle(THREAD, sig));
duke@0 117 }
duke@0 118 case T_INT: return VerificationType::integer_type();
duke@0 119 case T_BYTE: return VerificationType::byte_type();
duke@0 120 case T_CHAR: return VerificationType::char_type();
duke@0 121 case T_SHORT: return VerificationType::short_type();
duke@0 122 case T_BOOLEAN: return VerificationType::boolean_type();
duke@0 123 case T_FLOAT: return VerificationType::float_type();
duke@0 124 case T_DOUBLE: return VerificationType::double_type();
duke@0 125 case T_LONG: return VerificationType::long_type();
duke@0 126 case T_VOID: return VerificationType::bogus_type();
duke@0 127 default:
duke@0 128 ShouldNotReachHere();
duke@0 129 }
duke@0 130 return VerificationType::bogus_type();
duke@0 131 }
duke@0 132
duke@0 133 void StackMapFrame::copy_locals(const StackMapFrame* src) {
duke@0 134 int32_t len = src->locals_size() < _locals_size ?
duke@0 135 src->locals_size() : _locals_size;
duke@0 136 for (int32_t i = 0; i < len; i++) {
duke@0 137 _locals[i] = src->locals()[i];
duke@0 138 }
duke@0 139 }
duke@0 140
duke@0 141 void StackMapFrame::copy_stack(const StackMapFrame* src) {
duke@0 142 int32_t len = src->stack_size() < _stack_size ?
duke@0 143 src->stack_size() : _stack_size;
duke@0 144 for (int32_t i = 0; i < len; i++) {
duke@0 145 _stack[i] = src->stack()[i];
duke@0 146 }
duke@0 147 }
duke@0 148
duke@0 149
duke@0 150 bool StackMapFrame::is_assignable_to(
duke@0 151 VerificationType* from, VerificationType* to, int32_t len, TRAPS) const {
duke@0 152 for (int32_t i = 0; i < len; i++) {
duke@0 153 bool subtype = to[i].is_assignable_from(
duke@0 154 from[i], verifier()->current_class(), THREAD);
duke@0 155 if (!subtype) {
duke@0 156 return false;
duke@0 157 }
duke@0 158 }
duke@0 159 return true;
duke@0 160 }
duke@0 161
duke@0 162 bool StackMapFrame::is_assignable_to(const StackMapFrame* target, TRAPS) const {
duke@0 163 if (_max_locals != target->max_locals() || _stack_size != target->stack_size()) {
duke@0 164 return false;
duke@0 165 }
duke@0 166 // Only need to compare type elements up to target->locals() or target->stack().
duke@0 167 // The remaining type elements in this state can be ignored because they are
duke@0 168 // assignable to bogus type.
duke@0 169 bool match_locals = is_assignable_to(
duke@0 170 _locals, target->locals(), target->locals_size(), CHECK_false);
duke@0 171 bool match_stack = is_assignable_to(
duke@0 172 _stack, target->stack(), _stack_size, CHECK_false);
duke@0 173 bool match_flags = (_flags | target->flags()) == target->flags();
duke@0 174 return (match_locals && match_stack && match_flags);
duke@0 175 }
duke@0 176
duke@0 177 VerificationType StackMapFrame::pop_stack_ex(VerificationType type, TRAPS) {
duke@0 178 if (_stack_size <= 0) {
duke@0 179 verifier()->verify_error(_offset, "Operand stack underflow");
duke@0 180 return VerificationType::bogus_type();
duke@0 181 }
duke@0 182 VerificationType top = _stack[--_stack_size];
duke@0 183 bool subtype = type.is_assignable_from(
duke@0 184 top, verifier()->current_class(), CHECK_(VerificationType::bogus_type()));
duke@0 185 if (!subtype) {
duke@0 186 verifier()->verify_error(_offset, "Bad type on operand stack");
duke@0 187 return VerificationType::bogus_type();
duke@0 188 }
duke@0 189 NOT_PRODUCT( _stack[_stack_size] = VerificationType::bogus_type(); )
duke@0 190 return top;
duke@0 191 }
duke@0 192
duke@0 193 VerificationType StackMapFrame::get_local(
duke@0 194 int32_t index, VerificationType type, TRAPS) {
duke@0 195 if (index >= _max_locals) {
duke@0 196 verifier()->verify_error(_offset, "Local variable table overflow");
duke@0 197 return VerificationType::bogus_type();
duke@0 198 }
duke@0 199 bool subtype = type.is_assignable_from(_locals[index],
duke@0 200 verifier()->current_class(), CHECK_(VerificationType::bogus_type()));
duke@0 201 if (!subtype) {
duke@0 202 verifier()->verify_error(_offset, "Bad local variable type");
duke@0 203 return VerificationType::bogus_type();
duke@0 204 }
duke@0 205 if(index >= _locals_size) { _locals_size = index + 1; }
duke@0 206 return _locals[index];
duke@0 207 }
duke@0 208
duke@0 209 void StackMapFrame::get_local_2(
duke@0 210 int32_t index, VerificationType type1, VerificationType type2, TRAPS) {
duke@0 211 assert(type1.is_long() || type1.is_double(), "must be long/double");
duke@0 212 assert(type2.is_long2() || type2.is_double2(), "must be long/double_2");
duke@0 213 if (index >= _locals_size - 1) {
duke@0 214 verifier()->verify_error(_offset, "get long/double overflows locals");
duke@0 215 return;
duke@0 216 }
duke@0 217 bool subtype1 = type1.is_assignable_from(
duke@0 218 _locals[index], verifier()->current_class(), CHECK);
duke@0 219 bool subtype2 = type2.is_assignable_from(
duke@0 220 _locals[index+1], verifier()->current_class(), CHECK);
duke@0 221 if (!subtype1 || !subtype2) {
duke@0 222 verifier()->verify_error(_offset, "Bad local variable type");
duke@0 223 return;
duke@0 224 }
duke@0 225 }
duke@0 226
duke@0 227 void StackMapFrame::set_local(int32_t index, VerificationType type, TRAPS) {
duke@0 228 assert(!type.is_check(), "Must be a real type");
duke@0 229 if (index >= _max_locals) {
duke@0 230 verifier()->verify_error("Local variable table overflow", _offset);
duke@0 231 return;
duke@0 232 }
duke@0 233 // If type at index is double or long, set the next location to be unusable
duke@0 234 if (_locals[index].is_double() || _locals[index].is_long()) {
duke@0 235 assert((index + 1) < _locals_size, "Local variable table overflow");
duke@0 236 _locals[index + 1] = VerificationType::bogus_type();
duke@0 237 }
duke@0 238 // If type at index is double_2 or long_2, set the previous location to be unusable
duke@0 239 if (_locals[index].is_double2() || _locals[index].is_long2()) {
duke@0 240 assert(index >= 1, "Local variable table underflow");
duke@0 241 _locals[index - 1] = VerificationType::bogus_type();
duke@0 242 }
duke@0 243 _locals[index] = type;
duke@0 244 if (index >= _locals_size) {
duke@0 245 #ifdef ASSERT
duke@0 246 for (int i=_locals_size; i<index; i++) {
duke@0 247 assert(_locals[i] == VerificationType::bogus_type(),
duke@0 248 "holes must be bogus type");
duke@0 249 }
duke@0 250 #endif
duke@0 251 _locals_size = index + 1;
duke@0 252 }
duke@0 253 }
duke@0 254
duke@0 255 void StackMapFrame::set_local_2(
duke@0 256 int32_t index, VerificationType type1, VerificationType type2, TRAPS) {
duke@0 257 assert(type1.is_long() || type1.is_double(), "must be long/double");
duke@0 258 assert(type2.is_long2() || type2.is_double2(), "must be long/double_2");
duke@0 259 if (index >= _max_locals - 1) {
duke@0 260 verifier()->verify_error("Local variable table overflow", _offset);
duke@0 261 return;
duke@0 262 }
duke@0 263 // If type at index+1 is double or long, set the next location to be unusable
duke@0 264 if (_locals[index+1].is_double() || _locals[index+1].is_long()) {
duke@0 265 assert((index + 2) < _locals_size, "Local variable table overflow");
duke@0 266 _locals[index + 2] = VerificationType::bogus_type();
duke@0 267 }
duke@0 268 // If type at index is double_2 or long_2, set the previous location to be unusable
duke@0 269 if (_locals[index].is_double2() || _locals[index].is_long2()) {
duke@0 270 assert(index >= 1, "Local variable table underflow");
duke@0 271 _locals[index - 1] = VerificationType::bogus_type();
duke@0 272 }
duke@0 273 _locals[index] = type1;
duke@0 274 _locals[index+1] = type2;
duke@0 275 if (index >= _locals_size - 1) {
duke@0 276 #ifdef ASSERT
duke@0 277 for (int i=_locals_size; i<index; i++) {
duke@0 278 assert(_locals[i] == VerificationType::bogus_type(),
duke@0 279 "holes must be bogus type");
duke@0 280 }
duke@0 281 #endif
duke@0 282 _locals_size = index + 2;
duke@0 283 }
duke@0 284 }
duke@0 285
duke@0 286 #ifndef PRODUCT
duke@0 287
duke@0 288 void StackMapFrame::print() const {
duke@0 289 tty->print_cr("stackmap_frame[%d]:", _offset);
duke@0 290 tty->print_cr("flags = 0x%x", _flags);
duke@0 291 tty->print("locals[%d] = { ", _locals_size);
duke@0 292 for (int32_t i = 0; i < _locals_size; i++) {
duke@0 293 _locals[i].print_on(tty);
duke@0 294 }
duke@0 295 tty->print_cr(" }");
duke@0 296 tty->print("stack[%d] = { ", _stack_size);
duke@0 297 for (int32_t j = 0; j < _stack_size; j++) {
duke@0 298 _stack[j].print_on(tty);
duke@0 299 }
duke@0 300 tty->print_cr(" }");
duke@0 301 }
duke@0 302
duke@0 303 #endif