< 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 
 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 SigEntry;
573 class SigEntryFilter;
574 typedef GrowableArrayFilterIterator<SigEntry, SigEntryFilter> ExtendedSignature;
575 
576 // Used for adapter generation. One SigEntry is used per element of
577 // the signature of the method. Inline type arguments are treated
578 // specially. See comment for InlineKlass::collect_fields().
579 class SigEntry {
580  public:
581   BasicType _bt;      // Basic type of the argument
582   int _offset;        // Offset of the field in its value class holder for scalarized arguments (-1 otherwise). Used for packing and unpacking.
583   Symbol* _name;      // Symbol for printing
584   bool _null_marker;  // Is it a null marker? For printing
585 
586   SigEntry()
587     : _bt(T_ILLEGAL), _offset(-1), _name(nullptr) {}
588 
589   SigEntry(BasicType bt, int offset, Symbol* name, bool null_marker)
590     : _bt(bt), _offset(offset), _name(name), _null_marker(null_marker) {}
591 
592   static void add_entry(GrowableArray<SigEntry>* sig, BasicType bt, Symbol* name = nullptr, int offset = -1);
593   static void add_null_marker(GrowableArray<SigEntry>* sig, Symbol* name, int offset);
594   static bool skip_value_delimiters(const GrowableArray<SigEntry>* sig, int i);
595   static int fill_sig_bt(const GrowableArray<SigEntry>* sig, BasicType* sig_bt);
596   static TempNewSymbol create_symbol(const GrowableArray<SigEntry>* sig);
597 };
598 
599 class SigEntryFilter {
600 public:
601   bool operator()(const SigEntry& entry) { return entry._bt != T_METADATA && entry._bt != T_VOID; }
602 };
603 
604 // Specialized SignatureStream: used for invoking SystemDictionary to either find
605 //                              or resolve the underlying type when iterating over a
606 //                              Java descriptor (or parts of it).
607 class ResolvingSignatureStream : public SignatureStream {
608   Klass*       _load_origin;
609   bool         _handles_cached;
610   Handle       _class_loader;       // cached when needed
611 
612   void initialize_load_origin(Klass* load_origin) {
613     _load_origin = load_origin;
614     _handles_cached = (load_origin == nullptr);
615   }
616   void need_handles() {
617     if (!_handles_cached) {
618       cache_handles();
619       _handles_cached = true;
620     }
621   }
622   void cache_handles();
623 

646 
647   // Check for too many arguments, or missing fingerprint:
648   if (!fp_is_valid(unaccumulator)) {
649     SignatureStream ss(_signature);
650     for (; !ss.at_return_type(); ss.next()) {
651       callback->do_type(ss.type());
652     }
653     // while we are here, capture the return type
654     _return_type = ss.type();
655   } else {
656     // Optimized version of do_parameters when fingerprint is known
657     assert(_return_type != T_ILLEGAL, "return type already captured from fp");
658     unaccumulator = fp_start_parameters(unaccumulator);
659     for (BasicType type; (type = fp_next_parameter(unaccumulator)) != (BasicType)fp_parameters_done; ) {
660       assert(fp_is_valid_type(type), "garbled fingerprint");
661       callback->do_type(type);
662     }
663   }
664 }
665 
666 #ifdef ASSERT
667  class SignatureVerifier : public StackObj {
668   public:
669     static bool is_valid_method_signature(const Symbol* sig);
670     static bool is_valid_type_signature(const Symbol* sig);
671   private:
672     static ssize_t is_valid_type(const char*, ssize_t);
673 };
674 #endif
675 #endif // SHARE_RUNTIME_SIGNATURE_HPP
< prev index next >