< prev index next >

src/hotspot/share/runtime/signature.hpp

Print this page

  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, Handle protection_domain, FailureMode failure_mode, TRAPS);

566   oop as_java_mirror(Handle class_loader, Handle protection_domain, 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   Handle       _protection_domain;  // cached when needed
577 
578   void initialize_load_origin(Klass* load_origin) {
579     _load_origin = load_origin;
580     _handles_cached = (load_origin == nullptr);
581   }
582   void need_handles() {
583     if (!_handles_cached) {
584       cache_handles();
585       _handles_cached = true;
586     }
587   }
588   void cache_handles();

614 
615   // Check for too many arguments, or missing fingerprint:
616   if (!fp_is_valid(unaccumulator)) {
617     SignatureStream ss(_signature);
618     for (; !ss.at_return_type(); ss.next()) {
619       callback->do_type(ss.type());
620     }
621     // while we are here, capture the return type
622     _return_type = ss.type();
623   } else {
624     // Optimized version of do_parameters when fingerprint is known
625     assert(_return_type != T_ILLEGAL, "return type already captured from fp");
626     unaccumulator = fp_start_parameters(unaccumulator);
627     for (BasicType type; (type = fp_next_parameter(unaccumulator)) != (BasicType)fp_parameters_done; ) {
628       assert(fp_is_valid_type(type), "garbled fingerprint");
629       callback->do_type(type);
630     }
631   }
632 }
633 
634  #ifdef ASSERT
635  class SignatureVerifier : public StackObj {
636   public:
637     static bool is_valid_method_signature(Symbol* sig);
638     static bool is_valid_type_signature(Symbol* sig);
639   private:
640     static ssize_t is_valid_type(const char*, ssize_t);
641 };
642 #endif
643 #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, Handle protection_domain, FailureMode failure_mode, TRAPS);
568   InlineKlass* as_inline_klass(InstanceKlass* holder);
569   oop as_java_mirror(Handle class_loader, Handle protection_domain, 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;
581   int _offset;
582   Symbol* _symbol;
583 
584   SigEntry()
585     : _bt(T_ILLEGAL), _offset(-1), _symbol(NULL) {}
586 
587   SigEntry(BasicType bt, int offset, Symbol* symbol)
588     : _bt(bt), _offset(offset), _symbol(symbol) {}
589 
590   static int compare(SigEntry* e1, SigEntry* e2) {
591     if (e1->_offset != e2->_offset) {
592       return e1->_offset - e2->_offset;
593     }
594     assert((e1->_bt == T_LONG && (e2->_bt == T_LONG || e2->_bt == T_VOID)) ||
595            (e1->_bt == T_DOUBLE && (e2->_bt == T_DOUBLE || e2->_bt == T_VOID)) ||
596            e1->_bt == T_METADATA || e2->_bt == T_METADATA || e1->_bt == T_VOID || e2->_bt == T_VOID, "bad bt");
597     if (e1->_bt == e2->_bt) {
598       assert(e1->_bt == T_METADATA || e1->_bt == T_VOID, "only ones with duplicate offsets");
599       return 0;
600     }
601     if (e1->_bt == T_VOID ||
602         e2->_bt == T_METADATA) {
603       return 1;
604     }
605     if (e1->_bt == T_METADATA ||
606         e2->_bt == T_VOID) {
607       return -1;
608     }
609     ShouldNotReachHere();
610     return 0;
611   }
612   static void add_entry(GrowableArray<SigEntry>* sig, BasicType bt, Symbol* symbol, int offset = -1);
613   static bool skip_value_delimiters(const GrowableArray<SigEntry>* sig, int i);
614   static int fill_sig_bt(const GrowableArray<SigEntry>* sig, BasicType* sig_bt);
615   static TempNewSymbol create_symbol(const GrowableArray<SigEntry>* sig);
616 };
617 
618 class SigEntryFilter {
619 public:
620   bool operator()(const SigEntry& entry) { return entry._bt != T_METADATA && entry._bt != T_VOID; }
621 };
622 
623 // Specialized SignatureStream: used for invoking SystemDictionary to either find
624 //                              or resolve the underlying type when iterating over a
625 //                              Java descriptor (or parts of it).
626 class ResolvingSignatureStream : public SignatureStream {
627   Klass*       _load_origin;
628   bool         _handles_cached;
629   Handle       _class_loader;       // cached when needed
630   Handle       _protection_domain;  // cached when needed
631 
632   void initialize_load_origin(Klass* load_origin) {
633     _load_origin = load_origin;
634     _handles_cached = (load_origin == nullptr);
635   }
636   void need_handles() {
637     if (!_handles_cached) {
638       cache_handles();
639       _handles_cached = true;
640     }
641   }
642   void cache_handles();

668 
669   // Check for too many arguments, or missing fingerprint:
670   if (!fp_is_valid(unaccumulator)) {
671     SignatureStream ss(_signature);
672     for (; !ss.at_return_type(); ss.next()) {
673       callback->do_type(ss.type());
674     }
675     // while we are here, capture the return type
676     _return_type = ss.type();
677   } else {
678     // Optimized version of do_parameters when fingerprint is known
679     assert(_return_type != T_ILLEGAL, "return type already captured from fp");
680     unaccumulator = fp_start_parameters(unaccumulator);
681     for (BasicType type; (type = fp_next_parameter(unaccumulator)) != (BasicType)fp_parameters_done; ) {
682       assert(fp_is_valid_type(type), "garbled fingerprint");
683       callback->do_type(type);
684     }
685   }
686 }
687 
688 #ifdef ASSERT
689  class SignatureVerifier : public StackObj {
690   public:
691     static bool is_valid_method_signature(const Symbol* sig);
692     static bool is_valid_type_signature(const Symbol* sig);
693   private:
694     static ssize_t is_valid_type(const char*, ssize_t);
695 };
696 #endif
697 #endif // SHARE_RUNTIME_SIGNATURE_HPP
< prev index next >