< 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 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   Symbol* _name;      // Symbol for printing
583   bool _null_marker;  // Is it a null marker? For printing
584 
585   SigEntry()
586     : _bt(T_ILLEGAL), _offset(-1), _name(nullptr) {}
587 
588   SigEntry(BasicType bt, int offset, Symbol* name, bool null_marker)
589     : _bt(bt), _offset(offset), _name(name), _null_marker(null_marker) {}
590 
591   static void add_entry(GrowableArray<SigEntry>* sig, BasicType bt, Symbol* name = nullptr, int offset = -1);
592   static void add_null_marker(GrowableArray<SigEntry>* sig, Symbol* name, int offset);
593   static bool skip_value_delimiters(const GrowableArray<SigEntry>* sig, int i);
594   static int fill_sig_bt(const GrowableArray<SigEntry>* sig, BasicType* sig_bt);
595   static TempNewSymbol create_symbol(const GrowableArray<SigEntry>* sig);
596 };
597 
598 class SigEntryFilter {
599 public:
600   bool operator()(const SigEntry& entry) { return entry._bt != T_METADATA && entry._bt != T_VOID; }
601 };
602 
603 // Specialized SignatureStream: used for invoking SystemDictionary to either find
604 //                              or resolve the underlying type when iterating over a
605 //                              Java descriptor (or parts of it).
606 class ResolvingSignatureStream : public SignatureStream {
607   Klass*       _load_origin;
608   bool         _handles_cached;
609   Handle       _class_loader;       // cached when needed
610 
611   void initialize_load_origin(Klass* load_origin) {
612     _load_origin = load_origin;
613     _handles_cached = (load_origin == nullptr);
614   }
615   void need_handles() {
616     if (!_handles_cached) {
617       cache_handles();
618       _handles_cached = true;
619     }
620   }
621   void cache_handles();
622 

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