Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/code/compressedStream.hpp
32285 views
/*1* Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_VM_CODE_COMPRESSEDSTREAM_HPP25#define SHARE_VM_CODE_COMPRESSEDSTREAM_HPP2627#include "memory/allocation.hpp"2829// Simple interface for filing out and filing in basic types30// Used for writing out and reading in debugging information.3132class CompressedStream : public ResourceObj {33friend class VMStructs;34protected:35u_char* _buffer;36int _position;3738enum {39// Constants for UNSIGNED5 coding of Pack20040lg_H = 6, H = 1<<lg_H, // number of high codes (64)41L = (1<<BitsPerByte)-H, // number of low codes (192)42MAX_i = 4 // bytes are numbered in (0..4), max 5 bytes43};4445// these inlines are defined only in compressedStream.cpp46static inline juint encode_sign(jint value); // for Pack200 SIGNED547static inline jint decode_sign(juint value); // for Pack200 SIGNED548static inline juint reverse_int(juint bits); // to trim trailing float 0's4950public:51CompressedStream(u_char* buffer, int position = 0) {52_buffer = buffer;53_position = position;54}5556u_char* buffer() const { return _buffer; }5758// Positioning59int position() const { return _position; }60void set_position(int position) { _position = position; }61};626364class CompressedReadStream : public CompressedStream {65private:66inline u_char read() { return _buffer[_position++]; }6768jint read_int_mb(jint b0); // UNSIGNED5 coding, 2-5 byte cases6970public:71CompressedReadStream(u_char* buffer, int position = 0)72: CompressedStream(buffer, position) {}7374jboolean read_bool() { return (jboolean) read(); }75jbyte read_byte() { return (jbyte ) read(); }76jchar read_char() { return (jchar ) read_int(); }77jshort read_short() { return (jshort ) read_signed_int(); }78jint read_int() { jint b0 = read();79if (b0 < L) return b0;80else return read_int_mb(b0);81}82jint read_signed_int();83jfloat read_float(); // jfloat_cast(reverse_int(read_int()))84jdouble read_double(); // jdouble_cast(2*reverse_int(read_int))85jlong read_long(); // jlong_from(2*read_signed_int())86};878889class CompressedWriteStream : public CompressedStream {90private:91bool full() {92return _position >= _size;93}94void store(u_char b) {95_buffer[_position++] = b;96}97void write(u_char b) {98if (full()) grow();99store(b);100}101void grow();102103void write_int_mb(jint value); // UNSIGNED5 coding, 1-5 byte cases104105protected:106int _size;107108public:109CompressedWriteStream(int initial_size);110CompressedWriteStream(u_char* buffer, int initial_size, int position = 0)111: CompressedStream(buffer, position) { _size = initial_size; }112113void write_bool(jboolean value) { write(value); }114void write_byte(jbyte value) { write(value); }115void write_char(jchar value) { write_int(value); }116void write_short(jshort value) { write_signed_int(value); }117void write_int(jint value) { if ((juint)value < L && !full())118store((u_char)value);119else write_int_mb(value); }120void write_signed_int(jint value); // write_int(encode_sign(value))121void write_float(jfloat value); // write_int(reverse_int(jint_cast(v)))122void write_double(jdouble value); // write_int(reverse_int(<low,high>))123void write_long(jlong value); // write_signed_int(<low,high>)124};125126#endif // SHARE_VM_CODE_COMPRESSEDSTREAM_HPP127128129