640 while (!bcs.is_last_bytecode()) { 641 // Check for recursive re-verification before each bytecode. 642 if (was_recursively_verified()) return; 643 644 opcode = bcs.raw_next(); 645 u2 bci = bcs.bci(); 646 647 // Set current frame's offset to bci 648 current_frame.set_offset(bci); 649 current_frame.set_mark(); 650 651 // Make sure every offset in stackmap table point to the beginning to 652 // an instruction. Match current_frame to stackmap_table entry with 653 // the same offset if exists. 654 stackmap_index = verify_stackmap_table( 655 stackmap_index, bci, ¤t_frame, &stackmap_table, 656 no_control_flow, CHECK_VERIFY(this)); 657 658 659 bool this_uninit = false; // Set to true when invokespecial <init> initialized 'this' 660 661 // Merge with the next instruction 662 { 663 u2 index; 664 int target; 665 VerificationType type, type2; 666 VerificationType atype; 667 668 #ifndef PRODUCT 669 if (VerboseVerification) { 670 current_frame.print_on(tty); 671 tty->print_cr("offset = %d, opcode = %s", bci, Bytecodes::name(opcode)); 672 } 673 #endif 674 675 // Make sure wide instruction is in correct format 676 if (bcs.is_wide()) { 677 if (opcode != Bytecodes::_iinc && opcode != Bytecodes::_iload && 678 opcode != Bytecodes::_aload && opcode != Bytecodes::_lload && 679 opcode != Bytecodes::_istore && opcode != Bytecodes::_astore && 680 opcode != Bytecodes::_lstore && opcode != Bytecodes::_fload && 681 opcode != Bytecodes::_dload && opcode != Bytecodes::_fstore && 682 opcode != Bytecodes::_dstore) { 683 /* Unreachable? RawBytecodeStream's raw_next() returns 'illegal' 684 * if we encounter a wide instruction that modifies an invalid 685 * opcode (not one of the ones listed above) */ 686 verify_error(ErrorContext::bad_code(bci), "Bad wide instruction"); 687 return; 688 } 689 } 690 691 switch (opcode) { 692 case Bytecodes::_nop : 693 no_control_flow = false; break; 694 case Bytecodes::_aconst_null : 695 current_frame.push_stack( 696 VerificationType::null_type(), CHECK_VERIFY(this)); 697 no_control_flow = false; break; 698 case Bytecodes::_iconst_m1 : 699 case Bytecodes::_iconst_0 : 700 case Bytecodes::_iconst_1 : 701 case Bytecodes::_iconst_2 : 702 case Bytecodes::_iconst_3 : 703 case Bytecodes::_iconst_4 : 704 case Bytecodes::_iconst_5 : 705 current_frame.push_stack( 706 VerificationType::integer_type(), CHECK_VERIFY(this)); 707 no_control_flow = false; break; 708 case Bytecodes::_lconst_0 : 709 case Bytecodes::_lconst_1 : 710 current_frame.push_stack_2( 1652 VerificationType::integer_type(), CHECK_VERIFY(this)); 1653 } 1654 current_frame.push_stack(new_array_type, CHECK_VERIFY(this)); 1655 no_control_flow = false; break; 1656 } 1657 case Bytecodes::_athrow : 1658 type = VerificationType::reference_type( 1659 vmSymbols::java_lang_Throwable()); 1660 current_frame.pop_stack(type, CHECK_VERIFY(this)); 1661 no_control_flow = true; break; 1662 default: 1663 // We only need to check the valid bytecodes in class file. 1664 // And jsr and ret are not in the new class file format in JDK1.5. 1665 verify_error(ErrorContext::bad_code(bci), 1666 "Bad instruction: %02x", opcode); 1667 no_control_flow = false; 1668 return; 1669 } // end switch 1670 } // end Merge with the next instruction 1671 1672 // Look for possible jump target in exception handlers and see if it 1673 // matches current_frame 1674 if (bci >= ex_min && bci < ex_max) { 1675 verify_exception_handler_targets( 1676 bci, this_uninit, ¤t_frame, &stackmap_table, CHECK_VERIFY(this)); 1677 } 1678 } // end while 1679 1680 // Make sure that control flow does not fall through end of the method 1681 if (!no_control_flow) { 1682 verify_error(ErrorContext::bad_code(code_length), 1683 "Control flow falls through code end"); 1684 return; 1685 } 1686 } 1687 1688 #undef bad_type_message 1689 1690 char* ClassVerifier::generate_code_data(methodHandle m, u4 code_length, TRAPS) { 1691 char* code_data = NEW_RESOURCE_ARRAY(char, code_length); 1692 memset(code_data, 0, sizeof(char) * code_length); 1693 RawBytecodeStream bcs(m); 1694 | 640 while (!bcs.is_last_bytecode()) { 641 // Check for recursive re-verification before each bytecode. 642 if (was_recursively_verified()) return; 643 644 opcode = bcs.raw_next(); 645 u2 bci = bcs.bci(); 646 647 // Set current frame's offset to bci 648 current_frame.set_offset(bci); 649 current_frame.set_mark(); 650 651 // Make sure every offset in stackmap table point to the beginning to 652 // an instruction. Match current_frame to stackmap_table entry with 653 // the same offset if exists. 654 stackmap_index = verify_stackmap_table( 655 stackmap_index, bci, ¤t_frame, &stackmap_table, 656 no_control_flow, CHECK_VERIFY(this)); 657 658 659 bool this_uninit = false; // Set to true when invokespecial <init> initialized 'this' 660 bool verified_exc_handlers = false; 661 662 // Merge with the next instruction 663 { 664 u2 index; 665 int target; 666 VerificationType type, type2; 667 VerificationType atype; 668 669 #ifndef PRODUCT 670 if (VerboseVerification) { 671 current_frame.print_on(tty); 672 tty->print_cr("offset = %d, opcode = %s", bci, Bytecodes::name(opcode)); 673 } 674 #endif 675 676 // Make sure wide instruction is in correct format 677 if (bcs.is_wide()) { 678 if (opcode != Bytecodes::_iinc && opcode != Bytecodes::_iload && 679 opcode != Bytecodes::_aload && opcode != Bytecodes::_lload && 680 opcode != Bytecodes::_istore && opcode != Bytecodes::_astore && 681 opcode != Bytecodes::_lstore && opcode != Bytecodes::_fload && 682 opcode != Bytecodes::_dload && opcode != Bytecodes::_fstore && 683 opcode != Bytecodes::_dstore) { 684 /* Unreachable? RawBytecodeStream's raw_next() returns 'illegal' 685 * if we encounter a wide instruction that modifies an invalid 686 * opcode (not one of the ones listed above) */ 687 verify_error(ErrorContext::bad_code(bci), "Bad wide instruction"); 688 return; 689 } 690 } 691 692 // Look for possible jump target in exception handlers and see if it 693 // matches current_frame. Do this check here for astore* opcodes because 694 // they can both reference the exception object in a handler and change 695 // the type state. JVM Spec says that the incoming type state should be 696 // used for this check. 697 if (Bytecodes::is_astore(opcode) && bci >= ex_min && bci < ex_max) { 698 verify_exception_handler_targets( 699 bci, this_uninit, ¤t_frame, &stackmap_table, CHECK_VERIFY(this)); 700 verified_exc_handlers = true; 701 } 702 703 switch (opcode) { 704 case Bytecodes::_nop : 705 no_control_flow = false; break; 706 case Bytecodes::_aconst_null : 707 current_frame.push_stack( 708 VerificationType::null_type(), CHECK_VERIFY(this)); 709 no_control_flow = false; break; 710 case Bytecodes::_iconst_m1 : 711 case Bytecodes::_iconst_0 : 712 case Bytecodes::_iconst_1 : 713 case Bytecodes::_iconst_2 : 714 case Bytecodes::_iconst_3 : 715 case Bytecodes::_iconst_4 : 716 case Bytecodes::_iconst_5 : 717 current_frame.push_stack( 718 VerificationType::integer_type(), CHECK_VERIFY(this)); 719 no_control_flow = false; break; 720 case Bytecodes::_lconst_0 : 721 case Bytecodes::_lconst_1 : 722 current_frame.push_stack_2( 1664 VerificationType::integer_type(), CHECK_VERIFY(this)); 1665 } 1666 current_frame.push_stack(new_array_type, CHECK_VERIFY(this)); 1667 no_control_flow = false; break; 1668 } 1669 case Bytecodes::_athrow : 1670 type = VerificationType::reference_type( 1671 vmSymbols::java_lang_Throwable()); 1672 current_frame.pop_stack(type, CHECK_VERIFY(this)); 1673 no_control_flow = true; break; 1674 default: 1675 // We only need to check the valid bytecodes in class file. 1676 // And jsr and ret are not in the new class file format in JDK1.5. 1677 verify_error(ErrorContext::bad_code(bci), 1678 "Bad instruction: %02x", opcode); 1679 no_control_flow = false; 1680 return; 1681 } // end switch 1682 } // end Merge with the next instruction 1683 1684 // Look for possible jump target in exception handlers and see if it matches 1685 // current_frame. Don't do this check if it has already been done (for 1686 // astore* opcodes). This check cannot be done earlier because opcodes, 1687 // such as invokespecial, may set the this_uninit flag. 1688 assert(!(verified_exc_handlers && this_uninit), 1689 "Exception handler targets got verified before this_uninit got set"); 1690 if (!verified_exc_handlers && bci >= ex_min && bci < ex_max) { 1691 verify_exception_handler_targets( 1692 bci, this_uninit, ¤t_frame, &stackmap_table, CHECK_VERIFY(this)); 1693 } 1694 } // end while 1695 1696 // Make sure that control flow does not fall through end of the method 1697 if (!no_control_flow) { 1698 verify_error(ErrorContext::bad_code(code_length), 1699 "Control flow falls through code end"); 1700 return; 1701 } 1702 } 1703 1704 #undef bad_type_message 1705 1706 char* ClassVerifier::generate_code_data(methodHandle m, u4 code_length, TRAPS) { 1707 char* code_data = NEW_RESOURCE_ARRAY(char, code_length); 1708 memset(code_data, 0, sizeof(char) * code_length); 1709 RawBytecodeStream bcs(m); 1710 |