27 28 #include "memory/allocation.hpp" 29 #include "utilities/bytes.hpp" 30 #include "utilities/exceptions.hpp" 31 32 // Input stream for reading .class file 33 // 34 // The entire input stream is present in a buffer allocated by the caller. 35 // The caller is responsible for deallocating the buffer and for using 36 // ResourceMarks appropriately when constructing streams. 37 38 class ClassPathEntry; 39 40 class ClassFileStream: public ResourceObj { 41 private: 42 const u1* const _buffer_start; // Buffer bottom 43 const u1* const _buffer_end; // Buffer top (one past last element) 44 mutable const u1* _current; // Current buffer position 45 const char* const _source; // Source of stream (directory name, ZIP/JAR archive name) 46 bool _need_verify; // True if verification is on for the class file 47 48 void truncated_file_error(TRAPS) const ; 49 50 protected: 51 const u1* clone_buffer() const; 52 const char* const clone_source() const; 53 54 public: 55 static const bool no_verification; 56 static const bool verify; 57 58 ClassFileStream(const u1* buffer, 59 int length, 60 const char* source, 61 bool verify_stream = verify); // to be verified by default 62 63 virtual const ClassFileStream* clone() const; 64 65 // Buffer access 66 const u1* buffer() const { return _buffer_start; } 67 int length() const { return _buffer_end - _buffer_start; } 68 const u1* current() const { return _current; } 69 void set_current(const u1* pos) const { 70 assert(pos >= _buffer_start && pos <= _buffer_end, "invariant"); 71 _current = pos; 72 } 73 74 // for relative positioning 75 juint current_offset() const { 76 return (juint)(_current - _buffer_start); 77 } 78 const char* source() const { return _source; } 79 bool need_verify() const { return _need_verify; } 80 void set_verify(bool flag) { _need_verify = flag; } 81 82 void check_truncated_file(bool b, TRAPS) const { 83 if (b) { 84 truncated_file_error(THREAD); 85 } 86 } 87 88 void guarantee_more(int size, TRAPS) const { 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) const; 96 u1 get_u1_fast() const { 97 return *_current++; 98 } 99 100 // Read u2 from stream | 27 28 #include "memory/allocation.hpp" 29 #include "utilities/bytes.hpp" 30 #include "utilities/exceptions.hpp" 31 32 // Input stream for reading .class file 33 // 34 // The entire input stream is present in a buffer allocated by the caller. 35 // The caller is responsible for deallocating the buffer and for using 36 // ResourceMarks appropriately when constructing streams. 37 38 class ClassPathEntry; 39 40 class ClassFileStream: public ResourceObj { 41 private: 42 const u1* const _buffer_start; // Buffer bottom 43 const u1* const _buffer_end; // Buffer top (one past last element) 44 mutable const u1* _current; // Current buffer position 45 const char* const _source; // Source of stream (directory name, ZIP/JAR archive name) 46 bool _need_verify; // True if verification is on for the class file 47 bool _from_modules_image; // True if this was created by ClassPathImageEntry. 48 void truncated_file_error(TRAPS) const ; 49 50 protected: 51 const u1* clone_buffer() const; 52 const char* const clone_source() const; 53 54 public: 55 static const bool no_verification; 56 static const bool verify; 57 58 ClassFileStream(const u1* buffer, 59 int length, 60 const char* source, 61 bool verify_stream = verify, // to be verified by default 62 bool from_modules_image = false); 63 64 virtual const ClassFileStream* clone() const; 65 66 // Buffer access 67 const u1* buffer() const { return _buffer_start; } 68 int length() const { return _buffer_end - _buffer_start; } 69 const u1* current() const { return _current; } 70 void set_current(const u1* pos) const { 71 assert(pos >= _buffer_start && pos <= _buffer_end, "invariant"); 72 _current = pos; 73 } 74 75 // for relative positioning 76 juint current_offset() const { 77 return (juint)(_current - _buffer_start); 78 } 79 const char* source() const { return _source; } 80 bool need_verify() const { return _need_verify; } 81 void set_verify(bool flag) { _need_verify = flag; } 82 bool from_modules_image() const { return _from_modules_image; } 83 84 void check_truncated_file(bool b, TRAPS) const { 85 if (b) { 86 truncated_file_error(THREAD); 87 } 88 } 89 90 void guarantee_more(int size, TRAPS) const { 91 size_t remaining = (size_t)(_buffer_end - _current); 92 unsigned int usize = (unsigned int)size; 93 check_truncated_file(usize > remaining, CHECK); 94 } 95 96 // Read u1 from stream 97 u1 get_u1(TRAPS) const; 98 u1 get_u1_fast() const { 99 return *_current++; 100 } 101 102 // Read u2 from stream |