duke@435: /* stefank@2314: * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #ifndef SHARE_VM_CODE_COMPRESSEDSTREAM_HPP stefank@2314: #define SHARE_VM_CODE_COMPRESSEDSTREAM_HPP stefank@2314: stefank@2314: #include "memory/allocation.hpp" stefank@2314: duke@435: // Simple interface for filing out and filing in basic types duke@435: // Used for writing out and reading in debugging information. duke@435: duke@435: class CompressedStream : public ResourceObj { duke@435: friend class VMStructs; duke@435: protected: duke@435: u_char* _buffer; duke@435: int _position; duke@435: duke@435: enum { duke@435: // Constants for UNSIGNED5 coding of Pack200 duke@435: lg_H = 6, H = 1<= _size; duke@435: } duke@435: void store(u_char b) { duke@435: _buffer[_position++] = b; duke@435: } duke@435: void write(u_char b) { duke@435: if (full()) grow(); duke@435: store(b); duke@435: } duke@435: void grow(); duke@435: duke@435: void write_int_mb(jint value); // UNSIGNED5 coding, 1-5 byte cases duke@435: duke@435: protected: duke@435: int _size; duke@435: duke@435: public: duke@435: CompressedWriteStream(int initial_size); duke@435: CompressedWriteStream(u_char* buffer, int initial_size, int position = 0) duke@435: : CompressedStream(buffer, position) { _size = initial_size; } duke@435: duke@435: void write_bool(jboolean value) { write(value); } duke@435: void write_byte(jbyte value) { write(value); } duke@435: void write_char(jchar value) { write_int(value); } duke@435: void write_short(jshort value) { write_signed_int(value); } duke@435: void write_int(jint value) { if ((juint)value < L && !full()) duke@435: store((u_char)value); duke@435: else write_int_mb(value); } duke@435: void write_signed_int(jint value); // write_int(encode_sign(value)) duke@435: void write_float(jfloat value); // write_int(reverse_int(jint_cast(v))) duke@435: void write_double(jdouble value); // write_int(reverse_int()) duke@435: void write_long(jlong value); // write_signed_int() duke@435: }; stefank@2314: stefank@2314: #endif // SHARE_VM_CODE_COMPRESSEDSTREAM_HPP