src/share/vm/classfile/classFileStream.hpp

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 6198
55fb97c4c58d
parent 1
2d8a650513c2
child 7535
7ae4e26cb1e0
permissions
-rw-r--r--

merge

     1 /*
     2  * Copyright (c) 1997, 2013, 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_CLASSFILESTREAM_HPP
    32 #define SHARE_VM_CLASSFILE_CLASSFILESTREAM_HPP
    34 #include "utilities/top.hpp"
    35 #ifdef TARGET_ARCH_x86
    36 # include "bytes_x86.hpp"
    37 #endif
    38 #ifdef TARGET_ARCH_mips
    39 # include "bytes_mips.hpp"
    40 #endif
    41 #ifdef TARGET_ARCH_sparc
    42 # include "bytes_sparc.hpp"
    43 #endif
    44 #ifdef TARGET_ARCH_zero
    45 # include "bytes_zero.hpp"
    46 #endif
    47 #ifdef TARGET_ARCH_arm
    48 # include "bytes_arm.hpp"
    49 #endif
    50 #ifdef TARGET_ARCH_ppc
    51 # include "bytes_ppc.hpp"
    52 #endif
    54 // Input stream for reading .class file
    55 //
    56 // The entire input stream is present in a buffer allocated by the caller.
    57 // The caller is responsible for deallocating the buffer and for using
    58 // ResourceMarks appropriately when constructing streams.
    60 class ClassFileStream: public ResourceObj {
    61  private:
    62   u1*   _buffer_start; // Buffer bottom
    63   u1*   _buffer_end;   // Buffer top (one past last element)
    64   u1*   _current;      // Current buffer position
    65   char* _source;       // Source of stream (directory name, ZIP/JAR archive name)
    66   bool  _need_verify;  // True if verification is on for the class file
    68   void truncated_file_error(TRAPS);
    69  public:
    70   // Constructor
    71   ClassFileStream(u1* buffer, int length, char* source);
    73   // Buffer access
    74   u1* buffer() const           { return _buffer_start; }
    75   int length() const           { return _buffer_end - _buffer_start; }
    76   u1* current() const          { return _current; }
    77   void set_current(u1* pos)    { _current = pos; }
    78   char* source() const         { return _source; }
    79   void set_verify(bool flag)   { _need_verify = flag; }
    81   void check_truncated_file(bool b, TRAPS) {
    82     if (b) {
    83       truncated_file_error(THREAD);
    84     }
    85   }
    87   void guarantee_more(int size, TRAPS) {
    88     size_t remaining = (size_t)(_buffer_end - _current);
    89     unsigned int usize = (unsigned int)size;
    90     check_truncated_file(usize > remaining, CHECK);
    91   }
    93   // Read u1 from stream
    94   u1 get_u1(TRAPS);
    95   u1 get_u1_fast() {
    96     return *_current++;
    97   }
    99   // Read u2 from stream
   100   u2 get_u2(TRAPS);
   101   u2 get_u2_fast() {
   102     u2 res = Bytes::get_Java_u2(_current);
   103     _current += 2;
   104     return res;
   105   }
   107   // Read u4 from stream
   108   u4 get_u4(TRAPS);
   109   u4 get_u4_fast() {
   110     u4 res = Bytes::get_Java_u4(_current);
   111     _current += 4;
   112     return res;
   113   }
   115   // Read u8 from stream
   116   u8 get_u8(TRAPS);
   117   u8 get_u8_fast() {
   118     u8 res = Bytes::get_Java_u8(_current);
   119     _current += 8;
   120     return res;
   121   }
   123   // Get direct pointer into stream at current position.
   124   // Returns NULL if length elements are not remaining. The caller is
   125   // responsible for calling skip below if buffer contents is used.
   126   u1* get_u1_buffer() {
   127     return _current;
   128   }
   130   u2* get_u2_buffer() {
   131     return (u2*) _current;
   132   }
   134   // Skip length u1 or u2 elements from stream
   135   void skip_u1(int length, TRAPS);
   136   void skip_u1_fast(int length) {
   137     _current += length;
   138   }
   140   void skip_u2(int length, TRAPS);
   141   void skip_u2_fast(int length) {
   142     _current += 2 * length;
   143   }
   145   void skip_u4(int length, TRAPS);
   146   void skip_u4_fast(int length) {
   147     _current += 4 * length;
   148   }
   150   // Tells whether eos is reached
   151   bool at_eos() const          { return _current == _buffer_end; }
   152 };
   154 #endif // SHARE_VM_CLASSFILE_CLASSFILESTREAM_HPP

mercurial