@@ -2438,216 +2438,6 @@ void ClassVerifier::verify_field_instructions(RawBytecodeStream* bcs,
24382438 }
24392439}
24402440
2441- // Look at the method's handlers. If the bci is in the handler's try block
2442- // then check if the handler_pc is already on the stack. If not, push it
2443- // unless the handler has already been scanned.
2444- void ClassVerifier::push_handlers (ExceptionTable* exhandlers,
2445- GrowableArray<u4>* handler_list,
2446- GrowableArray<u4>* handler_stack,
2447- u4 bci) {
2448- int exlength = exhandlers->length ();
2449- for (int x = 0 ; x < exlength; x++) {
2450- if (bci >= exhandlers->start_pc (x) && bci < exhandlers->end_pc (x)) {
2451- u4 exhandler_pc = exhandlers->handler_pc (x);
2452- if (!handler_list->contains (exhandler_pc)) {
2453- handler_stack->append_if_missing (exhandler_pc);
2454- handler_list->append (exhandler_pc);
2455- }
2456- }
2457- }
2458- }
2459-
2460- // Return TRUE if all code paths starting with start_bc_offset end in
2461- // bytecode athrow or loop.
2462- bool ClassVerifier::ends_in_athrow (u4 start_bc_offset) {
2463- ResourceMark rm;
2464- // Create bytecode stream.
2465- RawBytecodeStream bcs (method ());
2466- u4 code_length = method ()->code_size ();
2467- bcs.set_start (start_bc_offset);
2468- u4 target;
2469- // Create stack for storing bytecode start offsets for if* and *switch.
2470- GrowableArray<u4>* bci_stack = new GrowableArray<u4>(30 );
2471- // Create stack for handlers for try blocks containing this handler.
2472- GrowableArray<u4>* handler_stack = new GrowableArray<u4>(30 );
2473- // Create list of handlers that have been pushed onto the handler_stack
2474- // so that handlers embedded inside of their own TRY blocks only get
2475- // scanned once.
2476- GrowableArray<u4>* handler_list = new GrowableArray<u4>(30 );
2477- // Create list of visited branch opcodes (goto* and if*).
2478- GrowableArray<u4>* visited_branches = new GrowableArray<u4>(30 );
2479- ExceptionTable exhandlers (_method ());
2480-
2481- while (true ) {
2482- if (bcs.is_last_bytecode ()) {
2483- // if no more starting offsets to parse or if at the end of the
2484- // method then return false.
2485- if ((bci_stack->is_empty ()) || ((u4)bcs.end_bci () == code_length))
2486- return false ;
2487- // Pop a bytecode starting offset and scan from there.
2488- bcs.set_start (bci_stack->pop ());
2489- }
2490- Bytecodes::Code opcode = bcs.raw_next ();
2491- u4 bci = bcs.bci ();
2492-
2493- // If the bytecode is in a TRY block, push its handlers so they
2494- // will get parsed.
2495- push_handlers (&exhandlers, handler_list, handler_stack, bci);
2496-
2497- switch (opcode) {
2498- case Bytecodes::_if_icmpeq:
2499- case Bytecodes::_if_icmpne:
2500- case Bytecodes::_if_icmplt:
2501- case Bytecodes::_if_icmpge:
2502- case Bytecodes::_if_icmpgt:
2503- case Bytecodes::_if_icmple:
2504- case Bytecodes::_ifeq:
2505- case Bytecodes::_ifne:
2506- case Bytecodes::_iflt:
2507- case Bytecodes::_ifge:
2508- case Bytecodes::_ifgt:
2509- case Bytecodes::_ifle:
2510- case Bytecodes::_if_acmpeq:
2511- case Bytecodes::_if_acmpne:
2512- case Bytecodes::_ifnull:
2513- case Bytecodes::_ifnonnull:
2514- target = bcs.dest ();
2515- if (visited_branches->contains (bci)) {
2516- if (bci_stack->is_empty ()) {
2517- if (handler_stack->is_empty ()) {
2518- return true ;
2519- } else {
2520- // Parse the catch handlers for try blocks containing athrow.
2521- bcs.set_start (handler_stack->pop ());
2522- }
2523- } else {
2524- // Pop a bytecode starting offset and scan from there.
2525- bcs.set_start (bci_stack->pop ());
2526- }
2527- } else {
2528- if (target > bci) { // forward branch
2529- if (target >= code_length) return false ;
2530- // Push the branch target onto the stack.
2531- bci_stack->push (target);
2532- // then, scan bytecodes starting with next.
2533- bcs.set_start (bcs.next_bci ());
2534- } else { // backward branch
2535- // Push bytecode offset following backward branch onto the stack.
2536- bci_stack->push (bcs.next_bci ());
2537- // Check bytecodes starting with branch target.
2538- bcs.set_start (target);
2539- }
2540- // Record target so we don't branch here again.
2541- visited_branches->append (bci);
2542- }
2543- break ;
2544-
2545- case Bytecodes::_goto:
2546- case Bytecodes::_goto_w: {
2547- int offset = (opcode == Bytecodes::_goto ? bcs.get_offset_s2 () : bcs.get_offset_s4 ());
2548- int min_offset = -1 * max_method_code_size;
2549- // Check offset for overflow
2550- if (offset < min_offset || offset > max_method_code_size) return false ;
2551-
2552- target = bci + offset;
2553- if (visited_branches->contains (bci)) {
2554- if (bci_stack->is_empty ()) {
2555- if (handler_stack->is_empty ()) {
2556- return true ;
2557- } else {
2558- // Parse the catch handlers for try blocks containing athrow.
2559- bcs.set_start (handler_stack->pop ());
2560- }
2561- } else {
2562- // Been here before, pop new starting offset from stack.
2563- bcs.set_start (bci_stack->pop ());
2564- }
2565- } else {
2566- if (target >= code_length) return false ;
2567- // Continue scanning from the target onward.
2568- bcs.set_start (target);
2569- // Record target so we don't branch here again.
2570- visited_branches->append (bci);
2571- }
2572- break ;
2573- }
2574-
2575- // Check that all switch alternatives end in 'athrow' bytecodes. Since it
2576- // is difficult to determine where each switch alternative ends, parse
2577- // each switch alternative until either hit a 'return', 'athrow', or reach
2578- // the end of the method's bytecodes. This is gross but should be okay
2579- // because:
2580- // 1. tableswitch and lookupswitch byte codes in handlers for ctor explicit
2581- // constructor invocations should be rare.
2582- // 2. if each switch alternative ends in an athrow then the parsing should be
2583- // short. If there is no athrow then it is bogus code, anyway.
2584- case Bytecodes::_lookupswitch:
2585- case Bytecodes::_tableswitch:
2586- {
2587- address aligned_bcp = align_up (bcs.bcp () + 1 , jintSize);
2588- u4 default_offset = Bytes::get_Java_u4 (aligned_bcp) + bci;
2589- int keys, delta;
2590- if (opcode == Bytecodes::_tableswitch) {
2591- jint low = (jint)Bytes::get_Java_u4 (aligned_bcp + jintSize);
2592- jint high = (jint)Bytes::get_Java_u4 (aligned_bcp + 2 *jintSize);
2593- // This is invalid, but let the regular bytecode verifier
2594- // report this because the user will get a better error message.
2595- if (low > high) return true ;
2596- keys = high - low + 1 ;
2597- delta = 1 ;
2598- } else {
2599- keys = (int )Bytes::get_Java_u4 (aligned_bcp + jintSize);
2600- delta = 2 ;
2601- }
2602- // Invalid, let the regular bytecode verifier deal with it.
2603- if (keys < 0 ) return true ;
2604-
2605- // Push the offset of the next bytecode onto the stack.
2606- bci_stack->push (bcs.next_bci ());
2607-
2608- // Push the switch alternatives onto the stack.
2609- for (int i = 0 ; i < keys; i++) {
2610- int min_offset = -1 * max_method_code_size;
2611- int offset = (jint)Bytes::get_Java_u4 (aligned_bcp+(3 +i*delta)*jintSize);
2612- if (offset < min_offset || offset > max_method_code_size) return false ;
2613- u4 target = bci + offset;
2614- if (target > code_length) return false ;
2615- bci_stack->push (target);
2616- }
2617-
2618- // Start bytecode parsing for the switch at the default alternative.
2619- if (default_offset > code_length) return false ;
2620- bcs.set_start (default_offset);
2621- break ;
2622- }
2623-
2624- case Bytecodes::_return:
2625- return false ;
2626-
2627- case Bytecodes::_athrow:
2628- {
2629- if (bci_stack->is_empty ()) {
2630- if (handler_stack->is_empty ()) {
2631- return true ;
2632- } else {
2633- // Parse the catch handlers for try blocks containing athrow.
2634- bcs.set_start (handler_stack->pop ());
2635- }
2636- } else {
2637- // Pop a bytecode offset and starting scanning from there.
2638- bcs.set_start (bci_stack->pop ());
2639- }
2640- }
2641- break ;
2642-
2643- default :
2644- ;
2645- } // end switch
2646- } // end while loop
2647-
2648- return false ;
2649- }
2650-
26512441void ClassVerifier::verify_invoke_init (
26522442 RawBytecodeStream* bcs, u2 ref_class_index, VerificationType ref_class_type,
26532443 StackMapFrame* current_frame, u4 code_length, bool in_try_block,
@@ -2672,25 +2462,6 @@ void ClassVerifier::verify_invoke_init(
26722462 // sure that all catch clause paths end in a throw. Otherwise, this can
26732463 // result in returning an incomplete object.
26742464 if (in_try_block) {
2675- ExceptionTable exhandlers (_method ());
2676- int exlength = exhandlers.length ();
2677- for (int i = 0 ; i < exlength; i++) {
2678- u2 start_pc = exhandlers.start_pc (i);
2679- u2 end_pc = exhandlers.end_pc (i);
2680-
2681- if (bci >= start_pc && bci < end_pc) {
2682- if (!ends_in_athrow (exhandlers.handler_pc (i))) {
2683- verify_error (ErrorContext::bad_code (bci),
2684- " Bad <init> method call from after the start of a try block" );
2685- return ;
2686- } else if (log_is_enabled (Debug, verification)) {
2687- ResourceMark rm (THREAD);
2688- log_debug (verification)(" Survived call to ends_in_athrow(): %s" ,
2689- current_class ()->name ()->as_C_string ());
2690- }
2691- }
2692- }
2693-
26942465 // Check the exception handler target stackmaps with the locals from the
26952466 // incoming stackmap (before initialize_object() changes them to outgoing
26962467 // state).
0 commit comments