src/hotspot/share/classfile/classFileStream.cpp
changeset 54042 6dd6f988b4e4
parent 47216 71c04702a3d5
child 54257 21702e87efdf
equal deleted inserted replaced
54041:bba6644b6fe3 54042:6dd6f988b4e4
    28 #include "classfile/dictionary.hpp"
    28 #include "classfile/dictionary.hpp"
    29 #include "classfile/vmSymbols.hpp"
    29 #include "classfile/vmSymbols.hpp"
    30 #include "memory/resourceArea.hpp"
    30 #include "memory/resourceArea.hpp"
    31 
    31 
    32 const bool ClassFileStream::verify = true;
    32 const bool ClassFileStream::verify = true;
    33 const bool ClassFileStream::no_verification = false;
       
    34 
    33 
    35 void ClassFileStream::truncated_file_error(TRAPS) const {
    34 void ClassFileStream::truncated_file_error(TRAPS) const {
    36   THROW_MSG(vmSymbols::java_lang_ClassFormatError(), "Truncated class file");
    35   THROW_MSG(vmSymbols::java_lang_ClassFormatError(), "Truncated class file");
    37 }
    36 }
    38 
    37 
    71                              length(),
    70                              length(),
    72                              clone_source(),
    71                              clone_source(),
    73                              need_verify());
    72                              need_verify());
    74 }
    73 }
    75 
    74 
    76 u1 ClassFileStream::get_u1(TRAPS) const {
       
    77   if (_need_verify) {
       
    78     guarantee_more(1, CHECK_0);
       
    79   } else {
       
    80     assert(1 <= _buffer_end - _current, "buffer overflow");
       
    81   }
       
    82   return *_current++;
       
    83 }
       
    84 
       
    85 u2 ClassFileStream::get_u2(TRAPS) const {
       
    86   if (_need_verify) {
       
    87     guarantee_more(2, CHECK_0);
       
    88   } else {
       
    89     assert(2 <= _buffer_end - _current, "buffer overflow");
       
    90   }
       
    91   const u1* tmp = _current;
       
    92   _current += 2;
       
    93   return Bytes::get_Java_u2((address)tmp);
       
    94 }
       
    95 
       
    96 u4 ClassFileStream::get_u4(TRAPS) const {
       
    97   if (_need_verify) {
       
    98     guarantee_more(4, CHECK_0);
       
    99   } else {
       
   100     assert(4 <= _buffer_end - _current, "buffer overflow");
       
   101   }
       
   102   const u1* tmp = _current;
       
   103   _current += 4;
       
   104   return Bytes::get_Java_u4((address)tmp);
       
   105 }
       
   106 
       
   107 u8 ClassFileStream::get_u8(TRAPS) const {
       
   108   if (_need_verify) {
       
   109     guarantee_more(8, CHECK_0);
       
   110   } else {
       
   111     assert(8 <= _buffer_end - _current, "buffer overflow");
       
   112   }
       
   113   const u1* tmp = _current;
       
   114   _current += 8;
       
   115   return Bytes::get_Java_u8((address)tmp);
       
   116 }
       
   117 
       
   118 void ClassFileStream::skip_u1(int length, TRAPS) const {
       
   119   if (_need_verify) {
       
   120     guarantee_more(length, CHECK);
       
   121   }
       
   122   _current += length;
       
   123 }
       
   124 
       
   125 void ClassFileStream::skip_u2(int length, TRAPS) const {
       
   126   if (_need_verify) {
       
   127     guarantee_more(length * 2, CHECK);
       
   128   }
       
   129   _current += length * 2;
       
   130 }
       
   131 
       
   132 void ClassFileStream::skip_u4(int length, TRAPS) const {
       
   133   if (_need_verify) {
       
   134     guarantee_more(length * 4, CHECK);
       
   135   }
       
   136   _current += length * 4;
       
   137 }
       
   138 
       
   139 uint64_t ClassFileStream::compute_fingerprint() const {
    75 uint64_t ClassFileStream::compute_fingerprint() const {
   140   int classfile_size = length();
    76   int classfile_size = length();
   141   int classfile_crc = ClassLoader::crc32(0, (const char*)buffer(), length());
    77   int classfile_crc = ClassLoader::crc32(0, (const char*)buffer(), length());
   142   uint64_t fingerprint = (uint64_t(classfile_size) << 32) | uint64_t(uint32_t(classfile_crc));
    78   uint64_t fingerprint = (uint64_t(classfile_size) << 32) | uint64_t(uint32_t(classfile_crc));
   143   assert(fingerprint != 0, "must not be zero");
    79   assert(fingerprint != 0, "must not be zero");