< prev index next >

src/share/vm/code/compressedStream.hpp

Print this page
rev 13143 : 8183001: Various inlining improvements
Reviewed-by: iklam, mikael, ehelin


  49   static inline juint reverse_int(juint bits);   // to trim trailing float 0's
  50 
  51  public:
  52   CompressedStream(u_char* buffer, int position = 0) {
  53     _buffer   = buffer;
  54     _position = position;
  55   }
  56 
  57   u_char* buffer() const               { return _buffer; }
  58 
  59   // Positioning
  60   int position() const                 { return _position; }
  61   void set_position(int position)      { _position = position; }
  62 };
  63 
  64 
  65 class CompressedReadStream : public CompressedStream {
  66  private:
  67   inline u_char read()                 { return _buffer[_position++]; }
  68 
  69   jint     read_int_mb(jint b0);  // UNSIGNED5 coding, 2-5 byte cases

































  70 
  71  public:
  72   CompressedReadStream(u_char* buffer, int position = 0)
  73   : CompressedStream(buffer, position) {}
  74 
  75   jboolean read_bool()                 { return (jboolean) read();      }
  76   jbyte    read_byte()                 { return (jbyte   ) read();      }
  77   jchar    read_char()                 { return (jchar   ) read_int();  }
  78   jshort   read_short()                { return (jshort  ) read_signed_int(); }
  79   jint     read_int()                  { jint   b0 = read();
  80                                          if (b0 < L)  return b0;
  81                                          else         return read_int_mb(b0);
  82                                        }
  83   jint     read_signed_int();
  84   jfloat   read_float();               // jfloat_cast(reverse_int(read_int()))
  85   jdouble  read_double();              // jdouble_cast(2*reverse_int(read_int))
  86   jlong    read_long();                // jlong_from(2*read_signed_int())
  87 };
  88 
  89 




  49   static inline juint reverse_int(juint bits);   // to trim trailing float 0's
  50 
  51  public:
  52   CompressedStream(u_char* buffer, int position = 0) {
  53     _buffer   = buffer;
  54     _position = position;
  55   }
  56 
  57   u_char* buffer() const               { return _buffer; }
  58 
  59   // Positioning
  60   int position() const                 { return _position; }
  61   void set_position(int position)      { _position = position; }
  62 };
  63 
  64 
  65 class CompressedReadStream : public CompressedStream {
  66  private:
  67   inline u_char read()                 { return _buffer[_position++]; }
  68 
  69   // This encoding, called UNSIGNED5, is taken from J2SE Pack200.
  70   // It assumes that most values have lots of leading zeroes.
  71   // Very small values, in the range [0..191], code in one byte.
  72   // Any 32-bit value (including negatives) can be coded, in
  73   // up to five bytes.  The grammar is:
  74   //    low_byte  = [0..191]
  75   //    high_byte = [192..255]
  76   //    any_byte  = low_byte | high_byte
  77   //    coding = low_byte
  78   //           | high_byte low_byte
  79   //           | high_byte high_byte low_byte
  80   //           | high_byte high_byte high_byte low_byte
  81   //           | high_byte high_byte high_byte high_byte any_byte
  82   // Each high_byte contributes six bits of payload.
  83   // The encoding is one-to-one (except for integer overflow)
  84   // and easy to parse and unparse.
  85 
  86   jint read_int_mb(jint b0) {
  87     int     pos = position() - 1;
  88     u_char* buf = buffer() + pos;
  89     assert(buf[0] == b0 && b0 >= L, "correctly called");
  90     jint    sum = b0;
  91     // must collect more bytes:  b[1]...b[4]
  92     int lg_H_i = lg_H;
  93     for (int i = 0; ; ) {
  94       jint b_i = buf[++i]; // b_i = read(); ++i;
  95       sum += b_i << lg_H_i;  // sum += b[i]*(64**i)
  96       if (b_i < L || i == MAX_i) {
  97         set_position(pos+i+1);
  98         return sum;
  99       }
 100       lg_H_i += lg_H;
 101     }
 102   }
 103 
 104  public:
 105   CompressedReadStream(u_char* buffer, int position = 0)
 106   : CompressedStream(buffer, position) {}
 107 
 108   jboolean read_bool()                 { return (jboolean) read();      }
 109   jbyte    read_byte()                 { return (jbyte   ) read();      }
 110   jchar    read_char()                 { return (jchar   ) read_int();  }
 111   jshort   read_short()                { return (jshort  ) read_signed_int(); }
 112   jint     read_int()                  { jint   b0 = read();
 113                                          if (b0 < L)  return b0;
 114                                          else         return read_int_mb(b0);
 115                                        }
 116   jint     read_signed_int();
 117   jfloat   read_float();               // jfloat_cast(reverse_int(read_int()))
 118   jdouble  read_double();              // jdouble_cast(2*reverse_int(read_int))
 119   jlong    read_long();                // jlong_from(2*read_signed_int())
 120 };
 121 
 122 


< prev index next >