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(object_type()); 1056 // fall through 1057 case IFNULL : 1058 case IFNONNULL : 1059 current_frame.pop_stack(object_type()); 1060 target = bcs.dest(); 1061 stackmap_table.check_jump_target 1062 (current_frame, target); 1063 no_control_flow = false; break; 1064 case GOTO : 1065 target = bcs.dest(); 1066 stackmap_table.check_jump_target( 1067 current_frame, target); 1068 no_control_flow = true; break; 1069 case GOTO_W : 1070 target = bcs.destW(); 1071 stackmap_table.check_jump_target( 1072 current_frame, target); 1073 no_control_flow = true; break; 1074 case TABLESWITCH : 1075 case LOOKUPSWITCH : 1076 verify_switch( 1077 bcs, code_length, code_data, current_frame, 1078 stackmap_table); 1079 no_control_flow = true; break; 1080 case IRETURN : 1081 type = current_frame.pop_stack( 1082 VerificationType.integer_type); 1083 verify_return_value(return_type, type, bci, 1084 current_frame); 1085 no_control_flow = true; break; 1086 case LRETURN : 1087 type2 = current_frame.pop_stack( 1088 VerificationType.long2_type); 1089 type = current_frame.pop_stack( 1090 VerificationType.long_type); 1091 verify_return_value(return_type, type, bci, 1092 current_frame); 1093 no_control_flow = true; break; 1094 case FRETURN : 1095 type = current_frame.pop_stack( 1096 VerificationType.float_type); 1097 verify_return_value(return_type, type, bci, 1098 current_frame); 1099 no_control_flow = true; break; 1100 case DRETURN : 1101 type2 = current_frame.pop_stack( 1102 VerificationType.double2_type); 1103 type = current_frame.pop_stack( 1104 VerificationType.double_type); 1105 verify_return_value(return_type, type, bci, 1106 current_frame); 1107 no_control_flow = true; break; 1108 case ARETURN : 1109 type = current_frame.pop_stack( 1110 VerificationType.reference_check); 1111 verify_return_value(return_type, type, bci, 1112 current_frame); 1113 no_control_flow = true; break; 1114 case RETURN: 1115 if (!return_type.is_bogus()) { 1116 verifyError("Method expects a return value"); 1117 } 1118 if (object_initializer_name.equals(_method.name()) && 1119 current_frame.flag_this_uninit()) { 1120 verifyError("Constructor must call super() or this() before return"); 1121 } 1122 no_control_flow = true; break; 1123 case GETSTATIC : 1124 case PUTSTATIC : 1125 verify_field_instructions(bcs, current_frame, cp, true); 1126 no_control_flow = false; break; 1127 case GETFIELD : 1128 case PUTFIELD : 1129 verify_field_instructions(bcs, current_frame, cp, false); 1130 no_control_flow = false; break; 1131 case INVOKEVIRTUAL : 1132 case INVOKESPECIAL : 1133 case INVOKESTATIC : 1134 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); 1135 no_control_flow = false; break; 1136 case INVOKEINTERFACE : 1137 case INVOKEDYNAMIC : 1138 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); 1139 no_control_flow = false; break; 1140 case NEW : 1141 { 1142 index = bcs.getIndexU2(); 1143 verify_cp_class_type(bci, index, cp); 1144 VerificationType new_class_type = 1145 cp_index_to_type(index, cp); 1146 if (!new_class_type.is_object()) { 1147 verifyError("Illegal new instruction"); 1148 } 1149 type = VerificationType.uninitialized_type(bci); 1150 current_frame.push_stack(type); 1151 no_control_flow = false; break; 1152 } 1153 case NEWARRAY : 1154 type = get_newarray_type(bcs.getIndex(), bci); 1155 current_frame.pop_stack( 1156 VerificationType.integer_type); 1157 current_frame.push_stack(type); 1158 no_control_flow = false; break; 1159 case ANEWARRAY : 1160 verify_anewarray(bci, bcs.getIndexU2(), cp, current_frame); 1161 no_control_flow = false; break; 1162 case ARRAYLENGTH : 1163 type = current_frame.pop_stack( 1164 VerificationType.reference_check); 1165 if (!(type.is_null() || type.is_array())) { 1166 verifyError("Bad type"); 1167 } 1168 current_frame.push_stack( 1169 VerificationType.integer_type); 1170 no_control_flow = false; break; 1171 case CHECKCAST : 1172 { 1173 index = bcs.getIndexU2(); 1174 verify_cp_class_type(bci, index, cp); 1175 current_frame.pop_stack(object_type()); 1176 VerificationType klass_type = cp_index_to_type( 1177 index, cp); 1178 current_frame.push_stack(klass_type); 1179 no_control_flow = false; break; 1180 } 1181 case INSTANCEOF : { 1182 index = bcs.getIndexU2(); 1183 verify_cp_class_type(bci, index, cp); 1184 current_frame.pop_stack(object_type()); 1185 current_frame.push_stack( 1186 VerificationType.integer_type); 1187 no_control_flow = false; break; 1188 } 1189 case MONITORENTER : 1190 case MONITOREXIT : 1191 current_frame.pop_stack( 1192 VerificationType.reference_check); 1193 no_control_flow = false; break; 1194 case MULTIANEWARRAY : 1195 { 1196 index = bcs.getIndexU2(); 1197 int dim = _method.codeArray()[bcs.bci() +3] & 0xff; 1198 verify_cp_class_type(bci, index, cp); 1199 VerificationType new_array_type = 1200 cp_index_to_type(index, cp); 1201 if (!new_array_type.is_array()) { 1202 verifyError("Illegal constant pool index in multianewarray instruction"); 1203 } 1204 if (dim < 1 || new_array_type.dimensions(this) < dim) { 1205 verifyError(String.format("Illegal dimension in multianewarray instruction: %d", dim)); 1206 } 1207 for (int i = 0; i < dim; i++) { 1208 current_frame.pop_stack( 1209 VerificationType.integer_type); 1210 } 1211 current_frame.push_stack(new_array_type); 1212 no_control_flow = false; break; 1213 } 1214 case ATHROW : 1215 type = VerificationType.reference_type(java_lang_Throwable); 1216 current_frame.pop_stack(type); 1217 no_control_flow = true; break; 1218 default: 1219 verifyError(String.format("Bad instruction: %02x", opcode)); 1220 } 1221 } 1222 if (verified_exc_handlers && this_uninit) verifyError("Exception handler targets got verified before this_uninit got set"); 1223 if (!verified_exc_handlers && bci >= ex_minmax[0] && bci < ex_minmax[1]) { 1224 verify_exception_handler_targets(bci, this_uninit, current_frame, stackmap_table); 1225 } 1226 } 1227 if (!no_control_flow) { 1228 verifyError("Control flow falls through code end"); 1229 } 1230 } 1231 1232 private byte[] generate_code_data(RawBytecodeHelper.CodeRange code) { 1233 byte[] code_data = new byte[code.length()]; 1234 var bcs = code.start(); 1235 while (bcs.next()) { 1236 if (bcs.opcode() != ILLEGAL) { 1237 int bci = bcs.bci(); 1238 if (bcs.opcode() == NEW) { 1239 code_data[bci] = NEW_OFFSET; 1240 } else { 1241 code_data[bci] = BYTECODE_OFFSET; 1242 } 1243 } else { 1244 verifyError("Bad instruction"); 1245 } 1246 } 1247 return code_data; 1248 } 1249 1250 void verify_exception_handler_table(int code_length, byte[] code_data, int[] minmax) { 1251 var cp = _method.constantPool(); 1252 for (var exhandler : _method.exceptionTable()) { 1253 int start_pc = exhandler[0]; 1254 int end_pc = exhandler[1]; 1255 int handler_pc = exhandler[2]; 1256 if (start_pc >= code_length || code_data[start_pc] == 0) { 1257 classError(String.format("Illegal exception table start_pc %d", start_pc)); 1258 } 1259 if (end_pc != code_length) { 1260 if (end_pc > code_length || code_data[end_pc] == 0) { 1261 classError(String.format("Illegal exception table end_pc %d", end_pc)); 1262 } 1263 } 1264 if (handler_pc >= code_length || code_data[handler_pc] == 0) { 1265 classError(String.format("Illegal exception table handler_pc %d", handler_pc)); 1266 } 1267 int catch_type_index = exhandler[3]; 1268 if (catch_type_index != 0) { 1269 VerificationType catch_type = cp_index_to_type(catch_type_index, cp); 1270 VerificationType throwable = VerificationType.reference_type(java_lang_Throwable); 1271 boolean is_subclass = throwable.is_assignable_from(catch_type, this); 1272 if (!is_subclass) { 1273 verifyError(String.format("Catch type is not a subclass of Throwable in exception handler %d", handler_pc)); 1274 } 1275 } 1276 if (start_pc < minmax[0]) minmax[0] = start_pc; 1277 if (end_pc > minmax[1]) minmax[1] = end_pc; 1278 } 1279 } 1280 1281 void verify_local_variable_table(int code_length, byte[] code_data) { 1282 for (var lvte : _method.localVariableTable()) { 1283 int start_bci = lvte.startPc(); 1284 int length = lvte.length(); 1285 if (start_bci >= code_length || code_data[start_bci] == 0) { 1286 classError(String.format("Illegal local variable table start_pc %d", start_bci)); 1287 } 1288 int end_bci = start_bci + length; 1289 if (end_bci != code_length) { 1290 if (end_bci >= code_length || code_data[end_bci] == 0) { 1291 classError(String.format("Illegal local variable table length %d", length)); 1292 } 1293 } 1294 } 1295 } 1296 1297 int verify_stackmap_table(int stackmap_index, int bci, VerificationFrame current_frame, VerificationTable stackmap_table, boolean no_control_flow) { 1298 if (stackmap_index < stackmap_table.get_frame_count()) { 1299 int this_offset = stackmap_table.get_offset(stackmap_index); 1300 if (no_control_flow && this_offset > bci) { 1301 verifyError("Expecting a stack map frame"); 1302 } 1303 if (this_offset == bci) { 1304 boolean matches = stackmap_table.match_stackmap(current_frame, this_offset, stackmap_index, !no_control_flow, true); 1305 if (!matches) { 1306 verifyError("Instruction type does not match stack map"); 1307 } 1308 stackmap_index++; 1309 } else if (this_offset < bci) { 1310 classError(String.format("Bad stack map offset %d", this_offset)); 1311 } 1312 } else if (no_control_flow) { 1313 verifyError("Expecting a stack map frame"); 1314 } 1315 return stackmap_index; 1316 } 1317 1318 void verify_exception_handler_targets(int bci, boolean this_uninit, VerificationFrame current_frame, VerificationTable stackmap_table) { 1319 var cp = _method.constantPool(); 1320 for(var exhandler : _method.exceptionTable()) { 1321 int start_pc = exhandler[0]; 1322 int end_pc = exhandler[1]; 1323 int handler_pc = exhandler[2]; 1324 int catch_type_index = exhandler[3]; 1325 if(bci >= start_pc && bci < end_pc) { 1326 int flags = current_frame.flags(); 1327 if (this_uninit) { flags |= FLAG_THIS_UNINIT; } 1328 VerificationFrame new_frame = current_frame.frame_in_exception_handler(flags); 1329 if (catch_type_index != 0) { 1330 VerificationType catch_type = cp_index_to_type(catch_type_index, cp); 1331 new_frame.push_stack(catch_type); 1332 } else { 1333 VerificationType throwable = VerificationType.reference_type(java_lang_Throwable); 1334 new_frame.push_stack(throwable); 1335 } 1336 boolean matches = stackmap_table.match_stackmap(new_frame, handler_pc, true, false); 1337 if (!matches) { 1338 verifyError(String.format("Stack map does not match the one at exception handler %d", handler_pc)); 1339 } 1340 } 1341 } 1342 } 1343 1344 void verify_cp_index(int bci, ConstantPoolWrapper cp, int index) { 1345 int nconstants = cp.entryCount(); 1346 if ((index <= 0) || (index >= nconstants)) { 1347 verifyError(String.format("Illegal constant pool index %d", index)); 1348 } 1349 } 1350 1351 void verify_cp_type(int bci, int index, ConstantPoolWrapper cp, int types) { 1352 verify_cp_index(bci, cp, index); 1353 int tag = cp.tagAt(index); 1354 if ((types & (1 << tag))== 0) { 1355 verifyError(String.format("Illegal type at constant pool entry %d", index)); 1356 } 1357 } 1358 1359 void verify_cp_class_type(int bci, int index, ConstantPoolWrapper cp) { 1360 verify_cp_index(bci, cp, index); 1361 int tag = cp.tagAt(index); 1362 if (tag != JVM_CONSTANT_Class) { 1363 verifyError(String.format("Illegal type at constant pool entry %d", index)); 1364 } 1365 } 1366 1367 void verify_ldc(int opcode, int index, VerificationFrame current_frame, ConstantPoolWrapper cp, int bci) { 1368 verify_cp_index(bci, cp, index); 1369 int tag = cp.tagAt(index); 1370 int types = 0; 1371 if (opcode == LDC || opcode == LDC_W) { 1372 types = (1 << JVM_CONSTANT_Integer) | (1 << JVM_CONSTANT_Float) 1373 | (1 << JVM_CONSTANT_String) | (1 << JVM_CONSTANT_Class) 1374 | (1 << JVM_CONSTANT_MethodHandle) | (1 << JVM_CONSTANT_MethodType) 1375 | (1 << JVM_CONSTANT_Dynamic); 1376 verify_cp_type(bci, index, cp, types); 1377 } else { 1378 if (opcode != LDC2_W) verifyError("must be ldc2_w"); 1379 types = (1 << JVM_CONSTANT_Double) | (1 << JVM_CONSTANT_Long) | (1 << JVM_CONSTANT_Dynamic); 1380 verify_cp_type(bci, index, cp, types); 1381 } 1382 switch (tag) { 1383 case JVM_CONSTANT_Utf8 -> current_frame.push_stack(object_type()); 1384 case JVM_CONSTANT_String -> current_frame.push_stack(VerificationType.reference_type(java_lang_String)); 1385 case JVM_CONSTANT_Class -> current_frame.push_stack(VerificationType.reference_type(java_lang_Class)); 1386 case JVM_CONSTANT_Integer -> current_frame.push_stack(VerificationType.integer_type); 1387 case JVM_CONSTANT_Float -> current_frame.push_stack(VerificationType.float_type); 1388 case JVM_CONSTANT_Double -> current_frame.push_stack_2(VerificationType.double_type, VerificationType.double2_type); 1389 case JVM_CONSTANT_Long -> current_frame.push_stack_2(VerificationType.long_type, VerificationType.long2_type); 1390 case JVM_CONSTANT_MethodHandle -> current_frame.push_stack(VerificationType.reference_type(java_lang_invoke_MethodHandle)); 1391 case JVM_CONSTANT_MethodType -> current_frame.push_stack(VerificationType.reference_type(java_lang_invoke_MethodType)); 1392 case JVM_CONSTANT_Dynamic -> { 1393 String constant_type = cp.dynamicConstantSignatureAt(index); 1394 if (!VerificationSignature.isValidTypeSignature(constant_type)) verifyError("Invalid type for dynamic constant"); 1395 VerificationType[] v_constant_type = new VerificationType[2]; 1396 var sig_stream = new VerificationSignature(constant_type, false, this); 1397 int n = change_sig_to_verificationType(sig_stream, v_constant_type, 0); 1398 int opcode_n = (opcode == LDC2_W ? 2 : 1); 1399 if (n != opcode_n) { 1400 types &= ~(1 << JVM_CONSTANT_Dynamic); 1401 verify_cp_type(bci, index, cp, types); 1402 } 1403 for (int i = 0; i < n; i++) { 1404 current_frame.push_stack(v_constant_type[i]); 1405 } 1406 } 1407 default -> verifyError("Invalid index in ldc"); 1408 } 1409 } 1410 1411 void verify_switch(RawBytecodeHelper bcs, int code_length, byte[] code_data, VerificationFrame current_frame, VerificationTable stackmap_table) { 1412 int bci = bcs.bci(); 1413 int aligned_bci = VerificationBytecodes.align(bci + 1); 1414 // 4639449 & 4647081: padding bytes must be 0 1415 if (_klass.majorVersion() < NONZERO_PADDING_BYTES_IN_SWITCH_MAJOR_VERSION) { 1416 int padding_offset = 1; 1417 while ((bci + padding_offset) < aligned_bci) { 1418 if (_method.codeArray()[bci + padding_offset] != 0) { 1419 verifyError("Nonzero padding byte in lookupswitch or tableswitch"); 1420 } 1421 padding_offset++; 1422 } 1423 } 1424 int default_offset = bcs.getIntUnchecked(aligned_bci); 1425 int keys, delta; 1426 current_frame.pop_stack(VerificationType.integer_type); 1427 if (bcs.opcode() == TABLESWITCH) { 1428 int low = bcs.getIntUnchecked(aligned_bci + 4); 1429 int high = bcs.getIntUnchecked(aligned_bci + 2*4); 1430 if (low > high) { 1431 verifyError("low must be less than or equal to high in tableswitch"); 1432 } 1433 keys = high - low + 1; 1434 if (keys < 0) { 1435 verifyError("too many keys in tableswitch"); 1436 } 1437 delta = 1; 1438 } else { 1439 // Make sure that the lookupswitch items are sorted 1440 keys = bcs.getIntUnchecked(aligned_bci + 4); 1441 if (keys < 0) { 1442 verifyError("number of keys in lookupswitch less than 0"); 1443 } 1444 delta = 2; 1445 for (int i = 0; i < (keys - 1); i++) { 1446 int this_key = bcs.getIntUnchecked(aligned_bci + (2+2*i)*4); 1447 int next_key = bcs.getIntUnchecked(aligned_bci + (2+2*i+2)*4); 1448 if (this_key >= next_key) { 1449 verifyError("Bad lookupswitch instruction"); 1450 } 1451 } 1452 } 1453 int target = bci + default_offset; 1454 stackmap_table.check_jump_target(current_frame, target); 1455 for (int i = 0; i < keys; i++) { 1456 aligned_bci = VerificationBytecodes.align(bcs.bci() + 1); 1457 target = bci + bcs.getIntUnchecked(aligned_bci + (3+i*delta)*4); 1458 stackmap_table.check_jump_target(current_frame, target); 1459 } 1460 } 1461 1462 void verify_field_instructions(RawBytecodeHelper bcs, VerificationFrame current_frame, ConstantPoolWrapper cp, boolean allow_arrays) { 1463 int index = bcs.getIndexU2(); 1464 verify_cp_type(bcs.bci(), index, cp, 1 << JVM_CONSTANT_Fieldref); 1465 String field_name = cp.refNameAt(index); 1466 String field_sig = cp.refSignatureAt(index); 1467 if (!VerificationSignature.isValidTypeSignature(field_sig)) verifyError("Invalid field signature"); 1468 VerificationType ref_class_type = cp_ref_index_to_type(index, cp); 1469 if (!ref_class_type.is_object() && 1470 (!allow_arrays || !ref_class_type.is_array())) { 1471 verifyError(String.format("Expecting reference to class in class %s at constant pool index %d", _klass.thisClassName(), index)); 1472 } 1473 VerificationType target_class_type = ref_class_type; 1474 VerificationType[] field_type = new VerificationType[2]; 1475 var sig_stream = new VerificationSignature(field_sig, false, this); 1476 VerificationType stack_object_type = null; 1477 int n = change_sig_to_verificationType(sig_stream, field_type, 0); 1478 boolean is_assignable; 1479 switch (bcs.opcode()) { 1480 case GETSTATIC -> { 1481 for (int i = 0; i < n; i++) { 1482 current_frame.push_stack(field_type[i]); 1483 } 1484 } 1485 case PUTSTATIC -> { 1486 for (int i = n - 1; i >= 0; i--) { 1487 current_frame.pop_stack(field_type[i]); 1488 } 1489 } 1490 case GETFIELD -> { 1491 stack_object_type = current_frame.pop_stack( 1492 target_class_type); 1493 for (int i = 0; i < n; i++) { 1494 current_frame.push_stack(field_type[i]); 1495 } 1496 } 1497 case PUTFIELD -> { 1498 for (int i = n - 1; i >= 0; i--) { 1499 current_frame.pop_stack(field_type[i]); 1500 } 1501 stack_object_type = current_frame.pop_stack(); 1502 if (stack_object_type.is_uninitialized_this(this) && 1503 target_class_type.equals(current_type()) && 1504 _klass.findField(field_name, field_sig)) { 1505 stack_object_type = current_type(); 1506 } 1507 is_assignable = target_class_type.is_assignable_from(stack_object_type, this); 1508 if (!is_assignable) { 1509 verifyError("Bad type on operand stack in putfield"); 1510 } 1511 } 1512 default -> verifyError("Should not reach here"); 1513 } 1514 } 1515 1516 // Return TRUE if all code paths starting with start_bc_offset end in 1517 // bytecode athrow or loop. 1518 boolean ends_in_athrow(int start_bc_offset) { 1519 log_info("unimplemented VerifierImpl.ends_in_athrow"); 1520 return true; 1521 } 1522 1523 boolean verify_invoke_init(RawBytecodeHelper bcs, int ref_class_index, VerificationType ref_class_type, 1524 VerificationFrame current_frame, int code_length, boolean in_try_block, 1525 boolean this_uninit, ConstantPoolWrapper cp, VerificationTable stackmap_table) { 1526 int bci = bcs.bci(); 1527 VerificationType type = current_frame.pop_stack(VerificationType.reference_check); 1528 if (type.is_uninitialized_this(this)) { 1529 String superk_name = current_class().superclassName(); 1530 if (!current_class().thisClassName().equals(ref_class_type.name()) && 1531 !superk_name.equals(ref_class_type.name())) { 1532 verifyError("Bad <init> method call"); 1533 } 1534 if (in_try_block) { 1535 for(var exhandler : _method.exceptionTable()) { 1536 int start_pc = exhandler[0]; 1537 int end_pc = exhandler[1]; 1538 1539 if (bci >= start_pc && bci < end_pc) { 1540 if (!ends_in_athrow(exhandler[2])) { 1541 verifyError("Bad <init> method call from after the start of a try block"); 1542 } 1543 } 1544 } 1545 verify_exception_handler_targets(bci, true, current_frame, stackmap_table); 1546 } 1547 current_frame.initialize_object(type, current_type()); 1548 this_uninit = true; 1549 } else if (type.is_uninitialized()) { 1550 int new_offset = type.bci(this); 1551 if (new_offset > (code_length - 3) || (_method.codeArray()[new_offset] & 0xff) != NEW) { 1552 verifyError("Expecting new instruction"); 1553 } 1554 int new_class_index = bcs.getU2(new_offset + 1); 1555 verify_cp_class_type(bci, new_class_index, cp); 1556 VerificationType new_class_type = cp_index_to_type( 1557 new_class_index, cp); 1558 if (!new_class_type.equals(ref_class_type)) { 1559 verifyError("Call to wrong <init> method"); 1560 } 1561 if (in_try_block) { 1562 verify_exception_handler_targets(bci, this_uninit, current_frame, 1563 stackmap_table); 1564 } 1565 current_frame.initialize_object(type, new_class_type); 1566 } else { 1567 verifyError("Bad operand type when invoking <init>"); 1568 } 1569 return this_uninit; 1570 } 1571 1572 static boolean is_same_or_direct_interface(VerificationWrapper klass, VerificationType klass_type, VerificationType ref_class_type) { 1573 if (ref_class_type.equals(klass_type)) return true; 1574 for (String k_name : klass.interfaceNames()) { 1575 if (ref_class_type.equals(VerificationType.reference_type(k_name))) { 1576 return true; 1577 } 1578 } 1579 return false; 1580 } 1581 1582 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) { 1583 // Make sure the constant pool item is the right type 1584 int index = bcs.getIndexU2(); 1585 int opcode = bcs.opcode(); 1586 int types = 0; 1587 switch (opcode) { 1588 case INVOKEINTERFACE: 1589 types = 1 << JVM_CONSTANT_InterfaceMethodref; 1590 break; 1591 case INVOKEDYNAMIC: 1592 types = 1 << JVM_CONSTANT_InvokeDynamic; 1593 break; 1594 case INVOKESPECIAL: 1595 case INVOKESTATIC: 1596 types = (_klass.majorVersion() < STATIC_METHOD_IN_INTERFACE_MAJOR_VERSION) ? 1597 (1 << JVM_CONSTANT_Methodref) : 1598 ((1 << JVM_CONSTANT_InterfaceMethodref) | (1 << JVM_CONSTANT_Methodref)); 1599 break; 1600 default: 1601 types = 1 << JVM_CONSTANT_Methodref; 1602 } 1603 verify_cp_type(bcs.bci(), index, cp, types); 1604 String method_name = cp.refNameAt(index); 1605 String method_sig = cp.refSignatureAt(index); 1606 if (!VerificationSignature.isValidMethodSignature(method_sig)) verifyError("Invalid method signature"); 1607 VerificationType ref_class_type = null; 1608 if (opcode == INVOKEDYNAMIC) { 1609 if (_klass.majorVersion() < INVOKEDYNAMIC_MAJOR_VERSION) { 1610 classError(String.format("invokedynamic instructions not supported by this class file version (%d), class %s", _klass.majorVersion(), _klass.thisClassName())); 1611 } 1612 } else { 1613 ref_class_type = cp_ref_index_to_type(index, cp); 1614 } 1615 String sig = cp.refSignatureAt(index); 1616 sig_as_verification_types mth_sig_verif_types; 1617 ArrayList<VerificationType> verif_types = new ArrayList<>(10); 1618 mth_sig_verif_types = new sig_as_verification_types(verif_types); 1619 create_method_sig_entry(mth_sig_verif_types, sig); 1620 int nargs = mth_sig_verif_types.num_args(); 1621 int bci = bcs.bci(); 1622 if (opcode == INVOKEINTERFACE) { 1623 if ((_method.codeArray()[bci+3] & 0xff) != (nargs+1)) { 1624 verifyError("Inconsistent args count operand in invokeinterface"); 1625 } 1626 if ((_method.codeArray()[bci+4] & 0xff) != 0) { 1627 verifyError("Fourth operand byte of invokeinterface must be zero"); 1628 } 1629 } 1630 if (opcode == INVOKEDYNAMIC) { 1631 if ((_method.codeArray()[bci+3] & 0xff) != 0 || (_method.codeArray()[bci+4] & 0xff) != 0) { 1632 verifyError("Third and fourth operand bytes of invokedynamic must be zero"); 1633 } 1634 } 1635 if (method_name.charAt(0) == JVM_SIGNATURE_SPECIAL) { 1636 if (opcode != INVOKESPECIAL || 1637 !object_initializer_name.equals(method_name)) { 1638 verifyError("Illegal call to internal method"); 1639 } 1640 } else if (opcode == INVOKESPECIAL 1641 && !is_same_or_direct_interface(current_class(), current_type(), ref_class_type) 1642 && !ref_class_type.equals(VerificationType.reference_type( 1643 current_class().superclassName()))) { 1644 boolean have_imr_indirect = cp.tagAt(index) == JVM_CONSTANT_InterfaceMethodref; 1645 boolean subtype = ref_class_type.is_assignable_from(current_type(), this); 1646 if (!subtype) { 1647 verifyError("Bad invokespecial instruction: current class isn't assignable to reference class."); 1648 } else if (have_imr_indirect) { 1649 verifyError("Bad invokespecial instruction: interface method reference is in an indirect superinterface."); 1650 } 1651 1652 } 1653 ArrayList<VerificationType> sig_verif_types = mth_sig_verif_types.sig_verif_types(); 1654 if (sig_verif_types == null) verifyError("Missing signature's array of verification types"); 1655 for (int i = nargs - 1; i >= 0; i--) { // Run backwards 1656 current_frame.pop_stack(sig_verif_types.get(i)); 1657 } 1658 if (opcode != INVOKESTATIC && 1659 opcode != INVOKEDYNAMIC) { 1660 if (object_initializer_name.equals(method_name)) { // <init> method 1661 this_uninit = verify_invoke_init(bcs, index, ref_class_type, current_frame, 1662 code_length, in_try_block, this_uninit, cp, stackmap_table); 1663 } else { 1664 switch (opcode) { 1665 case INVOKESPECIAL -> 1666 current_frame.pop_stack(current_type()); 1667 case INVOKEVIRTUAL -> { 1668 VerificationType stack_object_type = 1669 current_frame.pop_stack(ref_class_type); 1670 if (current_type() != stack_object_type) { 1671 cp.classNameAt(cp.refClassIndexAt(index)); 1672 } 1673 } 1674 default -> { 1675 if (opcode != INVOKEINTERFACE) 1676 verifyError("Unexpected opcode encountered"); 1677 current_frame.pop_stack(ref_class_type); 1678 } 1679 } 1680 } 1681 } 1682 int sig_verif_types_len = sig_verif_types.size(); 1683 if (sig_verif_types_len > nargs) { // There's a return type 1684 if (object_initializer_name.equals(method_name)) { 1685 verifyError("Return type must be void in <init> method"); 1686 } 1687 1688 if (sig_verif_types_len > nargs + 2) verifyError("Signature verification types array return type is bogus"); 1689 for (int i = nargs; i < sig_verif_types_len; i++) { 1690 if (!(i == nargs || sig_verif_types.get(i).is_long2() || sig_verif_types.get(i).is_double2())) verifyError("Unexpected return verificationType"); 1691 current_frame.push_stack(sig_verif_types.get(i)); 1692 } 1693 } 1694 return this_uninit; 1695 } 1696 1697 VerificationType get_newarray_type(int index, int bci) { 1698 String[] from_bt = new String[] { 1699 null, null, null, null, "[Z", "[C", "[F", "[D", "[B", "[S", "[I", "[J", 1700 }; 1701 if (index < T_BOOLEAN.type || index > T_LONG.type) { 1702 verifyError("Illegal newarray instruction"); 1703 } 1704 String sig = from_bt[index]; 1705 return VerificationType.reference_type(sig); 1706 } 1707 1708 void verify_anewarray(int bci, int index, ConstantPoolWrapper cp, VerificationFrame current_frame) { 1709 verify_cp_class_type(bci, index, cp); 1710 current_frame.pop_stack(VerificationType.integer_type); 1711 VerificationType component_type = cp_index_to_type(index, cp); 1712 int length; 1713 String arr_sig_str; 1714 if (component_type.is_array()) { // it's an array 1715 String component_name = component_type.name(); 1716 length = component_name.length(); 1717 if (length > MAX_ARRAY_DIMENSIONS && 1718 component_name.charAt(MAX_ARRAY_DIMENSIONS - 1) == JVM_SIGNATURE_ARRAY) { 1719 verifyError("Illegal anewarray instruction, array has more than 255 dimensions"); 1720 } 1721 length++; 1722 arr_sig_str = String.format("%c%s", JVM_SIGNATURE_ARRAY, component_name); 1723 if (arr_sig_str.length() != length) verifyError("Unexpected number of characters in string"); 1724 } else { // it's an object or interface 1725 String component_name = component_type.name(); 1726 length = component_name.length() + 3; 1727 arr_sig_str = String.format("%c%c%s;", JVM_SIGNATURE_ARRAY, JVM_SIGNATURE_CLASS, component_name); 1728 if (arr_sig_str.length() != length) verifyError("Unexpected number of characters in string"); 1729 } 1730 VerificationType new_array_type = VerificationType.reference_type(arr_sig_str); 1731 current_frame.push_stack(new_array_type); 1732 } 1733 1734 void verify_iload(int index, VerificationFrame current_frame) { 1735 current_frame.get_local( 1736 index, VerificationType.integer_type); 1737 current_frame.push_stack( 1738 VerificationType.integer_type); 1739 } 1740 1741 void verify_lload(int index, VerificationFrame current_frame) { 1742 current_frame.get_local_2( 1743 index, VerificationType.long_type, 1744 VerificationType.long2_type); 1745 current_frame.push_stack_2( 1746 VerificationType.long_type, 1747 VerificationType.long2_type); 1748 } 1749 1750 void verify_fload(int index, VerificationFrame current_frame) { 1751 current_frame.get_local( 1752 index, VerificationType.float_type); 1753 current_frame.push_stack( 1754 VerificationType.float_type); 1755 } 1756 1757 void verify_dload(int index, VerificationFrame current_frame) { 1758 current_frame.get_local_2( 1759 index, VerificationType.double_type, 1760 VerificationType.double2_type); 1761 current_frame.push_stack_2( 1762 VerificationType.double_type, 1763 VerificationType.double2_type); 1764 } 1765 1766 void verify_aload(int index, VerificationFrame current_frame) { 1767 VerificationType type = current_frame.get_local( 1768 index, VerificationType.reference_check); 1769 current_frame.push_stack(type); 1770 } 1771 1772 void verify_istore(int index, VerificationFrame current_frame) { 1773 current_frame.pop_stack( 1774 VerificationType.integer_type); 1775 current_frame.set_local( 1776 index, VerificationType.integer_type); 1777 } 1778 1779 void verify_lstore(int index, VerificationFrame current_frame) { 1780 current_frame.pop_stack_2( 1781 VerificationType.long2_type, 1782 VerificationType.long_type); 1783 current_frame.set_local_2( 1784 index, VerificationType.long_type, 1785 VerificationType.long2_type); 1786 } 1787 1788 void verify_fstore(int index, VerificationFrame current_frame) { 1789 current_frame.pop_stack( 1790 VerificationType.float_type); 1791 current_frame.set_local( 1792 index, VerificationType.float_type); 1793 } 1794 1795 void verify_dstore(int index, VerificationFrame current_frame) { 1796 current_frame.pop_stack_2( 1797 VerificationType.double2_type, 1798 VerificationType.double_type); 1799 current_frame.set_local_2( 1800 index, VerificationType.double_type, 1801 VerificationType.double2_type); 1802 } 1803 1804 void verify_astore(int index, VerificationFrame current_frame) { 1805 VerificationType type = current_frame.pop_stack( 1806 VerificationType.reference_check); 1807 current_frame.set_local(index, type); 1808 } 1809 1810 void verify_iinc(int index, VerificationFrame current_frame) { 1811 VerificationType type = current_frame.get_local( 1812 index, VerificationType.integer_type); 1813 current_frame.set_local(index, type); 1814 } 1815 1816 void verify_return_value(VerificationType return_type, VerificationType type, int bci, VerificationFrame current_frame) { 1817 if (return_type.is_bogus()) { 1818 verifyError("Method expects a return value"); 1819 } 1820 boolean match = return_type.is_assignable_from(type, this); 1821 if (!match) { 1822 verifyError("Bad return type"); 1823 } 1824 } 1825 1826 private void dumpMethod() { 1827 if (_logger != null) ClassPrinter.toTree(_method.m, ClassPrinter.Verbosity.CRITICAL_ATTRIBUTES).toYaml(_logger); 1828 } 1829 1830 void verifyError(String msg) { 1831 dumpMethod(); 1832 throw new VerifyError(String.format("%s in %s::%s(%s) @%d %s", msg, _klass.thisClassName(), _method.name(), _method.parameters(), bci, errorContext).trim()); 1833 } 1834 1835 void verifyError(String msg, VerificationFrame from, VerificationFrame target) { 1836 dumpMethod(); 1837 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)); 1838 } 1839 1840 void classError(String msg) { 1841 dumpMethod(); 1842 throw new VerifyError(String.format("%s in %s::%s(%s)", msg, _klass.thisClassName(), _method.name(), _method.parameters())); 1843 } 1844 }