-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8366498: Simplify ClassFileParser::parse_super_class #27026
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
d353bfe
dec4af7
256716f
8390278
4422804
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3803,39 +3803,33 @@ AnnotationArray* ClassFileParser::allocate_annotations(const u1* const anno, | |
return annotations; | ||
} | ||
|
||
const InstanceKlass* ClassFileParser::parse_super_class(ConstantPool* const cp, | ||
const int super_class_index, | ||
const bool need_verify, | ||
TRAPS) { | ||
void ClassFileParser::check_super_class(ConstantPool* const cp, | ||
const int super_class_index, | ||
const bool need_verify, | ||
TRAPS) { | ||
assert(cp != nullptr, "invariant"); | ||
const InstanceKlass* super_klass = nullptr; | ||
|
||
if (super_class_index == 0) { | ||
guarantee_property(_class_name == vmSymbols::java_lang_Object(), | ||
"Invalid superclass index %u in class file %s", | ||
super_class_index, | ||
CHECK_NULL); | ||
CHECK); | ||
} else { | ||
guarantee_property(valid_klass_reference_at(super_class_index), | ||
"Invalid superclass index %u in class file %s", | ||
super_class_index, | ||
CHECK_NULL); | ||
CHECK); | ||
|
||
// Ioi note: remove this in final commit. | ||
assert(!cp->tag_at(super_class_index).is_klass(), "should not have been resolved"); | ||
|
||
// The class name should be legal because it is checked when parsing constant pool. | ||
// However, make sure it is not an array type. | ||
bool is_array = false; | ||
if (cp->tag_at(super_class_index).is_klass()) { | ||
super_klass = InstanceKlass::cast(cp->resolved_klass_at(super_class_index)); | ||
if (need_verify) | ||
is_array = super_klass->is_array_klass(); | ||
} else if (need_verify) { | ||
is_array = (cp->klass_name_at(super_class_index)->char_at(0) == JVM_SIGNATURE_ARRAY); | ||
} | ||
if (need_verify) { | ||
guarantee_property(!is_array, | ||
"Bad superclass name in class file %s", CHECK_NULL); | ||
guarantee_property(cp->klass_name_at(super_class_index)->char_at(0) != JVM_SIGNATURE_ARRAY, | ||
"Bad superclass name in class file %s", CHECK); | ||
} | ||
} | ||
return super_klass; | ||
} | ||
|
||
OopMapBlocksBuilder::OopMapBlocksBuilder(unsigned int max_blocks) { | ||
|
@@ -5667,10 +5661,10 @@ void ClassFileParser::parse_stream(const ClassFileStream* const stream, | |
|
||
// SUPERKLASS | ||
_super_class_index = stream->get_u2_fast(); | ||
_super_klass = parse_super_class(cp, | ||
_super_class_index, | ||
_need_verify, | ||
CHECK); | ||
check_super_class(cp, | ||
_super_class_index, | ||
_need_verify, | ||
CHECK); | ||
|
||
// Interfaces | ||
_itfs_len = stream->get_u2_fast(); | ||
|
@@ -5777,8 +5771,8 @@ void ClassFileParser::post_process_parsed_stream(const ClassFileStream* const st | |
"java.lang.Object cannot implement an interface in class file %s", | ||
CHECK); | ||
} | ||
|
||
// We check super class after class file is parsed and format is checked | ||
if (_super_class_index > 0 && nullptr == _super_klass) { | ||
// Set _super_klass after class file is parsed and format is checked | ||
if (_super_class_index > 0) { | ||
Symbol* const super_class_name = cp->klass_name_at(_super_class_index); | ||
if (_access_flags.is_interface()) { | ||
// Before attempting to resolve the superclass, check for class format | ||
|
@@ -5789,6 +5783,7 @@ void ClassFileParser::post_process_parsed_stream(const ClassFileStream* const st | |
} | ||
Handle loader(THREAD, _loader_data->class_loader()); | ||
if (loader.is_null() && super_class_name == vmSymbols::java_lang_Object()) { | ||
// fast path to avoid lookup | ||
_super_klass = vmClasses::Object_klass(); | ||
} else { | ||
_super_klass = (const InstanceKlass*) | ||
|
@@ -5798,6 +5793,9 @@ void ClassFileParser::post_process_parsed_stream(const ClassFileStream* const st | |
true, | ||
CHECK); | ||
} | ||
} else { | ||
assert(_class_name == vmSymbols::java_lang_Object(), "already checked"); | ||
_super_klass = nullptr; | ||
|
||
} | ||
|
||
if (_super_klass != nullptr) { | ||
|
Uh oh!
There was an error while loading. Please reload this page.