9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 *
24 */
25
26 #ifndef SHARE_RUNTIME_SIGNATURE_HPP
27 #define SHARE_RUNTIME_SIGNATURE_HPP
28
29 #include "memory/allocation.hpp"
30 #include "oops/method.hpp"
31 #include "sanitizers/ub.hpp"
32
33
34 // Static routines and parsing loops for processing field and method
35 // descriptors. In the HotSpot sources we call them "signatures".
36 //
37 // A SignatureStream iterates over a Java descriptor (or parts of it).
38 // The syntax is documented in the Java Virtual Machine Specification,
39 // section 4.3.
40 //
41 // The syntax may be summarized as follows:
42 //
43 // MethodType: '(' {FieldType}* ')' (FieldType | 'V')
44 // FieldType: PrimitiveType | ObjectType | ArrayType
45 // PrimitiveType: 'B' | 'C' | 'D' | 'F' | 'I' | 'J' | 'S' | 'Z'
46 // ObjectType: 'L' ClassName ';' | ArrayType
47 // ArrayType: '[' FieldType
48 // ClassName: {UnqualifiedName '/'}* UnqualifiedName
545 if (_type != T_ARRAY) {
546 return 0;
547 }
548 if (_array_prefix > max_skip_length) {
549 // strip some but not all levels of T_ARRAY
550 _array_prefix -= max_skip_length;
551 _begin += max_skip_length;
552 return max_skip_length;
553 }
554 return skip_whole_array_prefix();
555 }
556 int skip_array_prefix() {
557 if (_type != T_ARRAY) {
558 return 0;
559 }
560 return skip_whole_array_prefix();
561 }
562
563 // free-standing lookups (bring your own CL/PD pair)
564 enum FailureMode { ReturnNull, NCDFError, CachedOrNull };
565 Klass* as_klass(Handle class_loader, FailureMode failure_mode, TRAPS);
566 oop as_java_mirror(Handle class_loader, FailureMode failure_mode, TRAPS);
567 };
568
569 // Specialized SignatureStream: used for invoking SystemDictionary to either find
570 // or resolve the underlying type when iterating over a
571 // Java descriptor (or parts of it).
572 class ResolvingSignatureStream : public SignatureStream {
573 Klass* _load_origin;
574 bool _handles_cached;
575 Handle _class_loader; // cached when needed
576
577 void initialize_load_origin(Klass* load_origin) {
578 _load_origin = load_origin;
579 _handles_cached = (load_origin == nullptr);
580 }
581 void need_handles() {
582 if (!_handles_cached) {
583 cache_handles();
584 _handles_cached = true;
585 }
586 }
587 void cache_handles();
588
611
612 // Check for too many arguments, or missing fingerprint:
613 if (!fp_is_valid(unaccumulator)) {
614 SignatureStream ss(_signature);
615 for (; !ss.at_return_type(); ss.next()) {
616 callback->do_type(ss.type());
617 }
618 // while we are here, capture the return type
619 _return_type = ss.type();
620 } else {
621 // Optimized version of do_parameters when fingerprint is known
622 assert(_return_type != T_ILLEGAL, "return type already captured from fp");
623 unaccumulator = fp_start_parameters(unaccumulator);
624 for (BasicType type; (type = fp_next_parameter(unaccumulator)) != (BasicType)fp_parameters_done; ) {
625 assert(fp_is_valid_type(type), "garbled fingerprint");
626 callback->do_type(type);
627 }
628 }
629 }
630
631 #ifdef ASSERT
632 class SignatureVerifier : public StackObj {
633 public:
634 static bool is_valid_method_signature(Symbol* sig);
635 static bool is_valid_type_signature(Symbol* sig);
636 private:
637 static ssize_t is_valid_type(const char*, ssize_t);
638 };
639 #endif
640 #endif // SHARE_RUNTIME_SIGNATURE_HPP
|
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 *
24 */
25
26 #ifndef SHARE_RUNTIME_SIGNATURE_HPP
27 #define SHARE_RUNTIME_SIGNATURE_HPP
28
29 #include "classfile/symbolTable.hpp"
30 #include "memory/allocation.hpp"
31 #include "oops/method.hpp"
32 #include "sanitizers/ub.hpp"
33
34
35 // Static routines and parsing loops for processing field and method
36 // descriptors. In the HotSpot sources we call them "signatures".
37 //
38 // A SignatureStream iterates over a Java descriptor (or parts of it).
39 // The syntax is documented in the Java Virtual Machine Specification,
40 // section 4.3.
41 //
42 // The syntax may be summarized as follows:
43 //
44 // MethodType: '(' {FieldType}* ')' (FieldType | 'V')
45 // FieldType: PrimitiveType | ObjectType | ArrayType
46 // PrimitiveType: 'B' | 'C' | 'D' | 'F' | 'I' | 'J' | 'S' | 'Z'
47 // ObjectType: 'L' ClassName ';' | ArrayType
48 // ArrayType: '[' FieldType
49 // ClassName: {UnqualifiedName '/'}* UnqualifiedName
546 if (_type != T_ARRAY) {
547 return 0;
548 }
549 if (_array_prefix > max_skip_length) {
550 // strip some but not all levels of T_ARRAY
551 _array_prefix -= max_skip_length;
552 _begin += max_skip_length;
553 return max_skip_length;
554 }
555 return skip_whole_array_prefix();
556 }
557 int skip_array_prefix() {
558 if (_type != T_ARRAY) {
559 return 0;
560 }
561 return skip_whole_array_prefix();
562 }
563
564 // free-standing lookups (bring your own CL/PD pair)
565 enum FailureMode { ReturnNull, NCDFError, CachedOrNull };
566
567 Klass* as_klass(Handle class_loader, FailureMode failure_mode, TRAPS);
568 InlineKlass* as_inline_klass(InstanceKlass* holder);
569 oop as_java_mirror(Handle class_loader, FailureMode failure_mode, TRAPS);
570 };
571
572 class SigEntryFilter;
573 typedef GrowableArrayFilterIterator<SigEntry, SigEntryFilter> ExtendedSignature;
574
575 // Used for adapter generation. One SigEntry is used per element of
576 // the signature of the method. Inline type arguments are treated
577 // specially. See comment for InlineKlass::collect_fields().
578 class SigEntry {
579 public:
580 BasicType _bt; // Basic type of the argument
581 int _offset; // Offset of the field in its value class holder for scalarized arguments (-1 otherwise). Used for packing and unpacking.
582 float _sort_offset; // Offset used for sorting
583 Symbol* _symbol; // Symbol for printing
584
585 SigEntry()
586 : _bt(T_ILLEGAL), _offset(-1), _sort_offset(-1), _symbol(nullptr) {}
587
588 SigEntry(BasicType bt, int offset = -1, float sort_offset = -1, Symbol* symbol = nullptr)
589 : _bt(bt), _offset(offset), _sort_offset(sort_offset), _symbol(symbol) {}
590
591 static int compare(SigEntry* e1, SigEntry* e2) {
592 if (e1->_sort_offset != e2->_sort_offset) {
593 return e1->_sort_offset - e2->_sort_offset;
594 }
595 if (e1->_offset != e2->_offset) {
596 return e1->_offset - e2->_offset;
597 }
598 assert((e1->_bt == T_LONG && (e2->_bt == T_LONG || e2->_bt == T_VOID)) ||
599 (e1->_bt == T_DOUBLE && (e2->_bt == T_DOUBLE || e2->_bt == T_VOID)) ||
600 e1->_bt == T_METADATA || e2->_bt == T_METADATA || e1->_bt == T_VOID || e2->_bt == T_VOID, "bad bt");
601 if (e1->_bt == e2->_bt) {
602 assert(e1->_bt == T_METADATA || e1->_bt == T_VOID, "only ones with duplicate offsets");
603 return 0;
604 }
605 if (e1->_bt == T_VOID ||
606 e2->_bt == T_METADATA) {
607 return 1;
608 }
609 if (e1->_bt == T_METADATA ||
610 e2->_bt == T_VOID) {
611 return -1;
612 }
613 ShouldNotReachHere();
614 return 0;
615 }
616 static void add_entry(GrowableArray<SigEntry>* sig, BasicType bt, Symbol* symbol = nullptr, int offset = -1, float sort_offset = -1);
617 static bool skip_value_delimiters(const GrowableArray<SigEntry>* sig, int i);
618 static int fill_sig_bt(const GrowableArray<SigEntry>* sig, BasicType* sig_bt);
619 static TempNewSymbol create_symbol(const GrowableArray<SigEntry>* sig);
620 };
621
622 class SigEntryFilter {
623 public:
624 bool operator()(const SigEntry& entry) { return entry._bt != T_METADATA && entry._bt != T_VOID; }
625 };
626
627 // Specialized SignatureStream: used for invoking SystemDictionary to either find
628 // or resolve the underlying type when iterating over a
629 // Java descriptor (or parts of it).
630 class ResolvingSignatureStream : public SignatureStream {
631 Klass* _load_origin;
632 bool _handles_cached;
633 Handle _class_loader; // cached when needed
634
635 void initialize_load_origin(Klass* load_origin) {
636 _load_origin = load_origin;
637 _handles_cached = (load_origin == nullptr);
638 }
639 void need_handles() {
640 if (!_handles_cached) {
641 cache_handles();
642 _handles_cached = true;
643 }
644 }
645 void cache_handles();
646
669
670 // Check for too many arguments, or missing fingerprint:
671 if (!fp_is_valid(unaccumulator)) {
672 SignatureStream ss(_signature);
673 for (; !ss.at_return_type(); ss.next()) {
674 callback->do_type(ss.type());
675 }
676 // while we are here, capture the return type
677 _return_type = ss.type();
678 } else {
679 // Optimized version of do_parameters when fingerprint is known
680 assert(_return_type != T_ILLEGAL, "return type already captured from fp");
681 unaccumulator = fp_start_parameters(unaccumulator);
682 for (BasicType type; (type = fp_next_parameter(unaccumulator)) != (BasicType)fp_parameters_done; ) {
683 assert(fp_is_valid_type(type), "garbled fingerprint");
684 callback->do_type(type);
685 }
686 }
687 }
688
689 #ifdef ASSERT
690 class SignatureVerifier : public StackObj {
691 public:
692 static bool is_valid_method_signature(const Symbol* sig);
693 static bool is_valid_type_signature(const Symbol* sig);
694 private:
695 static ssize_t is_valid_type(const char*, ssize_t);
696 };
697 #endif
698 #endif // SHARE_RUNTIME_SIGNATURE_HPP
|