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
32 // Static routines and parsing loops for processing field and method
33 // descriptors. In the HotSpot sources we call them "signatures".
34 //
35 // A SignatureStream iterates over a Java descriptor (or parts of it).
36 // The syntax is documented in the Java Virtual Machine Specification,
37 // section 4.3.
38 //
39 // The syntax may be summarized as follows:
40 //
41 // MethodType: '(' {FieldType}* ')' (FieldType | 'V')
42 // FieldType: PrimitiveType | ObjectType | ArrayType
43 // PrimitiveType: 'B' | 'C' | 'D' | 'F' | 'I' | 'J' | 'S' | 'Z'
44 // ObjectType: 'L' ClassName ';' | ArrayType
45 // ArrayType: '[' FieldType
46 // ClassName: {UnqualifiedName '/'}* UnqualifiedName
47 // UnqualifiedName: NameChar {NameChar}*
48 // NameChar: ANY_CHAR_EXCEPT('/' | '.' | ';' | '[')
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
33 // Static routines and parsing loops for processing field and method
34 // descriptors. In the HotSpot sources we call them "signatures".
35 //
36 // A SignatureStream iterates over a Java descriptor (or parts of it).
37 // The syntax is documented in the Java Virtual Machine Specification,
38 // section 4.3.
39 //
40 // The syntax may be summarized as follows:
41 //
42 // MethodType: '(' {FieldType}* ')' (FieldType | 'V')
43 // FieldType: PrimitiveType | ObjectType | ArrayType
44 // PrimitiveType: 'B' | 'C' | 'D' | 'F' | 'I' | 'J' | 'S' | 'Z'
45 // ObjectType: 'L' ClassName ';' | ArrayType
46 // ArrayType: '[' FieldType
47 // ClassName: {UnqualifiedName '/'}* UnqualifiedName
48 // UnqualifiedName: NameChar {NameChar}*
49 // NameChar: ANY_CHAR_EXCEPT('/' | '.' | ';' | '[')
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 -1;
594 } else if (e1->_sort_offset > e2->_sort_offset) {
595 return 1;
596 }
597
598 if (e1->_offset != e2->_offset) {
599 return e1->_offset - e2->_offset;
600 }
601 assert((e1->_bt == T_LONG && (e2->_bt == T_LONG || e2->_bt == T_VOID)) ||
602 (e1->_bt == T_DOUBLE && (e2->_bt == T_DOUBLE || e2->_bt == T_VOID)) ||
603 e1->_bt == T_METADATA || e2->_bt == T_METADATA || e1->_bt == T_VOID || e2->_bt == T_VOID, "bad bt");
604 if (e1->_bt == e2->_bt) {
605 assert(e1->_bt == T_METADATA || e1->_bt == T_VOID, "only ones with duplicate offsets");
606 return 0;
607 }
608 if (e1->_bt == T_VOID ||
609 e2->_bt == T_METADATA) {
610 return 1;
611 }
612 if (e1->_bt == T_METADATA ||
613 e2->_bt == T_VOID) {
614 return -1;
615 }
616 ShouldNotReachHere();
617 return 0;
618 }
619 static void add_entry(GrowableArray<SigEntry>* sig, BasicType bt, Symbol* symbol = nullptr, int offset = -1, float sort_offset = -1);
620 static bool skip_value_delimiters(const GrowableArray<SigEntry>* sig, int i);
621 static int fill_sig_bt(const GrowableArray<SigEntry>* sig, BasicType* sig_bt);
622 static TempNewSymbol create_symbol(const GrowableArray<SigEntry>* sig);
623 };
624
625 class SigEntryFilter {
626 public:
627 bool operator()(const SigEntry& entry) { return entry._bt != T_METADATA && entry._bt != T_VOID; }
628 };
629
630 // Specialized SignatureStream: used for invoking SystemDictionary to either find
631 // or resolve the underlying type when iterating over a
632 // Java descriptor (or parts of it).
633 class ResolvingSignatureStream : public SignatureStream {
634 Klass* _load_origin;
635 bool _handles_cached;
636 Handle _class_loader; // cached when needed
637
638 void initialize_load_origin(Klass* load_origin) {
639 _load_origin = load_origin;
640 _handles_cached = (load_origin == nullptr);
641 }
642 void need_handles() {
643 if (!_handles_cached) {
644 cache_handles();
645 _handles_cached = true;
646 }
647 }
648 void cache_handles();
649
672
673 // Check for too many arguments, or missing fingerprint:
674 if (!fp_is_valid(unaccumulator)) {
675 SignatureStream ss(_signature);
676 for (; !ss.at_return_type(); ss.next()) {
677 callback->do_type(ss.type());
678 }
679 // while we are here, capture the return type
680 _return_type = ss.type();
681 } else {
682 // Optimized version of do_parameters when fingerprint is known
683 assert(_return_type != T_ILLEGAL, "return type already captured from fp");
684 unaccumulator = fp_start_parameters(unaccumulator);
685 for (BasicType type; (type = fp_next_parameter(unaccumulator)) != (BasicType)fp_parameters_done; ) {
686 assert(fp_is_valid_type(type), "garbled fingerprint");
687 callback->do_type(type);
688 }
689 }
690 }
691
692 #ifdef ASSERT
693 class SignatureVerifier : public StackObj {
694 public:
695 static bool is_valid_method_signature(const Symbol* sig);
696 static bool is_valid_type_signature(const Symbol* sig);
697 private:
698 static ssize_t is_valid_type(const char*, ssize_t);
699 };
700 #endif
701 #endif // SHARE_RUNTIME_SIGNATURE_HPP
|