1 /* 2 * Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 package jdk.internal.classfile.impl.verifier; 26 27 import java.lang.classfile.ClassHierarchyResolver; 28 import java.lang.classfile.ClassModel; 29 import jdk.internal.classfile.components.ClassPrinter; 30 import java.util.ArrayList; 31 import java.util.Collections; 32 import java.util.List; 33 import java.util.function.Consumer; 34 35 import jdk.internal.classfile.impl.ClassHierarchyImpl; 36 import jdk.internal.classfile.impl.RawBytecodeHelper; 37 import jdk.internal.classfile.impl.verifier.VerificationSignature.BasicType; 38 import jdk.internal.classfile.impl.verifier.VerificationWrapper.ConstantPoolWrapper; 39 40 import static jdk.internal.classfile.impl.RawBytecodeHelper.*; 41 import static jdk.internal.classfile.impl.verifier.VerificationFrame.FLAG_THIS_UNINIT; 42 import static jdk.internal.classfile.impl.verifier.VerificationSignature.BasicType.T_BOOLEAN; 43 import static jdk.internal.classfile.impl.verifier.VerificationSignature.BasicType.T_LONG; 44 45 /** 46 * VerifierImpl performs selected checks and verifications of the class file 47 * format according to {@jvms 4.8 Format Checking}, 48 * {@jvms 4.9 Constraints on Java Virtual Machine code}, 49 * {@jvms 4.10 Verification of class Files} and {@jvms 6.5 Instructions} 50 * 51 * @see <a href="https://raw.githubusercontent.com/openjdk/jdk/master/src/java.base/share/native/include/classfile_constants.h.template">java.base/share/native/include/classfile_constants.h.template</a> 52 * @see <a href="https://raw.githubusercontent.com/openjdk/jdk/master/src/hotspot/share/classfile/verifier.hpp">hotspot/share/classfile/verifier.hpp</a> 53 * @see <a href="https://raw.githubusercontent.com/openjdk/jdk/master/src/hotspot/share/classfile/verifier.cpp">hotspot/share/classfile/verifier.cpp</a> 54 */ 55 public final class VerifierImpl { 56 static final int 57 JVM_CONSTANT_Utf8 = 1, 58 JVM_CONSTANT_Unicode = 2, 59 JVM_CONSTANT_Integer = 3, 60 JVM_CONSTANT_Float = 4, 61 JVM_CONSTANT_Long = 5, 62 JVM_CONSTANT_Double = 6, 63 JVM_CONSTANT_Class = 7, 64 JVM_CONSTANT_String = 8, 65 JVM_CONSTANT_Fieldref = 9, 66 JVM_CONSTANT_Methodref = 10, 67 JVM_CONSTANT_InterfaceMethodref = 11, 68 JVM_CONSTANT_NameAndType = 12, 69 JVM_CONSTANT_MethodHandle = 15, 70 JVM_CONSTANT_MethodType = 16, 71 JVM_CONSTANT_Dynamic = 17, 72 JVM_CONSTANT_InvokeDynamic = 18, 73 JVM_CONSTANT_Module = 19, 74 JVM_CONSTANT_Package = 20, 75 JVM_CONSTANT_ExternalMax = 20; 76 77 static final char JVM_SIGNATURE_SPECIAL = '<', 78 JVM_SIGNATURE_ARRAY = '[', 79 JVM_SIGNATURE_BYTE = 'B', 80 JVM_SIGNATURE_CHAR = 'C', 81 JVM_SIGNATURE_CLASS = 'L', 82 JVM_SIGNATURE_FLOAT = 'F', 83 JVM_SIGNATURE_DOUBLE = 'D', 84 JVM_SIGNATURE_INT = 'I', 85 JVM_SIGNATURE_LONG = 'J', 86 JVM_SIGNATURE_SHORT = 'S', 87 JVM_SIGNATURE_BOOLEAN = 'Z'; 88 89 static final String java_lang_String = "java/lang/String"; 90 static final String object_initializer_name = "<init>"; 91 static final String java_lang_invoke_MethodHandle = "java/lang/invoke/MethodHandle"; 92 static final String java_lang_Object = "java/lang/Object"; 93 static final String java_lang_invoke_MethodType = "java/lang/invoke/MethodType"; 94 static final String java_lang_Throwable = "java/lang/Throwable"; 95 static final String java_lang_Class = "java/lang/Class"; 96 97 String errorContext = ""; 98 private int bci; 99 100 static void log_info(Consumer<String> logger, String messageFormat, Object... args) { 101 if (logger != null) logger.accept(String.format(messageFormat + "%n", args)); 102 } 103 private final Consumer<String> _logger; 104 void log_info(String messageFormat, Object... args) { 105 log_info(_logger, messageFormat, args); 106 } 107 108 109 static final int STACKMAP_ATTRIBUTE_MAJOR_VERSION = 50; 110 static final int INVOKEDYNAMIC_MAJOR_VERSION = 51; 111 static final int NOFAILOVER_MAJOR_VERSION = 51; 112 static final int MAX_CODE_SIZE = 65535; 113 114 public static List<VerifyError> verify(ClassModel classModel, Consumer<String> logger) { 115 return verify(classModel, ClassHierarchyResolver.defaultResolver(), logger); 116 } 117 118 public static List<VerifyError> verify(ClassModel classModel, ClassHierarchyResolver classHierarchyResolver, Consumer<String> logger) { 119 String clsName = classModel.thisClass().asInternalName(); 120 log_info(logger, "Start class verification for: %s", clsName); 121 try { 122 var klass = new VerificationWrapper(classModel); 123 var errors = new ArrayList<VerifyError>(); 124 errors.addAll(new ParserVerifier(classModel).verify()); 125 if (is_eligible_for_verification(klass)) { 126 if (klass.majorVersion() >= STACKMAP_ATTRIBUTE_MAJOR_VERSION) { 127 var verifierErrors = new VerifierImpl(klass, classHierarchyResolver, logger).verify_class(); 128 if (!verifierErrors.isEmpty() && klass.majorVersion() < NOFAILOVER_MAJOR_VERSION) { 129 log_info(logger, "Fail over class verification to old verifier for: %s", klass.thisClassName()); 130 errors.addAll(inference_verify(klass)); 131 } else { 132 errors.addAll(verifierErrors); 133 } 134 } else { 135 errors.addAll(inference_verify(klass)); 136 } 137 } 138 return Collections.unmodifiableList(errors); 139 } finally { 140 log_info(logger, "End class verification for: %s", clsName); 141 } 142 } 143 144 public static boolean is_eligible_for_verification(VerificationWrapper klass) { 145 String name = klass.thisClassName(); 146 return !java_lang_Object.equals(name) && 147 !java_lang_Class.equals(name) && 148 !java_lang_String.equals(name) && 149 !java_lang_Throwable.equals(name); 150 } 151 152 static List<VerifyError> inference_verify(VerificationWrapper klass) { 153 return List.of(new VerifyError("Inference verification is not supported")); 154 } 155 156 static class sig_as_verification_types { 157 private int _num_args; 158 private ArrayList<VerificationType> _sig_verif_types; 159 160 sig_as_verification_types(ArrayList<VerificationType> sig_verif_types) { 161 this._sig_verif_types = sig_verif_types; 162 this._num_args = 0; 163 } 164 165 int num_args() { 166 return _num_args; 167 } 168 169 void set_num_args(int num_args) { 170 _num_args = num_args; 171 } 172 173 ArrayList<VerificationType> sig_verif_types() { 174 return _sig_verif_types; 175 } 176 } 177 178 VerificationType cp_ref_index_to_type(int index, ConstantPoolWrapper cp) { 179 return cp_index_to_type(cp.refClassIndexAt(index), cp); 180 } 181 182 final VerificationWrapper _klass; 183 final ClassHierarchyImpl _class_hierarchy; 184 VerificationWrapper.MethodWrapper _method; 185 VerificationType _this_type; 186 187 static final int BYTECODE_OFFSET = 1, NEW_OFFSET = 2; 188 189 VerificationWrapper current_class() { 190 return _klass; 191 } 192 193 ClassHierarchyImpl class_hierarchy() { 194 return _class_hierarchy; 195 } 196 197 VerificationType current_type() { 198 return _this_type; 199 } 200 201 VerificationType cp_index_to_type(int index, ConstantPoolWrapper cp) { 202 return VerificationType.reference_type(cp.classNameAt(index)); 203 } 204 205 int change_sig_to_verificationType(VerificationSignature sig_type, VerificationType inference_types[], int inference_type_index) { 206 BasicType bt = sig_type.type(); 207 switch (bt) { 208 case T_OBJECT: 209 case T_ARRAY: 210 String name = sig_type.asSymbol(); 211 inference_types[inference_type_index] = VerificationType.reference_type(name); 212 return 1; 213 case T_LONG: 214 inference_types[inference_type_index] = VerificationType.long_type; 215 inference_types[++inference_type_index] = VerificationType.long2_type; 216 return 2; 217 case T_DOUBLE: 218 inference_types[inference_type_index] = VerificationType.double_type; 219 inference_types[++inference_type_index] = VerificationType.double2_type; 220 return 2; 221 case T_INT: 222 case T_BOOLEAN: 223 case T_BYTE: 224 case T_CHAR: 225 case T_SHORT: 226 inference_types[inference_type_index] = VerificationType.integer_type; 227 return 1; 228 case T_FLOAT: 229 inference_types[inference_type_index] = VerificationType.float_type; 230 return 1; 231 default: 232 verifyError("Should not reach here"); 233 return 1; 234 } 235 } 236 237 private static final int NONZERO_PADDING_BYTES_IN_SWITCH_MAJOR_VERSION = 51; 238 private static final int STATIC_METHOD_IN_INTERFACE_MAJOR_VERSION = 52; 239 private static final int MAX_ARRAY_DIMENSIONS = 255; 240 241 VerifierImpl(VerificationWrapper klass, ClassHierarchyResolver classHierarchyResolver, Consumer<String> logger) { 242 _klass = klass; 243 _class_hierarchy = new ClassHierarchyImpl(classHierarchyResolver); 244 _this_type = VerificationType.reference_type(klass.thisClassName()); 245 _logger = logger; 246 } 247 248 private VerificationType object_type() { 249 return VerificationType.reference_type(java_lang_Object); 250 } 251 252 List<VerifyError> verify_class() { 253 log_info("Verifying class %s with new format", _klass.thisClassName()); 254 var errors = new ArrayList<VerifyError>(); 255 for (VerificationWrapper.MethodWrapper m : _klass.methods()) { 256 if (m.isNative() || m.isAbstract() || m.isBridge()) { 257 continue; 258 } 259 verify_method(m, errors); 260 } 261 return errors; 262 } 263 264 void translate_signature(String method_sig, sig_as_verification_types sig_verif_types) { 265 var sig_stream = new VerificationSignature(method_sig, true, this); 266 VerificationType[] sig_type = new VerificationType[2]; 267 int sig_i = 0; 268 ArrayList<VerificationType> verif_types = sig_verif_types.sig_verif_types(); 269 while (!sig_stream.atReturnType()) { 270 int n = change_sig_to_verificationType(sig_stream, sig_type, 0); 271 if (n > 2) verifyError("Unexpected signature type"); 272 for (int x = 0; x < n; x++) { 273 verif_types.add(sig_type[x]); 274 } 275 sig_i += n; 276 sig_stream.next(); 277 } 278 sig_verif_types.set_num_args(sig_i); 279 if (sig_stream.type() != BasicType.T_VOID) { 280 int n = change_sig_to_verificationType(sig_stream, sig_type, 0); 281 if (n > 2) verifyError("Unexpected signature return type"); 282 for (int y = 0; y < n; y++) { 283 verif_types.add(sig_type[y]); 284 } 285 } 286 } 287 288 void create_method_sig_entry(sig_as_verification_types sig_verif_types, String method_sig) { 289 translate_signature(method_sig, sig_verif_types); 290 } 291 292 void verify_method(VerificationWrapper.MethodWrapper m, List<VerifyError> errorsCollector) { 293 try { 294 verify_method(m); 295 } catch (VerifyError err) { 296 errorsCollector.add(err); 297 } catch (Error | Exception e) { 298 errorsCollector.add(new VerifyError(e.toString())); 299 } 300 } 301 302 @SuppressWarnings("fallthrough") 303 void verify_method(VerificationWrapper.MethodWrapper m) { 304 _method = m; 305 log_info(_logger, "Verifying method %s%s", m.name(), m.descriptor()); 306 byte[] codeArray = m.codeArray(); 307 if (codeArray == null) verifyError("Missing Code attribute"); 308 int max_locals = m.maxLocals(); 309 int max_stack = m.maxStack(); 310 byte[] stackmap_data = m.stackMapTableRawData(); 311 var cp = m.constantPool(); 312 if (!VerificationSignature.isValidMethodSignature(m.descriptor())) verifyError("Invalid method signature"); 313 VerificationFrame current_frame = new VerificationFrame(max_locals, max_stack, this); 314 VerificationType return_type = current_frame.set_locals_from_arg(m, current_type()); 315 int stackmap_index = 0; 316 int code_length = m.codeLength(); 317 if (code_length < 1 || code_length > MAX_CODE_SIZE) { 318 verifyError(String.format("Invalid method Code length %d", code_length)); 319 } 320 var code = RawBytecodeHelper.of(codeArray); 321 byte[] code_data = generate_code_data(code); 322 int ex_minmax[] = new int[] {code_length, -1}; 323 verify_exception_handler_table(code_length, code_data, ex_minmax); 324 verify_local_variable_table(code_length, code_data); 325 326 VerificationTable stackmap_table = new VerificationTable(stackmap_data, current_frame, max_locals, max_stack, code_data, code_length, cp, this); 327 328 var bcs = code.start(); 329 boolean no_control_flow = false; 330 int opcode; 331 while (bcs.next()) { 332 opcode = bcs.opcode(); 333 bci = bcs.bci(); 334 current_frame.set_offset(bci); 335 current_frame.set_mark(); 336 stackmap_index = verify_stackmap_table(stackmap_index, bci, current_frame, stackmap_table, no_control_flow); 337 boolean this_uninit = false; 338 boolean verified_exc_handlers = false; 339 { 340 int index; 341 int target; 342 VerificationType type, type2 = null; 343 VerificationType atype; 344 if (bcs.isWide()) { 345 if (opcode != IINC && opcode != ILOAD 346 && opcode != ALOAD && opcode != LLOAD 347 && opcode != ISTORE && opcode != ASTORE 348 && opcode != LSTORE && opcode != FLOAD 349 && opcode != DLOAD && opcode != FSTORE 350 && opcode != DSTORE) { 351 verifyError("Bad wide instruction"); 352 } 353 } 354 if (VerificationBytecodes.is_store_into_local(opcode) && bci >= ex_minmax[0] && bci < ex_minmax[1]) { 355 verify_exception_handler_targets(bci, this_uninit, current_frame, stackmap_table); 356 verified_exc_handlers = true; 357 } 358 switch (opcode) { 359 case NOP : 360 no_control_flow = false; break; 361 case ACONST_NULL : 362 current_frame.push_stack( 363 VerificationType.null_type); 364 no_control_flow = false; break; 365 case ICONST_M1 : 366 case ICONST_0 : 367 case ICONST_1 : 368 case ICONST_2 : 369 case ICONST_3 : 370 case ICONST_4 : 371 case ICONST_5 : 372 current_frame.push_stack( 373 VerificationType.integer_type); 374 no_control_flow = false; break; 375 case LCONST_0 : 376 case LCONST_1 : 377 current_frame.push_stack_2( 378 VerificationType.long_type, 379 VerificationType.long2_type); 380 no_control_flow = false; break; 381 case FCONST_0 : 382 case FCONST_1 : 383 case FCONST_2 : 384 current_frame.push_stack( 385 VerificationType.float_type); 386 no_control_flow = false; break; 387 case DCONST_0 : 388 case DCONST_1 : 389 current_frame.push_stack_2( 390 VerificationType.double_type, 391 VerificationType.double2_type); 392 no_control_flow = false; break; 393 case SIPUSH : 394 case BIPUSH : 395 current_frame.push_stack( 396 VerificationType.integer_type); 397 no_control_flow = false; break; 398 case LDC : 399 verify_ldc( 400 opcode, bcs.getIndexU1(), current_frame, 401 cp, bci); 402 no_control_flow = false; break; 403 case LDC_W : 404 case LDC2_W : 405 verify_ldc( 406 opcode, bcs.getIndexU2(), current_frame, 407 cp, bci); 408 no_control_flow = false; break; 409 case ILOAD : 410 verify_iload(bcs.getIndex(), current_frame); 411 no_control_flow = false; break; 412 case ILOAD_0 : 413 case ILOAD_1 : 414 case ILOAD_2 : 415 case ILOAD_3 : 416 index = opcode - ILOAD_0; 417 verify_iload(index, current_frame); 418 no_control_flow = false; break; 419 case LLOAD : 420 verify_lload(bcs.getIndex(), current_frame); 421 no_control_flow = false; break; 422 case LLOAD_0 : 423 case LLOAD_1 : 424 case LLOAD_2 : 425 case LLOAD_3 : 426 index = opcode - LLOAD_0; 427 verify_lload(index, current_frame); 428 no_control_flow = false; break; 429 case FLOAD : 430 verify_fload(bcs.getIndex(), current_frame); 431 no_control_flow = false; break; 432 case FLOAD_0 : 433 case FLOAD_1 : 434 case FLOAD_2 : 435 case FLOAD_3 : 436 index = opcode - FLOAD_0; 437 verify_fload(index, current_frame); 438 no_control_flow = false; break; 439 case DLOAD : 440 verify_dload(bcs.getIndex(), current_frame); 441 no_control_flow = false; break; 442 case DLOAD_0 : 443 case DLOAD_1 : 444 case DLOAD_2 : 445 case DLOAD_3 : 446 index = opcode - DLOAD_0; 447 verify_dload(index, current_frame); 448 no_control_flow = false; break; 449 case ALOAD : 450 verify_aload(bcs.getIndex(), current_frame); 451 no_control_flow = false; break; 452 case ALOAD_0 : 453 case ALOAD_1 : 454 case ALOAD_2 : 455 case ALOAD_3 : 456 index = opcode - ALOAD_0; 457 verify_aload(index, current_frame); 458 no_control_flow = false; break; 459 case IALOAD : 460 type = current_frame.pop_stack( 461 VerificationType.integer_type); 462 atype = current_frame.pop_stack( 463 VerificationType.reference_check); 464 if (!atype.is_int_array()) { 465 verifyError("Bad type"); 466 } 467 current_frame.push_stack( 468 VerificationType.integer_type); 469 no_control_flow = false; break; 470 case BALOAD : 471 type = current_frame.pop_stack( 472 VerificationType.integer_type); 473 atype = current_frame.pop_stack( 474 VerificationType.reference_check); 475 if (!atype.is_bool_array() && !atype.is_byte_array()) { 476 verifyError("Bad type"); 477 } 478 current_frame.push_stack( 479 VerificationType.integer_type); 480 no_control_flow = false; break; 481 case CALOAD : 482 type = current_frame.pop_stack( 483 VerificationType.integer_type); 484 atype = current_frame.pop_stack( 485 VerificationType.reference_check); 486 if (!atype.is_char_array()) { 487 verifyError("Bad type"); 488 } 489 current_frame.push_stack( 490 VerificationType.integer_type); 491 no_control_flow = false; break; 492 case SALOAD : 493 type = current_frame.pop_stack( 494 VerificationType.integer_type); 495 atype = current_frame.pop_stack( 496 VerificationType.reference_check); 497 if (!atype.is_short_array()) { 498 verifyError("Bad type"); 499 } 500 current_frame.push_stack( 501 VerificationType.integer_type); 502 no_control_flow = false; break; 503 case LALOAD : 504 type = current_frame.pop_stack( 505 VerificationType.integer_type); 506 atype = current_frame.pop_stack( 507 VerificationType.reference_check); 508 if (!atype.is_long_array()) { 509 verifyError("Bad type"); 510 } 511 current_frame.push_stack_2( 512 VerificationType.long_type, 513 VerificationType.long2_type); 514 no_control_flow = false; break; 515 case FALOAD : 516 type = current_frame.pop_stack( 517 VerificationType.integer_type); 518 atype = current_frame.pop_stack( 519 VerificationType.reference_check); 520 if (!atype.is_float_array()) { 521 verifyError("Bad type"); 522 } 523 current_frame.push_stack( 524 VerificationType.float_type); 525 no_control_flow = false; break; 526 case DALOAD : 527 type = current_frame.pop_stack( 528 VerificationType.integer_type); 529 atype = current_frame.pop_stack( 530 VerificationType.reference_check); 531 if (!atype.is_double_array()) { 532 verifyError("Bad type"); 533 } 534 current_frame.push_stack_2( 535 VerificationType.double_type, 536 VerificationType.double2_type); 537 no_control_flow = false; break; 538 case AALOAD : { 539 type = current_frame.pop_stack( 540 VerificationType.integer_type); 541 atype = current_frame.pop_stack( 542 VerificationType.reference_check); 543 if (!atype.is_reference_array()) { 544 verifyError("Bad type"); 545 } 546 if (atype.is_null()) { 547 current_frame.push_stack( 548 VerificationType.null_type); 549 } else { 550 VerificationType component = 551 atype.get_component(this); 552 current_frame.push_stack(component); 553 } 554 no_control_flow = false; break; 555 } 556 case ISTORE : 557 verify_istore(bcs.getIndex(), current_frame); 558 no_control_flow = false; break; 559 case ISTORE_0 : 560 case ISTORE_1 : 561 case ISTORE_2 : 562 case ISTORE_3 : 563 index = opcode - ISTORE_0; 564 verify_istore(index, current_frame); 565 no_control_flow = false; break; 566 case LSTORE : 567 verify_lstore(bcs.getIndex(), current_frame); 568 no_control_flow = false; break; 569 case LSTORE_0 : 570 case LSTORE_1 : 571 case LSTORE_2 : 572 case LSTORE_3 : 573 index = opcode - LSTORE_0; 574 verify_lstore(index, current_frame); 575 no_control_flow = false; break; 576 case FSTORE : 577 verify_fstore(bcs.getIndex(), current_frame); 578 no_control_flow = false; break; 579 case FSTORE_0 : 580 case FSTORE_1 : 581 case FSTORE_2 : 582 case FSTORE_3 : 583 index = opcode - FSTORE_0; 584 verify_fstore(index, current_frame); 585 no_control_flow = false; break; 586 case DSTORE : 587 verify_dstore(bcs.getIndex(), current_frame); 588 no_control_flow = false; break; 589 case DSTORE_0 : 590 case DSTORE_1 : 591 case DSTORE_2 : 592 case DSTORE_3 : 593 index = opcode - DSTORE_0; 594 verify_dstore(index, current_frame); 595 no_control_flow = false; break; 596 case ASTORE : 597 verify_astore(bcs.getIndex(), current_frame); 598 no_control_flow = false; break; 599 case ASTORE_0 : 600 case ASTORE_1 : 601 case ASTORE_2 : 602 case ASTORE_3 : 603 index = opcode - ASTORE_0; 604 verify_astore(index, current_frame); 605 no_control_flow = false; break; 606 case IASTORE : 607 type = current_frame.pop_stack( 608 VerificationType.integer_type); 609 type2 = current_frame.pop_stack( 610 VerificationType.integer_type); 611 atype = current_frame.pop_stack( 612 VerificationType.reference_check); 613 if (!atype.is_int_array()) { 614 verifyError("Bad type"); 615 } 616 no_control_flow = false; break; 617 case BASTORE : 618 type = current_frame.pop_stack( 619 VerificationType.integer_type); 620 type2 = current_frame.pop_stack( 621 VerificationType.integer_type); 622 atype = current_frame.pop_stack( 623 VerificationType.reference_check); 624 if (!atype.is_bool_array() && !atype.is_byte_array()) { 625 verifyError("Bad type"); 626 } 627 no_control_flow = false; break; 628 case CASTORE : 629 current_frame.pop_stack( 630 VerificationType.integer_type); 631 current_frame.pop_stack( 632 VerificationType.integer_type); 633 atype = current_frame.pop_stack( 634 VerificationType.reference_check); 635 if (!atype.is_char_array()) { 636 verifyError("Bad type"); 637 } 638 no_control_flow = false; break; 639 case SASTORE : 640 current_frame.pop_stack( 641 VerificationType.integer_type); 642 current_frame.pop_stack( 643 VerificationType.integer_type); 644 atype = current_frame.pop_stack( 645 VerificationType.reference_check); 646 if (!atype.is_short_array()) { 647 verifyError("Bad type"); 648 } 649 no_control_flow = false; break; 650 case LASTORE : 651 current_frame.pop_stack_2( 652 VerificationType.long2_type, 653 VerificationType.long_type); 654 current_frame.pop_stack( 655 VerificationType.integer_type); 656 atype = current_frame.pop_stack( 657 VerificationType.reference_check); 658 if (!atype.is_long_array()) { 659 verifyError("Bad type"); 660 } 661 no_control_flow = false; break; 662 case FASTORE : 663 current_frame.pop_stack( 664 VerificationType.float_type); 665 current_frame.pop_stack 666 (VerificationType.integer_type); 667 atype = current_frame.pop_stack( 668 VerificationType.reference_check); 669 if (!atype.is_float_array()) { 670 verifyError("Bad type"); 671 } 672 no_control_flow = false; break; 673 case DASTORE : 674 current_frame.pop_stack_2( 675 VerificationType.double2_type, 676 VerificationType.double_type); 677 current_frame.pop_stack( 678 VerificationType.integer_type); 679 atype = current_frame.pop_stack( 680 VerificationType.reference_check); 681 if (!atype.is_double_array()) { 682 verifyError("Bad type"); 683 } 684 no_control_flow = false; break; 685 case AASTORE : 686 type = current_frame.pop_stack(object_type()); 687 type2 = current_frame.pop_stack( 688 VerificationType.integer_type); 689 atype = current_frame.pop_stack( 690 VerificationType.reference_check); 691 // more type-checking is done at runtime 692 if (!atype.is_reference_array()) { 693 verifyError("Bad type"); 694 } 695 // 4938384: relaxed constraint in JVMS 3nd edition. 696 no_control_flow = false; break; 697 case POP : 698 current_frame.pop_stack( 699 VerificationType.category1_check); 700 no_control_flow = false; break; 701 case POP2 : 702 type = current_frame.pop_stack(); 703 if (type.is_category1(this)) { 704 current_frame.pop_stack( 705 VerificationType.category1_check); 706 } else if (type.is_category2_2nd()) { 707 current_frame.pop_stack( 708 VerificationType.category2_check); 709 } else { 710 verifyError("Bad type"); 711 } 712 no_control_flow = false; break; 713 case DUP : 714 type = current_frame.pop_stack( 715 VerificationType.category1_check); 716 current_frame.push_stack(type); 717 current_frame.push_stack(type); 718 no_control_flow = false; break; 719 case DUP_X1 : 720 type = current_frame.pop_stack( 721 VerificationType.category1_check); 722 type2 = current_frame.pop_stack( 723 VerificationType.category1_check); 724 current_frame.push_stack(type); 725 current_frame.push_stack(type2); 726 current_frame.push_stack(type); 727 no_control_flow = false; break; 728 case DUP_X2 : 729 { 730 VerificationType type3 = null; 731 type = current_frame.pop_stack( 732 VerificationType.category1_check); 733 type2 = current_frame.pop_stack(); 734 if (type2.is_category1(this)) { 735 type3 = current_frame.pop_stack( 736 VerificationType.category1_check); 737 } else if (type2.is_category2_2nd()) { 738 type3 = current_frame.pop_stack( 739 VerificationType.category2_check); 740 } else { 741 verifyError("Bad type"); 742 } 743 current_frame.push_stack(type); 744 current_frame.push_stack(type3); 745 current_frame.push_stack(type2); 746 current_frame.push_stack(type); 747 no_control_flow = false; break; 748 } 749 case DUP2 : 750 type = current_frame.pop_stack(); 751 if (type.is_category1(this)) { 752 type2 = current_frame.pop_stack( 753 VerificationType.category1_check); 754 } else if (type.is_category2_2nd()) { 755 type2 = current_frame.pop_stack( 756 VerificationType.category2_check); 757 } else { 758 verifyError("Bad type"); 759 } 760 current_frame.push_stack(type2); 761 current_frame.push_stack(type); 762 current_frame.push_stack(type2); 763 current_frame.push_stack(type); 764 no_control_flow = false; break; 765 case DUP2_X1 : 766 { 767 VerificationType type3; 768 type = current_frame.pop_stack(); 769 if (type.is_category1(this)) { 770 type2 = current_frame.pop_stack( 771 VerificationType.category1_check); 772 } else if (type.is_category2_2nd()) { 773 type2 = current_frame.pop_stack( 774 VerificationType.category2_check); 775 } else { 776 verifyError("Bad type"); 777 } 778 type3 = current_frame.pop_stack( 779 VerificationType.category1_check); 780 current_frame.push_stack(type2); 781 current_frame.push_stack(type); 782 current_frame.push_stack(type3); 783 current_frame.push_stack(type2); 784 current_frame.push_stack(type); 785 no_control_flow = false; break; 786 } 787 case DUP2_X2 : 788 VerificationType type3, type4 = null; 789 type = current_frame.pop_stack(); 790 if (type.is_category1(this)) { 791 type2 = current_frame.pop_stack( 792 VerificationType.category1_check); 793 } else if (type.is_category2_2nd()) { 794 type2 = current_frame.pop_stack( 795 VerificationType.category2_check); 796 } else { 797 verifyError("Bad type"); 798 } 799 type3 = current_frame.pop_stack(); 800 if (type3.is_category1(this)) { 801 type4 = current_frame.pop_stack( 802 VerificationType.category1_check); 803 } else if (type3.is_category2_2nd()) { 804 type4 = current_frame.pop_stack( 805 VerificationType.category2_check); 806 } else { 807 verifyError("Bad type"); 808 } 809 current_frame.push_stack(type2); 810 current_frame.push_stack(type); 811 current_frame.push_stack(type4); 812 current_frame.push_stack(type3); 813 current_frame.push_stack(type2); 814 current_frame.push_stack(type); 815 no_control_flow = false; break; 816 case SWAP : 817 type = current_frame.pop_stack( 818 VerificationType.category1_check); 819 type2 = current_frame.pop_stack( 820 VerificationType.category1_check); 821 current_frame.push_stack(type); 822 current_frame.push_stack(type2); 823 no_control_flow = false; break; 824 case IADD : 825 case ISUB : 826 case IMUL : 827 case IDIV : 828 case IREM : 829 case ISHL : 830 case ISHR : 831 case IUSHR : 832 case IOR : 833 case IXOR : 834 case IAND : 835 current_frame.pop_stack( 836 VerificationType.integer_type); 837 // fall through 838 case INEG : 839 current_frame.pop_stack( 840 VerificationType.integer_type); 841 current_frame.push_stack( 842 VerificationType.integer_type); 843 no_control_flow = false; break; 844 case LADD : 845 case LSUB : 846 case LMUL : 847 case LDIV : 848 case LREM : 849 case LAND : 850 case LOR : 851 case LXOR : 852 current_frame.pop_stack_2( 853 VerificationType.long2_type, 854 VerificationType.long_type); 855 // fall through 856 case LNEG : 857 current_frame.pop_stack_2( 858 VerificationType.long2_type, 859 VerificationType.long_type); 860 current_frame.push_stack_2( 861 VerificationType.long_type, 862 VerificationType.long2_type); 863 no_control_flow = false; break; 864 case LSHL : 865 case LSHR : 866 case LUSHR : 867 current_frame.pop_stack( 868 VerificationType.integer_type); 869 current_frame.pop_stack_2( 870 VerificationType.long2_type, 871 VerificationType.long_type); 872 current_frame.push_stack_2( 873 VerificationType.long_type, 874 VerificationType.long2_type); 875 no_control_flow = false; break; 876 case FADD : 877 case FSUB : 878 case FMUL : 879 case FDIV : 880 case FREM : 881 current_frame.pop_stack( 882 VerificationType.float_type); 883 // fall through 884 case FNEG : 885 current_frame.pop_stack( 886 VerificationType.float_type); 887 current_frame.push_stack( 888 VerificationType.float_type); 889 no_control_flow = false; break; 890 case DADD : 891 case DSUB : 892 case DMUL : 893 case DDIV : 894 case DREM : 895 current_frame.pop_stack_2( 896 VerificationType.double2_type, 897 VerificationType.double_type); 898 // fall through 899 case DNEG : 900 current_frame.pop_stack_2( 901 VerificationType.double2_type, 902 VerificationType.double_type); 903 current_frame.push_stack_2( 904 VerificationType.double_type, 905 VerificationType.double2_type); 906 no_control_flow = false; break; 907 case IINC : 908 verify_iinc(bcs.getIndex(), current_frame); 909 no_control_flow = false; break; 910 case I2L : 911 type = current_frame.pop_stack( 912 VerificationType.integer_type); 913 current_frame.push_stack_2( 914 VerificationType.long_type, 915 VerificationType.long2_type); 916 no_control_flow = false; break; 917 case L2I : 918 current_frame.pop_stack_2( 919 VerificationType.long2_type, 920 VerificationType.long_type); 921 current_frame.push_stack( 922 VerificationType.integer_type); 923 no_control_flow = false; break; 924 case I2F : 925 current_frame.pop_stack( 926 VerificationType.integer_type); 927 current_frame.push_stack( 928 VerificationType.float_type); 929 no_control_flow = false; break; 930 case I2D : 931 current_frame.pop_stack( 932 VerificationType.integer_type); 933 current_frame.push_stack_2( 934 VerificationType.double_type, 935 VerificationType.double2_type); 936 no_control_flow = false; break; 937 case L2F : 938 current_frame.pop_stack_2( 939 VerificationType.long2_type, 940 VerificationType.long_type); 941 current_frame.push_stack( 942 VerificationType.float_type); 943 no_control_flow = false; break; 944 case L2D : 945 current_frame.pop_stack_2( 946 VerificationType.long2_type, 947 VerificationType.long_type); 948 current_frame.push_stack_2( 949 VerificationType.double_type, 950 VerificationType.double2_type); 951 no_control_flow = false; break; 952 case F2I : 953 current_frame.pop_stack( 954 VerificationType.float_type); 955 current_frame.push_stack( 956 VerificationType.integer_type); 957 no_control_flow = false; break; 958 case F2L : 959 current_frame.pop_stack( 960 VerificationType.float_type); 961 current_frame.push_stack_2( 962 VerificationType.long_type, 963 VerificationType.long2_type); 964 no_control_flow = false; break; 965 case F2D : 966 current_frame.pop_stack( 967 VerificationType.float_type); 968 current_frame.push_stack_2( 969 VerificationType.double_type, 970 VerificationType.double2_type); 971 no_control_flow = false; break; 972 case D2I : 973 current_frame.pop_stack_2( 974 VerificationType.double2_type, 975 VerificationType.double_type); 976 current_frame.push_stack( 977 VerificationType.integer_type); 978 no_control_flow = false; break; 979 case D2L : 980 current_frame.pop_stack_2( 981 VerificationType.double2_type, 982 VerificationType.double_type); 983 current_frame.push_stack_2( 984 VerificationType.long_type, 985 VerificationType.long2_type); 986 no_control_flow = false; break; 987 case D2F : 988 current_frame.pop_stack_2( 989 VerificationType.double2_type, 990 VerificationType.double_type); 991 current_frame.push_stack( 992 VerificationType.float_type); 993 no_control_flow = false; break; 994 case I2B : 995 case I2C : 996 case I2S : 997 current_frame.pop_stack( 998 VerificationType.integer_type); 999 current_frame.push_stack( 1000 VerificationType.integer_type); 1001 no_control_flow = false; break; 1002 case LCMP : 1003 current_frame.pop_stack_2( 1004 VerificationType.long2_type, 1005 VerificationType.long_type); 1006 current_frame.pop_stack_2( 1007 VerificationType.long2_type, 1008 VerificationType.long_type); 1009 current_frame.push_stack( 1010 VerificationType.integer_type); 1011 no_control_flow = false; break; 1012 case FCMPL : 1013 case FCMPG : 1014 current_frame.pop_stack( 1015 VerificationType.float_type); 1016 current_frame.pop_stack( 1017 VerificationType.float_type); 1018 current_frame.push_stack( 1019 VerificationType.integer_type); 1020 no_control_flow = false; break; 1021 case DCMPL : 1022 case DCMPG : 1023 current_frame.pop_stack_2( 1024 VerificationType.double2_type, 1025 VerificationType.double_type); 1026 current_frame.pop_stack_2( 1027 VerificationType.double2_type, 1028 VerificationType.double_type); 1029 current_frame.push_stack( 1030 VerificationType.integer_type); 1031 no_control_flow = false; break; 1032 case IF_ICMPEQ: 1033 case IF_ICMPNE: 1034 case IF_ICMPLT: 1035 case IF_ICMPGE: 1036 case IF_ICMPGT: 1037 case IF_ICMPLE: 1038 current_frame.pop_stack( 1039 VerificationType.integer_type); 1040 // fall through 1041 case IFEQ: 1042 case IFNE: 1043 case IFLT: 1044 case IFGE: 1045 case IFGT: 1046 case IFLE: 1047 current_frame.pop_stack( 1048 VerificationType.integer_type); 1049 target = bcs.dest(); 1050 stackmap_table.check_jump_target( 1051 current_frame, target); 1052 no_control_flow = false; break; 1053 case IF_ACMPEQ : 1054 case IF_ACMPNE : 1055 current_frame.pop_stack( 1056 VerificationType.reference_check); 1057 // fall through 1058 case IFNULL : 1059 case IFNONNULL : 1060 current_frame.pop_stack( 1061 VerificationType.reference_check); 1062 target = bcs.dest(); 1063 stackmap_table.check_jump_target 1064 (current_frame, target); 1065 no_control_flow = false; break; 1066 case GOTO : 1067 target = bcs.dest(); 1068 stackmap_table.check_jump_target( 1069 current_frame, target); 1070 no_control_flow = true; break; 1071 case GOTO_W : 1072 target = bcs.destW(); 1073 stackmap_table.check_jump_target( 1074 current_frame, target); 1075 no_control_flow = true; break; 1076 case TABLESWITCH : 1077 case LOOKUPSWITCH : 1078 verify_switch( 1079 bcs, code_length, code_data, current_frame, 1080 stackmap_table); 1081 no_control_flow = true; break; 1082 case IRETURN : 1083 type = current_frame.pop_stack( 1084 VerificationType.integer_type); 1085 verify_return_value(return_type, type, bci, 1086 current_frame); 1087 no_control_flow = true; break; 1088 case LRETURN : 1089 type2 = current_frame.pop_stack( 1090 VerificationType.long2_type); 1091 type = current_frame.pop_stack( 1092 VerificationType.long_type); 1093 verify_return_value(return_type, type, bci, 1094 current_frame); 1095 no_control_flow = true; break; 1096 case FRETURN : 1097 type = current_frame.pop_stack( 1098 VerificationType.float_type); 1099 verify_return_value(return_type, type, bci, 1100 current_frame); 1101 no_control_flow = true; break; 1102 case DRETURN : 1103 type2 = current_frame.pop_stack( 1104 VerificationType.double2_type); 1105 type = current_frame.pop_stack( 1106 VerificationType.double_type); 1107 verify_return_value(return_type, type, bci, 1108 current_frame); 1109 no_control_flow = true; break; 1110 case ARETURN : 1111 type = current_frame.pop_stack( 1112 VerificationType.reference_check); 1113 verify_return_value(return_type, type, bci, 1114 current_frame); 1115 no_control_flow = true; break; 1116 case RETURN: 1117 if (!return_type.is_bogus()) { 1118 verifyError("Method expects a return value"); 1119 } 1120 if (object_initializer_name.equals(_method.name()) && 1121 current_frame.flag_this_uninit()) { 1122 verifyError("Constructor must call super() or this() before return"); 1123 } 1124 no_control_flow = true; break; 1125 case GETSTATIC : 1126 case PUTSTATIC : 1127 verify_field_instructions(bcs, current_frame, cp, true); 1128 no_control_flow = false; break; 1129 case GETFIELD : 1130 case PUTFIELD : 1131 verify_field_instructions(bcs, current_frame, cp, false); 1132 no_control_flow = false; break; 1133 case INVOKEVIRTUAL : 1134 case INVOKESPECIAL : 1135 case INVOKESTATIC : 1136 this_uninit = verify_invoke_instructions(bcs, code_length, current_frame, (bci >= ex_minmax[0] && bci < ex_minmax[1]), this_uninit, return_type, cp, stackmap_table); 1137 no_control_flow = false; break; 1138 case INVOKEINTERFACE : 1139 case INVOKEDYNAMIC : 1140 this_uninit = verify_invoke_instructions(bcs, code_length, current_frame, (bci >= ex_minmax[0] && bci < ex_minmax[1]), this_uninit, return_type, cp, stackmap_table); 1141 no_control_flow = false; break; 1142 case NEW : 1143 { 1144 index = bcs.getIndexU2(); 1145 verify_cp_class_type(bci, index, cp); 1146 VerificationType new_class_type = 1147 cp_index_to_type(index, cp); 1148 if (!new_class_type.is_object()) { 1149 verifyError("Illegal new instruction"); 1150 } 1151 type = VerificationType.uninitialized_type(bci); 1152 current_frame.push_stack(type); 1153 no_control_flow = false; break; 1154 } 1155 case NEWARRAY : 1156 type = get_newarray_type(bcs.getIndex(), bci); 1157 current_frame.pop_stack( 1158 VerificationType.integer_type); 1159 current_frame.push_stack(type); 1160 no_control_flow = false; break; 1161 case ANEWARRAY : 1162 verify_anewarray(bci, bcs.getIndexU2(), cp, current_frame); 1163 no_control_flow = false; break; 1164 case ARRAYLENGTH : 1165 type = current_frame.pop_stack( 1166 VerificationType.reference_check); 1167 if (!(type.is_null() || type.is_array())) { 1168 verifyError("Bad type"); 1169 } 1170 current_frame.push_stack( 1171 VerificationType.integer_type); 1172 no_control_flow = false; break; 1173 case CHECKCAST : 1174 { 1175 index = bcs.getIndexU2(); 1176 verify_cp_class_type(bci, index, cp); 1177 current_frame.pop_stack(object_type()); 1178 VerificationType klass_type = cp_index_to_type( 1179 index, cp); 1180 current_frame.push_stack(klass_type); 1181 no_control_flow = false; break; 1182 } 1183 case INSTANCEOF : { 1184 index = bcs.getIndexU2(); 1185 verify_cp_class_type(bci, index, cp); 1186 current_frame.pop_stack(object_type()); 1187 current_frame.push_stack( 1188 VerificationType.integer_type); 1189 no_control_flow = false; break; 1190 } 1191 case MONITORENTER : 1192 case MONITOREXIT : 1193 current_frame.pop_stack( 1194 VerificationType.reference_check); 1195 no_control_flow = false; break; 1196 case MULTIANEWARRAY : 1197 { 1198 index = bcs.getIndexU2(); 1199 int dim = _method.codeArray()[bcs.bci() +3] & 0xff; 1200 verify_cp_class_type(bci, index, cp); 1201 VerificationType new_array_type = 1202 cp_index_to_type(index, cp); 1203 if (!new_array_type.is_array()) { 1204 verifyError("Illegal constant pool index in multianewarray instruction"); 1205 } 1206 if (dim < 1 || new_array_type.dimensions(this) < dim) { 1207 verifyError(String.format("Illegal dimension in multianewarray instruction: %d", dim)); 1208 } 1209 for (int i = 0; i < dim; i++) { 1210 current_frame.pop_stack( 1211 VerificationType.integer_type); 1212 } 1213 current_frame.push_stack(new_array_type); 1214 no_control_flow = false; break; 1215 } 1216 case ATHROW : 1217 type = VerificationType.reference_type(java_lang_Throwable); 1218 current_frame.pop_stack(type); 1219 no_control_flow = true; break; 1220 default: 1221 verifyError(String.format("Bad instruction: %02x", opcode)); 1222 } 1223 } 1224 if (verified_exc_handlers && this_uninit) verifyError("Exception handler targets got verified before this_uninit got set"); 1225 if (!verified_exc_handlers && bci >= ex_minmax[0] && bci < ex_minmax[1]) { 1226 verify_exception_handler_targets(bci, this_uninit, current_frame, stackmap_table); 1227 } 1228 } 1229 if (!no_control_flow) { 1230 verifyError("Control flow falls through code end"); 1231 } 1232 } 1233 1234 private byte[] generate_code_data(RawBytecodeHelper.CodeRange code) { 1235 byte[] code_data = new byte[code.length()]; 1236 var bcs = code.start(); 1237 while (bcs.next()) { 1238 if (bcs.opcode() != ILLEGAL) { 1239 int bci = bcs.bci(); 1240 if (bcs.opcode() == NEW) { 1241 code_data[bci] = NEW_OFFSET; 1242 } else { 1243 code_data[bci] = BYTECODE_OFFSET; 1244 } 1245 } else { 1246 verifyError("Bad instruction"); 1247 } 1248 } 1249 return code_data; 1250 } 1251 1252 void verify_exception_handler_table(int code_length, byte[] code_data, int[] minmax) { 1253 var cp = _method.constantPool(); 1254 for (var exhandler : _method.exceptionTable()) { 1255 int start_pc = exhandler[0]; 1256 int end_pc = exhandler[1]; 1257 int handler_pc = exhandler[2]; 1258 if (start_pc >= code_length || code_data[start_pc] == 0) { 1259 classError(String.format("Illegal exception table start_pc %d", start_pc)); 1260 } 1261 if (end_pc != code_length) { 1262 if (end_pc > code_length || code_data[end_pc] == 0) { 1263 classError(String.format("Illegal exception table end_pc %d", end_pc)); 1264 } 1265 } 1266 if (handler_pc >= code_length || code_data[handler_pc] == 0) { 1267 classError(String.format("Illegal exception table handler_pc %d", handler_pc)); 1268 } 1269 int catch_type_index = exhandler[3]; 1270 if (catch_type_index != 0) { 1271 VerificationType catch_type = cp_index_to_type(catch_type_index, cp); 1272 VerificationType throwable = VerificationType.reference_type(java_lang_Throwable); 1273 boolean is_subclass = throwable.is_assignable_from(catch_type, this); 1274 if (!is_subclass) { 1275 verifyError(String.format("Catch type is not a subclass of Throwable in exception handler %d", handler_pc)); 1276 } 1277 } 1278 if (start_pc < minmax[0]) minmax[0] = start_pc; 1279 if (end_pc > minmax[1]) minmax[1] = end_pc; 1280 } 1281 } 1282 1283 void verify_local_variable_table(int code_length, byte[] code_data) { 1284 for (var lvte : _method.localVariableTable()) { 1285 int start_bci = lvte.startPc(); 1286 int length = lvte.length(); 1287 if (start_bci >= code_length || code_data[start_bci] == 0) { 1288 classError(String.format("Illegal local variable table start_pc %d", start_bci)); 1289 } 1290 int end_bci = start_bci + length; 1291 if (end_bci != code_length) { 1292 if (end_bci >= code_length || code_data[end_bci] == 0) { 1293 classError(String.format("Illegal local variable table length %d", length)); 1294 } 1295 } 1296 } 1297 } 1298 1299 int verify_stackmap_table(int stackmap_index, int bci, VerificationFrame current_frame, VerificationTable stackmap_table, boolean no_control_flow) { 1300 if (stackmap_index < stackmap_table.get_frame_count()) { 1301 int this_offset = stackmap_table.get_offset(stackmap_index); 1302 if (no_control_flow && this_offset > bci) { 1303 verifyError("Expecting a stack map frame"); 1304 } 1305 if (this_offset == bci) { 1306 boolean matches = stackmap_table.match_stackmap(current_frame, this_offset, stackmap_index, !no_control_flow, true); 1307 if (!matches) { 1308 verifyError("Instruction type does not match stack map"); 1309 } 1310 stackmap_index++; 1311 } else if (this_offset < bci) { 1312 classError(String.format("Bad stack map offset %d", this_offset)); 1313 } 1314 } else if (no_control_flow) { 1315 verifyError("Expecting a stack map frame"); 1316 } 1317 return stackmap_index; 1318 } 1319 1320 void verify_exception_handler_targets(int bci, boolean this_uninit, VerificationFrame current_frame, VerificationTable stackmap_table) { 1321 var cp = _method.constantPool(); 1322 for(var exhandler : _method.exceptionTable()) { 1323 int start_pc = exhandler[0]; 1324 int end_pc = exhandler[1]; 1325 int handler_pc = exhandler[2]; 1326 int catch_type_index = exhandler[3]; 1327 if(bci >= start_pc && bci < end_pc) { 1328 int flags = current_frame.flags(); 1329 if (this_uninit) { flags |= FLAG_THIS_UNINIT; } 1330 VerificationFrame new_frame = current_frame.frame_in_exception_handler(flags); 1331 if (catch_type_index != 0) { 1332 VerificationType catch_type = cp_index_to_type(catch_type_index, cp); 1333 new_frame.push_stack(catch_type); 1334 } else { 1335 VerificationType throwable = VerificationType.reference_type(java_lang_Throwable); 1336 new_frame.push_stack(throwable); 1337 } 1338 boolean matches = stackmap_table.match_stackmap(new_frame, handler_pc, true, false); 1339 if (!matches) { 1340 verifyError(String.format("Stack map does not match the one at exception handler %d", handler_pc)); 1341 } 1342 } 1343 } 1344 } 1345 1346 void verify_cp_index(int bci, ConstantPoolWrapper cp, int index) { 1347 int nconstants = cp.entryCount(); 1348 if ((index <= 0) || (index >= nconstants)) { 1349 verifyError(String.format("Illegal constant pool index %d", index)); 1350 } 1351 } 1352 1353 void verify_cp_type(int bci, int index, ConstantPoolWrapper cp, int types) { 1354 verify_cp_index(bci, cp, index); 1355 int tag = cp.tagAt(index); 1356 if ((types & (1 << tag))== 0) { 1357 verifyError(String.format("Illegal type at constant pool entry %d", index)); 1358 } 1359 } 1360 1361 void verify_cp_class_type(int bci, int index, ConstantPoolWrapper cp) { 1362 verify_cp_index(bci, cp, index); 1363 int tag = cp.tagAt(index); 1364 if (tag != JVM_CONSTANT_Class) { 1365 verifyError(String.format("Illegal type at constant pool entry %d", index)); 1366 } 1367 } 1368 1369 void verify_ldc(int opcode, int index, VerificationFrame current_frame, ConstantPoolWrapper cp, int bci) { 1370 verify_cp_index(bci, cp, index); 1371 int tag = cp.tagAt(index); 1372 int types = 0; 1373 if (opcode == LDC || opcode == LDC_W) { 1374 types = (1 << JVM_CONSTANT_Integer) | (1 << JVM_CONSTANT_Float) 1375 | (1 << JVM_CONSTANT_String) | (1 << JVM_CONSTANT_Class) 1376 | (1 << JVM_CONSTANT_MethodHandle) | (1 << JVM_CONSTANT_MethodType) 1377 | (1 << JVM_CONSTANT_Dynamic); 1378 verify_cp_type(bci, index, cp, types); 1379 } else { 1380 if (opcode != LDC2_W) verifyError("must be ldc2_w"); 1381 types = (1 << JVM_CONSTANT_Double) | (1 << JVM_CONSTANT_Long) | (1 << JVM_CONSTANT_Dynamic); 1382 verify_cp_type(bci, index, cp, types); 1383 } 1384 switch (tag) { 1385 case JVM_CONSTANT_Utf8 -> current_frame.push_stack(object_type()); 1386 case JVM_CONSTANT_String -> current_frame.push_stack(VerificationType.reference_type(java_lang_String)); 1387 case JVM_CONSTANT_Class -> current_frame.push_stack(VerificationType.reference_type(java_lang_Class)); 1388 case JVM_CONSTANT_Integer -> current_frame.push_stack(VerificationType.integer_type); 1389 case JVM_CONSTANT_Float -> current_frame.push_stack(VerificationType.float_type); 1390 case JVM_CONSTANT_Double -> current_frame.push_stack_2(VerificationType.double_type, VerificationType.double2_type); 1391 case JVM_CONSTANT_Long -> current_frame.push_stack_2(VerificationType.long_type, VerificationType.long2_type); 1392 case JVM_CONSTANT_MethodHandle -> current_frame.push_stack(VerificationType.reference_type(java_lang_invoke_MethodHandle)); 1393 case JVM_CONSTANT_MethodType -> current_frame.push_stack(VerificationType.reference_type(java_lang_invoke_MethodType)); 1394 case JVM_CONSTANT_Dynamic -> { 1395 String constant_type = cp.dynamicConstantSignatureAt(index); 1396 if (!VerificationSignature.isValidTypeSignature(constant_type)) verifyError("Invalid type for dynamic constant"); 1397 VerificationType[] v_constant_type = new VerificationType[2]; 1398 var sig_stream = new VerificationSignature(constant_type, false, this); 1399 int n = change_sig_to_verificationType(sig_stream, v_constant_type, 0); 1400 int opcode_n = (opcode == LDC2_W ? 2 : 1); 1401 if (n != opcode_n) { 1402 types &= ~(1 << JVM_CONSTANT_Dynamic); 1403 verify_cp_type(bci, index, cp, types); 1404 } 1405 for (int i = 0; i < n; i++) { 1406 current_frame.push_stack(v_constant_type[i]); 1407 } 1408 } 1409 default -> verifyError("Invalid index in ldc"); 1410 } 1411 } 1412 1413 void verify_switch(RawBytecodeHelper bcs, int code_length, byte[] code_data, VerificationFrame current_frame, VerificationTable stackmap_table) { 1414 int bci = bcs.bci(); 1415 int aligned_bci = VerificationBytecodes.align(bci + 1); 1416 // 4639449 & 4647081: padding bytes must be 0 1417 if (_klass.majorVersion() < NONZERO_PADDING_BYTES_IN_SWITCH_MAJOR_VERSION) { 1418 int padding_offset = 1; 1419 while ((bci + padding_offset) < aligned_bci) { 1420 if (_method.codeArray()[bci + padding_offset] != 0) { 1421 verifyError("Nonzero padding byte in lookupswitch or tableswitch"); 1422 } 1423 padding_offset++; 1424 } 1425 } 1426 int default_offset = bcs.getIntUnchecked(aligned_bci); 1427 int keys, delta; 1428 current_frame.pop_stack(VerificationType.integer_type); 1429 if (bcs.opcode() == TABLESWITCH) { 1430 int low = bcs.getIntUnchecked(aligned_bci + 4); 1431 int high = bcs.getIntUnchecked(aligned_bci + 2*4); 1432 if (low > high) { 1433 verifyError("low must be less than or equal to high in tableswitch"); 1434 } 1435 keys = high - low + 1; 1436 if (keys < 0) { 1437 verifyError("too many keys in tableswitch"); 1438 } 1439 delta = 1; 1440 } else { 1441 // Make sure that the lookupswitch items are sorted 1442 keys = bcs.getIntUnchecked(aligned_bci + 4); 1443 if (keys < 0) { 1444 verifyError("number of keys in lookupswitch less than 0"); 1445 } 1446 delta = 2; 1447 for (int i = 0; i < (keys - 1); i++) { 1448 int this_key = bcs.getIntUnchecked(aligned_bci + (2+2*i)*4); 1449 int next_key = bcs.getIntUnchecked(aligned_bci + (2+2*i+2)*4); 1450 if (this_key >= next_key) { 1451 verifyError("Bad lookupswitch instruction"); 1452 } 1453 } 1454 } 1455 int target = bci + default_offset; 1456 stackmap_table.check_jump_target(current_frame, target); 1457 for (int i = 0; i < keys; i++) { 1458 aligned_bci = VerificationBytecodes.align(bcs.bci() + 1); 1459 target = bci + bcs.getIntUnchecked(aligned_bci + (3+i*delta)*4); 1460 stackmap_table.check_jump_target(current_frame, target); 1461 } 1462 } 1463 1464 void verify_field_instructions(RawBytecodeHelper bcs, VerificationFrame current_frame, ConstantPoolWrapper cp, boolean allow_arrays) { 1465 int index = bcs.getIndexU2(); 1466 verify_cp_type(bcs.bci(), index, cp, 1 << JVM_CONSTANT_Fieldref); 1467 String field_name = cp.refNameAt(index); 1468 String field_sig = cp.refSignatureAt(index); 1469 if (!VerificationSignature.isValidTypeSignature(field_sig)) verifyError("Invalid field signature"); 1470 VerificationType ref_class_type = cp_ref_index_to_type(index, cp); 1471 if (!ref_class_type.is_object() && 1472 (!allow_arrays || !ref_class_type.is_array())) { 1473 verifyError(String.format("Expecting reference to class in class %s at constant pool index %d", _klass.thisClassName(), index)); 1474 } 1475 VerificationType target_class_type = ref_class_type; 1476 VerificationType[] field_type = new VerificationType[2]; 1477 var sig_stream = new VerificationSignature(field_sig, false, this); 1478 VerificationType stack_object_type = null; 1479 int n = change_sig_to_verificationType(sig_stream, field_type, 0); 1480 boolean is_assignable; 1481 switch (bcs.opcode()) { 1482 case GETSTATIC -> { 1483 for (int i = 0; i < n; i++) { 1484 current_frame.push_stack(field_type[i]); 1485 } 1486 } 1487 case PUTSTATIC -> { 1488 for (int i = n - 1; i >= 0; i--) { 1489 current_frame.pop_stack(field_type[i]); 1490 } 1491 } 1492 case GETFIELD -> { 1493 stack_object_type = current_frame.pop_stack( 1494 target_class_type); 1495 for (int i = 0; i < n; i++) { 1496 current_frame.push_stack(field_type[i]); 1497 } 1498 } 1499 case PUTFIELD -> { 1500 for (int i = n - 1; i >= 0; i--) { 1501 current_frame.pop_stack(field_type[i]); 1502 } 1503 stack_object_type = current_frame.pop_stack(); 1504 if (stack_object_type.is_uninitialized_this(this) && 1505 target_class_type.equals(current_type()) && 1506 _klass.findField(field_name, field_sig)) { 1507 stack_object_type = current_type(); 1508 } 1509 is_assignable = target_class_type.is_assignable_from(stack_object_type, this); 1510 if (!is_assignable) { 1511 verifyError("Bad type on operand stack in putfield"); 1512 } 1513 } 1514 default -> verifyError("Should not reach here"); 1515 } 1516 } 1517 1518 // Return TRUE if all code paths starting with start_bc_offset end in 1519 // bytecode athrow or loop. 1520 boolean ends_in_athrow(int start_bc_offset) { 1521 log_info("unimplemented VerifierImpl.ends_in_athrow"); 1522 return true; 1523 } 1524 1525 boolean verify_invoke_init(RawBytecodeHelper bcs, int ref_class_index, VerificationType ref_class_type, 1526 VerificationFrame current_frame, int code_length, boolean in_try_block, 1527 boolean this_uninit, ConstantPoolWrapper cp, VerificationTable stackmap_table) { 1528 int bci = bcs.bci(); 1529 VerificationType type = current_frame.pop_stack(VerificationType.reference_check); 1530 if (type.is_uninitialized_this(this)) { 1531 String superk_name = current_class().superclassName(); 1532 if (!current_class().thisClassName().equals(ref_class_type.name()) && 1533 !superk_name.equals(ref_class_type.name())) { 1534 verifyError("Bad <init> method call"); 1535 } 1536 if (in_try_block) { 1537 for(var exhandler : _method.exceptionTable()) { 1538 int start_pc = exhandler[0]; 1539 int end_pc = exhandler[1]; 1540 1541 if (bci >= start_pc && bci < end_pc) { 1542 if (!ends_in_athrow(exhandler[2])) { 1543 verifyError("Bad <init> method call from after the start of a try block"); 1544 } 1545 } 1546 } 1547 verify_exception_handler_targets(bci, true, current_frame, stackmap_table); 1548 } 1549 current_frame.initialize_object(type, current_type()); 1550 this_uninit = true; 1551 } else if (type.is_uninitialized()) { 1552 int new_offset = type.bci(this); 1553 if (new_offset > (code_length - 3) || (_method.codeArray()[new_offset] & 0xff) != NEW) { 1554 verifyError("Expecting new instruction"); 1555 } 1556 int new_class_index = bcs.getU2(new_offset + 1); 1557 verify_cp_class_type(bci, new_class_index, cp); 1558 VerificationType new_class_type = cp_index_to_type( 1559 new_class_index, cp); 1560 if (!new_class_type.equals(ref_class_type)) { 1561 verifyError("Call to wrong <init> method"); 1562 } 1563 if (in_try_block) { 1564 verify_exception_handler_targets(bci, this_uninit, current_frame, 1565 stackmap_table); 1566 } 1567 current_frame.initialize_object(type, new_class_type); 1568 } else { 1569 verifyError("Bad operand type when invoking <init>"); 1570 } 1571 return this_uninit; 1572 } 1573 1574 static boolean is_same_or_direct_interface(VerificationWrapper klass, VerificationType klass_type, VerificationType ref_class_type) { 1575 if (ref_class_type.equals(klass_type)) return true; 1576 for (String k_name : klass.interfaceNames()) { 1577 if (ref_class_type.equals(VerificationType.reference_type(k_name))) { 1578 return true; 1579 } 1580 } 1581 return false; 1582 } 1583 1584 boolean verify_invoke_instructions(RawBytecodeHelper bcs, int code_length, VerificationFrame current_frame, boolean in_try_block, boolean this_uninit, VerificationType return_type, ConstantPoolWrapper cp, VerificationTable stackmap_table) { 1585 // Make sure the constant pool item is the right type 1586 int index = bcs.getIndexU2(); 1587 int opcode = bcs.opcode(); 1588 int types = 0; 1589 switch (opcode) { 1590 case INVOKEINTERFACE: 1591 types = 1 << JVM_CONSTANT_InterfaceMethodref; 1592 break; 1593 case INVOKEDYNAMIC: 1594 types = 1 << JVM_CONSTANT_InvokeDynamic; 1595 break; 1596 case INVOKESPECIAL: 1597 case INVOKESTATIC: 1598 types = (_klass.majorVersion() < STATIC_METHOD_IN_INTERFACE_MAJOR_VERSION) ? 1599 (1 << JVM_CONSTANT_Methodref) : 1600 ((1 << JVM_CONSTANT_InterfaceMethodref) | (1 << JVM_CONSTANT_Methodref)); 1601 break; 1602 default: 1603 types = 1 << JVM_CONSTANT_Methodref; 1604 } 1605 verify_cp_type(bcs.bci(), index, cp, types); 1606 String method_name = cp.refNameAt(index); 1607 String method_sig = cp.refSignatureAt(index); 1608 if (!VerificationSignature.isValidMethodSignature(method_sig)) verifyError("Invalid method signature"); 1609 VerificationType ref_class_type = null; 1610 if (opcode == INVOKEDYNAMIC) { 1611 if (_klass.majorVersion() < INVOKEDYNAMIC_MAJOR_VERSION) { 1612 classError(String.format("invokedynamic instructions not supported by this class file version (%d), class %s", _klass.majorVersion(), _klass.thisClassName())); 1613 } 1614 } else { 1615 ref_class_type = cp_ref_index_to_type(index, cp); 1616 } 1617 String sig = cp.refSignatureAt(index); 1618 sig_as_verification_types mth_sig_verif_types; 1619 ArrayList<VerificationType> verif_types = new ArrayList<>(10); 1620 mth_sig_verif_types = new sig_as_verification_types(verif_types); 1621 create_method_sig_entry(mth_sig_verif_types, sig); 1622 int nargs = mth_sig_verif_types.num_args(); 1623 int bci = bcs.bci(); 1624 if (opcode == INVOKEINTERFACE) { 1625 if ((_method.codeArray()[bci+3] & 0xff) != (nargs+1)) { 1626 verifyError("Inconsistent args count operand in invokeinterface"); 1627 } 1628 if ((_method.codeArray()[bci+4] & 0xff) != 0) { 1629 verifyError("Fourth operand byte of invokeinterface must be zero"); 1630 } 1631 } 1632 if (opcode == INVOKEDYNAMIC) { 1633 if ((_method.codeArray()[bci+3] & 0xff) != 0 || (_method.codeArray()[bci+4] & 0xff) != 0) { 1634 verifyError("Third and fourth operand bytes of invokedynamic must be zero"); 1635 } 1636 } 1637 if (method_name.charAt(0) == JVM_SIGNATURE_SPECIAL) { 1638 if (opcode != INVOKESPECIAL || 1639 !object_initializer_name.equals(method_name)) { 1640 verifyError("Illegal call to internal method"); 1641 } 1642 } else if (opcode == INVOKESPECIAL 1643 && !is_same_or_direct_interface(current_class(), current_type(), ref_class_type) 1644 && !ref_class_type.equals(VerificationType.reference_type( 1645 current_class().superclassName()))) { 1646 boolean have_imr_indirect = cp.tagAt(index) == JVM_CONSTANT_InterfaceMethodref; 1647 boolean subtype = ref_class_type.is_assignable_from(current_type(), this); 1648 if (!subtype) { 1649 verifyError("Bad invokespecial instruction: current class isn't assignable to reference class."); 1650 } else if (have_imr_indirect) { 1651 verifyError("Bad invokespecial instruction: interface method reference is in an indirect superinterface."); 1652 } 1653 1654 } 1655 ArrayList<VerificationType> sig_verif_types = mth_sig_verif_types.sig_verif_types(); 1656 if (sig_verif_types == null) verifyError("Missing signature's array of verification types"); 1657 for (int i = nargs - 1; i >= 0; i--) { // Run backwards 1658 current_frame.pop_stack(sig_verif_types.get(i)); 1659 } 1660 if (opcode != INVOKESTATIC && 1661 opcode != INVOKEDYNAMIC) { 1662 if (object_initializer_name.equals(method_name)) { // <init> method 1663 this_uninit = verify_invoke_init(bcs, index, ref_class_type, current_frame, 1664 code_length, in_try_block, this_uninit, cp, stackmap_table); 1665 } else { 1666 switch (opcode) { 1667 case INVOKESPECIAL -> 1668 current_frame.pop_stack(current_type()); 1669 case INVOKEVIRTUAL -> { 1670 VerificationType stack_object_type = 1671 current_frame.pop_stack(ref_class_type); 1672 if (current_type() != stack_object_type) { 1673 cp.classNameAt(cp.refClassIndexAt(index)); 1674 } 1675 } 1676 default -> { 1677 if (opcode != INVOKEINTERFACE) 1678 verifyError("Unexpected opcode encountered"); 1679 current_frame.pop_stack(ref_class_type); 1680 } 1681 } 1682 } 1683 } 1684 int sig_verif_types_len = sig_verif_types.size(); 1685 if (sig_verif_types_len > nargs) { // There's a return type 1686 if (object_initializer_name.equals(method_name)) { 1687 verifyError("Return type must be void in <init> method"); 1688 } 1689 1690 if (sig_verif_types_len > nargs + 2) verifyError("Signature verification types array return type is bogus"); 1691 for (int i = nargs; i < sig_verif_types_len; i++) { 1692 if (!(i == nargs || sig_verif_types.get(i).is_long2() || sig_verif_types.get(i).is_double2())) verifyError("Unexpected return verificationType"); 1693 current_frame.push_stack(sig_verif_types.get(i)); 1694 } 1695 } 1696 return this_uninit; 1697 } 1698 1699 VerificationType get_newarray_type(int index, int bci) { 1700 String[] from_bt = new String[] { 1701 null, null, null, null, "[Z", "[C", "[F", "[D", "[B", "[S", "[I", "[J", 1702 }; 1703 if (index < T_BOOLEAN.type || index > T_LONG.type) { 1704 verifyError("Illegal newarray instruction"); 1705 } 1706 String sig = from_bt[index]; 1707 return VerificationType.reference_type(sig); 1708 } 1709 1710 void verify_anewarray(int bci, int index, ConstantPoolWrapper cp, VerificationFrame current_frame) { 1711 verify_cp_class_type(bci, index, cp); 1712 current_frame.pop_stack(VerificationType.integer_type); 1713 VerificationType component_type = cp_index_to_type(index, cp); 1714 int length; 1715 String arr_sig_str; 1716 if (component_type.is_array()) { // it's an array 1717 String component_name = component_type.name(); 1718 length = component_name.length(); 1719 if (length > MAX_ARRAY_DIMENSIONS && 1720 component_name.charAt(MAX_ARRAY_DIMENSIONS - 1) == JVM_SIGNATURE_ARRAY) { 1721 verifyError("Illegal anewarray instruction, array has more than 255 dimensions"); 1722 } 1723 length++; 1724 arr_sig_str = String.format("%c%s", JVM_SIGNATURE_ARRAY, component_name); 1725 if (arr_sig_str.length() != length) verifyError("Unexpected number of characters in string"); 1726 } else { // it's an object or interface 1727 String component_name = component_type.name(); 1728 length = component_name.length() + 3; 1729 arr_sig_str = String.format("%c%c%s;", JVM_SIGNATURE_ARRAY, JVM_SIGNATURE_CLASS, component_name); 1730 if (arr_sig_str.length() != length) verifyError("Unexpected number of characters in string"); 1731 } 1732 VerificationType new_array_type = VerificationType.reference_type(arr_sig_str); 1733 current_frame.push_stack(new_array_type); 1734 } 1735 1736 void verify_iload(int index, VerificationFrame current_frame) { 1737 current_frame.get_local( 1738 index, VerificationType.integer_type); 1739 current_frame.push_stack( 1740 VerificationType.integer_type); 1741 } 1742 1743 void verify_lload(int index, VerificationFrame current_frame) { 1744 current_frame.get_local_2( 1745 index, VerificationType.long_type, 1746 VerificationType.long2_type); 1747 current_frame.push_stack_2( 1748 VerificationType.long_type, 1749 VerificationType.long2_type); 1750 } 1751 1752 void verify_fload(int index, VerificationFrame current_frame) { 1753 current_frame.get_local( 1754 index, VerificationType.float_type); 1755 current_frame.push_stack( 1756 VerificationType.float_type); 1757 } 1758 1759 void verify_dload(int index, VerificationFrame current_frame) { 1760 current_frame.get_local_2( 1761 index, VerificationType.double_type, 1762 VerificationType.double2_type); 1763 current_frame.push_stack_2( 1764 VerificationType.double_type, 1765 VerificationType.double2_type); 1766 } 1767 1768 void verify_aload(int index, VerificationFrame current_frame) { 1769 VerificationType type = current_frame.get_local( 1770 index, VerificationType.reference_check); 1771 current_frame.push_stack(type); 1772 } 1773 1774 void verify_istore(int index, VerificationFrame current_frame) { 1775 current_frame.pop_stack( 1776 VerificationType.integer_type); 1777 current_frame.set_local( 1778 index, VerificationType.integer_type); 1779 } 1780 1781 void verify_lstore(int index, VerificationFrame current_frame) { 1782 current_frame.pop_stack_2( 1783 VerificationType.long2_type, 1784 VerificationType.long_type); 1785 current_frame.set_local_2( 1786 index, VerificationType.long_type, 1787 VerificationType.long2_type); 1788 } 1789 1790 void verify_fstore(int index, VerificationFrame current_frame) { 1791 current_frame.pop_stack( 1792 VerificationType.float_type); 1793 current_frame.set_local( 1794 index, VerificationType.float_type); 1795 } 1796 1797 void verify_dstore(int index, VerificationFrame current_frame) { 1798 current_frame.pop_stack_2( 1799 VerificationType.double2_type, 1800 VerificationType.double_type); 1801 current_frame.set_local_2( 1802 index, VerificationType.double_type, 1803 VerificationType.double2_type); 1804 } 1805 1806 void verify_astore(int index, VerificationFrame current_frame) { 1807 VerificationType type = current_frame.pop_stack( 1808 VerificationType.reference_check); 1809 current_frame.set_local(index, type); 1810 } 1811 1812 void verify_iinc(int index, VerificationFrame current_frame) { 1813 VerificationType type = current_frame.get_local( 1814 index, VerificationType.integer_type); 1815 current_frame.set_local(index, type); 1816 } 1817 1818 void verify_return_value(VerificationType return_type, VerificationType type, int bci, VerificationFrame current_frame) { 1819 if (return_type.is_bogus()) { 1820 verifyError("Method expects a return value"); 1821 } 1822 boolean match = return_type.is_assignable_from(type, this); 1823 if (!match) { 1824 verifyError("Bad return type"); 1825 } 1826 } 1827 1828 private void dumpMethod() { 1829 if (_logger != null) ClassPrinter.toTree(_method.m, ClassPrinter.Verbosity.CRITICAL_ATTRIBUTES).toYaml(_logger); 1830 } 1831 1832 void verifyError(String msg) { 1833 dumpMethod(); 1834 throw new VerifyError(String.format("%s in %s::%s(%s) @%d %s", msg, _klass.thisClassName(), _method.name(), _method.parameters(), bci, errorContext).trim()); 1835 } 1836 1837 void verifyError(String msg, VerificationFrame from, VerificationFrame target) { 1838 dumpMethod(); 1839 throw new VerifyError(String.format("%s in %s::%s(%s) @%d %s%n while assigning %s%n to %s", msg, _klass.thisClassName(), _method.name(), _method.parameters(), bci, errorContext, from, target)); 1840 } 1841 1842 void classError(String msg) { 1843 dumpMethod(); 1844 throw new VerifyError(String.format("%s in %s::%s(%s)", msg, _klass.thisClassName(), _method.name(), _method.parameters())); 1845 } 1846 }