1 /*
2 * Copyright (c) 1997, 2005, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 // Simple interface for filing out and filing in basic types
26 // Used for writing out and reading in debugging information.
27
28 class CompressedStream : public ResourceObj {
29 friend class VMStructs;
30 protected:
31 u_char* _buffer;
32 int _position;
33
34 enum {
35 // Constants for UNSIGNED5 coding of Pack200
36 lg_H = 6, H = 1<<lg_H, // number of high codes (64)
37 L = (1<<BitsPerByte)-H, // number of low codes (192)
38 MAX_i = 4 // bytes are numbered in (0..4), max 5 bytes
39 };
40
41 // these inlines are defined only in compressedStream.cpp
42 static inline juint encode_sign(jint value); // for Pack200 SIGNED5
43 static inline jint decode_sign(juint value); // for Pack200 SIGNED5
44 static inline juint reverse_int(juint bits); // to trim trailing float 0's
101 protected:
102 int _size;
103
104 public:
105 CompressedWriteStream(int initial_size);
106 CompressedWriteStream(u_char* buffer, int initial_size, int position = 0)
107 : CompressedStream(buffer, position) { _size = initial_size; }
108
109 void write_bool(jboolean value) { write(value); }
110 void write_byte(jbyte value) { write(value); }
111 void write_char(jchar value) { write_int(value); }
112 void write_short(jshort value) { write_signed_int(value); }
113 void write_int(jint value) { if ((juint)value < L && !full())
114 store((u_char)value);
115 else write_int_mb(value); }
116 void write_signed_int(jint value); // write_int(encode_sign(value))
117 void write_float(jfloat value); // write_int(reverse_int(jint_cast(v)))
118 void write_double(jdouble value); // write_int(reverse_int(<low,high>))
119 void write_long(jlong value); // write_signed_int(<low,high>)
120 };
|
1 /*
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_VM_CODE_COMPRESSEDSTREAM_HPP
26 #define SHARE_VM_CODE_COMPRESSEDSTREAM_HPP
27
28 #include "memory/allocation.hpp"
29
30 // Simple interface for filing out and filing in basic types
31 // Used for writing out and reading in debugging information.
32
33 class CompressedStream : public ResourceObj {
34 friend class VMStructs;
35 protected:
36 u_char* _buffer;
37 int _position;
38
39 enum {
40 // Constants for UNSIGNED5 coding of Pack200
41 lg_H = 6, H = 1<<lg_H, // number of high codes (64)
42 L = (1<<BitsPerByte)-H, // number of low codes (192)
43 MAX_i = 4 // bytes are numbered in (0..4), max 5 bytes
44 };
45
46 // these inlines are defined only in compressedStream.cpp
47 static inline juint encode_sign(jint value); // for Pack200 SIGNED5
48 static inline jint decode_sign(juint value); // for Pack200 SIGNED5
49 static inline juint reverse_int(juint bits); // to trim trailing float 0's
106 protected:
107 int _size;
108
109 public:
110 CompressedWriteStream(int initial_size);
111 CompressedWriteStream(u_char* buffer, int initial_size, int position = 0)
112 : CompressedStream(buffer, position) { _size = initial_size; }
113
114 void write_bool(jboolean value) { write(value); }
115 void write_byte(jbyte value) { write(value); }
116 void write_char(jchar value) { write_int(value); }
117 void write_short(jshort value) { write_signed_int(value); }
118 void write_int(jint value) { if ((juint)value < L && !full())
119 store((u_char)value);
120 else write_int_mb(value); }
121 void write_signed_int(jint value); // write_int(encode_sign(value))
122 void write_float(jfloat value); // write_int(reverse_int(jint_cast(v)))
123 void write_double(jdouble value); // write_int(reverse_int(<low,high>))
124 void write_long(jlong value); // write_signed_int(<low,high>)
125 };
126
127 #endif // SHARE_VM_CODE_COMPRESSEDSTREAM_HPP
|