src/share/vm/classfile/verifier.cpp

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 6871
077483254bf6
parent 1
2d8a650513c2
child 7535
7ae4e26cb1e0
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1998, 2014, 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"
aoqi@0 52 #include "runtime/orderAccess.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;
aoqi@0 516 for (u2 i = 0; i < sm_table->number_of_entries(); ++i) {
aoqi@0 517 ss->indent();
aoqi@0 518 sm_frame->print_on(ss, current_offset);
aoqi@0 519 ss->cr();
aoqi@0 520 current_offset += sm_frame->offset_delta();
aoqi@0 521 sm_frame = sm_frame->next();
aoqi@0 522 }
aoqi@0 523 }
aoqi@0 524 }
aoqi@0 525
aoqi@0 526 // Methods in ClassVerifier
aoqi@0 527
aoqi@0 528 ClassVerifier::ClassVerifier(
aoqi@0 529 instanceKlassHandle klass, TRAPS)
aoqi@0 530 : _thread(THREAD), _exception_type(NULL), _message(NULL), _klass(klass) {
aoqi@0 531 _this_type = VerificationType::reference_type(klass->name());
aoqi@0 532 // Create list to hold symbols in reference area.
aoqi@0 533 _symbols = new GrowableArray<Symbol*>(100, 0, NULL);
aoqi@0 534 }
aoqi@0 535
aoqi@0 536 ClassVerifier::~ClassVerifier() {
aoqi@0 537 // Decrement the reference count for any symbols created.
aoqi@0 538 for (int i = 0; i < _symbols->length(); i++) {
aoqi@0 539 Symbol* s = _symbols->at(i);
aoqi@0 540 s->decrement_refcount();
aoqi@0 541 }
aoqi@0 542 }
aoqi@0 543
aoqi@0 544 VerificationType ClassVerifier::object_type() const {
aoqi@0 545 return VerificationType::reference_type(vmSymbols::java_lang_Object());
aoqi@0 546 }
aoqi@0 547
aoqi@0 548 TypeOrigin ClassVerifier::ref_ctx(const char* sig, TRAPS) {
aoqi@0 549 VerificationType vt = VerificationType::reference_type(
aoqi@0 550 create_temporary_symbol(sig, (int)strlen(sig), THREAD));
aoqi@0 551 return TypeOrigin::implicit(vt);
aoqi@0 552 }
aoqi@0 553
aoqi@0 554 void ClassVerifier::verify_class(TRAPS) {
aoqi@0 555 if (VerboseVerification) {
aoqi@0 556 tty->print_cr("Verifying class %s with new format",
aoqi@0 557 _klass->external_name());
aoqi@0 558 }
aoqi@0 559
aoqi@0 560 Array<Method*>* methods = _klass->methods();
aoqi@0 561 int num_methods = methods->length();
aoqi@0 562
aoqi@0 563 for (int index = 0; index < num_methods; index++) {
aoqi@0 564 // Check for recursive re-verification before each method.
aoqi@0 565 if (was_recursively_verified()) return;
aoqi@0 566
aoqi@0 567 Method* m = methods->at(index);
aoqi@0 568 if (m->is_native() || m->is_abstract() || m->is_overpass()) {
aoqi@0 569 // If m is native or abstract, skip it. It is checked in class file
aoqi@0 570 // parser that methods do not override a final method. Overpass methods
aoqi@0 571 // are trusted since the VM generates them.
aoqi@0 572 continue;
aoqi@0 573 }
aoqi@0 574 verify_method(methodHandle(THREAD, m), CHECK_VERIFY(this));
aoqi@0 575 }
aoqi@0 576
aoqi@0 577 if (VerboseVerification || TraceClassInitialization) {
aoqi@0 578 if (was_recursively_verified())
aoqi@0 579 tty->print_cr("Recursive verification detected for: %s",
aoqi@0 580 _klass->external_name());
aoqi@0 581 }
aoqi@0 582 }
aoqi@0 583
aoqi@0 584 void ClassVerifier::verify_method(methodHandle m, TRAPS) {
aoqi@0 585 HandleMark hm(THREAD);
aoqi@0 586 _method = m; // initialize _method
aoqi@0 587 if (VerboseVerification) {
aoqi@0 588 tty->print_cr("Verifying method %s", m->name_and_sig_as_C_string());
aoqi@0 589 }
aoqi@0 590
aoqi@0 591 // For clang, the only good constant format string is a literal constant format string.
aoqi@0 592 #define bad_type_msg "Bad type on operand stack in %s"
aoqi@0 593
aoqi@0 594 int32_t max_stack = m->verifier_max_stack();
aoqi@0 595 int32_t max_locals = m->max_locals();
aoqi@0 596 constantPoolHandle cp(THREAD, m->constants());
aoqi@0 597
aoqi@0 598 if (!SignatureVerifier::is_valid_method_signature(m->signature())) {
aoqi@0 599 class_format_error("Invalid method signature");
aoqi@0 600 return;
aoqi@0 601 }
aoqi@0 602
aoqi@0 603 // Initial stack map frame: offset is 0, stack is initially empty.
aoqi@0 604 StackMapFrame current_frame(max_locals, max_stack, this);
aoqi@0 605 // Set initial locals
aoqi@0 606 VerificationType return_type = current_frame.set_locals_from_arg(
aoqi@0 607 m, current_type(), CHECK_VERIFY(this));
aoqi@0 608
aoqi@0 609 int32_t stackmap_index = 0; // index to the stackmap array
aoqi@0 610
aoqi@0 611 u4 code_length = m->code_size();
aoqi@0 612
aoqi@0 613 // Scan the bytecode and map each instruction's start offset to a number.
aoqi@0 614 char* code_data = generate_code_data(m, code_length, CHECK_VERIFY(this));
aoqi@0 615
aoqi@0 616 int ex_min = code_length;
aoqi@0 617 int ex_max = -1;
aoqi@0 618 // Look through each item on the exception table. Each of the fields must refer
aoqi@0 619 // to a legal instruction.
aoqi@0 620 verify_exception_handler_table(
aoqi@0 621 code_length, code_data, ex_min, ex_max, CHECK_VERIFY(this));
aoqi@0 622
aoqi@0 623 // Look through each entry on the local variable table and make sure
aoqi@0 624 // its range of code array offsets is valid. (4169817)
aoqi@0 625 if (m->has_localvariable_table()) {
aoqi@0 626 verify_local_variable_table(code_length, code_data, CHECK_VERIFY(this));
aoqi@0 627 }
aoqi@0 628
aoqi@0 629 Array<u1>* stackmap_data = m->stackmap_data();
aoqi@0 630 StackMapStream stream(stackmap_data);
aoqi@0 631 StackMapReader reader(this, &stream, code_data, code_length, THREAD);
aoqi@0 632 StackMapTable stackmap_table(&reader, &current_frame, max_locals, max_stack,
aoqi@0 633 code_data, code_length, CHECK_VERIFY(this));
aoqi@0 634
aoqi@0 635 if (VerboseVerification) {
aoqi@0 636 stackmap_table.print_on(tty);
aoqi@0 637 }
aoqi@0 638
aoqi@0 639 RawBytecodeStream bcs(m);
aoqi@0 640
aoqi@0 641 // Scan the byte code linearly from the start to the end
aoqi@0 642 bool no_control_flow = false; // Set to true when there is no direct control
aoqi@0 643 // flow from current instruction to the next
aoqi@0 644 // instruction in sequence
aoqi@0 645
aoqi@0 646 Bytecodes::Code opcode;
aoqi@0 647 while (!bcs.is_last_bytecode()) {
aoqi@0 648 // Check for recursive re-verification before each bytecode.
aoqi@0 649 if (was_recursively_verified()) return;
aoqi@0 650
aoqi@0 651 opcode = bcs.raw_next();
aoqi@0 652 u2 bci = bcs.bci();
aoqi@0 653
aoqi@0 654 // Set current frame's offset to bci
aoqi@0 655 current_frame.set_offset(bci);
aoqi@0 656 current_frame.set_mark();
aoqi@0 657
aoqi@0 658 // Make sure every offset in stackmap table point to the beginning to
aoqi@0 659 // an instruction. Match current_frame to stackmap_table entry with
aoqi@0 660 // the same offset if exists.
aoqi@0 661 stackmap_index = verify_stackmap_table(
aoqi@0 662 stackmap_index, bci, &current_frame, &stackmap_table,
aoqi@0 663 no_control_flow, CHECK_VERIFY(this));
aoqi@0 664
aoqi@0 665
aoqi@0 666 bool this_uninit = false; // Set to true when invokespecial <init> initialized 'this'
aoqi@0 667
aoqi@0 668 // Merge with the next instruction
aoqi@0 669 {
aoqi@0 670 u2 index;
aoqi@0 671 int target;
aoqi@0 672 VerificationType type, type2;
aoqi@0 673 VerificationType atype;
aoqi@0 674
aoqi@0 675 #ifndef PRODUCT
aoqi@0 676 if (VerboseVerification) {
aoqi@0 677 current_frame.print_on(tty);
aoqi@0 678 tty->print_cr("offset = %d, opcode = %s", bci, Bytecodes::name(opcode));
aoqi@0 679 }
aoqi@0 680 #endif
aoqi@0 681
aoqi@0 682 // Make sure wide instruction is in correct format
aoqi@0 683 if (bcs.is_wide()) {
aoqi@0 684 if (opcode != Bytecodes::_iinc && opcode != Bytecodes::_iload &&
aoqi@0 685 opcode != Bytecodes::_aload && opcode != Bytecodes::_lload &&
aoqi@0 686 opcode != Bytecodes::_istore && opcode != Bytecodes::_astore &&
aoqi@0 687 opcode != Bytecodes::_lstore && opcode != Bytecodes::_fload &&
aoqi@0 688 opcode != Bytecodes::_dload && opcode != Bytecodes::_fstore &&
aoqi@0 689 opcode != Bytecodes::_dstore) {
aoqi@0 690 /* Unreachable? RawBytecodeStream's raw_next() returns 'illegal'
aoqi@0 691 * if we encounter a wide instruction that modifies an invalid
aoqi@0 692 * opcode (not one of the ones listed above) */
aoqi@0 693 verify_error(ErrorContext::bad_code(bci), "Bad wide instruction");
aoqi@0 694 return;
aoqi@0 695 }
aoqi@0 696 }
aoqi@0 697
aoqi@0 698 switch (opcode) {
aoqi@0 699 case Bytecodes::_nop :
aoqi@0 700 no_control_flow = false; break;
aoqi@0 701 case Bytecodes::_aconst_null :
aoqi@0 702 current_frame.push_stack(
aoqi@0 703 VerificationType::null_type(), CHECK_VERIFY(this));
aoqi@0 704 no_control_flow = false; break;
aoqi@0 705 case Bytecodes::_iconst_m1 :
aoqi@0 706 case Bytecodes::_iconst_0 :
aoqi@0 707 case Bytecodes::_iconst_1 :
aoqi@0 708 case Bytecodes::_iconst_2 :
aoqi@0 709 case Bytecodes::_iconst_3 :
aoqi@0 710 case Bytecodes::_iconst_4 :
aoqi@0 711 case Bytecodes::_iconst_5 :
aoqi@0 712 current_frame.push_stack(
aoqi@0 713 VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 714 no_control_flow = false; break;
aoqi@0 715 case Bytecodes::_lconst_0 :
aoqi@0 716 case Bytecodes::_lconst_1 :
aoqi@0 717 current_frame.push_stack_2(
aoqi@0 718 VerificationType::long_type(),
aoqi@0 719 VerificationType::long2_type(), CHECK_VERIFY(this));
aoqi@0 720 no_control_flow = false; break;
aoqi@0 721 case Bytecodes::_fconst_0 :
aoqi@0 722 case Bytecodes::_fconst_1 :
aoqi@0 723 case Bytecodes::_fconst_2 :
aoqi@0 724 current_frame.push_stack(
aoqi@0 725 VerificationType::float_type(), CHECK_VERIFY(this));
aoqi@0 726 no_control_flow = false; break;
aoqi@0 727 case Bytecodes::_dconst_0 :
aoqi@0 728 case Bytecodes::_dconst_1 :
aoqi@0 729 current_frame.push_stack_2(
aoqi@0 730 VerificationType::double_type(),
aoqi@0 731 VerificationType::double2_type(), CHECK_VERIFY(this));
aoqi@0 732 no_control_flow = false; break;
aoqi@0 733 case Bytecodes::_sipush :
aoqi@0 734 case Bytecodes::_bipush :
aoqi@0 735 current_frame.push_stack(
aoqi@0 736 VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 737 no_control_flow = false; break;
aoqi@0 738 case Bytecodes::_ldc :
aoqi@0 739 verify_ldc(
aoqi@0 740 opcode, bcs.get_index_u1(), &current_frame,
aoqi@0 741 cp, bci, CHECK_VERIFY(this));
aoqi@0 742 no_control_flow = false; break;
aoqi@0 743 case Bytecodes::_ldc_w :
aoqi@0 744 case Bytecodes::_ldc2_w :
aoqi@0 745 verify_ldc(
aoqi@0 746 opcode, bcs.get_index_u2(), &current_frame,
aoqi@0 747 cp, bci, CHECK_VERIFY(this));
aoqi@0 748 no_control_flow = false; break;
aoqi@0 749 case Bytecodes::_iload :
aoqi@0 750 verify_iload(bcs.get_index(), &current_frame, CHECK_VERIFY(this));
aoqi@0 751 no_control_flow = false; break;
aoqi@0 752 case Bytecodes::_iload_0 :
aoqi@0 753 case Bytecodes::_iload_1 :
aoqi@0 754 case Bytecodes::_iload_2 :
aoqi@0 755 case Bytecodes::_iload_3 :
aoqi@0 756 index = opcode - Bytecodes::_iload_0;
aoqi@0 757 verify_iload(index, &current_frame, CHECK_VERIFY(this));
aoqi@0 758 no_control_flow = false; break;
aoqi@0 759 case Bytecodes::_lload :
aoqi@0 760 verify_lload(bcs.get_index(), &current_frame, CHECK_VERIFY(this));
aoqi@0 761 no_control_flow = false; break;
aoqi@0 762 case Bytecodes::_lload_0 :
aoqi@0 763 case Bytecodes::_lload_1 :
aoqi@0 764 case Bytecodes::_lload_2 :
aoqi@0 765 case Bytecodes::_lload_3 :
aoqi@0 766 index = opcode - Bytecodes::_lload_0;
aoqi@0 767 verify_lload(index, &current_frame, CHECK_VERIFY(this));
aoqi@0 768 no_control_flow = false; break;
aoqi@0 769 case Bytecodes::_fload :
aoqi@0 770 verify_fload(bcs.get_index(), &current_frame, CHECK_VERIFY(this));
aoqi@0 771 no_control_flow = false; break;
aoqi@0 772 case Bytecodes::_fload_0 :
aoqi@0 773 case Bytecodes::_fload_1 :
aoqi@0 774 case Bytecodes::_fload_2 :
aoqi@0 775 case Bytecodes::_fload_3 :
aoqi@0 776 index = opcode - Bytecodes::_fload_0;
aoqi@0 777 verify_fload(index, &current_frame, CHECK_VERIFY(this));
aoqi@0 778 no_control_flow = false; break;
aoqi@0 779 case Bytecodes::_dload :
aoqi@0 780 verify_dload(bcs.get_index(), &current_frame, CHECK_VERIFY(this));
aoqi@0 781 no_control_flow = false; break;
aoqi@0 782 case Bytecodes::_dload_0 :
aoqi@0 783 case Bytecodes::_dload_1 :
aoqi@0 784 case Bytecodes::_dload_2 :
aoqi@0 785 case Bytecodes::_dload_3 :
aoqi@0 786 index = opcode - Bytecodes::_dload_0;
aoqi@0 787 verify_dload(index, &current_frame, CHECK_VERIFY(this));
aoqi@0 788 no_control_flow = false; break;
aoqi@0 789 case Bytecodes::_aload :
aoqi@0 790 verify_aload(bcs.get_index(), &current_frame, CHECK_VERIFY(this));
aoqi@0 791 no_control_flow = false; break;
aoqi@0 792 case Bytecodes::_aload_0 :
aoqi@0 793 case Bytecodes::_aload_1 :
aoqi@0 794 case Bytecodes::_aload_2 :
aoqi@0 795 case Bytecodes::_aload_3 :
aoqi@0 796 index = opcode - Bytecodes::_aload_0;
aoqi@0 797 verify_aload(index, &current_frame, CHECK_VERIFY(this));
aoqi@0 798 no_control_flow = false; break;
aoqi@0 799 case Bytecodes::_iaload :
aoqi@0 800 type = current_frame.pop_stack(
aoqi@0 801 VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 802 atype = current_frame.pop_stack(
aoqi@0 803 VerificationType::reference_check(), CHECK_VERIFY(this));
aoqi@0 804 if (!atype.is_int_array()) {
aoqi@0 805 verify_error(ErrorContext::bad_type(bci,
aoqi@0 806 current_frame.stack_top_ctx(), ref_ctx("[I", THREAD)),
aoqi@0 807 bad_type_msg, "iaload");
aoqi@0 808 return;
aoqi@0 809 }
aoqi@0 810 current_frame.push_stack(
aoqi@0 811 VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 812 no_control_flow = false; break;
aoqi@0 813 case Bytecodes::_baload :
aoqi@0 814 type = current_frame.pop_stack(
aoqi@0 815 VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 816 atype = current_frame.pop_stack(
aoqi@0 817 VerificationType::reference_check(), CHECK_VERIFY(this));
aoqi@0 818 if (!atype.is_bool_array() && !atype.is_byte_array()) {
aoqi@0 819 verify_error(
aoqi@0 820 ErrorContext::bad_type(bci, current_frame.stack_top_ctx()),
aoqi@0 821 bad_type_msg, "baload");
aoqi@0 822 return;
aoqi@0 823 }
aoqi@0 824 current_frame.push_stack(
aoqi@0 825 VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 826 no_control_flow = false; break;
aoqi@0 827 case Bytecodes::_caload :
aoqi@0 828 type = current_frame.pop_stack(
aoqi@0 829 VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 830 atype = current_frame.pop_stack(
aoqi@0 831 VerificationType::reference_check(), CHECK_VERIFY(this));
aoqi@0 832 if (!atype.is_char_array()) {
aoqi@0 833 verify_error(ErrorContext::bad_type(bci,
aoqi@0 834 current_frame.stack_top_ctx(), ref_ctx("[C", THREAD)),
aoqi@0 835 bad_type_msg, "caload");
aoqi@0 836 return;
aoqi@0 837 }
aoqi@0 838 current_frame.push_stack(
aoqi@0 839 VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 840 no_control_flow = false; break;
aoqi@0 841 case Bytecodes::_saload :
aoqi@0 842 type = current_frame.pop_stack(
aoqi@0 843 VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 844 atype = current_frame.pop_stack(
aoqi@0 845 VerificationType::reference_check(), CHECK_VERIFY(this));
aoqi@0 846 if (!atype.is_short_array()) {
aoqi@0 847 verify_error(ErrorContext::bad_type(bci,
aoqi@0 848 current_frame.stack_top_ctx(), ref_ctx("[S", THREAD)),
aoqi@0 849 bad_type_msg, "saload");
aoqi@0 850 return;
aoqi@0 851 }
aoqi@0 852 current_frame.push_stack(
aoqi@0 853 VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 854 no_control_flow = false; break;
aoqi@0 855 case Bytecodes::_laload :
aoqi@0 856 type = current_frame.pop_stack(
aoqi@0 857 VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 858 atype = current_frame.pop_stack(
aoqi@0 859 VerificationType::reference_check(), CHECK_VERIFY(this));
aoqi@0 860 if (!atype.is_long_array()) {
aoqi@0 861 verify_error(ErrorContext::bad_type(bci,
aoqi@0 862 current_frame.stack_top_ctx(), ref_ctx("[J", THREAD)),
aoqi@0 863 bad_type_msg, "laload");
aoqi@0 864 return;
aoqi@0 865 }
aoqi@0 866 current_frame.push_stack_2(
aoqi@0 867 VerificationType::long_type(),
aoqi@0 868 VerificationType::long2_type(), CHECK_VERIFY(this));
aoqi@0 869 no_control_flow = false; break;
aoqi@0 870 case Bytecodes::_faload :
aoqi@0 871 type = current_frame.pop_stack(
aoqi@0 872 VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 873 atype = current_frame.pop_stack(
aoqi@0 874 VerificationType::reference_check(), CHECK_VERIFY(this));
aoqi@0 875 if (!atype.is_float_array()) {
aoqi@0 876 verify_error(ErrorContext::bad_type(bci,
aoqi@0 877 current_frame.stack_top_ctx(), ref_ctx("[F", THREAD)),
aoqi@0 878 bad_type_msg, "faload");
aoqi@0 879 return;
aoqi@0 880 }
aoqi@0 881 current_frame.push_stack(
aoqi@0 882 VerificationType::float_type(), CHECK_VERIFY(this));
aoqi@0 883 no_control_flow = false; break;
aoqi@0 884 case Bytecodes::_daload :
aoqi@0 885 type = current_frame.pop_stack(
aoqi@0 886 VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 887 atype = current_frame.pop_stack(
aoqi@0 888 VerificationType::reference_check(), CHECK_VERIFY(this));
aoqi@0 889 if (!atype.is_double_array()) {
aoqi@0 890 verify_error(ErrorContext::bad_type(bci,
aoqi@0 891 current_frame.stack_top_ctx(), ref_ctx("[D", THREAD)),
aoqi@0 892 bad_type_msg, "daload");
aoqi@0 893 return;
aoqi@0 894 }
aoqi@0 895 current_frame.push_stack_2(
aoqi@0 896 VerificationType::double_type(),
aoqi@0 897 VerificationType::double2_type(), CHECK_VERIFY(this));
aoqi@0 898 no_control_flow = false; break;
aoqi@0 899 case Bytecodes::_aaload : {
aoqi@0 900 type = current_frame.pop_stack(
aoqi@0 901 VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 902 atype = current_frame.pop_stack(
aoqi@0 903 VerificationType::reference_check(), CHECK_VERIFY(this));
aoqi@0 904 if (!atype.is_reference_array()) {
aoqi@0 905 verify_error(ErrorContext::bad_type(bci,
aoqi@0 906 current_frame.stack_top_ctx(),
aoqi@0 907 TypeOrigin::implicit(VerificationType::reference_check())),
aoqi@0 908 bad_type_msg, "aaload");
aoqi@0 909 return;
aoqi@0 910 }
aoqi@0 911 if (atype.is_null()) {
aoqi@0 912 current_frame.push_stack(
aoqi@0 913 VerificationType::null_type(), CHECK_VERIFY(this));
aoqi@0 914 } else {
aoqi@0 915 VerificationType component =
aoqi@0 916 atype.get_component(this, CHECK_VERIFY(this));
aoqi@0 917 current_frame.push_stack(component, CHECK_VERIFY(this));
aoqi@0 918 }
aoqi@0 919 no_control_flow = false; break;
aoqi@0 920 }
aoqi@0 921 case Bytecodes::_istore :
aoqi@0 922 verify_istore(bcs.get_index(), &current_frame, CHECK_VERIFY(this));
aoqi@0 923 no_control_flow = false; break;
aoqi@0 924 case Bytecodes::_istore_0 :
aoqi@0 925 case Bytecodes::_istore_1 :
aoqi@0 926 case Bytecodes::_istore_2 :
aoqi@0 927 case Bytecodes::_istore_3 :
aoqi@0 928 index = opcode - Bytecodes::_istore_0;
aoqi@0 929 verify_istore(index, &current_frame, CHECK_VERIFY(this));
aoqi@0 930 no_control_flow = false; break;
aoqi@0 931 case Bytecodes::_lstore :
aoqi@0 932 verify_lstore(bcs.get_index(), &current_frame, CHECK_VERIFY(this));
aoqi@0 933 no_control_flow = false; break;
aoqi@0 934 case Bytecodes::_lstore_0 :
aoqi@0 935 case Bytecodes::_lstore_1 :
aoqi@0 936 case Bytecodes::_lstore_2 :
aoqi@0 937 case Bytecodes::_lstore_3 :
aoqi@0 938 index = opcode - Bytecodes::_lstore_0;
aoqi@0 939 verify_lstore(index, &current_frame, CHECK_VERIFY(this));
aoqi@0 940 no_control_flow = false; break;
aoqi@0 941 case Bytecodes::_fstore :
aoqi@0 942 verify_fstore(bcs.get_index(), &current_frame, CHECK_VERIFY(this));
aoqi@0 943 no_control_flow = false; break;
aoqi@0 944 case Bytecodes::_fstore_0 :
aoqi@0 945 case Bytecodes::_fstore_1 :
aoqi@0 946 case Bytecodes::_fstore_2 :
aoqi@0 947 case Bytecodes::_fstore_3 :
aoqi@0 948 index = opcode - Bytecodes::_fstore_0;
aoqi@0 949 verify_fstore(index, &current_frame, CHECK_VERIFY(this));
aoqi@0 950 no_control_flow = false; break;
aoqi@0 951 case Bytecodes::_dstore :
aoqi@0 952 verify_dstore(bcs.get_index(), &current_frame, CHECK_VERIFY(this));
aoqi@0 953 no_control_flow = false; break;
aoqi@0 954 case Bytecodes::_dstore_0 :
aoqi@0 955 case Bytecodes::_dstore_1 :
aoqi@0 956 case Bytecodes::_dstore_2 :
aoqi@0 957 case Bytecodes::_dstore_3 :
aoqi@0 958 index = opcode - Bytecodes::_dstore_0;
aoqi@0 959 verify_dstore(index, &current_frame, CHECK_VERIFY(this));
aoqi@0 960 no_control_flow = false; break;
aoqi@0 961 case Bytecodes::_astore :
aoqi@0 962 verify_astore(bcs.get_index(), &current_frame, CHECK_VERIFY(this));
aoqi@0 963 no_control_flow = false; break;
aoqi@0 964 case Bytecodes::_astore_0 :
aoqi@0 965 case Bytecodes::_astore_1 :
aoqi@0 966 case Bytecodes::_astore_2 :
aoqi@0 967 case Bytecodes::_astore_3 :
aoqi@0 968 index = opcode - Bytecodes::_astore_0;
aoqi@0 969 verify_astore(index, &current_frame, CHECK_VERIFY(this));
aoqi@0 970 no_control_flow = false; break;
aoqi@0 971 case Bytecodes::_iastore :
aoqi@0 972 type = current_frame.pop_stack(
aoqi@0 973 VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 974 type2 = current_frame.pop_stack(
aoqi@0 975 VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 976 atype = current_frame.pop_stack(
aoqi@0 977 VerificationType::reference_check(), CHECK_VERIFY(this));
aoqi@0 978 if (!atype.is_int_array()) {
aoqi@0 979 verify_error(ErrorContext::bad_type(bci,
aoqi@0 980 current_frame.stack_top_ctx(), ref_ctx("[I", THREAD)),
aoqi@0 981 bad_type_msg, "iastore");
aoqi@0 982 return;
aoqi@0 983 }
aoqi@0 984 no_control_flow = false; break;
aoqi@0 985 case Bytecodes::_bastore :
aoqi@0 986 type = current_frame.pop_stack(
aoqi@0 987 VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 988 type2 = current_frame.pop_stack(
aoqi@0 989 VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 990 atype = current_frame.pop_stack(
aoqi@0 991 VerificationType::reference_check(), CHECK_VERIFY(this));
aoqi@0 992 if (!atype.is_bool_array() && !atype.is_byte_array()) {
aoqi@0 993 verify_error(
aoqi@0 994 ErrorContext::bad_type(bci, current_frame.stack_top_ctx()),
aoqi@0 995 bad_type_msg, "bastore");
aoqi@0 996 return;
aoqi@0 997 }
aoqi@0 998 no_control_flow = false; break;
aoqi@0 999 case Bytecodes::_castore :
aoqi@0 1000 current_frame.pop_stack(
aoqi@0 1001 VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 1002 current_frame.pop_stack(
aoqi@0 1003 VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 1004 atype = current_frame.pop_stack(
aoqi@0 1005 VerificationType::reference_check(), CHECK_VERIFY(this));
aoqi@0 1006 if (!atype.is_char_array()) {
aoqi@0 1007 verify_error(ErrorContext::bad_type(bci,
aoqi@0 1008 current_frame.stack_top_ctx(), ref_ctx("[C", THREAD)),
aoqi@0 1009 bad_type_msg, "castore");
aoqi@0 1010 return;
aoqi@0 1011 }
aoqi@0 1012 no_control_flow = false; break;
aoqi@0 1013 case Bytecodes::_sastore :
aoqi@0 1014 current_frame.pop_stack(
aoqi@0 1015 VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 1016 current_frame.pop_stack(
aoqi@0 1017 VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 1018 atype = current_frame.pop_stack(
aoqi@0 1019 VerificationType::reference_check(), CHECK_VERIFY(this));
aoqi@0 1020 if (!atype.is_short_array()) {
aoqi@0 1021 verify_error(ErrorContext::bad_type(bci,
aoqi@0 1022 current_frame.stack_top_ctx(), ref_ctx("[S", THREAD)),
aoqi@0 1023 bad_type_msg, "sastore");
aoqi@0 1024 return;
aoqi@0 1025 }
aoqi@0 1026 no_control_flow = false; break;
aoqi@0 1027 case Bytecodes::_lastore :
aoqi@0 1028 current_frame.pop_stack_2(
aoqi@0 1029 VerificationType::long2_type(),
aoqi@0 1030 VerificationType::long_type(), CHECK_VERIFY(this));
aoqi@0 1031 current_frame.pop_stack(
aoqi@0 1032 VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 1033 atype = current_frame.pop_stack(
aoqi@0 1034 VerificationType::reference_check(), CHECK_VERIFY(this));
aoqi@0 1035 if (!atype.is_long_array()) {
aoqi@0 1036 verify_error(ErrorContext::bad_type(bci,
aoqi@0 1037 current_frame.stack_top_ctx(), ref_ctx("[J", THREAD)),
aoqi@0 1038 bad_type_msg, "lastore");
aoqi@0 1039 return;
aoqi@0 1040 }
aoqi@0 1041 no_control_flow = false; break;
aoqi@0 1042 case Bytecodes::_fastore :
aoqi@0 1043 current_frame.pop_stack(
aoqi@0 1044 VerificationType::float_type(), CHECK_VERIFY(this));
aoqi@0 1045 current_frame.pop_stack
aoqi@0 1046 (VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 1047 atype = current_frame.pop_stack(
aoqi@0 1048 VerificationType::reference_check(), CHECK_VERIFY(this));
aoqi@0 1049 if (!atype.is_float_array()) {
aoqi@0 1050 verify_error(ErrorContext::bad_type(bci,
aoqi@0 1051 current_frame.stack_top_ctx(), ref_ctx("[F", THREAD)),
aoqi@0 1052 bad_type_msg, "fastore");
aoqi@0 1053 return;
aoqi@0 1054 }
aoqi@0 1055 no_control_flow = false; break;
aoqi@0 1056 case Bytecodes::_dastore :
aoqi@0 1057 current_frame.pop_stack_2(
aoqi@0 1058 VerificationType::double2_type(),
aoqi@0 1059 VerificationType::double_type(), CHECK_VERIFY(this));
aoqi@0 1060 current_frame.pop_stack(
aoqi@0 1061 VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 1062 atype = current_frame.pop_stack(
aoqi@0 1063 VerificationType::reference_check(), CHECK_VERIFY(this));
aoqi@0 1064 if (!atype.is_double_array()) {
aoqi@0 1065 verify_error(ErrorContext::bad_type(bci,
aoqi@0 1066 current_frame.stack_top_ctx(), ref_ctx("[D", THREAD)),
aoqi@0 1067 bad_type_msg, "dastore");
aoqi@0 1068 return;
aoqi@0 1069 }
aoqi@0 1070 no_control_flow = false; break;
aoqi@0 1071 case Bytecodes::_aastore :
aoqi@0 1072 type = current_frame.pop_stack(object_type(), CHECK_VERIFY(this));
aoqi@0 1073 type2 = current_frame.pop_stack(
aoqi@0 1074 VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 1075 atype = current_frame.pop_stack(
aoqi@0 1076 VerificationType::reference_check(), CHECK_VERIFY(this));
aoqi@0 1077 // more type-checking is done at runtime
aoqi@0 1078 if (!atype.is_reference_array()) {
aoqi@0 1079 verify_error(ErrorContext::bad_type(bci,
aoqi@0 1080 current_frame.stack_top_ctx(),
aoqi@0 1081 TypeOrigin::implicit(VerificationType::reference_check())),
aoqi@0 1082 bad_type_msg, "aastore");
aoqi@0 1083 return;
aoqi@0 1084 }
aoqi@0 1085 // 4938384: relaxed constraint in JVMS 3nd edition.
aoqi@0 1086 no_control_flow = false; break;
aoqi@0 1087 case Bytecodes::_pop :
aoqi@0 1088 current_frame.pop_stack(
aoqi@0 1089 VerificationType::category1_check(), CHECK_VERIFY(this));
aoqi@0 1090 no_control_flow = false; break;
aoqi@0 1091 case Bytecodes::_pop2 :
aoqi@0 1092 type = current_frame.pop_stack(CHECK_VERIFY(this));
aoqi@0 1093 if (type.is_category1()) {
aoqi@0 1094 current_frame.pop_stack(
aoqi@0 1095 VerificationType::category1_check(), CHECK_VERIFY(this));
aoqi@0 1096 } else if (type.is_category2_2nd()) {
aoqi@0 1097 current_frame.pop_stack(
aoqi@0 1098 VerificationType::category2_check(), CHECK_VERIFY(this));
aoqi@0 1099 } else {
aoqi@0 1100 /* Unreachable? Would need a category2_1st on TOS
aoqi@0 1101 * which does not appear possible. */
aoqi@0 1102 verify_error(
aoqi@0 1103 ErrorContext::bad_type(bci, current_frame.stack_top_ctx()),
aoqi@0 1104 bad_type_msg, "pop2");
aoqi@0 1105 return;
aoqi@0 1106 }
aoqi@0 1107 no_control_flow = false; break;
aoqi@0 1108 case Bytecodes::_dup :
aoqi@0 1109 type = current_frame.pop_stack(
aoqi@0 1110 VerificationType::category1_check(), CHECK_VERIFY(this));
aoqi@0 1111 current_frame.push_stack(type, CHECK_VERIFY(this));
aoqi@0 1112 current_frame.push_stack(type, CHECK_VERIFY(this));
aoqi@0 1113 no_control_flow = false; break;
aoqi@0 1114 case Bytecodes::_dup_x1 :
aoqi@0 1115 type = current_frame.pop_stack(
aoqi@0 1116 VerificationType::category1_check(), CHECK_VERIFY(this));
aoqi@0 1117 type2 = current_frame.pop_stack(
aoqi@0 1118 VerificationType::category1_check(), CHECK_VERIFY(this));
aoqi@0 1119 current_frame.push_stack(type, CHECK_VERIFY(this));
aoqi@0 1120 current_frame.push_stack(type2, CHECK_VERIFY(this));
aoqi@0 1121 current_frame.push_stack(type, CHECK_VERIFY(this));
aoqi@0 1122 no_control_flow = false; break;
aoqi@0 1123 case Bytecodes::_dup_x2 :
aoqi@0 1124 {
aoqi@0 1125 VerificationType type3;
aoqi@0 1126 type = current_frame.pop_stack(
aoqi@0 1127 VerificationType::category1_check(), CHECK_VERIFY(this));
aoqi@0 1128 type2 = current_frame.pop_stack(CHECK_VERIFY(this));
aoqi@0 1129 if (type2.is_category1()) {
aoqi@0 1130 type3 = current_frame.pop_stack(
aoqi@0 1131 VerificationType::category1_check(), CHECK_VERIFY(this));
aoqi@0 1132 } else if (type2.is_category2_2nd()) {
aoqi@0 1133 type3 = current_frame.pop_stack(
aoqi@0 1134 VerificationType::category2_check(), CHECK_VERIFY(this));
aoqi@0 1135 } else {
aoqi@0 1136 /* Unreachable? Would need a category2_1st at stack depth 2 with
aoqi@0 1137 * a category1 on TOS which does not appear possible. */
aoqi@0 1138 verify_error(ErrorContext::bad_type(
aoqi@0 1139 bci, current_frame.stack_top_ctx()), bad_type_msg, "dup_x2");
aoqi@0 1140 return;
aoqi@0 1141 }
aoqi@0 1142 current_frame.push_stack(type, CHECK_VERIFY(this));
aoqi@0 1143 current_frame.push_stack(type3, CHECK_VERIFY(this));
aoqi@0 1144 current_frame.push_stack(type2, CHECK_VERIFY(this));
aoqi@0 1145 current_frame.push_stack(type, CHECK_VERIFY(this));
aoqi@0 1146 no_control_flow = false; break;
aoqi@0 1147 }
aoqi@0 1148 case Bytecodes::_dup2 :
aoqi@0 1149 type = current_frame.pop_stack(CHECK_VERIFY(this));
aoqi@0 1150 if (type.is_category1()) {
aoqi@0 1151 type2 = current_frame.pop_stack(
aoqi@0 1152 VerificationType::category1_check(), CHECK_VERIFY(this));
aoqi@0 1153 } else if (type.is_category2_2nd()) {
aoqi@0 1154 type2 = current_frame.pop_stack(
aoqi@0 1155 VerificationType::category2_check(), CHECK_VERIFY(this));
aoqi@0 1156 } else {
aoqi@0 1157 /* Unreachable? Would need a category2_1st on TOS which does not
aoqi@0 1158 * appear possible. */
aoqi@0 1159 verify_error(
aoqi@0 1160 ErrorContext::bad_type(bci, current_frame.stack_top_ctx()),
aoqi@0 1161 bad_type_msg, "dup2");
aoqi@0 1162 return;
aoqi@0 1163 }
aoqi@0 1164 current_frame.push_stack(type2, CHECK_VERIFY(this));
aoqi@0 1165 current_frame.push_stack(type, CHECK_VERIFY(this));
aoqi@0 1166 current_frame.push_stack(type2, CHECK_VERIFY(this));
aoqi@0 1167 current_frame.push_stack(type, CHECK_VERIFY(this));
aoqi@0 1168 no_control_flow = false; break;
aoqi@0 1169 case Bytecodes::_dup2_x1 :
aoqi@0 1170 {
aoqi@0 1171 VerificationType type3;
aoqi@0 1172 type = current_frame.pop_stack(CHECK_VERIFY(this));
aoqi@0 1173 if (type.is_category1()) {
aoqi@0 1174 type2 = current_frame.pop_stack(
aoqi@0 1175 VerificationType::category1_check(), CHECK_VERIFY(this));
aoqi@0 1176 } else if (type.is_category2_2nd()) {
aoqi@0 1177 type2 = current_frame.pop_stack(
aoqi@0 1178 VerificationType::category2_check(), CHECK_VERIFY(this));
aoqi@0 1179 } else {
aoqi@0 1180 /* Unreachable? Would need a category2_1st on TOS which does
aoqi@0 1181 * not appear possible. */
aoqi@0 1182 verify_error(
aoqi@0 1183 ErrorContext::bad_type(bci, current_frame.stack_top_ctx()),
aoqi@0 1184 bad_type_msg, "dup2_x1");
aoqi@0 1185 return;
aoqi@0 1186 }
aoqi@0 1187 type3 = current_frame.pop_stack(
aoqi@0 1188 VerificationType::category1_check(), CHECK_VERIFY(this));
aoqi@0 1189 current_frame.push_stack(type2, CHECK_VERIFY(this));
aoqi@0 1190 current_frame.push_stack(type, CHECK_VERIFY(this));
aoqi@0 1191 current_frame.push_stack(type3, CHECK_VERIFY(this));
aoqi@0 1192 current_frame.push_stack(type2, CHECK_VERIFY(this));
aoqi@0 1193 current_frame.push_stack(type, CHECK_VERIFY(this));
aoqi@0 1194 no_control_flow = false; break;
aoqi@0 1195 }
aoqi@0 1196 case Bytecodes::_dup2_x2 :
aoqi@0 1197 {
aoqi@0 1198 VerificationType type3, type4;
aoqi@0 1199 type = current_frame.pop_stack(CHECK_VERIFY(this));
aoqi@0 1200 if (type.is_category1()) {
aoqi@0 1201 type2 = current_frame.pop_stack(
aoqi@0 1202 VerificationType::category1_check(), CHECK_VERIFY(this));
aoqi@0 1203 } else if (type.is_category2_2nd()) {
aoqi@0 1204 type2 = current_frame.pop_stack(
aoqi@0 1205 VerificationType::category2_check(), CHECK_VERIFY(this));
aoqi@0 1206 } else {
aoqi@0 1207 /* Unreachable? Would need a category2_1st on TOS which does
aoqi@0 1208 * not appear possible. */
aoqi@0 1209 verify_error(
aoqi@0 1210 ErrorContext::bad_type(bci, current_frame.stack_top_ctx()),
aoqi@0 1211 bad_type_msg, "dup2_x2");
aoqi@0 1212 return;
aoqi@0 1213 }
aoqi@0 1214 type3 = current_frame.pop_stack(CHECK_VERIFY(this));
aoqi@0 1215 if (type3.is_category1()) {
aoqi@0 1216 type4 = current_frame.pop_stack(
aoqi@0 1217 VerificationType::category1_check(), CHECK_VERIFY(this));
aoqi@0 1218 } else if (type3.is_category2_2nd()) {
aoqi@0 1219 type4 = current_frame.pop_stack(
aoqi@0 1220 VerificationType::category2_check(), CHECK_VERIFY(this));
aoqi@0 1221 } else {
aoqi@0 1222 /* Unreachable? Would need a category2_1st on TOS after popping
aoqi@0 1223 * a long/double or two category 1's, which does not
aoqi@0 1224 * appear possible. */
aoqi@0 1225 verify_error(
aoqi@0 1226 ErrorContext::bad_type(bci, current_frame.stack_top_ctx()),
aoqi@0 1227 bad_type_msg, "dup2_x2");
aoqi@0 1228 return;
aoqi@0 1229 }
aoqi@0 1230 current_frame.push_stack(type2, CHECK_VERIFY(this));
aoqi@0 1231 current_frame.push_stack(type, CHECK_VERIFY(this));
aoqi@0 1232 current_frame.push_stack(type4, CHECK_VERIFY(this));
aoqi@0 1233 current_frame.push_stack(type3, CHECK_VERIFY(this));
aoqi@0 1234 current_frame.push_stack(type2, CHECK_VERIFY(this));
aoqi@0 1235 current_frame.push_stack(type, CHECK_VERIFY(this));
aoqi@0 1236 no_control_flow = false; break;
aoqi@0 1237 }
aoqi@0 1238 case Bytecodes::_swap :
aoqi@0 1239 type = current_frame.pop_stack(
aoqi@0 1240 VerificationType::category1_check(), CHECK_VERIFY(this));
aoqi@0 1241 type2 = current_frame.pop_stack(
aoqi@0 1242 VerificationType::category1_check(), CHECK_VERIFY(this));
aoqi@0 1243 current_frame.push_stack(type, CHECK_VERIFY(this));
aoqi@0 1244 current_frame.push_stack(type2, CHECK_VERIFY(this));
aoqi@0 1245 no_control_flow = false; break;
aoqi@0 1246 case Bytecodes::_iadd :
aoqi@0 1247 case Bytecodes::_isub :
aoqi@0 1248 case Bytecodes::_imul :
aoqi@0 1249 case Bytecodes::_idiv :
aoqi@0 1250 case Bytecodes::_irem :
aoqi@0 1251 case Bytecodes::_ishl :
aoqi@0 1252 case Bytecodes::_ishr :
aoqi@0 1253 case Bytecodes::_iushr :
aoqi@0 1254 case Bytecodes::_ior :
aoqi@0 1255 case Bytecodes::_ixor :
aoqi@0 1256 case Bytecodes::_iand :
aoqi@0 1257 current_frame.pop_stack(
aoqi@0 1258 VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 1259 // fall through
aoqi@0 1260 case Bytecodes::_ineg :
aoqi@0 1261 current_frame.pop_stack(
aoqi@0 1262 VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 1263 current_frame.push_stack(
aoqi@0 1264 VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 1265 no_control_flow = false; break;
aoqi@0 1266 case Bytecodes::_ladd :
aoqi@0 1267 case Bytecodes::_lsub :
aoqi@0 1268 case Bytecodes::_lmul :
aoqi@0 1269 case Bytecodes::_ldiv :
aoqi@0 1270 case Bytecodes::_lrem :
aoqi@0 1271 case Bytecodes::_land :
aoqi@0 1272 case Bytecodes::_lor :
aoqi@0 1273 case Bytecodes::_lxor :
aoqi@0 1274 current_frame.pop_stack_2(
aoqi@0 1275 VerificationType::long2_type(),
aoqi@0 1276 VerificationType::long_type(), CHECK_VERIFY(this));
aoqi@0 1277 // fall through
aoqi@0 1278 case Bytecodes::_lneg :
aoqi@0 1279 current_frame.pop_stack_2(
aoqi@0 1280 VerificationType::long2_type(),
aoqi@0 1281 VerificationType::long_type(), CHECK_VERIFY(this));
aoqi@0 1282 current_frame.push_stack_2(
aoqi@0 1283 VerificationType::long_type(),
aoqi@0 1284 VerificationType::long2_type(), CHECK_VERIFY(this));
aoqi@0 1285 no_control_flow = false; break;
aoqi@0 1286 case Bytecodes::_lshl :
aoqi@0 1287 case Bytecodes::_lshr :
aoqi@0 1288 case Bytecodes::_lushr :
aoqi@0 1289 current_frame.pop_stack(
aoqi@0 1290 VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 1291 current_frame.pop_stack_2(
aoqi@0 1292 VerificationType::long2_type(),
aoqi@0 1293 VerificationType::long_type(), CHECK_VERIFY(this));
aoqi@0 1294 current_frame.push_stack_2(
aoqi@0 1295 VerificationType::long_type(),
aoqi@0 1296 VerificationType::long2_type(), CHECK_VERIFY(this));
aoqi@0 1297 no_control_flow = false; break;
aoqi@0 1298 case Bytecodes::_fadd :
aoqi@0 1299 case Bytecodes::_fsub :
aoqi@0 1300 case Bytecodes::_fmul :
aoqi@0 1301 case Bytecodes::_fdiv :
aoqi@0 1302 case Bytecodes::_frem :
aoqi@0 1303 current_frame.pop_stack(
aoqi@0 1304 VerificationType::float_type(), CHECK_VERIFY(this));
aoqi@0 1305 // fall through
aoqi@0 1306 case Bytecodes::_fneg :
aoqi@0 1307 current_frame.pop_stack(
aoqi@0 1308 VerificationType::float_type(), CHECK_VERIFY(this));
aoqi@0 1309 current_frame.push_stack(
aoqi@0 1310 VerificationType::float_type(), CHECK_VERIFY(this));
aoqi@0 1311 no_control_flow = false; break;
aoqi@0 1312 case Bytecodes::_dadd :
aoqi@0 1313 case Bytecodes::_dsub :
aoqi@0 1314 case Bytecodes::_dmul :
aoqi@0 1315 case Bytecodes::_ddiv :
aoqi@0 1316 case Bytecodes::_drem :
aoqi@0 1317 current_frame.pop_stack_2(
aoqi@0 1318 VerificationType::double2_type(),
aoqi@0 1319 VerificationType::double_type(), CHECK_VERIFY(this));
aoqi@0 1320 // fall through
aoqi@0 1321 case Bytecodes::_dneg :
aoqi@0 1322 current_frame.pop_stack_2(
aoqi@0 1323 VerificationType::double2_type(),
aoqi@0 1324 VerificationType::double_type(), CHECK_VERIFY(this));
aoqi@0 1325 current_frame.push_stack_2(
aoqi@0 1326 VerificationType::double_type(),
aoqi@0 1327 VerificationType::double2_type(), CHECK_VERIFY(this));
aoqi@0 1328 no_control_flow = false; break;
aoqi@0 1329 case Bytecodes::_iinc :
aoqi@0 1330 verify_iinc(bcs.get_index(), &current_frame, CHECK_VERIFY(this));
aoqi@0 1331 no_control_flow = false; break;
aoqi@0 1332 case Bytecodes::_i2l :
aoqi@0 1333 type = current_frame.pop_stack(
aoqi@0 1334 VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 1335 current_frame.push_stack_2(
aoqi@0 1336 VerificationType::long_type(),
aoqi@0 1337 VerificationType::long2_type(), CHECK_VERIFY(this));
aoqi@0 1338 no_control_flow = false; break;
aoqi@0 1339 case Bytecodes::_l2i :
aoqi@0 1340 current_frame.pop_stack_2(
aoqi@0 1341 VerificationType::long2_type(),
aoqi@0 1342 VerificationType::long_type(), CHECK_VERIFY(this));
aoqi@0 1343 current_frame.push_stack(
aoqi@0 1344 VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 1345 no_control_flow = false; break;
aoqi@0 1346 case Bytecodes::_i2f :
aoqi@0 1347 current_frame.pop_stack(
aoqi@0 1348 VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 1349 current_frame.push_stack(
aoqi@0 1350 VerificationType::float_type(), CHECK_VERIFY(this));
aoqi@0 1351 no_control_flow = false; break;
aoqi@0 1352 case Bytecodes::_i2d :
aoqi@0 1353 current_frame.pop_stack(
aoqi@0 1354 VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 1355 current_frame.push_stack_2(
aoqi@0 1356 VerificationType::double_type(),
aoqi@0 1357 VerificationType::double2_type(), CHECK_VERIFY(this));
aoqi@0 1358 no_control_flow = false; break;
aoqi@0 1359 case Bytecodes::_l2f :
aoqi@0 1360 current_frame.pop_stack_2(
aoqi@0 1361 VerificationType::long2_type(),
aoqi@0 1362 VerificationType::long_type(), CHECK_VERIFY(this));
aoqi@0 1363 current_frame.push_stack(
aoqi@0 1364 VerificationType::float_type(), CHECK_VERIFY(this));
aoqi@0 1365 no_control_flow = false; break;
aoqi@0 1366 case Bytecodes::_l2d :
aoqi@0 1367 current_frame.pop_stack_2(
aoqi@0 1368 VerificationType::long2_type(),
aoqi@0 1369 VerificationType::long_type(), CHECK_VERIFY(this));
aoqi@0 1370 current_frame.push_stack_2(
aoqi@0 1371 VerificationType::double_type(),
aoqi@0 1372 VerificationType::double2_type(), CHECK_VERIFY(this));
aoqi@0 1373 no_control_flow = false; break;
aoqi@0 1374 case Bytecodes::_f2i :
aoqi@0 1375 current_frame.pop_stack(
aoqi@0 1376 VerificationType::float_type(), CHECK_VERIFY(this));
aoqi@0 1377 current_frame.push_stack(
aoqi@0 1378 VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 1379 no_control_flow = false; break;
aoqi@0 1380 case Bytecodes::_f2l :
aoqi@0 1381 current_frame.pop_stack(
aoqi@0 1382 VerificationType::float_type(), CHECK_VERIFY(this));
aoqi@0 1383 current_frame.push_stack_2(
aoqi@0 1384 VerificationType::long_type(),
aoqi@0 1385 VerificationType::long2_type(), CHECK_VERIFY(this));
aoqi@0 1386 no_control_flow = false; break;
aoqi@0 1387 case Bytecodes::_f2d :
aoqi@0 1388 current_frame.pop_stack(
aoqi@0 1389 VerificationType::float_type(), CHECK_VERIFY(this));
aoqi@0 1390 current_frame.push_stack_2(
aoqi@0 1391 VerificationType::double_type(),
aoqi@0 1392 VerificationType::double2_type(), CHECK_VERIFY(this));
aoqi@0 1393 no_control_flow = false; break;
aoqi@0 1394 case Bytecodes::_d2i :
aoqi@0 1395 current_frame.pop_stack_2(
aoqi@0 1396 VerificationType::double2_type(),
aoqi@0 1397 VerificationType::double_type(), CHECK_VERIFY(this));
aoqi@0 1398 current_frame.push_stack(
aoqi@0 1399 VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 1400 no_control_flow = false; break;
aoqi@0 1401 case Bytecodes::_d2l :
aoqi@0 1402 current_frame.pop_stack_2(
aoqi@0 1403 VerificationType::double2_type(),
aoqi@0 1404 VerificationType::double_type(), CHECK_VERIFY(this));
aoqi@0 1405 current_frame.push_stack_2(
aoqi@0 1406 VerificationType::long_type(),
aoqi@0 1407 VerificationType::long2_type(), CHECK_VERIFY(this));
aoqi@0 1408 no_control_flow = false; break;
aoqi@0 1409 case Bytecodes::_d2f :
aoqi@0 1410 current_frame.pop_stack_2(
aoqi@0 1411 VerificationType::double2_type(),
aoqi@0 1412 VerificationType::double_type(), CHECK_VERIFY(this));
aoqi@0 1413 current_frame.push_stack(
aoqi@0 1414 VerificationType::float_type(), CHECK_VERIFY(this));
aoqi@0 1415 no_control_flow = false; break;
aoqi@0 1416 case Bytecodes::_i2b :
aoqi@0 1417 case Bytecodes::_i2c :
aoqi@0 1418 case Bytecodes::_i2s :
aoqi@0 1419 current_frame.pop_stack(
aoqi@0 1420 VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 1421 current_frame.push_stack(
aoqi@0 1422 VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 1423 no_control_flow = false; break;
aoqi@0 1424 case Bytecodes::_lcmp :
aoqi@0 1425 current_frame.pop_stack_2(
aoqi@0 1426 VerificationType::long2_type(),
aoqi@0 1427 VerificationType::long_type(), CHECK_VERIFY(this));
aoqi@0 1428 current_frame.pop_stack_2(
aoqi@0 1429 VerificationType::long2_type(),
aoqi@0 1430 VerificationType::long_type(), CHECK_VERIFY(this));
aoqi@0 1431 current_frame.push_stack(
aoqi@0 1432 VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 1433 no_control_flow = false; break;
aoqi@0 1434 case Bytecodes::_fcmpl :
aoqi@0 1435 case Bytecodes::_fcmpg :
aoqi@0 1436 current_frame.pop_stack(
aoqi@0 1437 VerificationType::float_type(), CHECK_VERIFY(this));
aoqi@0 1438 current_frame.pop_stack(
aoqi@0 1439 VerificationType::float_type(), CHECK_VERIFY(this));
aoqi@0 1440 current_frame.push_stack(
aoqi@0 1441 VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 1442 no_control_flow = false; break;
aoqi@0 1443 case Bytecodes::_dcmpl :
aoqi@0 1444 case Bytecodes::_dcmpg :
aoqi@0 1445 current_frame.pop_stack_2(
aoqi@0 1446 VerificationType::double2_type(),
aoqi@0 1447 VerificationType::double_type(), CHECK_VERIFY(this));
aoqi@0 1448 current_frame.pop_stack_2(
aoqi@0 1449 VerificationType::double2_type(),
aoqi@0 1450 VerificationType::double_type(), CHECK_VERIFY(this));
aoqi@0 1451 current_frame.push_stack(
aoqi@0 1452 VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 1453 no_control_flow = false; break;
aoqi@0 1454 case Bytecodes::_if_icmpeq:
aoqi@0 1455 case Bytecodes::_if_icmpne:
aoqi@0 1456 case Bytecodes::_if_icmplt:
aoqi@0 1457 case Bytecodes::_if_icmpge:
aoqi@0 1458 case Bytecodes::_if_icmpgt:
aoqi@0 1459 case Bytecodes::_if_icmple:
aoqi@0 1460 current_frame.pop_stack(
aoqi@0 1461 VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 1462 // fall through
aoqi@0 1463 case Bytecodes::_ifeq:
aoqi@0 1464 case Bytecodes::_ifne:
aoqi@0 1465 case Bytecodes::_iflt:
aoqi@0 1466 case Bytecodes::_ifge:
aoqi@0 1467 case Bytecodes::_ifgt:
aoqi@0 1468 case Bytecodes::_ifle:
aoqi@0 1469 current_frame.pop_stack(
aoqi@0 1470 VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 1471 target = bcs.dest();
aoqi@0 1472 stackmap_table.check_jump_target(
aoqi@0 1473 &current_frame, target, CHECK_VERIFY(this));
aoqi@0 1474 no_control_flow = false; break;
aoqi@0 1475 case Bytecodes::_if_acmpeq :
aoqi@0 1476 case Bytecodes::_if_acmpne :
aoqi@0 1477 current_frame.pop_stack(
aoqi@0 1478 VerificationType::reference_check(), CHECK_VERIFY(this));
aoqi@0 1479 // fall through
aoqi@0 1480 case Bytecodes::_ifnull :
aoqi@0 1481 case Bytecodes::_ifnonnull :
aoqi@0 1482 current_frame.pop_stack(
aoqi@0 1483 VerificationType::reference_check(), CHECK_VERIFY(this));
aoqi@0 1484 target = bcs.dest();
aoqi@0 1485 stackmap_table.check_jump_target
aoqi@0 1486 (&current_frame, target, CHECK_VERIFY(this));
aoqi@0 1487 no_control_flow = false; break;
aoqi@0 1488 case Bytecodes::_goto :
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 = true; break;
aoqi@0 1493 case Bytecodes::_goto_w :
aoqi@0 1494 target = bcs.dest_w();
aoqi@0 1495 stackmap_table.check_jump_target(
aoqi@0 1496 &current_frame, target, CHECK_VERIFY(this));
aoqi@0 1497 no_control_flow = true; break;
aoqi@0 1498 case Bytecodes::_tableswitch :
aoqi@0 1499 case Bytecodes::_lookupswitch :
aoqi@0 1500 verify_switch(
aoqi@0 1501 &bcs, code_length, code_data, &current_frame,
aoqi@0 1502 &stackmap_table, CHECK_VERIFY(this));
aoqi@0 1503 no_control_flow = true; break;
aoqi@0 1504 case Bytecodes::_ireturn :
aoqi@0 1505 type = current_frame.pop_stack(
aoqi@0 1506 VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 1507 verify_return_value(return_type, type, bci,
aoqi@0 1508 &current_frame, CHECK_VERIFY(this));
aoqi@0 1509 no_control_flow = true; break;
aoqi@0 1510 case Bytecodes::_lreturn :
aoqi@0 1511 type2 = current_frame.pop_stack(
aoqi@0 1512 VerificationType::long2_type(), CHECK_VERIFY(this));
aoqi@0 1513 type = current_frame.pop_stack(
aoqi@0 1514 VerificationType::long_type(), CHECK_VERIFY(this));
aoqi@0 1515 verify_return_value(return_type, type, bci,
aoqi@0 1516 &current_frame, CHECK_VERIFY(this));
aoqi@0 1517 no_control_flow = true; break;
aoqi@0 1518 case Bytecodes::_freturn :
aoqi@0 1519 type = current_frame.pop_stack(
aoqi@0 1520 VerificationType::float_type(), CHECK_VERIFY(this));
aoqi@0 1521 verify_return_value(return_type, type, bci,
aoqi@0 1522 &current_frame, CHECK_VERIFY(this));
aoqi@0 1523 no_control_flow = true; break;
aoqi@0 1524 case Bytecodes::_dreturn :
aoqi@0 1525 type2 = current_frame.pop_stack(
aoqi@0 1526 VerificationType::double2_type(), CHECK_VERIFY(this));
aoqi@0 1527 type = current_frame.pop_stack(
aoqi@0 1528 VerificationType::double_type(), CHECK_VERIFY(this));
aoqi@0 1529 verify_return_value(return_type, type, bci,
aoqi@0 1530 &current_frame, CHECK_VERIFY(this));
aoqi@0 1531 no_control_flow = true; break;
aoqi@0 1532 case Bytecodes::_areturn :
aoqi@0 1533 type = current_frame.pop_stack(
aoqi@0 1534 VerificationType::reference_check(), CHECK_VERIFY(this));
aoqi@0 1535 verify_return_value(return_type, type, bci,
aoqi@0 1536 &current_frame, CHECK_VERIFY(this));
aoqi@0 1537 no_control_flow = true; break;
aoqi@0 1538 case Bytecodes::_return :
aoqi@0 1539 if (return_type != VerificationType::bogus_type()) {
aoqi@0 1540 verify_error(ErrorContext::bad_code(bci),
aoqi@0 1541 "Method expects a return value");
aoqi@0 1542 return;
aoqi@0 1543 }
aoqi@0 1544 // Make sure "this" has been initialized if current method is an
aoqi@0 1545 // <init>
aoqi@0 1546 if (_method->name() == vmSymbols::object_initializer_name() &&
aoqi@0 1547 current_frame.flag_this_uninit()) {
aoqi@0 1548 verify_error(ErrorContext::bad_code(bci),
aoqi@0 1549 "Constructor must call super() or this() "
aoqi@0 1550 "before return");
aoqi@0 1551 return;
aoqi@0 1552 }
aoqi@0 1553 no_control_flow = true; break;
aoqi@0 1554 case Bytecodes::_getstatic :
aoqi@0 1555 case Bytecodes::_putstatic :
aoqi@0 1556 case Bytecodes::_getfield :
aoqi@0 1557 case Bytecodes::_putfield :
aoqi@0 1558 verify_field_instructions(
aoqi@0 1559 &bcs, &current_frame, cp, CHECK_VERIFY(this));
aoqi@0 1560 no_control_flow = false; break;
aoqi@0 1561 case Bytecodes::_invokevirtual :
aoqi@0 1562 case Bytecodes::_invokespecial :
aoqi@0 1563 case Bytecodes::_invokestatic :
aoqi@0 1564 verify_invoke_instructions(
aoqi@0 1565 &bcs, code_length, &current_frame,
aoqi@0 1566 &this_uninit, return_type, cp, CHECK_VERIFY(this));
aoqi@0 1567 no_control_flow = false; break;
aoqi@0 1568 case Bytecodes::_invokeinterface :
aoqi@0 1569 case Bytecodes::_invokedynamic :
aoqi@0 1570 verify_invoke_instructions(
aoqi@0 1571 &bcs, code_length, &current_frame,
aoqi@0 1572 &this_uninit, return_type, cp, CHECK_VERIFY(this));
aoqi@0 1573 no_control_flow = false; break;
aoqi@0 1574 case Bytecodes::_new :
aoqi@0 1575 {
aoqi@0 1576 index = bcs.get_index_u2();
aoqi@0 1577 verify_cp_class_type(bci, index, cp, CHECK_VERIFY(this));
aoqi@0 1578 VerificationType new_class_type =
aoqi@0 1579 cp_index_to_type(index, cp, CHECK_VERIFY(this));
aoqi@0 1580 if (!new_class_type.is_object()) {
aoqi@0 1581 verify_error(ErrorContext::bad_type(bci,
aoqi@0 1582 TypeOrigin::cp(index, new_class_type)),
aoqi@0 1583 "Illegal new instruction");
aoqi@0 1584 return;
aoqi@0 1585 }
aoqi@0 1586 type = VerificationType::uninitialized_type(bci);
aoqi@0 1587 current_frame.push_stack(type, CHECK_VERIFY(this));
aoqi@0 1588 no_control_flow = false; break;
aoqi@0 1589 }
aoqi@0 1590 case Bytecodes::_newarray :
aoqi@0 1591 type = get_newarray_type(bcs.get_index(), bci, CHECK_VERIFY(this));
aoqi@0 1592 current_frame.pop_stack(
aoqi@0 1593 VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 1594 current_frame.push_stack(type, CHECK_VERIFY(this));
aoqi@0 1595 no_control_flow = false; break;
aoqi@0 1596 case Bytecodes::_anewarray :
aoqi@0 1597 verify_anewarray(
aoqi@0 1598 bci, bcs.get_index_u2(), cp, &current_frame, CHECK_VERIFY(this));
aoqi@0 1599 no_control_flow = false; break;
aoqi@0 1600 case Bytecodes::_arraylength :
aoqi@0 1601 type = current_frame.pop_stack(
aoqi@0 1602 VerificationType::reference_check(), CHECK_VERIFY(this));
aoqi@0 1603 if (!(type.is_null() || type.is_array())) {
aoqi@0 1604 verify_error(ErrorContext::bad_type(
aoqi@0 1605 bci, current_frame.stack_top_ctx()),
aoqi@0 1606 bad_type_msg, "arraylength");
aoqi@0 1607 }
aoqi@0 1608 current_frame.push_stack(
aoqi@0 1609 VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 1610 no_control_flow = false; break;
aoqi@0 1611 case Bytecodes::_checkcast :
aoqi@0 1612 {
aoqi@0 1613 index = bcs.get_index_u2();
aoqi@0 1614 verify_cp_class_type(bci, index, cp, CHECK_VERIFY(this));
aoqi@0 1615 current_frame.pop_stack(object_type(), CHECK_VERIFY(this));
aoqi@0 1616 VerificationType klass_type = cp_index_to_type(
aoqi@0 1617 index, cp, CHECK_VERIFY(this));
aoqi@0 1618 current_frame.push_stack(klass_type, CHECK_VERIFY(this));
aoqi@0 1619 no_control_flow = false; break;
aoqi@0 1620 }
aoqi@0 1621 case Bytecodes::_instanceof : {
aoqi@0 1622 index = bcs.get_index_u2();
aoqi@0 1623 verify_cp_class_type(bci, index, cp, CHECK_VERIFY(this));
aoqi@0 1624 current_frame.pop_stack(object_type(), CHECK_VERIFY(this));
aoqi@0 1625 current_frame.push_stack(
aoqi@0 1626 VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 1627 no_control_flow = false; break;
aoqi@0 1628 }
aoqi@0 1629 case Bytecodes::_monitorenter :
aoqi@0 1630 case Bytecodes::_monitorexit :
aoqi@0 1631 current_frame.pop_stack(
aoqi@0 1632 VerificationType::reference_check(), CHECK_VERIFY(this));
aoqi@0 1633 no_control_flow = false; break;
aoqi@0 1634 case Bytecodes::_multianewarray :
aoqi@0 1635 {
aoqi@0 1636 index = bcs.get_index_u2();
aoqi@0 1637 u2 dim = *(bcs.bcp()+3);
aoqi@0 1638 verify_cp_class_type(bci, index, cp, CHECK_VERIFY(this));
aoqi@0 1639 VerificationType new_array_type =
aoqi@0 1640 cp_index_to_type(index, cp, CHECK_VERIFY(this));
aoqi@0 1641 if (!new_array_type.is_array()) {
aoqi@0 1642 verify_error(ErrorContext::bad_type(bci,
aoqi@0 1643 TypeOrigin::cp(index, new_array_type)),
aoqi@0 1644 "Illegal constant pool index in multianewarray instruction");
aoqi@0 1645 return;
aoqi@0 1646 }
aoqi@0 1647 if (dim < 1 || new_array_type.dimensions() < dim) {
aoqi@0 1648 verify_error(ErrorContext::bad_code(bci),
aoqi@0 1649 "Illegal dimension in multianewarray instruction: %d", dim);
aoqi@0 1650 return;
aoqi@0 1651 }
aoqi@0 1652 for (int i = 0; i < dim; i++) {
aoqi@0 1653 current_frame.pop_stack(
aoqi@0 1654 VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 1655 }
aoqi@0 1656 current_frame.push_stack(new_array_type, CHECK_VERIFY(this));
aoqi@0 1657 no_control_flow = false; break;
aoqi@0 1658 }
aoqi@0 1659 case Bytecodes::_athrow :
aoqi@0 1660 type = VerificationType::reference_type(
aoqi@0 1661 vmSymbols::java_lang_Throwable());
aoqi@0 1662 current_frame.pop_stack(type, CHECK_VERIFY(this));
aoqi@0 1663 no_control_flow = true; break;
aoqi@0 1664 default:
aoqi@0 1665 // We only need to check the valid bytecodes in class file.
aoqi@0 1666 // And jsr and ret are not in the new class file format in JDK1.5.
aoqi@0 1667 verify_error(ErrorContext::bad_code(bci),
aoqi@0 1668 "Bad instruction: %02x", opcode);
aoqi@0 1669 no_control_flow = false;
aoqi@0 1670 return;
aoqi@0 1671 } // end switch
aoqi@0 1672 } // end Merge with the next instruction
aoqi@0 1673
aoqi@0 1674 // Look for possible jump target in exception handlers and see if it
aoqi@0 1675 // matches current_frame
aoqi@0 1676 if (bci >= ex_min && bci < ex_max) {
aoqi@0 1677 verify_exception_handler_targets(
aoqi@0 1678 bci, this_uninit, &current_frame, &stackmap_table, CHECK_VERIFY(this));
aoqi@0 1679 }
aoqi@0 1680 } // end while
aoqi@0 1681
aoqi@0 1682 // Make sure that control flow does not fall through end of the method
aoqi@0 1683 if (!no_control_flow) {
aoqi@0 1684 verify_error(ErrorContext::bad_code(code_length),
aoqi@0 1685 "Control flow falls through code end");
aoqi@0 1686 return;
aoqi@0 1687 }
aoqi@0 1688 }
aoqi@0 1689
aoqi@0 1690 #undef bad_type_message
aoqi@0 1691
aoqi@0 1692 char* ClassVerifier::generate_code_data(methodHandle m, u4 code_length, TRAPS) {
aoqi@0 1693 char* code_data = NEW_RESOURCE_ARRAY(char, code_length);
aoqi@0 1694 memset(code_data, 0, sizeof(char) * code_length);
aoqi@0 1695 RawBytecodeStream bcs(m);
aoqi@0 1696
aoqi@0 1697 while (!bcs.is_last_bytecode()) {
aoqi@0 1698 if (bcs.raw_next() != Bytecodes::_illegal) {
aoqi@0 1699 int bci = bcs.bci();
aoqi@0 1700 if (bcs.raw_code() == Bytecodes::_new) {
aoqi@0 1701 code_data[bci] = NEW_OFFSET;
aoqi@0 1702 } else {
aoqi@0 1703 code_data[bci] = BYTECODE_OFFSET;
aoqi@0 1704 }
aoqi@0 1705 } else {
aoqi@0 1706 verify_error(ErrorContext::bad_code(bcs.bci()), "Bad instruction");
aoqi@0 1707 return NULL;
aoqi@0 1708 }
aoqi@0 1709 }
aoqi@0 1710
aoqi@0 1711 return code_data;
aoqi@0 1712 }
aoqi@0 1713
aoqi@0 1714 void ClassVerifier::verify_exception_handler_table(u4 code_length, char* code_data, int& min, int& max, TRAPS) {
aoqi@0 1715 ExceptionTable exhandlers(_method());
aoqi@0 1716 int exlength = exhandlers.length();
aoqi@0 1717 constantPoolHandle cp (THREAD, _method->constants());
aoqi@0 1718
aoqi@0 1719 for(int i = 0; i < exlength; i++) {
aoqi@0 1720 //reacquire the table in case a GC happened
aoqi@0 1721 ExceptionTable exhandlers(_method());
aoqi@0 1722 u2 start_pc = exhandlers.start_pc(i);
aoqi@0 1723 u2 end_pc = exhandlers.end_pc(i);
aoqi@0 1724 u2 handler_pc = exhandlers.handler_pc(i);
aoqi@0 1725 if (start_pc >= code_length || code_data[start_pc] == 0) {
aoqi@0 1726 class_format_error("Illegal exception table start_pc %d", start_pc);
aoqi@0 1727 return;
aoqi@0 1728 }
aoqi@0 1729 if (end_pc != code_length) { // special case: end_pc == code_length
aoqi@0 1730 if (end_pc > code_length || code_data[end_pc] == 0) {
aoqi@0 1731 class_format_error("Illegal exception table end_pc %d", end_pc);
aoqi@0 1732 return;
aoqi@0 1733 }
aoqi@0 1734 }
aoqi@0 1735 if (handler_pc >= code_length || code_data[handler_pc] == 0) {
aoqi@0 1736 class_format_error("Illegal exception table handler_pc %d", handler_pc);
aoqi@0 1737 return;
aoqi@0 1738 }
aoqi@0 1739 int catch_type_index = exhandlers.catch_type_index(i);
aoqi@0 1740 if (catch_type_index != 0) {
aoqi@0 1741 VerificationType catch_type = cp_index_to_type(
aoqi@0 1742 catch_type_index, cp, CHECK_VERIFY(this));
aoqi@0 1743 VerificationType throwable =
aoqi@0 1744 VerificationType::reference_type(vmSymbols::java_lang_Throwable());
aoqi@0 1745 bool is_subclass = throwable.is_assignable_from(
aoqi@0 1746 catch_type, this, false, CHECK_VERIFY(this));
aoqi@0 1747 if (!is_subclass) {
aoqi@0 1748 // 4286534: should throw VerifyError according to recent spec change
aoqi@0 1749 verify_error(ErrorContext::bad_type(handler_pc,
aoqi@0 1750 TypeOrigin::cp(catch_type_index, catch_type),
aoqi@0 1751 TypeOrigin::implicit(throwable)),
aoqi@0 1752 "Catch type is not a subclass "
aoqi@0 1753 "of Throwable in exception handler %d", handler_pc);
aoqi@0 1754 return;
aoqi@0 1755 }
aoqi@0 1756 }
aoqi@0 1757 if (start_pc < min) min = start_pc;
aoqi@0 1758 if (end_pc > max) max = end_pc;
aoqi@0 1759 }
aoqi@0 1760 }
aoqi@0 1761
aoqi@0 1762 void ClassVerifier::verify_local_variable_table(u4 code_length, char* code_data, TRAPS) {
aoqi@0 1763 int localvariable_table_length = _method()->localvariable_table_length();
aoqi@0 1764 if (localvariable_table_length > 0) {
aoqi@0 1765 LocalVariableTableElement* table = _method()->localvariable_table_start();
aoqi@0 1766 for (int i = 0; i < localvariable_table_length; i++) {
aoqi@0 1767 u2 start_bci = table[i].start_bci;
aoqi@0 1768 u2 length = table[i].length;
aoqi@0 1769
aoqi@0 1770 if (start_bci >= code_length || code_data[start_bci] == 0) {
aoqi@0 1771 class_format_error(
aoqi@0 1772 "Illegal local variable table start_pc %d", start_bci);
aoqi@0 1773 return;
aoqi@0 1774 }
aoqi@0 1775 u4 end_bci = (u4)(start_bci + length);
aoqi@0 1776 if (end_bci != code_length) {
aoqi@0 1777 if (end_bci >= code_length || code_data[end_bci] == 0) {
aoqi@0 1778 class_format_error( "Illegal local variable table length %d", length);
aoqi@0 1779 return;
aoqi@0 1780 }
aoqi@0 1781 }
aoqi@0 1782 }
aoqi@0 1783 }
aoqi@0 1784 }
aoqi@0 1785
aoqi@0 1786 u2 ClassVerifier::verify_stackmap_table(u2 stackmap_index, u2 bci,
aoqi@0 1787 StackMapFrame* current_frame,
aoqi@0 1788 StackMapTable* stackmap_table,
aoqi@0 1789 bool no_control_flow, TRAPS) {
aoqi@0 1790 if (stackmap_index < stackmap_table->get_frame_count()) {
aoqi@0 1791 u2 this_offset = stackmap_table->get_offset(stackmap_index);
aoqi@0 1792 if (no_control_flow && this_offset > bci) {
aoqi@0 1793 verify_error(ErrorContext::missing_stackmap(bci),
aoqi@0 1794 "Expecting a stack map frame");
aoqi@0 1795 return 0;
aoqi@0 1796 }
aoqi@0 1797 if (this_offset == bci) {
aoqi@0 1798 ErrorContext ctx;
aoqi@0 1799 // See if current stack map can be assigned to the frame in table.
aoqi@0 1800 // current_frame is the stackmap frame got from the last instruction.
aoqi@0 1801 // If matched, current_frame will be updated by this method.
aoqi@0 1802 bool matches = stackmap_table->match_stackmap(
aoqi@0 1803 current_frame, this_offset, stackmap_index,
aoqi@0 1804 !no_control_flow, true, false, &ctx, CHECK_VERIFY_(this, 0));
aoqi@0 1805 if (!matches) {
aoqi@0 1806 // report type error
aoqi@0 1807 verify_error(ctx, "Instruction type does not match stack map");
aoqi@0 1808 return 0;
aoqi@0 1809 }
aoqi@0 1810 stackmap_index++;
aoqi@0 1811 } else if (this_offset < bci) {
aoqi@0 1812 // current_offset should have met this_offset.
aoqi@0 1813 class_format_error("Bad stack map offset %d", this_offset);
aoqi@0 1814 return 0;
aoqi@0 1815 }
aoqi@0 1816 } else if (no_control_flow) {
aoqi@0 1817 verify_error(ErrorContext::bad_code(bci), "Expecting a stack map frame");
aoqi@0 1818 return 0;
aoqi@0 1819 }
aoqi@0 1820 return stackmap_index;
aoqi@0 1821 }
aoqi@0 1822
aoqi@0 1823 void ClassVerifier::verify_exception_handler_targets(u2 bci, bool this_uninit, StackMapFrame* current_frame,
aoqi@0 1824 StackMapTable* stackmap_table, TRAPS) {
aoqi@0 1825 constantPoolHandle cp (THREAD, _method->constants());
aoqi@0 1826 ExceptionTable exhandlers(_method());
aoqi@0 1827 int exlength = exhandlers.length();
aoqi@0 1828 for(int i = 0; i < exlength; i++) {
aoqi@0 1829 //reacquire the table in case a GC happened
aoqi@0 1830 ExceptionTable exhandlers(_method());
aoqi@0 1831 u2 start_pc = exhandlers.start_pc(i);
aoqi@0 1832 u2 end_pc = exhandlers.end_pc(i);
aoqi@0 1833 u2 handler_pc = exhandlers.handler_pc(i);
aoqi@0 1834 int catch_type_index = exhandlers.catch_type_index(i);
aoqi@0 1835 if(bci >= start_pc && bci < end_pc) {
aoqi@0 1836 u1 flags = current_frame->flags();
aoqi@0 1837 if (this_uninit) { flags |= FLAG_THIS_UNINIT; }
aoqi@0 1838 StackMapFrame* new_frame = current_frame->frame_in_exception_handler(flags);
aoqi@0 1839 if (catch_type_index != 0) {
aoqi@0 1840 // We know that this index refers to a subclass of Throwable
aoqi@0 1841 VerificationType catch_type = cp_index_to_type(
aoqi@0 1842 catch_type_index, cp, CHECK_VERIFY(this));
aoqi@0 1843 new_frame->push_stack(catch_type, CHECK_VERIFY(this));
aoqi@0 1844 } else {
aoqi@0 1845 VerificationType throwable =
aoqi@0 1846 VerificationType::reference_type(vmSymbols::java_lang_Throwable());
aoqi@0 1847 new_frame->push_stack(throwable, CHECK_VERIFY(this));
aoqi@0 1848 }
aoqi@0 1849 ErrorContext ctx;
aoqi@0 1850 bool matches = stackmap_table->match_stackmap(
aoqi@0 1851 new_frame, handler_pc, true, false, true, &ctx, CHECK_VERIFY(this));
aoqi@0 1852 if (!matches) {
aoqi@0 1853 verify_error(ctx, "Stack map does not match the one at "
aoqi@0 1854 "exception handler %d", handler_pc);
aoqi@0 1855 return;
aoqi@0 1856 }
aoqi@0 1857 }
aoqi@0 1858 }
aoqi@0 1859 }
aoqi@0 1860
aoqi@0 1861 void ClassVerifier::verify_cp_index(
aoqi@0 1862 u2 bci, constantPoolHandle cp, int index, TRAPS) {
aoqi@0 1863 int nconstants = cp->length();
aoqi@0 1864 if ((index <= 0) || (index >= nconstants)) {
aoqi@0 1865 verify_error(ErrorContext::bad_cp_index(bci, index),
aoqi@0 1866 "Illegal constant pool index %d in class %s",
aoqi@0 1867 index, cp->pool_holder()->external_name());
aoqi@0 1868 return;
aoqi@0 1869 }
aoqi@0 1870 }
aoqi@0 1871
aoqi@0 1872 void ClassVerifier::verify_cp_type(
aoqi@0 1873 u2 bci, int index, constantPoolHandle cp, unsigned int types, TRAPS) {
aoqi@0 1874
aoqi@0 1875 // In some situations, bytecode rewriting may occur while we're verifying.
aoqi@0 1876 // In this case, a constant pool cache exists and some indices refer to that
aoqi@0 1877 // instead. Be sure we don't pick up such indices by accident.
aoqi@0 1878 // We must check was_recursively_verified() before we get here.
aoqi@0 1879 guarantee(cp->cache() == NULL, "not rewritten yet");
aoqi@0 1880
aoqi@0 1881 verify_cp_index(bci, cp, index, CHECK_VERIFY(this));
aoqi@0 1882 unsigned int tag = cp->tag_at(index).value();
aoqi@0 1883 if ((types & (1 << tag)) == 0) {
aoqi@0 1884 verify_error(ErrorContext::bad_cp_index(bci, index),
aoqi@0 1885 "Illegal type at constant pool entry %d in class %s",
aoqi@0 1886 index, cp->pool_holder()->external_name());
aoqi@0 1887 return;
aoqi@0 1888 }
aoqi@0 1889 }
aoqi@0 1890
aoqi@0 1891 void ClassVerifier::verify_cp_class_type(
aoqi@0 1892 u2 bci, int index, constantPoolHandle cp, TRAPS) {
aoqi@0 1893 verify_cp_index(bci, cp, index, CHECK_VERIFY(this));
aoqi@0 1894 constantTag tag = cp->tag_at(index);
aoqi@0 1895 if (!tag.is_klass() && !tag.is_unresolved_klass()) {
aoqi@0 1896 verify_error(ErrorContext::bad_cp_index(bci, index),
aoqi@0 1897 "Illegal type at constant pool entry %d in class %s",
aoqi@0 1898 index, cp->pool_holder()->external_name());
aoqi@0 1899 return;
aoqi@0 1900 }
aoqi@0 1901 }
aoqi@0 1902
aoqi@0 1903 void ClassVerifier::verify_error(ErrorContext ctx, const char* msg, ...) {
aoqi@0 1904 stringStream ss;
aoqi@0 1905
aoqi@0 1906 ctx.reset_frames();
aoqi@0 1907 _exception_type = vmSymbols::java_lang_VerifyError();
aoqi@0 1908 _error_context = ctx;
aoqi@0 1909 va_list va;
aoqi@0 1910 va_start(va, msg);
aoqi@0 1911 ss.vprint(msg, va);
aoqi@0 1912 va_end(va);
aoqi@0 1913 _message = ss.as_string();
aoqi@0 1914 #ifdef ASSERT
aoqi@0 1915 ResourceMark rm;
aoqi@0 1916 const char* exception_name = _exception_type->as_C_string();
aoqi@0 1917 Exceptions::debug_check_abort(exception_name, NULL);
aoqi@0 1918 #endif // ndef ASSERT
aoqi@0 1919 }
aoqi@0 1920
aoqi@0 1921 void ClassVerifier::class_format_error(const char* msg, ...) {
aoqi@0 1922 stringStream ss;
aoqi@0 1923 _exception_type = vmSymbols::java_lang_ClassFormatError();
aoqi@0 1924 va_list va;
aoqi@0 1925 va_start(va, msg);
aoqi@0 1926 ss.vprint(msg, va);
aoqi@0 1927 va_end(va);
aoqi@0 1928 if (!_method.is_null()) {
aoqi@0 1929 ss.print(" in method %s", _method->name_and_sig_as_C_string());
aoqi@0 1930 }
aoqi@0 1931 _message = ss.as_string();
aoqi@0 1932 }
aoqi@0 1933
aoqi@0 1934 Klass* ClassVerifier::load_class(Symbol* name, TRAPS) {
aoqi@0 1935 // Get current loader and protection domain first.
aoqi@0 1936 oop loader = current_class()->class_loader();
aoqi@0 1937 oop protection_domain = current_class()->protection_domain();
aoqi@0 1938
aoqi@0 1939 return SystemDictionary::resolve_or_fail(
aoqi@0 1940 name, Handle(THREAD, loader), Handle(THREAD, protection_domain),
aoqi@0 1941 true, CHECK_NULL);
aoqi@0 1942 }
aoqi@0 1943
aoqi@0 1944 bool ClassVerifier::is_protected_access(instanceKlassHandle this_class,
aoqi@0 1945 Klass* target_class,
aoqi@0 1946 Symbol* field_name,
aoqi@0 1947 Symbol* field_sig,
aoqi@0 1948 bool is_method) {
aoqi@0 1949 No_Safepoint_Verifier nosafepoint;
aoqi@0 1950
aoqi@0 1951 // If target class isn't a super class of this class, we don't worry about this case
aoqi@0 1952 if (!this_class->is_subclass_of(target_class)) {
aoqi@0 1953 return false;
aoqi@0 1954 }
aoqi@0 1955 // Check if the specified method or field is protected
aoqi@0 1956 InstanceKlass* target_instance = InstanceKlass::cast(target_class);
aoqi@0 1957 fieldDescriptor fd;
aoqi@0 1958 if (is_method) {
aoqi@0 1959 Method* m = target_instance->uncached_lookup_method(field_name, field_sig, Klass::normal);
aoqi@0 1960 if (m != NULL && m->is_protected()) {
aoqi@0 1961 if (!this_class->is_same_class_package(m->method_holder())) {
aoqi@0 1962 return true;
aoqi@0 1963 }
aoqi@0 1964 }
aoqi@0 1965 } else {
aoqi@0 1966 Klass* member_klass = target_instance->find_field(field_name, field_sig, &fd);
aoqi@0 1967 if (member_klass != NULL && fd.is_protected()) {
aoqi@0 1968 if (!this_class->is_same_class_package(member_klass)) {
aoqi@0 1969 return true;
aoqi@0 1970 }
aoqi@0 1971 }
aoqi@0 1972 }
aoqi@0 1973 return false;
aoqi@0 1974 }
aoqi@0 1975
aoqi@0 1976 void ClassVerifier::verify_ldc(
aoqi@0 1977 int opcode, u2 index, StackMapFrame* current_frame,
aoqi@0 1978 constantPoolHandle cp, u2 bci, TRAPS) {
aoqi@0 1979 verify_cp_index(bci, cp, index, CHECK_VERIFY(this));
aoqi@0 1980 constantTag tag = cp->tag_at(index);
aoqi@0 1981 unsigned int types;
aoqi@0 1982 if (opcode == Bytecodes::_ldc || opcode == Bytecodes::_ldc_w) {
aoqi@0 1983 if (!tag.is_unresolved_klass()) {
aoqi@0 1984 types = (1 << JVM_CONSTANT_Integer) | (1 << JVM_CONSTANT_Float)
aoqi@0 1985 | (1 << JVM_CONSTANT_String) | (1 << JVM_CONSTANT_Class)
aoqi@0 1986 | (1 << JVM_CONSTANT_MethodHandle) | (1 << JVM_CONSTANT_MethodType);
aoqi@0 1987 // Note: The class file parser already verified the legality of
aoqi@0 1988 // MethodHandle and MethodType constants.
aoqi@0 1989 verify_cp_type(bci, index, cp, types, CHECK_VERIFY(this));
aoqi@0 1990 }
aoqi@0 1991 } else {
aoqi@0 1992 assert(opcode == Bytecodes::_ldc2_w, "must be ldc2_w");
aoqi@0 1993 types = (1 << JVM_CONSTANT_Double) | (1 << JVM_CONSTANT_Long);
aoqi@0 1994 verify_cp_type(bci, index, cp, types, CHECK_VERIFY(this));
aoqi@0 1995 }
aoqi@0 1996 if (tag.is_string() && cp->is_pseudo_string_at(index)) {
aoqi@0 1997 current_frame->push_stack(object_type(), CHECK_VERIFY(this));
aoqi@0 1998 } else if (tag.is_string()) {
aoqi@0 1999 current_frame->push_stack(
aoqi@0 2000 VerificationType::reference_type(
aoqi@0 2001 vmSymbols::java_lang_String()), CHECK_VERIFY(this));
aoqi@0 2002 } else if (tag.is_klass() || tag.is_unresolved_klass()) {
aoqi@0 2003 current_frame->push_stack(
aoqi@0 2004 VerificationType::reference_type(
aoqi@0 2005 vmSymbols::java_lang_Class()), CHECK_VERIFY(this));
aoqi@0 2006 } else if (tag.is_int()) {
aoqi@0 2007 current_frame->push_stack(
aoqi@0 2008 VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 2009 } else if (tag.is_float()) {
aoqi@0 2010 current_frame->push_stack(
aoqi@0 2011 VerificationType::float_type(), CHECK_VERIFY(this));
aoqi@0 2012 } else if (tag.is_double()) {
aoqi@0 2013 current_frame->push_stack_2(
aoqi@0 2014 VerificationType::double_type(),
aoqi@0 2015 VerificationType::double2_type(), CHECK_VERIFY(this));
aoqi@0 2016 } else if (tag.is_long()) {
aoqi@0 2017 current_frame->push_stack_2(
aoqi@0 2018 VerificationType::long_type(),
aoqi@0 2019 VerificationType::long2_type(), CHECK_VERIFY(this));
aoqi@0 2020 } else if (tag.is_method_handle()) {
aoqi@0 2021 current_frame->push_stack(
aoqi@0 2022 VerificationType::reference_type(
aoqi@0 2023 vmSymbols::java_lang_invoke_MethodHandle()), CHECK_VERIFY(this));
aoqi@0 2024 } else if (tag.is_method_type()) {
aoqi@0 2025 current_frame->push_stack(
aoqi@0 2026 VerificationType::reference_type(
aoqi@0 2027 vmSymbols::java_lang_invoke_MethodType()), CHECK_VERIFY(this));
aoqi@0 2028 } else {
aoqi@0 2029 /* Unreachable? verify_cp_type has already validated the cp type. */
aoqi@0 2030 verify_error(
aoqi@0 2031 ErrorContext::bad_cp_index(bci, index), "Invalid index in ldc");
aoqi@0 2032 return;
aoqi@0 2033 }
aoqi@0 2034 }
aoqi@0 2035
aoqi@0 2036 void ClassVerifier::verify_switch(
aoqi@0 2037 RawBytecodeStream* bcs, u4 code_length, char* code_data,
aoqi@0 2038 StackMapFrame* current_frame, StackMapTable* stackmap_table, TRAPS) {
aoqi@0 2039 int bci = bcs->bci();
aoqi@0 2040 address bcp = bcs->bcp();
aoqi@0 2041 address aligned_bcp = (address) round_to((intptr_t)(bcp + 1), jintSize);
aoqi@0 2042
aoqi@0 2043 if (_klass->major_version() < NONZERO_PADDING_BYTES_IN_SWITCH_MAJOR_VERSION) {
aoqi@0 2044 // 4639449 & 4647081: padding bytes must be 0
aoqi@0 2045 u2 padding_offset = 1;
aoqi@0 2046 while ((bcp + padding_offset) < aligned_bcp) {
aoqi@0 2047 if(*(bcp + padding_offset) != 0) {
aoqi@0 2048 verify_error(ErrorContext::bad_code(bci),
aoqi@0 2049 "Nonzero padding byte in lookswitch or tableswitch");
aoqi@0 2050 return;
aoqi@0 2051 }
aoqi@0 2052 padding_offset++;
aoqi@0 2053 }
aoqi@0 2054 }
aoqi@0 2055
aoqi@0 2056 int default_offset = (int) Bytes::get_Java_u4(aligned_bcp);
aoqi@0 2057 int keys, delta;
aoqi@0 2058 current_frame->pop_stack(
aoqi@0 2059 VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 2060 if (bcs->raw_code() == Bytecodes::_tableswitch) {
aoqi@0 2061 jint low = (jint)Bytes::get_Java_u4(aligned_bcp + jintSize);
aoqi@0 2062 jint high = (jint)Bytes::get_Java_u4(aligned_bcp + 2*jintSize);
aoqi@0 2063 if (low > high) {
aoqi@0 2064 verify_error(ErrorContext::bad_code(bci),
aoqi@0 2065 "low must be less than or equal to high in tableswitch");
aoqi@0 2066 return;
aoqi@0 2067 }
aoqi@0 2068 keys = high - low + 1;
aoqi@0 2069 if (keys < 0) {
aoqi@0 2070 verify_error(ErrorContext::bad_code(bci), "too many keys in tableswitch");
aoqi@0 2071 return;
aoqi@0 2072 }
aoqi@0 2073 delta = 1;
aoqi@0 2074 } else {
aoqi@0 2075 keys = (int)Bytes::get_Java_u4(aligned_bcp + jintSize);
aoqi@0 2076 if (keys < 0) {
aoqi@0 2077 verify_error(ErrorContext::bad_code(bci),
aoqi@0 2078 "number of keys in lookupswitch less than 0");
aoqi@0 2079 return;
aoqi@0 2080 }
aoqi@0 2081 delta = 2;
aoqi@0 2082 // Make sure that the lookupswitch items are sorted
aoqi@0 2083 for (int i = 0; i < (keys - 1); i++) {
aoqi@0 2084 jint this_key = Bytes::get_Java_u4(aligned_bcp + (2+2*i)*jintSize);
aoqi@0 2085 jint next_key = Bytes::get_Java_u4(aligned_bcp + (2+2*i+2)*jintSize);
aoqi@0 2086 if (this_key >= next_key) {
aoqi@0 2087 verify_error(ErrorContext::bad_code(bci),
aoqi@0 2088 "Bad lookupswitch instruction");
aoqi@0 2089 return;
aoqi@0 2090 }
aoqi@0 2091 }
aoqi@0 2092 }
aoqi@0 2093 int target = bci + default_offset;
aoqi@0 2094 stackmap_table->check_jump_target(current_frame, target, CHECK_VERIFY(this));
aoqi@0 2095 for (int i = 0; i < keys; i++) {
aoqi@0 2096 // Because check_jump_target() may safepoint, the bytecode could have
aoqi@0 2097 // moved, which means 'aligned_bcp' is no good and needs to be recalculated.
aoqi@0 2098 aligned_bcp = (address)round_to((intptr_t)(bcs->bcp() + 1), jintSize);
aoqi@0 2099 target = bci + (jint)Bytes::get_Java_u4(aligned_bcp+(3+i*delta)*jintSize);
aoqi@0 2100 stackmap_table->check_jump_target(
aoqi@0 2101 current_frame, target, CHECK_VERIFY(this));
aoqi@0 2102 }
aoqi@0 2103 NOT_PRODUCT(aligned_bcp = NULL); // no longer valid at this point
aoqi@0 2104 }
aoqi@0 2105
aoqi@0 2106 bool ClassVerifier::name_in_supers(
aoqi@0 2107 Symbol* ref_name, instanceKlassHandle current) {
aoqi@0 2108 Klass* super = current->super();
aoqi@0 2109 while (super != NULL) {
aoqi@0 2110 if (super->name() == ref_name) {
aoqi@0 2111 return true;
aoqi@0 2112 }
aoqi@0 2113 super = super->super();
aoqi@0 2114 }
aoqi@0 2115 return false;
aoqi@0 2116 }
aoqi@0 2117
aoqi@0 2118 void ClassVerifier::verify_field_instructions(RawBytecodeStream* bcs,
aoqi@0 2119 StackMapFrame* current_frame,
aoqi@0 2120 constantPoolHandle cp,
aoqi@0 2121 TRAPS) {
aoqi@0 2122 u2 index = bcs->get_index_u2();
aoqi@0 2123 verify_cp_type(bcs->bci(), index, cp,
aoqi@0 2124 1 << JVM_CONSTANT_Fieldref, CHECK_VERIFY(this));
aoqi@0 2125
aoqi@0 2126 // Get field name and signature
aoqi@0 2127 Symbol* field_name = cp->name_ref_at(index);
aoqi@0 2128 Symbol* field_sig = cp->signature_ref_at(index);
aoqi@0 2129
aoqi@0 2130 if (!SignatureVerifier::is_valid_type_signature(field_sig)) {
aoqi@0 2131 class_format_error(
aoqi@0 2132 "Invalid signature for field in class %s referenced "
aoqi@0 2133 "from constant pool index %d", _klass->external_name(), index);
aoqi@0 2134 return;
aoqi@0 2135 }
aoqi@0 2136
aoqi@0 2137 // Get referenced class type
aoqi@0 2138 VerificationType ref_class_type = cp_ref_index_to_type(
aoqi@0 2139 index, cp, CHECK_VERIFY(this));
aoqi@0 2140 if (!ref_class_type.is_object()) {
aoqi@0 2141 /* Unreachable? Class file parser verifies Fieldref contents */
aoqi@0 2142 verify_error(ErrorContext::bad_type(bcs->bci(),
aoqi@0 2143 TypeOrigin::cp(index, ref_class_type)),
aoqi@0 2144 "Expecting reference to class in class %s at constant pool index %d",
aoqi@0 2145 _klass->external_name(), index);
aoqi@0 2146 return;
aoqi@0 2147 }
aoqi@0 2148 VerificationType target_class_type = ref_class_type;
aoqi@0 2149
aoqi@0 2150 assert(sizeof(VerificationType) == sizeof(uintptr_t),
aoqi@0 2151 "buffer type must match VerificationType size");
aoqi@0 2152 uintptr_t field_type_buffer[2];
aoqi@0 2153 VerificationType* field_type = (VerificationType*)field_type_buffer;
aoqi@0 2154 // If we make a VerificationType[2] array directly, the compiler calls
aoqi@0 2155 // to the c-runtime library to do the allocation instead of just
aoqi@0 2156 // stack allocating it. Plus it would run constructors. This shows up
aoqi@0 2157 // in performance profiles.
aoqi@0 2158
aoqi@0 2159 SignatureStream sig_stream(field_sig, false);
aoqi@0 2160 VerificationType stack_object_type;
aoqi@0 2161 int n = change_sig_to_verificationType(
aoqi@0 2162 &sig_stream, field_type, CHECK_VERIFY(this));
aoqi@0 2163 u2 bci = bcs->bci();
aoqi@0 2164 bool is_assignable;
aoqi@0 2165 switch (bcs->raw_code()) {
aoqi@0 2166 case Bytecodes::_getstatic: {
aoqi@0 2167 for (int i = 0; i < n; i++) {
aoqi@0 2168 current_frame->push_stack(field_type[i], CHECK_VERIFY(this));
aoqi@0 2169 }
aoqi@0 2170 break;
aoqi@0 2171 }
aoqi@0 2172 case Bytecodes::_putstatic: {
aoqi@0 2173 for (int i = n - 1; i >= 0; i--) {
aoqi@0 2174 current_frame->pop_stack(field_type[i], CHECK_VERIFY(this));
aoqi@0 2175 }
aoqi@0 2176 break;
aoqi@0 2177 }
aoqi@0 2178 case Bytecodes::_getfield: {
aoqi@0 2179 stack_object_type = current_frame->pop_stack(
aoqi@0 2180 target_class_type, CHECK_VERIFY(this));
aoqi@0 2181 for (int i = 0; i < n; i++) {
aoqi@0 2182 current_frame->push_stack(field_type[i], CHECK_VERIFY(this));
aoqi@0 2183 }
aoqi@0 2184 goto check_protected;
aoqi@0 2185 }
aoqi@0 2186 case Bytecodes::_putfield: {
aoqi@0 2187 for (int i = n - 1; i >= 0; i--) {
aoqi@0 2188 current_frame->pop_stack(field_type[i], CHECK_VERIFY(this));
aoqi@0 2189 }
aoqi@0 2190 stack_object_type = current_frame->pop_stack(CHECK_VERIFY(this));
aoqi@0 2191
aoqi@0 2192 // The JVMS 2nd edition allows field initialization before the superclass
aoqi@0 2193 // initializer, if the field is defined within the current class.
aoqi@0 2194 fieldDescriptor fd;
aoqi@0 2195 if (stack_object_type == VerificationType::uninitialized_this_type() &&
aoqi@0 2196 target_class_type.equals(current_type()) &&
aoqi@0 2197 _klass->find_local_field(field_name, field_sig, &fd)) {
aoqi@0 2198 stack_object_type = current_type();
aoqi@0 2199 }
aoqi@0 2200 is_assignable = target_class_type.is_assignable_from(
aoqi@0 2201 stack_object_type, this, false, CHECK_VERIFY(this));
aoqi@0 2202 if (!is_assignable) {
aoqi@0 2203 verify_error(ErrorContext::bad_type(bci,
aoqi@0 2204 current_frame->stack_top_ctx(),
aoqi@0 2205 TypeOrigin::cp(index, target_class_type)),
aoqi@0 2206 "Bad type on operand stack in putfield");
aoqi@0 2207 return;
aoqi@0 2208 }
aoqi@0 2209 }
aoqi@0 2210 check_protected: {
aoqi@0 2211 if (_this_type == stack_object_type)
aoqi@0 2212 break; // stack_object_type must be assignable to _current_class_type
aoqi@0 2213 Symbol* ref_class_name =
aoqi@0 2214 cp->klass_name_at(cp->klass_ref_index_at(index));
aoqi@0 2215 if (!name_in_supers(ref_class_name, current_class()))
aoqi@0 2216 // stack_object_type must be assignable to _current_class_type since:
aoqi@0 2217 // 1. stack_object_type must be assignable to ref_class.
aoqi@0 2218 // 2. ref_class must be _current_class or a subclass of it. It can't
aoqi@0 2219 // be a superclass of it. See revised JVMS 5.4.4.
aoqi@0 2220 break;
aoqi@0 2221
aoqi@0 2222 Klass* ref_class_oop = load_class(ref_class_name, CHECK);
aoqi@0 2223 if (is_protected_access(current_class(), ref_class_oop, field_name,
aoqi@0 2224 field_sig, false)) {
aoqi@0 2225 // It's protected access, check if stack object is assignable to
aoqi@0 2226 // current class.
aoqi@0 2227 is_assignable = current_type().is_assignable_from(
aoqi@0 2228 stack_object_type, this, true, CHECK_VERIFY(this));
aoqi@0 2229 if (!is_assignable) {
aoqi@0 2230 verify_error(ErrorContext::bad_type(bci,
aoqi@0 2231 current_frame->stack_top_ctx(),
aoqi@0 2232 TypeOrigin::implicit(current_type())),
aoqi@0 2233 "Bad access to protected data in getfield");
aoqi@0 2234 return;
aoqi@0 2235 }
aoqi@0 2236 }
aoqi@0 2237 break;
aoqi@0 2238 }
aoqi@0 2239 default: ShouldNotReachHere();
aoqi@0 2240 }
aoqi@0 2241 }
aoqi@0 2242
aoqi@0 2243 // Look at the method's handlers. If the bci is in the handler's try block
aoqi@0 2244 // then check if the handler_pc is already on the stack. If not, push it.
aoqi@0 2245 void ClassVerifier::push_handlers(ExceptionTable* exhandlers,
aoqi@0 2246 GrowableArray<u4>* handler_stack,
aoqi@0 2247 u4 bci) {
aoqi@0 2248 int exlength = exhandlers->length();
aoqi@0 2249 for(int x = 0; x < exlength; x++) {
aoqi@0 2250 if (bci >= exhandlers->start_pc(x) && bci < exhandlers->end_pc(x)) {
aoqi@0 2251 handler_stack->append_if_missing(exhandlers->handler_pc(x));
aoqi@0 2252 }
aoqi@0 2253 }
aoqi@0 2254 }
aoqi@0 2255
aoqi@0 2256 // Return TRUE if all code paths starting with start_bc_offset end in
aoqi@0 2257 // bytecode athrow or loop.
aoqi@0 2258 bool ClassVerifier::ends_in_athrow(u4 start_bc_offset) {
aoqi@0 2259 ResourceMark rm;
aoqi@0 2260 // Create bytecode stream.
aoqi@0 2261 RawBytecodeStream bcs(method());
aoqi@0 2262 u4 code_length = method()->code_size();
aoqi@0 2263 bcs.set_start(start_bc_offset);
aoqi@0 2264 u4 target;
aoqi@0 2265 // Create stack for storing bytecode start offsets for if* and *switch.
aoqi@0 2266 GrowableArray<u4>* bci_stack = new GrowableArray<u4>(30);
aoqi@0 2267 // Create stack for handlers for try blocks containing this handler.
aoqi@0 2268 GrowableArray<u4>* handler_stack = new GrowableArray<u4>(30);
aoqi@0 2269 // Create list of visited branch opcodes (goto* and if*).
aoqi@0 2270 GrowableArray<u4>* visited_branches = new GrowableArray<u4>(30);
aoqi@0 2271 ExceptionTable exhandlers(_method());
aoqi@0 2272
aoqi@0 2273 while (true) {
aoqi@0 2274 if (bcs.is_last_bytecode()) {
aoqi@0 2275 // if no more starting offsets to parse or if at the end of the
aoqi@0 2276 // method then return false.
aoqi@0 2277 if ((bci_stack->is_empty()) || ((u4)bcs.end_bci() == code_length))
aoqi@0 2278 return false;
aoqi@0 2279 // Pop a bytecode starting offset and scan from there.
aoqi@0 2280 bcs.set_start(bci_stack->pop());
aoqi@0 2281 }
aoqi@0 2282 Bytecodes::Code opcode = bcs.raw_next();
aoqi@0 2283 u4 bci = bcs.bci();
aoqi@0 2284
aoqi@0 2285 // If the bytecode is in a TRY block, push its handlers so they
aoqi@0 2286 // will get parsed.
aoqi@0 2287 push_handlers(&exhandlers, handler_stack, bci);
aoqi@0 2288
aoqi@0 2289 switch (opcode) {
aoqi@0 2290 case Bytecodes::_if_icmpeq:
aoqi@0 2291 case Bytecodes::_if_icmpne:
aoqi@0 2292 case Bytecodes::_if_icmplt:
aoqi@0 2293 case Bytecodes::_if_icmpge:
aoqi@0 2294 case Bytecodes::_if_icmpgt:
aoqi@0 2295 case Bytecodes::_if_icmple:
aoqi@0 2296 case Bytecodes::_ifeq:
aoqi@0 2297 case Bytecodes::_ifne:
aoqi@0 2298 case Bytecodes::_iflt:
aoqi@0 2299 case Bytecodes::_ifge:
aoqi@0 2300 case Bytecodes::_ifgt:
aoqi@0 2301 case Bytecodes::_ifle:
aoqi@0 2302 case Bytecodes::_if_acmpeq:
aoqi@0 2303 case Bytecodes::_if_acmpne:
aoqi@0 2304 case Bytecodes::_ifnull:
aoqi@0 2305 case Bytecodes::_ifnonnull:
aoqi@0 2306 target = bcs.dest();
aoqi@0 2307 if (visited_branches->contains(bci)) {
aoqi@0 2308 if (bci_stack->is_empty()) return true;
aoqi@0 2309 // Pop a bytecode starting offset and scan from there.
aoqi@0 2310 bcs.set_start(bci_stack->pop());
aoqi@0 2311 } else {
aoqi@0 2312 if (target > bci) { // forward branch
aoqi@0 2313 if (target >= code_length) return false;
aoqi@0 2314 // Push the branch target onto the stack.
aoqi@0 2315 bci_stack->push(target);
aoqi@0 2316 // then, scan bytecodes starting with next.
aoqi@0 2317 bcs.set_start(bcs.next_bci());
aoqi@0 2318 } else { // backward branch
aoqi@0 2319 // Push bytecode offset following backward branch onto the stack.
aoqi@0 2320 bci_stack->push(bcs.next_bci());
aoqi@0 2321 // Check bytecodes starting with branch target.
aoqi@0 2322 bcs.set_start(target);
aoqi@0 2323 }
aoqi@0 2324 // Record target so we don't branch here again.
aoqi@0 2325 visited_branches->append(bci);
aoqi@0 2326 }
aoqi@0 2327 break;
aoqi@0 2328
aoqi@0 2329 case Bytecodes::_goto:
aoqi@0 2330 case Bytecodes::_goto_w:
aoqi@0 2331 target = (opcode == Bytecodes::_goto ? bcs.dest() : bcs.dest_w());
aoqi@0 2332 if (visited_branches->contains(bci)) {
aoqi@0 2333 if (bci_stack->is_empty()) return true;
aoqi@0 2334 // Been here before, pop new starting offset from stack.
aoqi@0 2335 bcs.set_start(bci_stack->pop());
aoqi@0 2336 } else {
aoqi@0 2337 if (target >= code_length) return false;
aoqi@0 2338 // Continue scanning from the target onward.
aoqi@0 2339 bcs.set_start(target);
aoqi@0 2340 // Record target so we don't branch here again.
aoqi@0 2341 visited_branches->append(bci);
aoqi@0 2342 }
aoqi@0 2343 break;
aoqi@0 2344
aoqi@0 2345 // Check that all switch alternatives end in 'athrow' bytecodes. Since it
aoqi@0 2346 // is difficult to determine where each switch alternative ends, parse
aoqi@0 2347 // each switch alternative until either hit a 'return', 'athrow', or reach
aoqi@0 2348 // the end of the method's bytecodes. This is gross but should be okay
aoqi@0 2349 // because:
aoqi@0 2350 // 1. tableswitch and lookupswitch byte codes in handlers for ctor explicit
aoqi@0 2351 // constructor invocations should be rare.
aoqi@0 2352 // 2. if each switch alternative ends in an athrow then the parsing should be
aoqi@0 2353 // short. If there is no athrow then it is bogus code, anyway.
aoqi@0 2354 case Bytecodes::_lookupswitch:
aoqi@0 2355 case Bytecodes::_tableswitch:
aoqi@0 2356 {
aoqi@0 2357 address aligned_bcp = (address) round_to((intptr_t)(bcs.bcp() + 1), jintSize);
aoqi@0 2358 u4 default_offset = Bytes::get_Java_u4(aligned_bcp) + bci;
aoqi@0 2359 int keys, delta;
aoqi@0 2360 if (opcode == Bytecodes::_tableswitch) {
aoqi@0 2361 jint low = (jint)Bytes::get_Java_u4(aligned_bcp + jintSize);
aoqi@0 2362 jint high = (jint)Bytes::get_Java_u4(aligned_bcp + 2*jintSize);
aoqi@0 2363 // This is invalid, but let the regular bytecode verifier
aoqi@0 2364 // report this because the user will get a better error message.
aoqi@0 2365 if (low > high) return true;
aoqi@0 2366 keys = high - low + 1;
aoqi@0 2367 delta = 1;
aoqi@0 2368 } else {
aoqi@0 2369 keys = (int)Bytes::get_Java_u4(aligned_bcp + jintSize);
aoqi@0 2370 delta = 2;
aoqi@0 2371 }
aoqi@0 2372 // Invalid, let the regular bytecode verifier deal with it.
aoqi@0 2373 if (keys < 0) return true;
aoqi@0 2374
aoqi@0 2375 // Push the offset of the next bytecode onto the stack.
aoqi@0 2376 bci_stack->push(bcs.next_bci());
aoqi@0 2377
aoqi@0 2378 // Push the switch alternatives onto the stack.
aoqi@0 2379 for (int i = 0; i < keys; i++) {
aoqi@0 2380 u4 target = bci + (jint)Bytes::get_Java_u4(aligned_bcp+(3+i*delta)*jintSize);
aoqi@0 2381 if (target > code_length) return false;
aoqi@0 2382 bci_stack->push(target);
aoqi@0 2383 }
aoqi@0 2384
aoqi@0 2385 // Start bytecode parsing for the switch at the default alternative.
aoqi@0 2386 if (default_offset > code_length) return false;
aoqi@0 2387 bcs.set_start(default_offset);
aoqi@0 2388 break;
aoqi@0 2389 }
aoqi@0 2390
aoqi@0 2391 case Bytecodes::_return:
aoqi@0 2392 return false;
aoqi@0 2393
aoqi@0 2394 case Bytecodes::_athrow:
aoqi@0 2395 {
aoqi@0 2396 if (bci_stack->is_empty()) {
aoqi@0 2397 if (handler_stack->is_empty()) {
aoqi@0 2398 return true;
aoqi@0 2399 } else {
aoqi@0 2400 // Parse the catch handlers for try blocks containing athrow.
aoqi@0 2401 bcs.set_start(handler_stack->pop());
aoqi@0 2402 }
aoqi@0 2403 } else {
aoqi@0 2404 // Pop a bytecode offset and starting scanning from there.
aoqi@0 2405 bcs.set_start(bci_stack->pop());
aoqi@0 2406 }
aoqi@0 2407 }
aoqi@0 2408 break;
aoqi@0 2409
aoqi@0 2410 default:
aoqi@0 2411 ;
aoqi@0 2412 } // end switch
aoqi@0 2413 } // end while loop
aoqi@0 2414
aoqi@0 2415 return false;
aoqi@0 2416 }
aoqi@0 2417
aoqi@0 2418 void ClassVerifier::verify_invoke_init(
aoqi@0 2419 RawBytecodeStream* bcs, u2 ref_class_index, VerificationType ref_class_type,
aoqi@0 2420 StackMapFrame* current_frame, u4 code_length, bool *this_uninit,
aoqi@0 2421 constantPoolHandle cp, TRAPS) {
aoqi@0 2422 u2 bci = bcs->bci();
aoqi@0 2423 VerificationType type = current_frame->pop_stack(
aoqi@0 2424 VerificationType::reference_check(), CHECK_VERIFY(this));
aoqi@0 2425 if (type == VerificationType::uninitialized_this_type()) {
aoqi@0 2426 // The method must be an <init> method of this class or its superclass
aoqi@0 2427 Klass* superk = current_class()->super();
aoqi@0 2428 if (ref_class_type.name() != current_class()->name() &&
aoqi@0 2429 ref_class_type.name() != superk->name()) {
aoqi@0 2430 verify_error(ErrorContext::bad_type(bci,
aoqi@0 2431 TypeOrigin::implicit(ref_class_type),
aoqi@0 2432 TypeOrigin::implicit(current_type())),
aoqi@0 2433 "Bad <init> method call");
aoqi@0 2434 return;
aoqi@0 2435 }
aoqi@0 2436
aoqi@0 2437 // Check if this call is done from inside of a TRY block. If so, make
aoqi@0 2438 // sure that all catch clause paths end in a throw. Otherwise, this
aoqi@0 2439 // can result in returning an incomplete object.
aoqi@0 2440 ExceptionTable exhandlers(_method());
aoqi@0 2441 int exlength = exhandlers.length();
aoqi@0 2442 for(int i = 0; i < exlength; i++) {
aoqi@0 2443 u2 start_pc = exhandlers.start_pc(i);
aoqi@0 2444 u2 end_pc = exhandlers.end_pc(i);
aoqi@0 2445
aoqi@0 2446 if (bci >= start_pc && bci < end_pc) {
aoqi@0 2447 if (!ends_in_athrow(exhandlers.handler_pc(i))) {
aoqi@0 2448 verify_error(ErrorContext::bad_code(bci),
aoqi@0 2449 "Bad <init> method call from after the start of a try block");
aoqi@0 2450 return;
aoqi@0 2451 } else if (VerboseVerification) {
aoqi@0 2452 ResourceMark rm;
aoqi@0 2453 tty->print_cr(
aoqi@0 2454 "Survived call to ends_in_athrow(): %s",
aoqi@0 2455 current_class()->name()->as_C_string());
aoqi@0 2456 }
aoqi@0 2457 }
aoqi@0 2458 }
aoqi@0 2459
aoqi@0 2460 current_frame->initialize_object(type, current_type());
aoqi@0 2461 *this_uninit = true;
aoqi@0 2462 } else if (type.is_uninitialized()) {
aoqi@0 2463 u2 new_offset = type.bci();
aoqi@0 2464 address new_bcp = bcs->bcp() - bci + new_offset;
aoqi@0 2465 if (new_offset > (code_length - 3) || (*new_bcp) != Bytecodes::_new) {
aoqi@0 2466 /* Unreachable? Stack map parsing ensures valid type and new
aoqi@0 2467 * instructions have a valid BCI. */
aoqi@0 2468 verify_error(ErrorContext::bad_code(new_offset),
aoqi@0 2469 "Expecting new instruction");
aoqi@0 2470 return;
aoqi@0 2471 }
aoqi@0 2472 u2 new_class_index = Bytes::get_Java_u2(new_bcp + 1);
aoqi@0 2473 verify_cp_class_type(bci, new_class_index, cp, CHECK_VERIFY(this));
aoqi@0 2474
aoqi@0 2475 // The method must be an <init> method of the indicated class
aoqi@0 2476 VerificationType new_class_type = cp_index_to_type(
aoqi@0 2477 new_class_index, cp, CHECK_VERIFY(this));
aoqi@0 2478 if (!new_class_type.equals(ref_class_type)) {
aoqi@0 2479 verify_error(ErrorContext::bad_type(bci,
aoqi@0 2480 TypeOrigin::cp(new_class_index, new_class_type),
aoqi@0 2481 TypeOrigin::cp(ref_class_index, ref_class_type)),
aoqi@0 2482 "Call to wrong <init> method");
aoqi@0 2483 return;
aoqi@0 2484 }
aoqi@0 2485 // According to the VM spec, if the referent class is a superclass of the
aoqi@0 2486 // current class, and is in a different runtime package, and the method is
aoqi@0 2487 // protected, then the objectref must be the current class or a subclass
aoqi@0 2488 // of the current class.
aoqi@0 2489 VerificationType objectref_type = new_class_type;
aoqi@0 2490 if (name_in_supers(ref_class_type.name(), current_class())) {
aoqi@0 2491 Klass* ref_klass = load_class(
aoqi@0 2492 ref_class_type.name(), CHECK_VERIFY(this));
aoqi@0 2493 Method* m = InstanceKlass::cast(ref_klass)->uncached_lookup_method(
aoqi@0 2494 vmSymbols::object_initializer_name(),
aoqi@0 2495 cp->signature_ref_at(bcs->get_index_u2()), Klass::normal);
aoqi@0 2496 // Do nothing if method is not found. Let resolution detect the error.
aoqi@0 2497 if (m != NULL) {
aoqi@0 2498 instanceKlassHandle mh(THREAD, m->method_holder());
aoqi@0 2499 if (m->is_protected() && !mh->is_same_class_package(_klass())) {
aoqi@0 2500 bool assignable = current_type().is_assignable_from(
aoqi@0 2501 objectref_type, this, true, CHECK_VERIFY(this));
aoqi@0 2502 if (!assignable) {
aoqi@0 2503 verify_error(ErrorContext::bad_type(bci,
aoqi@0 2504 TypeOrigin::cp(new_class_index, objectref_type),
aoqi@0 2505 TypeOrigin::implicit(current_type())),
aoqi@0 2506 "Bad access to protected <init> method");
aoqi@0 2507 return;
aoqi@0 2508 }
aoqi@0 2509 }
aoqi@0 2510 }
aoqi@0 2511 }
aoqi@0 2512 current_frame->initialize_object(type, new_class_type);
aoqi@0 2513 } else {
aoqi@0 2514 verify_error(ErrorContext::bad_type(bci, current_frame->stack_top_ctx()),
aoqi@0 2515 "Bad operand type when invoking <init>");
aoqi@0 2516 return;
aoqi@0 2517 }
aoqi@0 2518 }
aoqi@0 2519
aoqi@0 2520 bool ClassVerifier::is_same_or_direct_interface(
aoqi@0 2521 instanceKlassHandle klass,
aoqi@0 2522 VerificationType klass_type,
aoqi@0 2523 VerificationType ref_class_type) {
aoqi@0 2524 if (ref_class_type.equals(klass_type)) return true;
aoqi@0 2525 Array<Klass*>* local_interfaces = klass->local_interfaces();
aoqi@0 2526 if (local_interfaces != NULL) {
aoqi@0 2527 for (int x = 0; x < local_interfaces->length(); x++) {
aoqi@0 2528 Klass* k = local_interfaces->at(x);
aoqi@0 2529 assert (k != NULL && k->is_interface(), "invalid interface");
aoqi@0 2530 if (ref_class_type.equals(VerificationType::reference_type(k->name()))) {
aoqi@0 2531 return true;
aoqi@0 2532 }
aoqi@0 2533 }
aoqi@0 2534 }
aoqi@0 2535 return false;
aoqi@0 2536 }
aoqi@0 2537
aoqi@0 2538 void ClassVerifier::verify_invoke_instructions(
aoqi@0 2539 RawBytecodeStream* bcs, u4 code_length, StackMapFrame* current_frame,
aoqi@0 2540 bool *this_uninit, VerificationType return_type,
aoqi@0 2541 constantPoolHandle cp, TRAPS) {
aoqi@0 2542 // Make sure the constant pool item is the right type
aoqi@0 2543 u2 index = bcs->get_index_u2();
aoqi@0 2544 Bytecodes::Code opcode = bcs->raw_code();
aoqi@0 2545 unsigned int types;
aoqi@0 2546 switch (opcode) {
aoqi@0 2547 case Bytecodes::_invokeinterface:
aoqi@0 2548 types = 1 << JVM_CONSTANT_InterfaceMethodref;
aoqi@0 2549 break;
aoqi@0 2550 case Bytecodes::_invokedynamic:
aoqi@0 2551 types = 1 << JVM_CONSTANT_InvokeDynamic;
aoqi@0 2552 break;
aoqi@0 2553 case Bytecodes::_invokespecial:
aoqi@0 2554 case Bytecodes::_invokestatic:
aoqi@0 2555 types = (_klass->major_version() < STATIC_METHOD_IN_INTERFACE_MAJOR_VERSION) ?
aoqi@0 2556 (1 << JVM_CONSTANT_Methodref) :
aoqi@0 2557 ((1 << JVM_CONSTANT_InterfaceMethodref) | (1 << JVM_CONSTANT_Methodref));
aoqi@0 2558 break;
aoqi@0 2559 default:
aoqi@0 2560 types = 1 << JVM_CONSTANT_Methodref;
aoqi@0 2561 }
aoqi@0 2562 verify_cp_type(bcs->bci(), index, cp, types, CHECK_VERIFY(this));
aoqi@0 2563
aoqi@0 2564 // Get method name and signature
aoqi@0 2565 Symbol* method_name = cp->name_ref_at(index);
aoqi@0 2566 Symbol* method_sig = cp->signature_ref_at(index);
aoqi@0 2567
aoqi@0 2568 if (!SignatureVerifier::is_valid_method_signature(method_sig)) {
aoqi@0 2569 class_format_error(
aoqi@0 2570 "Invalid method signature in class %s referenced "
aoqi@0 2571 "from constant pool index %d", _klass->external_name(), index);
aoqi@0 2572 return;
aoqi@0 2573 }
aoqi@0 2574
aoqi@0 2575 // Get referenced class type
aoqi@0 2576 VerificationType ref_class_type;
aoqi@0 2577 if (opcode == Bytecodes::_invokedynamic) {
aoqi@0 2578 if (!EnableInvokeDynamic ||
aoqi@0 2579 _klass->major_version() < Verifier::INVOKEDYNAMIC_MAJOR_VERSION) {
aoqi@0 2580 if (!EnableInvokeDynamic) {
aoqi@0 2581 class_format_error("invokedynamic instructions not enabled in this JVM");
aoqi@0 2582 } else {
aoqi@0 2583 class_format_error("invokedynamic instructions not supported by this class file version (%d), class %s",
aoqi@0 2584 _klass->major_version(), _klass->external_name());
aoqi@0 2585 }
aoqi@0 2586 return;
aoqi@0 2587 }
aoqi@0 2588 } else {
aoqi@0 2589 ref_class_type = cp_ref_index_to_type(index, cp, CHECK_VERIFY(this));
aoqi@0 2590 }
aoqi@0 2591
aoqi@0 2592 // For a small signature length, we just allocate 128 bytes instead
aoqi@0 2593 // of parsing the signature once to find its size.
aoqi@0 2594 // -3 is for '(', ')' and return descriptor; multiply by 2 is for
aoqi@0 2595 // longs/doubles to be consertive.
aoqi@0 2596 assert(sizeof(VerificationType) == sizeof(uintptr_t),
aoqi@0 2597 "buffer type must match VerificationType size");
aoqi@0 2598 uintptr_t on_stack_sig_types_buffer[128];
aoqi@0 2599 // If we make a VerificationType[128] array directly, the compiler calls
aoqi@0 2600 // to the c-runtime library to do the allocation instead of just
aoqi@0 2601 // stack allocating it. Plus it would run constructors. This shows up
aoqi@0 2602 // in performance profiles.
aoqi@0 2603
aoqi@0 2604 VerificationType* sig_types;
aoqi@0 2605 int size = (method_sig->utf8_length() - 3) * 2;
aoqi@0 2606 if (size > 128) {
aoqi@0 2607 // Long and double occupies two slots here.
aoqi@0 2608 ArgumentSizeComputer size_it(method_sig);
aoqi@0 2609 size = size_it.size();
aoqi@0 2610 sig_types = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, VerificationType, size);
aoqi@0 2611 } else{
aoqi@0 2612 sig_types = (VerificationType*)on_stack_sig_types_buffer;
aoqi@0 2613 }
aoqi@0 2614 SignatureStream sig_stream(method_sig);
aoqi@0 2615 int sig_i = 0;
aoqi@0 2616 while (!sig_stream.at_return_type()) {
aoqi@0 2617 sig_i += change_sig_to_verificationType(
aoqi@0 2618 &sig_stream, &sig_types[sig_i], CHECK_VERIFY(this));
aoqi@0 2619 sig_stream.next();
aoqi@0 2620 }
aoqi@0 2621 int nargs = sig_i;
aoqi@0 2622
aoqi@0 2623 #ifdef ASSERT
aoqi@0 2624 {
aoqi@0 2625 ArgumentSizeComputer size_it(method_sig);
aoqi@0 2626 assert(nargs == size_it.size(), "Argument sizes do not match");
aoqi@0 2627 assert(nargs <= (method_sig->utf8_length() - 3) * 2, "estimate of max size isn't conservative enough");
aoqi@0 2628 }
aoqi@0 2629 #endif
aoqi@0 2630
aoqi@0 2631 // Check instruction operands
aoqi@0 2632 u2 bci = bcs->bci();
aoqi@0 2633 if (opcode == Bytecodes::_invokeinterface) {
aoqi@0 2634 address bcp = bcs->bcp();
aoqi@0 2635 // 4905268: count operand in invokeinterface should be nargs+1, not nargs.
aoqi@0 2636 // JSR202 spec: The count operand of an invokeinterface instruction is valid if it is
aoqi@0 2637 // the difference between the size of the operand stack before and after the instruction
aoqi@0 2638 // executes.
aoqi@0 2639 if (*(bcp+3) != (nargs+1)) {
aoqi@0 2640 verify_error(ErrorContext::bad_code(bci),
aoqi@0 2641 "Inconsistent args count operand in invokeinterface");
aoqi@0 2642 return;
aoqi@0 2643 }
aoqi@0 2644 if (*(bcp+4) != 0) {
aoqi@0 2645 verify_error(ErrorContext::bad_code(bci),
aoqi@0 2646 "Fourth operand byte of invokeinterface must be zero");
aoqi@0 2647 return;
aoqi@0 2648 }
aoqi@0 2649 }
aoqi@0 2650
aoqi@0 2651 if (opcode == Bytecodes::_invokedynamic) {
aoqi@0 2652 address bcp = bcs->bcp();
aoqi@0 2653 if (*(bcp+3) != 0 || *(bcp+4) != 0) {
aoqi@0 2654 verify_error(ErrorContext::bad_code(bci),
aoqi@0 2655 "Third and fourth operand bytes of invokedynamic must be zero");
aoqi@0 2656 return;
aoqi@0 2657 }
aoqi@0 2658 }
aoqi@0 2659
aoqi@0 2660 if (method_name->byte_at(0) == '<') {
aoqi@0 2661 // Make sure <init> can only be invoked by invokespecial
aoqi@0 2662 if (opcode != Bytecodes::_invokespecial ||
aoqi@0 2663 method_name != vmSymbols::object_initializer_name()) {
aoqi@0 2664 verify_error(ErrorContext::bad_code(bci),
aoqi@0 2665 "Illegal call to internal method");
aoqi@0 2666 return;
aoqi@0 2667 }
aoqi@0 2668 } else if (opcode == Bytecodes::_invokespecial
aoqi@0 2669 && !is_same_or_direct_interface(current_class(), current_type(), ref_class_type)
aoqi@0 2670 && !ref_class_type.equals(VerificationType::reference_type(
aoqi@0 2671 current_class()->super()->name()))) {
aoqi@0 2672 bool subtype = false;
aoqi@0 2673 bool have_imr_indirect = cp->tag_at(index).value() == JVM_CONSTANT_InterfaceMethodref;
aoqi@0 2674 if (!current_class()->is_anonymous()) {
aoqi@0 2675 subtype = ref_class_type.is_assignable_from(
aoqi@0 2676 current_type(), this, false, CHECK_VERIFY(this));
aoqi@0 2677 } else {
aoqi@0 2678 VerificationType host_klass_type =
aoqi@0 2679 VerificationType::reference_type(current_class()->host_klass()->name());
aoqi@0 2680 subtype = ref_class_type.is_assignable_from(host_klass_type, this, false, CHECK_VERIFY(this));
aoqi@0 2681
aoqi@0 2682 // If invokespecial of IMR, need to recheck for same or
aoqi@0 2683 // direct interface relative to the host class
aoqi@0 2684 have_imr_indirect = (have_imr_indirect &&
aoqi@0 2685 !is_same_or_direct_interface(
aoqi@0 2686 InstanceKlass::cast(current_class()->host_klass()),
aoqi@0 2687 host_klass_type, ref_class_type));
aoqi@0 2688 }
aoqi@0 2689 if (!subtype) {
aoqi@0 2690 verify_error(ErrorContext::bad_code(bci),
aoqi@0 2691 "Bad invokespecial instruction: "
aoqi@0 2692 "current class isn't assignable to reference class.");
aoqi@0 2693 return;
aoqi@0 2694 } else if (have_imr_indirect) {
aoqi@0 2695 verify_error(ErrorContext::bad_code(bci),
aoqi@0 2696 "Bad invokespecial instruction: "
aoqi@0 2697 "interface method reference is in an indirect superinterface.");
aoqi@0 2698 return;
aoqi@0 2699 }
aoqi@0 2700
aoqi@0 2701 }
aoqi@0 2702 // Match method descriptor with operand stack
aoqi@0 2703 for (int i = nargs - 1; i >= 0; i--) { // Run backwards
aoqi@0 2704 current_frame->pop_stack(sig_types[i], CHECK_VERIFY(this));
aoqi@0 2705 }
aoqi@0 2706 // Check objectref on operand stack
aoqi@0 2707 if (opcode != Bytecodes::_invokestatic &&
aoqi@0 2708 opcode != Bytecodes::_invokedynamic) {
aoqi@0 2709 if (method_name == vmSymbols::object_initializer_name()) { // <init> method
aoqi@0 2710 verify_invoke_init(bcs, index, ref_class_type, current_frame,
aoqi@0 2711 code_length, this_uninit, cp, CHECK_VERIFY(this));
aoqi@0 2712 } else { // other methods
aoqi@0 2713 // Ensures that target class is assignable to method class.
aoqi@0 2714 if (opcode == Bytecodes::_invokespecial) {
aoqi@0 2715 if (!current_class()->is_anonymous()) {
aoqi@0 2716 current_frame->pop_stack(current_type(), CHECK_VERIFY(this));
aoqi@0 2717 } else {
aoqi@0 2718 // anonymous class invokespecial calls: check if the
aoqi@0 2719 // objectref is a subtype of the host_klass of the current class
aoqi@0 2720 // to allow an anonymous class to reference methods in the host_klass
aoqi@0 2721 VerificationType top = current_frame->pop_stack(CHECK_VERIFY(this));
aoqi@0 2722 VerificationType hosttype =
aoqi@0 2723 VerificationType::reference_type(current_class()->host_klass()->name());
aoqi@0 2724 bool subtype = hosttype.is_assignable_from(top, this, false, CHECK_VERIFY(this));
aoqi@0 2725 if (!subtype) {
aoqi@0 2726 verify_error( ErrorContext::bad_type(current_frame->offset(),
aoqi@0 2727 current_frame->stack_top_ctx(),
aoqi@0 2728 TypeOrigin::implicit(top)),
aoqi@0 2729 "Bad type on operand stack");
aoqi@0 2730 return;
aoqi@0 2731 }
aoqi@0 2732 }
aoqi@0 2733 } else if (opcode == Bytecodes::_invokevirtual) {
aoqi@0 2734 VerificationType stack_object_type =
aoqi@0 2735 current_frame->pop_stack(ref_class_type, CHECK_VERIFY(this));
aoqi@0 2736 if (current_type() != stack_object_type) {
aoqi@0 2737 assert(cp->cache() == NULL, "not rewritten yet");
aoqi@0 2738 Symbol* ref_class_name =
aoqi@0 2739 cp->klass_name_at(cp->klass_ref_index_at(index));
aoqi@0 2740 // See the comments in verify_field_instructions() for
aoqi@0 2741 // the rationale behind this.
aoqi@0 2742 if (name_in_supers(ref_class_name, current_class())) {
aoqi@0 2743 Klass* ref_class = load_class(ref_class_name, CHECK);
aoqi@0 2744 if (is_protected_access(
aoqi@0 2745 _klass, ref_class, method_name, method_sig, true)) {
aoqi@0 2746 // It's protected access, check if stack object is
aoqi@0 2747 // assignable to current class.
aoqi@0 2748 bool is_assignable = current_type().is_assignable_from(
aoqi@0 2749 stack_object_type, this, true, CHECK_VERIFY(this));
aoqi@0 2750 if (!is_assignable) {
aoqi@0 2751 if (ref_class_type.name() == vmSymbols::java_lang_Object()
aoqi@0 2752 && stack_object_type.is_array()
aoqi@0 2753 && method_name == vmSymbols::clone_name()) {
aoqi@0 2754 // Special case: arrays pretend to implement public Object
aoqi@0 2755 // clone().
aoqi@0 2756 } else {
aoqi@0 2757 verify_error(ErrorContext::bad_type(bci,
aoqi@0 2758 current_frame->stack_top_ctx(),
aoqi@0 2759 TypeOrigin::implicit(current_type())),
aoqi@0 2760 "Bad access to protected data in invokevirtual");
aoqi@0 2761 return;
aoqi@0 2762 }
aoqi@0 2763 }
aoqi@0 2764 }
aoqi@0 2765 }
aoqi@0 2766 }
aoqi@0 2767 } else {
aoqi@0 2768 assert(opcode == Bytecodes::_invokeinterface, "Unexpected opcode encountered");
aoqi@0 2769 current_frame->pop_stack(ref_class_type, CHECK_VERIFY(this));
aoqi@0 2770 }
aoqi@0 2771 }
aoqi@0 2772 }
aoqi@0 2773 // Push the result type.
aoqi@0 2774 if (sig_stream.type() != T_VOID) {
aoqi@0 2775 if (method_name == vmSymbols::object_initializer_name()) {
aoqi@0 2776 // <init> method must have a void return type
aoqi@0 2777 /* Unreachable? Class file parser verifies that methods with '<' have
aoqi@0 2778 * void return */
aoqi@0 2779 verify_error(ErrorContext::bad_code(bci),
aoqi@0 2780 "Return type must be void in <init> method");
aoqi@0 2781 return;
aoqi@0 2782 }
aoqi@0 2783 VerificationType return_type[2];
aoqi@0 2784 int n = change_sig_to_verificationType(
aoqi@0 2785 &sig_stream, return_type, CHECK_VERIFY(this));
aoqi@0 2786 for (int i = 0; i < n; i++) {
aoqi@0 2787 current_frame->push_stack(return_type[i], CHECK_VERIFY(this)); // push types backwards
aoqi@0 2788 }
aoqi@0 2789 }
aoqi@0 2790 }
aoqi@0 2791
aoqi@0 2792 VerificationType ClassVerifier::get_newarray_type(
aoqi@0 2793 u2 index, u2 bci, TRAPS) {
aoqi@0 2794 const char* from_bt[] = {
aoqi@0 2795 NULL, NULL, NULL, NULL, "[Z", "[C", "[F", "[D", "[B", "[S", "[I", "[J",
aoqi@0 2796 };
aoqi@0 2797 if (index < T_BOOLEAN || index > T_LONG) {
aoqi@0 2798 verify_error(ErrorContext::bad_code(bci), "Illegal newarray instruction");
aoqi@0 2799 return VerificationType::bogus_type();
aoqi@0 2800 }
aoqi@0 2801
aoqi@0 2802 // from_bt[index] contains the array signature which has a length of 2
aoqi@0 2803 Symbol* sig = create_temporary_symbol(
aoqi@0 2804 from_bt[index], 2, CHECK_(VerificationType::bogus_type()));
aoqi@0 2805 return VerificationType::reference_type(sig);
aoqi@0 2806 }
aoqi@0 2807
aoqi@0 2808 void ClassVerifier::verify_anewarray(
aoqi@0 2809 u2 bci, u2 index, constantPoolHandle cp,
aoqi@0 2810 StackMapFrame* current_frame, TRAPS) {
aoqi@0 2811 verify_cp_class_type(bci, index, cp, CHECK_VERIFY(this));
aoqi@0 2812 current_frame->pop_stack(
aoqi@0 2813 VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 2814
aoqi@0 2815 VerificationType component_type =
aoqi@0 2816 cp_index_to_type(index, cp, CHECK_VERIFY(this));
aoqi@0 2817 int length;
aoqi@0 2818 char* arr_sig_str;
aoqi@0 2819 if (component_type.is_array()) { // it's an array
aoqi@0 2820 const char* component_name = component_type.name()->as_utf8();
aoqi@0 2821 // add one dimension to component
aoqi@0 2822 length = (int)strlen(component_name) + 1;
aoqi@0 2823 arr_sig_str = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, length);
aoqi@0 2824 arr_sig_str[0] = '[';
aoqi@0 2825 strncpy(&arr_sig_str[1], component_name, length - 1);
aoqi@0 2826 } else { // it's an object or interface
aoqi@0 2827 const char* component_name = component_type.name()->as_utf8();
aoqi@0 2828 // add one dimension to component with 'L' prepended and ';' postpended.
aoqi@0 2829 length = (int)strlen(component_name) + 3;
aoqi@0 2830 arr_sig_str = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, length);
aoqi@0 2831 arr_sig_str[0] = '[';
aoqi@0 2832 arr_sig_str[1] = 'L';
aoqi@0 2833 strncpy(&arr_sig_str[2], component_name, length - 2);
aoqi@0 2834 arr_sig_str[length - 1] = ';';
aoqi@0 2835 }
aoqi@0 2836 Symbol* arr_sig = create_temporary_symbol(
aoqi@0 2837 arr_sig_str, length, CHECK_VERIFY(this));
aoqi@0 2838 VerificationType new_array_type = VerificationType::reference_type(arr_sig);
aoqi@0 2839 current_frame->push_stack(new_array_type, CHECK_VERIFY(this));
aoqi@0 2840 }
aoqi@0 2841
aoqi@0 2842 void ClassVerifier::verify_iload(u2 index, StackMapFrame* current_frame, TRAPS) {
aoqi@0 2843 current_frame->get_local(
aoqi@0 2844 index, VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 2845 current_frame->push_stack(
aoqi@0 2846 VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 2847 }
aoqi@0 2848
aoqi@0 2849 void ClassVerifier::verify_lload(u2 index, StackMapFrame* current_frame, TRAPS) {
aoqi@0 2850 current_frame->get_local_2(
aoqi@0 2851 index, VerificationType::long_type(),
aoqi@0 2852 VerificationType::long2_type(), CHECK_VERIFY(this));
aoqi@0 2853 current_frame->push_stack_2(
aoqi@0 2854 VerificationType::long_type(),
aoqi@0 2855 VerificationType::long2_type(), CHECK_VERIFY(this));
aoqi@0 2856 }
aoqi@0 2857
aoqi@0 2858 void ClassVerifier::verify_fload(u2 index, StackMapFrame* current_frame, TRAPS) {
aoqi@0 2859 current_frame->get_local(
aoqi@0 2860 index, VerificationType::float_type(), CHECK_VERIFY(this));
aoqi@0 2861 current_frame->push_stack(
aoqi@0 2862 VerificationType::float_type(), CHECK_VERIFY(this));
aoqi@0 2863 }
aoqi@0 2864
aoqi@0 2865 void ClassVerifier::verify_dload(u2 index, StackMapFrame* current_frame, TRAPS) {
aoqi@0 2866 current_frame->get_local_2(
aoqi@0 2867 index, VerificationType::double_type(),
aoqi@0 2868 VerificationType::double2_type(), CHECK_VERIFY(this));
aoqi@0 2869 current_frame->push_stack_2(
aoqi@0 2870 VerificationType::double_type(),
aoqi@0 2871 VerificationType::double2_type(), CHECK_VERIFY(this));
aoqi@0 2872 }
aoqi@0 2873
aoqi@0 2874 void ClassVerifier::verify_aload(u2 index, StackMapFrame* current_frame, TRAPS) {
aoqi@0 2875 VerificationType type = current_frame->get_local(
aoqi@0 2876 index, VerificationType::reference_check(), CHECK_VERIFY(this));
aoqi@0 2877 current_frame->push_stack(type, CHECK_VERIFY(this));
aoqi@0 2878 }
aoqi@0 2879
aoqi@0 2880 void ClassVerifier::verify_istore(u2 index, StackMapFrame* current_frame, TRAPS) {
aoqi@0 2881 current_frame->pop_stack(
aoqi@0 2882 VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 2883 current_frame->set_local(
aoqi@0 2884 index, VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 2885 }
aoqi@0 2886
aoqi@0 2887 void ClassVerifier::verify_lstore(u2 index, StackMapFrame* current_frame, TRAPS) {
aoqi@0 2888 current_frame->pop_stack_2(
aoqi@0 2889 VerificationType::long2_type(),
aoqi@0 2890 VerificationType::long_type(), CHECK_VERIFY(this));
aoqi@0 2891 current_frame->set_local_2(
aoqi@0 2892 index, VerificationType::long_type(),
aoqi@0 2893 VerificationType::long2_type(), CHECK_VERIFY(this));
aoqi@0 2894 }
aoqi@0 2895
aoqi@0 2896 void ClassVerifier::verify_fstore(u2 index, StackMapFrame* current_frame, TRAPS) {
aoqi@0 2897 current_frame->pop_stack(VerificationType::float_type(), CHECK_VERIFY(this));
aoqi@0 2898 current_frame->set_local(
aoqi@0 2899 index, VerificationType::float_type(), CHECK_VERIFY(this));
aoqi@0 2900 }
aoqi@0 2901
aoqi@0 2902 void ClassVerifier::verify_dstore(u2 index, StackMapFrame* current_frame, TRAPS) {
aoqi@0 2903 current_frame->pop_stack_2(
aoqi@0 2904 VerificationType::double2_type(),
aoqi@0 2905 VerificationType::double_type(), CHECK_VERIFY(this));
aoqi@0 2906 current_frame->set_local_2(
aoqi@0 2907 index, VerificationType::double_type(),
aoqi@0 2908 VerificationType::double2_type(), CHECK_VERIFY(this));
aoqi@0 2909 }
aoqi@0 2910
aoqi@0 2911 void ClassVerifier::verify_astore(u2 index, StackMapFrame* current_frame, TRAPS) {
aoqi@0 2912 VerificationType type = current_frame->pop_stack(
aoqi@0 2913 VerificationType::reference_check(), CHECK_VERIFY(this));
aoqi@0 2914 current_frame->set_local(index, type, CHECK_VERIFY(this));
aoqi@0 2915 }
aoqi@0 2916
aoqi@0 2917 void ClassVerifier::verify_iinc(u2 index, StackMapFrame* current_frame, TRAPS) {
aoqi@0 2918 VerificationType type = current_frame->get_local(
aoqi@0 2919 index, VerificationType::integer_type(), CHECK_VERIFY(this));
aoqi@0 2920 current_frame->set_local(index, type, CHECK_VERIFY(this));
aoqi@0 2921 }
aoqi@0 2922
aoqi@0 2923 void ClassVerifier::verify_return_value(
aoqi@0 2924 VerificationType return_type, VerificationType type, u2 bci,
aoqi@0 2925 StackMapFrame* current_frame, TRAPS) {
aoqi@0 2926 if (return_type == VerificationType::bogus_type()) {
aoqi@0 2927 verify_error(ErrorContext::bad_type(bci,
aoqi@0 2928 current_frame->stack_top_ctx(), TypeOrigin::signature(return_type)),
aoqi@0 2929 "Method expects a return value");
aoqi@0 2930 return;
aoqi@0 2931 }
aoqi@0 2932 bool match = return_type.is_assignable_from(type, this, false, CHECK_VERIFY(this));
aoqi@0 2933 if (!match) {
aoqi@0 2934 verify_error(ErrorContext::bad_type(bci,
aoqi@0 2935 current_frame->stack_top_ctx(), TypeOrigin::signature(return_type)),
aoqi@0 2936 "Bad return type");
aoqi@0 2937 return;
aoqi@0 2938 }
aoqi@0 2939 }
aoqi@0 2940
aoqi@0 2941 // The verifier creates symbols which are substrings of Symbols.
aoqi@0 2942 // These are stored in the verifier until the end of verification so that
aoqi@0 2943 // they can be reference counted.
aoqi@0 2944 Symbol* ClassVerifier::create_temporary_symbol(const Symbol *s, int begin,
aoqi@0 2945 int end, TRAPS) {
aoqi@0 2946 Symbol* sym = SymbolTable::new_symbol(s, begin, end, CHECK_NULL);
aoqi@0 2947 _symbols->push(sym);
aoqi@0 2948 return sym;
aoqi@0 2949 }
aoqi@0 2950
aoqi@0 2951 Symbol* ClassVerifier::create_temporary_symbol(const char *s, int length, TRAPS) {
aoqi@0 2952 Symbol* sym = SymbolTable::new_symbol(s, length, CHECK_NULL);
aoqi@0 2953 _symbols->push(sym);
aoqi@0 2954 return sym;
aoqi@0 2955 }

mercurial