src/share/vm/code/compressedStream.hpp

changeset 435
a61af66fc99e
child 1907
c18cbe5936b8
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/code/compressedStream.hpp	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,120 @@
     1.4 +/*
     1.5 + * Copyright 1997-2005 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.24 + * have any questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +// Simple interface for filing out and filing in basic types
    1.29 +// Used for writing out and reading in debugging information.
    1.30 +
    1.31 +class CompressedStream : public ResourceObj {
    1.32 +  friend class VMStructs;
    1.33 + protected:
    1.34 +  u_char* _buffer;
    1.35 +  int     _position;
    1.36 +
    1.37 +  enum {
    1.38 +    // Constants for UNSIGNED5 coding of Pack200
    1.39 +    lg_H = 6, H = 1<<lg_H,    // number of high codes (64)
    1.40 +    L = (1<<BitsPerByte)-H,   // number of low codes (192)
    1.41 +    MAX_i = 4                 // bytes are numbered in (0..4), max 5 bytes
    1.42 +  };
    1.43 +
    1.44 +  // these inlines are defined only in compressedStream.cpp
    1.45 +  static inline juint encode_sign(jint  value);  // for Pack200 SIGNED5
    1.46 +  static inline jint  decode_sign(juint value);  // for Pack200 SIGNED5
    1.47 +  static inline juint reverse_int(juint bits);   // to trim trailing float 0's
    1.48 +
    1.49 + public:
    1.50 +  CompressedStream(u_char* buffer, int position = 0) {
    1.51 +    _buffer   = buffer;
    1.52 +    _position = position;
    1.53 +  }
    1.54 +
    1.55 +  u_char* buffer() const               { return _buffer; }
    1.56 +
    1.57 +  // Positioning
    1.58 +  int position() const                 { return _position; }
    1.59 +  void set_position(int position)      { _position = position; }
    1.60 +};
    1.61 +
    1.62 +
    1.63 +class CompressedReadStream : public CompressedStream {
    1.64 + private:
    1.65 +  inline u_char read()                 { return _buffer[_position++]; }
    1.66 +
    1.67 +  jint     read_int_mb(jint b0);  // UNSIGNED5 coding, 2-5 byte cases
    1.68 +
    1.69 + public:
    1.70 +  CompressedReadStream(u_char* buffer, int position = 0)
    1.71 +  : CompressedStream(buffer, position) {}
    1.72 +
    1.73 +  jboolean read_bool()                 { return (jboolean) read();      }
    1.74 +  jbyte    read_byte()                 { return (jbyte   ) read();      }
    1.75 +  jchar    read_char()                 { return (jchar   ) read_int();  }
    1.76 +  jshort   read_short()                { return (jshort  ) read_signed_int(); }
    1.77 +  jint     read_int()                  { jint   b0 = read();
    1.78 +                                         if (b0 < L)  return b0;
    1.79 +                                         else         return read_int_mb(b0);
    1.80 +                                       }
    1.81 +  jint     read_signed_int();
    1.82 +  jfloat   read_float();               // jfloat_cast(reverse_int(read_int()))
    1.83 +  jdouble  read_double();              // jdouble_cast(2*reverse_int(read_int))
    1.84 +  jlong    read_long();                // jlong_from(2*read_signed_int())
    1.85 +};
    1.86 +
    1.87 +
    1.88 +class CompressedWriteStream : public CompressedStream {
    1.89 + private:
    1.90 +  bool full() {
    1.91 +    return _position >= _size;
    1.92 +  }
    1.93 +  void store(u_char b) {
    1.94 +    _buffer[_position++] = b;
    1.95 +  }
    1.96 +  void write(u_char b) {
    1.97 +    if (full()) grow();
    1.98 +    store(b);
    1.99 +  }
   1.100 +  void grow();
   1.101 +
   1.102 +  void write_int_mb(jint value);  // UNSIGNED5 coding, 1-5 byte cases
   1.103 +
   1.104 + protected:
   1.105 +  int _size;
   1.106 +
   1.107 + public:
   1.108 +  CompressedWriteStream(int initial_size);
   1.109 +  CompressedWriteStream(u_char* buffer, int initial_size, int position = 0)
   1.110 +  : CompressedStream(buffer, position) { _size = initial_size; }
   1.111 +
   1.112 +  void write_bool(jboolean value)      { write(value);      }
   1.113 +  void write_byte(jbyte value)         { write(value);      }
   1.114 +  void write_char(jchar value)         { write_int(value); }
   1.115 +  void write_short(jshort value)       { write_signed_int(value);  }
   1.116 +  void write_int(jint value)           { if ((juint)value < L && !full())
   1.117 +                                               store((u_char)value);
   1.118 +                                         else  write_int_mb(value);  }
   1.119 +  void write_signed_int(jint value);   // write_int(encode_sign(value))
   1.120 +  void write_float(jfloat value);      // write_int(reverse_int(jint_cast(v)))
   1.121 +  void write_double(jdouble value);    // write_int(reverse_int(<low,high>))
   1.122 +  void write_long(jlong value);        // write_signed_int(<low,high>)
   1.123 +};

mercurial