src/share/vm/classfile/verifier.cpp

Thu, 26 Sep 2013 10:25:02 -0400

author
hseigel
date
Thu, 26 Sep 2013 10:25:02 -0400
changeset 5784
190899198332
parent 5622
3a1df0dce3e5
child 5852
c72075c2883e
permissions
-rw-r--r--

7195622: CheckUnhandledOops has limited usefulness now
Summary: Enable CHECK_UNHANDLED_OOPS in fastdebug builds across all supported platforms.
Reviewed-by: coleenp, hseigel, dholmes, stefank, twisti, ihse, rdurbin
Contributed-by: lois.foltan@oracle.com

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

mercurial