@@ -2341,6 +2341,11 @@ Method* ClassFileParser::parse_method(const ClassFileStream* const cfs,
2341
2341
const u1* annotation_default = nullptr ;
2342
2342
int annotation_default_length = 0 ;
2343
2343
2344
+ int pattern_length = 0 ;
2345
+ const u1* pattern_runtime_visible_parameter_annotations = nullptr ;
2346
+ int pattern_runtime_visible_parameter_annotations_length = 0 ;
2347
+ bool is_pattern = false ;
2348
+
2344
2349
// Parse code and exceptions attribute
2345
2350
u2 method_attributes_count = cfs->get_u2_fast ();
2346
2351
while (method_attributes_count--) {
@@ -2675,7 +2680,64 @@ Method* ClassFileParser::parse_method(const ClassFileStream* const cfs,
2675
2680
assert (runtime_invisible_type_annotations != nullptr , " null invisible type annotations" );
2676
2681
}
2677
2682
cfs->skip_u1 (method_attribute_length, CHECK_NULL);
2678
- } else {
2683
+ }
2684
+ else if (method_attribute_name == vmSymbols::tag_pattern ()) {
2685
+ cfs->guarantee_more (6 , CHECK_NULL); // pattern_name_index, pattern_flags, pattern_methodtype_index
2686
+
2687
+ const u2 pattern_name_index = cfs->get_u2_fast ();
2688
+ check_property (
2689
+ valid_symbol_at (pattern_name_index),
2690
+ " Invalid pattern attribute name index %u in class file %s" ,
2691
+ pattern_name_index, CHECK_NULL);
2692
+ const Symbol *const pattern_name = cp->symbol_at (pattern_name_index);
2693
+
2694
+ const u2 pattern_flags = cfs->get_u2_fast ();
2695
+
2696
+ const u2 pattern_methodtype_index = cfs->get_u2_fast ();
2697
+ guarantee_property (
2698
+ valid_symbol_at (pattern_methodtype_index),
2699
+ " Illegal constant pool index %u for pattern method type in class file %s" ,
2700
+ pattern_methodtype_index, CHECK_NULL);
2701
+ const Symbol* const signature = cp->symbol_at (pattern_methodtype_index);
2702
+
2703
+ is_pattern = true ;
2704
+
2705
+ cfs->guarantee_more (2 , CHECK_NULL); // pattern_method_attributes_count
2706
+
2707
+ u2 pattern_method_attributes_count = cfs->get_u2_fast ();
2708
+ while (pattern_method_attributes_count--) {
2709
+ cfs->guarantee_more (6 , CHECK_NULL); // method_attribute_name_index, method_attribute_length
2710
+ const u2 pattern_method_attribute_name_index = cfs->get_u2_fast ();
2711
+ const u4 pattern_method_attribute_length = cfs->get_u4_fast ();
2712
+ check_property (
2713
+ valid_symbol_at (pattern_method_attribute_name_index),
2714
+ " Invalid pattern method attribute name index %u in class file %s" ,
2715
+ pattern_method_attribute_name_index, CHECK_NULL);
2716
+
2717
+ const Symbol *const pattern_method_attribute_name = cp->symbol_at (pattern_method_attribute_name_index);
2718
+
2719
+ if (pattern_method_attribute_name == vmSymbols::tag_method_parameters ()) {
2720
+ const int pattern_method_parameters_length = cfs->get_u1_fast ();
2721
+
2722
+ cfs->skip_u2_fast (pattern_method_parameters_length);
2723
+ cfs->skip_u2_fast (pattern_method_parameters_length);
2724
+ }
2725
+ else if (pattern_method_attribute_name == vmSymbols::tag_signature ()) {
2726
+ const int pattern_signature_data = parse_generic_signature_attribute (cfs, CHECK_NULL);
2727
+ } else if (pattern_method_attribute_name == vmSymbols::tag_runtime_visible_parameter_annotations ()) {
2728
+ if (runtime_visible_type_annotations != nullptr ) {
2729
+ classfile_parse_error (
2730
+ " Multiple RuntimeVisibleTypeAnnotations attributes for pattern method in class file %s" ,
2731
+ THREAD);
2732
+ return nullptr ;
2733
+ }
2734
+ pattern_runtime_visible_parameter_annotations_length = pattern_method_attribute_length;
2735
+ pattern_runtime_visible_parameter_annotations = cfs->current ();
2736
+ cfs->skip_u1 (pattern_runtime_visible_parameter_annotations_length, CHECK_NULL);
2737
+ }
2738
+ }
2739
+ }
2740
+ else {
2679
2741
// Skip unknown attributes
2680
2742
cfs->skip_u1 (method_attribute_length, CHECK_NULL);
2681
2743
}
@@ -2730,6 +2792,8 @@ Method* ClassFileParser::parse_method(const ClassFileStream* const cfs,
2730
2792
m->set_constants (_cp);
2731
2793
m->set_name_index (name_index);
2732
2794
m->set_signature_index (signature_index);
2795
+ m->set_is_pattern (is_pattern);
2796
+
2733
2797
m->constMethod ()->compute_from_signature (cp->symbol_at (signature_index), access_flags.is_static ());
2734
2798
assert (args_size < 0 || args_size == m->size_of_parameters (), " " );
2735
2799
0 commit comments