302 // Copy _current pointer of local copy back to stream().
303 #ifdef ASSERT
304 assert(cfs0->current() == old_current, "non-exclusive use of stream()");
305 #endif
306 cfs0->set_current(cfs1.current());
307 }
308
309 bool inline valid_cp_range(int index, int length) { return (index > 0 && index < length); }
310
311 inline Symbol* check_symbol_at(constantPoolHandle cp, int index) {
312 if (valid_cp_range(index, cp->length()) && cp->tag_at(index).is_utf8())
313 return cp->symbol_at(index);
314 else
315 return NULL;
316 }
317
318 PRAGMA_DIAG_PUSH
319 PRAGMA_FORMAT_NONLITERAL_IGNORED
320 void ClassFileParser::report_assert_property_failure(const char* msg, TRAPS) {
321 ResourceMark rm(THREAD);
322 fatal(err_msg(msg, _class_name->as_C_string()));
323 }
324
325 void ClassFileParser::report_assert_property_failure(const char* msg, int index, TRAPS) {
326 ResourceMark rm(THREAD);
327 fatal(err_msg(msg, index, _class_name->as_C_string()));
328 }
329 PRAGMA_DIAG_POP
330
331 constantPoolHandle ClassFileParser::parse_constant_pool(TRAPS) {
332 ClassFileStream* cfs = stream();
333 constantPoolHandle nullHandle;
334
335 cfs->guarantee_more(3, CHECK_(nullHandle)); // length, first cp tag
336 u2 length = cfs->get_u2_fast();
337 guarantee_property(
338 length >= 1, "Illegal constant pool size %u in class file %s",
339 length, CHECK_(nullHandle));
340 ConstantPool* constant_pool = ConstantPool::allocate(_loader_data, length,
341 CHECK_(nullHandle));
342 _cp = constant_pool; // save in case of errors
343 constantPoolHandle cp (THREAD, constant_pool);
344
345 // parsing constant pool entries
346 parse_constant_pool_entries(length, CHECK_(nullHandle));
347
475 case JVM_CONSTANT_MethodType :
476 {
477 int ref_index = cp->method_type_index_at(index);
478 check_property(valid_symbol_at(ref_index),
479 "Invalid constant pool index %u in class file %s",
480 ref_index, CHECK_(nullHandle));
481 }
482 break;
483 case JVM_CONSTANT_InvokeDynamic :
484 {
485 int name_and_type_ref_index = cp->invoke_dynamic_name_and_type_ref_index_at(index);
486 check_property(valid_cp_range(name_and_type_ref_index, length) &&
487 cp->tag_at(name_and_type_ref_index).is_name_and_type(),
488 "Invalid constant pool index %u in class file %s",
489 name_and_type_ref_index,
490 CHECK_(nullHandle));
491 // bootstrap specifier index must be checked later, when BootstrapMethods attr is available
492 break;
493 }
494 default:
495 fatal(err_msg("bad constant pool tag value %u",
496 cp->tag_at(index).value()));
497 ShouldNotReachHere();
498 break;
499 } // end of switch
500 } // end of for
501
502 if (_cp_patches != NULL) {
503 // need to treat this_class specially...
504 int this_class_index;
505 {
506 cfs->guarantee_more(8, CHECK_(nullHandle)); // flags, this_class, super_class, infs_len
507 u1* mark = cfs->current();
508 u2 flags = cfs->get_u2_fast();
509 this_class_index = cfs->get_u2_fast();
510 cfs->set_current(mark); // revert to mark
511 }
512
513 for (index = 1; index < length; index++) { // Index 0 is unused
514 if (has_cp_patch_at(index)) {
515 guarantee_property(index != this_class_index,
516 "Illegal constant pool patch to self at %d in class file %s",
|
302 // Copy _current pointer of local copy back to stream().
303 #ifdef ASSERT
304 assert(cfs0->current() == old_current, "non-exclusive use of stream()");
305 #endif
306 cfs0->set_current(cfs1.current());
307 }
308
309 bool inline valid_cp_range(int index, int length) { return (index > 0 && index < length); }
310
311 inline Symbol* check_symbol_at(constantPoolHandle cp, int index) {
312 if (valid_cp_range(index, cp->length()) && cp->tag_at(index).is_utf8())
313 return cp->symbol_at(index);
314 else
315 return NULL;
316 }
317
318 PRAGMA_DIAG_PUSH
319 PRAGMA_FORMAT_NONLITERAL_IGNORED
320 void ClassFileParser::report_assert_property_failure(const char* msg, TRAPS) {
321 ResourceMark rm(THREAD);
322 fatal(msg, _class_name->as_C_string());
323 }
324
325 void ClassFileParser::report_assert_property_failure(const char* msg, int index, TRAPS) {
326 ResourceMark rm(THREAD);
327 fatal(msg, index, _class_name->as_C_string());
328 }
329 PRAGMA_DIAG_POP
330
331 constantPoolHandle ClassFileParser::parse_constant_pool(TRAPS) {
332 ClassFileStream* cfs = stream();
333 constantPoolHandle nullHandle;
334
335 cfs->guarantee_more(3, CHECK_(nullHandle)); // length, first cp tag
336 u2 length = cfs->get_u2_fast();
337 guarantee_property(
338 length >= 1, "Illegal constant pool size %u in class file %s",
339 length, CHECK_(nullHandle));
340 ConstantPool* constant_pool = ConstantPool::allocate(_loader_data, length,
341 CHECK_(nullHandle));
342 _cp = constant_pool; // save in case of errors
343 constantPoolHandle cp (THREAD, constant_pool);
344
345 // parsing constant pool entries
346 parse_constant_pool_entries(length, CHECK_(nullHandle));
347
475 case JVM_CONSTANT_MethodType :
476 {
477 int ref_index = cp->method_type_index_at(index);
478 check_property(valid_symbol_at(ref_index),
479 "Invalid constant pool index %u in class file %s",
480 ref_index, CHECK_(nullHandle));
481 }
482 break;
483 case JVM_CONSTANT_InvokeDynamic :
484 {
485 int name_and_type_ref_index = cp->invoke_dynamic_name_and_type_ref_index_at(index);
486 check_property(valid_cp_range(name_and_type_ref_index, length) &&
487 cp->tag_at(name_and_type_ref_index).is_name_and_type(),
488 "Invalid constant pool index %u in class file %s",
489 name_and_type_ref_index,
490 CHECK_(nullHandle));
491 // bootstrap specifier index must be checked later, when BootstrapMethods attr is available
492 break;
493 }
494 default:
495 fatal("bad constant pool tag value %u", cp->tag_at(index).value());
496 ShouldNotReachHere();
497 break;
498 } // end of switch
499 } // end of for
500
501 if (_cp_patches != NULL) {
502 // need to treat this_class specially...
503 int this_class_index;
504 {
505 cfs->guarantee_more(8, CHECK_(nullHandle)); // flags, this_class, super_class, infs_len
506 u1* mark = cfs->current();
507 u2 flags = cfs->get_u2_fast();
508 this_class_index = cfs->get_u2_fast();
509 cfs->set_current(mark); // revert to mark
510 }
511
512 for (index = 1; index < length; index++) { // Index 0 is unused
513 if (has_cp_patch_at(index)) {
514 guarantee_property(index != this_class_index,
515 "Illegal constant pool patch to self at %d in class file %s",
|