Wed, 02 Jun 2010 22:45:42 -0700
Merge
duke@435 | 1 | /* |
jrose@1934 | 2 | * Copyright (c) 1998, 2010, 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 | |
duke@435 | 25 | # include "incls/_precompiled.incl" |
duke@435 | 26 | # include "incls/_verifier.cpp.incl" |
duke@435 | 27 | |
kamg@1915 | 28 | #define NOFAILOVER_MAJOR_VERSION 51 |
kamg@1915 | 29 | |
duke@435 | 30 | // Access to external entry for VerifyClassCodes - old byte code verifier |
duke@435 | 31 | |
duke@435 | 32 | extern "C" { |
duke@435 | 33 | typedef jboolean (*verify_byte_codes_fn_t)(JNIEnv *, jclass, char *, jint); |
duke@435 | 34 | typedef jboolean (*verify_byte_codes_fn_new_t)(JNIEnv *, jclass, char *, jint, jint); |
duke@435 | 35 | } |
duke@435 | 36 | |
duke@435 | 37 | static void* volatile _verify_byte_codes_fn = NULL; |
duke@435 | 38 | |
duke@435 | 39 | static volatile jint _is_new_verify_byte_codes_fn = (jint) true; |
duke@435 | 40 | |
duke@435 | 41 | static void* verify_byte_codes_fn() { |
duke@435 | 42 | if (_verify_byte_codes_fn == NULL) { |
duke@435 | 43 | void *lib_handle = os::native_java_library(); |
duke@435 | 44 | void *func = hpi::dll_lookup(lib_handle, "VerifyClassCodesForMajorVersion"); |
duke@435 | 45 | OrderAccess::release_store_ptr(&_verify_byte_codes_fn, func); |
duke@435 | 46 | if (func == NULL) { |
duke@435 | 47 | OrderAccess::release_store(&_is_new_verify_byte_codes_fn, false); |
duke@435 | 48 | func = hpi::dll_lookup(lib_handle, "VerifyClassCodes"); |
duke@435 | 49 | OrderAccess::release_store_ptr(&_verify_byte_codes_fn, func); |
duke@435 | 50 | } |
duke@435 | 51 | } |
duke@435 | 52 | return (void*)_verify_byte_codes_fn; |
duke@435 | 53 | } |
duke@435 | 54 | |
duke@435 | 55 | |
duke@435 | 56 | // Methods in Verifier |
duke@435 | 57 | |
acorn@1408 | 58 | bool Verifier::should_verify_for(oop class_loader, bool should_verify_class) { |
acorn@1408 | 59 | return (class_loader == NULL || !should_verify_class) ? |
duke@435 | 60 | BytecodeVerificationLocal : BytecodeVerificationRemote; |
duke@435 | 61 | } |
duke@435 | 62 | |
duke@435 | 63 | bool Verifier::relax_verify_for(oop loader) { |
duke@435 | 64 | bool trusted = java_lang_ClassLoader::is_trusted_loader(loader); |
duke@435 | 65 | bool need_verify = |
duke@435 | 66 | // verifyAll |
duke@435 | 67 | (BytecodeVerificationLocal && BytecodeVerificationRemote) || |
duke@435 | 68 | // verifyRemote |
duke@435 | 69 | (!BytecodeVerificationLocal && BytecodeVerificationRemote && !trusted); |
duke@435 | 70 | return !need_verify; |
duke@435 | 71 | } |
duke@435 | 72 | |
acorn@1408 | 73 | bool Verifier::verify(instanceKlassHandle klass, Verifier::Mode mode, bool should_verify_class, TRAPS) { |
duke@435 | 74 | ResourceMark rm(THREAD); |
duke@435 | 75 | HandleMark hm; |
duke@435 | 76 | |
duke@435 | 77 | symbolHandle exception_name; |
duke@435 | 78 | const size_t message_buffer_len = klass->name()->utf8_length() + 1024; |
duke@435 | 79 | char* message_buffer = NEW_RESOURCE_ARRAY(char, message_buffer_len); |
duke@435 | 80 | |
duke@435 | 81 | const char* klassName = klass->external_name(); |
duke@435 | 82 | |
duke@435 | 83 | // If the class should be verified, first see if we can use the split |
duke@435 | 84 | // verifier. If not, or if verification fails and FailOverToOldVerifier |
duke@435 | 85 | // is set, then call the inference verifier. |
acorn@1408 | 86 | if (is_eligible_for_verification(klass, should_verify_class)) { |
duke@435 | 87 | if (TraceClassInitialization) { |
duke@435 | 88 | tty->print_cr("Start class verification for: %s", klassName); |
duke@435 | 89 | } |
duke@435 | 90 | if (UseSplitVerifier && |
duke@435 | 91 | klass->major_version() >= STACKMAP_ATTRIBUTE_MAJOR_VERSION) { |
duke@435 | 92 | ClassVerifier split_verifier( |
duke@435 | 93 | klass, message_buffer, message_buffer_len, THREAD); |
duke@435 | 94 | split_verifier.verify_class(THREAD); |
duke@435 | 95 | exception_name = split_verifier.result(); |
kamg@1915 | 96 | if (klass->major_version() < NOFAILOVER_MAJOR_VERSION && |
kamg@1915 | 97 | FailOverToOldVerifier && !HAS_PENDING_EXCEPTION && |
duke@435 | 98 | (exception_name == vmSymbols::java_lang_VerifyError() || |
duke@435 | 99 | exception_name == vmSymbols::java_lang_ClassFormatError())) { |
duke@435 | 100 | if (TraceClassInitialization) { |
duke@435 | 101 | tty->print_cr( |
duke@435 | 102 | "Fail over class verification to old verifier for: %s", klassName); |
duke@435 | 103 | } |
duke@435 | 104 | exception_name = inference_verify( |
duke@435 | 105 | klass, message_buffer, message_buffer_len, THREAD); |
duke@435 | 106 | } |
duke@435 | 107 | } else { |
duke@435 | 108 | exception_name = inference_verify( |
duke@435 | 109 | klass, message_buffer, message_buffer_len, THREAD); |
duke@435 | 110 | } |
duke@435 | 111 | |
duke@435 | 112 | if (TraceClassInitialization) { |
duke@435 | 113 | if (HAS_PENDING_EXCEPTION) { |
duke@435 | 114 | tty->print("Verification for %s has", klassName); |
duke@435 | 115 | tty->print_cr(" exception pending %s ", |
duke@435 | 116 | instanceKlass::cast(PENDING_EXCEPTION->klass())->external_name()); |
duke@435 | 117 | } else if (!exception_name.is_null()) { |
duke@435 | 118 | tty->print_cr("Verification for %s failed", klassName); |
duke@435 | 119 | } |
duke@435 | 120 | tty->print_cr("End class verification for: %s", klassName); |
duke@435 | 121 | } |
duke@435 | 122 | } |
duke@435 | 123 | |
duke@435 | 124 | if (HAS_PENDING_EXCEPTION) { |
duke@435 | 125 | return false; // use the existing exception |
duke@435 | 126 | } else if (exception_name.is_null()) { |
duke@435 | 127 | return true; // verifcation succeeded |
duke@435 | 128 | } else { // VerifyError or ClassFormatError to be created and thrown |
duke@435 | 129 | ResourceMark rm(THREAD); |
duke@435 | 130 | instanceKlassHandle kls = |
duke@435 | 131 | SystemDictionary::resolve_or_fail(exception_name, true, CHECK_false); |
duke@435 | 132 | while (!kls.is_null()) { |
duke@435 | 133 | if (kls == klass) { |
duke@435 | 134 | // If the class being verified is the exception we're creating |
duke@435 | 135 | // or one of it's superclasses, we're in trouble and are going |
duke@435 | 136 | // to infinitely recurse when we try to initialize the exception. |
duke@435 | 137 | // So bail out here by throwing the preallocated VM error. |
duke@435 | 138 | THROW_OOP_(Universe::virtual_machine_error_instance(), false); |
duke@435 | 139 | } |
duke@435 | 140 | kls = kls->super(); |
duke@435 | 141 | } |
duke@435 | 142 | message_buffer[message_buffer_len - 1] = '\0'; // just to be sure |
duke@435 | 143 | THROW_MSG_(exception_name, message_buffer, false); |
duke@435 | 144 | } |
duke@435 | 145 | } |
duke@435 | 146 | |
acorn@1408 | 147 | bool Verifier::is_eligible_for_verification(instanceKlassHandle klass, bool should_verify_class) { |
duke@435 | 148 | symbolOop name = klass->name(); |
never@1577 | 149 | klassOop refl_magic_klass = SystemDictionary::reflect_MagicAccessorImpl_klass(); |
duke@435 | 150 | |
acorn@1408 | 151 | return (should_verify_for(klass->class_loader(), should_verify_class) && |
duke@435 | 152 | // return if the class is a bootstrapping class |
acorn@1408 | 153 | // or defineClass specified not to verify by default (flags override passed arg) |
duke@435 | 154 | // We need to skip the following four for bootstraping |
duke@435 | 155 | name != vmSymbols::java_lang_Object() && |
duke@435 | 156 | name != vmSymbols::java_lang_Class() && |
duke@435 | 157 | name != vmSymbols::java_lang_String() && |
duke@435 | 158 | name != vmSymbols::java_lang_Throwable() && |
duke@435 | 159 | |
duke@435 | 160 | // Can not verify the bytecodes for shared classes because they have |
duke@435 | 161 | // already been rewritten to contain constant pool cache indices, |
duke@435 | 162 | // which the verifier can't understand. |
duke@435 | 163 | // Shared classes shouldn't have stackmaps either. |
duke@435 | 164 | !klass()->is_shared() && |
duke@435 | 165 | |
duke@435 | 166 | // As of the fix for 4486457 we disable verification for all of the |
duke@435 | 167 | // dynamically-generated bytecodes associated with the 1.4 |
duke@435 | 168 | // reflection implementation, not just those associated with |
duke@435 | 169 | // sun/reflect/SerializationConstructorAccessor. |
duke@435 | 170 | // NOTE: this is called too early in the bootstrapping process to be |
duke@435 | 171 | // guarded by Universe::is_gte_jdk14x_version()/UseNewReflection. |
duke@435 | 172 | (refl_magic_klass == NULL || |
duke@435 | 173 | !klass->is_subtype_of(refl_magic_klass) || |
duke@435 | 174 | VerifyReflectionBytecodes) |
duke@435 | 175 | ); |
duke@435 | 176 | } |
duke@435 | 177 | |
duke@435 | 178 | symbolHandle Verifier::inference_verify( |
duke@435 | 179 | instanceKlassHandle klass, char* message, size_t message_len, TRAPS) { |
duke@435 | 180 | JavaThread* thread = (JavaThread*)THREAD; |
duke@435 | 181 | JNIEnv *env = thread->jni_environment(); |
duke@435 | 182 | |
duke@435 | 183 | void* verify_func = verify_byte_codes_fn(); |
duke@435 | 184 | |
duke@435 | 185 | if (verify_func == NULL) { |
duke@435 | 186 | jio_snprintf(message, message_len, "Could not link verifier"); |
duke@435 | 187 | return vmSymbols::java_lang_VerifyError(); |
duke@435 | 188 | } |
duke@435 | 189 | |
duke@435 | 190 | ResourceMark rm(THREAD); |
duke@435 | 191 | if (ClassVerifier::_verify_verbose) { |
duke@435 | 192 | tty->print_cr("Verifying class %s with old format", klass->external_name()); |
duke@435 | 193 | } |
duke@435 | 194 | |
duke@435 | 195 | jclass cls = (jclass) JNIHandles::make_local(env, klass->java_mirror()); |
duke@435 | 196 | jint result; |
duke@435 | 197 | |
duke@435 | 198 | { |
duke@435 | 199 | HandleMark hm(thread); |
duke@435 | 200 | ThreadToNativeFromVM ttn(thread); |
duke@435 | 201 | // ThreadToNativeFromVM takes care of changing thread_state, so safepoint |
duke@435 | 202 | // code knows that we have left the VM |
duke@435 | 203 | |
duke@435 | 204 | if (_is_new_verify_byte_codes_fn) { |
duke@435 | 205 | verify_byte_codes_fn_new_t func = |
duke@435 | 206 | CAST_TO_FN_PTR(verify_byte_codes_fn_new_t, verify_func); |
duke@435 | 207 | result = (*func)(env, cls, message, (int)message_len, |
duke@435 | 208 | klass->major_version()); |
duke@435 | 209 | } else { |
duke@435 | 210 | verify_byte_codes_fn_t func = |
duke@435 | 211 | CAST_TO_FN_PTR(verify_byte_codes_fn_t, verify_func); |
duke@435 | 212 | result = (*func)(env, cls, message, (int)message_len); |
duke@435 | 213 | } |
duke@435 | 214 | } |
duke@435 | 215 | |
duke@435 | 216 | JNIHandles::destroy_local(cls); |
duke@435 | 217 | |
duke@435 | 218 | // These numbers are chosen so that VerifyClassCodes interface doesn't need |
duke@435 | 219 | // to be changed (still return jboolean (unsigned char)), and result is |
duke@435 | 220 | // 1 when verification is passed. |
duke@435 | 221 | symbolHandle nh(NULL); |
duke@435 | 222 | if (result == 0) { |
duke@435 | 223 | return vmSymbols::java_lang_VerifyError(); |
duke@435 | 224 | } else if (result == 1) { |
duke@435 | 225 | return nh; // verified. |
duke@435 | 226 | } else if (result == 2) { |
duke@435 | 227 | THROW_MSG_(vmSymbols::java_lang_OutOfMemoryError(), message, nh); |
duke@435 | 228 | } else if (result == 3) { |
duke@435 | 229 | return vmSymbols::java_lang_ClassFormatError(); |
duke@435 | 230 | } else { |
duke@435 | 231 | ShouldNotReachHere(); |
duke@435 | 232 | return nh; |
duke@435 | 233 | } |
duke@435 | 234 | } |
duke@435 | 235 | |
duke@435 | 236 | // Methods in ClassVerifier |
duke@435 | 237 | |
duke@435 | 238 | bool ClassVerifier::_verify_verbose = false; |
duke@435 | 239 | |
duke@435 | 240 | ClassVerifier::ClassVerifier( |
duke@435 | 241 | instanceKlassHandle klass, char* msg, size_t msg_len, TRAPS) |
duke@435 | 242 | : _thread(THREAD), _exception_type(symbolHandle()), _message(msg), |
duke@435 | 243 | _message_buffer_len(msg_len), _klass(klass) { |
duke@435 | 244 | _this_type = VerificationType::reference_type(klass->name()); |
duke@435 | 245 | } |
duke@435 | 246 | |
duke@435 | 247 | ClassVerifier::~ClassVerifier() { |
duke@435 | 248 | } |
duke@435 | 249 | |
duke@435 | 250 | void ClassVerifier::verify_class(TRAPS) { |
duke@435 | 251 | if (_verify_verbose) { |
duke@435 | 252 | tty->print_cr("Verifying class %s with new format", |
duke@435 | 253 | _klass->external_name()); |
duke@435 | 254 | } |
duke@435 | 255 | |
duke@435 | 256 | objArrayHandle methods(THREAD, _klass->methods()); |
duke@435 | 257 | int num_methods = methods->length(); |
duke@435 | 258 | |
duke@435 | 259 | for (int index = 0; index < num_methods; index++) { |
jrose@1925 | 260 | // Check for recursive re-verification before each method. |
jrose@1925 | 261 | if (was_recursively_verified()) return; |
jrose@1925 | 262 | |
duke@435 | 263 | methodOop m = (methodOop)methods->obj_at(index); |
duke@435 | 264 | if (m->is_native() || m->is_abstract()) { |
duke@435 | 265 | // If m is native or abstract, skip it. It is checked in class file |
duke@435 | 266 | // parser that methods do not override a final method. |
duke@435 | 267 | continue; |
duke@435 | 268 | } |
duke@435 | 269 | verify_method(methodHandle(THREAD, m), CHECK_VERIFY(this)); |
duke@435 | 270 | } |
jrose@1925 | 271 | |
jrose@1925 | 272 | if (_verify_verbose || TraceClassInitialization) { |
jrose@1925 | 273 | if (was_recursively_verified()) |
jrose@1925 | 274 | tty->print_cr("Recursive verification detected for: %s", |
jrose@1925 | 275 | _klass->external_name()); |
jrose@1925 | 276 | } |
duke@435 | 277 | } |
duke@435 | 278 | |
duke@435 | 279 | void ClassVerifier::verify_method(methodHandle m, TRAPS) { |
duke@435 | 280 | ResourceMark rm(THREAD); |
duke@435 | 281 | _method = m; // initialize _method |
duke@435 | 282 | if (_verify_verbose) { |
duke@435 | 283 | tty->print_cr("Verifying method %s", m->name_and_sig_as_C_string()); |
duke@435 | 284 | } |
duke@435 | 285 | |
duke@435 | 286 | const char* bad_type_msg = "Bad type on operand stack in %s"; |
duke@435 | 287 | |
duke@435 | 288 | int32_t max_stack = m->max_stack(); |
duke@435 | 289 | int32_t max_locals = m->max_locals(); |
duke@435 | 290 | constantPoolHandle cp(THREAD, m->constants()); |
duke@435 | 291 | |
duke@435 | 292 | if (!SignatureVerifier::is_valid_method_signature(m->signature())) { |
duke@435 | 293 | class_format_error("Invalid method signature"); |
duke@435 | 294 | return; |
duke@435 | 295 | } |
duke@435 | 296 | |
duke@435 | 297 | // Initial stack map frame: offset is 0, stack is initially empty. |
duke@435 | 298 | StackMapFrame current_frame(max_locals, max_stack, this); |
duke@435 | 299 | // Set initial locals |
duke@435 | 300 | VerificationType return_type = current_frame.set_locals_from_arg( |
duke@435 | 301 | m, current_type(), CHECK_VERIFY(this)); |
duke@435 | 302 | |
duke@435 | 303 | int32_t stackmap_index = 0; // index to the stackmap array |
duke@435 | 304 | |
duke@435 | 305 | u4 code_length = m->code_size(); |
duke@435 | 306 | |
duke@435 | 307 | // Scan the bytecode and map each instruction's start offset to a number. |
duke@435 | 308 | char* code_data = generate_code_data(m, code_length, CHECK_VERIFY(this)); |
duke@435 | 309 | |
duke@435 | 310 | int ex_min = code_length; |
duke@435 | 311 | int ex_max = -1; |
duke@435 | 312 | // Look through each item on the exception table. Each of the fields must refer |
duke@435 | 313 | // to a legal instruction. |
duke@435 | 314 | verify_exception_handler_table( |
duke@435 | 315 | code_length, code_data, ex_min, ex_max, CHECK_VERIFY(this)); |
duke@435 | 316 | |
duke@435 | 317 | // Look through each entry on the local variable table and make sure |
duke@435 | 318 | // its range of code array offsets is valid. (4169817) |
duke@435 | 319 | if (m->has_localvariable_table()) { |
duke@435 | 320 | verify_local_variable_table(code_length, code_data, CHECK_VERIFY(this)); |
duke@435 | 321 | } |
duke@435 | 322 | |
duke@435 | 323 | typeArrayHandle stackmap_data(THREAD, m->stackmap_data()); |
duke@435 | 324 | StackMapStream stream(stackmap_data); |
duke@435 | 325 | StackMapReader reader(this, &stream, code_data, code_length, THREAD); |
duke@435 | 326 | StackMapTable stackmap_table(&reader, ¤t_frame, max_locals, max_stack, |
duke@435 | 327 | code_data, code_length, CHECK_VERIFY(this)); |
duke@435 | 328 | |
duke@435 | 329 | if (_verify_verbose) { |
duke@435 | 330 | stackmap_table.print(); |
duke@435 | 331 | } |
duke@435 | 332 | |
duke@435 | 333 | RawBytecodeStream bcs(m); |
duke@435 | 334 | |
duke@435 | 335 | // Scan the byte code linearly from the start to the end |
duke@435 | 336 | bool no_control_flow = false; // Set to true when there is no direct control |
duke@435 | 337 | // flow from current instruction to the next |
duke@435 | 338 | // instruction in sequence |
duke@435 | 339 | Bytecodes::Code opcode; |
duke@435 | 340 | while (!bcs.is_last_bytecode()) { |
jrose@1925 | 341 | // Check for recursive re-verification before each bytecode. |
jrose@1925 | 342 | if (was_recursively_verified()) return; |
jrose@1925 | 343 | |
duke@435 | 344 | opcode = bcs.raw_next(); |
duke@435 | 345 | u2 bci = bcs.bci(); |
duke@435 | 346 | |
duke@435 | 347 | // Set current frame's offset to bci |
duke@435 | 348 | current_frame.set_offset(bci); |
duke@435 | 349 | |
duke@435 | 350 | // Make sure every offset in stackmap table point to the beginning to |
duke@435 | 351 | // an instruction. Match current_frame to stackmap_table entry with |
duke@435 | 352 | // the same offset if exists. |
duke@435 | 353 | stackmap_index = verify_stackmap_table( |
duke@435 | 354 | stackmap_index, bci, ¤t_frame, &stackmap_table, |
duke@435 | 355 | no_control_flow, CHECK_VERIFY(this)); |
duke@435 | 356 | |
duke@435 | 357 | bool this_uninit = false; // Set to true when invokespecial <init> initialized 'this' |
duke@435 | 358 | |
duke@435 | 359 | // Merge with the next instruction |
duke@435 | 360 | { |
duke@435 | 361 | u2 index; |
duke@435 | 362 | int target; |
duke@435 | 363 | VerificationType type, type2; |
duke@435 | 364 | VerificationType atype; |
duke@435 | 365 | |
duke@435 | 366 | #ifndef PRODUCT |
duke@435 | 367 | if (_verify_verbose) { |
duke@435 | 368 | current_frame.print(); |
duke@435 | 369 | tty->print_cr("offset = %d, opcode = %s", bci, Bytecodes::name(opcode)); |
duke@435 | 370 | } |
duke@435 | 371 | #endif |
duke@435 | 372 | |
duke@435 | 373 | // Make sure wide instruction is in correct format |
duke@435 | 374 | if (bcs.is_wide()) { |
duke@435 | 375 | if (opcode != Bytecodes::_iinc && opcode != Bytecodes::_iload && |
duke@435 | 376 | opcode != Bytecodes::_aload && opcode != Bytecodes::_lload && |
duke@435 | 377 | opcode != Bytecodes::_istore && opcode != Bytecodes::_astore && |
duke@435 | 378 | opcode != Bytecodes::_lstore && opcode != Bytecodes::_fload && |
duke@435 | 379 | opcode != Bytecodes::_dload && opcode != Bytecodes::_fstore && |
duke@435 | 380 | opcode != Bytecodes::_dstore) { |
duke@435 | 381 | verify_error(bci, "Bad wide instruction"); |
duke@435 | 382 | return; |
duke@435 | 383 | } |
duke@435 | 384 | } |
duke@435 | 385 | |
duke@435 | 386 | switch (opcode) { |
duke@435 | 387 | case Bytecodes::_nop : |
duke@435 | 388 | no_control_flow = false; break; |
duke@435 | 389 | case Bytecodes::_aconst_null : |
duke@435 | 390 | current_frame.push_stack( |
duke@435 | 391 | VerificationType::null_type(), CHECK_VERIFY(this)); |
duke@435 | 392 | no_control_flow = false; break; |
duke@435 | 393 | case Bytecodes::_iconst_m1 : |
duke@435 | 394 | case Bytecodes::_iconst_0 : |
duke@435 | 395 | case Bytecodes::_iconst_1 : |
duke@435 | 396 | case Bytecodes::_iconst_2 : |
duke@435 | 397 | case Bytecodes::_iconst_3 : |
duke@435 | 398 | case Bytecodes::_iconst_4 : |
duke@435 | 399 | case Bytecodes::_iconst_5 : |
duke@435 | 400 | current_frame.push_stack( |
duke@435 | 401 | VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 402 | no_control_flow = false; break; |
duke@435 | 403 | case Bytecodes::_lconst_0 : |
duke@435 | 404 | case Bytecodes::_lconst_1 : |
duke@435 | 405 | current_frame.push_stack_2( |
duke@435 | 406 | VerificationType::long_type(), |
duke@435 | 407 | VerificationType::long2_type(), CHECK_VERIFY(this)); |
duke@435 | 408 | no_control_flow = false; break; |
duke@435 | 409 | case Bytecodes::_fconst_0 : |
duke@435 | 410 | case Bytecodes::_fconst_1 : |
duke@435 | 411 | case Bytecodes::_fconst_2 : |
duke@435 | 412 | current_frame.push_stack( |
duke@435 | 413 | VerificationType::float_type(), CHECK_VERIFY(this)); |
duke@435 | 414 | no_control_flow = false; break; |
duke@435 | 415 | case Bytecodes::_dconst_0 : |
duke@435 | 416 | case Bytecodes::_dconst_1 : |
duke@435 | 417 | current_frame.push_stack_2( |
duke@435 | 418 | VerificationType::double_type(), |
duke@435 | 419 | VerificationType::double2_type(), CHECK_VERIFY(this)); |
duke@435 | 420 | no_control_flow = false; break; |
duke@435 | 421 | case Bytecodes::_sipush : |
duke@435 | 422 | case Bytecodes::_bipush : |
duke@435 | 423 | current_frame.push_stack( |
duke@435 | 424 | VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 425 | no_control_flow = false; break; |
duke@435 | 426 | case Bytecodes::_ldc : |
duke@435 | 427 | verify_ldc( |
jrose@1920 | 428 | opcode, bcs.get_index_u1(), ¤t_frame, |
duke@435 | 429 | cp, bci, CHECK_VERIFY(this)); |
duke@435 | 430 | no_control_flow = false; break; |
duke@435 | 431 | case Bytecodes::_ldc_w : |
duke@435 | 432 | case Bytecodes::_ldc2_w : |
duke@435 | 433 | verify_ldc( |
jrose@1920 | 434 | opcode, bcs.get_index_u2(), ¤t_frame, |
duke@435 | 435 | cp, bci, CHECK_VERIFY(this)); |
duke@435 | 436 | no_control_flow = false; break; |
duke@435 | 437 | case Bytecodes::_iload : |
duke@435 | 438 | verify_iload(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); |
duke@435 | 439 | no_control_flow = false; break; |
duke@435 | 440 | case Bytecodes::_iload_0 : |
duke@435 | 441 | case Bytecodes::_iload_1 : |
duke@435 | 442 | case Bytecodes::_iload_2 : |
duke@435 | 443 | case Bytecodes::_iload_3 : |
duke@435 | 444 | index = opcode - Bytecodes::_iload_0; |
duke@435 | 445 | verify_iload(index, ¤t_frame, CHECK_VERIFY(this)); |
duke@435 | 446 | no_control_flow = false; break; |
duke@435 | 447 | case Bytecodes::_lload : |
duke@435 | 448 | verify_lload(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); |
duke@435 | 449 | no_control_flow = false; break; |
duke@435 | 450 | case Bytecodes::_lload_0 : |
duke@435 | 451 | case Bytecodes::_lload_1 : |
duke@435 | 452 | case Bytecodes::_lload_2 : |
duke@435 | 453 | case Bytecodes::_lload_3 : |
duke@435 | 454 | index = opcode - Bytecodes::_lload_0; |
duke@435 | 455 | verify_lload(index, ¤t_frame, CHECK_VERIFY(this)); |
duke@435 | 456 | no_control_flow = false; break; |
duke@435 | 457 | case Bytecodes::_fload : |
duke@435 | 458 | verify_fload(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); |
duke@435 | 459 | no_control_flow = false; break; |
duke@435 | 460 | case Bytecodes::_fload_0 : |
duke@435 | 461 | case Bytecodes::_fload_1 : |
duke@435 | 462 | case Bytecodes::_fload_2 : |
duke@435 | 463 | case Bytecodes::_fload_3 : |
duke@435 | 464 | index = opcode - Bytecodes::_fload_0; |
duke@435 | 465 | verify_fload(index, ¤t_frame, CHECK_VERIFY(this)); |
duke@435 | 466 | no_control_flow = false; break; |
duke@435 | 467 | case Bytecodes::_dload : |
duke@435 | 468 | verify_dload(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); |
duke@435 | 469 | no_control_flow = false; break; |
duke@435 | 470 | case Bytecodes::_dload_0 : |
duke@435 | 471 | case Bytecodes::_dload_1 : |
duke@435 | 472 | case Bytecodes::_dload_2 : |
duke@435 | 473 | case Bytecodes::_dload_3 : |
duke@435 | 474 | index = opcode - Bytecodes::_dload_0; |
duke@435 | 475 | verify_dload(index, ¤t_frame, CHECK_VERIFY(this)); |
duke@435 | 476 | no_control_flow = false; break; |
duke@435 | 477 | case Bytecodes::_aload : |
duke@435 | 478 | verify_aload(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); |
duke@435 | 479 | no_control_flow = false; break; |
duke@435 | 480 | case Bytecodes::_aload_0 : |
duke@435 | 481 | case Bytecodes::_aload_1 : |
duke@435 | 482 | case Bytecodes::_aload_2 : |
duke@435 | 483 | case Bytecodes::_aload_3 : |
duke@435 | 484 | index = opcode - Bytecodes::_aload_0; |
duke@435 | 485 | verify_aload(index, ¤t_frame, CHECK_VERIFY(this)); |
duke@435 | 486 | no_control_flow = false; break; |
duke@435 | 487 | case Bytecodes::_iaload : |
duke@435 | 488 | type = current_frame.pop_stack( |
duke@435 | 489 | VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 490 | atype = current_frame.pop_stack( |
duke@435 | 491 | VerificationType::reference_check(), CHECK_VERIFY(this)); |
duke@435 | 492 | if (!atype.is_int_array()) { |
duke@435 | 493 | verify_error(bci, bad_type_msg, "iaload"); |
duke@435 | 494 | return; |
duke@435 | 495 | } |
duke@435 | 496 | current_frame.push_stack( |
duke@435 | 497 | VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 498 | no_control_flow = false; break; |
duke@435 | 499 | case Bytecodes::_baload : |
duke@435 | 500 | type = current_frame.pop_stack( |
duke@435 | 501 | VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 502 | atype = current_frame.pop_stack( |
duke@435 | 503 | VerificationType::reference_check(), CHECK_VERIFY(this)); |
duke@435 | 504 | if (!atype.is_bool_array() && !atype.is_byte_array()) { |
duke@435 | 505 | verify_error(bci, bad_type_msg, "baload"); |
duke@435 | 506 | return; |
duke@435 | 507 | } |
duke@435 | 508 | current_frame.push_stack( |
duke@435 | 509 | VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 510 | no_control_flow = false; break; |
duke@435 | 511 | case Bytecodes::_caload : |
duke@435 | 512 | type = current_frame.pop_stack( |
duke@435 | 513 | VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 514 | atype = current_frame.pop_stack( |
duke@435 | 515 | VerificationType::reference_check(), CHECK_VERIFY(this)); |
duke@435 | 516 | if (!atype.is_char_array()) { |
duke@435 | 517 | verify_error(bci, bad_type_msg, "caload"); |
duke@435 | 518 | return; |
duke@435 | 519 | } |
duke@435 | 520 | current_frame.push_stack( |
duke@435 | 521 | VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 522 | no_control_flow = false; break; |
duke@435 | 523 | case Bytecodes::_saload : |
duke@435 | 524 | type = current_frame.pop_stack( |
duke@435 | 525 | VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 526 | atype = current_frame.pop_stack( |
duke@435 | 527 | VerificationType::reference_check(), CHECK_VERIFY(this)); |
duke@435 | 528 | if (!atype.is_short_array()) { |
duke@435 | 529 | verify_error(bci, bad_type_msg, "saload"); |
duke@435 | 530 | return; |
duke@435 | 531 | } |
duke@435 | 532 | current_frame.push_stack( |
duke@435 | 533 | VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 534 | no_control_flow = false; break; |
duke@435 | 535 | case Bytecodes::_laload : |
duke@435 | 536 | type = current_frame.pop_stack( |
duke@435 | 537 | VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 538 | atype = current_frame.pop_stack( |
duke@435 | 539 | VerificationType::reference_check(), CHECK_VERIFY(this)); |
duke@435 | 540 | if (!atype.is_long_array()) { |
duke@435 | 541 | verify_error(bci, bad_type_msg, "laload"); |
duke@435 | 542 | return; |
duke@435 | 543 | } |
duke@435 | 544 | current_frame.push_stack_2( |
duke@435 | 545 | VerificationType::long_type(), |
duke@435 | 546 | VerificationType::long2_type(), CHECK_VERIFY(this)); |
duke@435 | 547 | no_control_flow = false; break; |
duke@435 | 548 | case Bytecodes::_faload : |
duke@435 | 549 | type = current_frame.pop_stack( |
duke@435 | 550 | VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 551 | atype = current_frame.pop_stack( |
duke@435 | 552 | VerificationType::reference_check(), CHECK_VERIFY(this)); |
duke@435 | 553 | if (!atype.is_float_array()) { |
duke@435 | 554 | verify_error(bci, bad_type_msg, "faload"); |
duke@435 | 555 | return; |
duke@435 | 556 | } |
duke@435 | 557 | current_frame.push_stack( |
duke@435 | 558 | VerificationType::float_type(), CHECK_VERIFY(this)); |
duke@435 | 559 | no_control_flow = false; break; |
duke@435 | 560 | case Bytecodes::_daload : |
duke@435 | 561 | type = current_frame.pop_stack( |
duke@435 | 562 | VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 563 | atype = current_frame.pop_stack( |
duke@435 | 564 | VerificationType::reference_check(), CHECK_VERIFY(this)); |
duke@435 | 565 | if (!atype.is_double_array()) { |
duke@435 | 566 | verify_error(bci, bad_type_msg, "daload"); |
duke@435 | 567 | return; |
duke@435 | 568 | } |
duke@435 | 569 | current_frame.push_stack_2( |
duke@435 | 570 | VerificationType::double_type(), |
duke@435 | 571 | VerificationType::double2_type(), CHECK_VERIFY(this)); |
duke@435 | 572 | no_control_flow = false; break; |
duke@435 | 573 | case Bytecodes::_aaload : { |
duke@435 | 574 | type = current_frame.pop_stack( |
duke@435 | 575 | VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 576 | atype = current_frame.pop_stack( |
duke@435 | 577 | VerificationType::reference_check(), CHECK_VERIFY(this)); |
duke@435 | 578 | if (!atype.is_reference_array()) { |
duke@435 | 579 | verify_error(bci, bad_type_msg, "aaload"); |
duke@435 | 580 | return; |
duke@435 | 581 | } |
duke@435 | 582 | if (atype.is_null()) { |
duke@435 | 583 | current_frame.push_stack( |
duke@435 | 584 | VerificationType::null_type(), CHECK_VERIFY(this)); |
duke@435 | 585 | } else { |
duke@435 | 586 | VerificationType component = |
duke@435 | 587 | atype.get_component(CHECK_VERIFY(this)); |
duke@435 | 588 | current_frame.push_stack(component, CHECK_VERIFY(this)); |
duke@435 | 589 | } |
duke@435 | 590 | no_control_flow = false; break; |
duke@435 | 591 | } |
duke@435 | 592 | case Bytecodes::_istore : |
duke@435 | 593 | verify_istore(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); |
duke@435 | 594 | no_control_flow = false; break; |
duke@435 | 595 | case Bytecodes::_istore_0 : |
duke@435 | 596 | case Bytecodes::_istore_1 : |
duke@435 | 597 | case Bytecodes::_istore_2 : |
duke@435 | 598 | case Bytecodes::_istore_3 : |
duke@435 | 599 | index = opcode - Bytecodes::_istore_0; |
duke@435 | 600 | verify_istore(index, ¤t_frame, CHECK_VERIFY(this)); |
duke@435 | 601 | no_control_flow = false; break; |
duke@435 | 602 | case Bytecodes::_lstore : |
duke@435 | 603 | verify_lstore(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); |
duke@435 | 604 | no_control_flow = false; break; |
duke@435 | 605 | case Bytecodes::_lstore_0 : |
duke@435 | 606 | case Bytecodes::_lstore_1 : |
duke@435 | 607 | case Bytecodes::_lstore_2 : |
duke@435 | 608 | case Bytecodes::_lstore_3 : |
duke@435 | 609 | index = opcode - Bytecodes::_lstore_0; |
duke@435 | 610 | verify_lstore(index, ¤t_frame, CHECK_VERIFY(this)); |
duke@435 | 611 | no_control_flow = false; break; |
duke@435 | 612 | case Bytecodes::_fstore : |
duke@435 | 613 | verify_fstore(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); |
duke@435 | 614 | no_control_flow = false; break; |
duke@435 | 615 | case Bytecodes::_fstore_0 : |
duke@435 | 616 | case Bytecodes::_fstore_1 : |
duke@435 | 617 | case Bytecodes::_fstore_2 : |
duke@435 | 618 | case Bytecodes::_fstore_3 : |
duke@435 | 619 | index = opcode - Bytecodes::_fstore_0; |
duke@435 | 620 | verify_fstore(index, ¤t_frame, CHECK_VERIFY(this)); |
duke@435 | 621 | no_control_flow = false; break; |
duke@435 | 622 | case Bytecodes::_dstore : |
duke@435 | 623 | verify_dstore(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); |
duke@435 | 624 | no_control_flow = false; break; |
duke@435 | 625 | case Bytecodes::_dstore_0 : |
duke@435 | 626 | case Bytecodes::_dstore_1 : |
duke@435 | 627 | case Bytecodes::_dstore_2 : |
duke@435 | 628 | case Bytecodes::_dstore_3 : |
duke@435 | 629 | index = opcode - Bytecodes::_dstore_0; |
duke@435 | 630 | verify_dstore(index, ¤t_frame, CHECK_VERIFY(this)); |
duke@435 | 631 | no_control_flow = false; break; |
duke@435 | 632 | case Bytecodes::_astore : |
duke@435 | 633 | verify_astore(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); |
duke@435 | 634 | no_control_flow = false; break; |
duke@435 | 635 | case Bytecodes::_astore_0 : |
duke@435 | 636 | case Bytecodes::_astore_1 : |
duke@435 | 637 | case Bytecodes::_astore_2 : |
duke@435 | 638 | case Bytecodes::_astore_3 : |
duke@435 | 639 | index = opcode - Bytecodes::_astore_0; |
duke@435 | 640 | verify_astore(index, ¤t_frame, CHECK_VERIFY(this)); |
duke@435 | 641 | no_control_flow = false; break; |
duke@435 | 642 | case Bytecodes::_iastore : |
duke@435 | 643 | type = current_frame.pop_stack( |
duke@435 | 644 | VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 645 | type2 = current_frame.pop_stack( |
duke@435 | 646 | VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 647 | atype = current_frame.pop_stack( |
duke@435 | 648 | VerificationType::reference_check(), CHECK_VERIFY(this)); |
duke@435 | 649 | if (!atype.is_int_array()) { |
duke@435 | 650 | verify_error(bci, bad_type_msg, "iastore"); |
duke@435 | 651 | return; |
duke@435 | 652 | } |
duke@435 | 653 | no_control_flow = false; break; |
duke@435 | 654 | case Bytecodes::_bastore : |
duke@435 | 655 | type = current_frame.pop_stack( |
duke@435 | 656 | VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 657 | type2 = current_frame.pop_stack( |
duke@435 | 658 | VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 659 | atype = current_frame.pop_stack( |
duke@435 | 660 | VerificationType::reference_check(), CHECK_VERIFY(this)); |
duke@435 | 661 | if (!atype.is_bool_array() && !atype.is_byte_array()) { |
duke@435 | 662 | verify_error(bci, bad_type_msg, "bastore"); |
duke@435 | 663 | return; |
duke@435 | 664 | } |
duke@435 | 665 | no_control_flow = false; break; |
duke@435 | 666 | case Bytecodes::_castore : |
duke@435 | 667 | current_frame.pop_stack( |
duke@435 | 668 | VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 669 | current_frame.pop_stack( |
duke@435 | 670 | VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 671 | atype = current_frame.pop_stack( |
duke@435 | 672 | VerificationType::reference_check(), CHECK_VERIFY(this)); |
duke@435 | 673 | if (!atype.is_char_array()) { |
duke@435 | 674 | verify_error(bci, bad_type_msg, "castore"); |
duke@435 | 675 | return; |
duke@435 | 676 | } |
duke@435 | 677 | no_control_flow = false; break; |
duke@435 | 678 | case Bytecodes::_sastore : |
duke@435 | 679 | current_frame.pop_stack( |
duke@435 | 680 | VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 681 | current_frame.pop_stack( |
duke@435 | 682 | VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 683 | atype = current_frame.pop_stack( |
duke@435 | 684 | VerificationType::reference_check(), CHECK_VERIFY(this)); |
duke@435 | 685 | if (!atype.is_short_array()) { |
duke@435 | 686 | verify_error(bci, bad_type_msg, "sastore"); |
duke@435 | 687 | return; |
duke@435 | 688 | } |
duke@435 | 689 | no_control_flow = false; break; |
duke@435 | 690 | case Bytecodes::_lastore : |
duke@435 | 691 | current_frame.pop_stack_2( |
duke@435 | 692 | VerificationType::long2_type(), |
duke@435 | 693 | VerificationType::long_type(), CHECK_VERIFY(this)); |
duke@435 | 694 | current_frame.pop_stack( |
duke@435 | 695 | VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 696 | atype = current_frame.pop_stack( |
duke@435 | 697 | VerificationType::reference_check(), CHECK_VERIFY(this)); |
duke@435 | 698 | if (!atype.is_long_array()) { |
duke@435 | 699 | verify_error(bci, bad_type_msg, "lastore"); |
duke@435 | 700 | return; |
duke@435 | 701 | } |
duke@435 | 702 | no_control_flow = false; break; |
duke@435 | 703 | case Bytecodes::_fastore : |
duke@435 | 704 | current_frame.pop_stack( |
duke@435 | 705 | VerificationType::float_type(), CHECK_VERIFY(this)); |
duke@435 | 706 | current_frame.pop_stack |
duke@435 | 707 | (VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 708 | atype = current_frame.pop_stack( |
duke@435 | 709 | VerificationType::reference_check(), CHECK_VERIFY(this)); |
duke@435 | 710 | if (!atype.is_float_array()) { |
duke@435 | 711 | verify_error(bci, bad_type_msg, "fastore"); |
duke@435 | 712 | return; |
duke@435 | 713 | } |
duke@435 | 714 | no_control_flow = false; break; |
duke@435 | 715 | case Bytecodes::_dastore : |
duke@435 | 716 | current_frame.pop_stack_2( |
duke@435 | 717 | VerificationType::double2_type(), |
duke@435 | 718 | VerificationType::double_type(), CHECK_VERIFY(this)); |
duke@435 | 719 | current_frame.pop_stack( |
duke@435 | 720 | VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 721 | atype = current_frame.pop_stack( |
duke@435 | 722 | VerificationType::reference_check(), CHECK_VERIFY(this)); |
duke@435 | 723 | if (!atype.is_double_array()) { |
duke@435 | 724 | verify_error(bci, bad_type_msg, "dastore"); |
duke@435 | 725 | return; |
duke@435 | 726 | } |
duke@435 | 727 | no_control_flow = false; break; |
duke@435 | 728 | case Bytecodes::_aastore : |
duke@435 | 729 | type = current_frame.pop_stack( |
duke@435 | 730 | VerificationType::reference_check(), CHECK_VERIFY(this)); |
duke@435 | 731 | type2 = current_frame.pop_stack( |
duke@435 | 732 | VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 733 | atype = current_frame.pop_stack( |
duke@435 | 734 | VerificationType::reference_check(), CHECK_VERIFY(this)); |
duke@435 | 735 | // more type-checking is done at runtime |
duke@435 | 736 | if (!atype.is_reference_array()) { |
duke@435 | 737 | verify_error(bci, bad_type_msg, "aastore"); |
duke@435 | 738 | return; |
duke@435 | 739 | } |
duke@435 | 740 | // 4938384: relaxed constraint in JVMS 3nd edition. |
duke@435 | 741 | no_control_flow = false; break; |
duke@435 | 742 | case Bytecodes::_pop : |
duke@435 | 743 | current_frame.pop_stack( |
duke@435 | 744 | VerificationType::category1_check(), CHECK_VERIFY(this)); |
duke@435 | 745 | no_control_flow = false; break; |
duke@435 | 746 | case Bytecodes::_pop2 : |
duke@435 | 747 | type = current_frame.pop_stack(CHECK_VERIFY(this)); |
duke@435 | 748 | if (type.is_category1()) { |
duke@435 | 749 | current_frame.pop_stack( |
duke@435 | 750 | VerificationType::category1_check(), CHECK_VERIFY(this)); |
duke@435 | 751 | } else if (type.is_category2_2nd()) { |
duke@435 | 752 | current_frame.pop_stack( |
duke@435 | 753 | VerificationType::category2_check(), CHECK_VERIFY(this)); |
duke@435 | 754 | } else { |
duke@435 | 755 | verify_error(bci, bad_type_msg, "pop2"); |
duke@435 | 756 | return; |
duke@435 | 757 | } |
duke@435 | 758 | no_control_flow = false; break; |
duke@435 | 759 | case Bytecodes::_dup : |
duke@435 | 760 | type = current_frame.pop_stack( |
duke@435 | 761 | VerificationType::category1_check(), CHECK_VERIFY(this)); |
duke@435 | 762 | current_frame.push_stack(type, CHECK_VERIFY(this)); |
duke@435 | 763 | current_frame.push_stack(type, CHECK_VERIFY(this)); |
duke@435 | 764 | no_control_flow = false; break; |
duke@435 | 765 | case Bytecodes::_dup_x1 : |
duke@435 | 766 | type = current_frame.pop_stack( |
duke@435 | 767 | VerificationType::category1_check(), CHECK_VERIFY(this)); |
duke@435 | 768 | type2 = current_frame.pop_stack( |
duke@435 | 769 | VerificationType::category1_check(), CHECK_VERIFY(this)); |
duke@435 | 770 | current_frame.push_stack(type, CHECK_VERIFY(this)); |
duke@435 | 771 | current_frame.push_stack(type2, CHECK_VERIFY(this)); |
duke@435 | 772 | current_frame.push_stack(type, CHECK_VERIFY(this)); |
duke@435 | 773 | no_control_flow = false; break; |
duke@435 | 774 | case Bytecodes::_dup_x2 : |
duke@435 | 775 | { |
duke@435 | 776 | VerificationType type3; |
duke@435 | 777 | type = current_frame.pop_stack( |
duke@435 | 778 | VerificationType::category1_check(), CHECK_VERIFY(this)); |
duke@435 | 779 | type2 = current_frame.pop_stack(CHECK_VERIFY(this)); |
duke@435 | 780 | if (type2.is_category1()) { |
duke@435 | 781 | type3 = current_frame.pop_stack( |
duke@435 | 782 | VerificationType::category1_check(), CHECK_VERIFY(this)); |
duke@435 | 783 | } else if (type2.is_category2_2nd()) { |
duke@435 | 784 | type3 = current_frame.pop_stack( |
duke@435 | 785 | VerificationType::category2_check(), CHECK_VERIFY(this)); |
duke@435 | 786 | } else { |
duke@435 | 787 | verify_error(bci, bad_type_msg, "dup_x2"); |
duke@435 | 788 | return; |
duke@435 | 789 | } |
duke@435 | 790 | current_frame.push_stack(type, CHECK_VERIFY(this)); |
duke@435 | 791 | current_frame.push_stack(type3, CHECK_VERIFY(this)); |
duke@435 | 792 | current_frame.push_stack(type2, CHECK_VERIFY(this)); |
duke@435 | 793 | current_frame.push_stack(type, CHECK_VERIFY(this)); |
duke@435 | 794 | no_control_flow = false; break; |
duke@435 | 795 | } |
duke@435 | 796 | case Bytecodes::_dup2 : |
duke@435 | 797 | type = current_frame.pop_stack(CHECK_VERIFY(this)); |
duke@435 | 798 | if (type.is_category1()) { |
duke@435 | 799 | type2 = current_frame.pop_stack( |
duke@435 | 800 | VerificationType::category1_check(), CHECK_VERIFY(this)); |
duke@435 | 801 | } else if (type.is_category2_2nd()) { |
duke@435 | 802 | type2 = current_frame.pop_stack( |
duke@435 | 803 | VerificationType::category2_check(), CHECK_VERIFY(this)); |
duke@435 | 804 | } else { |
duke@435 | 805 | verify_error(bci, bad_type_msg, "dup2"); |
duke@435 | 806 | return; |
duke@435 | 807 | } |
duke@435 | 808 | current_frame.push_stack(type2, CHECK_VERIFY(this)); |
duke@435 | 809 | current_frame.push_stack(type, CHECK_VERIFY(this)); |
duke@435 | 810 | current_frame.push_stack(type2, CHECK_VERIFY(this)); |
duke@435 | 811 | current_frame.push_stack(type, CHECK_VERIFY(this)); |
duke@435 | 812 | no_control_flow = false; break; |
duke@435 | 813 | case Bytecodes::_dup2_x1 : |
duke@435 | 814 | { |
duke@435 | 815 | VerificationType type3; |
duke@435 | 816 | type = current_frame.pop_stack(CHECK_VERIFY(this)); |
duke@435 | 817 | if (type.is_category1()) { |
duke@435 | 818 | type2 = current_frame.pop_stack( |
duke@435 | 819 | VerificationType::category1_check(), CHECK_VERIFY(this)); |
duke@435 | 820 | } else if(type.is_category2_2nd()) { |
duke@435 | 821 | type2 = current_frame.pop_stack |
duke@435 | 822 | (VerificationType::category2_check(), CHECK_VERIFY(this)); |
duke@435 | 823 | } else { |
duke@435 | 824 | verify_error(bci, bad_type_msg, "dup2_x1"); |
duke@435 | 825 | return; |
duke@435 | 826 | } |
duke@435 | 827 | type3 = current_frame.pop_stack( |
duke@435 | 828 | VerificationType::category1_check(), CHECK_VERIFY(this)); |
duke@435 | 829 | current_frame.push_stack(type2, CHECK_VERIFY(this)); |
duke@435 | 830 | current_frame.push_stack(type, CHECK_VERIFY(this)); |
duke@435 | 831 | current_frame.push_stack(type3, CHECK_VERIFY(this)); |
duke@435 | 832 | current_frame.push_stack(type2, CHECK_VERIFY(this)); |
duke@435 | 833 | current_frame.push_stack(type, CHECK_VERIFY(this)); |
duke@435 | 834 | no_control_flow = false; break; |
duke@435 | 835 | } |
duke@435 | 836 | case Bytecodes::_dup2_x2 : |
duke@435 | 837 | { |
duke@435 | 838 | VerificationType type3, type4; |
duke@435 | 839 | type = current_frame.pop_stack(CHECK_VERIFY(this)); |
duke@435 | 840 | if (type.is_category1()) { |
duke@435 | 841 | type2 = current_frame.pop_stack( |
duke@435 | 842 | VerificationType::category1_check(), CHECK_VERIFY(this)); |
duke@435 | 843 | } else if (type.is_category2_2nd()) { |
duke@435 | 844 | type2 = current_frame.pop_stack( |
duke@435 | 845 | VerificationType::category2_check(), CHECK_VERIFY(this)); |
duke@435 | 846 | } else { |
duke@435 | 847 | verify_error(bci, bad_type_msg, "dup2_x2"); |
duke@435 | 848 | return; |
duke@435 | 849 | } |
duke@435 | 850 | type3 = current_frame.pop_stack(CHECK_VERIFY(this)); |
duke@435 | 851 | if (type3.is_category1()) { |
duke@435 | 852 | type4 = current_frame.pop_stack( |
duke@435 | 853 | VerificationType::category1_check(), CHECK_VERIFY(this)); |
duke@435 | 854 | } else if (type3.is_category2_2nd()) { |
duke@435 | 855 | type4 = current_frame.pop_stack( |
duke@435 | 856 | VerificationType::category2_check(), CHECK_VERIFY(this)); |
duke@435 | 857 | } else { |
duke@435 | 858 | verify_error(bci, bad_type_msg, "dup2_x2"); |
duke@435 | 859 | return; |
duke@435 | 860 | } |
duke@435 | 861 | current_frame.push_stack(type2, CHECK_VERIFY(this)); |
duke@435 | 862 | current_frame.push_stack(type, CHECK_VERIFY(this)); |
duke@435 | 863 | current_frame.push_stack(type4, CHECK_VERIFY(this)); |
duke@435 | 864 | current_frame.push_stack(type3, CHECK_VERIFY(this)); |
duke@435 | 865 | current_frame.push_stack(type2, CHECK_VERIFY(this)); |
duke@435 | 866 | current_frame.push_stack(type, CHECK_VERIFY(this)); |
duke@435 | 867 | no_control_flow = false; break; |
duke@435 | 868 | } |
duke@435 | 869 | case Bytecodes::_swap : |
duke@435 | 870 | type = current_frame.pop_stack( |
duke@435 | 871 | VerificationType::category1_check(), CHECK_VERIFY(this)); |
duke@435 | 872 | type2 = current_frame.pop_stack( |
duke@435 | 873 | VerificationType::category1_check(), CHECK_VERIFY(this)); |
duke@435 | 874 | current_frame.push_stack(type, CHECK_VERIFY(this)); |
duke@435 | 875 | current_frame.push_stack(type2, CHECK_VERIFY(this)); |
duke@435 | 876 | no_control_flow = false; break; |
duke@435 | 877 | case Bytecodes::_iadd : |
duke@435 | 878 | case Bytecodes::_isub : |
duke@435 | 879 | case Bytecodes::_imul : |
duke@435 | 880 | case Bytecodes::_idiv : |
duke@435 | 881 | case Bytecodes::_irem : |
duke@435 | 882 | case Bytecodes::_ishl : |
duke@435 | 883 | case Bytecodes::_ishr : |
duke@435 | 884 | case Bytecodes::_iushr : |
duke@435 | 885 | case Bytecodes::_ior : |
duke@435 | 886 | case Bytecodes::_ixor : |
duke@435 | 887 | case Bytecodes::_iand : |
duke@435 | 888 | current_frame.pop_stack( |
duke@435 | 889 | VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 890 | // fall through |
duke@435 | 891 | case Bytecodes::_ineg : |
duke@435 | 892 | current_frame.pop_stack( |
duke@435 | 893 | VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 894 | current_frame.push_stack( |
duke@435 | 895 | VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 896 | no_control_flow = false; break; |
duke@435 | 897 | case Bytecodes::_ladd : |
duke@435 | 898 | case Bytecodes::_lsub : |
duke@435 | 899 | case Bytecodes::_lmul : |
duke@435 | 900 | case Bytecodes::_ldiv : |
duke@435 | 901 | case Bytecodes::_lrem : |
duke@435 | 902 | case Bytecodes::_land : |
duke@435 | 903 | case Bytecodes::_lor : |
duke@435 | 904 | case Bytecodes::_lxor : |
duke@435 | 905 | current_frame.pop_stack_2( |
duke@435 | 906 | VerificationType::long2_type(), |
duke@435 | 907 | VerificationType::long_type(), CHECK_VERIFY(this)); |
duke@435 | 908 | // fall through |
duke@435 | 909 | case Bytecodes::_lneg : |
duke@435 | 910 | current_frame.pop_stack_2( |
duke@435 | 911 | VerificationType::long2_type(), |
duke@435 | 912 | VerificationType::long_type(), CHECK_VERIFY(this)); |
duke@435 | 913 | current_frame.push_stack_2( |
duke@435 | 914 | VerificationType::long_type(), |
duke@435 | 915 | VerificationType::long2_type(), CHECK_VERIFY(this)); |
duke@435 | 916 | no_control_flow = false; break; |
duke@435 | 917 | case Bytecodes::_lshl : |
duke@435 | 918 | case Bytecodes::_lshr : |
duke@435 | 919 | case Bytecodes::_lushr : |
duke@435 | 920 | current_frame.pop_stack( |
duke@435 | 921 | VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 922 | current_frame.pop_stack_2( |
duke@435 | 923 | VerificationType::long2_type(), |
duke@435 | 924 | VerificationType::long_type(), CHECK_VERIFY(this)); |
duke@435 | 925 | current_frame.push_stack_2( |
duke@435 | 926 | VerificationType::long_type(), |
duke@435 | 927 | VerificationType::long2_type(), CHECK_VERIFY(this)); |
duke@435 | 928 | no_control_flow = false; break; |
duke@435 | 929 | case Bytecodes::_fadd : |
duke@435 | 930 | case Bytecodes::_fsub : |
duke@435 | 931 | case Bytecodes::_fmul : |
duke@435 | 932 | case Bytecodes::_fdiv : |
duke@435 | 933 | case Bytecodes::_frem : |
duke@435 | 934 | current_frame.pop_stack( |
duke@435 | 935 | VerificationType::float_type(), CHECK_VERIFY(this)); |
duke@435 | 936 | // fall through |
duke@435 | 937 | case Bytecodes::_fneg : |
duke@435 | 938 | current_frame.pop_stack( |
duke@435 | 939 | VerificationType::float_type(), CHECK_VERIFY(this)); |
duke@435 | 940 | current_frame.push_stack( |
duke@435 | 941 | VerificationType::float_type(), CHECK_VERIFY(this)); |
duke@435 | 942 | no_control_flow = false; break; |
duke@435 | 943 | case Bytecodes::_dadd : |
duke@435 | 944 | case Bytecodes::_dsub : |
duke@435 | 945 | case Bytecodes::_dmul : |
duke@435 | 946 | case Bytecodes::_ddiv : |
duke@435 | 947 | case Bytecodes::_drem : |
duke@435 | 948 | current_frame.pop_stack_2( |
duke@435 | 949 | VerificationType::double2_type(), |
duke@435 | 950 | VerificationType::double_type(), CHECK_VERIFY(this)); |
duke@435 | 951 | // fall through |
duke@435 | 952 | case Bytecodes::_dneg : |
duke@435 | 953 | current_frame.pop_stack_2( |
duke@435 | 954 | VerificationType::double2_type(), |
duke@435 | 955 | VerificationType::double_type(), CHECK_VERIFY(this)); |
duke@435 | 956 | current_frame.push_stack_2( |
duke@435 | 957 | VerificationType::double_type(), |
duke@435 | 958 | VerificationType::double2_type(), CHECK_VERIFY(this)); |
duke@435 | 959 | no_control_flow = false; break; |
duke@435 | 960 | case Bytecodes::_iinc : |
duke@435 | 961 | verify_iinc(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); |
duke@435 | 962 | no_control_flow = false; break; |
duke@435 | 963 | case Bytecodes::_i2l : |
duke@435 | 964 | type = current_frame.pop_stack( |
duke@435 | 965 | VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 966 | current_frame.push_stack_2( |
duke@435 | 967 | VerificationType::long_type(), |
duke@435 | 968 | VerificationType::long2_type(), CHECK_VERIFY(this)); |
duke@435 | 969 | no_control_flow = false; break; |
duke@435 | 970 | case Bytecodes::_l2i : |
duke@435 | 971 | current_frame.pop_stack_2( |
duke@435 | 972 | VerificationType::long2_type(), |
duke@435 | 973 | VerificationType::long_type(), CHECK_VERIFY(this)); |
duke@435 | 974 | current_frame.push_stack( |
duke@435 | 975 | VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 976 | no_control_flow = false; break; |
duke@435 | 977 | case Bytecodes::_i2f : |
duke@435 | 978 | current_frame.pop_stack( |
duke@435 | 979 | VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 980 | current_frame.push_stack( |
duke@435 | 981 | VerificationType::float_type(), CHECK_VERIFY(this)); |
duke@435 | 982 | no_control_flow = false; break; |
duke@435 | 983 | case Bytecodes::_i2d : |
duke@435 | 984 | current_frame.pop_stack( |
duke@435 | 985 | VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 986 | current_frame.push_stack_2( |
duke@435 | 987 | VerificationType::double_type(), |
duke@435 | 988 | VerificationType::double2_type(), CHECK_VERIFY(this)); |
duke@435 | 989 | no_control_flow = false; break; |
duke@435 | 990 | case Bytecodes::_l2f : |
duke@435 | 991 | current_frame.pop_stack_2( |
duke@435 | 992 | VerificationType::long2_type(), |
duke@435 | 993 | VerificationType::long_type(), CHECK_VERIFY(this)); |
duke@435 | 994 | current_frame.push_stack( |
duke@435 | 995 | VerificationType::float_type(), CHECK_VERIFY(this)); |
duke@435 | 996 | no_control_flow = false; break; |
duke@435 | 997 | case Bytecodes::_l2d : |
duke@435 | 998 | current_frame.pop_stack_2( |
duke@435 | 999 | VerificationType::long2_type(), |
duke@435 | 1000 | VerificationType::long_type(), CHECK_VERIFY(this)); |
duke@435 | 1001 | current_frame.push_stack_2( |
duke@435 | 1002 | VerificationType::double_type(), |
duke@435 | 1003 | VerificationType::double2_type(), CHECK_VERIFY(this)); |
duke@435 | 1004 | no_control_flow = false; break; |
duke@435 | 1005 | case Bytecodes::_f2i : |
duke@435 | 1006 | current_frame.pop_stack( |
duke@435 | 1007 | VerificationType::float_type(), CHECK_VERIFY(this)); |
duke@435 | 1008 | current_frame.push_stack( |
duke@435 | 1009 | VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 1010 | no_control_flow = false; break; |
duke@435 | 1011 | case Bytecodes::_f2l : |
duke@435 | 1012 | current_frame.pop_stack( |
duke@435 | 1013 | VerificationType::float_type(), CHECK_VERIFY(this)); |
duke@435 | 1014 | current_frame.push_stack_2( |
duke@435 | 1015 | VerificationType::long_type(), |
duke@435 | 1016 | VerificationType::long2_type(), CHECK_VERIFY(this)); |
duke@435 | 1017 | no_control_flow = false; break; |
duke@435 | 1018 | case Bytecodes::_f2d : |
duke@435 | 1019 | current_frame.pop_stack( |
duke@435 | 1020 | VerificationType::float_type(), CHECK_VERIFY(this)); |
duke@435 | 1021 | current_frame.push_stack_2( |
duke@435 | 1022 | VerificationType::double_type(), |
duke@435 | 1023 | VerificationType::double2_type(), CHECK_VERIFY(this)); |
duke@435 | 1024 | no_control_flow = false; break; |
duke@435 | 1025 | case Bytecodes::_d2i : |
duke@435 | 1026 | current_frame.pop_stack_2( |
duke@435 | 1027 | VerificationType::double2_type(), |
duke@435 | 1028 | VerificationType::double_type(), CHECK_VERIFY(this)); |
duke@435 | 1029 | current_frame.push_stack( |
duke@435 | 1030 | VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 1031 | no_control_flow = false; break; |
duke@435 | 1032 | case Bytecodes::_d2l : |
duke@435 | 1033 | current_frame.pop_stack_2( |
duke@435 | 1034 | VerificationType::double2_type(), |
duke@435 | 1035 | VerificationType::double_type(), CHECK_VERIFY(this)); |
duke@435 | 1036 | current_frame.push_stack_2( |
duke@435 | 1037 | VerificationType::long_type(), |
duke@435 | 1038 | VerificationType::long2_type(), CHECK_VERIFY(this)); |
duke@435 | 1039 | no_control_flow = false; break; |
duke@435 | 1040 | case Bytecodes::_d2f : |
duke@435 | 1041 | current_frame.pop_stack_2( |
duke@435 | 1042 | VerificationType::double2_type(), |
duke@435 | 1043 | VerificationType::double_type(), CHECK_VERIFY(this)); |
duke@435 | 1044 | current_frame.push_stack( |
duke@435 | 1045 | VerificationType::float_type(), CHECK_VERIFY(this)); |
duke@435 | 1046 | no_control_flow = false; break; |
duke@435 | 1047 | case Bytecodes::_i2b : |
duke@435 | 1048 | case Bytecodes::_i2c : |
duke@435 | 1049 | case Bytecodes::_i2s : |
duke@435 | 1050 | current_frame.pop_stack( |
duke@435 | 1051 | VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 1052 | current_frame.push_stack( |
duke@435 | 1053 | VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 1054 | no_control_flow = false; break; |
duke@435 | 1055 | case Bytecodes::_lcmp : |
duke@435 | 1056 | current_frame.pop_stack_2( |
duke@435 | 1057 | VerificationType::long2_type(), |
duke@435 | 1058 | VerificationType::long_type(), CHECK_VERIFY(this)); |
duke@435 | 1059 | current_frame.pop_stack_2( |
duke@435 | 1060 | VerificationType::long2_type(), |
duke@435 | 1061 | VerificationType::long_type(), CHECK_VERIFY(this)); |
duke@435 | 1062 | current_frame.push_stack( |
duke@435 | 1063 | VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 1064 | no_control_flow = false; break; |
duke@435 | 1065 | case Bytecodes::_fcmpl : |
duke@435 | 1066 | case Bytecodes::_fcmpg : |
duke@435 | 1067 | current_frame.pop_stack( |
duke@435 | 1068 | VerificationType::float_type(), CHECK_VERIFY(this)); |
duke@435 | 1069 | current_frame.pop_stack( |
duke@435 | 1070 | VerificationType::float_type(), CHECK_VERIFY(this)); |
duke@435 | 1071 | current_frame.push_stack( |
duke@435 | 1072 | VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 1073 | no_control_flow = false; break; |
duke@435 | 1074 | case Bytecodes::_dcmpl : |
duke@435 | 1075 | case Bytecodes::_dcmpg : |
duke@435 | 1076 | current_frame.pop_stack_2( |
duke@435 | 1077 | VerificationType::double2_type(), |
duke@435 | 1078 | VerificationType::double_type(), CHECK_VERIFY(this)); |
duke@435 | 1079 | current_frame.pop_stack_2( |
duke@435 | 1080 | VerificationType::double2_type(), |
duke@435 | 1081 | VerificationType::double_type(), CHECK_VERIFY(this)); |
duke@435 | 1082 | current_frame.push_stack( |
duke@435 | 1083 | VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 1084 | no_control_flow = false; break; |
duke@435 | 1085 | case Bytecodes::_if_icmpeq: |
duke@435 | 1086 | case Bytecodes::_if_icmpne: |
duke@435 | 1087 | case Bytecodes::_if_icmplt: |
duke@435 | 1088 | case Bytecodes::_if_icmpge: |
duke@435 | 1089 | case Bytecodes::_if_icmpgt: |
duke@435 | 1090 | case Bytecodes::_if_icmple: |
duke@435 | 1091 | current_frame.pop_stack( |
duke@435 | 1092 | VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 1093 | // fall through |
duke@435 | 1094 | case Bytecodes::_ifeq: |
duke@435 | 1095 | case Bytecodes::_ifne: |
duke@435 | 1096 | case Bytecodes::_iflt: |
duke@435 | 1097 | case Bytecodes::_ifge: |
duke@435 | 1098 | case Bytecodes::_ifgt: |
duke@435 | 1099 | case Bytecodes::_ifle: |
duke@435 | 1100 | current_frame.pop_stack( |
duke@435 | 1101 | VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 1102 | target = bcs.dest(); |
duke@435 | 1103 | stackmap_table.check_jump_target( |
duke@435 | 1104 | ¤t_frame, target, CHECK_VERIFY(this)); |
duke@435 | 1105 | no_control_flow = false; break; |
duke@435 | 1106 | case Bytecodes::_if_acmpeq : |
duke@435 | 1107 | case Bytecodes::_if_acmpne : |
duke@435 | 1108 | current_frame.pop_stack( |
duke@435 | 1109 | VerificationType::reference_check(), CHECK_VERIFY(this)); |
duke@435 | 1110 | // fall through |
duke@435 | 1111 | case Bytecodes::_ifnull : |
duke@435 | 1112 | case Bytecodes::_ifnonnull : |
duke@435 | 1113 | current_frame.pop_stack( |
duke@435 | 1114 | VerificationType::reference_check(), CHECK_VERIFY(this)); |
duke@435 | 1115 | target = bcs.dest(); |
duke@435 | 1116 | stackmap_table.check_jump_target |
duke@435 | 1117 | (¤t_frame, target, CHECK_VERIFY(this)); |
duke@435 | 1118 | no_control_flow = false; break; |
duke@435 | 1119 | case Bytecodes::_goto : |
duke@435 | 1120 | target = bcs.dest(); |
duke@435 | 1121 | stackmap_table.check_jump_target( |
duke@435 | 1122 | ¤t_frame, target, CHECK_VERIFY(this)); |
duke@435 | 1123 | no_control_flow = true; break; |
duke@435 | 1124 | case Bytecodes::_goto_w : |
duke@435 | 1125 | target = bcs.dest_w(); |
duke@435 | 1126 | stackmap_table.check_jump_target( |
duke@435 | 1127 | ¤t_frame, target, CHECK_VERIFY(this)); |
duke@435 | 1128 | no_control_flow = true; break; |
duke@435 | 1129 | case Bytecodes::_tableswitch : |
duke@435 | 1130 | case Bytecodes::_lookupswitch : |
duke@435 | 1131 | verify_switch( |
duke@435 | 1132 | &bcs, code_length, code_data, ¤t_frame, |
duke@435 | 1133 | &stackmap_table, CHECK_VERIFY(this)); |
duke@435 | 1134 | no_control_flow = true; break; |
duke@435 | 1135 | case Bytecodes::_ireturn : |
duke@435 | 1136 | type = current_frame.pop_stack( |
duke@435 | 1137 | VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 1138 | verify_return_value(return_type, type, bci, CHECK_VERIFY(this)); |
duke@435 | 1139 | no_control_flow = true; break; |
duke@435 | 1140 | case Bytecodes::_lreturn : |
duke@435 | 1141 | type2 = current_frame.pop_stack( |
duke@435 | 1142 | VerificationType::long2_type(), CHECK_VERIFY(this)); |
duke@435 | 1143 | type = current_frame.pop_stack( |
duke@435 | 1144 | VerificationType::long_type(), CHECK_VERIFY(this)); |
duke@435 | 1145 | verify_return_value(return_type, type, bci, CHECK_VERIFY(this)); |
duke@435 | 1146 | no_control_flow = true; break; |
duke@435 | 1147 | case Bytecodes::_freturn : |
duke@435 | 1148 | type = current_frame.pop_stack( |
duke@435 | 1149 | VerificationType::float_type(), CHECK_VERIFY(this)); |
duke@435 | 1150 | verify_return_value(return_type, type, bci, CHECK_VERIFY(this)); |
duke@435 | 1151 | no_control_flow = true; break; |
duke@435 | 1152 | case Bytecodes::_dreturn : |
duke@435 | 1153 | type2 = current_frame.pop_stack( |
duke@435 | 1154 | VerificationType::double2_type(), CHECK_VERIFY(this)); |
duke@435 | 1155 | type = current_frame.pop_stack( |
duke@435 | 1156 | VerificationType::double_type(), CHECK_VERIFY(this)); |
duke@435 | 1157 | verify_return_value(return_type, type, bci, CHECK_VERIFY(this)); |
duke@435 | 1158 | no_control_flow = true; break; |
duke@435 | 1159 | case Bytecodes::_areturn : |
duke@435 | 1160 | type = current_frame.pop_stack( |
duke@435 | 1161 | VerificationType::reference_check(), CHECK_VERIFY(this)); |
duke@435 | 1162 | verify_return_value(return_type, type, bci, CHECK_VERIFY(this)); |
duke@435 | 1163 | no_control_flow = true; break; |
duke@435 | 1164 | case Bytecodes::_return : |
duke@435 | 1165 | if (return_type != VerificationType::bogus_type()) { |
duke@435 | 1166 | verify_error(bci, "Method expects no return value"); |
duke@435 | 1167 | return; |
duke@435 | 1168 | } |
duke@435 | 1169 | // Make sure "this" has been initialized if current method is an |
duke@435 | 1170 | // <init> |
duke@435 | 1171 | if (_method->name() == vmSymbols::object_initializer_name() && |
duke@435 | 1172 | current_frame.flag_this_uninit()) { |
duke@435 | 1173 | verify_error(bci, |
duke@435 | 1174 | "Constructor must call super() or this() before return"); |
duke@435 | 1175 | return; |
duke@435 | 1176 | } |
duke@435 | 1177 | no_control_flow = true; break; |
duke@435 | 1178 | case Bytecodes::_getstatic : |
duke@435 | 1179 | case Bytecodes::_putstatic : |
duke@435 | 1180 | case Bytecodes::_getfield : |
duke@435 | 1181 | case Bytecodes::_putfield : |
duke@435 | 1182 | verify_field_instructions( |
duke@435 | 1183 | &bcs, ¤t_frame, cp, CHECK_VERIFY(this)); |
duke@435 | 1184 | no_control_flow = false; break; |
duke@435 | 1185 | case Bytecodes::_invokevirtual : |
duke@435 | 1186 | case Bytecodes::_invokespecial : |
duke@435 | 1187 | case Bytecodes::_invokestatic : |
duke@435 | 1188 | verify_invoke_instructions( |
duke@435 | 1189 | &bcs, code_length, ¤t_frame, |
duke@435 | 1190 | &this_uninit, return_type, cp, CHECK_VERIFY(this)); |
duke@435 | 1191 | no_control_flow = false; break; |
duke@435 | 1192 | case Bytecodes::_invokeinterface : |
jrose@1161 | 1193 | case Bytecodes::_invokedynamic : |
duke@435 | 1194 | verify_invoke_instructions( |
duke@435 | 1195 | &bcs, code_length, ¤t_frame, |
duke@435 | 1196 | &this_uninit, return_type, cp, CHECK_VERIFY(this)); |
duke@435 | 1197 | no_control_flow = false; break; |
duke@435 | 1198 | case Bytecodes::_new : |
duke@435 | 1199 | { |
jrose@1920 | 1200 | index = bcs.get_index_u2(); |
duke@435 | 1201 | verify_cp_class_type(index, cp, CHECK_VERIFY(this)); |
duke@435 | 1202 | VerificationType new_class_type = |
duke@435 | 1203 | cp_index_to_type(index, cp, CHECK_VERIFY(this)); |
duke@435 | 1204 | if (!new_class_type.is_object()) { |
duke@435 | 1205 | verify_error(bci, "Illegal new instruction"); |
duke@435 | 1206 | return; |
duke@435 | 1207 | } |
duke@435 | 1208 | type = VerificationType::uninitialized_type(bci); |
duke@435 | 1209 | current_frame.push_stack(type, CHECK_VERIFY(this)); |
duke@435 | 1210 | no_control_flow = false; break; |
duke@435 | 1211 | } |
duke@435 | 1212 | case Bytecodes::_newarray : |
duke@435 | 1213 | type = get_newarray_type(bcs.get_index(), bci, CHECK_VERIFY(this)); |
duke@435 | 1214 | current_frame.pop_stack( |
duke@435 | 1215 | VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 1216 | current_frame.push_stack(type, CHECK_VERIFY(this)); |
duke@435 | 1217 | no_control_flow = false; break; |
duke@435 | 1218 | case Bytecodes::_anewarray : |
duke@435 | 1219 | verify_anewarray( |
jrose@1920 | 1220 | bcs.get_index_u2(), cp, ¤t_frame, CHECK_VERIFY(this)); |
duke@435 | 1221 | no_control_flow = false; break; |
duke@435 | 1222 | case Bytecodes::_arraylength : |
duke@435 | 1223 | type = current_frame.pop_stack( |
duke@435 | 1224 | VerificationType::reference_check(), CHECK_VERIFY(this)); |
kamg@569 | 1225 | if (!(type.is_null() || type.is_array())) { |
duke@435 | 1226 | verify_error(bci, bad_type_msg, "arraylength"); |
duke@435 | 1227 | } |
duke@435 | 1228 | current_frame.push_stack( |
duke@435 | 1229 | VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 1230 | no_control_flow = false; break; |
duke@435 | 1231 | case Bytecodes::_checkcast : |
duke@435 | 1232 | { |
jrose@1920 | 1233 | index = bcs.get_index_u2(); |
duke@435 | 1234 | verify_cp_class_type(index, cp, CHECK_VERIFY(this)); |
duke@435 | 1235 | current_frame.pop_stack( |
duke@435 | 1236 | VerificationType::reference_check(), CHECK_VERIFY(this)); |
duke@435 | 1237 | VerificationType klass_type = cp_index_to_type( |
duke@435 | 1238 | index, cp, CHECK_VERIFY(this)); |
duke@435 | 1239 | current_frame.push_stack(klass_type, CHECK_VERIFY(this)); |
duke@435 | 1240 | no_control_flow = false; break; |
duke@435 | 1241 | } |
duke@435 | 1242 | case Bytecodes::_instanceof : { |
jrose@1920 | 1243 | index = bcs.get_index_u2(); |
duke@435 | 1244 | verify_cp_class_type(index, cp, CHECK_VERIFY(this)); |
duke@435 | 1245 | current_frame.pop_stack( |
duke@435 | 1246 | VerificationType::reference_check(), CHECK_VERIFY(this)); |
duke@435 | 1247 | current_frame.push_stack( |
duke@435 | 1248 | VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 1249 | no_control_flow = false; break; |
duke@435 | 1250 | } |
duke@435 | 1251 | case Bytecodes::_monitorenter : |
duke@435 | 1252 | case Bytecodes::_monitorexit : |
duke@435 | 1253 | current_frame.pop_stack( |
duke@435 | 1254 | VerificationType::reference_check(), CHECK_VERIFY(this)); |
duke@435 | 1255 | no_control_flow = false; break; |
duke@435 | 1256 | case Bytecodes::_multianewarray : |
duke@435 | 1257 | { |
jrose@1920 | 1258 | index = bcs.get_index_u2(); |
duke@435 | 1259 | u2 dim = *(bcs.bcp()+3); |
duke@435 | 1260 | verify_cp_class_type(index, cp, CHECK_VERIFY(this)); |
duke@435 | 1261 | VerificationType new_array_type = |
duke@435 | 1262 | cp_index_to_type(index, cp, CHECK_VERIFY(this)); |
duke@435 | 1263 | if (!new_array_type.is_array()) { |
duke@435 | 1264 | verify_error(bci, |
duke@435 | 1265 | "Illegal constant pool index in multianewarray instruction"); |
duke@435 | 1266 | return; |
duke@435 | 1267 | } |
duke@435 | 1268 | if (dim < 1 || new_array_type.dimensions() < dim) { |
duke@435 | 1269 | verify_error(bci, |
duke@435 | 1270 | "Illegal dimension in multianewarray instruction"); |
duke@435 | 1271 | return; |
duke@435 | 1272 | } |
duke@435 | 1273 | for (int i = 0; i < dim; i++) { |
duke@435 | 1274 | current_frame.pop_stack( |
duke@435 | 1275 | VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 1276 | } |
duke@435 | 1277 | current_frame.push_stack(new_array_type, CHECK_VERIFY(this)); |
duke@435 | 1278 | no_control_flow = false; break; |
duke@435 | 1279 | } |
duke@435 | 1280 | case Bytecodes::_athrow : |
duke@435 | 1281 | type = VerificationType::reference_type( |
duke@435 | 1282 | vmSymbols::java_lang_Throwable()); |
duke@435 | 1283 | current_frame.pop_stack(type, CHECK_VERIFY(this)); |
duke@435 | 1284 | no_control_flow = true; break; |
duke@435 | 1285 | default: |
duke@435 | 1286 | // We only need to check the valid bytecodes in class file. |
duke@435 | 1287 | // And jsr and ret are not in the new class file format in JDK1.5. |
duke@435 | 1288 | verify_error(bci, "Bad instruction"); |
duke@435 | 1289 | no_control_flow = false; |
duke@435 | 1290 | return; |
duke@435 | 1291 | } // end switch |
duke@435 | 1292 | } // end Merge with the next instruction |
duke@435 | 1293 | |
duke@435 | 1294 | // Look for possible jump target in exception handlers and see if it |
duke@435 | 1295 | // matches current_frame |
duke@435 | 1296 | if (bci >= ex_min && bci < ex_max) { |
duke@435 | 1297 | verify_exception_handler_targets( |
duke@435 | 1298 | bci, this_uninit, ¤t_frame, &stackmap_table, CHECK_VERIFY(this)); |
duke@435 | 1299 | } |
duke@435 | 1300 | } // end while |
duke@435 | 1301 | |
duke@435 | 1302 | // Make sure that control flow does not fall through end of the method |
duke@435 | 1303 | if (!no_control_flow) { |
duke@435 | 1304 | verify_error(code_length, "Control flow falls through code end"); |
duke@435 | 1305 | return; |
duke@435 | 1306 | } |
duke@435 | 1307 | } |
duke@435 | 1308 | |
duke@435 | 1309 | char* ClassVerifier::generate_code_data(methodHandle m, u4 code_length, TRAPS) { |
duke@435 | 1310 | char* code_data = NEW_RESOURCE_ARRAY(char, code_length); |
duke@435 | 1311 | memset(code_data, 0, sizeof(char) * code_length); |
duke@435 | 1312 | RawBytecodeStream bcs(m); |
duke@435 | 1313 | |
duke@435 | 1314 | while (!bcs.is_last_bytecode()) { |
duke@435 | 1315 | if (bcs.raw_next() != Bytecodes::_illegal) { |
duke@435 | 1316 | int bci = bcs.bci(); |
jrose@1920 | 1317 | if (bcs.raw_code() == Bytecodes::_new) { |
duke@435 | 1318 | code_data[bci] = NEW_OFFSET; |
duke@435 | 1319 | } else { |
duke@435 | 1320 | code_data[bci] = BYTECODE_OFFSET; |
duke@435 | 1321 | } |
duke@435 | 1322 | } else { |
duke@435 | 1323 | verify_error(bcs.bci(), "Bad instruction"); |
duke@435 | 1324 | return NULL; |
duke@435 | 1325 | } |
duke@435 | 1326 | } |
duke@435 | 1327 | |
duke@435 | 1328 | return code_data; |
duke@435 | 1329 | } |
duke@435 | 1330 | |
duke@435 | 1331 | void ClassVerifier::verify_exception_handler_table(u4 code_length, char* code_data, int& min, int& max, TRAPS) { |
duke@435 | 1332 | typeArrayHandle exhandlers (THREAD, _method->exception_table()); |
duke@435 | 1333 | constantPoolHandle cp (THREAD, _method->constants()); |
duke@435 | 1334 | |
duke@435 | 1335 | if (exhandlers() != NULL) { |
duke@435 | 1336 | for(int i = 0; i < exhandlers->length();) { |
duke@435 | 1337 | u2 start_pc = exhandlers->int_at(i++); |
duke@435 | 1338 | u2 end_pc = exhandlers->int_at(i++); |
duke@435 | 1339 | u2 handler_pc = exhandlers->int_at(i++); |
duke@435 | 1340 | if (start_pc >= code_length || code_data[start_pc] == 0) { |
duke@435 | 1341 | class_format_error("Illegal exception table start_pc %d", start_pc); |
duke@435 | 1342 | return; |
duke@435 | 1343 | } |
duke@435 | 1344 | if (end_pc != code_length) { // special case: end_pc == code_length |
duke@435 | 1345 | if (end_pc > code_length || code_data[end_pc] == 0) { |
duke@435 | 1346 | class_format_error("Illegal exception table end_pc %d", end_pc); |
duke@435 | 1347 | return; |
duke@435 | 1348 | } |
duke@435 | 1349 | } |
duke@435 | 1350 | if (handler_pc >= code_length || code_data[handler_pc] == 0) { |
duke@435 | 1351 | class_format_error("Illegal exception table handler_pc %d", handler_pc); |
duke@435 | 1352 | return; |
duke@435 | 1353 | } |
duke@435 | 1354 | int catch_type_index = exhandlers->int_at(i++); |
duke@435 | 1355 | if (catch_type_index != 0) { |
duke@435 | 1356 | VerificationType catch_type = cp_index_to_type( |
duke@435 | 1357 | catch_type_index, cp, CHECK_VERIFY(this)); |
duke@435 | 1358 | VerificationType throwable = |
duke@435 | 1359 | VerificationType::reference_type(vmSymbols::java_lang_Throwable()); |
duke@435 | 1360 | bool is_subclass = throwable.is_assignable_from( |
duke@435 | 1361 | catch_type, current_class(), CHECK_VERIFY(this)); |
duke@435 | 1362 | if (!is_subclass) { |
duke@435 | 1363 | // 4286534: should throw VerifyError according to recent spec change |
duke@435 | 1364 | verify_error( |
duke@435 | 1365 | "Catch type is not a subclass of Throwable in handler %d", |
duke@435 | 1366 | handler_pc); |
duke@435 | 1367 | return; |
duke@435 | 1368 | } |
duke@435 | 1369 | } |
duke@435 | 1370 | if (start_pc < min) min = start_pc; |
duke@435 | 1371 | if (end_pc > max) max = end_pc; |
duke@435 | 1372 | } |
duke@435 | 1373 | } |
duke@435 | 1374 | } |
duke@435 | 1375 | |
duke@435 | 1376 | void ClassVerifier::verify_local_variable_table(u4 code_length, char* code_data, TRAPS) { |
duke@435 | 1377 | int localvariable_table_length = _method()->localvariable_table_length(); |
duke@435 | 1378 | if (localvariable_table_length > 0) { |
duke@435 | 1379 | LocalVariableTableElement* table = _method()->localvariable_table_start(); |
duke@435 | 1380 | for (int i = 0; i < localvariable_table_length; i++) { |
duke@435 | 1381 | u2 start_bci = table[i].start_bci; |
duke@435 | 1382 | u2 length = table[i].length; |
duke@435 | 1383 | |
duke@435 | 1384 | if (start_bci >= code_length || code_data[start_bci] == 0) { |
duke@435 | 1385 | class_format_error( |
duke@435 | 1386 | "Illegal local variable table start_pc %d", start_bci); |
duke@435 | 1387 | return; |
duke@435 | 1388 | } |
duke@435 | 1389 | u4 end_bci = (u4)(start_bci + length); |
duke@435 | 1390 | if (end_bci != code_length) { |
duke@435 | 1391 | if (end_bci >= code_length || code_data[end_bci] == 0) { |
duke@435 | 1392 | class_format_error( "Illegal local variable table length %d", length); |
duke@435 | 1393 | return; |
duke@435 | 1394 | } |
duke@435 | 1395 | } |
duke@435 | 1396 | } |
duke@435 | 1397 | } |
duke@435 | 1398 | } |
duke@435 | 1399 | |
duke@435 | 1400 | u2 ClassVerifier::verify_stackmap_table(u2 stackmap_index, u2 bci, |
duke@435 | 1401 | StackMapFrame* current_frame, |
duke@435 | 1402 | StackMapTable* stackmap_table, |
duke@435 | 1403 | bool no_control_flow, TRAPS) { |
duke@435 | 1404 | if (stackmap_index < stackmap_table->get_frame_count()) { |
duke@435 | 1405 | u2 this_offset = stackmap_table->get_offset(stackmap_index); |
duke@435 | 1406 | if (no_control_flow && this_offset > bci) { |
duke@435 | 1407 | verify_error(bci, "Expecting a stack map frame"); |
duke@435 | 1408 | return 0; |
duke@435 | 1409 | } |
duke@435 | 1410 | if (this_offset == bci) { |
duke@435 | 1411 | // See if current stack map can be assigned to the frame in table. |
duke@435 | 1412 | // current_frame is the stackmap frame got from the last instruction. |
duke@435 | 1413 | // If matched, current_frame will be updated by this method. |
duke@435 | 1414 | bool match = stackmap_table->match_stackmap( |
duke@435 | 1415 | current_frame, this_offset, stackmap_index, |
duke@435 | 1416 | !no_control_flow, true, CHECK_VERIFY_(this, 0)); |
duke@435 | 1417 | if (!match) { |
duke@435 | 1418 | // report type error |
duke@435 | 1419 | verify_error(bci, "Instruction type does not match stack map"); |
duke@435 | 1420 | return 0; |
duke@435 | 1421 | } |
duke@435 | 1422 | stackmap_index++; |
duke@435 | 1423 | } else if (this_offset < bci) { |
duke@435 | 1424 | // current_offset should have met this_offset. |
duke@435 | 1425 | class_format_error("Bad stack map offset %d", this_offset); |
duke@435 | 1426 | return 0; |
duke@435 | 1427 | } |
duke@435 | 1428 | } else if (no_control_flow) { |
duke@435 | 1429 | verify_error(bci, "Expecting a stack map frame"); |
duke@435 | 1430 | return 0; |
duke@435 | 1431 | } |
duke@435 | 1432 | return stackmap_index; |
duke@435 | 1433 | } |
duke@435 | 1434 | |
duke@435 | 1435 | void ClassVerifier::verify_exception_handler_targets(u2 bci, bool this_uninit, StackMapFrame* current_frame, |
duke@435 | 1436 | StackMapTable* stackmap_table, TRAPS) { |
duke@435 | 1437 | constantPoolHandle cp (THREAD, _method->constants()); |
duke@435 | 1438 | typeArrayHandle exhandlers (THREAD, _method->exception_table()); |
duke@435 | 1439 | if (exhandlers() != NULL) { |
duke@435 | 1440 | for(int i = 0; i < exhandlers->length();) { |
duke@435 | 1441 | u2 start_pc = exhandlers->int_at(i++); |
duke@435 | 1442 | u2 end_pc = exhandlers->int_at(i++); |
duke@435 | 1443 | u2 handler_pc = exhandlers->int_at(i++); |
duke@435 | 1444 | int catch_type_index = exhandlers->int_at(i++); |
duke@435 | 1445 | if(bci >= start_pc && bci < end_pc) { |
duke@435 | 1446 | u1 flags = current_frame->flags(); |
duke@435 | 1447 | if (this_uninit) { flags |= FLAG_THIS_UNINIT; } |
duke@435 | 1448 | |
duke@435 | 1449 | ResourceMark rm(THREAD); |
duke@435 | 1450 | StackMapFrame* new_frame = current_frame->frame_in_exception_handler(flags); |
duke@435 | 1451 | if (catch_type_index != 0) { |
duke@435 | 1452 | // We know that this index refers to a subclass of Throwable |
duke@435 | 1453 | VerificationType catch_type = cp_index_to_type( |
duke@435 | 1454 | catch_type_index, cp, CHECK_VERIFY(this)); |
duke@435 | 1455 | new_frame->push_stack(catch_type, CHECK_VERIFY(this)); |
duke@435 | 1456 | } else { |
duke@435 | 1457 | VerificationType throwable = |
duke@435 | 1458 | VerificationType::reference_type(vmSymbols::java_lang_Throwable()); |
duke@435 | 1459 | new_frame->push_stack(throwable, CHECK_VERIFY(this)); |
duke@435 | 1460 | } |
duke@435 | 1461 | bool match = stackmap_table->match_stackmap( |
duke@435 | 1462 | new_frame, handler_pc, true, false, CHECK_VERIFY(this)); |
duke@435 | 1463 | if (!match) { |
duke@435 | 1464 | verify_error(bci, |
duke@435 | 1465 | "Stack map does not match the one at exception handler %d", |
duke@435 | 1466 | handler_pc); |
duke@435 | 1467 | return; |
duke@435 | 1468 | } |
duke@435 | 1469 | } |
duke@435 | 1470 | } |
duke@435 | 1471 | } |
duke@435 | 1472 | } |
duke@435 | 1473 | |
duke@435 | 1474 | void ClassVerifier::verify_cp_index(constantPoolHandle cp, int index, TRAPS) { |
duke@435 | 1475 | int nconstants = cp->length(); |
duke@435 | 1476 | if ((index <= 0) || (index >= nconstants)) { |
duke@435 | 1477 | verify_error("Illegal constant pool index %d in class %s", |
duke@435 | 1478 | index, instanceKlass::cast(cp->pool_holder())->external_name()); |
duke@435 | 1479 | return; |
duke@435 | 1480 | } |
duke@435 | 1481 | } |
duke@435 | 1482 | |
duke@435 | 1483 | void ClassVerifier::verify_cp_type( |
duke@435 | 1484 | int index, constantPoolHandle cp, unsigned int types, TRAPS) { |
duke@435 | 1485 | |
duke@435 | 1486 | // In some situations, bytecode rewriting may occur while we're verifying. |
duke@435 | 1487 | // In this case, a constant pool cache exists and some indices refer to that |
jrose@1925 | 1488 | // instead. Be sure we don't pick up such indices by accident. |
jrose@1925 | 1489 | // We must check was_recursively_verified() before we get here. |
jrose@1925 | 1490 | guarantee(cp->cache() == NULL, "not rewritten yet"); |
duke@435 | 1491 | |
duke@435 | 1492 | verify_cp_index(cp, index, CHECK_VERIFY(this)); |
duke@435 | 1493 | unsigned int tag = cp->tag_at(index).value(); |
duke@435 | 1494 | if ((types & (1 << tag)) == 0) { |
duke@435 | 1495 | verify_error( |
duke@435 | 1496 | "Illegal type at constant pool entry %d in class %s", |
duke@435 | 1497 | index, instanceKlass::cast(cp->pool_holder())->external_name()); |
duke@435 | 1498 | return; |
duke@435 | 1499 | } |
duke@435 | 1500 | } |
duke@435 | 1501 | |
duke@435 | 1502 | void ClassVerifier::verify_cp_class_type( |
duke@435 | 1503 | int index, constantPoolHandle cp, TRAPS) { |
duke@435 | 1504 | verify_cp_index(cp, index, CHECK_VERIFY(this)); |
duke@435 | 1505 | constantTag tag = cp->tag_at(index); |
duke@435 | 1506 | if (!tag.is_klass() && !tag.is_unresolved_klass()) { |
duke@435 | 1507 | verify_error("Illegal type at constant pool entry %d in class %s", |
duke@435 | 1508 | index, instanceKlass::cast(cp->pool_holder())->external_name()); |
duke@435 | 1509 | return; |
duke@435 | 1510 | } |
duke@435 | 1511 | } |
duke@435 | 1512 | |
duke@435 | 1513 | void ClassVerifier::format_error_message( |
duke@435 | 1514 | const char* fmt, int offset, va_list va) { |
duke@435 | 1515 | ResourceMark rm(_thread); |
duke@435 | 1516 | stringStream message(_message, _message_buffer_len); |
duke@435 | 1517 | message.vprint(fmt, va); |
duke@435 | 1518 | if (!_method.is_null()) { |
duke@435 | 1519 | message.print(" in method %s", _method->name_and_sig_as_C_string()); |
duke@435 | 1520 | } |
duke@435 | 1521 | if (offset != -1) { |
duke@435 | 1522 | message.print(" at offset %d", offset); |
duke@435 | 1523 | } |
duke@435 | 1524 | } |
duke@435 | 1525 | |
duke@435 | 1526 | void ClassVerifier::verify_error(u2 offset, const char* fmt, ...) { |
duke@435 | 1527 | _exception_type = vmSymbols::java_lang_VerifyError(); |
duke@435 | 1528 | va_list va; |
duke@435 | 1529 | va_start(va, fmt); |
duke@435 | 1530 | format_error_message(fmt, offset, va); |
duke@435 | 1531 | va_end(va); |
duke@435 | 1532 | } |
duke@435 | 1533 | |
duke@435 | 1534 | void ClassVerifier::verify_error(const char* fmt, ...) { |
duke@435 | 1535 | _exception_type = vmSymbols::java_lang_VerifyError(); |
duke@435 | 1536 | va_list va; |
duke@435 | 1537 | va_start(va, fmt); |
duke@435 | 1538 | format_error_message(fmt, -1, va); |
duke@435 | 1539 | va_end(va); |
duke@435 | 1540 | } |
duke@435 | 1541 | |
duke@435 | 1542 | void ClassVerifier::class_format_error(const char* msg, ...) { |
duke@435 | 1543 | _exception_type = vmSymbols::java_lang_ClassFormatError(); |
duke@435 | 1544 | va_list va; |
duke@435 | 1545 | va_start(va, msg); |
duke@435 | 1546 | format_error_message(msg, -1, va); |
duke@435 | 1547 | va_end(va); |
duke@435 | 1548 | } |
duke@435 | 1549 | |
duke@435 | 1550 | klassOop ClassVerifier::load_class(symbolHandle name, TRAPS) { |
duke@435 | 1551 | // Get current loader and protection domain first. |
duke@435 | 1552 | oop loader = current_class()->class_loader(); |
duke@435 | 1553 | oop protection_domain = current_class()->protection_domain(); |
duke@435 | 1554 | |
duke@435 | 1555 | return SystemDictionary::resolve_or_fail( |
duke@435 | 1556 | name, Handle(THREAD, loader), Handle(THREAD, protection_domain), |
duke@435 | 1557 | true, CHECK_NULL); |
duke@435 | 1558 | } |
duke@435 | 1559 | |
duke@435 | 1560 | bool ClassVerifier::is_protected_access(instanceKlassHandle this_class, |
duke@435 | 1561 | klassOop target_class, |
duke@435 | 1562 | symbolOop field_name, |
duke@435 | 1563 | symbolOop field_sig, |
duke@435 | 1564 | bool is_method) { |
duke@435 | 1565 | No_Safepoint_Verifier nosafepoint; |
duke@435 | 1566 | |
duke@435 | 1567 | // If target class isn't a super class of this class, we don't worry about this case |
duke@435 | 1568 | if (!this_class->is_subclass_of(target_class)) { |
duke@435 | 1569 | return false; |
duke@435 | 1570 | } |
duke@435 | 1571 | // Check if the specified method or field is protected |
duke@435 | 1572 | instanceKlass* target_instance = instanceKlass::cast(target_class); |
duke@435 | 1573 | fieldDescriptor fd; |
duke@435 | 1574 | if (is_method) { |
duke@435 | 1575 | methodOop m = target_instance->uncached_lookup_method(field_name, field_sig); |
duke@435 | 1576 | if (m != NULL && m->is_protected()) { |
duke@435 | 1577 | if (!this_class->is_same_class_package(m->method_holder())) { |
duke@435 | 1578 | return true; |
duke@435 | 1579 | } |
duke@435 | 1580 | } |
duke@435 | 1581 | } else { |
duke@435 | 1582 | klassOop member_klass = target_instance->find_field(field_name, field_sig, &fd); |
duke@435 | 1583 | if(member_klass != NULL && fd.is_protected()) { |
duke@435 | 1584 | if (!this_class->is_same_class_package(member_klass)) { |
duke@435 | 1585 | return true; |
duke@435 | 1586 | } |
duke@435 | 1587 | } |
duke@435 | 1588 | } |
duke@435 | 1589 | return false; |
duke@435 | 1590 | } |
duke@435 | 1591 | |
duke@435 | 1592 | void ClassVerifier::verify_ldc( |
duke@435 | 1593 | int opcode, u2 index, StackMapFrame *current_frame, |
duke@435 | 1594 | constantPoolHandle cp, u2 bci, TRAPS) { |
duke@435 | 1595 | verify_cp_index(cp, index, CHECK_VERIFY(this)); |
duke@435 | 1596 | constantTag tag = cp->tag_at(index); |
duke@435 | 1597 | unsigned int types; |
duke@435 | 1598 | if (opcode == Bytecodes::_ldc || opcode == Bytecodes::_ldc_w) { |
duke@435 | 1599 | if (!tag.is_unresolved_string() && !tag.is_unresolved_klass()) { |
duke@435 | 1600 | types = (1 << JVM_CONSTANT_Integer) | (1 << JVM_CONSTANT_Float) |
duke@435 | 1601 | | (1 << JVM_CONSTANT_String) | (1 << JVM_CONSTANT_Class); |
duke@435 | 1602 | verify_cp_type(index, cp, types, CHECK_VERIFY(this)); |
duke@435 | 1603 | } |
duke@435 | 1604 | } else { |
duke@435 | 1605 | assert(opcode == Bytecodes::_ldc2_w, "must be ldc2_w"); |
duke@435 | 1606 | types = (1 << JVM_CONSTANT_Double) | (1 << JVM_CONSTANT_Long); |
duke@435 | 1607 | verify_cp_type(index, cp, types, CHECK_VERIFY(this)); |
duke@435 | 1608 | } |
jrose@866 | 1609 | if (tag.is_string() && cp->is_pseudo_string_at(index)) { |
jrose@866 | 1610 | current_frame->push_stack( |
jrose@866 | 1611 | VerificationType::reference_type( |
jrose@866 | 1612 | vmSymbols::java_lang_Object()), CHECK_VERIFY(this)); |
jrose@866 | 1613 | } else if (tag.is_string() || tag.is_unresolved_string()) { |
duke@435 | 1614 | current_frame->push_stack( |
duke@435 | 1615 | VerificationType::reference_type( |
duke@435 | 1616 | vmSymbols::java_lang_String()), CHECK_VERIFY(this)); |
duke@435 | 1617 | } else if (tag.is_klass() || tag.is_unresolved_klass()) { |
duke@435 | 1618 | current_frame->push_stack( |
duke@435 | 1619 | VerificationType::reference_type( |
duke@435 | 1620 | vmSymbols::java_lang_Class()), CHECK_VERIFY(this)); |
duke@435 | 1621 | } else if (tag.is_int()) { |
duke@435 | 1622 | current_frame->push_stack( |
duke@435 | 1623 | VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 1624 | } else if (tag.is_float()) { |
duke@435 | 1625 | current_frame->push_stack( |
duke@435 | 1626 | VerificationType::float_type(), CHECK_VERIFY(this)); |
duke@435 | 1627 | } else if (tag.is_double()) { |
duke@435 | 1628 | current_frame->push_stack_2( |
duke@435 | 1629 | VerificationType::double_type(), |
duke@435 | 1630 | VerificationType::double2_type(), CHECK_VERIFY(this)); |
duke@435 | 1631 | } else if (tag.is_long()) { |
duke@435 | 1632 | current_frame->push_stack_2( |
duke@435 | 1633 | VerificationType::long_type(), |
duke@435 | 1634 | VerificationType::long2_type(), CHECK_VERIFY(this)); |
duke@435 | 1635 | } else { |
duke@435 | 1636 | verify_error(bci, "Invalid index in ldc"); |
duke@435 | 1637 | return; |
duke@435 | 1638 | } |
duke@435 | 1639 | } |
duke@435 | 1640 | |
duke@435 | 1641 | void ClassVerifier::verify_switch( |
duke@435 | 1642 | RawBytecodeStream* bcs, u4 code_length, char* code_data, |
duke@435 | 1643 | StackMapFrame* current_frame, StackMapTable* stackmap_table, TRAPS) { |
duke@435 | 1644 | int bci = bcs->bci(); |
duke@435 | 1645 | address bcp = bcs->bcp(); |
duke@435 | 1646 | address aligned_bcp = (address) round_to((intptr_t)(bcp + 1), jintSize); |
duke@435 | 1647 | |
duke@435 | 1648 | // 4639449 & 4647081: padding bytes must be 0 |
duke@435 | 1649 | u2 padding_offset = 1; |
duke@435 | 1650 | while ((bcp + padding_offset) < aligned_bcp) { |
duke@435 | 1651 | if(*(bcp + padding_offset) != 0) { |
duke@435 | 1652 | verify_error(bci, "Nonzero padding byte in lookswitch or tableswitch"); |
duke@435 | 1653 | return; |
duke@435 | 1654 | } |
duke@435 | 1655 | padding_offset++; |
duke@435 | 1656 | } |
duke@435 | 1657 | int default_offset = (int) Bytes::get_Java_u4(aligned_bcp); |
duke@435 | 1658 | int keys, delta; |
duke@435 | 1659 | current_frame->pop_stack( |
duke@435 | 1660 | VerificationType::integer_type(), CHECK_VERIFY(this)); |
jrose@1920 | 1661 | if (bcs->raw_code() == Bytecodes::_tableswitch) { |
duke@435 | 1662 | jint low = (jint)Bytes::get_Java_u4(aligned_bcp + jintSize); |
duke@435 | 1663 | jint high = (jint)Bytes::get_Java_u4(aligned_bcp + 2*jintSize); |
duke@435 | 1664 | if (low > high) { |
duke@435 | 1665 | verify_error(bci, |
duke@435 | 1666 | "low must be less than or equal to high in tableswitch"); |
duke@435 | 1667 | return; |
duke@435 | 1668 | } |
duke@435 | 1669 | keys = high - low + 1; |
duke@435 | 1670 | if (keys < 0) { |
duke@435 | 1671 | verify_error(bci, "too many keys in tableswitch"); |
duke@435 | 1672 | return; |
duke@435 | 1673 | } |
duke@435 | 1674 | delta = 1; |
duke@435 | 1675 | } else { |
duke@435 | 1676 | keys = (int)Bytes::get_Java_u4(aligned_bcp + jintSize); |
duke@435 | 1677 | if (keys < 0) { |
duke@435 | 1678 | verify_error(bci, "number of keys in lookupswitch less than 0"); |
duke@435 | 1679 | return; |
duke@435 | 1680 | } |
duke@435 | 1681 | delta = 2; |
duke@435 | 1682 | // Make sure that the lookupswitch items are sorted |
duke@435 | 1683 | for (int i = 0; i < (keys - 1); i++) { |
duke@435 | 1684 | jint this_key = Bytes::get_Java_u4(aligned_bcp + (2+2*i)*jintSize); |
duke@435 | 1685 | jint next_key = Bytes::get_Java_u4(aligned_bcp + (2+2*i+2)*jintSize); |
duke@435 | 1686 | if (this_key >= next_key) { |
duke@435 | 1687 | verify_error(bci, "Bad lookupswitch instruction"); |
duke@435 | 1688 | return; |
duke@435 | 1689 | } |
duke@435 | 1690 | } |
duke@435 | 1691 | } |
duke@435 | 1692 | int target = bci + default_offset; |
duke@435 | 1693 | stackmap_table->check_jump_target(current_frame, target, CHECK_VERIFY(this)); |
duke@435 | 1694 | for (int i = 0; i < keys; i++) { |
duke@435 | 1695 | target = bci + (jint)Bytes::get_Java_u4(aligned_bcp+(3+i*delta)*jintSize); |
duke@435 | 1696 | stackmap_table->check_jump_target( |
duke@435 | 1697 | current_frame, target, CHECK_VERIFY(this)); |
duke@435 | 1698 | } |
duke@435 | 1699 | } |
duke@435 | 1700 | |
duke@435 | 1701 | bool ClassVerifier::name_in_supers( |
duke@435 | 1702 | symbolOop ref_name, instanceKlassHandle current) { |
duke@435 | 1703 | klassOop super = current->super(); |
duke@435 | 1704 | while (super != NULL) { |
duke@435 | 1705 | if (super->klass_part()->name() == ref_name) { |
duke@435 | 1706 | return true; |
duke@435 | 1707 | } |
duke@435 | 1708 | super = super->klass_part()->super(); |
duke@435 | 1709 | } |
duke@435 | 1710 | return false; |
duke@435 | 1711 | } |
duke@435 | 1712 | |
duke@435 | 1713 | void ClassVerifier::verify_field_instructions(RawBytecodeStream* bcs, |
duke@435 | 1714 | StackMapFrame* current_frame, |
duke@435 | 1715 | constantPoolHandle cp, |
duke@435 | 1716 | TRAPS) { |
jrose@1920 | 1717 | u2 index = bcs->get_index_u2(); |
duke@435 | 1718 | verify_cp_type(index, cp, 1 << JVM_CONSTANT_Fieldref, CHECK_VERIFY(this)); |
duke@435 | 1719 | |
duke@435 | 1720 | // Get field name and signature |
duke@435 | 1721 | symbolHandle field_name = symbolHandle(THREAD, cp->name_ref_at(index)); |
duke@435 | 1722 | symbolHandle field_sig = symbolHandle(THREAD, cp->signature_ref_at(index)); |
duke@435 | 1723 | |
duke@435 | 1724 | if (!SignatureVerifier::is_valid_type_signature(field_sig)) { |
duke@435 | 1725 | class_format_error( |
duke@435 | 1726 | "Invalid signature for field in class %s referenced " |
duke@435 | 1727 | "from constant pool index %d", _klass->external_name(), index); |
duke@435 | 1728 | return; |
duke@435 | 1729 | } |
duke@435 | 1730 | |
duke@435 | 1731 | // Get referenced class type |
duke@435 | 1732 | VerificationType ref_class_type = cp_ref_index_to_type( |
duke@435 | 1733 | index, cp, CHECK_VERIFY(this)); |
duke@435 | 1734 | if (!ref_class_type.is_object()) { |
duke@435 | 1735 | verify_error( |
duke@435 | 1736 | "Expecting reference to class in class %s at constant pool index %d", |
duke@435 | 1737 | _klass->external_name(), index); |
duke@435 | 1738 | return; |
duke@435 | 1739 | } |
duke@435 | 1740 | VerificationType target_class_type = ref_class_type; |
duke@435 | 1741 | |
duke@435 | 1742 | assert(sizeof(VerificationType) == sizeof(uintptr_t), |
duke@435 | 1743 | "buffer type must match VerificationType size"); |
duke@435 | 1744 | uintptr_t field_type_buffer[2]; |
duke@435 | 1745 | VerificationType* field_type = (VerificationType*)field_type_buffer; |
duke@435 | 1746 | // If we make a VerificationType[2] array directly, the compiler calls |
duke@435 | 1747 | // to the c-runtime library to do the allocation instead of just |
duke@435 | 1748 | // stack allocating it. Plus it would run constructors. This shows up |
duke@435 | 1749 | // in performance profiles. |
duke@435 | 1750 | |
duke@435 | 1751 | SignatureStream sig_stream(field_sig, false); |
duke@435 | 1752 | VerificationType stack_object_type; |
duke@435 | 1753 | int n = change_sig_to_verificationType( |
duke@435 | 1754 | &sig_stream, field_type, CHECK_VERIFY(this)); |
duke@435 | 1755 | u2 bci = bcs->bci(); |
duke@435 | 1756 | bool is_assignable; |
jrose@1920 | 1757 | switch (bcs->raw_code()) { |
duke@435 | 1758 | case Bytecodes::_getstatic: { |
duke@435 | 1759 | for (int i = 0; i < n; i++) { |
duke@435 | 1760 | current_frame->push_stack(field_type[i], CHECK_VERIFY(this)); |
duke@435 | 1761 | } |
duke@435 | 1762 | break; |
duke@435 | 1763 | } |
duke@435 | 1764 | case Bytecodes::_putstatic: { |
duke@435 | 1765 | for (int i = n - 1; i >= 0; i--) { |
duke@435 | 1766 | current_frame->pop_stack(field_type[i], CHECK_VERIFY(this)); |
duke@435 | 1767 | } |
duke@435 | 1768 | break; |
duke@435 | 1769 | } |
duke@435 | 1770 | case Bytecodes::_getfield: { |
duke@435 | 1771 | stack_object_type = current_frame->pop_stack( |
duke@435 | 1772 | target_class_type, CHECK_VERIFY(this)); |
duke@435 | 1773 | for (int i = 0; i < n; i++) { |
duke@435 | 1774 | current_frame->push_stack(field_type[i], CHECK_VERIFY(this)); |
duke@435 | 1775 | } |
duke@435 | 1776 | goto check_protected; |
duke@435 | 1777 | } |
duke@435 | 1778 | case Bytecodes::_putfield: { |
duke@435 | 1779 | for (int i = n - 1; i >= 0; i--) { |
duke@435 | 1780 | current_frame->pop_stack(field_type[i], CHECK_VERIFY(this)); |
duke@435 | 1781 | } |
duke@435 | 1782 | stack_object_type = current_frame->pop_stack(CHECK_VERIFY(this)); |
duke@435 | 1783 | |
duke@435 | 1784 | // The JVMS 2nd edition allows field initialization before the superclass |
duke@435 | 1785 | // initializer, if the field is defined within the current class. |
duke@435 | 1786 | fieldDescriptor fd; |
duke@435 | 1787 | if (stack_object_type == VerificationType::uninitialized_this_type() && |
duke@435 | 1788 | target_class_type.equals(current_type()) && |
duke@435 | 1789 | _klass->find_local_field(field_name(), field_sig(), &fd)) { |
duke@435 | 1790 | stack_object_type = current_type(); |
duke@435 | 1791 | } |
duke@435 | 1792 | is_assignable = target_class_type.is_assignable_from( |
duke@435 | 1793 | stack_object_type, current_class(), CHECK_VERIFY(this)); |
duke@435 | 1794 | if (!is_assignable) { |
duke@435 | 1795 | verify_error(bci, "Bad type on operand stack in putfield"); |
duke@435 | 1796 | return; |
duke@435 | 1797 | } |
duke@435 | 1798 | } |
duke@435 | 1799 | check_protected: { |
duke@435 | 1800 | if (_this_type == stack_object_type) |
duke@435 | 1801 | break; // stack_object_type must be assignable to _current_class_type |
duke@435 | 1802 | symbolHandle ref_class_name = symbolHandle(THREAD, |
duke@435 | 1803 | cp->klass_name_at(cp->klass_ref_index_at(index))); |
duke@435 | 1804 | if (!name_in_supers(ref_class_name(), current_class())) |
duke@435 | 1805 | // stack_object_type must be assignable to _current_class_type since: |
duke@435 | 1806 | // 1. stack_object_type must be assignable to ref_class. |
duke@435 | 1807 | // 2. ref_class must be _current_class or a subclass of it. It can't |
duke@435 | 1808 | // be a superclass of it. See revised JVMS 5.4.4. |
duke@435 | 1809 | break; |
duke@435 | 1810 | |
duke@435 | 1811 | klassOop ref_class_oop = load_class(ref_class_name, CHECK); |
duke@435 | 1812 | if (is_protected_access(current_class(), ref_class_oop, field_name(), |
duke@435 | 1813 | field_sig(), false)) { |
duke@435 | 1814 | // It's protected access, check if stack object is assignable to |
duke@435 | 1815 | // current class. |
duke@435 | 1816 | is_assignable = current_type().is_assignable_from( |
duke@435 | 1817 | stack_object_type, current_class(), CHECK_VERIFY(this)); |
duke@435 | 1818 | if (!is_assignable) { |
duke@435 | 1819 | verify_error(bci, "Bad access to protected data in getfield"); |
duke@435 | 1820 | return; |
duke@435 | 1821 | } |
duke@435 | 1822 | } |
duke@435 | 1823 | break; |
duke@435 | 1824 | } |
duke@435 | 1825 | default: ShouldNotReachHere(); |
duke@435 | 1826 | } |
duke@435 | 1827 | } |
duke@435 | 1828 | |
duke@435 | 1829 | void ClassVerifier::verify_invoke_init( |
duke@435 | 1830 | RawBytecodeStream* bcs, VerificationType ref_class_type, |
duke@435 | 1831 | StackMapFrame* current_frame, u4 code_length, bool *this_uninit, |
duke@435 | 1832 | constantPoolHandle cp, TRAPS) { |
duke@435 | 1833 | u2 bci = bcs->bci(); |
duke@435 | 1834 | VerificationType type = current_frame->pop_stack( |
duke@435 | 1835 | VerificationType::reference_check(), CHECK_VERIFY(this)); |
duke@435 | 1836 | if (type == VerificationType::uninitialized_this_type()) { |
duke@435 | 1837 | // The method must be an <init> method of either this class, or one of its |
duke@435 | 1838 | // superclasses |
duke@435 | 1839 | klassOop oop = current_class()(); |
duke@435 | 1840 | Klass* klass = oop->klass_part(); |
duke@435 | 1841 | while (klass != NULL && ref_class_type.name() != klass->name()) { |
duke@435 | 1842 | klass = klass->super()->klass_part(); |
duke@435 | 1843 | } |
duke@435 | 1844 | if (klass == NULL) { |
duke@435 | 1845 | verify_error(bci, "Bad <init> method call"); |
duke@435 | 1846 | return; |
duke@435 | 1847 | } |
duke@435 | 1848 | current_frame->initialize_object(type, current_type()); |
duke@435 | 1849 | *this_uninit = true; |
duke@435 | 1850 | } else if (type.is_uninitialized()) { |
duke@435 | 1851 | u2 new_offset = type.bci(); |
duke@435 | 1852 | address new_bcp = bcs->bcp() - bci + new_offset; |
duke@435 | 1853 | if (new_offset > (code_length - 3) || (*new_bcp) != Bytecodes::_new) { |
duke@435 | 1854 | verify_error(new_offset, "Expecting new instruction"); |
duke@435 | 1855 | return; |
duke@435 | 1856 | } |
duke@435 | 1857 | u2 new_class_index = Bytes::get_Java_u2(new_bcp + 1); |
duke@435 | 1858 | verify_cp_class_type(new_class_index, cp, CHECK_VERIFY(this)); |
duke@435 | 1859 | |
duke@435 | 1860 | // The method must be an <init> method of the indicated class |
duke@435 | 1861 | VerificationType new_class_type = cp_index_to_type( |
duke@435 | 1862 | new_class_index, cp, CHECK_VERIFY(this)); |
duke@435 | 1863 | if (!new_class_type.equals(ref_class_type)) { |
duke@435 | 1864 | verify_error(bci, "Call to wrong <init> method"); |
duke@435 | 1865 | return; |
duke@435 | 1866 | } |
duke@435 | 1867 | // According to the VM spec, if the referent class is a superclass of the |
duke@435 | 1868 | // current class, and is in a different runtime package, and the method is |
duke@435 | 1869 | // protected, then the objectref must be the current class or a subclass |
duke@435 | 1870 | // of the current class. |
duke@435 | 1871 | VerificationType objectref_type = new_class_type; |
duke@435 | 1872 | if (name_in_supers(ref_class_type.name(), current_class())) { |
duke@435 | 1873 | klassOop ref_klass = load_class( |
duke@435 | 1874 | ref_class_type.name(), CHECK_VERIFY(this)); |
duke@435 | 1875 | methodOop m = instanceKlass::cast(ref_klass)->uncached_lookup_method( |
duke@435 | 1876 | vmSymbols::object_initializer_name(), |
jrose@1920 | 1877 | cp->signature_ref_at(bcs->get_index_u2())); |
duke@435 | 1878 | instanceKlassHandle mh(THREAD, m->method_holder()); |
duke@435 | 1879 | if (m->is_protected() && !mh->is_same_class_package(_klass())) { |
duke@435 | 1880 | bool assignable = current_type().is_assignable_from( |
duke@435 | 1881 | objectref_type, current_class(), CHECK_VERIFY(this)); |
duke@435 | 1882 | if (!assignable) { |
duke@435 | 1883 | verify_error(bci, "Bad access to protected <init> method"); |
duke@435 | 1884 | return; |
duke@435 | 1885 | } |
duke@435 | 1886 | } |
duke@435 | 1887 | } |
duke@435 | 1888 | current_frame->initialize_object(type, new_class_type); |
duke@435 | 1889 | } else { |
duke@435 | 1890 | verify_error(bci, "Bad operand type when invoking <init>"); |
duke@435 | 1891 | return; |
duke@435 | 1892 | } |
duke@435 | 1893 | } |
duke@435 | 1894 | |
duke@435 | 1895 | void ClassVerifier::verify_invoke_instructions( |
duke@435 | 1896 | RawBytecodeStream* bcs, u4 code_length, StackMapFrame* current_frame, |
duke@435 | 1897 | bool *this_uninit, VerificationType return_type, |
duke@435 | 1898 | constantPoolHandle cp, TRAPS) { |
duke@435 | 1899 | // Make sure the constant pool item is the right type |
jrose@1920 | 1900 | u2 index = bcs->get_index_u2(); |
jrose@1920 | 1901 | Bytecodes::Code opcode = bcs->raw_code(); |
duke@435 | 1902 | unsigned int types = (opcode == Bytecodes::_invokeinterface |
duke@435 | 1903 | ? 1 << JVM_CONSTANT_InterfaceMethodref |
jrose@1161 | 1904 | : opcode == Bytecodes::_invokedynamic |
jrose@1161 | 1905 | ? 1 << JVM_CONSTANT_NameAndType |
duke@435 | 1906 | : 1 << JVM_CONSTANT_Methodref); |
duke@435 | 1907 | verify_cp_type(index, cp, types, CHECK_VERIFY(this)); |
duke@435 | 1908 | |
duke@435 | 1909 | // Get method name and signature |
jrose@1494 | 1910 | symbolHandle method_name(THREAD, cp->name_ref_at(index)); |
jrose@1494 | 1911 | symbolHandle method_sig(THREAD, cp->signature_ref_at(index)); |
duke@435 | 1912 | |
duke@435 | 1913 | if (!SignatureVerifier::is_valid_method_signature(method_sig)) { |
duke@435 | 1914 | class_format_error( |
duke@435 | 1915 | "Invalid method signature in class %s referenced " |
duke@435 | 1916 | "from constant pool index %d", _klass->external_name(), index); |
duke@435 | 1917 | return; |
duke@435 | 1918 | } |
duke@435 | 1919 | |
duke@435 | 1920 | // Get referenced class type |
jrose@1161 | 1921 | VerificationType ref_class_type; |
jrose@1161 | 1922 | if (opcode == Bytecodes::_invokedynamic) { |
jrose@1161 | 1923 | if (!EnableInvokeDynamic) { |
jrose@1161 | 1924 | class_format_error( |
jrose@1161 | 1925 | "invokedynamic instructions not enabled on this JVM", |
jrose@1161 | 1926 | _klass->external_name()); |
jrose@1161 | 1927 | return; |
jrose@1161 | 1928 | } |
jrose@1161 | 1929 | } else { |
jrose@1161 | 1930 | ref_class_type = cp_ref_index_to_type(index, cp, CHECK_VERIFY(this)); |
jrose@1161 | 1931 | } |
duke@435 | 1932 | |
duke@435 | 1933 | // For a small signature length, we just allocate 128 bytes instead |
duke@435 | 1934 | // of parsing the signature once to find its size. |
duke@435 | 1935 | // -3 is for '(', ')' and return descriptor; multiply by 2 is for |
duke@435 | 1936 | // longs/doubles to be consertive. |
duke@435 | 1937 | assert(sizeof(VerificationType) == sizeof(uintptr_t), |
duke@435 | 1938 | "buffer type must match VerificationType size"); |
duke@435 | 1939 | uintptr_t on_stack_sig_types_buffer[128]; |
duke@435 | 1940 | // If we make a VerificationType[128] array directly, the compiler calls |
duke@435 | 1941 | // to the c-runtime library to do the allocation instead of just |
duke@435 | 1942 | // stack allocating it. Plus it would run constructors. This shows up |
duke@435 | 1943 | // in performance profiles. |
duke@435 | 1944 | |
duke@435 | 1945 | VerificationType* sig_types; |
duke@435 | 1946 | int size = (method_sig->utf8_length() - 3) * 2; |
duke@435 | 1947 | if (size > 128) { |
duke@435 | 1948 | // Long and double occupies two slots here. |
duke@435 | 1949 | ArgumentSizeComputer size_it(method_sig); |
duke@435 | 1950 | size = size_it.size(); |
duke@435 | 1951 | sig_types = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, VerificationType, size); |
duke@435 | 1952 | } else{ |
duke@435 | 1953 | sig_types = (VerificationType*)on_stack_sig_types_buffer; |
duke@435 | 1954 | } |
duke@435 | 1955 | SignatureStream sig_stream(method_sig); |
duke@435 | 1956 | int sig_i = 0; |
duke@435 | 1957 | while (!sig_stream.at_return_type()) { |
duke@435 | 1958 | sig_i += change_sig_to_verificationType( |
duke@435 | 1959 | &sig_stream, &sig_types[sig_i], CHECK_VERIFY(this)); |
duke@435 | 1960 | sig_stream.next(); |
duke@435 | 1961 | } |
duke@435 | 1962 | int nargs = sig_i; |
duke@435 | 1963 | |
duke@435 | 1964 | #ifdef ASSERT |
duke@435 | 1965 | { |
duke@435 | 1966 | ArgumentSizeComputer size_it(method_sig); |
duke@435 | 1967 | assert(nargs == size_it.size(), "Argument sizes do not match"); |
duke@435 | 1968 | assert(nargs <= (method_sig->utf8_length() - 3) * 2, "estimate of max size isn't conservative enough"); |
duke@435 | 1969 | } |
duke@435 | 1970 | #endif |
duke@435 | 1971 | |
duke@435 | 1972 | // Check instruction operands |
duke@435 | 1973 | u2 bci = bcs->bci(); |
duke@435 | 1974 | if (opcode == Bytecodes::_invokeinterface) { |
duke@435 | 1975 | address bcp = bcs->bcp(); |
duke@435 | 1976 | // 4905268: count operand in invokeinterface should be nargs+1, not nargs. |
duke@435 | 1977 | // JSR202 spec: The count operand of an invokeinterface instruction is valid if it is |
duke@435 | 1978 | // the difference between the size of the operand stack before and after the instruction |
duke@435 | 1979 | // executes. |
duke@435 | 1980 | if (*(bcp+3) != (nargs+1)) { |
duke@435 | 1981 | verify_error(bci, "Inconsistent args count operand in invokeinterface"); |
duke@435 | 1982 | return; |
duke@435 | 1983 | } |
duke@435 | 1984 | if (*(bcp+4) != 0) { |
duke@435 | 1985 | verify_error(bci, "Fourth operand byte of invokeinterface must be zero"); |
duke@435 | 1986 | return; |
duke@435 | 1987 | } |
duke@435 | 1988 | } |
duke@435 | 1989 | |
jrose@1161 | 1990 | if (opcode == Bytecodes::_invokedynamic) { |
jrose@1161 | 1991 | address bcp = bcs->bcp(); |
jrose@1161 | 1992 | if (*(bcp+3) != 0 || *(bcp+4) != 0) { |
jrose@1161 | 1993 | verify_error(bci, "Third and fourth operand bytes of invokedynamic must be zero"); |
jrose@1161 | 1994 | return; |
jrose@1161 | 1995 | } |
jrose@1161 | 1996 | } |
jrose@1161 | 1997 | |
duke@435 | 1998 | if (method_name->byte_at(0) == '<') { |
duke@435 | 1999 | // Make sure <init> can only be invoked by invokespecial |
duke@435 | 2000 | if (opcode != Bytecodes::_invokespecial || |
duke@435 | 2001 | method_name() != vmSymbols::object_initializer_name()) { |
duke@435 | 2002 | verify_error(bci, "Illegal call to internal method"); |
duke@435 | 2003 | return; |
duke@435 | 2004 | } |
duke@435 | 2005 | } else if (opcode == Bytecodes::_invokespecial |
duke@435 | 2006 | && !ref_class_type.equals(current_type()) |
duke@435 | 2007 | && !ref_class_type.equals(VerificationType::reference_type( |
duke@435 | 2008 | current_class()->super()->klass_part()->name()))) { |
duke@435 | 2009 | bool subtype = ref_class_type.is_assignable_from( |
duke@435 | 2010 | current_type(), current_class(), CHECK_VERIFY(this)); |
duke@435 | 2011 | if (!subtype) { |
duke@435 | 2012 | verify_error(bci, "Bad invokespecial instruction: " |
duke@435 | 2013 | "current class isn't assignable to reference class."); |
duke@435 | 2014 | return; |
duke@435 | 2015 | } |
duke@435 | 2016 | } |
duke@435 | 2017 | // Match method descriptor with operand stack |
duke@435 | 2018 | for (int i = nargs - 1; i >= 0; i--) { // Run backwards |
duke@435 | 2019 | current_frame->pop_stack(sig_types[i], CHECK_VERIFY(this)); |
duke@435 | 2020 | } |
duke@435 | 2021 | // Check objectref on operand stack |
jrose@1161 | 2022 | if (opcode != Bytecodes::_invokestatic && |
jrose@1161 | 2023 | opcode != Bytecodes::_invokedynamic) { |
duke@435 | 2024 | if (method_name() == vmSymbols::object_initializer_name()) { // <init> method |
duke@435 | 2025 | verify_invoke_init(bcs, ref_class_type, current_frame, |
duke@435 | 2026 | code_length, this_uninit, cp, CHECK_VERIFY(this)); |
duke@435 | 2027 | } else { // other methods |
duke@435 | 2028 | // Ensures that target class is assignable to method class. |
duke@435 | 2029 | if (opcode == Bytecodes::_invokespecial) { |
duke@435 | 2030 | current_frame->pop_stack(current_type(), CHECK_VERIFY(this)); |
duke@435 | 2031 | } else if (opcode == Bytecodes::_invokevirtual) { |
duke@435 | 2032 | VerificationType stack_object_type = |
duke@435 | 2033 | current_frame->pop_stack(ref_class_type, CHECK_VERIFY(this)); |
duke@435 | 2034 | if (current_type() != stack_object_type) { |
duke@435 | 2035 | assert(cp->cache() == NULL, "not rewritten yet"); |
duke@435 | 2036 | symbolHandle ref_class_name = symbolHandle(THREAD, |
duke@435 | 2037 | cp->klass_name_at(cp->klass_ref_index_at(index))); |
duke@435 | 2038 | // See the comments in verify_field_instructions() for |
duke@435 | 2039 | // the rationale behind this. |
duke@435 | 2040 | if (name_in_supers(ref_class_name(), current_class())) { |
duke@435 | 2041 | klassOop ref_class = load_class(ref_class_name, CHECK); |
duke@435 | 2042 | if (is_protected_access( |
duke@435 | 2043 | _klass, ref_class, method_name(), method_sig(), true)) { |
duke@435 | 2044 | // It's protected access, check if stack object is |
duke@435 | 2045 | // assignable to current class. |
duke@435 | 2046 | bool is_assignable = current_type().is_assignable_from( |
duke@435 | 2047 | stack_object_type, current_class(), CHECK_VERIFY(this)); |
duke@435 | 2048 | if (!is_assignable) { |
duke@435 | 2049 | if (ref_class_type.name() == vmSymbols::java_lang_Object() |
duke@435 | 2050 | && stack_object_type.is_array() |
duke@435 | 2051 | && method_name() == vmSymbols::clone_name()) { |
duke@435 | 2052 | // Special case: arrays pretend to implement public Object |
duke@435 | 2053 | // clone(). |
duke@435 | 2054 | } else { |
duke@435 | 2055 | verify_error(bci, |
duke@435 | 2056 | "Bad access to protected data in invokevirtual"); |
duke@435 | 2057 | return; |
duke@435 | 2058 | } |
duke@435 | 2059 | } |
duke@435 | 2060 | } |
duke@435 | 2061 | } |
duke@435 | 2062 | } |
duke@435 | 2063 | } else { |
duke@435 | 2064 | assert(opcode == Bytecodes::_invokeinterface, "Unexpected opcode encountered"); |
duke@435 | 2065 | current_frame->pop_stack(ref_class_type, CHECK_VERIFY(this)); |
duke@435 | 2066 | } |
duke@435 | 2067 | } |
duke@435 | 2068 | } |
duke@435 | 2069 | // Push the result type. |
duke@435 | 2070 | if (sig_stream.type() != T_VOID) { |
duke@435 | 2071 | if (method_name() == vmSymbols::object_initializer_name()) { |
duke@435 | 2072 | // <init> method must have a void return type |
duke@435 | 2073 | verify_error(bci, "Return type must be void in <init> method"); |
duke@435 | 2074 | return; |
duke@435 | 2075 | } |
duke@435 | 2076 | VerificationType return_type[2]; |
duke@435 | 2077 | int n = change_sig_to_verificationType( |
duke@435 | 2078 | &sig_stream, return_type, CHECK_VERIFY(this)); |
duke@435 | 2079 | for (int i = 0; i < n; i++) { |
duke@435 | 2080 | current_frame->push_stack(return_type[i], CHECK_VERIFY(this)); // push types backwards |
duke@435 | 2081 | } |
duke@435 | 2082 | } |
duke@435 | 2083 | } |
duke@435 | 2084 | |
duke@435 | 2085 | VerificationType ClassVerifier::get_newarray_type( |
duke@435 | 2086 | u2 index, u2 bci, TRAPS) { |
duke@435 | 2087 | const char* from_bt[] = { |
duke@435 | 2088 | NULL, NULL, NULL, NULL, "[Z", "[C", "[F", "[D", "[B", "[S", "[I", "[J", |
duke@435 | 2089 | }; |
duke@435 | 2090 | if (index < T_BOOLEAN || index > T_LONG) { |
duke@435 | 2091 | verify_error(bci, "Illegal newarray instruction"); |
duke@435 | 2092 | return VerificationType::bogus_type(); |
duke@435 | 2093 | } |
duke@435 | 2094 | |
duke@435 | 2095 | // from_bt[index] contains the array signature which has a length of 2 |
duke@435 | 2096 | symbolHandle sig = oopFactory::new_symbol_handle( |
duke@435 | 2097 | from_bt[index], 2, CHECK_(VerificationType::bogus_type())); |
duke@435 | 2098 | return VerificationType::reference_type(sig); |
duke@435 | 2099 | } |
duke@435 | 2100 | |
duke@435 | 2101 | void ClassVerifier::verify_anewarray( |
duke@435 | 2102 | u2 index, constantPoolHandle cp, StackMapFrame* current_frame, TRAPS) { |
duke@435 | 2103 | verify_cp_class_type(index, cp, CHECK_VERIFY(this)); |
duke@435 | 2104 | current_frame->pop_stack( |
duke@435 | 2105 | VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 2106 | |
duke@435 | 2107 | VerificationType component_type = |
duke@435 | 2108 | cp_index_to_type(index, cp, CHECK_VERIFY(this)); |
duke@435 | 2109 | ResourceMark rm(THREAD); |
duke@435 | 2110 | int length; |
duke@435 | 2111 | char* arr_sig_str; |
duke@435 | 2112 | if (component_type.is_array()) { // it's an array |
duke@435 | 2113 | const char* component_name = component_type.name()->as_utf8(); |
duke@435 | 2114 | // add one dimension to component |
duke@435 | 2115 | length = (int)strlen(component_name) + 1; |
duke@435 | 2116 | arr_sig_str = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, length); |
duke@435 | 2117 | arr_sig_str[0] = '['; |
duke@435 | 2118 | strncpy(&arr_sig_str[1], component_name, length - 1); |
duke@435 | 2119 | } else { // it's an object or interface |
duke@435 | 2120 | const char* component_name = component_type.name()->as_utf8(); |
duke@435 | 2121 | // add one dimension to component with 'L' prepended and ';' postpended. |
duke@435 | 2122 | length = (int)strlen(component_name) + 3; |
duke@435 | 2123 | arr_sig_str = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, length); |
duke@435 | 2124 | arr_sig_str[0] = '['; |
duke@435 | 2125 | arr_sig_str[1] = 'L'; |
duke@435 | 2126 | strncpy(&arr_sig_str[2], component_name, length - 2); |
duke@435 | 2127 | arr_sig_str[length - 1] = ';'; |
duke@435 | 2128 | } |
duke@435 | 2129 | symbolHandle arr_sig = oopFactory::new_symbol_handle( |
duke@435 | 2130 | arr_sig_str, length, CHECK_VERIFY(this)); |
duke@435 | 2131 | VerificationType new_array_type = VerificationType::reference_type(arr_sig); |
duke@435 | 2132 | current_frame->push_stack(new_array_type, CHECK_VERIFY(this)); |
duke@435 | 2133 | } |
duke@435 | 2134 | |
duke@435 | 2135 | void ClassVerifier::verify_iload(u2 index, StackMapFrame* current_frame, TRAPS) { |
duke@435 | 2136 | current_frame->get_local( |
duke@435 | 2137 | index, VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 2138 | current_frame->push_stack( |
duke@435 | 2139 | VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 2140 | } |
duke@435 | 2141 | |
duke@435 | 2142 | void ClassVerifier::verify_lload(u2 index, StackMapFrame* current_frame, TRAPS) { |
duke@435 | 2143 | current_frame->get_local_2( |
duke@435 | 2144 | index, VerificationType::long_type(), |
duke@435 | 2145 | VerificationType::long2_type(), CHECK_VERIFY(this)); |
duke@435 | 2146 | current_frame->push_stack_2( |
duke@435 | 2147 | VerificationType::long_type(), |
duke@435 | 2148 | VerificationType::long2_type(), CHECK_VERIFY(this)); |
duke@435 | 2149 | } |
duke@435 | 2150 | |
duke@435 | 2151 | void ClassVerifier::verify_fload(u2 index, StackMapFrame* current_frame, TRAPS) { |
duke@435 | 2152 | current_frame->get_local( |
duke@435 | 2153 | index, VerificationType::float_type(), CHECK_VERIFY(this)); |
duke@435 | 2154 | current_frame->push_stack( |
duke@435 | 2155 | VerificationType::float_type(), CHECK_VERIFY(this)); |
duke@435 | 2156 | } |
duke@435 | 2157 | |
duke@435 | 2158 | void ClassVerifier::verify_dload(u2 index, StackMapFrame* current_frame, TRAPS) { |
duke@435 | 2159 | current_frame->get_local_2( |
duke@435 | 2160 | index, VerificationType::double_type(), |
duke@435 | 2161 | VerificationType::double2_type(), CHECK_VERIFY(this)); |
duke@435 | 2162 | current_frame->push_stack_2( |
duke@435 | 2163 | VerificationType::double_type(), |
duke@435 | 2164 | VerificationType::double2_type(), CHECK_VERIFY(this)); |
duke@435 | 2165 | } |
duke@435 | 2166 | |
duke@435 | 2167 | void ClassVerifier::verify_aload(u2 index, StackMapFrame* current_frame, TRAPS) { |
duke@435 | 2168 | VerificationType type = current_frame->get_local( |
duke@435 | 2169 | index, VerificationType::reference_check(), CHECK_VERIFY(this)); |
duke@435 | 2170 | current_frame->push_stack(type, CHECK_VERIFY(this)); |
duke@435 | 2171 | } |
duke@435 | 2172 | |
duke@435 | 2173 | void ClassVerifier::verify_istore(u2 index, StackMapFrame* current_frame, TRAPS) { |
duke@435 | 2174 | current_frame->pop_stack( |
duke@435 | 2175 | VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 2176 | current_frame->set_local( |
duke@435 | 2177 | index, VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 2178 | } |
duke@435 | 2179 | |
duke@435 | 2180 | void ClassVerifier::verify_lstore(u2 index, StackMapFrame* current_frame, TRAPS) { |
duke@435 | 2181 | current_frame->pop_stack_2( |
duke@435 | 2182 | VerificationType::long2_type(), |
duke@435 | 2183 | VerificationType::long_type(), CHECK_VERIFY(this)); |
duke@435 | 2184 | current_frame->set_local_2( |
duke@435 | 2185 | index, VerificationType::long_type(), |
duke@435 | 2186 | VerificationType::long2_type(), CHECK_VERIFY(this)); |
duke@435 | 2187 | } |
duke@435 | 2188 | |
duke@435 | 2189 | void ClassVerifier::verify_fstore(u2 index, StackMapFrame* current_frame, TRAPS) { |
duke@435 | 2190 | current_frame->pop_stack(VerificationType::float_type(), CHECK_VERIFY(this)); |
duke@435 | 2191 | current_frame->set_local( |
duke@435 | 2192 | index, VerificationType::float_type(), CHECK_VERIFY(this)); |
duke@435 | 2193 | } |
duke@435 | 2194 | |
duke@435 | 2195 | void ClassVerifier::verify_dstore(u2 index, StackMapFrame* current_frame, TRAPS) { |
duke@435 | 2196 | current_frame->pop_stack_2( |
duke@435 | 2197 | VerificationType::double2_type(), |
duke@435 | 2198 | VerificationType::double_type(), CHECK_VERIFY(this)); |
duke@435 | 2199 | current_frame->set_local_2( |
duke@435 | 2200 | index, VerificationType::double_type(), |
duke@435 | 2201 | VerificationType::double2_type(), CHECK_VERIFY(this)); |
duke@435 | 2202 | } |
duke@435 | 2203 | |
duke@435 | 2204 | void ClassVerifier::verify_astore(u2 index, StackMapFrame* current_frame, TRAPS) { |
duke@435 | 2205 | VerificationType type = current_frame->pop_stack( |
duke@435 | 2206 | VerificationType::reference_check(), CHECK_VERIFY(this)); |
duke@435 | 2207 | current_frame->set_local(index, type, CHECK_VERIFY(this)); |
duke@435 | 2208 | } |
duke@435 | 2209 | |
duke@435 | 2210 | void ClassVerifier::verify_iinc(u2 index, StackMapFrame* current_frame, TRAPS) { |
duke@435 | 2211 | VerificationType type = current_frame->get_local( |
duke@435 | 2212 | index, VerificationType::integer_type(), CHECK_VERIFY(this)); |
duke@435 | 2213 | current_frame->set_local(index, type, CHECK_VERIFY(this)); |
duke@435 | 2214 | } |
duke@435 | 2215 | |
duke@435 | 2216 | void ClassVerifier::verify_return_value( |
duke@435 | 2217 | VerificationType return_type, VerificationType type, u2 bci, TRAPS) { |
duke@435 | 2218 | if (return_type == VerificationType::bogus_type()) { |
duke@435 | 2219 | verify_error(bci, "Method expects a return value"); |
duke@435 | 2220 | return; |
duke@435 | 2221 | } |
duke@435 | 2222 | bool match = return_type.is_assignable_from(type, _klass, CHECK_VERIFY(this)); |
duke@435 | 2223 | if (!match) { |
duke@435 | 2224 | verify_error(bci, "Bad return type"); |
duke@435 | 2225 | return; |
duke@435 | 2226 | } |
duke@435 | 2227 | } |