src/share/vm/code/compressedStream.hpp

Wed, 25 Jun 2014 08:56:57 +0200

author
stefank
date
Wed, 25 Jun 2014 08:56:57 +0200
changeset 6985
c64b6b0c40c8
parent 2314
f95d63e2154a
child 6876
710a3c8b516e
permissions
-rw-r--r--

8047326: Consolidate all CompiledIC::CompiledIC implementations and move it to compiledIC.cpp
Reviewed-by: vlivanov, ehelin

duke@435 1 /*
stefank@2314 2 * Copyright (c) 1997, 2010, 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
stefank@2314 25 #ifndef SHARE_VM_CODE_COMPRESSEDSTREAM_HPP
stefank@2314 26 #define SHARE_VM_CODE_COMPRESSEDSTREAM_HPP
stefank@2314 27
stefank@2314 28 #include "memory/allocation.hpp"
stefank@2314 29
duke@435 30 // Simple interface for filing out and filing in basic types
duke@435 31 // Used for writing out and reading in debugging information.
duke@435 32
duke@435 33 class CompressedStream : public ResourceObj {
duke@435 34 friend class VMStructs;
duke@435 35 protected:
duke@435 36 u_char* _buffer;
duke@435 37 int _position;
duke@435 38
duke@435 39 enum {
duke@435 40 // Constants for UNSIGNED5 coding of Pack200
duke@435 41 lg_H = 6, H = 1<<lg_H, // number of high codes (64)
duke@435 42 L = (1<<BitsPerByte)-H, // number of low codes (192)
duke@435 43 MAX_i = 4 // bytes are numbered in (0..4), max 5 bytes
duke@435 44 };
duke@435 45
duke@435 46 // these inlines are defined only in compressedStream.cpp
duke@435 47 static inline juint encode_sign(jint value); // for Pack200 SIGNED5
duke@435 48 static inline jint decode_sign(juint value); // for Pack200 SIGNED5
duke@435 49 static inline juint reverse_int(juint bits); // to trim trailing float 0's
duke@435 50
duke@435 51 public:
duke@435 52 CompressedStream(u_char* buffer, int position = 0) {
duke@435 53 _buffer = buffer;
duke@435 54 _position = position;
duke@435 55 }
duke@435 56
duke@435 57 u_char* buffer() const { return _buffer; }
duke@435 58
duke@435 59 // Positioning
duke@435 60 int position() const { return _position; }
duke@435 61 void set_position(int position) { _position = position; }
duke@435 62 };
duke@435 63
duke@435 64
duke@435 65 class CompressedReadStream : public CompressedStream {
duke@435 66 private:
duke@435 67 inline u_char read() { return _buffer[_position++]; }
duke@435 68
duke@435 69 jint read_int_mb(jint b0); // UNSIGNED5 coding, 2-5 byte cases
duke@435 70
duke@435 71 public:
duke@435 72 CompressedReadStream(u_char* buffer, int position = 0)
duke@435 73 : CompressedStream(buffer, position) {}
duke@435 74
duke@435 75 jboolean read_bool() { return (jboolean) read(); }
duke@435 76 jbyte read_byte() { return (jbyte ) read(); }
duke@435 77 jchar read_char() { return (jchar ) read_int(); }
duke@435 78 jshort read_short() { return (jshort ) read_signed_int(); }
duke@435 79 jint read_int() { jint b0 = read();
duke@435 80 if (b0 < L) return b0;
duke@435 81 else return read_int_mb(b0);
duke@435 82 }
duke@435 83 jint read_signed_int();
duke@435 84 jfloat read_float(); // jfloat_cast(reverse_int(read_int()))
duke@435 85 jdouble read_double(); // jdouble_cast(2*reverse_int(read_int))
duke@435 86 jlong read_long(); // jlong_from(2*read_signed_int())
duke@435 87 };
duke@435 88
duke@435 89
duke@435 90 class CompressedWriteStream : public CompressedStream {
duke@435 91 private:
duke@435 92 bool full() {
duke@435 93 return _position >= _size;
duke@435 94 }
duke@435 95 void store(u_char b) {
duke@435 96 _buffer[_position++] = b;
duke@435 97 }
duke@435 98 void write(u_char b) {
duke@435 99 if (full()) grow();
duke@435 100 store(b);
duke@435 101 }
duke@435 102 void grow();
duke@435 103
duke@435 104 void write_int_mb(jint value); // UNSIGNED5 coding, 1-5 byte cases
duke@435 105
duke@435 106 protected:
duke@435 107 int _size;
duke@435 108
duke@435 109 public:
duke@435 110 CompressedWriteStream(int initial_size);
duke@435 111 CompressedWriteStream(u_char* buffer, int initial_size, int position = 0)
duke@435 112 : CompressedStream(buffer, position) { _size = initial_size; }
duke@435 113
duke@435 114 void write_bool(jboolean value) { write(value); }
duke@435 115 void write_byte(jbyte value) { write(value); }
duke@435 116 void write_char(jchar value) { write_int(value); }
duke@435 117 void write_short(jshort value) { write_signed_int(value); }
duke@435 118 void write_int(jint value) { if ((juint)value < L && !full())
duke@435 119 store((u_char)value);
duke@435 120 else write_int_mb(value); }
duke@435 121 void write_signed_int(jint value); // write_int(encode_sign(value))
duke@435 122 void write_float(jfloat value); // write_int(reverse_int(jint_cast(v)))
duke@435 123 void write_double(jdouble value); // write_int(reverse_int(<low,high>))
duke@435 124 void write_long(jlong value); // write_signed_int(<low,high>)
duke@435 125 };
stefank@2314 126
stefank@2314 127 #endif // SHARE_VM_CODE_COMPRESSEDSTREAM_HPP

mercurial