src/share/vm/code/compressedStream.hpp

changeset 0
f90c822e73f8
child 6876
710a3c8b516e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/code/compressedStream.hpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,127 @@
     1.4 +/*
     1.5 + * Copyright (c) 1997, 2010, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#ifndef SHARE_VM_CODE_COMPRESSEDSTREAM_HPP
    1.29 +#define SHARE_VM_CODE_COMPRESSEDSTREAM_HPP
    1.30 +
    1.31 +#include "memory/allocation.hpp"
    1.32 +
    1.33 +// Simple interface for filing out and filing in basic types
    1.34 +// Used for writing out and reading in debugging information.
    1.35 +
    1.36 +class CompressedStream : public ResourceObj {
    1.37 +  friend class VMStructs;
    1.38 + protected:
    1.39 +  u_char* _buffer;
    1.40 +  int     _position;
    1.41 +
    1.42 +  enum {
    1.43 +    // Constants for UNSIGNED5 coding of Pack200
    1.44 +    lg_H = 6, H = 1<<lg_H,    // number of high codes (64)
    1.45 +    L = (1<<BitsPerByte)-H,   // number of low codes (192)
    1.46 +    MAX_i = 4                 // bytes are numbered in (0..4), max 5 bytes
    1.47 +  };
    1.48 +
    1.49 +  // these inlines are defined only in compressedStream.cpp
    1.50 +  static inline juint encode_sign(jint  value);  // for Pack200 SIGNED5
    1.51 +  static inline jint  decode_sign(juint value);  // for Pack200 SIGNED5
    1.52 +  static inline juint reverse_int(juint bits);   // to trim trailing float 0's
    1.53 +
    1.54 + public:
    1.55 +  CompressedStream(u_char* buffer, int position = 0) {
    1.56 +    _buffer   = buffer;
    1.57 +    _position = position;
    1.58 +  }
    1.59 +
    1.60 +  u_char* buffer() const               { return _buffer; }
    1.61 +
    1.62 +  // Positioning
    1.63 +  int position() const                 { return _position; }
    1.64 +  void set_position(int position)      { _position = position; }
    1.65 +};
    1.66 +
    1.67 +
    1.68 +class CompressedReadStream : public CompressedStream {
    1.69 + private:
    1.70 +  inline u_char read()                 { return _buffer[_position++]; }
    1.71 +
    1.72 +  jint     read_int_mb(jint b0);  // UNSIGNED5 coding, 2-5 byte cases
    1.73 +
    1.74 + public:
    1.75 +  CompressedReadStream(u_char* buffer, int position = 0)
    1.76 +  : CompressedStream(buffer, position) {}
    1.77 +
    1.78 +  jboolean read_bool()                 { return (jboolean) read();      }
    1.79 +  jbyte    read_byte()                 { return (jbyte   ) read();      }
    1.80 +  jchar    read_char()                 { return (jchar   ) read_int();  }
    1.81 +  jshort   read_short()                { return (jshort  ) read_signed_int(); }
    1.82 +  jint     read_int()                  { jint   b0 = read();
    1.83 +                                         if (b0 < L)  return b0;
    1.84 +                                         else         return read_int_mb(b0);
    1.85 +                                       }
    1.86 +  jint     read_signed_int();
    1.87 +  jfloat   read_float();               // jfloat_cast(reverse_int(read_int()))
    1.88 +  jdouble  read_double();              // jdouble_cast(2*reverse_int(read_int))
    1.89 +  jlong    read_long();                // jlong_from(2*read_signed_int())
    1.90 +};
    1.91 +
    1.92 +
    1.93 +class CompressedWriteStream : public CompressedStream {
    1.94 + private:
    1.95 +  bool full() {
    1.96 +    return _position >= _size;
    1.97 +  }
    1.98 +  void store(u_char b) {
    1.99 +    _buffer[_position++] = b;
   1.100 +  }
   1.101 +  void write(u_char b) {
   1.102 +    if (full()) grow();
   1.103 +    store(b);
   1.104 +  }
   1.105 +  void grow();
   1.106 +
   1.107 +  void write_int_mb(jint value);  // UNSIGNED5 coding, 1-5 byte cases
   1.108 +
   1.109 + protected:
   1.110 +  int _size;
   1.111 +
   1.112 + public:
   1.113 +  CompressedWriteStream(int initial_size);
   1.114 +  CompressedWriteStream(u_char* buffer, int initial_size, int position = 0)
   1.115 +  : CompressedStream(buffer, position) { _size = initial_size; }
   1.116 +
   1.117 +  void write_bool(jboolean value)      { write(value);      }
   1.118 +  void write_byte(jbyte value)         { write(value);      }
   1.119 +  void write_char(jchar value)         { write_int(value); }
   1.120 +  void write_short(jshort value)       { write_signed_int(value);  }
   1.121 +  void write_int(jint value)           { if ((juint)value < L && !full())
   1.122 +                                               store((u_char)value);
   1.123 +                                         else  write_int_mb(value);  }
   1.124 +  void write_signed_int(jint value);   // write_int(encode_sign(value))
   1.125 +  void write_float(jfloat value);      // write_int(reverse_int(jint_cast(v)))
   1.126 +  void write_double(jdouble value);    // write_int(reverse_int(<low,high>))
   1.127 +  void write_long(jlong value);        // write_signed_int(<low,high>)
   1.128 +};
   1.129 +
   1.130 +#endif // SHARE_VM_CODE_COMPRESSEDSTREAM_HPP

mercurial