src/share/vm/classfile/stackMapTable.hpp

Thu, 12 Oct 2017 21:27:07 +0800

author
aoqi
date
Thu, 12 Oct 2017 21:27:07 +0800
changeset 7535
7ae4e26cb1e0
parent 6876
710a3c8b516e
child 8856
ac27a9c85bea
permissions
-rw-r--r--

merge

     1 /*
     2  * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  *
    23  */
    25 /*
    26  * This file has been modified by Loongson Technology in 2015. These
    27  * modifications are Copyright (c) 2015 Loongson Technology, and are made
    28  * available on the same license terms set forth above.
    29  */
    31 #ifndef SHARE_VM_CLASSFILE_STACKMAPTABLE_HPP
    32 #define SHARE_VM_CLASSFILE_STACKMAPTABLE_HPP
    34 #include "classfile/stackMapFrame.hpp"
    35 #include "classfile/verifier.hpp"
    36 #include "memory/allocation.hpp"
    37 #include "oops/constantPool.hpp"
    38 #include "oops/method.hpp"
    39 #include "utilities/globalDefinitions.hpp"
    40 #ifdef TARGET_ARCH_x86
    41 # include "bytes_x86.hpp"
    42 #endif
    43 #ifdef TARGET_ARCH_mips
    44 # include "bytes_mips.hpp"
    45 #endif
    46 #ifdef TARGET_ARCH_sparc
    47 # include "bytes_sparc.hpp"
    48 #endif
    49 #ifdef TARGET_ARCH_zero
    50 # include "bytes_zero.hpp"
    51 #endif
    52 #ifdef TARGET_ARCH_arm
    53 # include "bytes_arm.hpp"
    54 #endif
    55 #ifdef TARGET_ARCH_ppc
    56 # include "bytes_ppc.hpp"
    57 #endif
    59 class StackMapReader;
    61 // StackMapTable class is the StackMap table used by type checker
    62 class StackMapTable : public StackObj {
    63  private:
    64   // Logically, the _frame_count (as well as many fields in the StackFrame)
    65   // should be a u2, but if we defined the variable as that type it will
    66   // be difficult to detect/recover from overflow or underflow conditions.
    67   // Widening the type and making it signed will help detect these.
    68   int32_t              _code_length;
    69   int32_t              _frame_count;     // Stackmap frame count
    70   StackMapFrame**       _frame_array;
    72  public:
    73   StackMapTable(StackMapReader* reader, StackMapFrame* init_frame,
    74                 u2 max_locals, u2 max_stack,
    75                 char* code_data, int code_len, TRAPS);
    77   inline int32_t get_frame_count() const { return _frame_count; }
    78   inline int get_offset(int index) const {
    79     return _frame_array[index]->offset();
    80   }
    82   // Match and/or update current_frame to the frame in stackmap table with
    83   // specified offset. Return true if the two frames match.
    84   bool match_stackmap(
    85     StackMapFrame* current_frame, int32_t offset,
    86     bool match, bool update, bool handler, ErrorContext* ctx, TRAPS) const;
    87   // Match and/or update current_frame to the frame in stackmap table with
    88   // specified offset and frame index. Return true if the two frames match.
    89   bool match_stackmap(
    90     StackMapFrame* current_frame, int32_t offset, int32_t frame_index,
    91     bool match, bool update, bool handler, ErrorContext* ctx, TRAPS) const;
    93   // Check jump instructions. Make sure there are no uninitialized
    94   // instances on backward branch.
    95   void check_jump_target(StackMapFrame* frame, int32_t target, TRAPS) const;
    97   // The following methods are only used inside this class.
    99   // Returns the frame array index where the frame with offset is stored.
   100   int get_index_from_offset(int32_t offset) const;
   102   void print_on(outputStream* str) const;
   103 };
   105 class StackMapStream : StackObj {
   106  private:
   107   Array<u1>* _data;
   108   int _index;
   109  public:
   110   StackMapStream(Array<u1>* ah)
   111     : _data(ah), _index(0) {
   112   }
   113   u1 get_u1(TRAPS) {
   114     if (_data == NULL || _index >= _data->length()) {
   115       stackmap_format_error("access beyond the end of attribute", CHECK_0);
   116     }
   117     return _data->at(_index++);
   118   }
   119   u2 get_u2(TRAPS) {
   120     if (_data == NULL || _index >= _data->length() - 1) {
   121       stackmap_format_error("access beyond the end of attribute", CHECK_0);
   122     }
   123     u2 res = Bytes::get_Java_u2(_data->adr_at(_index));
   124     _index += 2;
   125     return res;
   126   }
   127   bool at_end() {
   128     return (_data == NULL) || (_index == _data->length());
   129   }
   130   static void stackmap_format_error(const char* msg, TRAPS);
   131 };
   133 class StackMapReader : StackObj {
   134  private:
   135   // information about the class and method
   136   constantPoolHandle  _cp;
   137   ClassVerifier* _verifier;
   138   StackMapStream* _stream;
   139   char* _code_data;
   140   int32_t _code_length;
   142   // information get from the attribute
   143   int32_t  _frame_count;       // frame count
   145   int32_t chop(VerificationType* locals, int32_t length, int32_t chops);
   146   VerificationType parse_verification_type(u1* flags, TRAPS);
   147   void check_verification_type_array_size(
   148       int32_t size, int32_t max_size, TRAPS) {
   149     if (size < 0 || size > max_size) {
   150       // Since this error could be caused someone rewriting the method
   151       // but not knowing to update the stackmap data, we call the the
   152       // verifier's error method, which may not throw an exception and
   153       // failover to the old verifier instead.
   154       _verifier->class_format_error(
   155         "StackMapTable format error: bad type array size");
   156     }
   157   }
   159   enum {
   160     SAME_LOCALS_1_STACK_ITEM_EXTENDED = 247,
   161     SAME_EXTENDED = 251,
   162     FULL = 255
   163   };
   165  public:
   166   // Constructor
   167   StackMapReader(ClassVerifier* v, StackMapStream* stream, char* code_data,
   168                  int32_t code_len, TRAPS) :
   169                  _verifier(v), _stream(stream),
   170                  _code_data(code_data), _code_length(code_len) {
   171     methodHandle m = v->method();
   172     if (m->has_stackmap_table()) {
   173       _cp = constantPoolHandle(THREAD, m->constants());
   174       _frame_count = _stream->get_u2(CHECK);
   175     } else {
   176       // There's no stackmap table present. Frame count and size are 0.
   177       _frame_count = 0;
   178     }
   179   }
   181   inline int32_t get_frame_count() const                { return _frame_count; }
   182   StackMapFrame* next(StackMapFrame* pre_frame, bool first,
   183                       u2 max_locals, u2 max_stack, TRAPS);
   185   void check_end(TRAPS) {
   186     if (!_stream->at_end()) {
   187       StackMapStream::stackmap_format_error("wrong attribute size", CHECK);
   188     }
   189   }
   190 };
   192 #endif // SHARE_VM_CLASSFILE_STACKMAPTABLE_HPP

mercurial