< prev index next >

src/share/vm/classfile/classFileStream.hpp

Print this page


   1 /*
   2  * Copyright (c) 1997, 2014, 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  *


  40 #endif
  41 #ifdef TARGET_ARCH_ppc
  42 # include "bytes_ppc.hpp"
  43 #endif
  44 
  45 // Input stream for reading .class file
  46 //
  47 // The entire input stream is present in a buffer allocated by the caller.
  48 // The caller is responsible for deallocating the buffer and for using
  49 // ResourceMarks appropriately when constructing streams.
  50 
  51 class ClassFileStream: public ResourceObj {
  52  private:
  53   u1*   _buffer_start; // Buffer bottom
  54   u1*   _buffer_end;   // Buffer top (one past last element)
  55   u1*   _current;      // Current buffer position
  56   const char* _source; // Source of stream (directory name, ZIP/JAR archive name)
  57   bool  _need_verify;  // True if verification is on for the class file
  58 
  59   void truncated_file_error(TRAPS);






  60  public:
  61   // Constructor
  62   ClassFileStream(u1* buffer, int length, const char* source);
  63 
  64   // Buffer access
  65   u1* buffer() const           { return _buffer_start; }
  66   int length() const           { return _buffer_end - _buffer_start; }
  67   u1* current() const          { return _current; }
  68   void set_current(u1* pos)    { _current = pos; }




  69   const char* source() const   { return _source; }
  70   void set_verify(bool flag)   { _need_verify = flag; }
  71 
  72   void check_truncated_file(bool b, TRAPS) {
  73     if (b) {
  74       truncated_file_error(THREAD);
  75     }
  76   }
  77 
  78   void guarantee_more(int size, TRAPS) {
  79     size_t remaining = (size_t)(_buffer_end - _current);
  80     unsigned int usize = (unsigned int)size;
  81     check_truncated_file(usize > remaining, CHECK);
  82   }
  83 
  84   // Read u1 from stream
  85   u1 get_u1(TRAPS);
  86   u1 get_u1_fast() {
  87     return *_current++;
  88   }


 123   }
 124 
 125   // Skip length u1 or u2 elements from stream
 126   void skip_u1(int length, TRAPS);
 127   void skip_u1_fast(int length) {
 128     _current += length;
 129   }
 130 
 131   void skip_u2(int length, TRAPS);
 132   void skip_u2_fast(int length) {
 133     _current += 2 * length;
 134   }
 135 
 136   void skip_u4(int length, TRAPS);
 137   void skip_u4_fast(int length) {
 138     _current += 4 * length;
 139   }
 140 
 141   // Tells whether eos is reached
 142   bool at_eos() const          { return _current == _buffer_end; }






 143 };
 144 
 145 #endif // SHARE_VM_CLASSFILE_CLASSFILESTREAM_HPP
   1 /*
   2  * Copyright (c) 1997, 2015, 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  *


  40 #endif
  41 #ifdef TARGET_ARCH_ppc
  42 # include "bytes_ppc.hpp"
  43 #endif
  44 
  45 // Input stream for reading .class file
  46 //
  47 // The entire input stream is present in a buffer allocated by the caller.
  48 // The caller is responsible for deallocating the buffer and for using
  49 // ResourceMarks appropriately when constructing streams.
  50 
  51 class ClassFileStream: public ResourceObj {
  52  private:
  53   u1*   _buffer_start; // Buffer bottom
  54   u1*   _buffer_end;   // Buffer top (one past last element)
  55   u1*   _current;      // Current buffer position
  56   const char* _source; // Source of stream (directory name, ZIP/JAR archive name)
  57   bool  _need_verify;  // True if verification is on for the class file
  58 
  59   void truncated_file_error(TRAPS);
  60 
  61 #if INCLUDE_JFR
  62   u1* clone_buffer() const;
  63   const char* const clone_source() const;
  64 #endif
  65 
  66  public:
  67   // Constructor
  68   ClassFileStream(u1* buffer, int length, const char* source, bool need_verify = false);
  69 
  70   // Buffer access
  71   u1* buffer() const           { return _buffer_start; }
  72   int length() const           { return _buffer_end - _buffer_start; }
  73   u1* current() const          { return _current; }
  74   void set_current(u1* pos)    { _current = pos; }
  75   // for relative positioning
  76   juint current_offset() const {
  77     return (juint)(_current - _buffer_start);
  78   }
  79   const char* source() const   { return _source; }
  80   void set_verify(bool flag)   { _need_verify = flag; }
  81 
  82   void check_truncated_file(bool b, TRAPS) {
  83     if (b) {
  84       truncated_file_error(THREAD);
  85     }
  86   }
  87 
  88   void guarantee_more(int size, TRAPS) {
  89     size_t remaining = (size_t)(_buffer_end - _current);
  90     unsigned int usize = (unsigned int)size;
  91     check_truncated_file(usize > remaining, CHECK);
  92   }
  93 
  94   // Read u1 from stream
  95   u1 get_u1(TRAPS);
  96   u1 get_u1_fast() {
  97     return *_current++;
  98   }


 133   }
 134 
 135   // Skip length u1 or u2 elements from stream
 136   void skip_u1(int length, TRAPS);
 137   void skip_u1_fast(int length) {
 138     _current += length;
 139   }
 140 
 141   void skip_u2(int length, TRAPS);
 142   void skip_u2_fast(int length) {
 143     _current += 2 * length;
 144   }
 145 
 146   void skip_u4(int length, TRAPS);
 147   void skip_u4_fast(int length) {
 148     _current += 4 * length;
 149   }
 150 
 151   // Tells whether eos is reached
 152   bool at_eos() const          { return _current == _buffer_end; }
 153 
 154 #if INCLUDE_JFR
 155   ClassFileStream* clone() const;
 156 
 157   bool need_verify() const { return _need_verify; }
 158 #endif
 159 };
 160 
 161 #endif // SHARE_VM_CLASSFILE_CLASSFILESTREAM_HPP
< prev index next >