src/share/vm/classfile/verifier.cpp

Thu, 30 Jun 2016 08:11:30 -0400

author
hseigel
date
Thu, 30 Jun 2016 08:11:30 -0400
changeset 8570
e4525db27263
parent 8525
0095e54dcaa1
child 8604
04d83ba48607
child 8676
b4b7e6bb414d
permissions
-rw-r--r--

8159511: Stack map validation
Reviewed-by: acorn, mschoene
Contributed-by: harold.seigel@oracle.com

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

mercurial