@@ -77,6 +77,43 @@ class CPKlassSlot {
7777 }
7878};
7979
80+ class BSMAttributeEntry {
81+ friend class ConstantPool ;
82+ u2 _bootstrap_method_index;
83+ u2 _argument_count;
84+
85+ // The argument indexes are stored right after the object, in a contiguous array.
86+ // [ bsmi_0 argc_0 arg_00 arg_01 ... arg_0N bsmi_1 argc_1 arg_10 ... arg_1N ... ]
87+ // So in order to find the argument array, jump over ourselves.
88+ const u2* argument_indexes () const {
89+ return reinterpret_cast <const u2*>(this + 1 );
90+ }
91+ u2* argument_indexes () {
92+ return reinterpret_cast <u2*>(this + 1 );
93+ }
94+ // These are overlays on top of the operands array. Do not construct.
95+ BSMAttributeEntry () = delete ;
96+
97+ public:
98+ // Offsets for SA
99+ enum {
100+ _bsmi_offset = 0 ,
101+ _argc_offset = 1 ,
102+ _argv_offset = 2
103+ };
104+
105+ int bootstrap_method_index () const {
106+ return _bootstrap_method_index;
107+ }
108+ int argument_count () const {
109+ return _argument_count;
110+ }
111+ int argument_index (int n) const {
112+ assert (checked_cast<u2>(n) < _argument_count, " oob" );
113+ return argument_indexes ()[n];
114+ }
115+ };
116+
80117class ConstantPool : public Metadata {
81118 friend class VMStructs ;
82119 friend class JVMCIVMStructs ;
@@ -519,10 +556,6 @@ class ConstantPool : public Metadata {
519556 assert (tag_at (cp_index).has_bootstrap (), " Corrupted constant pool" );
520557 return extract_low_short_from_int (*int_at_addr (cp_index));
521558 }
522- int bootstrap_operand_base (int cp_index) {
523- int bsms_attribute_index = bootstrap_methods_attribute_index (cp_index);
524- return operand_offset_at (operands (), bsms_attribute_index);
525- }
526559 // The first part of the operands array consists of an index into the second part.
527560 // Extract a 32-bit index value from the first part.
528561 static int operand_offset_at (Array<u2>* operands, int bsms_attribute_index) {
@@ -560,47 +593,26 @@ class ConstantPool : public Metadata {
560593 else
561594 return operand_offset_at (operands, nextidx);
562595 }
563- int bootstrap_operand_limit (int cp_index) {
564- int bsms_attribute_index = bootstrap_methods_attribute_index (cp_index);
565- return operand_limit_at (operands (), bsms_attribute_index);
566- }
567596#endif // ASSERT
568597
569- // Layout of InvokeDynamic and Dynamic bootstrap method specifier
570- // data in second part of operands array. This encodes one record in
571- // the BootstrapMethods attribute. The whole specifier also includes
572- // the name and type information from the main constant pool entry.
573- enum {
574- _indy_bsm_offset = 0 , // CONSTANT_MethodHandle bsm
575- _indy_argc_offset = 1 , // u2 argc
576- _indy_argv_offset = 2 // u2 argv[argc]
577- };
578-
579598 // These functions are used in RedefineClasses for CP merge
580-
581599 int operand_offset_at (int bsms_attribute_index) {
582600 assert (0 <= bsms_attribute_index &&
583601 bsms_attribute_index < operand_array_length (operands ()),
584602 " Corrupted CP operands" );
585603 return operand_offset_at (operands (), bsms_attribute_index);
586604 }
587- u2 operand_bootstrap_method_ref_index_at (int bsms_attribute_index) {
588- int offset = operand_offset_at (bsms_attribute_index);
589- return operands ()->at (offset + _indy_bsm_offset);
590- }
591- u2 operand_argument_count_at (int bsms_attribute_index) {
592- int offset = operand_offset_at (bsms_attribute_index);
593- u2 argc = operands ()->at (offset + _indy_argc_offset);
594- return argc;
595- }
596- u2 operand_argument_index_at (int bsms_attribute_index, int j) {
605+
606+ BSMAttributeEntry* bsm_attribute_entry (int bsms_attribute_index) {
597607 int offset = operand_offset_at (bsms_attribute_index);
598- return operands ()->at (offset + _indy_argv_offset + j );
608+ return reinterpret_cast <BSMAttributeEntry*>( operands ()->adr_at (offset) );
599609 }
610+
600611 int operand_next_offset_at (int bsms_attribute_index) {
601- int offset = operand_offset_at (bsms_attribute_index) + _indy_argv_offset
602- + operand_argument_count_at (bsms_attribute_index);
603- return offset;
612+ BSMAttributeEntry* bsme = bsm_attribute_entry (bsms_attribute_index);
613+ u2* argv_start = bsme->argument_indexes ();
614+ int offset = argv_start - operands ()->data ();
615+ return offset + bsme->argument_count ();
604616 }
605617 // Compare a bootstrap specifier data in the operands arrays
606618 bool compare_operand_to (int bsms_attribute_index1, const constantPoolHandle& cp2,
@@ -617,23 +629,19 @@ class ConstantPool : public Metadata {
617629
618630 u2 bootstrap_method_ref_index_at (int cp_index) {
619631 assert (tag_at (cp_index).has_bootstrap (), " Corrupted constant pool" );
620- int op_base = bootstrap_operand_base (cp_index);
621- return operands ( )->at (op_base + _indy_bsm_offset );
632+ int bsmai = bootstrap_methods_attribute_index (cp_index);
633+ return bsm_attribute_entry (bsmai )->bootstrap_method_index ( );
622634 }
623635 u2 bootstrap_argument_count_at (int cp_index) {
624636 assert (tag_at (cp_index).has_bootstrap (), " Corrupted constant pool" );
625- int op_base = bootstrap_operand_base (cp_index);
626- u2 argc = operands ()->at (op_base + _indy_argc_offset);
627- DEBUG_ONLY (int end_offset = op_base + _indy_argv_offset + argc;
628- int next_offset = bootstrap_operand_limit (cp_index));
629- assert (end_offset == next_offset, " matched ending" );
630- return argc;
637+ int bsmai = bootstrap_methods_attribute_index (cp_index);
638+ return bsm_attribute_entry (bsmai)->argument_count ();
631639 }
632640 u2 bootstrap_argument_index_at (int cp_index, int j) {
633- int op_base = bootstrap_operand_base (cp_index);
634- DEBUG_ONLY ( int argc = operands ()-> at (op_base + _indy_argc_offset) );
635- assert ((uint)j < (uint)argc , " oob" );
636- return operands ( )->at (op_base + _indy_argv_offset + j);
641+ int bsmai = bootstrap_methods_attribute_index (cp_index);
642+ BSMAttributeEntry* bsme = bsm_attribute_entry (bsmai );
643+ assert ((uint)j < (uint)bsme-> argument_count () , " oob" );
644+ return bsm_attribute_entry (bsmai )->argument_index ( j);
637645 }
638646
639647 // The following methods (name/signature/klass_ref_at, klass_ref_at_noresolve,
0 commit comments