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
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}*
543 if (_type != T_ARRAY) {
544 return 0;
545 }
546 if (_array_prefix > max_skip_length) {
547 // strip some but not all levels of T_ARRAY
548 _array_prefix -= max_skip_length;
549 _begin += max_skip_length;
550 return max_skip_length;
551 }
552 return skip_whole_array_prefix();
553 }
554 int skip_array_prefix() {
555 if (_type != T_ARRAY) {
556 return 0;
557 }
558 return skip_whole_array_prefix();
559 }
560
561 // free-standing lookups (bring your own CL/PD pair)
562 enum FailureMode { ReturnNull, NCDFError, CachedOrNull };
563 Klass* as_klass(Handle class_loader, Handle protection_domain, FailureMode failure_mode, TRAPS);
564 oop as_java_mirror(Handle class_loader, Handle protection_domain, FailureMode failure_mode, TRAPS);
565 };
566
567 // Specialized SignatureStream: used for invoking SystemDictionary to either find
568 // or resolve the underlying type when iterating over a
569 // Java descriptor (or parts of it).
570 class ResolvingSignatureStream : public SignatureStream {
571 Klass* _load_origin;
572 bool _handles_cached;
573 Handle _class_loader; // cached when needed
574 Handle _protection_domain; // cached when needed
575
576 void initialize_load_origin(Klass* load_origin) {
577 _load_origin = load_origin;
578 _handles_cached = (load_origin == nullptr);
579 }
580 void need_handles() {
581 if (!_handles_cached) {
582 cache_handles();
583 _handles_cached = true;
584 }
585 }
586 void cache_handles();
612
613 // Check for too many arguments, or missing fingerprint:
614 if (!fp_is_valid(unaccumulator)) {
615 SignatureStream ss(_signature);
616 for (; !ss.at_return_type(); ss.next()) {
617 callback->do_type(ss.type());
618 }
619 // while we are here, capture the return type
620 _return_type = ss.type();
621 } else {
622 // Optimized version of do_parameters when fingerprint is known
623 assert(_return_type != T_ILLEGAL, "return type already captured from fp");
624 unaccumulator = fp_start_parameters(unaccumulator);
625 for (BasicType type; (type = fp_next_parameter(unaccumulator)) != (BasicType)fp_parameters_done; ) {
626 assert(fp_is_valid_type(type), "garbled fingerprint");
627 callback->do_type(type);
628 }
629 }
630 }
631
632 #ifdef ASSERT
633 class SignatureVerifier : public StackObj {
634 public:
635 static bool is_valid_method_signature(Symbol* sig);
636 static bool is_valid_type_signature(Symbol* sig);
637 private:
638 static ssize_t is_valid_type(const char*, ssize_t);
639 };
640 #endif
641 #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
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
49 // UnqualifiedName: NameChar {NameChar}*
544 if (_type != T_ARRAY) {
545 return 0;
546 }
547 if (_array_prefix > max_skip_length) {
548 // strip some but not all levels of T_ARRAY
549 _array_prefix -= max_skip_length;
550 _begin += max_skip_length;
551 return max_skip_length;
552 }
553 return skip_whole_array_prefix();
554 }
555 int skip_array_prefix() {
556 if (_type != T_ARRAY) {
557 return 0;
558 }
559 return skip_whole_array_prefix();
560 }
561
562 // free-standing lookups (bring your own CL/PD pair)
563 enum FailureMode { ReturnNull, NCDFError, CachedOrNull };
564
565 Klass* as_klass(Handle class_loader, Handle protection_domain, FailureMode failure_mode, TRAPS);
566 InlineKlass* as_inline_klass(InstanceKlass* holder);
567 oop as_java_mirror(Handle class_loader, Handle protection_domain, FailureMode failure_mode, TRAPS);
568 };
569
570 class SigEntryFilter;
571 typedef GrowableArrayFilterIterator<SigEntry, SigEntryFilter> ExtendedSignature;
572
573 // Used for adapter generation. One SigEntry is used per element of
574 // the signature of the method. Inline type arguments are treated
575 // specially. See comment for InlineKlass::collect_fields().
576 class SigEntry {
577 public:
578 BasicType _bt;
579 int _offset;
580 Symbol* _symbol;
581
582 SigEntry()
583 : _bt(T_ILLEGAL), _offset(-1), _symbol(NULL) {}
584
585 SigEntry(BasicType bt, int offset, Symbol* symbol)
586 : _bt(bt), _offset(offset), _symbol(symbol) {}
587
588 static int compare(SigEntry* e1, SigEntry* e2) {
589 if (e1->_offset != e2->_offset) {
590 return e1->_offset - e2->_offset;
591 }
592 assert((e1->_bt == T_LONG && (e2->_bt == T_LONG || e2->_bt == T_VOID)) ||
593 (e1->_bt == T_DOUBLE && (e2->_bt == T_DOUBLE || e2->_bt == T_VOID)) ||
594 e1->_bt == T_METADATA || e2->_bt == T_METADATA || e1->_bt == T_VOID || e2->_bt == T_VOID, "bad bt");
595 if (e1->_bt == e2->_bt) {
596 assert(e1->_bt == T_METADATA || e1->_bt == T_VOID, "only ones with duplicate offsets");
597 return 0;
598 }
599 if (e1->_bt == T_VOID ||
600 e2->_bt == T_METADATA) {
601 return 1;
602 }
603 if (e1->_bt == T_METADATA ||
604 e2->_bt == T_VOID) {
605 return -1;
606 }
607 ShouldNotReachHere();
608 return 0;
609 }
610 static void add_entry(GrowableArray<SigEntry>* sig, BasicType bt, Symbol* symbol, int offset = -1);
611 static bool skip_value_delimiters(const GrowableArray<SigEntry>* sig, int i);
612 static int fill_sig_bt(const GrowableArray<SigEntry>* sig, BasicType* sig_bt);
613 static TempNewSymbol create_symbol(const GrowableArray<SigEntry>* sig);
614 };
615
616 class SigEntryFilter {
617 public:
618 bool operator()(const SigEntry& entry) { return entry._bt != T_METADATA && entry._bt != T_VOID; }
619 };
620
621 // Specialized SignatureStream: used for invoking SystemDictionary to either find
622 // or resolve the underlying type when iterating over a
623 // Java descriptor (or parts of it).
624 class ResolvingSignatureStream : public SignatureStream {
625 Klass* _load_origin;
626 bool _handles_cached;
627 Handle _class_loader; // cached when needed
628 Handle _protection_domain; // cached when needed
629
630 void initialize_load_origin(Klass* load_origin) {
631 _load_origin = load_origin;
632 _handles_cached = (load_origin == nullptr);
633 }
634 void need_handles() {
635 if (!_handles_cached) {
636 cache_handles();
637 _handles_cached = true;
638 }
639 }
640 void cache_handles();
666
667 // Check for too many arguments, or missing fingerprint:
668 if (!fp_is_valid(unaccumulator)) {
669 SignatureStream ss(_signature);
670 for (; !ss.at_return_type(); ss.next()) {
671 callback->do_type(ss.type());
672 }
673 // while we are here, capture the return type
674 _return_type = ss.type();
675 } else {
676 // Optimized version of do_parameters when fingerprint is known
677 assert(_return_type != T_ILLEGAL, "return type already captured from fp");
678 unaccumulator = fp_start_parameters(unaccumulator);
679 for (BasicType type; (type = fp_next_parameter(unaccumulator)) != (BasicType)fp_parameters_done; ) {
680 assert(fp_is_valid_type(type), "garbled fingerprint");
681 callback->do_type(type);
682 }
683 }
684 }
685
686 #ifdef ASSERT
687 class SignatureVerifier : public StackObj {
688 public:
689 static bool is_valid_method_signature(const Symbol* sig);
690 static bool is_valid_type_signature(const Symbol* sig);
691 private:
692 static ssize_t is_valid_type(const char*, ssize_t);
693 };
694 #endif
695 #endif // SHARE_RUNTIME_SIGNATURE_HPP
|