comparison src/share/vm/classfile/verifier.cpp @ 1565:ab102d5d923e

6939207: refactor constant pool index processing Summary: Factored cleanup of instruction decode which prepares for enhanced ldc semantics. Reviewed-by: twisti
author jrose
date Sun, 23 May 2010 01:38:26 -0700
parents 4ce7240d622c
children de91a2f25c7e
comparison
equal deleted inserted replaced
1564:61b2245abf36 1565:ab102d5d923e
1 /* 1 /*
2 * Copyright 1998-2009 Sun Microsystems, Inc. All Rights Reserved. 2 * Copyright 1998-2010 Sun Microsystems, Inc. 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.
408 current_frame.push_stack( 408 current_frame.push_stack(
409 VerificationType::integer_type(), CHECK_VERIFY(this)); 409 VerificationType::integer_type(), CHECK_VERIFY(this));
410 no_control_flow = false; break; 410 no_control_flow = false; break;
411 case Bytecodes::_ldc : 411 case Bytecodes::_ldc :
412 verify_ldc( 412 verify_ldc(
413 opcode, bcs.get_index(), &current_frame, 413 opcode, bcs.get_index_u1(), &current_frame,
414 cp, bci, CHECK_VERIFY(this)); 414 cp, bci, CHECK_VERIFY(this));
415 no_control_flow = false; break; 415 no_control_flow = false; break;
416 case Bytecodes::_ldc_w : 416 case Bytecodes::_ldc_w :
417 case Bytecodes::_ldc2_w : 417 case Bytecodes::_ldc2_w :
418 verify_ldc( 418 verify_ldc(
419 opcode, bcs.get_index_big(), &current_frame, 419 opcode, bcs.get_index_u2(), &current_frame,
420 cp, bci, CHECK_VERIFY(this)); 420 cp, bci, CHECK_VERIFY(this));
421 no_control_flow = false; break; 421 no_control_flow = false; break;
422 case Bytecodes::_iload : 422 case Bytecodes::_iload :
423 verify_iload(bcs.get_index(), &current_frame, CHECK_VERIFY(this)); 423 verify_iload(bcs.get_index(), &current_frame, CHECK_VERIFY(this));
424 no_control_flow = false; break; 424 no_control_flow = false; break;
1180 &bcs, code_length, &current_frame, 1180 &bcs, code_length, &current_frame,
1181 &this_uninit, return_type, cp, CHECK_VERIFY(this)); 1181 &this_uninit, return_type, cp, CHECK_VERIFY(this));
1182 no_control_flow = false; break; 1182 no_control_flow = false; break;
1183 case Bytecodes::_new : 1183 case Bytecodes::_new :
1184 { 1184 {
1185 index = bcs.get_index_big(); 1185 index = bcs.get_index_u2();
1186 verify_cp_class_type(index, cp, CHECK_VERIFY(this)); 1186 verify_cp_class_type(index, cp, CHECK_VERIFY(this));
1187 VerificationType new_class_type = 1187 VerificationType new_class_type =
1188 cp_index_to_type(index, cp, CHECK_VERIFY(this)); 1188 cp_index_to_type(index, cp, CHECK_VERIFY(this));
1189 if (!new_class_type.is_object()) { 1189 if (!new_class_type.is_object()) {
1190 verify_error(bci, "Illegal new instruction"); 1190 verify_error(bci, "Illegal new instruction");
1200 VerificationType::integer_type(), CHECK_VERIFY(this)); 1200 VerificationType::integer_type(), CHECK_VERIFY(this));
1201 current_frame.push_stack(type, CHECK_VERIFY(this)); 1201 current_frame.push_stack(type, CHECK_VERIFY(this));
1202 no_control_flow = false; break; 1202 no_control_flow = false; break;
1203 case Bytecodes::_anewarray : 1203 case Bytecodes::_anewarray :
1204 verify_anewarray( 1204 verify_anewarray(
1205 bcs.get_index_big(), cp, &current_frame, CHECK_VERIFY(this)); 1205 bcs.get_index_u2(), cp, &current_frame, CHECK_VERIFY(this));
1206 no_control_flow = false; break; 1206 no_control_flow = false; break;
1207 case Bytecodes::_arraylength : 1207 case Bytecodes::_arraylength :
1208 type = current_frame.pop_stack( 1208 type = current_frame.pop_stack(
1209 VerificationType::reference_check(), CHECK_VERIFY(this)); 1209 VerificationType::reference_check(), CHECK_VERIFY(this));
1210 if (!(type.is_null() || type.is_array())) { 1210 if (!(type.is_null() || type.is_array())) {
1213 current_frame.push_stack( 1213 current_frame.push_stack(
1214 VerificationType::integer_type(), CHECK_VERIFY(this)); 1214 VerificationType::integer_type(), CHECK_VERIFY(this));
1215 no_control_flow = false; break; 1215 no_control_flow = false; break;
1216 case Bytecodes::_checkcast : 1216 case Bytecodes::_checkcast :
1217 { 1217 {
1218 index = bcs.get_index_big(); 1218 index = bcs.get_index_u2();
1219 verify_cp_class_type(index, cp, CHECK_VERIFY(this)); 1219 verify_cp_class_type(index, cp, CHECK_VERIFY(this));
1220 current_frame.pop_stack( 1220 current_frame.pop_stack(
1221 VerificationType::reference_check(), CHECK_VERIFY(this)); 1221 VerificationType::reference_check(), CHECK_VERIFY(this));
1222 VerificationType klass_type = cp_index_to_type( 1222 VerificationType klass_type = cp_index_to_type(
1223 index, cp, CHECK_VERIFY(this)); 1223 index, cp, CHECK_VERIFY(this));
1224 current_frame.push_stack(klass_type, CHECK_VERIFY(this)); 1224 current_frame.push_stack(klass_type, CHECK_VERIFY(this));
1225 no_control_flow = false; break; 1225 no_control_flow = false; break;
1226 } 1226 }
1227 case Bytecodes::_instanceof : { 1227 case Bytecodes::_instanceof : {
1228 index = bcs.get_index_big(); 1228 index = bcs.get_index_u2();
1229 verify_cp_class_type(index, cp, CHECK_VERIFY(this)); 1229 verify_cp_class_type(index, cp, CHECK_VERIFY(this));
1230 current_frame.pop_stack( 1230 current_frame.pop_stack(
1231 VerificationType::reference_check(), CHECK_VERIFY(this)); 1231 VerificationType::reference_check(), CHECK_VERIFY(this));
1232 current_frame.push_stack( 1232 current_frame.push_stack(
1233 VerificationType::integer_type(), CHECK_VERIFY(this)); 1233 VerificationType::integer_type(), CHECK_VERIFY(this));
1238 current_frame.pop_stack( 1238 current_frame.pop_stack(
1239 VerificationType::reference_check(), CHECK_VERIFY(this)); 1239 VerificationType::reference_check(), CHECK_VERIFY(this));
1240 no_control_flow = false; break; 1240 no_control_flow = false; break;
1241 case Bytecodes::_multianewarray : 1241 case Bytecodes::_multianewarray :
1242 { 1242 {
1243 index = bcs.get_index_big(); 1243 index = bcs.get_index_u2();
1244 u2 dim = *(bcs.bcp()+3); 1244 u2 dim = *(bcs.bcp()+3);
1245 verify_cp_class_type(index, cp, CHECK_VERIFY(this)); 1245 verify_cp_class_type(index, cp, CHECK_VERIFY(this));
1246 VerificationType new_array_type = 1246 VerificationType new_array_type =
1247 cp_index_to_type(index, cp, CHECK_VERIFY(this)); 1247 cp_index_to_type(index, cp, CHECK_VERIFY(this));
1248 if (!new_array_type.is_array()) { 1248 if (!new_array_type.is_array()) {
1297 RawBytecodeStream bcs(m); 1297 RawBytecodeStream bcs(m);
1298 1298
1299 while (!bcs.is_last_bytecode()) { 1299 while (!bcs.is_last_bytecode()) {
1300 if (bcs.raw_next() != Bytecodes::_illegal) { 1300 if (bcs.raw_next() != Bytecodes::_illegal) {
1301 int bci = bcs.bci(); 1301 int bci = bcs.bci();
1302 if (bcs.code() == Bytecodes::_new) { 1302 if (bcs.raw_code() == Bytecodes::_new) {
1303 code_data[bci] = NEW_OFFSET; 1303 code_data[bci] = NEW_OFFSET;
1304 } else { 1304 } else {
1305 code_data[bci] = BYTECODE_OFFSET; 1305 code_data[bci] = BYTECODE_OFFSET;
1306 } 1306 }
1307 } else { 1307 } else {
1652 } 1652 }
1653 int default_offset = (int) Bytes::get_Java_u4(aligned_bcp); 1653 int default_offset = (int) Bytes::get_Java_u4(aligned_bcp);
1654 int keys, delta; 1654 int keys, delta;
1655 current_frame->pop_stack( 1655 current_frame->pop_stack(
1656 VerificationType::integer_type(), CHECK_VERIFY(this)); 1656 VerificationType::integer_type(), CHECK_VERIFY(this));
1657 if (bcs->code() == Bytecodes::_tableswitch) { 1657 if (bcs->raw_code() == Bytecodes::_tableswitch) {
1658 jint low = (jint)Bytes::get_Java_u4(aligned_bcp + jintSize); 1658 jint low = (jint)Bytes::get_Java_u4(aligned_bcp + jintSize);
1659 jint high = (jint)Bytes::get_Java_u4(aligned_bcp + 2*jintSize); 1659 jint high = (jint)Bytes::get_Java_u4(aligned_bcp + 2*jintSize);
1660 if (low > high) { 1660 if (low > high) {
1661 verify_error(bci, 1661 verify_error(bci,
1662 "low must be less than or equal to high in tableswitch"); 1662 "low must be less than or equal to high in tableswitch");
1708 1708
1709 void ClassVerifier::verify_field_instructions(RawBytecodeStream* bcs, 1709 void ClassVerifier::verify_field_instructions(RawBytecodeStream* bcs,
1710 StackMapFrame* current_frame, 1710 StackMapFrame* current_frame,
1711 constantPoolHandle cp, 1711 constantPoolHandle cp,
1712 TRAPS) { 1712 TRAPS) {
1713 u2 index = bcs->get_index_big(); 1713 u2 index = bcs->get_index_u2();
1714 verify_cp_type(index, cp, 1 << JVM_CONSTANT_Fieldref, CHECK_VERIFY(this)); 1714 verify_cp_type(index, cp, 1 << JVM_CONSTANT_Fieldref, CHECK_VERIFY(this));
1715 1715
1716 // Get field name and signature 1716 // Get field name and signature
1717 symbolHandle field_name = symbolHandle(THREAD, cp->name_ref_at(index)); 1717 symbolHandle field_name = symbolHandle(THREAD, cp->name_ref_at(index));
1718 symbolHandle field_sig = symbolHandle(THREAD, cp->signature_ref_at(index)); 1718 symbolHandle field_sig = symbolHandle(THREAD, cp->signature_ref_at(index));
1748 VerificationType stack_object_type; 1748 VerificationType stack_object_type;
1749 int n = change_sig_to_verificationType( 1749 int n = change_sig_to_verificationType(
1750 &sig_stream, field_type, CHECK_VERIFY(this)); 1750 &sig_stream, field_type, CHECK_VERIFY(this));
1751 u2 bci = bcs->bci(); 1751 u2 bci = bcs->bci();
1752 bool is_assignable; 1752 bool is_assignable;
1753 switch (bcs->code()) { 1753 switch (bcs->raw_code()) {
1754 case Bytecodes::_getstatic: { 1754 case Bytecodes::_getstatic: {
1755 for (int i = 0; i < n; i++) { 1755 for (int i = 0; i < n; i++) {
1756 current_frame->push_stack(field_type[i], CHECK_VERIFY(this)); 1756 current_frame->push_stack(field_type[i], CHECK_VERIFY(this));
1757 } 1757 }
1758 break; 1758 break;
1868 if (name_in_supers(ref_class_type.name(), current_class())) { 1868 if (name_in_supers(ref_class_type.name(), current_class())) {
1869 klassOop ref_klass = load_class( 1869 klassOop ref_klass = load_class(
1870 ref_class_type.name(), CHECK_VERIFY(this)); 1870 ref_class_type.name(), CHECK_VERIFY(this));
1871 methodOop m = instanceKlass::cast(ref_klass)->uncached_lookup_method( 1871 methodOop m = instanceKlass::cast(ref_klass)->uncached_lookup_method(
1872 vmSymbols::object_initializer_name(), 1872 vmSymbols::object_initializer_name(),
1873 cp->signature_ref_at(bcs->get_index_big())); 1873 cp->signature_ref_at(bcs->get_index_u2()));
1874 instanceKlassHandle mh(THREAD, m->method_holder()); 1874 instanceKlassHandle mh(THREAD, m->method_holder());
1875 if (m->is_protected() && !mh->is_same_class_package(_klass())) { 1875 if (m->is_protected() && !mh->is_same_class_package(_klass())) {
1876 bool assignable = current_type().is_assignable_from( 1876 bool assignable = current_type().is_assignable_from(
1877 objectref_type, current_class(), CHECK_VERIFY(this)); 1877 objectref_type, current_class(), CHECK_VERIFY(this));
1878 if (!assignable) { 1878 if (!assignable) {
1891 void ClassVerifier::verify_invoke_instructions( 1891 void ClassVerifier::verify_invoke_instructions(
1892 RawBytecodeStream* bcs, u4 code_length, StackMapFrame* current_frame, 1892 RawBytecodeStream* bcs, u4 code_length, StackMapFrame* current_frame,
1893 bool *this_uninit, VerificationType return_type, 1893 bool *this_uninit, VerificationType return_type,
1894 constantPoolHandle cp, TRAPS) { 1894 constantPoolHandle cp, TRAPS) {
1895 // Make sure the constant pool item is the right type 1895 // Make sure the constant pool item is the right type
1896 u2 index = bcs->get_index_big(); 1896 u2 index = bcs->get_index_u2();
1897 Bytecodes::Code opcode = bcs->code(); 1897 Bytecodes::Code opcode = bcs->raw_code();
1898 unsigned int types = (opcode == Bytecodes::_invokeinterface 1898 unsigned int types = (opcode == Bytecodes::_invokeinterface
1899 ? 1 << JVM_CONSTANT_InterfaceMethodref 1899 ? 1 << JVM_CONSTANT_InterfaceMethodref
1900 : opcode == Bytecodes::_invokedynamic 1900 : opcode == Bytecodes::_invokedynamic
1901 ? 1 << JVM_CONSTANT_NameAndType 1901 ? 1 << JVM_CONSTANT_NameAndType
1902 : 1 << JVM_CONSTANT_Methodref); 1902 : 1 << JVM_CONSTANT_Methodref);