src/share/vm/classfile/verifier.cpp

Thu, 24 May 2018 18:41:44 +0800

author
aoqi
date
Thu, 24 May 2018 18:41:44 +0800
changeset 8856
ac27a9c85bea
parent 8716
619700f41f8e
parent 8604
04d83ba48607
child 9122
024be04bb151
permissions
-rw-r--r--

Merge

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

mercurial