src/share/vm/code/compressedStream.hpp

Wed, 02 Jun 2010 22:45:42 -0700

author
jrose
date
Wed, 02 Jun 2010 22:45:42 -0700
changeset 1934
e9ff18c4ace7
parent 1907
c18cbe5936b8
child 2314
f95d63e2154a
permissions
-rw-r--r--

Merge

duke@435 1 /*
trims@1907 2 * Copyright (c) 1997, 2005, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 // Simple interface for filing out and filing in basic types
duke@435 26 // Used for writing out and reading in debugging information.
duke@435 27
duke@435 28 class CompressedStream : public ResourceObj {
duke@435 29 friend class VMStructs;
duke@435 30 protected:
duke@435 31 u_char* _buffer;
duke@435 32 int _position;
duke@435 33
duke@435 34 enum {
duke@435 35 // Constants for UNSIGNED5 coding of Pack200
duke@435 36 lg_H = 6, H = 1<<lg_H, // number of high codes (64)
duke@435 37 L = (1<<BitsPerByte)-H, // number of low codes (192)
duke@435 38 MAX_i = 4 // bytes are numbered in (0..4), max 5 bytes
duke@435 39 };
duke@435 40
duke@435 41 // these inlines are defined only in compressedStream.cpp
duke@435 42 static inline juint encode_sign(jint value); // for Pack200 SIGNED5
duke@435 43 static inline jint decode_sign(juint value); // for Pack200 SIGNED5
duke@435 44 static inline juint reverse_int(juint bits); // to trim trailing float 0's
duke@435 45
duke@435 46 public:
duke@435 47 CompressedStream(u_char* buffer, int position = 0) {
duke@435 48 _buffer = buffer;
duke@435 49 _position = position;
duke@435 50 }
duke@435 51
duke@435 52 u_char* buffer() const { return _buffer; }
duke@435 53
duke@435 54 // Positioning
duke@435 55 int position() const { return _position; }
duke@435 56 void set_position(int position) { _position = position; }
duke@435 57 };
duke@435 58
duke@435 59
duke@435 60 class CompressedReadStream : public CompressedStream {
duke@435 61 private:
duke@435 62 inline u_char read() { return _buffer[_position++]; }
duke@435 63
duke@435 64 jint read_int_mb(jint b0); // UNSIGNED5 coding, 2-5 byte cases
duke@435 65
duke@435 66 public:
duke@435 67 CompressedReadStream(u_char* buffer, int position = 0)
duke@435 68 : CompressedStream(buffer, position) {}
duke@435 69
duke@435 70 jboolean read_bool() { return (jboolean) read(); }
duke@435 71 jbyte read_byte() { return (jbyte ) read(); }
duke@435 72 jchar read_char() { return (jchar ) read_int(); }
duke@435 73 jshort read_short() { return (jshort ) read_signed_int(); }
duke@435 74 jint read_int() { jint b0 = read();
duke@435 75 if (b0 < L) return b0;
duke@435 76 else return read_int_mb(b0);
duke@435 77 }
duke@435 78 jint read_signed_int();
duke@435 79 jfloat read_float(); // jfloat_cast(reverse_int(read_int()))
duke@435 80 jdouble read_double(); // jdouble_cast(2*reverse_int(read_int))
duke@435 81 jlong read_long(); // jlong_from(2*read_signed_int())
duke@435 82 };
duke@435 83
duke@435 84
duke@435 85 class CompressedWriteStream : public CompressedStream {
duke@435 86 private:
duke@435 87 bool full() {
duke@435 88 return _position >= _size;
duke@435 89 }
duke@435 90 void store(u_char b) {
duke@435 91 _buffer[_position++] = b;
duke@435 92 }
duke@435 93 void write(u_char b) {
duke@435 94 if (full()) grow();
duke@435 95 store(b);
duke@435 96 }
duke@435 97 void grow();
duke@435 98
duke@435 99 void write_int_mb(jint value); // UNSIGNED5 coding, 1-5 byte cases
duke@435 100
duke@435 101 protected:
duke@435 102 int _size;
duke@435 103
duke@435 104 public:
duke@435 105 CompressedWriteStream(int initial_size);
duke@435 106 CompressedWriteStream(u_char* buffer, int initial_size, int position = 0)
duke@435 107 : CompressedStream(buffer, position) { _size = initial_size; }
duke@435 108
duke@435 109 void write_bool(jboolean value) { write(value); }
duke@435 110 void write_byte(jbyte value) { write(value); }
duke@435 111 void write_char(jchar value) { write_int(value); }
duke@435 112 void write_short(jshort value) { write_signed_int(value); }
duke@435 113 void write_int(jint value) { if ((juint)value < L && !full())
duke@435 114 store((u_char)value);
duke@435 115 else write_int_mb(value); }
duke@435 116 void write_signed_int(jint value); // write_int(encode_sign(value))
duke@435 117 void write_float(jfloat value); // write_int(reverse_int(jint_cast(v)))
duke@435 118 void write_double(jdouble value); // write_int(reverse_int(<low,high>))
duke@435 119 void write_long(jlong value); // write_signed_int(<low,high>)
duke@435 120 };

mercurial