1 /* 2 * Copyright (c) 1998, 2017, 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. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "precompiled.hpp" 26 #include "jvm.h" 27 #include "classfile/classFileStream.hpp" 28 #include "classfile/javaClasses.hpp" 29 #include "classfile/stackMapTable.hpp" 30 #include "classfile/stackMapFrame.hpp" 31 #include "classfile/stackMapTableFormat.hpp" 32 #include "classfile/systemDictionary.hpp" 33 #include "classfile/verifier.hpp" 34 #include "classfile/vmSymbols.hpp" 35 #include "interpreter/bytecodes.hpp" 36 #include "interpreter/bytecodeStream.hpp" 37 #include "logging/log.hpp" 38 #include "logging/logStream.hpp" 39 #include "memory/oopFactory.hpp" 40 #include "memory/resourceArea.hpp" 41 #include "oops/instanceKlass.hpp" 42 #include "oops/oop.inline.hpp" 43 #include "oops/typeArrayOop.hpp" 44 #include "runtime/fieldDescriptor.hpp" 45 #include "runtime/handles.inline.hpp" 46 #include "runtime/interfaceSupport.hpp" 47 #include "runtime/javaCalls.hpp" 48 #include "runtime/orderAccess.inline.hpp" 49 #include "runtime/os.hpp" 50 #include "runtime/thread.hpp" 51 #include "services/threadService.hpp" 52 #include "utilities/align.hpp" 53 #include "utilities/bytes.hpp" 54 55 #define NOFAILOVER_MAJOR_VERSION 51 56 #define NONZERO_PADDING_BYTES_IN_SWITCH_MAJOR_VERSION 51 57 #define STATIC_METHOD_IN_INTERFACE_MAJOR_VERSION 52 58 #define MAX_ARRAY_DIMENSIONS 255 59 60 // Access to external entry for VerifyClassCodes - old byte code verifier 61 62 extern "C" { 63 typedef jboolean (*verify_byte_codes_fn_t)(JNIEnv *, jclass, char *, jint); 64 typedef jboolean (*verify_byte_codes_fn_new_t)(JNIEnv *, jclass, char *, jint, jint); 65 } 66 67 static void* volatile _verify_byte_codes_fn = NULL; 68 69 static volatile jint _is_new_verify_byte_codes_fn = (jint) true; 70 71 static void* verify_byte_codes_fn() { 72 if (OrderAccess::load_acquire(&_verify_byte_codes_fn) == NULL) { 73 void *lib_handle = os::native_java_library(); 74 void *func = os::dll_lookup(lib_handle, "VerifyClassCodesForMajorVersion"); 75 OrderAccess::release_store(&_verify_byte_codes_fn, func); 76 if (func == NULL) { 77 _is_new_verify_byte_codes_fn = false; 78 func = os::dll_lookup(lib_handle, "VerifyClassCodes"); 79 OrderAccess::release_store(&_verify_byte_codes_fn, func); 80 } 81 } 82 return (void*)_verify_byte_codes_fn; 83 } 84 85 86 // Methods in Verifier 87 88 bool Verifier::should_verify_for(oop class_loader, bool should_verify_class) { 89 return (class_loader == NULL || !should_verify_class) ? 90 BytecodeVerificationLocal : BytecodeVerificationRemote; 91 } 92 93 bool Verifier::relax_access_for(oop loader) { 94 bool trusted = java_lang_ClassLoader::is_trusted_loader(loader); 95 bool need_verify = 96 // verifyAll 97 (BytecodeVerificationLocal && BytecodeVerificationRemote) || 98 // verifyRemote 99 (!BytecodeVerificationLocal && BytecodeVerificationRemote && !trusted); 100 return !need_verify; 101 } 102 103 void Verifier::trace_class_resolution(Klass* resolve_class, InstanceKlass* verify_class) { 104 assert(verify_class != NULL, "Unexpected null verify_class"); 105 ResourceMark rm; 106 Symbol* s = verify_class->source_file_name(); 107 const char* source_file = (s != NULL ? s->as_C_string() : NULL); 108 const char* verify = verify_class->external_name(); 109 const char* resolve = resolve_class->external_name(); 110 // print in a single call to reduce interleaving between threads 111 if (source_file != NULL) { 112 log_debug(class, resolve)("%s %s %s (verification)", verify, resolve, source_file); 113 } else { 114 log_debug(class, resolve)("%s %s (verification)", verify, resolve); 115 } 116 } 117 118 // Prints the end-verification message to the appropriate output. 119 void Verifier::log_end_verification(outputStream* st, const char* klassName, Symbol* exception_name, TRAPS) { 120 if (HAS_PENDING_EXCEPTION) { 121 st->print("Verification for %s has", klassName); 122 st->print_cr(" exception pending %s ", 123 PENDING_EXCEPTION->klass()->external_name()); 124 } else if (exception_name != NULL) { 125 st->print_cr("Verification for %s failed", klassName); 126 } 127 st->print_cr("End class verification for: %s", klassName); 128 } 129 130 bool Verifier::verify(InstanceKlass* klass, Verifier::Mode mode, bool should_verify_class, TRAPS) { 131 HandleMark hm(THREAD); 132 ResourceMark rm(THREAD); 133 134 // Eagerly allocate the identity hash code for a klass. This is a fallout 135 // from 6320749 and 8059924: hash code generator is not supposed to be called 136 // during the safepoint, but it allows to sneak the hashcode in during 137 // verification. Without this eager hashcode generation, we may end up 138 // installing the hashcode during some other operation, which may be at 139 // safepoint -- blowing up the checks. It was previously done as the side 140 // effect (sic!) for external_name(), but instead of doing that, we opt to 141 // explicitly push the hashcode in here. This is signify the following block 142 // is IMPORTANT: 143 if (klass->java_mirror() != NULL) { 144 klass->java_mirror()->identity_hash(); 145 } 146 147 if (!is_eligible_for_verification(klass, should_verify_class)) { 148 return true; 149 } 150 151 // Timer includes any side effects of class verification (resolution, 152 // etc), but not recursive calls to Verifier::verify(). 153 JavaThread* jt = (JavaThread*)THREAD; 154 PerfClassTraceTime timer(ClassLoader::perf_class_verify_time(), 155 ClassLoader::perf_class_verify_selftime(), 156 ClassLoader::perf_classes_verified(), 157 jt->get_thread_stat()->perf_recursion_counts_addr(), 158 jt->get_thread_stat()->perf_timers_addr(), 159 PerfClassTraceTime::CLASS_VERIFY); 160 161 // If the class should be verified, first see if we can use the split 162 // verifier. If not, or if verification fails and FailOverToOldVerifier 163 // is set, then call the inference verifier. 164 165 Symbol* exception_name = NULL; 166 const size_t message_buffer_len = klass->name()->utf8_length() + 1024; 167 char* message_buffer = NEW_RESOURCE_ARRAY(char, message_buffer_len); 168 char* exception_message = message_buffer; 169 170 const char* klassName = klass->external_name(); 171 bool can_failover = FailOverToOldVerifier && 172 klass->major_version() < NOFAILOVER_MAJOR_VERSION; 173 174 log_info(class, init)("Start class verification for: %s", klassName); 175 if (klass->major_version() >= STACKMAP_ATTRIBUTE_MAJOR_VERSION) { 176 ClassVerifier split_verifier(klass, THREAD); 177 split_verifier.verify_class(THREAD); 178 exception_name = split_verifier.result(); 179 if (can_failover && !HAS_PENDING_EXCEPTION && 180 (exception_name == vmSymbols::java_lang_VerifyError() || 181 exception_name == vmSymbols::java_lang_ClassFormatError())) { 182 log_info(verification)("Fail over class verification to old verifier for: %s", klassName); 183 log_info(class, init)("Fail over class verification to old verifier for: %s", klassName); 184 exception_name = inference_verify( 185 klass, message_buffer, message_buffer_len, THREAD); 186 } 187 if (exception_name != NULL) { 188 exception_message = split_verifier.exception_message(); 189 } 190 } else { 191 exception_name = inference_verify( 192 klass, message_buffer, message_buffer_len, THREAD); 193 } 194 195 LogTarget(Info, class, init) lt1; 196 if (lt1.is_enabled()) { 197 LogStream ls(lt1); 198 log_end_verification(&ls, klassName, exception_name, THREAD); 199 } 200 LogTarget(Info, verification) lt2; 201 if (lt2.is_enabled()) { 202 LogStream ls(lt2); 203 log_end_verification(&ls, klassName, exception_name, THREAD); 204 } 205 206 if (HAS_PENDING_EXCEPTION) { 207 return false; // use the existing exception 208 } else if (exception_name == NULL) { 209 return true; // verifcation succeeded 210 } else { // VerifyError or ClassFormatError to be created and thrown 211 ResourceMark rm(THREAD); 212 Klass* kls = 213 SystemDictionary::resolve_or_fail(exception_name, true, CHECK_false); 214 if (log_is_enabled(Debug, class, resolve)) { 215 Verifier::trace_class_resolution(kls, klass); 216 } 217 218 while (kls != NULL) { 219 if (kls == klass) { 220 // If the class being verified is the exception we're creating 221 // or one of it's superclasses, we're in trouble and are going 222 // to infinitely recurse when we try to initialize the exception. 223 // So bail out here by throwing the preallocated VM error. 224 THROW_OOP_(Universe::virtual_machine_error_instance(), false); 225 } 226 kls = kls->super(); 227 } 228 message_buffer[message_buffer_len - 1] = '\0'; // just to be sure 229 THROW_MSG_(exception_name, exception_message, false); 230 } 231 } 232 233 bool Verifier::is_eligible_for_verification(InstanceKlass* klass, bool should_verify_class) { 234 Symbol* name = klass->name(); 235 Klass* refl_magic_klass = SystemDictionary::reflect_MagicAccessorImpl_klass(); 236 237 bool is_reflect = refl_magic_klass != NULL && klass->is_subtype_of(refl_magic_klass); 238 239 return (should_verify_for(klass->class_loader(), should_verify_class) && 240 // return if the class is a bootstrapping class 241 // or defineClass specified not to verify by default (flags override passed arg) 242 // We need to skip the following few for bootstrapping 243 name != vmSymbols::java_lang_Object() && 244 name != vmSymbols::java_lang_Class() && 245 name != vmSymbols::java_lang_String() && 246 name != vmSymbols::java_lang_Throwable() && 247 248 // Can not verify the bytecodes for shared classes because they have 249 // already been rewritten to contain constant pool cache indices, 250 // which the verifier can't understand. 251 // Shared classes shouldn't have stackmaps either. 252 !klass->is_shared() && 253 254 // A MVT derived value type contains no code atrribute - no private static 255 // methods, no instance methods, no <clinit>, no <init>. So while format 256 // checking is performed on it, verification is not. 257 (!((EnableMVT || EnableValhalla) && klass->access_flags().is_value_type())) && 258 259 // As of the fix for 4486457 we disable verification for all of the 260 // dynamically-generated bytecodes associated with the 1.4 261 // reflection implementation, not just those associated with 262 // jdk/internal/reflect/SerializationConstructorAccessor. 263 // NOTE: this is called too early in the bootstrapping process to be 264 // guarded by Universe::is_gte_jdk14x_version(). 265 // Also for lambda generated code, gte jdk8 266 (!is_reflect)); 267 } 268 269 Symbol* Verifier::inference_verify( 270 InstanceKlass* klass, char* message, size_t message_len, TRAPS) { 271 JavaThread* thread = (JavaThread*)THREAD; 272 JNIEnv *env = thread->jni_environment(); 273 274 void* verify_func = verify_byte_codes_fn(); 275 276 if (verify_func == NULL) { 277 jio_snprintf(message, message_len, "Could not link verifier"); 278 return vmSymbols::java_lang_VerifyError(); 279 } 280 281 ResourceMark rm(THREAD); 282 log_info(verification)("Verifying class %s with old format", klass->external_name()); 283 284 jclass cls = (jclass) JNIHandles::make_local(env, klass->java_mirror()); 285 jint result; 286 287 { 288 HandleMark hm(thread); 289 ThreadToNativeFromVM ttn(thread); 290 // ThreadToNativeFromVM takes care of changing thread_state, so safepoint 291 // code knows that we have left the VM 292 293 if (_is_new_verify_byte_codes_fn) { 294 verify_byte_codes_fn_new_t func = 295 CAST_TO_FN_PTR(verify_byte_codes_fn_new_t, verify_func); 296 result = (*func)(env, cls, message, (int)message_len, 297 klass->major_version()); 298 } else { 299 verify_byte_codes_fn_t func = 300 CAST_TO_FN_PTR(verify_byte_codes_fn_t, verify_func); 301 result = (*func)(env, cls, message, (int)message_len); 302 } 303 } 304 305 JNIHandles::destroy_local(cls); 306 307 // These numbers are chosen so that VerifyClassCodes interface doesn't need 308 // to be changed (still return jboolean (unsigned char)), and result is 309 // 1 when verification is passed. 310 if (result == 0) { 311 return vmSymbols::java_lang_VerifyError(); 312 } else if (result == 1) { 313 return NULL; // verified. 314 } else if (result == 2) { 315 THROW_MSG_(vmSymbols::java_lang_OutOfMemoryError(), message, NULL); 316 } else if (result == 3) { 317 return vmSymbols::java_lang_ClassFormatError(); 318 } else { 319 ShouldNotReachHere(); 320 return NULL; 321 } 322 } 323 324 TypeOrigin TypeOrigin::null() { 325 return TypeOrigin(); 326 } 327 TypeOrigin TypeOrigin::local(u2 index, StackMapFrame* frame) { 328 assert(frame != NULL, "Must have a frame"); 329 return TypeOrigin(CF_LOCALS, index, StackMapFrame::copy(frame), 330 frame->local_at(index)); 331 } 332 TypeOrigin TypeOrigin::stack(u2 index, StackMapFrame* frame) { 333 assert(frame != NULL, "Must have a frame"); 334 return TypeOrigin(CF_STACK, index, StackMapFrame::copy(frame), 335 frame->stack_at(index)); 336 } 337 TypeOrigin TypeOrigin::sm_local(u2 index, StackMapFrame* frame) { 338 assert(frame != NULL, "Must have a frame"); 339 return TypeOrigin(SM_LOCALS, index, StackMapFrame::copy(frame), 340 frame->local_at(index)); 341 } 342 TypeOrigin TypeOrigin::sm_stack(u2 index, StackMapFrame* frame) { 343 assert(frame != NULL, "Must have a frame"); 344 return TypeOrigin(SM_STACK, index, StackMapFrame::copy(frame), 345 frame->stack_at(index)); 346 } 347 TypeOrigin TypeOrigin::bad_index(u2 index) { 348 return TypeOrigin(BAD_INDEX, index, NULL, VerificationType::bogus_type()); 349 } 350 TypeOrigin TypeOrigin::cp(u2 index, VerificationType vt) { 351 return TypeOrigin(CONST_POOL, index, NULL, vt); 352 } 353 TypeOrigin TypeOrigin::signature(VerificationType vt) { 354 return TypeOrigin(SIG, 0, NULL, vt); 355 } 356 TypeOrigin TypeOrigin::implicit(VerificationType t) { 357 return TypeOrigin(IMPLICIT, 0, NULL, t); 358 } 359 TypeOrigin TypeOrigin::frame(StackMapFrame* frame) { 360 return TypeOrigin(FRAME_ONLY, 0, StackMapFrame::copy(frame), 361 VerificationType::bogus_type()); 362 } 363 364 void TypeOrigin::reset_frame() { 365 if (_frame != NULL) { 366 _frame->restore(); 367 } 368 } 369 370 void TypeOrigin::details(outputStream* ss) const { 371 _type.print_on(ss); 372 switch (_origin) { 373 case CF_LOCALS: 374 ss->print(" (current frame, locals[%d])", _index); 375 break; 376 case CF_STACK: 377 ss->print(" (current frame, stack[%d])", _index); 378 break; 379 case SM_LOCALS: 380 ss->print(" (stack map, locals[%d])", _index); 381 break; 382 case SM_STACK: 383 ss->print(" (stack map, stack[%d])", _index); 384 break; 385 case CONST_POOL: 386 ss->print(" (constant pool %d)", _index); 387 break; 388 case SIG: 389 ss->print(" (from method signature)"); 390 break; 391 case IMPLICIT: 392 case FRAME_ONLY: 393 case NONE: 394 default: 395 ; 396 } 397 } 398 399 #ifdef ASSERT 400 void TypeOrigin::print_on(outputStream* str) const { 401 str->print("{%d,%d,%p:", _origin, _index, _frame); 402 if (_frame != NULL) { 403 _frame->print_on(str); 404 } else { 405 str->print("null"); 406 } 407 str->print(","); 408 _type.print_on(str); 409 str->print("}"); 410 } 411 #endif 412 413 void ErrorContext::details(outputStream* ss, const Method* method) const { 414 if (is_valid()) { 415 ss->cr(); 416 ss->print_cr("Exception Details:"); 417 location_details(ss, method); 418 reason_details(ss); 419 frame_details(ss); 420 bytecode_details(ss, method); 421 handler_details(ss, method); 422 stackmap_details(ss, method); 423 } 424 } 425 426 void ErrorContext::reason_details(outputStream* ss) const { 427 streamIndentor si(ss); 428 ss->indent().print_cr("Reason:"); 429 streamIndentor si2(ss); 430 ss->indent().print("%s", ""); 431 switch (_fault) { 432 case INVALID_BYTECODE: 433 ss->print("Error exists in the bytecode"); 434 break; 435 case WRONG_TYPE: 436 if (_expected.is_valid()) { 437 ss->print("Type "); 438 _type.details(ss); 439 ss->print(" is not assignable to "); 440 _expected.details(ss); 441 } else { 442 ss->print("Invalid type: "); 443 _type.details(ss); 444 } 445 break; 446 case FLAGS_MISMATCH: 447 if (_expected.is_valid()) { 448 ss->print("Current frame's flags are not assignable " 449 "to stack map frame's."); 450 } else { 451 ss->print("Current frame's flags are invalid in this context."); 452 } 453 break; 454 case BAD_CP_INDEX: 455 ss->print("Constant pool index %d is invalid", _type.index()); 456 break; 457 case BAD_LOCAL_INDEX: 458 ss->print("Local index %d is invalid", _type.index()); 459 break; 460 case LOCALS_SIZE_MISMATCH: 461 ss->print("Current frame's local size doesn't match stackmap."); 462 break; 463 case STACK_SIZE_MISMATCH: 464 ss->print("Current frame's stack size doesn't match stackmap."); 465 break; 466 case STACK_OVERFLOW: 467 ss->print("Exceeded max stack size."); 468 break; 469 case STACK_UNDERFLOW: 470 ss->print("Attempt to pop empty stack."); 471 break; 472 case MISSING_STACKMAP: 473 ss->print("Expected stackmap frame at this location."); 474 break; 475 case BAD_STACKMAP: 476 ss->print("Invalid stackmap specification."); 477 break; 478 case UNKNOWN: 479 default: 480 ShouldNotReachHere(); 481 ss->print_cr("Unknown"); 482 } 483 ss->cr(); 484 } 485 486 void ErrorContext::location_details(outputStream* ss, const Method* method) const { 487 if (_bci != -1 && method != NULL) { 488 streamIndentor si(ss); 489 const char* bytecode_name = "<invalid>"; 490 if (method->validate_bci(_bci) != -1) { 491 Bytecodes::Code code = Bytecodes::code_or_bp_at(method->bcp_from(_bci)); 492 if (Bytecodes::is_defined(code)) { 493 bytecode_name = Bytecodes::name(code); 494 } else { 495 bytecode_name = "<illegal>"; 496 } 497 } 498 InstanceKlass* ik = method->method_holder(); 499 ss->indent().print_cr("Location:"); 500 streamIndentor si2(ss); 501 ss->indent().print_cr("%s.%s%s @%d: %s", 502 ik->name()->as_C_string(), method->name()->as_C_string(), 503 method->signature()->as_C_string(), _bci, bytecode_name); 504 } 505 } 506 507 void ErrorContext::frame_details(outputStream* ss) const { 508 streamIndentor si(ss); 509 if (_type.is_valid() && _type.frame() != NULL) { 510 ss->indent().print_cr("Current Frame:"); 511 streamIndentor si2(ss); 512 _type.frame()->print_on(ss); 513 } 514 if (_expected.is_valid() && _expected.frame() != NULL) { 515 ss->indent().print_cr("Stackmap Frame:"); 516 streamIndentor si2(ss); 517 _expected.frame()->print_on(ss); 518 } 519 } 520 521 void ErrorContext::bytecode_details(outputStream* ss, const Method* method) const { 522 if (method != NULL) { 523 streamIndentor si(ss); 524 ss->indent().print_cr("Bytecode:"); 525 streamIndentor si2(ss); 526 ss->print_data(method->code_base(), method->code_size(), false); 527 } 528 } 529 530 void ErrorContext::handler_details(outputStream* ss, const Method* method) const { 531 if (method != NULL) { 532 streamIndentor si(ss); 533 ExceptionTable table(method); 534 if (table.length() > 0) { 535 ss->indent().print_cr("Exception Handler Table:"); 536 streamIndentor si2(ss); 537 for (int i = 0; i < table.length(); ++i) { 538 ss->indent().print_cr("bci [%d, %d] => handler: %d", table.start_pc(i), 539 table.end_pc(i), table.handler_pc(i)); 540 } 541 } 542 } 543 } 544 545 void ErrorContext::stackmap_details(outputStream* ss, const Method* method) const { 546 if (method != NULL && method->has_stackmap_table()) { 547 streamIndentor si(ss); 548 ss->indent().print_cr("Stackmap Table:"); 549 Array<u1>* data = method->stackmap_data(); 550 stack_map_table* sm_table = 551 stack_map_table::at((address)data->adr_at(0)); 552 stack_map_frame* sm_frame = sm_table->entries(); 553 streamIndentor si2(ss); 554 int current_offset = -1; 555 address end_of_sm_table = (address)sm_table + method->stackmap_data()->length(); 556 for (u2 i = 0; i < sm_table->number_of_entries(); ++i) { 557 ss->indent(); 558 if (!sm_frame->verify((address)sm_frame, end_of_sm_table)) { 559 sm_frame->print_truncated(ss, current_offset); 560 return; 561 } 562 sm_frame->print_on(ss, current_offset); 563 ss->cr(); 564 current_offset += sm_frame->offset_delta(); 565 sm_frame = sm_frame->next(); 566 } 567 } 568 } 569 570 // Methods in ClassVerifier 571 572 ClassVerifier::ClassVerifier( 573 InstanceKlass* klass, TRAPS) 574 : _thread(THREAD), _exception_type(NULL), _message(NULL), _klass(klass) { 575 _this_type = VerificationType::reference_type(klass->name()); 576 // Create list to hold symbols in reference area. 577 _symbols = new GrowableArray<Symbol*>(100, 0, NULL); 578 } 579 580 ClassVerifier::~ClassVerifier() { 581 // Decrement the reference count for any symbols created. 582 for (int i = 0; i < _symbols->length(); i++) { 583 Symbol* s = _symbols->at(i); 584 s->decrement_refcount(); 585 } 586 } 587 588 VerificationType ClassVerifier::object_type() const { 589 return VerificationType::reference_type(vmSymbols::java_lang_Object()); 590 } 591 592 TypeOrigin ClassVerifier::ref_ctx(const char* sig, TRAPS) { 593 VerificationType vt = VerificationType::reference_type( 594 create_temporary_symbol(sig, (int)strlen(sig), THREAD)); 595 return TypeOrigin::implicit(vt); 596 } 597 598 TypeOrigin ClassVerifier::valuetype_ctx(const char* sig, TRAPS) { 599 VerificationType vt = VerificationType::valuetype_type( 600 create_temporary_symbol(sig, (int)strlen(sig), THREAD)); 601 return TypeOrigin::implicit(vt); 602 } 603 604 void ClassVerifier::verify_class(TRAPS) { 605 log_info(verification)("Verifying class %s with new format", _klass->external_name()); 606 607 Array<Method*>* methods = _klass->methods(); 608 int num_methods = methods->length(); 609 610 for (int index = 0; index < num_methods; index++) { 611 // Check for recursive re-verification before each method. 612 if (was_recursively_verified()) return; 613 614 Method* m = methods->at(index); 615 if (m->is_native() || m->is_abstract() || m->is_overpass()) { 616 // If m is native or abstract, skip it. It is checked in class file 617 // parser that methods do not override a final method. Overpass methods 618 // are trusted since the VM generates them. 619 continue; 620 } 621 verify_method(methodHandle(THREAD, m), CHECK_VERIFY(this)); 622 } 623 624 if (was_recursively_verified()){ 625 log_info(verification)("Recursive verification detected for: %s", _klass->external_name()); 626 log_info(class, init)("Recursive verification detected for: %s", 627 _klass->external_name()); 628 } 629 } 630 631 void ClassVerifier::verify_method(const methodHandle& m, TRAPS) { 632 HandleMark hm(THREAD); 633 _method = m; // initialize _method 634 log_info(verification)("Verifying method %s", m->name_and_sig_as_C_string()); 635 636 // For clang, the only good constant format string is a literal constant format string. 637 #define bad_type_msg "Bad type on operand stack in %s" 638 639 int32_t max_stack = m->verifier_max_stack(); 640 int32_t max_locals = m->max_locals(); 641 constantPoolHandle cp(THREAD, m->constants()); 642 643 if (!SignatureVerifier::is_valid_method_signature(m->signature())) { 644 class_format_error("Invalid method signature"); 645 return; 646 } 647 648 // Verify value type bytecodes if enabled and class file version supports them. 649 // Commented check out for now until class file version 54.1 is generated. 650 bool vbytecodes_allowed = (EnableMVT || EnableValhalla); 651 //_klass->major_version() >= Verifier::VALUETYPE_MAJOR_VERSION && 652 //_klass->minor_version() >= Verifier::VALUETYPE_MINOR_VERSION); 653 654 // Initial stack map frame: offset is 0, stack is initially empty. 655 StackMapFrame current_frame(max_locals, max_stack, this); 656 // Set initial locals 657 VerificationType return_type = current_frame.set_locals_from_arg( 658 m, current_type(), CHECK_VERIFY(this)); 659 660 int32_t stackmap_index = 0; // index to the stackmap array 661 662 u4 code_length = m->code_size(); 663 664 // Scan the bytecode and map each instruction's start offset to a number. 665 char* code_data = generate_code_data(m, code_length, CHECK_VERIFY(this)); 666 667 int ex_min = code_length; 668 int ex_max = -1; 669 // Look through each item on the exception table. Each of the fields must refer 670 // to a legal instruction. 671 if (was_recursively_verified()) return; 672 verify_exception_handler_table( 673 code_length, code_data, ex_min, ex_max, CHECK_VERIFY(this)); 674 675 // Look through each entry on the local variable table and make sure 676 // its range of code array offsets is valid. (4169817) 677 if (m->has_localvariable_table()) { 678 verify_local_variable_table(code_length, code_data, CHECK_VERIFY(this)); 679 } 680 681 Array<u1>* stackmap_data = m->stackmap_data(); 682 StackMapStream stream(stackmap_data); 683 StackMapReader reader(this, &stream, code_data, code_length, THREAD); 684 StackMapTable stackmap_table(&reader, ¤t_frame, max_locals, max_stack, 685 code_data, code_length, CHECK_VERIFY(this)); 686 687 LogTarget(Info, verification) lt; 688 if (lt.is_enabled()) { 689 ResourceMark rm(THREAD); 690 LogStream ls(lt); 691 stackmap_table.print_on(&ls); 692 } 693 694 RawBytecodeStream bcs(m); 695 696 // Scan the byte code linearly from the start to the end 697 bool no_control_flow = false; // Set to true when there is no direct control 698 // flow from current instruction to the next 699 // instruction in sequence 700 701 Bytecodes::Code opcode; 702 while (!bcs.is_last_bytecode()) { 703 // Check for recursive re-verification before each bytecode. 704 if (was_recursively_verified()) return; 705 706 opcode = bcs.raw_next(); 707 u2 bci = bcs.bci(); 708 709 // Set current frame's offset to bci 710 current_frame.set_offset(bci); 711 current_frame.set_mark(); 712 713 // Make sure every offset in stackmap table point to the beginning to 714 // an instruction. Match current_frame to stackmap_table entry with 715 // the same offset if exists. 716 stackmap_index = verify_stackmap_table( 717 stackmap_index, bci, ¤t_frame, &stackmap_table, 718 no_control_flow, CHECK_VERIFY(this)); 719 720 721 bool this_uninit = false; // Set to true when invokespecial <init> initialized 'this' 722 bool verified_exc_handlers = false; 723 724 // Merge with the next instruction 725 { 726 u2 index; 727 int target; 728 VerificationType type, type2; 729 VerificationType atype; 730 731 LogTarget(Info, verification) lt; 732 if (lt.is_enabled()) { 733 ResourceMark rm(THREAD); 734 LogStream ls(lt); 735 current_frame.print_on(&ls); 736 lt.print("offset = %d, opcode = %s", bci, Bytecodes::name(opcode)); 737 } 738 739 // Make sure wide instruction is in correct format 740 if (bcs.is_wide()) { 741 if (opcode != Bytecodes::_iinc && opcode != Bytecodes::_iload && 742 opcode != Bytecodes::_aload && opcode != Bytecodes::_lload && 743 opcode != Bytecodes::_istore && opcode != Bytecodes::_astore && 744 opcode != Bytecodes::_lstore && opcode != Bytecodes::_fload && 745 opcode != Bytecodes::_dload && opcode != Bytecodes::_fstore && 746 opcode != Bytecodes::_dstore) { 747 /* Unreachable? RawBytecodeStream's raw_next() returns 'illegal' 748 * if we encounter a wide instruction that modifies an invalid 749 * opcode (not one of the ones listed above) */ 750 verify_error(ErrorContext::bad_code(bci), "Bad wide instruction"); 751 return; 752 } 753 } 754 755 // Look for possible jump target in exception handlers and see if it 756 // matches current_frame. Do this check here for astore*, dstore*, 757 // fstore*, istore*, and lstore* opcodes because they can change the type 758 // state by adding a local. JVM Spec says that the incoming type state 759 // should be used for this check. So, do the check here before a possible 760 // local is added to the type state. 761 if (Bytecodes::is_store_into_local(opcode) && bci >= ex_min && bci < ex_max) { 762 if (was_recursively_verified()) return; 763 verify_exception_handler_targets( 764 bci, this_uninit, ¤t_frame, &stackmap_table, CHECK_VERIFY(this)); 765 verified_exc_handlers = true; 766 } 767 768 if (was_recursively_verified()) return; 769 770 switch (opcode) { 771 case Bytecodes::_nop : 772 no_control_flow = false; break; 773 case Bytecodes::_aconst_null : 774 current_frame.push_stack( 775 VerificationType::null_type(), CHECK_VERIFY(this)); 776 no_control_flow = false; break; 777 case Bytecodes::_iconst_m1 : 778 case Bytecodes::_iconst_0 : 779 case Bytecodes::_iconst_1 : 780 case Bytecodes::_iconst_2 : 781 case Bytecodes::_iconst_3 : 782 case Bytecodes::_iconst_4 : 783 case Bytecodes::_iconst_5 : 784 current_frame.push_stack( 785 VerificationType::integer_type(), CHECK_VERIFY(this)); 786 no_control_flow = false; break; 787 case Bytecodes::_lconst_0 : 788 case Bytecodes::_lconst_1 : 789 current_frame.push_stack_2( 790 VerificationType::long_type(), 791 VerificationType::long2_type(), CHECK_VERIFY(this)); 792 no_control_flow = false; break; 793 case Bytecodes::_fconst_0 : 794 case Bytecodes::_fconst_1 : 795 case Bytecodes::_fconst_2 : 796 current_frame.push_stack( 797 VerificationType::float_type(), CHECK_VERIFY(this)); 798 no_control_flow = false; break; 799 case Bytecodes::_dconst_0 : 800 case Bytecodes::_dconst_1 : 801 current_frame.push_stack_2( 802 VerificationType::double_type(), 803 VerificationType::double2_type(), CHECK_VERIFY(this)); 804 no_control_flow = false; break; 805 case Bytecodes::_sipush : 806 case Bytecodes::_bipush : 807 current_frame.push_stack( 808 VerificationType::integer_type(), CHECK_VERIFY(this)); 809 no_control_flow = false; break; 810 case Bytecodes::_ldc : 811 verify_ldc( 812 opcode, bcs.get_index_u1(), ¤t_frame, 813 cp, bci, CHECK_VERIFY(this)); 814 no_control_flow = false; break; 815 case Bytecodes::_ldc_w : 816 case Bytecodes::_ldc2_w : 817 verify_ldc( 818 opcode, bcs.get_index_u2(), ¤t_frame, 819 cp, bci, CHECK_VERIFY(this)); 820 no_control_flow = false; break; 821 case Bytecodes::_iload : 822 verify_iload(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); 823 no_control_flow = false; break; 824 case Bytecodes::_iload_0 : 825 case Bytecodes::_iload_1 : 826 case Bytecodes::_iload_2 : 827 case Bytecodes::_iload_3 : 828 index = opcode - Bytecodes::_iload_0; 829 verify_iload(index, ¤t_frame, CHECK_VERIFY(this)); 830 no_control_flow = false; break; 831 case Bytecodes::_lload : 832 verify_lload(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); 833 no_control_flow = false; break; 834 case Bytecodes::_lload_0 : 835 case Bytecodes::_lload_1 : 836 case Bytecodes::_lload_2 : 837 case Bytecodes::_lload_3 : 838 index = opcode - Bytecodes::_lload_0; 839 verify_lload(index, ¤t_frame, CHECK_VERIFY(this)); 840 no_control_flow = false; break; 841 case Bytecodes::_fload : 842 verify_fload(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); 843 no_control_flow = false; break; 844 case Bytecodes::_fload_0 : 845 case Bytecodes::_fload_1 : 846 case Bytecodes::_fload_2 : 847 case Bytecodes::_fload_3 : 848 index = opcode - Bytecodes::_fload_0; 849 verify_fload(index, ¤t_frame, CHECK_VERIFY(this)); 850 no_control_flow = false; break; 851 case Bytecodes::_dload : 852 verify_dload(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); 853 no_control_flow = false; break; 854 case Bytecodes::_dload_0 : 855 case Bytecodes::_dload_1 : 856 case Bytecodes::_dload_2 : 857 case Bytecodes::_dload_3 : 858 index = opcode - Bytecodes::_dload_0; 859 verify_dload(index, ¤t_frame, CHECK_VERIFY(this)); 860 no_control_flow = false; break; 861 case Bytecodes::_aload : 862 verify_aload(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); 863 no_control_flow = false; break; 864 case Bytecodes::_aload_0 : 865 case Bytecodes::_aload_1 : 866 case Bytecodes::_aload_2 : 867 case Bytecodes::_aload_3 : 868 index = opcode - Bytecodes::_aload_0; 869 verify_aload(index, ¤t_frame, CHECK_VERIFY(this)); 870 no_control_flow = false; break; 871 case Bytecodes::_iaload : 872 type = current_frame.pop_stack( 873 VerificationType::integer_type(), CHECK_VERIFY(this)); 874 atype = current_frame.pop_stack( 875 VerificationType::reference_check(), CHECK_VERIFY(this)); 876 if (!atype.is_int_array()) { 877 verify_error(ErrorContext::bad_type(bci, 878 current_frame.stack_top_ctx(), ref_ctx("[I", THREAD)), 879 bad_type_msg, "iaload"); 880 return; 881 } 882 current_frame.push_stack( 883 VerificationType::integer_type(), CHECK_VERIFY(this)); 884 no_control_flow = false; break; 885 case Bytecodes::_baload : 886 type = current_frame.pop_stack( 887 VerificationType::integer_type(), CHECK_VERIFY(this)); 888 atype = current_frame.pop_stack( 889 VerificationType::reference_check(), CHECK_VERIFY(this)); 890 if (!atype.is_bool_array() && !atype.is_byte_array()) { 891 verify_error( 892 ErrorContext::bad_type(bci, current_frame.stack_top_ctx()), 893 bad_type_msg, "baload"); 894 return; 895 } 896 current_frame.push_stack( 897 VerificationType::integer_type(), CHECK_VERIFY(this)); 898 no_control_flow = false; break; 899 case Bytecodes::_caload : 900 type = current_frame.pop_stack( 901 VerificationType::integer_type(), CHECK_VERIFY(this)); 902 atype = current_frame.pop_stack( 903 VerificationType::reference_check(), CHECK_VERIFY(this)); 904 if (!atype.is_char_array()) { 905 verify_error(ErrorContext::bad_type(bci, 906 current_frame.stack_top_ctx(), ref_ctx("[C", THREAD)), 907 bad_type_msg, "caload"); 908 return; 909 } 910 current_frame.push_stack( 911 VerificationType::integer_type(), CHECK_VERIFY(this)); 912 no_control_flow = false; break; 913 case Bytecodes::_saload : 914 type = current_frame.pop_stack( 915 VerificationType::integer_type(), CHECK_VERIFY(this)); 916 atype = current_frame.pop_stack( 917 VerificationType::reference_check(), CHECK_VERIFY(this)); 918 if (!atype.is_short_array()) { 919 verify_error(ErrorContext::bad_type(bci, 920 current_frame.stack_top_ctx(), ref_ctx("[S", THREAD)), 921 bad_type_msg, "saload"); 922 return; 923 } 924 current_frame.push_stack( 925 VerificationType::integer_type(), CHECK_VERIFY(this)); 926 no_control_flow = false; break; 927 case Bytecodes::_laload : 928 type = current_frame.pop_stack( 929 VerificationType::integer_type(), CHECK_VERIFY(this)); 930 atype = current_frame.pop_stack( 931 VerificationType::reference_check(), CHECK_VERIFY(this)); 932 if (!atype.is_long_array()) { 933 verify_error(ErrorContext::bad_type(bci, 934 current_frame.stack_top_ctx(), ref_ctx("[J", THREAD)), 935 bad_type_msg, "laload"); 936 return; 937 } 938 current_frame.push_stack_2( 939 VerificationType::long_type(), 940 VerificationType::long2_type(), CHECK_VERIFY(this)); 941 no_control_flow = false; break; 942 case Bytecodes::_faload : 943 type = current_frame.pop_stack( 944 VerificationType::integer_type(), CHECK_VERIFY(this)); 945 atype = current_frame.pop_stack( 946 VerificationType::reference_check(), CHECK_VERIFY(this)); 947 if (!atype.is_float_array()) { 948 verify_error(ErrorContext::bad_type(bci, 949 current_frame.stack_top_ctx(), ref_ctx("[F", THREAD)), 950 bad_type_msg, "faload"); 951 return; 952 } 953 current_frame.push_stack( 954 VerificationType::float_type(), CHECK_VERIFY(this)); 955 no_control_flow = false; break; 956 case Bytecodes::_daload : 957 type = current_frame.pop_stack( 958 VerificationType::integer_type(), CHECK_VERIFY(this)); 959 atype = current_frame.pop_stack( 960 VerificationType::reference_check(), CHECK_VERIFY(this)); 961 if (!atype.is_double_array()) { 962 verify_error(ErrorContext::bad_type(bci, 963 current_frame.stack_top_ctx(), ref_ctx("[D", THREAD)), 964 bad_type_msg, "daload"); 965 return; 966 } 967 current_frame.push_stack_2( 968 VerificationType::double_type(), 969 VerificationType::double2_type(), CHECK_VERIFY(this)); 970 no_control_flow = false; break; 971 case Bytecodes::_aaload : { 972 type = current_frame.pop_stack( 973 VerificationType::integer_type(), CHECK_VERIFY(this)); 974 atype = current_frame.pop_stack( 975 VerificationType::reference_check(), CHECK_VERIFY(this)); 976 if (!atype.is_reference_array()) { 977 verify_error(ErrorContext::bad_type(bci, 978 current_frame.stack_top_ctx(), 979 TypeOrigin::implicit(VerificationType::reference_check())), 980 bad_type_msg, "aaload"); 981 return; 982 } 983 if (atype.is_null()) { 984 current_frame.push_stack( 985 VerificationType::null_type(), CHECK_VERIFY(this)); 986 } else { 987 VerificationType component = 988 atype.get_component(this, CHECK_VERIFY(this)); 989 current_frame.push_stack(component, CHECK_VERIFY(this)); 990 } 991 no_control_flow = false; break; 992 } 993 // case Bytecodes::_vaload : { 994 // if (!vbytecodes_allowed) { 995 // class_format_error( 996 // "vaload not supported by this class file version (%d.%d), class %s", 997 // _klass->major_version(), _klass->minor_version(), _klass->external_name()); 998 // return; 999 // } 1000 // type = current_frame.pop_stack( 1001 // VerificationType::integer_type(), CHECK_VERIFY(this)); 1002 // atype = current_frame.pop_stack( 1003 // VerificationType::reference_check(), CHECK_VERIFY(this)); 1004 // // The null check is strictly not be necessary, left in for future proofing. 1005 // // Will be reconsidered if type indexes are removed. 1006 // if (atype.is_null() || !atype.is_value_array()) { 1007 // verify_error(ErrorContext::bad_type(bci, 1008 // current_frame.stack_top_ctx(), 1009 // TypeOrigin::implicit(VerificationType::reference_check())), 1010 // bad_type_msg, "vaload"); 1011 // return; 1012 // } 1013 // VerificationType component = atype.get_component(this, CHECK_VERIFY(this)); 1014 // if (!component.is_valuetype()) { 1015 // verify_error(ErrorContext::bad_type(bci, 1016 // current_frame.stack_top_ctx(), 1017 // TypeOrigin::implicit(VerificationType::valuetype_check())), 1018 // bad_type_msg, "vaload"); 1019 // return; 1020 // } 1021 // current_frame.push_stack(component, CHECK_VERIFY(this)); 1022 // no_control_flow = false; break; 1023 // } 1024 case Bytecodes::_istore : 1025 verify_istore(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); 1026 no_control_flow = false; break; 1027 case Bytecodes::_istore_0 : 1028 case Bytecodes::_istore_1 : 1029 case Bytecodes::_istore_2 : 1030 case Bytecodes::_istore_3 : 1031 index = opcode - Bytecodes::_istore_0; 1032 verify_istore(index, ¤t_frame, CHECK_VERIFY(this)); 1033 no_control_flow = false; break; 1034 case Bytecodes::_lstore : 1035 verify_lstore(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); 1036 no_control_flow = false; break; 1037 case Bytecodes::_lstore_0 : 1038 case Bytecodes::_lstore_1 : 1039 case Bytecodes::_lstore_2 : 1040 case Bytecodes::_lstore_3 : 1041 index = opcode - Bytecodes::_lstore_0; 1042 verify_lstore(index, ¤t_frame, CHECK_VERIFY(this)); 1043 no_control_flow = false; break; 1044 case Bytecodes::_fstore : 1045 verify_fstore(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); 1046 no_control_flow = false; break; 1047 case Bytecodes::_fstore_0 : 1048 case Bytecodes::_fstore_1 : 1049 case Bytecodes::_fstore_2 : 1050 case Bytecodes::_fstore_3 : 1051 index = opcode - Bytecodes::_fstore_0; 1052 verify_fstore(index, ¤t_frame, CHECK_VERIFY(this)); 1053 no_control_flow = false; break; 1054 case Bytecodes::_dstore : 1055 verify_dstore(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); 1056 no_control_flow = false; break; 1057 case Bytecodes::_dstore_0 : 1058 case Bytecodes::_dstore_1 : 1059 case Bytecodes::_dstore_2 : 1060 case Bytecodes::_dstore_3 : 1061 index = opcode - Bytecodes::_dstore_0; 1062 verify_dstore(index, ¤t_frame, CHECK_VERIFY(this)); 1063 no_control_flow = false; break; 1064 case Bytecodes::_astore : 1065 verify_astore(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); 1066 no_control_flow = false; break; 1067 case Bytecodes::_astore_0 : 1068 case Bytecodes::_astore_1 : 1069 case Bytecodes::_astore_2 : 1070 case Bytecodes::_astore_3 : 1071 index = opcode - Bytecodes::_astore_0; 1072 verify_astore(index, ¤t_frame, CHECK_VERIFY(this)); 1073 no_control_flow = false; break; 1074 case Bytecodes::_iastore : 1075 type = current_frame.pop_stack( 1076 VerificationType::integer_type(), CHECK_VERIFY(this)); 1077 type2 = current_frame.pop_stack( 1078 VerificationType::integer_type(), CHECK_VERIFY(this)); 1079 atype = current_frame.pop_stack( 1080 VerificationType::reference_check(), CHECK_VERIFY(this)); 1081 if (!atype.is_int_array()) { 1082 verify_error(ErrorContext::bad_type(bci, 1083 current_frame.stack_top_ctx(), ref_ctx("[I", THREAD)), 1084 bad_type_msg, "iastore"); 1085 return; 1086 } 1087 no_control_flow = false; break; 1088 case Bytecodes::_bastore : 1089 type = current_frame.pop_stack( 1090 VerificationType::integer_type(), CHECK_VERIFY(this)); 1091 type2 = current_frame.pop_stack( 1092 VerificationType::integer_type(), CHECK_VERIFY(this)); 1093 atype = current_frame.pop_stack( 1094 VerificationType::reference_check(), CHECK_VERIFY(this)); 1095 if (!atype.is_bool_array() && !atype.is_byte_array()) { 1096 verify_error( 1097 ErrorContext::bad_type(bci, current_frame.stack_top_ctx()), 1098 bad_type_msg, "bastore"); 1099 return; 1100 } 1101 no_control_flow = false; break; 1102 case Bytecodes::_castore : 1103 current_frame.pop_stack( 1104 VerificationType::integer_type(), CHECK_VERIFY(this)); 1105 current_frame.pop_stack( 1106 VerificationType::integer_type(), CHECK_VERIFY(this)); 1107 atype = current_frame.pop_stack( 1108 VerificationType::reference_check(), CHECK_VERIFY(this)); 1109 if (!atype.is_char_array()) { 1110 verify_error(ErrorContext::bad_type(bci, 1111 current_frame.stack_top_ctx(), ref_ctx("[C", THREAD)), 1112 bad_type_msg, "castore"); 1113 return; 1114 } 1115 no_control_flow = false; break; 1116 case Bytecodes::_sastore : 1117 current_frame.pop_stack( 1118 VerificationType::integer_type(), CHECK_VERIFY(this)); 1119 current_frame.pop_stack( 1120 VerificationType::integer_type(), CHECK_VERIFY(this)); 1121 atype = current_frame.pop_stack( 1122 VerificationType::reference_check(), CHECK_VERIFY(this)); 1123 if (!atype.is_short_array()) { 1124 verify_error(ErrorContext::bad_type(bci, 1125 current_frame.stack_top_ctx(), ref_ctx("[S", THREAD)), 1126 bad_type_msg, "sastore"); 1127 return; 1128 } 1129 no_control_flow = false; break; 1130 case Bytecodes::_lastore : 1131 current_frame.pop_stack_2( 1132 VerificationType::long2_type(), 1133 VerificationType::long_type(), CHECK_VERIFY(this)); 1134 current_frame.pop_stack( 1135 VerificationType::integer_type(), CHECK_VERIFY(this)); 1136 atype = current_frame.pop_stack( 1137 VerificationType::reference_check(), CHECK_VERIFY(this)); 1138 if (!atype.is_long_array()) { 1139 verify_error(ErrorContext::bad_type(bci, 1140 current_frame.stack_top_ctx(), ref_ctx("[J", THREAD)), 1141 bad_type_msg, "lastore"); 1142 return; 1143 } 1144 no_control_flow = false; break; 1145 case Bytecodes::_fastore : 1146 current_frame.pop_stack( 1147 VerificationType::float_type(), CHECK_VERIFY(this)); 1148 current_frame.pop_stack 1149 (VerificationType::integer_type(), CHECK_VERIFY(this)); 1150 atype = current_frame.pop_stack( 1151 VerificationType::reference_check(), CHECK_VERIFY(this)); 1152 if (!atype.is_float_array()) { 1153 verify_error(ErrorContext::bad_type(bci, 1154 current_frame.stack_top_ctx(), ref_ctx("[F", THREAD)), 1155 bad_type_msg, "fastore"); 1156 return; 1157 } 1158 no_control_flow = false; break; 1159 case Bytecodes::_dastore : 1160 current_frame.pop_stack_2( 1161 VerificationType::double2_type(), 1162 VerificationType::double_type(), CHECK_VERIFY(this)); 1163 current_frame.pop_stack( 1164 VerificationType::integer_type(), CHECK_VERIFY(this)); 1165 atype = current_frame.pop_stack( 1166 VerificationType::reference_check(), CHECK_VERIFY(this)); 1167 if (!atype.is_double_array()) { 1168 verify_error(ErrorContext::bad_type(bci, 1169 current_frame.stack_top_ctx(), ref_ctx("[D", THREAD)), 1170 bad_type_msg, "dastore"); 1171 return; 1172 } 1173 no_control_flow = false; break; 1174 case Bytecodes::_aastore : 1175 type = current_frame.pop_stack(object_type(), CHECK_VERIFY(this)); 1176 type2 = current_frame.pop_stack( 1177 VerificationType::integer_type(), CHECK_VERIFY(this)); 1178 atype = current_frame.pop_stack( 1179 VerificationType::reference_check(), CHECK_VERIFY(this)); 1180 // more type-checking is done at runtime 1181 if (!atype.is_reference_array()) { 1182 verify_error(ErrorContext::bad_type(bci, 1183 current_frame.stack_top_ctx(), 1184 TypeOrigin::implicit(VerificationType::reference_check())), 1185 bad_type_msg, "aastore"); 1186 return; 1187 } 1188 // 4938384: relaxed constraint in JVMS 3nd edition. 1189 no_control_flow = false; break; 1190 // case Bytecodes::_vastore : 1191 // if (!vbytecodes_allowed) { 1192 // class_format_error( 1193 // "vastore not supported by this class file version (%d.%d), class %s", 1194 // _klass->major_version(), _klass->minor_version(), _klass->external_name()); 1195 // return; 1196 // } 1197 // type = current_frame.pop_stack(__value_type(), CHECK_VERIFY(this)); 1198 // type2 = current_frame.pop_stack( 1199 // VerificationType::integer_type(), CHECK_VERIFY(this)); 1200 // atype = current_frame.pop_stack( 1201 // VerificationType::reference_check(), CHECK_VERIFY(this)); 1202 // // The null check is strictly not be necessary, left in for future proofing. 1203 // // Will be reconsidered if type indexes are removed. 1204 // if (atype.is_null() || !atype.is_value_array()) { 1205 // verify_error(ErrorContext::bad_type(bci, 1206 // current_frame.stack_top_ctx(), 1207 // TypeOrigin::implicit(VerificationType::reference_check())), 1208 // bad_type_msg, "vastore"); 1209 // return; 1210 // } 1211 // no_control_flow = false; break; 1212 case Bytecodes::_pop : 1213 current_frame.pop_stack( 1214 VerificationType::category1_check(), CHECK_VERIFY(this)); 1215 no_control_flow = false; break; 1216 case Bytecodes::_pop2 : 1217 type = current_frame.pop_stack(CHECK_VERIFY(this)); 1218 if (type.is_category1()) { 1219 current_frame.pop_stack( 1220 VerificationType::category1_check(), CHECK_VERIFY(this)); 1221 } else if (type.is_category2_2nd()) { 1222 current_frame.pop_stack( 1223 VerificationType::category2_check(), CHECK_VERIFY(this)); 1224 } else { 1225 /* Unreachable? Would need a category2_1st on TOS 1226 * which does not appear possible. */ 1227 verify_error( 1228 ErrorContext::bad_type(bci, current_frame.stack_top_ctx()), 1229 bad_type_msg, "pop2"); 1230 return; 1231 } 1232 no_control_flow = false; break; 1233 case Bytecodes::_dup : 1234 type = current_frame.pop_stack( 1235 VerificationType::category1_check(), CHECK_VERIFY(this)); 1236 current_frame.push_stack(type, CHECK_VERIFY(this)); 1237 current_frame.push_stack(type, CHECK_VERIFY(this)); 1238 no_control_flow = false; break; 1239 case Bytecodes::_dup_x1 : 1240 type = current_frame.pop_stack( 1241 VerificationType::category1_check(), CHECK_VERIFY(this)); 1242 type2 = current_frame.pop_stack( 1243 VerificationType::category1_check(), CHECK_VERIFY(this)); 1244 current_frame.push_stack(type, CHECK_VERIFY(this)); 1245 current_frame.push_stack(type2, CHECK_VERIFY(this)); 1246 current_frame.push_stack(type, CHECK_VERIFY(this)); 1247 no_control_flow = false; break; 1248 case Bytecodes::_dup_x2 : 1249 { 1250 VerificationType type3; 1251 type = current_frame.pop_stack( 1252 VerificationType::category1_check(), CHECK_VERIFY(this)); 1253 type2 = current_frame.pop_stack(CHECK_VERIFY(this)); 1254 if (type2.is_category1()) { 1255 type3 = current_frame.pop_stack( 1256 VerificationType::category1_check(), CHECK_VERIFY(this)); 1257 } else if (type2.is_category2_2nd()) { 1258 type3 = current_frame.pop_stack( 1259 VerificationType::category2_check(), CHECK_VERIFY(this)); 1260 } else { 1261 /* Unreachable? Would need a category2_1st at stack depth 2 with 1262 * a category1 on TOS which does not appear possible. */ 1263 verify_error(ErrorContext::bad_type( 1264 bci, current_frame.stack_top_ctx()), bad_type_msg, "dup_x2"); 1265 return; 1266 } 1267 current_frame.push_stack(type, CHECK_VERIFY(this)); 1268 current_frame.push_stack(type3, CHECK_VERIFY(this)); 1269 current_frame.push_stack(type2, CHECK_VERIFY(this)); 1270 current_frame.push_stack(type, CHECK_VERIFY(this)); 1271 no_control_flow = false; break; 1272 } 1273 case Bytecodes::_dup2 : 1274 type = current_frame.pop_stack(CHECK_VERIFY(this)); 1275 if (type.is_category1()) { 1276 type2 = current_frame.pop_stack( 1277 VerificationType::category1_check(), CHECK_VERIFY(this)); 1278 } else if (type.is_category2_2nd()) { 1279 type2 = current_frame.pop_stack( 1280 VerificationType::category2_check(), CHECK_VERIFY(this)); 1281 } else { 1282 /* Unreachable? Would need a category2_1st on TOS which does not 1283 * appear possible. */ 1284 verify_error( 1285 ErrorContext::bad_type(bci, current_frame.stack_top_ctx()), 1286 bad_type_msg, "dup2"); 1287 return; 1288 } 1289 current_frame.push_stack(type2, CHECK_VERIFY(this)); 1290 current_frame.push_stack(type, CHECK_VERIFY(this)); 1291 current_frame.push_stack(type2, CHECK_VERIFY(this)); 1292 current_frame.push_stack(type, CHECK_VERIFY(this)); 1293 no_control_flow = false; break; 1294 case Bytecodes::_dup2_x1 : 1295 { 1296 VerificationType type3; 1297 type = current_frame.pop_stack(CHECK_VERIFY(this)); 1298 if (type.is_category1()) { 1299 type2 = current_frame.pop_stack( 1300 VerificationType::category1_check(), CHECK_VERIFY(this)); 1301 } else if (type.is_category2_2nd()) { 1302 type2 = current_frame.pop_stack( 1303 VerificationType::category2_check(), CHECK_VERIFY(this)); 1304 } else { 1305 /* Unreachable? Would need a category2_1st on TOS which does 1306 * not appear possible. */ 1307 verify_error( 1308 ErrorContext::bad_type(bci, current_frame.stack_top_ctx()), 1309 bad_type_msg, "dup2_x1"); 1310 return; 1311 } 1312 type3 = current_frame.pop_stack( 1313 VerificationType::category1_check(), CHECK_VERIFY(this)); 1314 current_frame.push_stack(type2, CHECK_VERIFY(this)); 1315 current_frame.push_stack(type, CHECK_VERIFY(this)); 1316 current_frame.push_stack(type3, CHECK_VERIFY(this)); 1317 current_frame.push_stack(type2, CHECK_VERIFY(this)); 1318 current_frame.push_stack(type, CHECK_VERIFY(this)); 1319 no_control_flow = false; break; 1320 } 1321 case Bytecodes::_dup2_x2 : 1322 { 1323 VerificationType type3, type4; 1324 type = current_frame.pop_stack(CHECK_VERIFY(this)); 1325 if (type.is_category1()) { 1326 type2 = current_frame.pop_stack( 1327 VerificationType::category1_check(), CHECK_VERIFY(this)); 1328 } else if (type.is_category2_2nd()) { 1329 type2 = current_frame.pop_stack( 1330 VerificationType::category2_check(), CHECK_VERIFY(this)); 1331 } else { 1332 /* Unreachable? Would need a category2_1st on TOS which does 1333 * not appear possible. */ 1334 verify_error( 1335 ErrorContext::bad_type(bci, current_frame.stack_top_ctx()), 1336 bad_type_msg, "dup2_x2"); 1337 return; 1338 } 1339 type3 = current_frame.pop_stack(CHECK_VERIFY(this)); 1340 if (type3.is_category1()) { 1341 type4 = current_frame.pop_stack( 1342 VerificationType::category1_check(), CHECK_VERIFY(this)); 1343 } else if (type3.is_category2_2nd()) { 1344 type4 = current_frame.pop_stack( 1345 VerificationType::category2_check(), CHECK_VERIFY(this)); 1346 } else { 1347 /* Unreachable? Would need a category2_1st on TOS after popping 1348 * a long/double or two category 1's, which does not 1349 * appear possible. */ 1350 verify_error( 1351 ErrorContext::bad_type(bci, current_frame.stack_top_ctx()), 1352 bad_type_msg, "dup2_x2"); 1353 return; 1354 } 1355 current_frame.push_stack(type2, CHECK_VERIFY(this)); 1356 current_frame.push_stack(type, CHECK_VERIFY(this)); 1357 current_frame.push_stack(type4, CHECK_VERIFY(this)); 1358 current_frame.push_stack(type3, CHECK_VERIFY(this)); 1359 current_frame.push_stack(type2, CHECK_VERIFY(this)); 1360 current_frame.push_stack(type, CHECK_VERIFY(this)); 1361 no_control_flow = false; break; 1362 } 1363 case Bytecodes::_swap : 1364 type = current_frame.pop_stack( 1365 VerificationType::category1_check(), CHECK_VERIFY(this)); 1366 type2 = current_frame.pop_stack( 1367 VerificationType::category1_check(), CHECK_VERIFY(this)); 1368 current_frame.push_stack(type, CHECK_VERIFY(this)); 1369 current_frame.push_stack(type2, CHECK_VERIFY(this)); 1370 no_control_flow = false; break; 1371 case Bytecodes::_iadd : 1372 case Bytecodes::_isub : 1373 case Bytecodes::_imul : 1374 case Bytecodes::_idiv : 1375 case Bytecodes::_irem : 1376 case Bytecodes::_ishl : 1377 case Bytecodes::_ishr : 1378 case Bytecodes::_iushr : 1379 case Bytecodes::_ior : 1380 case Bytecodes::_ixor : 1381 case Bytecodes::_iand : 1382 current_frame.pop_stack( 1383 VerificationType::integer_type(), CHECK_VERIFY(this)); 1384 // fall through 1385 case Bytecodes::_ineg : 1386 current_frame.pop_stack( 1387 VerificationType::integer_type(), CHECK_VERIFY(this)); 1388 current_frame.push_stack( 1389 VerificationType::integer_type(), CHECK_VERIFY(this)); 1390 no_control_flow = false; break; 1391 case Bytecodes::_ladd : 1392 case Bytecodes::_lsub : 1393 case Bytecodes::_lmul : 1394 case Bytecodes::_ldiv : 1395 case Bytecodes::_lrem : 1396 case Bytecodes::_land : 1397 case Bytecodes::_lor : 1398 case Bytecodes::_lxor : 1399 current_frame.pop_stack_2( 1400 VerificationType::long2_type(), 1401 VerificationType::long_type(), CHECK_VERIFY(this)); 1402 // fall through 1403 case Bytecodes::_lneg : 1404 current_frame.pop_stack_2( 1405 VerificationType::long2_type(), 1406 VerificationType::long_type(), CHECK_VERIFY(this)); 1407 current_frame.push_stack_2( 1408 VerificationType::long_type(), 1409 VerificationType::long2_type(), CHECK_VERIFY(this)); 1410 no_control_flow = false; break; 1411 case Bytecodes::_lshl : 1412 case Bytecodes::_lshr : 1413 case Bytecodes::_lushr : 1414 current_frame.pop_stack( 1415 VerificationType::integer_type(), CHECK_VERIFY(this)); 1416 current_frame.pop_stack_2( 1417 VerificationType::long2_type(), 1418 VerificationType::long_type(), CHECK_VERIFY(this)); 1419 current_frame.push_stack_2( 1420 VerificationType::long_type(), 1421 VerificationType::long2_type(), CHECK_VERIFY(this)); 1422 no_control_flow = false; break; 1423 case Bytecodes::_fadd : 1424 case Bytecodes::_fsub : 1425 case Bytecodes::_fmul : 1426 case Bytecodes::_fdiv : 1427 case Bytecodes::_frem : 1428 current_frame.pop_stack( 1429 VerificationType::float_type(), CHECK_VERIFY(this)); 1430 // fall through 1431 case Bytecodes::_fneg : 1432 current_frame.pop_stack( 1433 VerificationType::float_type(), CHECK_VERIFY(this)); 1434 current_frame.push_stack( 1435 VerificationType::float_type(), CHECK_VERIFY(this)); 1436 no_control_flow = false; break; 1437 case Bytecodes::_dadd : 1438 case Bytecodes::_dsub : 1439 case Bytecodes::_dmul : 1440 case Bytecodes::_ddiv : 1441 case Bytecodes::_drem : 1442 current_frame.pop_stack_2( 1443 VerificationType::double2_type(), 1444 VerificationType::double_type(), CHECK_VERIFY(this)); 1445 // fall through 1446 case Bytecodes::_dneg : 1447 current_frame.pop_stack_2( 1448 VerificationType::double2_type(), 1449 VerificationType::double_type(), CHECK_VERIFY(this)); 1450 current_frame.push_stack_2( 1451 VerificationType::double_type(), 1452 VerificationType::double2_type(), CHECK_VERIFY(this)); 1453 no_control_flow = false; break; 1454 case Bytecodes::_iinc : 1455 verify_iinc(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); 1456 no_control_flow = false; break; 1457 case Bytecodes::_i2l : 1458 type = current_frame.pop_stack( 1459 VerificationType::integer_type(), CHECK_VERIFY(this)); 1460 current_frame.push_stack_2( 1461 VerificationType::long_type(), 1462 VerificationType::long2_type(), CHECK_VERIFY(this)); 1463 no_control_flow = false; break; 1464 case Bytecodes::_l2i : 1465 current_frame.pop_stack_2( 1466 VerificationType::long2_type(), 1467 VerificationType::long_type(), CHECK_VERIFY(this)); 1468 current_frame.push_stack( 1469 VerificationType::integer_type(), CHECK_VERIFY(this)); 1470 no_control_flow = false; break; 1471 case Bytecodes::_i2f : 1472 current_frame.pop_stack( 1473 VerificationType::integer_type(), CHECK_VERIFY(this)); 1474 current_frame.push_stack( 1475 VerificationType::float_type(), CHECK_VERIFY(this)); 1476 no_control_flow = false; break; 1477 case Bytecodes::_i2d : 1478 current_frame.pop_stack( 1479 VerificationType::integer_type(), CHECK_VERIFY(this)); 1480 current_frame.push_stack_2( 1481 VerificationType::double_type(), 1482 VerificationType::double2_type(), CHECK_VERIFY(this)); 1483 no_control_flow = false; break; 1484 case Bytecodes::_l2f : 1485 current_frame.pop_stack_2( 1486 VerificationType::long2_type(), 1487 VerificationType::long_type(), CHECK_VERIFY(this)); 1488 current_frame.push_stack( 1489 VerificationType::float_type(), CHECK_VERIFY(this)); 1490 no_control_flow = false; break; 1491 case Bytecodes::_l2d : 1492 current_frame.pop_stack_2( 1493 VerificationType::long2_type(), 1494 VerificationType::long_type(), CHECK_VERIFY(this)); 1495 current_frame.push_stack_2( 1496 VerificationType::double_type(), 1497 VerificationType::double2_type(), CHECK_VERIFY(this)); 1498 no_control_flow = false; break; 1499 case Bytecodes::_f2i : 1500 current_frame.pop_stack( 1501 VerificationType::float_type(), CHECK_VERIFY(this)); 1502 current_frame.push_stack( 1503 VerificationType::integer_type(), CHECK_VERIFY(this)); 1504 no_control_flow = false; break; 1505 case Bytecodes::_f2l : 1506 current_frame.pop_stack( 1507 VerificationType::float_type(), CHECK_VERIFY(this)); 1508 current_frame.push_stack_2( 1509 VerificationType::long_type(), 1510 VerificationType::long2_type(), CHECK_VERIFY(this)); 1511 no_control_flow = false; break; 1512 case Bytecodes::_f2d : 1513 current_frame.pop_stack( 1514 VerificationType::float_type(), CHECK_VERIFY(this)); 1515 current_frame.push_stack_2( 1516 VerificationType::double_type(), 1517 VerificationType::double2_type(), CHECK_VERIFY(this)); 1518 no_control_flow = false; break; 1519 case Bytecodes::_d2i : 1520 current_frame.pop_stack_2( 1521 VerificationType::double2_type(), 1522 VerificationType::double_type(), CHECK_VERIFY(this)); 1523 current_frame.push_stack( 1524 VerificationType::integer_type(), CHECK_VERIFY(this)); 1525 no_control_flow = false; break; 1526 case Bytecodes::_d2l : 1527 current_frame.pop_stack_2( 1528 VerificationType::double2_type(), 1529 VerificationType::double_type(), CHECK_VERIFY(this)); 1530 current_frame.push_stack_2( 1531 VerificationType::long_type(), 1532 VerificationType::long2_type(), CHECK_VERIFY(this)); 1533 no_control_flow = false; break; 1534 case Bytecodes::_d2f : 1535 current_frame.pop_stack_2( 1536 VerificationType::double2_type(), 1537 VerificationType::double_type(), CHECK_VERIFY(this)); 1538 current_frame.push_stack( 1539 VerificationType::float_type(), CHECK_VERIFY(this)); 1540 no_control_flow = false; break; 1541 case Bytecodes::_i2b : 1542 case Bytecodes::_i2c : 1543 case Bytecodes::_i2s : 1544 current_frame.pop_stack( 1545 VerificationType::integer_type(), CHECK_VERIFY(this)); 1546 current_frame.push_stack( 1547 VerificationType::integer_type(), CHECK_VERIFY(this)); 1548 no_control_flow = false; break; 1549 case Bytecodes::_lcmp : 1550 current_frame.pop_stack_2( 1551 VerificationType::long2_type(), 1552 VerificationType::long_type(), CHECK_VERIFY(this)); 1553 current_frame.pop_stack_2( 1554 VerificationType::long2_type(), 1555 VerificationType::long_type(), CHECK_VERIFY(this)); 1556 current_frame.push_stack( 1557 VerificationType::integer_type(), CHECK_VERIFY(this)); 1558 no_control_flow = false; break; 1559 case Bytecodes::_fcmpl : 1560 case Bytecodes::_fcmpg : 1561 current_frame.pop_stack( 1562 VerificationType::float_type(), CHECK_VERIFY(this)); 1563 current_frame.pop_stack( 1564 VerificationType::float_type(), CHECK_VERIFY(this)); 1565 current_frame.push_stack( 1566 VerificationType::integer_type(), CHECK_VERIFY(this)); 1567 no_control_flow = false; break; 1568 case Bytecodes::_dcmpl : 1569 case Bytecodes::_dcmpg : 1570 current_frame.pop_stack_2( 1571 VerificationType::double2_type(), 1572 VerificationType::double_type(), CHECK_VERIFY(this)); 1573 current_frame.pop_stack_2( 1574 VerificationType::double2_type(), 1575 VerificationType::double_type(), CHECK_VERIFY(this)); 1576 current_frame.push_stack( 1577 VerificationType::integer_type(), CHECK_VERIFY(this)); 1578 no_control_flow = false; break; 1579 case Bytecodes::_if_icmpeq: 1580 case Bytecodes::_if_icmpne: 1581 case Bytecodes::_if_icmplt: 1582 case Bytecodes::_if_icmpge: 1583 case Bytecodes::_if_icmpgt: 1584 case Bytecodes::_if_icmple: 1585 current_frame.pop_stack( 1586 VerificationType::integer_type(), CHECK_VERIFY(this)); 1587 // fall through 1588 case Bytecodes::_ifeq: 1589 case Bytecodes::_ifne: 1590 case Bytecodes::_iflt: 1591 case Bytecodes::_ifge: 1592 case Bytecodes::_ifgt: 1593 case Bytecodes::_ifle: 1594 current_frame.pop_stack( 1595 VerificationType::integer_type(), CHECK_VERIFY(this)); 1596 target = bcs.dest(); 1597 stackmap_table.check_jump_target( 1598 ¤t_frame, target, CHECK_VERIFY(this)); 1599 no_control_flow = false; break; 1600 case Bytecodes::_if_acmpeq : 1601 case Bytecodes::_if_acmpne : 1602 current_frame.pop_stack( 1603 VerificationType::reference_check(), CHECK_VERIFY(this)); 1604 // fall through 1605 case Bytecodes::_ifnull : 1606 case Bytecodes::_ifnonnull : 1607 current_frame.pop_stack( 1608 VerificationType::reference_check(), CHECK_VERIFY(this)); 1609 target = bcs.dest(); 1610 stackmap_table.check_jump_target 1611 (¤t_frame, target, CHECK_VERIFY(this)); 1612 no_control_flow = false; break; 1613 case Bytecodes::_goto : 1614 target = bcs.dest(); 1615 stackmap_table.check_jump_target( 1616 ¤t_frame, target, CHECK_VERIFY(this)); 1617 no_control_flow = true; break; 1618 case Bytecodes::_goto_w : 1619 target = bcs.dest_w(); 1620 stackmap_table.check_jump_target( 1621 ¤t_frame, target, CHECK_VERIFY(this)); 1622 no_control_flow = true; break; 1623 case Bytecodes::_tableswitch : 1624 case Bytecodes::_lookupswitch : 1625 verify_switch( 1626 &bcs, code_length, code_data, ¤t_frame, 1627 &stackmap_table, CHECK_VERIFY(this)); 1628 no_control_flow = true; break; 1629 case Bytecodes::_ireturn : 1630 type = current_frame.pop_stack( 1631 VerificationType::integer_type(), CHECK_VERIFY(this)); 1632 verify_return_value(return_type, type, bci, 1633 ¤t_frame, CHECK_VERIFY(this)); 1634 no_control_flow = true; break; 1635 case Bytecodes::_lreturn : 1636 type2 = current_frame.pop_stack( 1637 VerificationType::long2_type(), CHECK_VERIFY(this)); 1638 type = current_frame.pop_stack( 1639 VerificationType::long_type(), CHECK_VERIFY(this)); 1640 verify_return_value(return_type, type, bci, 1641 ¤t_frame, CHECK_VERIFY(this)); 1642 no_control_flow = true; break; 1643 case Bytecodes::_freturn : 1644 type = current_frame.pop_stack( 1645 VerificationType::float_type(), CHECK_VERIFY(this)); 1646 verify_return_value(return_type, type, bci, 1647 ¤t_frame, CHECK_VERIFY(this)); 1648 no_control_flow = true; break; 1649 case Bytecodes::_dreturn : 1650 type2 = current_frame.pop_stack( 1651 VerificationType::double2_type(), CHECK_VERIFY(this)); 1652 type = current_frame.pop_stack( 1653 VerificationType::double_type(), CHECK_VERIFY(this)); 1654 verify_return_value(return_type, type, bci, 1655 ¤t_frame, CHECK_VERIFY(this)); 1656 no_control_flow = true; break; 1657 case Bytecodes::_areturn : 1658 type = current_frame.pop_stack( 1659 VerificationType::reference_check(), CHECK_VERIFY(this)); 1660 verify_return_value(return_type, type, bci, 1661 ¤t_frame, CHECK_VERIFY(this)); 1662 no_control_flow = true; break; 1663 // case Bytecodes::_vreturn : 1664 // if (!vbytecodes_allowed) { 1665 // class_format_error( 1666 // "vreturn not supported by this class file version (%d.%d), class %s", 1667 // _klass->major_version(), _klass->minor_version(), _klass->external_name()); 1668 // return; 1669 // } 1670 // type = current_frame.pop_stack( 1671 // VerificationType::valuetype_check(), CHECK_VERIFY(this)); 1672 // verify_return_value(return_type, type, bci, 1673 // ¤t_frame, CHECK_VERIFY(this)); 1674 // no_control_flow = true; break; 1675 case Bytecodes::_return : 1676 if (return_type != VerificationType::bogus_type()) { 1677 verify_error(ErrorContext::bad_code(bci), 1678 "Method expects a return value"); 1679 return; 1680 } 1681 // Make sure "this" has been initialized if current method is an 1682 // <init>. 1683 if (_method->name() == vmSymbols::object_initializer_name() && 1684 current_frame.flag_this_uninit()) { 1685 verify_error(ErrorContext::bad_code(bci), 1686 "Constructor must call super() or this() " 1687 "before return"); 1688 return; 1689 } 1690 no_control_flow = true; break; 1691 case Bytecodes::_getstatic : 1692 case Bytecodes::_putstatic : 1693 // pass TRUE, operand can be an array type for getstatic/putstatic. 1694 verify_field_instructions( 1695 &bcs, ¤t_frame, cp, true, CHECK_VERIFY(this)); 1696 no_control_flow = false; break; 1697 case Bytecodes::_getfield : 1698 case Bytecodes::_putfield : 1699 // pass FALSE, operand can't be an array type for getfield/putfield. 1700 verify_field_instructions( 1701 &bcs, ¤t_frame, cp, false, CHECK_VERIFY(this)); 1702 no_control_flow = false; break; 1703 case Bytecodes::_withfield : 1704 if (!vbytecodes_allowed) { 1705 class_format_error( 1706 "vwithfield not supported by this class file version (%d.%d), class %s", 1707 _klass->major_version(), _klass->minor_version(), _klass->external_name()); 1708 return; 1709 } 1710 verify_vwithfield(&bcs, ¤t_frame, cp, CHECK_VERIFY(this)); 1711 no_control_flow = false; break; 1712 case Bytecodes::_invokevirtual : 1713 case Bytecodes::_invokespecial : 1714 case Bytecodes::_invokestatic : 1715 verify_invoke_instructions( 1716 &bcs, code_length, ¤t_frame, (bci >= ex_min && bci < ex_max), 1717 &this_uninit, return_type, cp, &stackmap_table, CHECK_VERIFY(this)); 1718 no_control_flow = false; break; 1719 case Bytecodes::_invokeinterface : 1720 case Bytecodes::_invokedynamic : 1721 verify_invoke_instructions( 1722 &bcs, code_length, ¤t_frame, (bci >= ex_min && bci < ex_max), 1723 &this_uninit, return_type, cp, &stackmap_table, CHECK_VERIFY(this)); 1724 no_control_flow = false; break; 1725 case Bytecodes::_new : 1726 { 1727 index = bcs.get_index_u2(); 1728 verify_cp_class_type(bci, index, cp, CHECK_VERIFY(this)); 1729 VerificationType new_class_type = 1730 cp_index_to_reference_type(index, cp, CHECK_VERIFY(this)); 1731 if (!new_class_type.is_object()) { 1732 verify_error(ErrorContext::bad_type(bci, 1733 TypeOrigin::cp(index, new_class_type)), 1734 "Illegal new instruction"); 1735 return; 1736 } 1737 type = VerificationType::uninitialized_type(bci); 1738 current_frame.push_stack(type, CHECK_VERIFY(this)); 1739 no_control_flow = false; break; 1740 } 1741 case Bytecodes::_defaultvalue : 1742 { 1743 if (!vbytecodes_allowed) { 1744 class_format_error( 1745 "vdefault not supported by this class file version (%d.%d), class %s", 1746 _klass->major_version(), _klass->minor_version(), _klass->external_name()); 1747 return; 1748 } 1749 index = bcs.get_index_u2(); 1750 verify_cp_value_type(bci, index, cp, CHECK_VERIFY(this)); 1751 VerificationType new_value_type = 1752 cp_index_to_valuetype(index, cp, CHECK_VERIFY(this)); 1753 if (!new_value_type.is_valuetype()) { 1754 verify_error(ErrorContext::bad_type(bci, 1755 TypeOrigin::cp(index, new_value_type)), 1756 "Illegal vdefault instruction"); 1757 return; 1758 } 1759 current_frame.push_stack(new_value_type, CHECK_VERIFY(this)); 1760 no_control_flow = false; break; 1761 } 1762 case Bytecodes::_newarray : 1763 type = get_newarray_type(bcs.get_index(), bci, CHECK_VERIFY(this)); 1764 current_frame.pop_stack( 1765 VerificationType::integer_type(), CHECK_VERIFY(this)); 1766 current_frame.push_stack(type, CHECK_VERIFY(this)); 1767 no_control_flow = false; break; 1768 case Bytecodes::_anewarray : 1769 verify_anewarray( 1770 bci, bcs.get_index_u2(), cp, ¤t_frame, CHECK_VERIFY(this)); 1771 no_control_flow = false; break; 1772 case Bytecodes::_arraylength : 1773 type = current_frame.pop_stack( 1774 VerificationType::reference_check(), CHECK_VERIFY(this)); 1775 if (!(type.is_null() || type.is_array())) { 1776 verify_error(ErrorContext::bad_type( 1777 bci, current_frame.stack_top_ctx()), 1778 bad_type_msg, "arraylength"); 1779 } 1780 current_frame.push_stack( 1781 VerificationType::integer_type(), CHECK_VERIFY(this)); 1782 no_control_flow = false; break; 1783 case Bytecodes::_checkcast : 1784 { 1785 index = bcs.get_index_u2(); 1786 verify_cp_class_type(bci, index, cp, CHECK_VERIFY(this)); 1787 current_frame.pop_stack(object_type(), CHECK_VERIFY(this)); 1788 VerificationType klass_type = cp_index_to_reference_type( 1789 index, cp, CHECK_VERIFY(this)); 1790 current_frame.push_stack(klass_type, CHECK_VERIFY(this)); 1791 no_control_flow = false; break; 1792 } 1793 case Bytecodes::_instanceof : { 1794 index = bcs.get_index_u2(); 1795 verify_cp_class_type(bci, index, cp, CHECK_VERIFY(this)); 1796 current_frame.pop_stack(object_type(), CHECK_VERIFY(this)); 1797 current_frame.push_stack( 1798 VerificationType::integer_type(), CHECK_VERIFY(this)); 1799 no_control_flow = false; break; 1800 } 1801 case Bytecodes::_monitorenter : 1802 case Bytecodes::_monitorexit : 1803 current_frame.pop_stack( 1804 VerificationType::reference_check(), CHECK_VERIFY(this)); 1805 no_control_flow = false; break; 1806 case Bytecodes::_multianewarray : 1807 { 1808 index = bcs.get_index_u2(); 1809 u2 dim = *(bcs.bcp()+3); 1810 verify_cp_class_or_value_type(bci, index, cp, CHECK_VERIFY(this)); 1811 VerificationType new_array_type = 1812 cp_index_to_reference_type(index, cp, CHECK_VERIFY(this)); 1813 if (!new_array_type.is_array()) { 1814 verify_error(ErrorContext::bad_type(bci, 1815 TypeOrigin::cp(index, new_array_type)), 1816 "Illegal constant pool index in multianewarray instruction"); 1817 return; 1818 } 1819 if (dim < 1 || new_array_type.dimensions() < dim) { 1820 verify_error(ErrorContext::bad_code(bci), 1821 "Illegal dimension in multianewarray instruction: %d", dim); 1822 return; 1823 } 1824 for (int i = 0; i < dim; i++) { 1825 current_frame.pop_stack( 1826 VerificationType::integer_type(), CHECK_VERIFY(this)); 1827 } 1828 current_frame.push_stack(new_array_type, CHECK_VERIFY(this)); 1829 no_control_flow = false; break; 1830 } 1831 case Bytecodes::_athrow : 1832 type = VerificationType::reference_type( 1833 vmSymbols::java_lang_Throwable()); 1834 current_frame.pop_stack(type, CHECK_VERIFY(this)); 1835 no_control_flow = true; break; 1836 default: 1837 // We only need to check the valid bytecodes in class file. 1838 // And jsr and ret are not in the new class file format in JDK1.5. 1839 verify_error(ErrorContext::bad_code(bci), 1840 "Bad instruction: %02x", opcode); 1841 no_control_flow = false; 1842 return; 1843 } // end switch 1844 } // end Merge with the next instruction 1845 1846 // Look for possible jump target in exception handlers and see if it matches 1847 // current_frame. Don't do this check if it has already been done (for 1848 // ([a,d,f,i,l]store* opcodes). This check cannot be done earlier because 1849 // opcodes, such as invokespecial, may set the this_uninit flag. 1850 assert(!(verified_exc_handlers && this_uninit), 1851 "Exception handler targets got verified before this_uninit got set"); 1852 if (!verified_exc_handlers && bci >= ex_min && bci < ex_max) { 1853 if (was_recursively_verified()) return; 1854 verify_exception_handler_targets( 1855 bci, this_uninit, ¤t_frame, &stackmap_table, CHECK_VERIFY(this)); 1856 } 1857 } // end while 1858 1859 // Make sure that control flow does not fall through end of the method 1860 if (!no_control_flow) { 1861 verify_error(ErrorContext::bad_code(code_length), 1862 "Control flow falls through code end"); 1863 return; 1864 } 1865 } 1866 1867 #undef bad_type_message 1868 1869 char* ClassVerifier::generate_code_data(const methodHandle& m, u4 code_length, TRAPS) { 1870 char* code_data = NEW_RESOURCE_ARRAY(char, code_length); 1871 memset(code_data, 0, sizeof(char) * code_length); 1872 RawBytecodeStream bcs(m); 1873 1874 while (!bcs.is_last_bytecode()) { 1875 if (bcs.raw_next() != Bytecodes::_illegal) { 1876 int bci = bcs.bci(); 1877 if (bcs.raw_code() == Bytecodes::_new) { 1878 code_data[bci] = NEW_OFFSET; 1879 } else { 1880 code_data[bci] = BYTECODE_OFFSET; 1881 } 1882 } else { 1883 verify_error(ErrorContext::bad_code(bcs.bci()), "Bad instruction"); 1884 return NULL; 1885 } 1886 } 1887 1888 return code_data; 1889 } 1890 1891 // Since this method references the constant pool, call was_recursively_verified() 1892 // before calling this method to make sure a prior class load did not cause the 1893 // current class to get verified. 1894 void ClassVerifier::verify_exception_handler_table(u4 code_length, char* code_data, int& min, int& max, TRAPS) { 1895 ExceptionTable exhandlers(_method()); 1896 int exlength = exhandlers.length(); 1897 constantPoolHandle cp (THREAD, _method->constants()); 1898 1899 for(int i = 0; i < exlength; i++) { 1900 u2 start_pc = exhandlers.start_pc(i); 1901 u2 end_pc = exhandlers.end_pc(i); 1902 u2 handler_pc = exhandlers.handler_pc(i); 1903 if (start_pc >= code_length || code_data[start_pc] == 0) { 1904 class_format_error("Illegal exception table start_pc %d", start_pc); 1905 return; 1906 } 1907 if (end_pc != code_length) { // special case: end_pc == code_length 1908 if (end_pc > code_length || code_data[end_pc] == 0) { 1909 class_format_error("Illegal exception table end_pc %d", end_pc); 1910 return; 1911 } 1912 } 1913 if (handler_pc >= code_length || code_data[handler_pc] == 0) { 1914 class_format_error("Illegal exception table handler_pc %d", handler_pc); 1915 return; 1916 } 1917 int catch_type_index = exhandlers.catch_type_index(i); 1918 if (catch_type_index != 0) { 1919 VerificationType catch_type = cp_index_to_reference_type( 1920 catch_type_index, cp, CHECK_VERIFY(this)); 1921 VerificationType throwable = 1922 VerificationType::reference_type(vmSymbols::java_lang_Throwable()); 1923 bool is_subclass = throwable.is_assignable_from( 1924 catch_type, this, false, CHECK_VERIFY(this)); 1925 if (!is_subclass) { 1926 // 4286534: should throw VerifyError according to recent spec change 1927 verify_error(ErrorContext::bad_type(handler_pc, 1928 TypeOrigin::cp(catch_type_index, catch_type), 1929 TypeOrigin::implicit(throwable)), 1930 "Catch type is not a subclass " 1931 "of Throwable in exception handler %d", handler_pc); 1932 return; 1933 } 1934 } 1935 if (start_pc < min) min = start_pc; 1936 if (end_pc > max) max = end_pc; 1937 } 1938 } 1939 1940 void ClassVerifier::verify_local_variable_table(u4 code_length, char* code_data, TRAPS) { 1941 int localvariable_table_length = _method->localvariable_table_length(); 1942 if (localvariable_table_length > 0) { 1943 LocalVariableTableElement* table = _method->localvariable_table_start(); 1944 for (int i = 0; i < localvariable_table_length; i++) { 1945 u2 start_bci = table[i].start_bci; 1946 u2 length = table[i].length; 1947 1948 if (start_bci >= code_length || code_data[start_bci] == 0) { 1949 class_format_error( 1950 "Illegal local variable table start_pc %d", start_bci); 1951 return; 1952 } 1953 u4 end_bci = (u4)(start_bci + length); 1954 if (end_bci != code_length) { 1955 if (end_bci >= code_length || code_data[end_bci] == 0) { 1956 class_format_error( "Illegal local variable table length %d", length); 1957 return; 1958 } 1959 } 1960 } 1961 } 1962 } 1963 1964 u2 ClassVerifier::verify_stackmap_table(u2 stackmap_index, u2 bci, 1965 StackMapFrame* current_frame, 1966 StackMapTable* stackmap_table, 1967 bool no_control_flow, TRAPS) { 1968 if (stackmap_index < stackmap_table->get_frame_count()) { 1969 u2 this_offset = stackmap_table->get_offset(stackmap_index); 1970 if (no_control_flow && this_offset > bci) { 1971 verify_error(ErrorContext::missing_stackmap(bci), 1972 "Expecting a stack map frame"); 1973 return 0; 1974 } 1975 if (this_offset == bci) { 1976 ErrorContext ctx; 1977 // See if current stack map can be assigned to the frame in table. 1978 // current_frame is the stackmap frame got from the last instruction. 1979 // If matched, current_frame will be updated by this method. 1980 bool matches = stackmap_table->match_stackmap( 1981 current_frame, this_offset, stackmap_index, 1982 !no_control_flow, true, &ctx, CHECK_VERIFY_(this, 0)); 1983 if (!matches) { 1984 // report type error 1985 verify_error(ctx, "Instruction type does not match stack map"); 1986 return 0; 1987 } 1988 stackmap_index++; 1989 } else if (this_offset < bci) { 1990 // current_offset should have met this_offset. 1991 class_format_error("Bad stack map offset %d", this_offset); 1992 return 0; 1993 } 1994 } else if (no_control_flow) { 1995 verify_error(ErrorContext::bad_code(bci), "Expecting a stack map frame"); 1996 return 0; 1997 } 1998 return stackmap_index; 1999 } 2000 2001 // Since this method references the constant pool, call was_recursively_verified() 2002 // before calling this method to make sure a prior class load did not cause the 2003 // current class to get verified. 2004 void ClassVerifier::verify_exception_handler_targets(u2 bci, bool this_uninit, 2005 StackMapFrame* current_frame, 2006 StackMapTable* stackmap_table, TRAPS) { 2007 constantPoolHandle cp (THREAD, _method->constants()); 2008 ExceptionTable exhandlers(_method()); 2009 int exlength = exhandlers.length(); 2010 for(int i = 0; i < exlength; i++) { 2011 u2 start_pc = exhandlers.start_pc(i); 2012 u2 end_pc = exhandlers.end_pc(i); 2013 u2 handler_pc = exhandlers.handler_pc(i); 2014 int catch_type_index = exhandlers.catch_type_index(i); 2015 if(bci >= start_pc && bci < end_pc) { 2016 u1 flags = current_frame->flags(); 2017 if (this_uninit) { flags |= FLAG_THIS_UNINIT; } 2018 StackMapFrame* new_frame = current_frame->frame_in_exception_handler(flags); 2019 if (catch_type_index != 0) { 2020 if (was_recursively_verified()) return; 2021 // We know that this index refers to a subclass of Throwable 2022 VerificationType catch_type = cp_index_to_reference_type( 2023 catch_type_index, cp, CHECK_VERIFY(this)); 2024 new_frame->push_stack(catch_type, CHECK_VERIFY(this)); 2025 } else { 2026 VerificationType throwable = 2027 VerificationType::reference_type(vmSymbols::java_lang_Throwable()); 2028 new_frame->push_stack(throwable, CHECK_VERIFY(this)); 2029 } 2030 ErrorContext ctx; 2031 bool matches = stackmap_table->match_stackmap( 2032 new_frame, handler_pc, true, false, &ctx, CHECK_VERIFY(this)); 2033 if (!matches) { 2034 verify_error(ctx, "Stack map does not match the one at " 2035 "exception handler %d", handler_pc); 2036 return; 2037 } 2038 } 2039 } 2040 } 2041 2042 void ClassVerifier::verify_cp_index( 2043 u2 bci, const constantPoolHandle& cp, int index, TRAPS) { 2044 int nconstants = cp->length(); 2045 if ((index <= 0) || (index >= nconstants)) { 2046 verify_error(ErrorContext::bad_cp_index(bci, index), 2047 "Illegal constant pool index %d in class %s", 2048 index, cp->pool_holder()->external_name()); 2049 return; 2050 } 2051 } 2052 2053 void ClassVerifier::verify_cp_type( 2054 u2 bci, int index, const constantPoolHandle& cp, unsigned int types, TRAPS) { 2055 2056 // In some situations, bytecode rewriting may occur while we're verifying. 2057 // In this case, a constant pool cache exists and some indices refer to that 2058 // instead. Be sure we don't pick up such indices by accident. 2059 // We must check was_recursively_verified() before we get here. 2060 guarantee(cp->cache() == NULL, "not rewritten yet"); 2061 2062 verify_cp_index(bci, cp, index, CHECK_VERIFY(this)); 2063 unsigned int tag = cp->tag_at(index).value(); 2064 2065 if (tag == JVM_CONSTANT_Value) { 2066 tag = SAFE_JVM_CONSTANT_Value; //avoid overflow 2067 } 2068 2069 if ((types & (1 << tag)) == 0) { 2070 verify_error(ErrorContext::bad_cp_index(bci, index), 2071 "Illegal type at constant pool entry %d in class %s", 2072 index, cp->pool_holder()->external_name()); 2073 return; 2074 } 2075 } 2076 2077 void ClassVerifier::verify_cp_class_type( 2078 u2 bci, int index, const constantPoolHandle& cp, TRAPS) { 2079 verify_cp_index(bci, cp, index, CHECK_VERIFY(this)); 2080 constantTag tag = cp->tag_at(index); 2081 if (!tag.is_klass() && !tag.is_unresolved_klass()) { 2082 verify_error(ErrorContext::bad_cp_index(bci, index), 2083 "Illegal type at constant pool entry %d in class %s", 2084 index, cp->pool_holder()->external_name()); 2085 return; 2086 } 2087 } 2088 2089 void ClassVerifier::verify_cp_value_type( 2090 u2 bci, int index, const constantPoolHandle& cp, TRAPS) { 2091 verify_cp_index(bci, cp, index, CHECK_VERIFY(this)); 2092 constantTag tag = cp->tag_at(index); 2093 if (!tag.is_value_type() && !tag.is_unresolved_value_type()) { 2094 verify_error(ErrorContext::bad_cp_index(bci, index), 2095 "Illegal type at constant pool entry %d in class %s", 2096 index, cp->pool_holder()->external_name()); 2097 return; 2098 } 2099 } 2100 2101 // Used for MVT value type overloaded bytecodes (anewarray, getfield, multianewarray) 2102 void ClassVerifier::verify_cp_class_or_value_type( 2103 u2 bci, int index, const constantPoolHandle& cp, TRAPS) { 2104 verify_cp_index(bci, cp, index, CHECK_VERIFY(this)); 2105 constantTag tag = cp->tag_at(index); 2106 if (!tag.is_klass() && !tag.is_unresolved_klass() && 2107 !tag.is_value_type() && !tag.is_unresolved_value_type()) { 2108 verify_error(ErrorContext::bad_cp_index(bci, index), 2109 "Illegal type at constant pool entry %d in class %s", 2110 index, cp->pool_holder()->external_name()); 2111 return; 2112 } 2113 } 2114 2115 void ClassVerifier::verify_error(ErrorContext ctx, const char* msg, ...) { 2116 stringStream ss; 2117 2118 ctx.reset_frames(); 2119 _exception_type = vmSymbols::java_lang_VerifyError(); 2120 _error_context = ctx; 2121 va_list va; 2122 va_start(va, msg); 2123 ss.vprint(msg, va); 2124 va_end(va); 2125 _message = ss.as_string(); 2126 #ifdef ASSERT 2127 ResourceMark rm; 2128 const char* exception_name = _exception_type->as_C_string(); 2129 Exceptions::debug_check_abort(exception_name, NULL); 2130 #endif // ndef ASSERT 2131 } 2132 2133 void ClassVerifier::class_format_error(const char* msg, ...) { 2134 stringStream ss; 2135 _exception_type = vmSymbols::java_lang_ClassFormatError(); 2136 va_list va; 2137 va_start(va, msg); 2138 ss.vprint(msg, va); 2139 va_end(va); 2140 if (!_method.is_null()) { 2141 ss.print(" in method %s", _method->name_and_sig_as_C_string()); 2142 } 2143 _message = ss.as_string(); 2144 } 2145 2146 Klass* ClassVerifier::load_class(Symbol* name, TRAPS) { 2147 HandleMark hm(THREAD); 2148 // Get current loader and protection domain first. 2149 oop loader = current_class()->class_loader(); 2150 oop protection_domain = current_class()->protection_domain(); 2151 2152 Klass* kls = SystemDictionary::resolve_or_fail( 2153 name, Handle(THREAD, loader), Handle(THREAD, protection_domain), 2154 true, THREAD); 2155 2156 if (log_is_enabled(Debug, class, resolve)) { 2157 InstanceKlass* cur_class = InstanceKlass::cast(current_class()); 2158 Verifier::trace_class_resolution(kls, cur_class); 2159 } 2160 return kls; 2161 } 2162 2163 bool ClassVerifier::is_protected_access(InstanceKlass* this_class, 2164 Klass* target_class, 2165 Symbol* field_name, 2166 Symbol* field_sig, 2167 bool is_method) { 2168 NoSafepointVerifier nosafepoint; 2169 2170 // If target class isn't a super class of this class, we don't worry about this case 2171 if (!this_class->is_subclass_of(target_class)) { 2172 return false; 2173 } 2174 // Check if the specified method or field is protected 2175 InstanceKlass* target_instance = InstanceKlass::cast(target_class); 2176 fieldDescriptor fd; 2177 if (is_method) { 2178 Method* m = target_instance->uncached_lookup_method(field_name, field_sig, Klass::find_overpass); 2179 if (m != NULL && m->is_protected()) { 2180 if (!this_class->is_same_class_package(m->method_holder())) { 2181 return true; 2182 } 2183 } 2184 } else { 2185 Klass* member_klass = target_instance->find_field(field_name, field_sig, &fd); 2186 if (member_klass != NULL && fd.is_protected()) { 2187 if (!this_class->is_same_class_package(member_klass)) { 2188 return true; 2189 } 2190 } 2191 } 2192 return false; 2193 } 2194 2195 void ClassVerifier::verify_ldc( 2196 int opcode, u2 index, StackMapFrame* current_frame, 2197 const constantPoolHandle& cp, u2 bci, TRAPS) { 2198 verify_cp_index(bci, cp, index, CHECK_VERIFY(this)); 2199 constantTag tag = cp->tag_at(index); 2200 unsigned int types = 0; 2201 if (opcode == Bytecodes::_ldc || opcode == Bytecodes::_ldc_w) { 2202 if (!tag.is_unresolved_klass() && !tag.is_unresolved_value_type()) { 2203 types = (1 << JVM_CONSTANT_Integer) | (1 << JVM_CONSTANT_Float) 2204 | (1 << JVM_CONSTANT_String) | (1 << JVM_CONSTANT_Class) 2205 | (1 << SAFE_JVM_CONSTANT_Value) 2206 | (1 << JVM_CONSTANT_MethodHandle) | (1 << JVM_CONSTANT_MethodType) 2207 | (1 << JVM_CONSTANT_Dynamic); 2208 // Note: The class file parser already verified the legality of 2209 // MethodHandle and MethodType constants. 2210 // Note: SAFE_JVM_CONSTANT_Value is used instead of JVM_CONSTANT_Value 2211 // since JVM_CONSTANT_Value is an internally defined CP tag that is 2212 // defined with a large value. When shifting left JVM_CONSTANT_Value 2213 // would overrun the width of types. 2214 verify_cp_type(bci, index, cp, types, CHECK_VERIFY(this)); 2215 } 2216 } else { 2217 assert(opcode == Bytecodes::_ldc2_w, "must be ldc2_w"); 2218 types = (1 << JVM_CONSTANT_Double) | (1 << JVM_CONSTANT_Long) 2219 | (1 << JVM_CONSTANT_Dynamic); 2220 verify_cp_type(bci, index, cp, types, CHECK_VERIFY(this)); 2221 } 2222 if (tag.is_string() && cp->is_pseudo_string_at(index)) { 2223 current_frame->push_stack(object_type(), CHECK_VERIFY(this)); 2224 } else if (tag.is_string()) { 2225 current_frame->push_stack( 2226 VerificationType::reference_type( 2227 vmSymbols::java_lang_String()), CHECK_VERIFY(this)); 2228 } else if (tag.is_klass() || tag.is_unresolved_klass() || 2229 tag.is_value_type() || tag.is_unresolved_value_type()) { 2230 current_frame->push_stack( 2231 VerificationType::reference_type( 2232 vmSymbols::java_lang_Class()), CHECK_VERIFY(this)); 2233 } else if (tag.is_int()) { 2234 current_frame->push_stack( 2235 VerificationType::integer_type(), CHECK_VERIFY(this)); 2236 } else if (tag.is_float()) { 2237 current_frame->push_stack( 2238 VerificationType::float_type(), CHECK_VERIFY(this)); 2239 } else if (tag.is_double()) { 2240 current_frame->push_stack_2( 2241 VerificationType::double_type(), 2242 VerificationType::double2_type(), CHECK_VERIFY(this)); 2243 } else if (tag.is_long()) { 2244 current_frame->push_stack_2( 2245 VerificationType::long_type(), 2246 VerificationType::long2_type(), CHECK_VERIFY(this)); 2247 } else if (tag.is_method_handle()) { 2248 current_frame->push_stack( 2249 VerificationType::reference_type( 2250 vmSymbols::java_lang_invoke_MethodHandle()), CHECK_VERIFY(this)); 2251 } else if (tag.is_method_type()) { 2252 current_frame->push_stack( 2253 VerificationType::reference_type( 2254 vmSymbols::java_lang_invoke_MethodType()), CHECK_VERIFY(this)); 2255 } else if (tag.is_dynamic_constant()) { 2256 Symbol* constant_type = cp->uncached_signature_ref_at(index); 2257 if (!SignatureVerifier::is_valid_type_signature(constant_type)) { 2258 class_format_error( 2259 "Invalid type for dynamic constant in class %s referenced " 2260 "from constant pool index %d", _klass->external_name(), index); 2261 return; 2262 } 2263 assert(sizeof(VerificationType) == sizeof(uintptr_t), 2264 "buffer type must match VerificationType size"); 2265 uintptr_t constant_type_buffer[2]; 2266 VerificationType* v_constant_type = (VerificationType*)constant_type_buffer; 2267 SignatureStream sig_stream(constant_type, false); 2268 int n = change_sig_to_verificationType( 2269 &sig_stream, v_constant_type, CHECK_VERIFY(this)); 2270 int opcode_n = (opcode == Bytecodes::_ldc2_w ? 2 : 1); 2271 if (n != opcode_n) { 2272 // wrong kind of ldc; reverify against updated type mask 2273 types &= ~(1 << JVM_CONSTANT_Dynamic); 2274 verify_cp_type(bci, index, cp, types, CHECK_VERIFY(this)); 2275 } 2276 for (int i = 0; i < n; i++) { 2277 current_frame->push_stack(v_constant_type[i], CHECK_VERIFY(this)); 2278 } 2279 } else { 2280 /* Unreachable? verify_cp_type has already validated the cp type. */ 2281 verify_error( 2282 ErrorContext::bad_cp_index(bci, index), "Invalid index in ldc"); 2283 return; 2284 } 2285 } 2286 2287 void ClassVerifier::verify_switch( 2288 RawBytecodeStream* bcs, u4 code_length, char* code_data, 2289 StackMapFrame* current_frame, StackMapTable* stackmap_table, TRAPS) { 2290 int bci = bcs->bci(); 2291 address bcp = bcs->bcp(); 2292 address aligned_bcp = align_up(bcp + 1, jintSize); 2293 2294 if (_klass->major_version() < NONZERO_PADDING_BYTES_IN_SWITCH_MAJOR_VERSION) { 2295 // 4639449 & 4647081: padding bytes must be 0 2296 u2 padding_offset = 1; 2297 while ((bcp + padding_offset) < aligned_bcp) { 2298 if(*(bcp + padding_offset) != 0) { 2299 verify_error(ErrorContext::bad_code(bci), 2300 "Nonzero padding byte in lookupswitch or tableswitch"); 2301 return; 2302 } 2303 padding_offset++; 2304 } 2305 } 2306 2307 int default_offset = (int) Bytes::get_Java_u4(aligned_bcp); 2308 int keys, delta; 2309 current_frame->pop_stack( 2310 VerificationType::integer_type(), CHECK_VERIFY(this)); 2311 if (bcs->raw_code() == Bytecodes::_tableswitch) { 2312 jint low = (jint)Bytes::get_Java_u4(aligned_bcp + jintSize); 2313 jint high = (jint)Bytes::get_Java_u4(aligned_bcp + 2*jintSize); 2314 if (low > high) { 2315 verify_error(ErrorContext::bad_code(bci), 2316 "low must be less than or equal to high in tableswitch"); 2317 return; 2318 } 2319 keys = high - low + 1; 2320 if (keys < 0) { 2321 verify_error(ErrorContext::bad_code(bci), "too many keys in tableswitch"); 2322 return; 2323 } 2324 delta = 1; 2325 } else { 2326 keys = (int)Bytes::get_Java_u4(aligned_bcp + jintSize); 2327 if (keys < 0) { 2328 verify_error(ErrorContext::bad_code(bci), 2329 "number of keys in lookupswitch less than 0"); 2330 return; 2331 } 2332 delta = 2; 2333 // Make sure that the lookupswitch items are sorted 2334 for (int i = 0; i < (keys - 1); i++) { 2335 jint this_key = Bytes::get_Java_u4(aligned_bcp + (2+2*i)*jintSize); 2336 jint next_key = Bytes::get_Java_u4(aligned_bcp + (2+2*i+2)*jintSize); 2337 if (this_key >= next_key) { 2338 verify_error(ErrorContext::bad_code(bci), 2339 "Bad lookupswitch instruction"); 2340 return; 2341 } 2342 } 2343 } 2344 int target = bci + default_offset; 2345 stackmap_table->check_jump_target(current_frame, target, CHECK_VERIFY(this)); 2346 for (int i = 0; i < keys; i++) { 2347 // Because check_jump_target() may safepoint, the bytecode could have 2348 // moved, which means 'aligned_bcp' is no good and needs to be recalculated. 2349 aligned_bcp = align_up(bcs->bcp() + 1, jintSize); 2350 target = bci + (jint)Bytes::get_Java_u4(aligned_bcp+(3+i*delta)*jintSize); 2351 stackmap_table->check_jump_target( 2352 current_frame, target, CHECK_VERIFY(this)); 2353 } 2354 NOT_PRODUCT(aligned_bcp = NULL); // no longer valid at this point 2355 } 2356 2357 bool ClassVerifier::name_in_supers( 2358 Symbol* ref_name, InstanceKlass* current) { 2359 Klass* super = current->super(); 2360 while (super != NULL) { 2361 if (super->name() == ref_name) { 2362 return true; 2363 } 2364 super = super->super(); 2365 } 2366 return false; 2367 } 2368 2369 void ClassVerifier::verify_field_instructions(RawBytecodeStream* bcs, 2370 StackMapFrame* current_frame, 2371 const constantPoolHandle& cp, 2372 bool allow_arrays, 2373 TRAPS) { 2374 u2 index = bcs->get_index_u2(); 2375 verify_cp_type(bcs->bci(), index, cp, 2376 1 << JVM_CONSTANT_Fieldref, CHECK_VERIFY(this)); 2377 2378 // Get field name and signature 2379 Symbol* field_name = cp->name_ref_at(index); 2380 Symbol* field_sig = cp->signature_ref_at(index); 2381 2382 if (!SignatureVerifier::is_valid_type_signature(field_sig)) { 2383 class_format_error( 2384 "Invalid signature for field in class %s referenced " 2385 "from constant pool index %d", _klass->external_name(), index); 2386 return; 2387 } 2388 2389 // Get referenced class or value type 2390 constantTag field_class_tag = cp->tag_at(cp->klass_ref_index_at(index)); 2391 VerificationType ref_class_type; 2392 2393 // getfield is overloaded to allow for either a reference or value type 2394 if (bcs->raw_code() == Bytecodes::_getfield && 2395 (EnableMVT || EnableValhalla) && 2396 (field_class_tag.is_value_type() || field_class_tag.is_unresolved_value_type())) { 2397 ref_class_type = cp_value_index_to_type(index, cp, CHECK_VERIFY(this)); 2398 if (!ref_class_type.is_valuetype()) { 2399 verify_error(ErrorContext::bad_type(bcs->bci(), 2400 TypeOrigin::cp(index, ref_class_type)), 2401 "Expecting reference to value type in class %s at constant pool index %d", 2402 _klass->external_name(), index); 2403 return; 2404 } 2405 } else { 2406 ref_class_type = cp_ref_index_to_type(index, cp, CHECK_VERIFY(this)); 2407 if (!ref_class_type.is_object() && 2408 (!allow_arrays || !ref_class_type.is_array())) { 2409 verify_error(ErrorContext::bad_type(bcs->bci(), 2410 TypeOrigin::cp(index, ref_class_type)), 2411 "Expecting reference to class in class %s at constant pool index %d", 2412 _klass->external_name(), index); 2413 return; 2414 } 2415 } 2416 2417 VerificationType target_class_type = ref_class_type; 2418 2419 assert(sizeof(VerificationType) == sizeof(uintptr_t), 2420 "buffer type must match VerificationType size"); 2421 uintptr_t field_type_buffer[2]; 2422 VerificationType* field_type = (VerificationType*)field_type_buffer; 2423 // If we make a VerificationType[2] array directly, the compiler calls 2424 // to the c-runtime library to do the allocation instead of just 2425 // stack allocating it. Plus it would run constructors. This shows up 2426 // in performance profiles. 2427 2428 SignatureStream sig_stream(field_sig, false); 2429 VerificationType stack_object_type; 2430 int n = change_sig_to_verificationType( 2431 &sig_stream, field_type, CHECK_VERIFY(this)); 2432 u2 bci = bcs->bci(); 2433 bool is_assignable; 2434 switch (bcs->raw_code()) { 2435 case Bytecodes::_getstatic: { 2436 for (int i = 0; i < n; i++) { 2437 current_frame->push_stack(field_type[i], CHECK_VERIFY(this)); 2438 } 2439 break; 2440 } 2441 case Bytecodes::_putstatic: { 2442 for (int i = n - 1; i >= 0; i--) { 2443 current_frame->pop_stack(field_type[i], CHECK_VERIFY(this)); 2444 } 2445 break; 2446 } 2447 case Bytecodes::_getfield: { 2448 stack_object_type = current_frame->pop_stack( 2449 target_class_type, CHECK_VERIFY(this)); 2450 for (int i = 0; i < n; i++) { 2451 current_frame->push_stack(field_type[i], CHECK_VERIFY(this)); 2452 } 2453 goto check_protected; 2454 } 2455 case Bytecodes::_putfield: { 2456 for (int i = n - 1; i >= 0; i--) { 2457 current_frame->pop_stack(field_type[i], CHECK_VERIFY(this)); 2458 } 2459 stack_object_type = current_frame->pop_stack(CHECK_VERIFY(this)); 2460 2461 // The JVMS 2nd edition allows field initialization before the superclass 2462 // initializer, if the field is defined within the current class. 2463 fieldDescriptor fd; 2464 if (stack_object_type == VerificationType::uninitialized_this_type() && 2465 target_class_type.equals(current_type()) && 2466 _klass->find_local_field(field_name, field_sig, &fd)) { 2467 stack_object_type = current_type(); 2468 } 2469 is_assignable = target_class_type.is_assignable_from( 2470 stack_object_type, this, false, CHECK_VERIFY(this)); 2471 if (!is_assignable) { 2472 verify_error(ErrorContext::bad_type(bci, 2473 current_frame->stack_top_ctx(), 2474 TypeOrigin::cp(index, target_class_type)), 2475 "Bad type on operand stack in putfield"); 2476 return; 2477 } 2478 } 2479 check_protected: { 2480 if (_this_type == stack_object_type) 2481 break; // stack_object_type must be assignable to _current_class_type 2482 if (was_recursively_verified()) return; 2483 Symbol* ref_class_name = 2484 cp->klass_name_at(cp->klass_ref_index_at(index)); 2485 if (!name_in_supers(ref_class_name, current_class())) 2486 // stack_object_type must be assignable to _current_class_type since: 2487 // 1. stack_object_type must be assignable to ref_class. 2488 // 2. ref_class must be _current_class or a subclass of it. It can't 2489 // be a superclass of it. See revised JVMS 5.4.4. 2490 break; 2491 2492 Klass* ref_class_oop = load_class(ref_class_name, CHECK); 2493 if (is_protected_access(current_class(), ref_class_oop, field_name, 2494 field_sig, false)) { 2495 // It's protected access, check if stack object is assignable to 2496 // current class. 2497 is_assignable = current_type().is_assignable_from( 2498 stack_object_type, this, true, CHECK_VERIFY(this)); 2499 if (!is_assignable) { 2500 verify_error(ErrorContext::bad_type(bci, 2501 current_frame->stack_top_ctx(), 2502 TypeOrigin::implicit(current_type())), 2503 "Bad access to protected data in getfield"); 2504 return; 2505 } 2506 } 2507 break; 2508 } 2509 default: ShouldNotReachHere(); 2510 } 2511 } 2512 2513 void ClassVerifier::verify_vwithfield(RawBytecodeStream* bcs, 2514 StackMapFrame* current_frame, 2515 const constantPoolHandle& cp, 2516 TRAPS) { 2517 u2 index = bcs->get_index_u2(); 2518 verify_cp_type(bcs->bci(), index, cp, 2519 1 << JVM_CONSTANT_Fieldref, CHECK_VERIFY(this)); 2520 2521 // Get field name and signature 2522 Symbol* field_name = cp->name_ref_at(index); 2523 Symbol* field_sig = cp->signature_ref_at(index); 2524 2525 if (!SignatureVerifier::is_valid_type_signature(field_sig)) { 2526 class_format_error( 2527 "Invalid signature for field in value type %s referenced " 2528 "from constant pool index %d", _klass->external_name(), index); 2529 return; 2530 } 2531 2532 // Check referenced value type 2533 VerificationType ref_value_type = cp_value_index_to_type( 2534 index, cp, CHECK_VERIFY(this)); 2535 if (!ref_value_type.is_valuetype()) { 2536 verify_error(ErrorContext::bad_type(bcs->bci(), 2537 TypeOrigin::cp(index, ref_value_type)), 2538 "Expecting reference to value type in class %s at constant pool index %d", 2539 _klass->external_name(), index); 2540 return; 2541 } 2542 VerificationType target_value_type = ref_value_type; 2543 2544 assert(sizeof(VerificationType) == sizeof(uintptr_t), 2545 "buffer type must match VerificationType size"); 2546 uintptr_t field_type_buffer[2]; 2547 VerificationType* field_type = (VerificationType*)field_type_buffer; 2548 // If we make a VerificationType[2] array directly, the compiler calls 2549 // to the c-runtime library to do the allocation instead of just 2550 // stack allocating it. Plus it would run constructors. This shows up 2551 // in performance profiles. 2552 2553 SignatureStream sig_stream(field_sig, false); 2554 int n = change_sig_to_verificationType( 2555 &sig_stream, field_type, CHECK_VERIFY(this)); 2556 u2 bci = bcs->bci(); 2557 2558 // The type of value2 must be compatible with the descriptor of the referenced field. 2559 // n could be 2 if it is a double or long. 2560 for (int i = n - 1; i >= 0; i--) { 2561 current_frame->pop_stack(field_type[i], CHECK_VERIFY(this)); 2562 } 2563 2564 // The type of value1 must be the direct value class type appearing in the field reference. 2565 VerificationType stack_object_type = current_frame->pop_stack(CHECK_VERIFY(this)); 2566 2567 bool is_assignable = target_value_type.is_assignable_from( 2568 stack_object_type, this, false, CHECK_VERIFY(this)); 2569 if (!is_assignable) { 2570 verify_error(ErrorContext::bad_type(bci, 2571 current_frame->stack_top_ctx(), 2572 TypeOrigin::cp(index, target_value_type)), 2573 "Bad type on operand stack in vwithfield"); 2574 return; 2575 } 2576 2577 // The derived value class instance from another, modifying a field 2578 current_frame->push_stack(stack_object_type, CHECK_VERIFY(this)); 2579 } 2580 2581 // Look at the method's handlers. If the bci is in the handler's try block 2582 // then check if the handler_pc is already on the stack. If not, push it 2583 // unless the handler has already been scanned. 2584 void ClassVerifier::push_handlers(ExceptionTable* exhandlers, 2585 GrowableArray<u4>* handler_list, 2586 GrowableArray<u4>* handler_stack, 2587 u4 bci) { 2588 int exlength = exhandlers->length(); 2589 for(int x = 0; x < exlength; x++) { 2590 if (bci >= exhandlers->start_pc(x) && bci < exhandlers->end_pc(x)) { 2591 u4 exhandler_pc = exhandlers->handler_pc(x); 2592 if (!handler_list->contains(exhandler_pc)) { 2593 handler_stack->append_if_missing(exhandler_pc); 2594 handler_list->append(exhandler_pc); 2595 } 2596 } 2597 } 2598 } 2599 2600 // Return TRUE if all code paths starting with start_bc_offset end in 2601 // bytecode athrow or loop. 2602 bool ClassVerifier::ends_in_athrow(u4 start_bc_offset) { 2603 ResourceMark rm; 2604 // Create bytecode stream. 2605 RawBytecodeStream bcs(method()); 2606 u4 code_length = method()->code_size(); 2607 bcs.set_start(start_bc_offset); 2608 u4 target; 2609 // Create stack for storing bytecode start offsets for if* and *switch. 2610 GrowableArray<u4>* bci_stack = new GrowableArray<u4>(30); 2611 // Create stack for handlers for try blocks containing this handler. 2612 GrowableArray<u4>* handler_stack = new GrowableArray<u4>(30); 2613 // Create list of handlers that have been pushed onto the handler_stack 2614 // so that handlers embedded inside of their own TRY blocks only get 2615 // scanned once. 2616 GrowableArray<u4>* handler_list = new GrowableArray<u4>(30); 2617 // Create list of visited branch opcodes (goto* and if*). 2618 GrowableArray<u4>* visited_branches = new GrowableArray<u4>(30); 2619 ExceptionTable exhandlers(_method()); 2620 2621 while (true) { 2622 if (bcs.is_last_bytecode()) { 2623 // if no more starting offsets to parse or if at the end of the 2624 // method then return false. 2625 if ((bci_stack->is_empty()) || ((u4)bcs.end_bci() == code_length)) 2626 return false; 2627 // Pop a bytecode starting offset and scan from there. 2628 bcs.set_start(bci_stack->pop()); 2629 } 2630 Bytecodes::Code opcode = bcs.raw_next(); 2631 u4 bci = bcs.bci(); 2632 2633 // If the bytecode is in a TRY block, push its handlers so they 2634 // will get parsed. 2635 push_handlers(&exhandlers, handler_list, handler_stack, bci); 2636 2637 switch (opcode) { 2638 case Bytecodes::_if_icmpeq: 2639 case Bytecodes::_if_icmpne: 2640 case Bytecodes::_if_icmplt: 2641 case Bytecodes::_if_icmpge: 2642 case Bytecodes::_if_icmpgt: 2643 case Bytecodes::_if_icmple: 2644 case Bytecodes::_ifeq: 2645 case Bytecodes::_ifne: 2646 case Bytecodes::_iflt: 2647 case Bytecodes::_ifge: 2648 case Bytecodes::_ifgt: 2649 case Bytecodes::_ifle: 2650 case Bytecodes::_if_acmpeq: 2651 case Bytecodes::_if_acmpne: 2652 case Bytecodes::_ifnull: 2653 case Bytecodes::_ifnonnull: 2654 target = bcs.dest(); 2655 if (visited_branches->contains(bci)) { 2656 if (bci_stack->is_empty()) { 2657 if (handler_stack->is_empty()) { 2658 return true; 2659 } else { 2660 // Parse the catch handlers for try blocks containing athrow. 2661 bcs.set_start(handler_stack->pop()); 2662 } 2663 } else { 2664 // Pop a bytecode starting offset and scan from there. 2665 bcs.set_start(bci_stack->pop()); 2666 } 2667 } else { 2668 if (target > bci) { // forward branch 2669 if (target >= code_length) return false; 2670 // Push the branch target onto the stack. 2671 bci_stack->push(target); 2672 // then, scan bytecodes starting with next. 2673 bcs.set_start(bcs.next_bci()); 2674 } else { // backward branch 2675 // Push bytecode offset following backward branch onto the stack. 2676 bci_stack->push(bcs.next_bci()); 2677 // Check bytecodes starting with branch target. 2678 bcs.set_start(target); 2679 } 2680 // Record target so we don't branch here again. 2681 visited_branches->append(bci); 2682 } 2683 break; 2684 2685 case Bytecodes::_goto: 2686 case Bytecodes::_goto_w: 2687 target = (opcode == Bytecodes::_goto ? bcs.dest() : bcs.dest_w()); 2688 if (visited_branches->contains(bci)) { 2689 if (bci_stack->is_empty()) { 2690 if (handler_stack->is_empty()) { 2691 return true; 2692 } else { 2693 // Parse the catch handlers for try blocks containing athrow. 2694 bcs.set_start(handler_stack->pop()); 2695 } 2696 } else { 2697 // Been here before, pop new starting offset from stack. 2698 bcs.set_start(bci_stack->pop()); 2699 } 2700 } else { 2701 if (target >= code_length) return false; 2702 // Continue scanning from the target onward. 2703 bcs.set_start(target); 2704 // Record target so we don't branch here again. 2705 visited_branches->append(bci); 2706 } 2707 break; 2708 2709 // Check that all switch alternatives end in 'athrow' bytecodes. Since it 2710 // is difficult to determine where each switch alternative ends, parse 2711 // each switch alternative until either hit a 'return', 'athrow', or reach 2712 // the end of the method's bytecodes. This is gross but should be okay 2713 // because: 2714 // 1. tableswitch and lookupswitch byte codes in handlers for ctor explicit 2715 // constructor invocations should be rare. 2716 // 2. if each switch alternative ends in an athrow then the parsing should be 2717 // short. If there is no athrow then it is bogus code, anyway. 2718 case Bytecodes::_lookupswitch: 2719 case Bytecodes::_tableswitch: 2720 { 2721 address aligned_bcp = align_up(bcs.bcp() + 1, jintSize); 2722 u4 default_offset = Bytes::get_Java_u4(aligned_bcp) + bci; 2723 int keys, delta; 2724 if (opcode == Bytecodes::_tableswitch) { 2725 jint low = (jint)Bytes::get_Java_u4(aligned_bcp + jintSize); 2726 jint high = (jint)Bytes::get_Java_u4(aligned_bcp + 2*jintSize); 2727 // This is invalid, but let the regular bytecode verifier 2728 // report this because the user will get a better error message. 2729 if (low > high) return true; 2730 keys = high - low + 1; 2731 delta = 1; 2732 } else { 2733 keys = (int)Bytes::get_Java_u4(aligned_bcp + jintSize); 2734 delta = 2; 2735 } 2736 // Invalid, let the regular bytecode verifier deal with it. 2737 if (keys < 0) return true; 2738 2739 // Push the offset of the next bytecode onto the stack. 2740 bci_stack->push(bcs.next_bci()); 2741 2742 // Push the switch alternatives onto the stack. 2743 for (int i = 0; i < keys; i++) { 2744 u4 target = bci + (jint)Bytes::get_Java_u4(aligned_bcp+(3+i*delta)*jintSize); 2745 if (target > code_length) return false; 2746 bci_stack->push(target); 2747 } 2748 2749 // Start bytecode parsing for the switch at the default alternative. 2750 if (default_offset > code_length) return false; 2751 bcs.set_start(default_offset); 2752 break; 2753 } 2754 2755 case Bytecodes::_return: 2756 return false; 2757 2758 case Bytecodes::_athrow: 2759 { 2760 if (bci_stack->is_empty()) { 2761 if (handler_stack->is_empty()) { 2762 return true; 2763 } else { 2764 // Parse the catch handlers for try blocks containing athrow. 2765 bcs.set_start(handler_stack->pop()); 2766 } 2767 } else { 2768 // Pop a bytecode offset and starting scanning from there. 2769 bcs.set_start(bci_stack->pop()); 2770 } 2771 } 2772 break; 2773 2774 default: 2775 ; 2776 } // end switch 2777 } // end while loop 2778 2779 return false; 2780 } 2781 2782 void ClassVerifier::verify_invoke_init( 2783 RawBytecodeStream* bcs, u2 ref_class_index, VerificationType ref_class_type, 2784 StackMapFrame* current_frame, u4 code_length, bool in_try_block, 2785 bool *this_uninit, const constantPoolHandle& cp, StackMapTable* stackmap_table, 2786 TRAPS) { 2787 u2 bci = bcs->bci(); 2788 VerificationType type = current_frame->pop_stack( 2789 VerificationType::reference_check(), CHECK_VERIFY(this)); 2790 if (type == VerificationType::uninitialized_this_type()) { 2791 // The method must be an <init> method of this class or its superclass 2792 Klass* superk = current_class()->super(); 2793 if (ref_class_type.name() != current_class()->name() && 2794 ref_class_type.name() != superk->name()) { 2795 verify_error(ErrorContext::bad_type(bci, 2796 TypeOrigin::implicit(ref_class_type), 2797 TypeOrigin::implicit(current_type())), 2798 "Bad <init> method call"); 2799 return; 2800 } 2801 2802 // If this invokespecial call is done from inside of a TRY block then make 2803 // sure that all catch clause paths end in a throw. Otherwise, this can 2804 // result in returning an incomplete object. 2805 if (in_try_block) { 2806 ExceptionTable exhandlers(_method()); 2807 int exlength = exhandlers.length(); 2808 for(int i = 0; i < exlength; i++) { 2809 u2 start_pc = exhandlers.start_pc(i); 2810 u2 end_pc = exhandlers.end_pc(i); 2811 2812 if (bci >= start_pc && bci < end_pc) { 2813 if (!ends_in_athrow(exhandlers.handler_pc(i))) { 2814 verify_error(ErrorContext::bad_code(bci), 2815 "Bad <init> method call from after the start of a try block"); 2816 return; 2817 } else if (log_is_enabled(Info, verification)) { 2818 ResourceMark rm(THREAD); 2819 log_info(verification)("Survived call to ends_in_athrow(): %s", 2820 current_class()->name()->as_C_string()); 2821 } 2822 } 2823 } 2824 2825 // Check the exception handler target stackmaps with the locals from the 2826 // incoming stackmap (before initialize_object() changes them to outgoing 2827 // state). 2828 if (was_recursively_verified()) return; 2829 verify_exception_handler_targets(bci, true, current_frame, 2830 stackmap_table, CHECK_VERIFY(this)); 2831 } // in_try_block 2832 2833 current_frame->initialize_object(type, current_type()); 2834 *this_uninit = true; 2835 } else if (type.is_uninitialized()) { 2836 u2 new_offset = type.bci(); 2837 address new_bcp = bcs->bcp() - bci + new_offset; 2838 if (new_offset > (code_length - 3) || (*new_bcp) != Bytecodes::_new) { 2839 /* Unreachable? Stack map parsing ensures valid type and new 2840 * instructions have a valid BCI. */ 2841 verify_error(ErrorContext::bad_code(new_offset), 2842 "Expecting new instruction"); 2843 return; 2844 } 2845 u2 new_class_index = Bytes::get_Java_u2(new_bcp + 1); 2846 if (was_recursively_verified()) return; 2847 verify_cp_class_type(bci, new_class_index, cp, CHECK_VERIFY(this)); 2848 2849 // The method must be an <init> method of the indicated class 2850 VerificationType new_class_type = cp_index_to_reference_type( 2851 new_class_index, cp, CHECK_VERIFY(this)); 2852 if (!new_class_type.equals(ref_class_type)) { 2853 verify_error(ErrorContext::bad_type(bci, 2854 TypeOrigin::cp(new_class_index, new_class_type), 2855 TypeOrigin::cp(ref_class_index, ref_class_type)), 2856 "Call to wrong <init> method"); 2857 return; 2858 } 2859 // According to the VM spec, if the referent class is a superclass of the 2860 // current class, and is in a different runtime package, and the method is 2861 // protected, then the objectref must be the current class or a subclass 2862 // of the current class. 2863 VerificationType objectref_type = new_class_type; 2864 if (name_in_supers(ref_class_type.name(), current_class())) { 2865 Klass* ref_klass = load_class(ref_class_type.name(), CHECK); 2866 if (was_recursively_verified()) return; 2867 Method* m = InstanceKlass::cast(ref_klass)->uncached_lookup_method( 2868 vmSymbols::object_initializer_name(), 2869 cp->signature_ref_at(bcs->get_index_u2()), 2870 Klass::find_overpass); 2871 // Do nothing if method is not found. Let resolution detect the error. 2872 if (m != NULL) { 2873 InstanceKlass* mh = m->method_holder(); 2874 if (m->is_protected() && !mh->is_same_class_package(_klass)) { 2875 bool assignable = current_type().is_assignable_from( 2876 objectref_type, this, true, CHECK_VERIFY(this)); 2877 if (!assignable) { 2878 verify_error(ErrorContext::bad_type(bci, 2879 TypeOrigin::cp(new_class_index, objectref_type), 2880 TypeOrigin::implicit(current_type())), 2881 "Bad access to protected <init> method"); 2882 return; 2883 } 2884 } 2885 } 2886 } 2887 // Check the exception handler target stackmaps with the locals from the 2888 // incoming stackmap (before initialize_object() changes them to outgoing 2889 // state). 2890 if (in_try_block) { 2891 if (was_recursively_verified()) return; 2892 verify_exception_handler_targets(bci, *this_uninit, current_frame, 2893 stackmap_table, CHECK_VERIFY(this)); 2894 } 2895 current_frame->initialize_object(type, new_class_type); 2896 } else { 2897 verify_error(ErrorContext::bad_type(bci, current_frame->stack_top_ctx()), 2898 "Bad operand type when invoking <init>"); 2899 return; 2900 } 2901 } 2902 2903 bool ClassVerifier::is_same_or_direct_interface( 2904 InstanceKlass* klass, 2905 VerificationType klass_type, 2906 VerificationType ref_class_type) { 2907 if (ref_class_type.equals(klass_type)) return true; 2908 Array<Klass*>* local_interfaces = klass->local_interfaces(); 2909 if (local_interfaces != NULL) { 2910 for (int x = 0; x < local_interfaces->length(); x++) { 2911 Klass* k = local_interfaces->at(x); 2912 assert (k != NULL && k->is_interface(), "invalid interface"); 2913 if (ref_class_type.equals(VerificationType::reference_type(k->name()))) { 2914 return true; 2915 } 2916 } 2917 } 2918 return false; 2919 } 2920 2921 void ClassVerifier::verify_invoke_instructions( 2922 RawBytecodeStream* bcs, u4 code_length, StackMapFrame* current_frame, 2923 bool in_try_block, bool *this_uninit, VerificationType return_type, 2924 const constantPoolHandle& cp, StackMapTable* stackmap_table, TRAPS) { 2925 // Make sure the constant pool item is the right type 2926 u2 index = bcs->get_index_u2(); 2927 Bytecodes::Code opcode = bcs->raw_code(); 2928 unsigned int types = 0; 2929 switch (opcode) { 2930 case Bytecodes::_invokeinterface: 2931 types = 1 << JVM_CONSTANT_InterfaceMethodref; 2932 break; 2933 case Bytecodes::_invokedynamic: 2934 types = 1 << JVM_CONSTANT_InvokeDynamic; 2935 break; 2936 case Bytecodes::_invokespecial: 2937 case Bytecodes::_invokestatic: 2938 types = (_klass->major_version() < STATIC_METHOD_IN_INTERFACE_MAJOR_VERSION) ? 2939 (1 << JVM_CONSTANT_Methodref) : 2940 ((1 << JVM_CONSTANT_InterfaceMethodref) | (1 << JVM_CONSTANT_Methodref)); 2941 break; 2942 default: 2943 types = 1 << JVM_CONSTANT_Methodref; 2944 } 2945 verify_cp_type(bcs->bci(), index, cp, types, CHECK_VERIFY(this)); 2946 2947 // Get method name and signature 2948 Symbol* method_name = cp->name_ref_at(index); 2949 Symbol* method_sig = cp->signature_ref_at(index); 2950 2951 if (!SignatureVerifier::is_valid_method_signature(method_sig)) { 2952 class_format_error( 2953 "Invalid method signature in class %s referenced " 2954 "from constant pool index %d", _klass->external_name(), index); 2955 return; 2956 } 2957 2958 // Get referenced class or value type 2959 VerificationType ref_class_type; 2960 if (opcode == Bytecodes::_invokedynamic) { 2961 if (_klass->major_version() < Verifier::INVOKEDYNAMIC_MAJOR_VERSION) { 2962 class_format_error( 2963 "invokedynamic instructions not supported by this class file version (%d), class %s", 2964 _klass->major_version(), _klass->external_name()); 2965 return; 2966 } 2967 } else { 2968 constantTag method_class_tag = cp->tag_at(cp->klass_ref_index_at(index)); 2969 if (EnableValhalla && 2970 opcode == Bytecodes::_invokevirtual && 2971 (method_class_tag.is_value_type() || method_class_tag.is_unresolved_value_type())) { 2972 ref_class_type = cp_value_index_to_type(index, cp, CHECK_VERIFY(this)); 2973 } else { 2974 ref_class_type = cp_ref_index_to_type(index, cp, CHECK_VERIFY(this)); 2975 } 2976 } 2977 2978 // For a small signature length, we just allocate 128 bytes instead 2979 // of parsing the signature once to find its size. 2980 // -3 is for '(', ')' and return descriptor; multiply by 2 is for 2981 // longs/doubles to be consertive. 2982 assert(sizeof(VerificationType) == sizeof(uintptr_t), 2983 "buffer type must match VerificationType size"); 2984 uintptr_t on_stack_sig_types_buffer[128]; 2985 // If we make a VerificationType[128] array directly, the compiler calls 2986 // to the c-runtime library to do the allocation instead of just 2987 // stack allocating it. Plus it would run constructors. This shows up 2988 // in performance profiles. 2989 2990 VerificationType* sig_types; 2991 int size = (method_sig->utf8_length() - 3) * 2; 2992 if (size > 128) { 2993 // Long and double occupies two slots here. 2994 ArgumentSizeComputer size_it(method_sig); 2995 size = size_it.size(); 2996 sig_types = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, VerificationType, size); 2997 } else{ 2998 sig_types = (VerificationType*)on_stack_sig_types_buffer; 2999 } 3000 SignatureStream sig_stream(method_sig); 3001 int sig_i = 0; 3002 while (!sig_stream.at_return_type()) { 3003 sig_i += change_sig_to_verificationType( 3004 &sig_stream, &sig_types[sig_i], CHECK_VERIFY(this)); 3005 sig_stream.next(); 3006 } 3007 int nargs = sig_i; 3008 3009 #ifdef ASSERT 3010 { 3011 ArgumentSizeComputer size_it(method_sig); 3012 assert(nargs == size_it.size(), "Argument sizes do not match"); 3013 assert(nargs <= (method_sig->utf8_length() - 3) * 2, "estimate of max size isn't conservative enough"); 3014 } 3015 #endif 3016 3017 // Check instruction operands 3018 u2 bci = bcs->bci(); 3019 if (opcode == Bytecodes::_invokeinterface) { 3020 address bcp = bcs->bcp(); 3021 // 4905268: count operand in invokeinterface should be nargs+1, not nargs. 3022 // JSR202 spec: The count operand of an invokeinterface instruction is valid if it is 3023 // the difference between the size of the operand stack before and after the instruction 3024 // executes. 3025 if (*(bcp+3) != (nargs+1)) { 3026 verify_error(ErrorContext::bad_code(bci), 3027 "Inconsistent args count operand in invokeinterface"); 3028 return; 3029 } 3030 if (*(bcp+4) != 0) { 3031 verify_error(ErrorContext::bad_code(bci), 3032 "Fourth operand byte of invokeinterface must be zero"); 3033 return; 3034 } 3035 } 3036 3037 if (opcode == Bytecodes::_invokedynamic) { 3038 address bcp = bcs->bcp(); 3039 if (*(bcp+3) != 0 || *(bcp+4) != 0) { 3040 verify_error(ErrorContext::bad_code(bci), 3041 "Third and fourth operand bytes of invokedynamic must be zero"); 3042 return; 3043 } 3044 } 3045 3046 if (method_name->byte_at(0) == '<') { 3047 // Make sure <init> can only be invoked by invokespecial 3048 if (opcode != Bytecodes::_invokespecial || 3049 method_name != vmSymbols::object_initializer_name()) { 3050 verify_error(ErrorContext::bad_code(bci), 3051 "Illegal call to internal method"); 3052 return; 3053 } 3054 } else if (opcode == Bytecodes::_invokespecial 3055 && !is_same_or_direct_interface(current_class(), current_type(), ref_class_type) 3056 && !ref_class_type.equals(VerificationType::reference_type( 3057 current_class()->super()->name()))) { 3058 bool subtype = false; 3059 bool have_imr_indirect = cp->tag_at(index).value() == JVM_CONSTANT_InterfaceMethodref; 3060 if (!current_class()->is_anonymous()) { 3061 subtype = ref_class_type.is_assignable_from( 3062 current_type(), this, false, CHECK_VERIFY(this)); 3063 } else { 3064 VerificationType host_klass_type = 3065 VerificationType::reference_type(current_class()->host_klass()->name()); 3066 subtype = ref_class_type.is_assignable_from(host_klass_type, this, false, CHECK_VERIFY(this)); 3067 3068 // If invokespecial of IMR, need to recheck for same or 3069 // direct interface relative to the host class 3070 have_imr_indirect = (have_imr_indirect && 3071 !is_same_or_direct_interface( 3072 current_class()->host_klass(), 3073 host_klass_type, ref_class_type)); 3074 } 3075 if (!subtype) { 3076 verify_error(ErrorContext::bad_code(bci), 3077 "Bad invokespecial instruction: " 3078 "current class isn't assignable to reference class."); 3079 return; 3080 } else if (have_imr_indirect) { 3081 verify_error(ErrorContext::bad_code(bci), 3082 "Bad invokespecial instruction: " 3083 "interface method reference is in an indirect superinterface."); 3084 return; 3085 } 3086 3087 } 3088 // Match method descriptor with operand stack 3089 for (int i = nargs - 1; i >= 0; i--) { // Run backwards 3090 current_frame->pop_stack(sig_types[i], CHECK_VERIFY(this)); 3091 } 3092 // Check objectref on operand stack 3093 if (opcode != Bytecodes::_invokestatic && 3094 opcode != Bytecodes::_invokedynamic) { 3095 if (method_name == vmSymbols::object_initializer_name()) { // <init> method 3096 verify_invoke_init(bcs, index, ref_class_type, current_frame, 3097 code_length, in_try_block, this_uninit, cp, stackmap_table, 3098 CHECK_VERIFY(this)); 3099 if (was_recursively_verified()) return; 3100 } else { // other methods 3101 // Ensures that target class is assignable to method class. 3102 if (opcode == Bytecodes::_invokespecial) { 3103 if (!current_class()->is_anonymous()) { 3104 current_frame->pop_stack(current_type(), CHECK_VERIFY(this)); 3105 } else { 3106 // anonymous class invokespecial calls: check if the 3107 // objectref is a subtype of the host_klass of the current class 3108 // to allow an anonymous class to reference methods in the host_klass 3109 VerificationType top = current_frame->pop_stack(CHECK_VERIFY(this)); 3110 VerificationType hosttype = 3111 VerificationType::reference_type(current_class()->host_klass()->name()); 3112 bool subtype = hosttype.is_assignable_from(top, this, false, CHECK_VERIFY(this)); 3113 if (!subtype) { 3114 verify_error( ErrorContext::bad_type(current_frame->offset(), 3115 current_frame->stack_top_ctx(), 3116 TypeOrigin::implicit(top)), 3117 "Bad type on operand stack"); 3118 return; 3119 } 3120 } 3121 } else if (opcode == Bytecodes::_invokevirtual) { 3122 VerificationType stack_object_type = 3123 current_frame->pop_stack(ref_class_type, CHECK_VERIFY(this)); 3124 if (current_type() != stack_object_type) { 3125 if (was_recursively_verified()) return; 3126 assert(cp->cache() == NULL, "not rewritten yet"); 3127 Symbol* ref_class_name = 3128 cp->klass_name_at(cp->klass_ref_index_at(index)); 3129 // See the comments in verify_field_instructions() for 3130 // the rationale behind this. 3131 if (name_in_supers(ref_class_name, current_class())) { 3132 Klass* ref_class = load_class(ref_class_name, CHECK); 3133 if (is_protected_access( 3134 _klass, ref_class, method_name, method_sig, true)) { 3135 // It's protected access, check if stack object is 3136 // assignable to current class. 3137 bool is_assignable = current_type().is_assignable_from( 3138 stack_object_type, this, true, CHECK_VERIFY(this)); 3139 if (!is_assignable) { 3140 if (ref_class_type.name() == vmSymbols::java_lang_Object() 3141 && stack_object_type.is_array() 3142 && method_name == vmSymbols::clone_name()) { 3143 // Special case: arrays pretend to implement public Object 3144 // clone(). 3145 } else { 3146 verify_error(ErrorContext::bad_type(bci, 3147 current_frame->stack_top_ctx(), 3148 TypeOrigin::implicit(current_type())), 3149 "Bad access to protected data in invokevirtual"); 3150 return; 3151 } 3152 } 3153 } 3154 } 3155 } 3156 } else { 3157 assert(opcode == Bytecodes::_invokeinterface, "Unexpected opcode encountered"); 3158 current_frame->pop_stack(ref_class_type, CHECK_VERIFY(this)); 3159 } 3160 } 3161 } 3162 // Push the result type. 3163 if (sig_stream.type() != T_VOID) { 3164 if (method_name == vmSymbols::object_initializer_name()) { 3165 // <init> method must have a void return type 3166 /* Unreachable? Class file parser verifies that methods with '<' have 3167 * void return */ 3168 verify_error(ErrorContext::bad_code(bci), 3169 "Return type must be void in <init> method"); 3170 return; 3171 } 3172 VerificationType return_type[2]; 3173 int n = change_sig_to_verificationType( 3174 &sig_stream, return_type, CHECK_VERIFY(this)); 3175 for (int i = 0; i < n; i++) { 3176 current_frame->push_stack(return_type[i], CHECK_VERIFY(this)); // push types backwards 3177 } 3178 } 3179 } 3180 3181 VerificationType ClassVerifier::get_newarray_type( 3182 u2 index, u2 bci, TRAPS) { 3183 const char* from_bt[] = { 3184 NULL, NULL, NULL, NULL, "[Z", "[C", "[F", "[D", "[B", "[S", "[I", "[J", 3185 }; 3186 if (index < T_BOOLEAN || index > T_LONG) { 3187 verify_error(ErrorContext::bad_code(bci), "Illegal newarray instruction"); 3188 return VerificationType::bogus_type(); 3189 } 3190 3191 // from_bt[index] contains the array signature which has a length of 2 3192 Symbol* sig = create_temporary_symbol( 3193 from_bt[index], 2, CHECK_(VerificationType::bogus_type())); 3194 return VerificationType::reference_type(sig); 3195 } 3196 3197 void ClassVerifier::verify_anewarray( 3198 u2 bci, u2 index, const constantPoolHandle& cp, 3199 StackMapFrame* current_frame, TRAPS) { 3200 verify_cp_class_or_value_type(bci, index, cp, CHECK_VERIFY(this)); 3201 current_frame->pop_stack( 3202 VerificationType::integer_type(), CHECK_VERIFY(this)); 3203 3204 if (was_recursively_verified()) return; 3205 constantTag class_tag = cp->tag_at(index); 3206 VerificationType component_type; 3207 if (class_tag.is_value_type() || class_tag.is_unresolved_value_type()) { 3208 component_type = cp_index_to_valuetype(index, cp, CHECK_VERIFY(this)); 3209 } else { 3210 component_type = cp_index_to_reference_type(index, cp, CHECK_VERIFY(this)); 3211 } 3212 int length; 3213 char* arr_sig_str; 3214 if (component_type.is_array()) { // it's an array 3215 const char* component_name = component_type.name()->as_utf8(); 3216 // Check for more than MAX_ARRAY_DIMENSIONS 3217 length = (int)strlen(component_name); 3218 if (length > MAX_ARRAY_DIMENSIONS && 3219 component_name[MAX_ARRAY_DIMENSIONS - 1] == '[') { 3220 verify_error(ErrorContext::bad_code(bci), 3221 "Illegal anewarray instruction, array has more than 255 dimensions"); 3222 } 3223 // add one dimension to component 3224 length++; 3225 arr_sig_str = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, length); 3226 arr_sig_str[0] = '['; 3227 strncpy(&arr_sig_str[1], component_name, length - 1); 3228 } else { // it's an object or interface 3229 const char* component_name = component_type.name()->as_utf8(); 3230 // add one dimension to component with 'L' or 'Q' (value type) prepended and ';' appended. 3231 length = (int)strlen(component_name) + 3; 3232 arr_sig_str = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, length); 3233 arr_sig_str[0] = '['; 3234 arr_sig_str[1] = component_type.is_reference() ? 'L' : 'Q'; 3235 strncpy(&arr_sig_str[2], component_name, length - 2); 3236 arr_sig_str[length - 1] = ';'; 3237 } 3238 Symbol* arr_sig = create_temporary_symbol( 3239 arr_sig_str, length, CHECK_VERIFY(this)); 3240 VerificationType new_array_type = VerificationType::reference_type(arr_sig); 3241 current_frame->push_stack(new_array_type, CHECK_VERIFY(this)); 3242 } 3243 3244 void ClassVerifier::verify_iload(u2 index, StackMapFrame* current_frame, TRAPS) { 3245 current_frame->get_local( 3246 index, VerificationType::integer_type(), CHECK_VERIFY(this)); 3247 current_frame->push_stack( 3248 VerificationType::integer_type(), CHECK_VERIFY(this)); 3249 } 3250 3251 void ClassVerifier::verify_lload(u2 index, StackMapFrame* current_frame, TRAPS) { 3252 current_frame->get_local_2( 3253 index, VerificationType::long_type(), 3254 VerificationType::long2_type(), CHECK_VERIFY(this)); 3255 current_frame->push_stack_2( 3256 VerificationType::long_type(), 3257 VerificationType::long2_type(), CHECK_VERIFY(this)); 3258 } 3259 3260 void ClassVerifier::verify_fload(u2 index, StackMapFrame* current_frame, TRAPS) { 3261 current_frame->get_local( 3262 index, VerificationType::float_type(), CHECK_VERIFY(this)); 3263 current_frame->push_stack( 3264 VerificationType::float_type(), CHECK_VERIFY(this)); 3265 } 3266 3267 void ClassVerifier::verify_dload(u2 index, StackMapFrame* current_frame, TRAPS) { 3268 current_frame->get_local_2( 3269 index, VerificationType::double_type(), 3270 VerificationType::double2_type(), CHECK_VERIFY(this)); 3271 current_frame->push_stack_2( 3272 VerificationType::double_type(), 3273 VerificationType::double2_type(), CHECK_VERIFY(this)); 3274 } 3275 3276 void ClassVerifier::verify_aload(u2 index, StackMapFrame* current_frame, TRAPS) { 3277 VerificationType type = current_frame->get_local( 3278 index, VerificationType::reference_check(), CHECK_VERIFY(this)); 3279 current_frame->push_stack(type, CHECK_VERIFY(this)); 3280 } 3281 3282 void ClassVerifier::verify_istore(u2 index, StackMapFrame* current_frame, TRAPS) { 3283 current_frame->pop_stack( 3284 VerificationType::integer_type(), CHECK_VERIFY(this)); 3285 current_frame->set_local( 3286 index, VerificationType::integer_type(), CHECK_VERIFY(this)); 3287 } 3288 3289 void ClassVerifier::verify_lstore(u2 index, StackMapFrame* current_frame, TRAPS) { 3290 current_frame->pop_stack_2( 3291 VerificationType::long2_type(), 3292 VerificationType::long_type(), CHECK_VERIFY(this)); 3293 current_frame->set_local_2( 3294 index, VerificationType::long_type(), 3295 VerificationType::long2_type(), CHECK_VERIFY(this)); 3296 } 3297 3298 void ClassVerifier::verify_fstore(u2 index, StackMapFrame* current_frame, TRAPS) { 3299 current_frame->pop_stack(VerificationType::float_type(), CHECK_VERIFY(this)); 3300 current_frame->set_local( 3301 index, VerificationType::float_type(), CHECK_VERIFY(this)); 3302 } 3303 3304 void ClassVerifier::verify_dstore(u2 index, StackMapFrame* current_frame, TRAPS) { 3305 current_frame->pop_stack_2( 3306 VerificationType::double2_type(), 3307 VerificationType::double_type(), CHECK_VERIFY(this)); 3308 current_frame->set_local_2( 3309 index, VerificationType::double_type(), 3310 VerificationType::double2_type(), CHECK_VERIFY(this)); 3311 } 3312 3313 void ClassVerifier::verify_astore(u2 index, StackMapFrame* current_frame, TRAPS) { 3314 VerificationType type = current_frame->pop_stack( 3315 VerificationType::reference_check(), CHECK_VERIFY(this)); 3316 current_frame->set_local(index, type, CHECK_VERIFY(this)); 3317 } 3318 3319 void ClassVerifier::verify_iinc(u2 index, StackMapFrame* current_frame, TRAPS) { 3320 VerificationType type = current_frame->get_local( 3321 index, VerificationType::integer_type(), CHECK_VERIFY(this)); 3322 current_frame->set_local(index, type, CHECK_VERIFY(this)); 3323 } 3324 3325 void ClassVerifier::verify_return_value( 3326 VerificationType return_type, VerificationType type, u2 bci, 3327 StackMapFrame* current_frame, TRAPS) { 3328 if (return_type == VerificationType::bogus_type()) { 3329 verify_error(ErrorContext::bad_type(bci, 3330 current_frame->stack_top_ctx(), TypeOrigin::signature(return_type)), 3331 "Method expects a return value"); 3332 return; 3333 } 3334 bool match = return_type.is_assignable_from(type, this, false, CHECK_VERIFY(this)); 3335 if (!match) { 3336 verify_error(ErrorContext::bad_type(bci, 3337 current_frame->stack_top_ctx(), TypeOrigin::signature(return_type)), 3338 "Bad return type"); 3339 return; 3340 } 3341 } 3342 3343 // The verifier creates symbols which are substrings of Symbols. 3344 // These are stored in the verifier until the end of verification so that 3345 // they can be reference counted. 3346 Symbol* ClassVerifier::create_temporary_symbol(const Symbol *s, int begin, 3347 int end, TRAPS) { 3348 Symbol* sym = SymbolTable::new_symbol(s, begin, end, CHECK_NULL); 3349 _symbols->push(sym); 3350 return sym; 3351 } 3352 3353 Symbol* ClassVerifier::create_temporary_symbol(const char *s, int length, TRAPS) { 3354 Symbol* sym = SymbolTable::new_symbol(s, length, CHECK_NULL); 3355 _symbols->push(sym); 3356 return sym; 3357 }