Mercurial > hg > graal-compiler
comparison src/share/vm/classfile/verifier.cpp @ 1579:e9ff18c4ace7
Merge
author | jrose |
---|---|
date | Wed, 02 Jun 2010 22:45:42 -0700 |
parents | dfe27f03244a de91a2f25c7e |
children | 136b78722a08 |
comparison
equal
deleted
inserted
replaced
1562:dfe27f03244a | 1579:e9ff18c4ace7 |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 1998, 2009, Oracle and/or its affiliates. All rights reserved. | 2 * Copyright (c) 1998, 2010, 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. |
255 | 255 |
256 objArrayHandle methods(THREAD, _klass->methods()); | 256 objArrayHandle methods(THREAD, _klass->methods()); |
257 int num_methods = methods->length(); | 257 int num_methods = methods->length(); |
258 | 258 |
259 for (int index = 0; index < num_methods; index++) { | 259 for (int index = 0; index < num_methods; index++) { |
260 // Check for recursive re-verification before each method. | |
261 if (was_recursively_verified()) return; | |
262 | |
260 methodOop m = (methodOop)methods->obj_at(index); | 263 methodOop m = (methodOop)methods->obj_at(index); |
261 if (m->is_native() || m->is_abstract()) { | 264 if (m->is_native() || m->is_abstract()) { |
262 // If m is native or abstract, skip it. It is checked in class file | 265 // If m is native or abstract, skip it. It is checked in class file |
263 // parser that methods do not override a final method. | 266 // parser that methods do not override a final method. |
264 continue; | 267 continue; |
265 } | 268 } |
266 verify_method(methodHandle(THREAD, m), CHECK_VERIFY(this)); | 269 verify_method(methodHandle(THREAD, m), CHECK_VERIFY(this)); |
270 } | |
271 | |
272 if (_verify_verbose || TraceClassInitialization) { | |
273 if (was_recursively_verified()) | |
274 tty->print_cr("Recursive verification detected for: %s", | |
275 _klass->external_name()); | |
267 } | 276 } |
268 } | 277 } |
269 | 278 |
270 void ClassVerifier::verify_method(methodHandle m, TRAPS) { | 279 void ClassVerifier::verify_method(methodHandle m, TRAPS) { |
271 ResourceMark rm(THREAD); | 280 ResourceMark rm(THREAD); |
327 bool no_control_flow = false; // Set to true when there is no direct control | 336 bool no_control_flow = false; // Set to true when there is no direct control |
328 // flow from current instruction to the next | 337 // flow from current instruction to the next |
329 // instruction in sequence | 338 // instruction in sequence |
330 Bytecodes::Code opcode; | 339 Bytecodes::Code opcode; |
331 while (!bcs.is_last_bytecode()) { | 340 while (!bcs.is_last_bytecode()) { |
341 // Check for recursive re-verification before each bytecode. | |
342 if (was_recursively_verified()) return; | |
343 | |
332 opcode = bcs.raw_next(); | 344 opcode = bcs.raw_next(); |
333 u2 bci = bcs.bci(); | 345 u2 bci = bcs.bci(); |
334 | 346 |
335 // Set current frame's offset to bci | 347 // Set current frame's offset to bci |
336 current_frame.set_offset(bci); | 348 current_frame.set_offset(bci); |
411 current_frame.push_stack( | 423 current_frame.push_stack( |
412 VerificationType::integer_type(), CHECK_VERIFY(this)); | 424 VerificationType::integer_type(), CHECK_VERIFY(this)); |
413 no_control_flow = false; break; | 425 no_control_flow = false; break; |
414 case Bytecodes::_ldc : | 426 case Bytecodes::_ldc : |
415 verify_ldc( | 427 verify_ldc( |
416 opcode, bcs.get_index(), ¤t_frame, | 428 opcode, bcs.get_index_u1(), ¤t_frame, |
417 cp, bci, CHECK_VERIFY(this)); | 429 cp, bci, CHECK_VERIFY(this)); |
418 no_control_flow = false; break; | 430 no_control_flow = false; break; |
419 case Bytecodes::_ldc_w : | 431 case Bytecodes::_ldc_w : |
420 case Bytecodes::_ldc2_w : | 432 case Bytecodes::_ldc2_w : |
421 verify_ldc( | 433 verify_ldc( |
422 opcode, bcs.get_index_big(), ¤t_frame, | 434 opcode, bcs.get_index_u2(), ¤t_frame, |
423 cp, bci, CHECK_VERIFY(this)); | 435 cp, bci, CHECK_VERIFY(this)); |
424 no_control_flow = false; break; | 436 no_control_flow = false; break; |
425 case Bytecodes::_iload : | 437 case Bytecodes::_iload : |
426 verify_iload(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); | 438 verify_iload(bcs.get_index(), ¤t_frame, CHECK_VERIFY(this)); |
427 no_control_flow = false; break; | 439 no_control_flow = false; break; |
1183 &bcs, code_length, ¤t_frame, | 1195 &bcs, code_length, ¤t_frame, |
1184 &this_uninit, return_type, cp, CHECK_VERIFY(this)); | 1196 &this_uninit, return_type, cp, CHECK_VERIFY(this)); |
1185 no_control_flow = false; break; | 1197 no_control_flow = false; break; |
1186 case Bytecodes::_new : | 1198 case Bytecodes::_new : |
1187 { | 1199 { |
1188 index = bcs.get_index_big(); | 1200 index = bcs.get_index_u2(); |
1189 verify_cp_class_type(index, cp, CHECK_VERIFY(this)); | 1201 verify_cp_class_type(index, cp, CHECK_VERIFY(this)); |
1190 VerificationType new_class_type = | 1202 VerificationType new_class_type = |
1191 cp_index_to_type(index, cp, CHECK_VERIFY(this)); | 1203 cp_index_to_type(index, cp, CHECK_VERIFY(this)); |
1192 if (!new_class_type.is_object()) { | 1204 if (!new_class_type.is_object()) { |
1193 verify_error(bci, "Illegal new instruction"); | 1205 verify_error(bci, "Illegal new instruction"); |
1203 VerificationType::integer_type(), CHECK_VERIFY(this)); | 1215 VerificationType::integer_type(), CHECK_VERIFY(this)); |
1204 current_frame.push_stack(type, CHECK_VERIFY(this)); | 1216 current_frame.push_stack(type, CHECK_VERIFY(this)); |
1205 no_control_flow = false; break; | 1217 no_control_flow = false; break; |
1206 case Bytecodes::_anewarray : | 1218 case Bytecodes::_anewarray : |
1207 verify_anewarray( | 1219 verify_anewarray( |
1208 bcs.get_index_big(), cp, ¤t_frame, CHECK_VERIFY(this)); | 1220 bcs.get_index_u2(), cp, ¤t_frame, CHECK_VERIFY(this)); |
1209 no_control_flow = false; break; | 1221 no_control_flow = false; break; |
1210 case Bytecodes::_arraylength : | 1222 case Bytecodes::_arraylength : |
1211 type = current_frame.pop_stack( | 1223 type = current_frame.pop_stack( |
1212 VerificationType::reference_check(), CHECK_VERIFY(this)); | 1224 VerificationType::reference_check(), CHECK_VERIFY(this)); |
1213 if (!(type.is_null() || type.is_array())) { | 1225 if (!(type.is_null() || type.is_array())) { |
1216 current_frame.push_stack( | 1228 current_frame.push_stack( |
1217 VerificationType::integer_type(), CHECK_VERIFY(this)); | 1229 VerificationType::integer_type(), CHECK_VERIFY(this)); |
1218 no_control_flow = false; break; | 1230 no_control_flow = false; break; |
1219 case Bytecodes::_checkcast : | 1231 case Bytecodes::_checkcast : |
1220 { | 1232 { |
1221 index = bcs.get_index_big(); | 1233 index = bcs.get_index_u2(); |
1222 verify_cp_class_type(index, cp, CHECK_VERIFY(this)); | 1234 verify_cp_class_type(index, cp, CHECK_VERIFY(this)); |
1223 current_frame.pop_stack( | 1235 current_frame.pop_stack( |
1224 VerificationType::reference_check(), CHECK_VERIFY(this)); | 1236 VerificationType::reference_check(), CHECK_VERIFY(this)); |
1225 VerificationType klass_type = cp_index_to_type( | 1237 VerificationType klass_type = cp_index_to_type( |
1226 index, cp, CHECK_VERIFY(this)); | 1238 index, cp, CHECK_VERIFY(this)); |
1227 current_frame.push_stack(klass_type, CHECK_VERIFY(this)); | 1239 current_frame.push_stack(klass_type, CHECK_VERIFY(this)); |
1228 no_control_flow = false; break; | 1240 no_control_flow = false; break; |
1229 } | 1241 } |
1230 case Bytecodes::_instanceof : { | 1242 case Bytecodes::_instanceof : { |
1231 index = bcs.get_index_big(); | 1243 index = bcs.get_index_u2(); |
1232 verify_cp_class_type(index, cp, CHECK_VERIFY(this)); | 1244 verify_cp_class_type(index, cp, CHECK_VERIFY(this)); |
1233 current_frame.pop_stack( | 1245 current_frame.pop_stack( |
1234 VerificationType::reference_check(), CHECK_VERIFY(this)); | 1246 VerificationType::reference_check(), CHECK_VERIFY(this)); |
1235 current_frame.push_stack( | 1247 current_frame.push_stack( |
1236 VerificationType::integer_type(), CHECK_VERIFY(this)); | 1248 VerificationType::integer_type(), CHECK_VERIFY(this)); |
1241 current_frame.pop_stack( | 1253 current_frame.pop_stack( |
1242 VerificationType::reference_check(), CHECK_VERIFY(this)); | 1254 VerificationType::reference_check(), CHECK_VERIFY(this)); |
1243 no_control_flow = false; break; | 1255 no_control_flow = false; break; |
1244 case Bytecodes::_multianewarray : | 1256 case Bytecodes::_multianewarray : |
1245 { | 1257 { |
1246 index = bcs.get_index_big(); | 1258 index = bcs.get_index_u2(); |
1247 u2 dim = *(bcs.bcp()+3); | 1259 u2 dim = *(bcs.bcp()+3); |
1248 verify_cp_class_type(index, cp, CHECK_VERIFY(this)); | 1260 verify_cp_class_type(index, cp, CHECK_VERIFY(this)); |
1249 VerificationType new_array_type = | 1261 VerificationType new_array_type = |
1250 cp_index_to_type(index, cp, CHECK_VERIFY(this)); | 1262 cp_index_to_type(index, cp, CHECK_VERIFY(this)); |
1251 if (!new_array_type.is_array()) { | 1263 if (!new_array_type.is_array()) { |
1300 RawBytecodeStream bcs(m); | 1312 RawBytecodeStream bcs(m); |
1301 | 1313 |
1302 while (!bcs.is_last_bytecode()) { | 1314 while (!bcs.is_last_bytecode()) { |
1303 if (bcs.raw_next() != Bytecodes::_illegal) { | 1315 if (bcs.raw_next() != Bytecodes::_illegal) { |
1304 int bci = bcs.bci(); | 1316 int bci = bcs.bci(); |
1305 if (bcs.code() == Bytecodes::_new) { | 1317 if (bcs.raw_code() == Bytecodes::_new) { |
1306 code_data[bci] = NEW_OFFSET; | 1318 code_data[bci] = NEW_OFFSET; |
1307 } else { | 1319 } else { |
1308 code_data[bci] = BYTECODE_OFFSET; | 1320 code_data[bci] = BYTECODE_OFFSET; |
1309 } | 1321 } |
1310 } else { | 1322 } else { |
1471 void ClassVerifier::verify_cp_type( | 1483 void ClassVerifier::verify_cp_type( |
1472 int index, constantPoolHandle cp, unsigned int types, TRAPS) { | 1484 int index, constantPoolHandle cp, unsigned int types, TRAPS) { |
1473 | 1485 |
1474 // In some situations, bytecode rewriting may occur while we're verifying. | 1486 // In some situations, bytecode rewriting may occur while we're verifying. |
1475 // In this case, a constant pool cache exists and some indices refer to that | 1487 // In this case, a constant pool cache exists and some indices refer to that |
1476 // instead. Get the original index for the tag check | 1488 // instead. Be sure we don't pick up such indices by accident. |
1477 constantPoolCacheOop cache = cp->cache(); | 1489 // We must check was_recursively_verified() before we get here. |
1478 if (cache != NULL && | 1490 guarantee(cp->cache() == NULL, "not rewritten yet"); |
1479 ((types == (1 << JVM_CONSTANT_InterfaceMethodref)) || | |
1480 (types == (1 << JVM_CONSTANT_Methodref)) || | |
1481 (types == (1 << JVM_CONSTANT_Fieldref)))) { | |
1482 int native_index = index; | |
1483 if (Bytes::is_Java_byte_ordering_different()) { | |
1484 native_index = Bytes::swap_u2(index); | |
1485 } | |
1486 assert((native_index >= 0) && (native_index < cache->length()), | |
1487 "Must be a legal index into the cp cache"); | |
1488 index = cache->entry_at(native_index)->constant_pool_index(); | |
1489 } | |
1490 | 1491 |
1491 verify_cp_index(cp, index, CHECK_VERIFY(this)); | 1492 verify_cp_index(cp, index, CHECK_VERIFY(this)); |
1492 unsigned int tag = cp->tag_at(index).value(); | 1493 unsigned int tag = cp->tag_at(index).value(); |
1493 if ((types & (1 << tag)) == 0) { | 1494 if ((types & (1 << tag)) == 0) { |
1494 verify_error( | 1495 verify_error( |
1655 } | 1656 } |
1656 int default_offset = (int) Bytes::get_Java_u4(aligned_bcp); | 1657 int default_offset = (int) Bytes::get_Java_u4(aligned_bcp); |
1657 int keys, delta; | 1658 int keys, delta; |
1658 current_frame->pop_stack( | 1659 current_frame->pop_stack( |
1659 VerificationType::integer_type(), CHECK_VERIFY(this)); | 1660 VerificationType::integer_type(), CHECK_VERIFY(this)); |
1660 if (bcs->code() == Bytecodes::_tableswitch) { | 1661 if (bcs->raw_code() == Bytecodes::_tableswitch) { |
1661 jint low = (jint)Bytes::get_Java_u4(aligned_bcp + jintSize); | 1662 jint low = (jint)Bytes::get_Java_u4(aligned_bcp + jintSize); |
1662 jint high = (jint)Bytes::get_Java_u4(aligned_bcp + 2*jintSize); | 1663 jint high = (jint)Bytes::get_Java_u4(aligned_bcp + 2*jintSize); |
1663 if (low > high) { | 1664 if (low > high) { |
1664 verify_error(bci, | 1665 verify_error(bci, |
1665 "low must be less than or equal to high in tableswitch"); | 1666 "low must be less than or equal to high in tableswitch"); |
1711 | 1712 |
1712 void ClassVerifier::verify_field_instructions(RawBytecodeStream* bcs, | 1713 void ClassVerifier::verify_field_instructions(RawBytecodeStream* bcs, |
1713 StackMapFrame* current_frame, | 1714 StackMapFrame* current_frame, |
1714 constantPoolHandle cp, | 1715 constantPoolHandle cp, |
1715 TRAPS) { | 1716 TRAPS) { |
1716 u2 index = bcs->get_index_big(); | 1717 u2 index = bcs->get_index_u2(); |
1717 verify_cp_type(index, cp, 1 << JVM_CONSTANT_Fieldref, CHECK_VERIFY(this)); | 1718 verify_cp_type(index, cp, 1 << JVM_CONSTANT_Fieldref, CHECK_VERIFY(this)); |
1718 | 1719 |
1719 // Get field name and signature | 1720 // Get field name and signature |
1720 symbolHandle field_name = symbolHandle(THREAD, cp->name_ref_at(index)); | 1721 symbolHandle field_name = symbolHandle(THREAD, cp->name_ref_at(index)); |
1721 symbolHandle field_sig = symbolHandle(THREAD, cp->signature_ref_at(index)); | 1722 symbolHandle field_sig = symbolHandle(THREAD, cp->signature_ref_at(index)); |
1751 VerificationType stack_object_type; | 1752 VerificationType stack_object_type; |
1752 int n = change_sig_to_verificationType( | 1753 int n = change_sig_to_verificationType( |
1753 &sig_stream, field_type, CHECK_VERIFY(this)); | 1754 &sig_stream, field_type, CHECK_VERIFY(this)); |
1754 u2 bci = bcs->bci(); | 1755 u2 bci = bcs->bci(); |
1755 bool is_assignable; | 1756 bool is_assignable; |
1756 switch (bcs->code()) { | 1757 switch (bcs->raw_code()) { |
1757 case Bytecodes::_getstatic: { | 1758 case Bytecodes::_getstatic: { |
1758 for (int i = 0; i < n; i++) { | 1759 for (int i = 0; i < n; i++) { |
1759 current_frame->push_stack(field_type[i], CHECK_VERIFY(this)); | 1760 current_frame->push_stack(field_type[i], CHECK_VERIFY(this)); |
1760 } | 1761 } |
1761 break; | 1762 break; |
1871 if (name_in_supers(ref_class_type.name(), current_class())) { | 1872 if (name_in_supers(ref_class_type.name(), current_class())) { |
1872 klassOop ref_klass = load_class( | 1873 klassOop ref_klass = load_class( |
1873 ref_class_type.name(), CHECK_VERIFY(this)); | 1874 ref_class_type.name(), CHECK_VERIFY(this)); |
1874 methodOop m = instanceKlass::cast(ref_klass)->uncached_lookup_method( | 1875 methodOop m = instanceKlass::cast(ref_klass)->uncached_lookup_method( |
1875 vmSymbols::object_initializer_name(), | 1876 vmSymbols::object_initializer_name(), |
1876 cp->signature_ref_at(bcs->get_index_big())); | 1877 cp->signature_ref_at(bcs->get_index_u2())); |
1877 instanceKlassHandle mh(THREAD, m->method_holder()); | 1878 instanceKlassHandle mh(THREAD, m->method_holder()); |
1878 if (m->is_protected() && !mh->is_same_class_package(_klass())) { | 1879 if (m->is_protected() && !mh->is_same_class_package(_klass())) { |
1879 bool assignable = current_type().is_assignable_from( | 1880 bool assignable = current_type().is_assignable_from( |
1880 objectref_type, current_class(), CHECK_VERIFY(this)); | 1881 objectref_type, current_class(), CHECK_VERIFY(this)); |
1881 if (!assignable) { | 1882 if (!assignable) { |
1894 void ClassVerifier::verify_invoke_instructions( | 1895 void ClassVerifier::verify_invoke_instructions( |
1895 RawBytecodeStream* bcs, u4 code_length, StackMapFrame* current_frame, | 1896 RawBytecodeStream* bcs, u4 code_length, StackMapFrame* current_frame, |
1896 bool *this_uninit, VerificationType return_type, | 1897 bool *this_uninit, VerificationType return_type, |
1897 constantPoolHandle cp, TRAPS) { | 1898 constantPoolHandle cp, TRAPS) { |
1898 // Make sure the constant pool item is the right type | 1899 // Make sure the constant pool item is the right type |
1899 u2 index = bcs->get_index_big(); | 1900 u2 index = bcs->get_index_u2(); |
1900 Bytecodes::Code opcode = bcs->code(); | 1901 Bytecodes::Code opcode = bcs->raw_code(); |
1901 unsigned int types = (opcode == Bytecodes::_invokeinterface | 1902 unsigned int types = (opcode == Bytecodes::_invokeinterface |
1902 ? 1 << JVM_CONSTANT_InterfaceMethodref | 1903 ? 1 << JVM_CONSTANT_InterfaceMethodref |
1903 : opcode == Bytecodes::_invokedynamic | 1904 : opcode == Bytecodes::_invokedynamic |
1904 ? 1 << JVM_CONSTANT_NameAndType | 1905 ? 1 << JVM_CONSTANT_NameAndType |
1905 : 1 << JVM_CONSTANT_Methodref); | 1906 : 1 << JVM_CONSTANT_Methodref); |