Skip to content

Commit

Permalink
Detecting attributes in classFileParser for pattern declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
biboudis committed May 27, 2024
1 parent 7b693b4 commit d635684
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
61 changes: 60 additions & 1 deletion src/hotspot/share/classfile/classFileParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2341,6 +2341,10 @@ Method* ClassFileParser::parse_method(const ClassFileStream* const cfs,
const u1* annotation_default = nullptr;
int annotation_default_length = 0;

int pattern_length = 0;
const u1* pattern_runtime_visible_parameter_annotations = nullptr;
int pattern_runtime_visible_parameter_annotations_length = 0;

// Parse code and exceptions attribute
u2 method_attributes_count = cfs->get_u2_fast();
while (method_attributes_count--) {
Expand Down Expand Up @@ -2675,7 +2679,62 @@ Method* ClassFileParser::parse_method(const ClassFileStream* const cfs,
assert(runtime_invisible_type_annotations != nullptr, "null invisible type annotations");
}
cfs->skip_u1(method_attribute_length, CHECK_NULL);
} else {
}
else if (method_attribute_name == vmSymbols::tag_pattern()) {
cfs->guarantee_more(6, CHECK_NULL); // pattern_name_index, pattern_flags, pattern_methodtype_index

const u2 pattern_name_index = cfs->get_u2_fast();
check_property(
valid_symbol_at(pattern_name_index),
"Invalid pattern attribute name index %u in class file %s",
pattern_name_index, CHECK_NULL);
const Symbol *const pattern_name = cp->symbol_at(pattern_name_index);

const u2 pattern_flags = cfs->get_u2_fast();

const u2 pattern_methodtype_index = cfs->get_u2_fast();
guarantee_property(
valid_symbol_at(pattern_methodtype_index),
"Illegal constant pool index %u for pattern method type in class file %s",
pattern_methodtype_index, CHECK_NULL);
const Symbol* const signature = cp->symbol_at(pattern_methodtype_index);

cfs->guarantee_more(2, CHECK_NULL); // pattern_method_attributes_count

u2 pattern_method_attributes_count = cfs->get_u2_fast();
while (pattern_method_attributes_count--) {
cfs->guarantee_more(6, CHECK_NULL); // method_attribute_name_index, method_attribute_length
const u2 pattern_method_attribute_name_index = cfs->get_u2_fast();
const u4 pattern_method_attribute_length = cfs->get_u4_fast();
check_property(
valid_symbol_at(pattern_method_attribute_name_index),
"Invalid pattern method attribute name index %u in class file %s",
pattern_method_attribute_name_index, CHECK_NULL);

const Symbol *const pattern_method_attribute_name = cp->symbol_at(pattern_method_attribute_name_index);

if (pattern_method_attribute_name == vmSymbols::tag_method_parameters()) {
const int pattern_method_parameters_length = cfs->get_u1_fast();

cfs->skip_u2_fast(pattern_method_parameters_length);
cfs->skip_u2_fast(pattern_method_parameters_length);
}
else if (pattern_method_attribute_name == vmSymbols::tag_signature()) {
const int pattern_signature_data = parse_generic_signature_attribute(cfs, CHECK_NULL);
} else if (pattern_method_attribute_name == vmSymbols::tag_runtime_visible_parameter_annotations()) {
if (runtime_visible_type_annotations != nullptr) {
classfile_parse_error(
"Multiple RuntimeVisibleTypeAnnotations attributes for pattern method in class file %s",
THREAD);
return nullptr;
}
pattern_runtime_visible_parameter_annotations_length = pattern_method_attribute_length;
pattern_runtime_visible_parameter_annotations = cfs->current();
cfs->skip_u1(pattern_runtime_visible_parameter_annotations_length, CHECK_NULL);
}
}
}
else {
// Skip unknown attributes
cfs->skip_u1(method_attribute_length, CHECK_NULL);
}
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/share/classfile/vmSymbols.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ class SerializeClosure;
template(tag_enclosing_method, "EnclosingMethod") \
template(tag_bootstrap_methods, "BootstrapMethods") \
template(tag_permitted_subclasses, "PermittedSubclasses") \
template(tag_pattern, "Pattern") \
\
/* exception klasses: at least all exceptions thrown by the VM have entries here */ \
template(java_lang_ArithmeticException, "java/lang/ArithmeticException") \
Expand Down

0 comments on commit d635684

Please sign in to comment.