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*, dstore*, 694 // fstore*, istore*, and lstore* opcodes because they can change the type 695 // state by adding a local. JVM Spec says that the incoming type state 696 // should be used for this check. So, do the check here before a possible 697 // local is added to the type state. 698 if (Bytecodes::is_store_into_local(opcode) && bci >= ex_min && bci < ex_max) { 699 verify_exception_handler_targets( 700 bci, this_uninit, ¤t_frame, &stackmap_table, CHECK_VERIFY(this)); 701 verified_exc_handlers = true; 702 } 703 704 switch (opcode) { 705 case Bytecodes::_nop : 706 no_control_flow = false; break; 707 case Bytecodes::_aconst_null : 708 current_frame.push_stack( 709 VerificationType::null_type(), CHECK_VERIFY(this)); 710 no_control_flow = false; break; 711 case Bytecodes::_iconst_m1 : 712 case Bytecodes::_iconst_0 : 713 case Bytecodes::_iconst_1 : 714 case Bytecodes::_iconst_2 : 715 case Bytecodes::_iconst_3 : 716 case Bytecodes::_iconst_4 : 717 case Bytecodes::_iconst_5 : 718 current_frame.push_stack( 719 VerificationType::integer_type(), CHECK_VERIFY(this)); 720 no_control_flow = false; break; 721 case Bytecodes::_lconst_0 : 722 case Bytecodes::_lconst_1 : 723 current_frame.push_stack_2( 1665 VerificationType::integer_type(), CHECK_VERIFY(this)); 1666 } 1667 current_frame.push_stack(new_array_type, CHECK_VERIFY(this)); 1668 no_control_flow = false; break; 1669 } 1670 case Bytecodes::_athrow : 1671 type = VerificationType::reference_type( 1672 vmSymbols::java_lang_Throwable()); 1673 current_frame.pop_stack(type, CHECK_VERIFY(this)); 1674 no_control_flow = true; break; 1675 default: 1676 // We only need to check the valid bytecodes in class file. 1677 // And jsr and ret are not in the new class file format in JDK1.5. 1678 verify_error(ErrorContext::bad_code(bci), 1679 "Bad instruction: %02x", opcode); 1680 no_control_flow = false; 1681 return; 1682 } // end switch 1683 } // end Merge with the next instruction 1684 1685 // Look for possible jump target in exception handlers and see if it matches 1686 // current_frame. Don't do this check if it has already been done (for 1687 // ([a,d,f,i,l]store* opcodes). This check cannot be done earlier because 1688 // opcodes, such as invokespecial, may set the this_uninit flag. 1689 assert(!(verified_exc_handlers && this_uninit), 1690 "Exception handler targets got verified before this_uninit got set"); 1691 if (!verified_exc_handlers && bci >= ex_min && bci < ex_max) { 1692 verify_exception_handler_targets( 1693 bci, this_uninit, ¤t_frame, &stackmap_table, CHECK_VERIFY(this)); 1694 } 1695 } // end while 1696 1697 // Make sure that control flow does not fall through end of the method 1698 if (!no_control_flow) { 1699 verify_error(ErrorContext::bad_code(code_length), 1700 "Control flow falls through code end"); 1701 return; 1702 } 1703 } 1704 1705 #undef bad_type_message 1706 1707 char* ClassVerifier::generate_code_data(methodHandle m, u4 code_length, TRAPS) { 1708 char* code_data = NEW_RESOURCE_ARRAY(char, code_length); 1709 memset(code_data, 0, sizeof(char) * code_length); 1710 RawBytecodeStream bcs(m); 1711 |