comparison src/share/vm/classfile/verifier.cpp @ 17573:aff11567504c

8035119: Fix exceptions to bytecode verification Summary: Prevent ctor calls to super() and this() from avoidable code (try blocks, if stmts, etc.) Reviewed-by: coleenp, acorn, mschoene
author hseigel
date Mon, 17 Mar 2014 10:17:55 -0400
parents 22eaa15b7960
children b5ae226b7516
comparison
equal deleted inserted replaced
17572:cc7a96a360d0 17573:aff11567504c
1 /* 1 /*
2 * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
630 630
631 // Scan the byte code linearly from the start to the end 631 // Scan the byte code linearly from the start to the end
632 bool no_control_flow = false; // Set to true when there is no direct control 632 bool no_control_flow = false; // Set to true when there is no direct control
633 // flow from current instruction to the next 633 // flow from current instruction to the next
634 // instruction in sequence 634 // instruction in sequence
635
636 set_furthest_jump(0);
637
635 Bytecodes::Code opcode; 638 Bytecodes::Code opcode;
636 while (!bcs.is_last_bytecode()) { 639 while (!bcs.is_last_bytecode()) {
637 // Check for recursive re-verification before each bytecode. 640 // Check for recursive re-verification before each bytecode.
638 if (was_recursively_verified()) return; 641 if (was_recursively_verified()) return;
639 642
2243 TypeOrigin::implicit(ref_class_type), 2246 TypeOrigin::implicit(ref_class_type),
2244 TypeOrigin::implicit(current_type())), 2247 TypeOrigin::implicit(current_type())),
2245 "Bad <init> method call"); 2248 "Bad <init> method call");
2246 return; 2249 return;
2247 } 2250 }
2251
2252 // Make sure that this call is not jumped over.
2253 if (bci < furthest_jump()) {
2254 verify_error(ErrorContext::bad_code(bci),
2255 "Bad <init> method call from inside of a branch");
2256 return;
2257 }
2258
2259 // Make sure that this call is not done from within a TRY block because
2260 // that can result in returning an incomplete object. Simply checking
2261 // (bci >= start_pc) also ensures that this call is not done after a TRY
2262 // block. That is also illegal because this call must be the first Java
2263 // statement in the constructor.
2264 ExceptionTable exhandlers(_method());
2265 int exlength = exhandlers.length();
2266 for(int i = 0; i < exlength; i++) {
2267 if (bci >= exhandlers.start_pc(i)) {
2268 verify_error(ErrorContext::bad_code(bci),
2269 "Bad <init> method call from after the start of a try block");
2270 return;
2271 }
2272 }
2273
2248 current_frame->initialize_object(type, current_type()); 2274 current_frame->initialize_object(type, current_type());
2249 *this_uninit = true; 2275 *this_uninit = true;
2250 } else if (type.is_uninitialized()) { 2276 } else if (type.is_uninitialized()) {
2251 u2 new_offset = type.bci(); 2277 u2 new_offset = type.bci();
2252 address new_bcp = bcs->bcp() - bci + new_offset; 2278 address new_bcp = bcs->bcp() - bci + new_offset;