src/share/vm/classfile/stackMapFrame.cpp

Thu, 20 Apr 2017 04:53:33 -0400

author
shshahma
date
Thu, 20 Apr 2017 04:53:33 -0400
changeset 8761
4c3cae5323bb
parent 8703
02a3d0dcbedd
child 8856
ac27a9c85bea
permissions
-rw-r--r--

8171194: Exception "Duplicate field name&signature in class file" should report the name and signature of the field
Summary: Added code to emit name and signature of duplicate field in java.lang.ClassFormatError exception message
Reviewed-by: dholmes, coleenp

duke@435 1 /*
kevinw@8703 2 * Copyright (c) 2003, 2016, 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 #include "precompiled.hpp"
stefank@2314 26 #include "classfile/stackMapFrame.hpp"
stefank@2314 27 #include "classfile/verifier.hpp"
stefank@2314 28 #include "memory/resourceArea.hpp"
stefank@2314 29 #include "oops/oop.inline.hpp"
coleenp@2497 30 #include "oops/symbol.hpp"
stefank@2314 31 #include "runtime/handles.inline.hpp"
stefank@2314 32 #include "utilities/globalDefinitions.hpp"
duke@435 33
duke@435 34 StackMapFrame::StackMapFrame(u2 max_locals, u2 max_stack, ClassVerifier* v) :
kamg@3992 35 _offset(0), _locals_size(0), _stack_size(0),
kamg@3992 36 _stack_mark(0), _flags(0), _max_locals(max_locals),
kamg@3992 37 _max_stack(max_stack), _verifier(v) {
duke@435 38 Thread* thr = v->thread();
duke@435 39 _locals = NEW_RESOURCE_ARRAY_IN_THREAD(thr, VerificationType, max_locals);
duke@435 40 _stack = NEW_RESOURCE_ARRAY_IN_THREAD(thr, VerificationType, max_stack);
duke@435 41 int32_t i;
duke@435 42 for(i = 0; i < max_locals; i++) {
duke@435 43 _locals[i] = VerificationType::bogus_type();
duke@435 44 }
duke@435 45 for(i = 0; i < max_stack; i++) {
duke@435 46 _stack[i] = VerificationType::bogus_type();
duke@435 47 }
duke@435 48 }
duke@435 49
duke@435 50 StackMapFrame* StackMapFrame::frame_in_exception_handler(u1 flags) {
duke@435 51 Thread* thr = _verifier->thread();
duke@435 52 VerificationType* stack = NEW_RESOURCE_ARRAY_IN_THREAD(thr, VerificationType, 1);
duke@435 53 StackMapFrame* frame = new StackMapFrame(_offset, flags, _locals_size, 0, _max_locals, _max_stack, _locals, stack, _verifier);
duke@435 54 return frame;
duke@435 55 }
duke@435 56
duke@435 57 void StackMapFrame::initialize_object(
duke@435 58 VerificationType old_object, VerificationType new_object) {
duke@435 59 int32_t i;
duke@435 60 for (i = 0; i < _max_locals; i++) {
duke@435 61 if (_locals[i].equals(old_object)) {
duke@435 62 _locals[i] = new_object;
duke@435 63 }
duke@435 64 }
duke@435 65 for (i = 0; i < _stack_size; i++) {
duke@435 66 if (_stack[i].equals(old_object)) {
duke@435 67 _stack[i] = new_object;
duke@435 68 }
duke@435 69 }
duke@435 70 if (old_object == VerificationType::uninitialized_this_type()) {
duke@435 71 // "this" has been initialized - reset flags
duke@435 72 _flags = 0;
duke@435 73 }
duke@435 74 }
duke@435 75
duke@435 76 VerificationType StackMapFrame::set_locals_from_arg(
duke@435 77 const methodHandle m, VerificationType thisKlass, TRAPS) {
coleenp@2497 78 SignatureStream ss(m->signature());
duke@435 79 int init_local_num = 0;
duke@435 80 if (!m->is_static()) {
duke@435 81 init_local_num++;
duke@435 82 // add one extra argument for instance method
duke@435 83 if (m->name() == vmSymbols::object_initializer_name() &&
duke@435 84 thisKlass.name() != vmSymbols::java_lang_Object()) {
duke@435 85 _locals[0] = VerificationType::uninitialized_this_type();
duke@435 86 _flags |= FLAG_THIS_UNINIT;
duke@435 87 } else {
duke@435 88 _locals[0] = thisKlass;
duke@435 89 }
duke@435 90 }
duke@435 91
duke@435 92 // local num may be greater than size of parameters because long/double occupies two slots
duke@435 93 while(!ss.at_return_type()) {
duke@435 94 init_local_num += _verifier->change_sig_to_verificationType(
duke@435 95 &ss, &_locals[init_local_num],
duke@435 96 CHECK_VERIFY_(verifier(), VerificationType::bogus_type()));
duke@435 97 ss.next();
duke@435 98 }
duke@435 99 _locals_size = init_local_num;
duke@435 100
duke@435 101 switch (ss.type()) {
duke@435 102 case T_OBJECT:
duke@435 103 case T_ARRAY:
duke@435 104 {
coleenp@2497 105 Symbol* sig = ss.as_symbol(CHECK_(VerificationType::bogus_type()));
coleenp@2497 106 // Create another symbol to save as signature stream unreferences
coleenp@2497 107 // this symbol.
coleenp@2497 108 Symbol* sig_copy =
coleenp@2497 109 verifier()->create_temporary_symbol(sig, 0, sig->utf8_length(),
coleenp@2497 110 CHECK_(VerificationType::bogus_type()));
coleenp@2497 111 assert(sig_copy == sig, "symbols don't match");
coleenp@2497 112 return VerificationType::reference_type(sig_copy);
duke@435 113 }
duke@435 114 case T_INT: return VerificationType::integer_type();
duke@435 115 case T_BYTE: return VerificationType::byte_type();
duke@435 116 case T_CHAR: return VerificationType::char_type();
duke@435 117 case T_SHORT: return VerificationType::short_type();
duke@435 118 case T_BOOLEAN: return VerificationType::boolean_type();
duke@435 119 case T_FLOAT: return VerificationType::float_type();
duke@435 120 case T_DOUBLE: return VerificationType::double_type();
duke@435 121 case T_LONG: return VerificationType::long_type();
duke@435 122 case T_VOID: return VerificationType::bogus_type();
duke@435 123 default:
duke@435 124 ShouldNotReachHere();
duke@435 125 }
duke@435 126 return VerificationType::bogus_type();
duke@435 127 }
duke@435 128
duke@435 129 void StackMapFrame::copy_locals(const StackMapFrame* src) {
duke@435 130 int32_t len = src->locals_size() < _locals_size ?
duke@435 131 src->locals_size() : _locals_size;
duke@435 132 for (int32_t i = 0; i < len; i++) {
duke@435 133 _locals[i] = src->locals()[i];
duke@435 134 }
duke@435 135 }
duke@435 136
duke@435 137 void StackMapFrame::copy_stack(const StackMapFrame* src) {
duke@435 138 int32_t len = src->stack_size() < _stack_size ?
duke@435 139 src->stack_size() : _stack_size;
duke@435 140 for (int32_t i = 0; i < len; i++) {
duke@435 141 _stack[i] = src->stack()[i];
duke@435 142 }
duke@435 143 }
duke@435 144
kamg@3992 145 // Returns the location of the first mismatch, or 'len' if there are no
kamg@3992 146 // mismatches
kamg@3992 147 int StackMapFrame::is_assignable_to(
duke@435 148 VerificationType* from, VerificationType* to, int32_t len, TRAPS) const {
kamg@3992 149 int32_t i = 0;
kamg@3992 150 for (i = 0; i < len; i++) {
hseigel@6824 151 if (!to[i].is_assignable_from(from[i], verifier(), false, THREAD)) {
kamg@3992 152 break;
duke@435 153 }
duke@435 154 }
kamg@3992 155 return i;
duke@435 156 }
duke@435 157
kamg@2754 158 bool StackMapFrame::is_assignable_to(
kevinw@8703 159 const StackMapFrame* target, ErrorContext* ctx, TRAPS) const {
kamg@3992 160 if (_max_locals != target->max_locals()) {
kamg@3992 161 *ctx = ErrorContext::locals_size_mismatch(
kamg@3992 162 _offset, (StackMapFrame*)this, (StackMapFrame*)target);
kamg@3992 163 return false;
kamg@3992 164 }
kamg@3992 165 if (_stack_size != target->stack_size()) {
kamg@3992 166 *ctx = ErrorContext::stack_size_mismatch(
kamg@3992 167 _offset, (StackMapFrame*)this, (StackMapFrame*)target);
duke@435 168 return false;
duke@435 169 }
duke@435 170 // Only need to compare type elements up to target->locals() or target->stack().
duke@435 171 // The remaining type elements in this state can be ignored because they are
duke@435 172 // assignable to bogus type.
kamg@3992 173 int mismatch_loc;
kamg@3992 174 mismatch_loc = is_assignable_to(
kamg@3992 175 _locals, target->locals(), target->locals_size(), THREAD);
kamg@3992 176 if (mismatch_loc != target->locals_size()) {
kamg@3992 177 *ctx = ErrorContext::bad_type(target->offset(),
kamg@3992 178 TypeOrigin::local(mismatch_loc, (StackMapFrame*)this),
kamg@3992 179 TypeOrigin::sm_local(mismatch_loc, (StackMapFrame*)target));
kamg@3992 180 return false;
kamg@3992 181 }
kamg@3992 182 mismatch_loc = is_assignable_to(_stack, target->stack(), _stack_size, THREAD);
kamg@3992 183 if (mismatch_loc != _stack_size) {
kamg@3992 184 *ctx = ErrorContext::bad_type(target->offset(),
kamg@3992 185 TypeOrigin::stack(mismatch_loc, (StackMapFrame*)this),
kamg@3992 186 TypeOrigin::sm_stack(mismatch_loc, (StackMapFrame*)target));
kamg@3992 187 return false;
kamg@3992 188 }
kamg@3992 189
kevinw@8703 190 if ((_flags | target->flags()) == target->flags()) {
kamg@3992 191 return true;
kamg@3992 192 } else {
kamg@3992 193 *ctx = ErrorContext::bad_flags(target->offset(),
kamg@3992 194 (StackMapFrame*)this, (StackMapFrame*)target);
kamg@3992 195 return false;
kamg@3992 196 }
duke@435 197 }
duke@435 198
duke@435 199 VerificationType StackMapFrame::pop_stack_ex(VerificationType type, TRAPS) {
duke@435 200 if (_stack_size <= 0) {
kamg@3992 201 verifier()->verify_error(
kamg@3992 202 ErrorContext::stack_underflow(_offset, this),
kamg@3992 203 "Operand stack underflow");
duke@435 204 return VerificationType::bogus_type();
duke@435 205 }
duke@435 206 VerificationType top = _stack[--_stack_size];
duke@435 207 bool subtype = type.is_assignable_from(
hseigel@6824 208 top, verifier(), false, CHECK_(VerificationType::bogus_type()));
duke@435 209 if (!subtype) {
kamg@3992 210 verifier()->verify_error(
kamg@3992 211 ErrorContext::bad_type(_offset, stack_top_ctx(),
kamg@3992 212 TypeOrigin::implicit(type)),
kamg@3992 213 "Bad type on operand stack");
duke@435 214 return VerificationType::bogus_type();
duke@435 215 }
duke@435 216 return top;
duke@435 217 }
duke@435 218
duke@435 219 VerificationType StackMapFrame::get_local(
duke@435 220 int32_t index, VerificationType type, TRAPS) {
duke@435 221 if (index >= _max_locals) {
kamg@3992 222 verifier()->verify_error(
kamg@3992 223 ErrorContext::bad_local_index(_offset, index),
kamg@3992 224 "Local variable table overflow");
duke@435 225 return VerificationType::bogus_type();
duke@435 226 }
duke@435 227 bool subtype = type.is_assignable_from(_locals[index],
hseigel@6824 228 verifier(), false, CHECK_(VerificationType::bogus_type()));
duke@435 229 if (!subtype) {
kamg@3992 230 verifier()->verify_error(
kamg@3992 231 ErrorContext::bad_type(_offset,
kamg@3992 232 TypeOrigin::local(index, this),
kamg@3992 233 TypeOrigin::implicit(type)),
kamg@3992 234 "Bad local variable type");
duke@435 235 return VerificationType::bogus_type();
duke@435 236 }
duke@435 237 if(index >= _locals_size) { _locals_size = index + 1; }
duke@435 238 return _locals[index];
duke@435 239 }
duke@435 240
duke@435 241 void StackMapFrame::get_local_2(
duke@435 242 int32_t index, VerificationType type1, VerificationType type2, TRAPS) {
duke@435 243 assert(type1.is_long() || type1.is_double(), "must be long/double");
duke@435 244 assert(type2.is_long2() || type2.is_double2(), "must be long/double_2");
duke@435 245 if (index >= _locals_size - 1) {
kamg@3992 246 verifier()->verify_error(
kamg@3992 247 ErrorContext::bad_local_index(_offset, index),
kamg@3992 248 "get long/double overflows locals");
duke@435 249 return;
duke@435 250 }
hseigel@6824 251 bool subtype = type1.is_assignable_from(_locals[index], verifier(), false, CHECK);
kamg@3992 252 if (!subtype) {
kamg@3992 253 verifier()->verify_error(
kamg@3992 254 ErrorContext::bad_type(_offset,
kamg@3992 255 TypeOrigin::local(index, this), TypeOrigin::implicit(type1)),
kamg@3992 256 "Bad local variable type");
kamg@3992 257 } else {
hseigel@6824 258 subtype = type2.is_assignable_from(_locals[index + 1], verifier(), false, CHECK);
kamg@3992 259 if (!subtype) {
kamg@3992 260 /* Unreachable? All local store routines convert a split long or double
kamg@3992 261 * into a TOP during the store. So we should never end up seeing an
kamg@3992 262 * orphaned half. */
kamg@3992 263 verifier()->verify_error(
kamg@3992 264 ErrorContext::bad_type(_offset,
kamg@3992 265 TypeOrigin::local(index + 1, this), TypeOrigin::implicit(type2)),
kamg@3992 266 "Bad local variable type");
kamg@3992 267 }
duke@435 268 }
duke@435 269 }
duke@435 270
duke@435 271 void StackMapFrame::set_local(int32_t index, VerificationType type, TRAPS) {
duke@435 272 assert(!type.is_check(), "Must be a real type");
duke@435 273 if (index >= _max_locals) {
kamg@3992 274 verifier()->verify_error(
kamg@3992 275 ErrorContext::bad_local_index(_offset, index),
kamg@3992 276 "Local variable table overflow");
duke@435 277 return;
duke@435 278 }
duke@435 279 // If type at index is double or long, set the next location to be unusable
duke@435 280 if (_locals[index].is_double() || _locals[index].is_long()) {
duke@435 281 assert((index + 1) < _locals_size, "Local variable table overflow");
duke@435 282 _locals[index + 1] = VerificationType::bogus_type();
duke@435 283 }
duke@435 284 // If type at index is double_2 or long_2, set the previous location to be unusable
duke@435 285 if (_locals[index].is_double2() || _locals[index].is_long2()) {
duke@435 286 assert(index >= 1, "Local variable table underflow");
duke@435 287 _locals[index - 1] = VerificationType::bogus_type();
duke@435 288 }
duke@435 289 _locals[index] = type;
duke@435 290 if (index >= _locals_size) {
duke@435 291 #ifdef ASSERT
duke@435 292 for (int i=_locals_size; i<index; i++) {
duke@435 293 assert(_locals[i] == VerificationType::bogus_type(),
duke@435 294 "holes must be bogus type");
duke@435 295 }
duke@435 296 #endif
duke@435 297 _locals_size = index + 1;
duke@435 298 }
duke@435 299 }
duke@435 300
duke@435 301 void StackMapFrame::set_local_2(
duke@435 302 int32_t index, VerificationType type1, VerificationType type2, TRAPS) {
duke@435 303 assert(type1.is_long() || type1.is_double(), "must be long/double");
duke@435 304 assert(type2.is_long2() || type2.is_double2(), "must be long/double_2");
duke@435 305 if (index >= _max_locals - 1) {
kamg@3992 306 verifier()->verify_error(
kamg@3992 307 ErrorContext::bad_local_index(_offset, index),
kamg@3992 308 "Local variable table overflow");
duke@435 309 return;
duke@435 310 }
duke@435 311 // If type at index+1 is double or long, set the next location to be unusable
duke@435 312 if (_locals[index+1].is_double() || _locals[index+1].is_long()) {
duke@435 313 assert((index + 2) < _locals_size, "Local variable table overflow");
duke@435 314 _locals[index + 2] = VerificationType::bogus_type();
duke@435 315 }
duke@435 316 // If type at index is double_2 or long_2, set the previous location to be unusable
duke@435 317 if (_locals[index].is_double2() || _locals[index].is_long2()) {
duke@435 318 assert(index >= 1, "Local variable table underflow");
duke@435 319 _locals[index - 1] = VerificationType::bogus_type();
duke@435 320 }
duke@435 321 _locals[index] = type1;
duke@435 322 _locals[index+1] = type2;
duke@435 323 if (index >= _locals_size - 1) {
duke@435 324 #ifdef ASSERT
duke@435 325 for (int i=_locals_size; i<index; i++) {
duke@435 326 assert(_locals[i] == VerificationType::bogus_type(),
duke@435 327 "holes must be bogus type");
duke@435 328 }
duke@435 329 #endif
duke@435 330 _locals_size = index + 2;
duke@435 331 }
duke@435 332 }
duke@435 333
kamg@3992 334 TypeOrigin StackMapFrame::stack_top_ctx() {
kamg@3992 335 return TypeOrigin::stack(_stack_size, this);
duke@435 336 }
duke@435 337
kamg@3992 338 void StackMapFrame::print_on(outputStream* str) const {
kamg@3992 339 str->indent().print_cr("bci: @%d", _offset);
kamg@3992 340 str->indent().print_cr("flags: {%s }",
kamg@3992 341 flag_this_uninit() ? " flagThisUninit" : "");
kamg@3992 342 str->indent().print("locals: {");
kamg@3992 343 for (int32_t i = 0; i < _locals_size; ++i) {
kamg@3992 344 str->print(" ");
kamg@3992 345 _locals[i].print_on(str);
kamg@3992 346 if (i != _locals_size - 1) {
kamg@3992 347 str->print(",");
kamg@3992 348 }
kamg@3992 349 }
kamg@3992 350 str->print_cr(" }");
kamg@3992 351 str->indent().print("stack: {");
kamg@3992 352 for (int32_t j = 0; j < _stack_size; ++j) {
kamg@3992 353 str->print(" ");
kamg@3992 354 _stack[j].print_on(str);
kamg@3992 355 if (j != _stack_size - 1) {
kamg@3992 356 str->print(",");
kamg@3992 357 }
kamg@3992 358 }
kamg@3992 359 str->print_cr(" }");
kamg@3992 360 }

mercurial