annotate src/share/vm/code/compressedStream.hpp @ 17716:cdb71841f4bc

6498581: ThreadInterruptTest3 produces wrong output on Windows Summary: There is race condition between os::interrupt and os::is_interrupted on Windows. In JVM_Sleep(Thread.sleep), check if thread gets interrupted, it may see interrupted but not really interrupted so cause spurious waking up (early return from sleep). Fix by checking if interrupt event really gets set thus prevent false return. For intrinsic of _isInterrupted, on Windows, go fastpath only on bit not set. Reviewed-by: acorn, kvn Contributed-by: david.holmes@oracle.com, yumin.qi@oracle.com
author minqi
date Wed, 26 Feb 2014 15:20:41 -0800
parents f95d63e2154a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
25 #ifndef SHARE_VM_CODE_COMPRESSEDSTREAM_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #define SHARE_VM_CODE_COMPRESSEDSTREAM_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
27
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
28 #include "memory/allocation.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
29
0
a61af66fc99e Initial load
duke
parents:
diff changeset
30 // Simple interface for filing out and filing in basic types
a61af66fc99e Initial load
duke
parents:
diff changeset
31 // Used for writing out and reading in debugging information.
a61af66fc99e Initial load
duke
parents:
diff changeset
32
a61af66fc99e Initial load
duke
parents:
diff changeset
33 class CompressedStream : public ResourceObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
34 friend class VMStructs;
a61af66fc99e Initial load
duke
parents:
diff changeset
35 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
36 u_char* _buffer;
a61af66fc99e Initial load
duke
parents:
diff changeset
37 int _position;
a61af66fc99e Initial load
duke
parents:
diff changeset
38
a61af66fc99e Initial load
duke
parents:
diff changeset
39 enum {
a61af66fc99e Initial load
duke
parents:
diff changeset
40 // Constants for UNSIGNED5 coding of Pack200
a61af66fc99e Initial load
duke
parents:
diff changeset
41 lg_H = 6, H = 1<<lg_H, // number of high codes (64)
a61af66fc99e Initial load
duke
parents:
diff changeset
42 L = (1<<BitsPerByte)-H, // number of low codes (192)
a61af66fc99e Initial load
duke
parents:
diff changeset
43 MAX_i = 4 // bytes are numbered in (0..4), max 5 bytes
a61af66fc99e Initial load
duke
parents:
diff changeset
44 };
a61af66fc99e Initial load
duke
parents:
diff changeset
45
a61af66fc99e Initial load
duke
parents:
diff changeset
46 // these inlines are defined only in compressedStream.cpp
a61af66fc99e Initial load
duke
parents:
diff changeset
47 static inline juint encode_sign(jint value); // for Pack200 SIGNED5
a61af66fc99e Initial load
duke
parents:
diff changeset
48 static inline jint decode_sign(juint value); // for Pack200 SIGNED5
a61af66fc99e Initial load
duke
parents:
diff changeset
49 static inline juint reverse_int(juint bits); // to trim trailing float 0's
a61af66fc99e Initial load
duke
parents:
diff changeset
50
a61af66fc99e Initial load
duke
parents:
diff changeset
51 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
52 CompressedStream(u_char* buffer, int position = 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
53 _buffer = buffer;
a61af66fc99e Initial load
duke
parents:
diff changeset
54 _position = position;
a61af66fc99e Initial load
duke
parents:
diff changeset
55 }
a61af66fc99e Initial load
duke
parents:
diff changeset
56
a61af66fc99e Initial load
duke
parents:
diff changeset
57 u_char* buffer() const { return _buffer; }
a61af66fc99e Initial load
duke
parents:
diff changeset
58
a61af66fc99e Initial load
duke
parents:
diff changeset
59 // Positioning
a61af66fc99e Initial load
duke
parents:
diff changeset
60 int position() const { return _position; }
a61af66fc99e Initial load
duke
parents:
diff changeset
61 void set_position(int position) { _position = position; }
a61af66fc99e Initial load
duke
parents:
diff changeset
62 };
a61af66fc99e Initial load
duke
parents:
diff changeset
63
a61af66fc99e Initial load
duke
parents:
diff changeset
64
a61af66fc99e Initial load
duke
parents:
diff changeset
65 class CompressedReadStream : public CompressedStream {
a61af66fc99e Initial load
duke
parents:
diff changeset
66 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
67 inline u_char read() { return _buffer[_position++]; }
a61af66fc99e Initial load
duke
parents:
diff changeset
68
a61af66fc99e Initial load
duke
parents:
diff changeset
69 jint read_int_mb(jint b0); // UNSIGNED5 coding, 2-5 byte cases
a61af66fc99e Initial load
duke
parents:
diff changeset
70
a61af66fc99e Initial load
duke
parents:
diff changeset
71 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
72 CompressedReadStream(u_char* buffer, int position = 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
73 : CompressedStream(buffer, position) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
74
a61af66fc99e Initial load
duke
parents:
diff changeset
75 jboolean read_bool() { return (jboolean) read(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
76 jbyte read_byte() { return (jbyte ) read(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
77 jchar read_char() { return (jchar ) read_int(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
78 jshort read_short() { return (jshort ) read_signed_int(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
79 jint read_int() { jint b0 = read();
a61af66fc99e Initial load
duke
parents:
diff changeset
80 if (b0 < L) return b0;
a61af66fc99e Initial load
duke
parents:
diff changeset
81 else return read_int_mb(b0);
a61af66fc99e Initial load
duke
parents:
diff changeset
82 }
a61af66fc99e Initial load
duke
parents:
diff changeset
83 jint read_signed_int();
a61af66fc99e Initial load
duke
parents:
diff changeset
84 jfloat read_float(); // jfloat_cast(reverse_int(read_int()))
a61af66fc99e Initial load
duke
parents:
diff changeset
85 jdouble read_double(); // jdouble_cast(2*reverse_int(read_int))
a61af66fc99e Initial load
duke
parents:
diff changeset
86 jlong read_long(); // jlong_from(2*read_signed_int())
a61af66fc99e Initial load
duke
parents:
diff changeset
87 };
a61af66fc99e Initial load
duke
parents:
diff changeset
88
a61af66fc99e Initial load
duke
parents:
diff changeset
89
a61af66fc99e Initial load
duke
parents:
diff changeset
90 class CompressedWriteStream : public CompressedStream {
a61af66fc99e Initial load
duke
parents:
diff changeset
91 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
92 bool full() {
a61af66fc99e Initial load
duke
parents:
diff changeset
93 return _position >= _size;
a61af66fc99e Initial load
duke
parents:
diff changeset
94 }
a61af66fc99e Initial load
duke
parents:
diff changeset
95 void store(u_char b) {
a61af66fc99e Initial load
duke
parents:
diff changeset
96 _buffer[_position++] = b;
a61af66fc99e Initial load
duke
parents:
diff changeset
97 }
a61af66fc99e Initial load
duke
parents:
diff changeset
98 void write(u_char b) {
a61af66fc99e Initial load
duke
parents:
diff changeset
99 if (full()) grow();
a61af66fc99e Initial load
duke
parents:
diff changeset
100 store(b);
a61af66fc99e Initial load
duke
parents:
diff changeset
101 }
a61af66fc99e Initial load
duke
parents:
diff changeset
102 void grow();
a61af66fc99e Initial load
duke
parents:
diff changeset
103
a61af66fc99e Initial load
duke
parents:
diff changeset
104 void write_int_mb(jint value); // UNSIGNED5 coding, 1-5 byte cases
a61af66fc99e Initial load
duke
parents:
diff changeset
105
a61af66fc99e Initial load
duke
parents:
diff changeset
106 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
107 int _size;
a61af66fc99e Initial load
duke
parents:
diff changeset
108
a61af66fc99e Initial load
duke
parents:
diff changeset
109 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
110 CompressedWriteStream(int initial_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
111 CompressedWriteStream(u_char* buffer, int initial_size, int position = 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
112 : CompressedStream(buffer, position) { _size = initial_size; }
a61af66fc99e Initial load
duke
parents:
diff changeset
113
a61af66fc99e Initial load
duke
parents:
diff changeset
114 void write_bool(jboolean value) { write(value); }
a61af66fc99e Initial load
duke
parents:
diff changeset
115 void write_byte(jbyte value) { write(value); }
a61af66fc99e Initial load
duke
parents:
diff changeset
116 void write_char(jchar value) { write_int(value); }
a61af66fc99e Initial load
duke
parents:
diff changeset
117 void write_short(jshort value) { write_signed_int(value); }
a61af66fc99e Initial load
duke
parents:
diff changeset
118 void write_int(jint value) { if ((juint)value < L && !full())
a61af66fc99e Initial load
duke
parents:
diff changeset
119 store((u_char)value);
a61af66fc99e Initial load
duke
parents:
diff changeset
120 else write_int_mb(value); }
a61af66fc99e Initial load
duke
parents:
diff changeset
121 void write_signed_int(jint value); // write_int(encode_sign(value))
a61af66fc99e Initial load
duke
parents:
diff changeset
122 void write_float(jfloat value); // write_int(reverse_int(jint_cast(v)))
a61af66fc99e Initial load
duke
parents:
diff changeset
123 void write_double(jdouble value); // write_int(reverse_int(<low,high>))
a61af66fc99e Initial load
duke
parents:
diff changeset
124 void write_long(jlong value); // write_signed_int(<low,high>)
a61af66fc99e Initial load
duke
parents:
diff changeset
125 };
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
126
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
127 #endif // SHARE_VM_CODE_COMPRESSEDSTREAM_HPP