annotate agent/src/share/classes/sun/jvm/hotspot/code/CompressedReadStream.java @ 17524:89152779163c

Merge with jdk8-b132
author Gilles Duboscq <duboscq@ssw.jku.at>
date Wed, 15 Oct 2014 11:59:32 +0200
parents c18cbe5936b8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
2 * Copyright (c) 2000, 2005, 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
a61af66fc99e Initial load
duke
parents:
diff changeset
25 package sun.jvm.hotspot.code;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import sun.jvm.hotspot.debugger.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28
a61af66fc99e Initial load
duke
parents:
diff changeset
29 public class CompressedReadStream extends CompressedStream {
a61af66fc99e Initial load
duke
parents:
diff changeset
30 /** Equivalent to CompressedReadStream(buffer, 0) */
a61af66fc99e Initial load
duke
parents:
diff changeset
31 public CompressedReadStream(Address buffer) {
a61af66fc99e Initial load
duke
parents:
diff changeset
32 this(buffer, 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
33 }
a61af66fc99e Initial load
duke
parents:
diff changeset
34
a61af66fc99e Initial load
duke
parents:
diff changeset
35 public CompressedReadStream(Address buffer, int position) {
a61af66fc99e Initial load
duke
parents:
diff changeset
36 super(buffer, position);
a61af66fc99e Initial load
duke
parents:
diff changeset
37 }
a61af66fc99e Initial load
duke
parents:
diff changeset
38
a61af66fc99e Initial load
duke
parents:
diff changeset
39 public boolean readBoolean() {
a61af66fc99e Initial load
duke
parents:
diff changeset
40 return (read() != 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
41 }
a61af66fc99e Initial load
duke
parents:
diff changeset
42
a61af66fc99e Initial load
duke
parents:
diff changeset
43 public byte readByte() {
a61af66fc99e Initial load
duke
parents:
diff changeset
44 return (byte) read();
a61af66fc99e Initial load
duke
parents:
diff changeset
45 }
a61af66fc99e Initial load
duke
parents:
diff changeset
46
a61af66fc99e Initial load
duke
parents:
diff changeset
47 public char readChar() {
a61af66fc99e Initial load
duke
parents:
diff changeset
48 return (char) readInt();
a61af66fc99e Initial load
duke
parents:
diff changeset
49 }
a61af66fc99e Initial load
duke
parents:
diff changeset
50
a61af66fc99e Initial load
duke
parents:
diff changeset
51 public short readShort() {
a61af66fc99e Initial load
duke
parents:
diff changeset
52 return (short) readSignedInt();
a61af66fc99e Initial load
duke
parents:
diff changeset
53 }
a61af66fc99e Initial load
duke
parents:
diff changeset
54
a61af66fc99e Initial load
duke
parents:
diff changeset
55 public int readSignedInt() {
a61af66fc99e Initial load
duke
parents:
diff changeset
56 return decodeSign(readInt());
a61af66fc99e Initial load
duke
parents:
diff changeset
57 }
a61af66fc99e Initial load
duke
parents:
diff changeset
58
a61af66fc99e Initial load
duke
parents:
diff changeset
59 public int readInt() {
a61af66fc99e Initial load
duke
parents:
diff changeset
60 int b0 = read();
a61af66fc99e Initial load
duke
parents:
diff changeset
61 if (b0 < L) {
a61af66fc99e Initial load
duke
parents:
diff changeset
62 return b0;
a61af66fc99e Initial load
duke
parents:
diff changeset
63 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
64 return readIntMb(b0);
a61af66fc99e Initial load
duke
parents:
diff changeset
65 }
a61af66fc99e Initial load
duke
parents:
diff changeset
66 }
a61af66fc99e Initial load
duke
parents:
diff changeset
67
a61af66fc99e Initial load
duke
parents:
diff changeset
68
a61af66fc99e Initial load
duke
parents:
diff changeset
69 public float readFloat() {
a61af66fc99e Initial load
duke
parents:
diff changeset
70 return Float.intBitsToFloat(reverseInt(readInt()));
a61af66fc99e Initial load
duke
parents:
diff changeset
71 }
a61af66fc99e Initial load
duke
parents:
diff changeset
72
a61af66fc99e Initial load
duke
parents:
diff changeset
73 public double readDouble() {
a61af66fc99e Initial load
duke
parents:
diff changeset
74 int rh = readInt();
a61af66fc99e Initial load
duke
parents:
diff changeset
75 int rl = readInt();
a61af66fc99e Initial load
duke
parents:
diff changeset
76 int h = reverseInt(rh);
a61af66fc99e Initial load
duke
parents:
diff changeset
77 int l = reverseInt(rl);
a61af66fc99e Initial load
duke
parents:
diff changeset
78 return Double.longBitsToDouble((h << 32) | ((long)l & 0x00000000FFFFFFFFL));
a61af66fc99e Initial load
duke
parents:
diff changeset
79 }
a61af66fc99e Initial load
duke
parents:
diff changeset
80
a61af66fc99e Initial load
duke
parents:
diff changeset
81 public long readLong() {
a61af66fc99e Initial load
duke
parents:
diff changeset
82 long low = readSignedInt() & 0x00000000FFFFFFFFL;
a61af66fc99e Initial load
duke
parents:
diff changeset
83 long high = readSignedInt();
a61af66fc99e Initial load
duke
parents:
diff changeset
84 return (high << 32) | low;
a61af66fc99e Initial load
duke
parents:
diff changeset
85 }
a61af66fc99e Initial load
duke
parents:
diff changeset
86
a61af66fc99e Initial load
duke
parents:
diff changeset
87 //--------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
88 // Internals only below this point
a61af66fc99e Initial load
duke
parents:
diff changeset
89 //
a61af66fc99e Initial load
duke
parents:
diff changeset
90
a61af66fc99e Initial load
duke
parents:
diff changeset
91
a61af66fc99e Initial load
duke
parents:
diff changeset
92 // This encoding, called UNSIGNED5, is taken from J2SE Pack200.
a61af66fc99e Initial load
duke
parents:
diff changeset
93 // It assumes that most values have lots of leading zeroes.
a61af66fc99e Initial load
duke
parents:
diff changeset
94 // Very small values, in the range [0..191], code in one byte.
a61af66fc99e Initial load
duke
parents:
diff changeset
95 // Any 32-bit value (including negatives) can be coded, in
a61af66fc99e Initial load
duke
parents:
diff changeset
96 // up to five bytes. The grammar is:
a61af66fc99e Initial load
duke
parents:
diff changeset
97 // low_byte = [0..191]
a61af66fc99e Initial load
duke
parents:
diff changeset
98 // high_byte = [192..255]
a61af66fc99e Initial load
duke
parents:
diff changeset
99 // any_byte = low_byte | high_byte
a61af66fc99e Initial load
duke
parents:
diff changeset
100 // coding = low_byte
a61af66fc99e Initial load
duke
parents:
diff changeset
101 // | high_byte low_byte
a61af66fc99e Initial load
duke
parents:
diff changeset
102 // | high_byte high_byte low_byte
a61af66fc99e Initial load
duke
parents:
diff changeset
103 // | high_byte high_byte high_byte low_byte
a61af66fc99e Initial load
duke
parents:
diff changeset
104 // | high_byte high_byte high_byte high_byte any_byte
a61af66fc99e Initial load
duke
parents:
diff changeset
105 // Each high_byte contributes six bits of payload.
a61af66fc99e Initial load
duke
parents:
diff changeset
106 // The encoding is one-to-one (except for integer overflow)
a61af66fc99e Initial load
duke
parents:
diff changeset
107 // and easy to parse and unparse.
a61af66fc99e Initial load
duke
parents:
diff changeset
108
a61af66fc99e Initial load
duke
parents:
diff changeset
109 private int readIntMb(int b0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
110 int pos = position - 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
111 int sum = b0;
a61af66fc99e Initial load
duke
parents:
diff changeset
112 // must collect more bytes: b[1]...b[4]
a61af66fc99e Initial load
duke
parents:
diff changeset
113 int lg_H_i = lg_H;
a61af66fc99e Initial load
duke
parents:
diff changeset
114 for (int i = 0; ;) {
a61af66fc99e Initial load
duke
parents:
diff changeset
115 int b_i = read(pos + (++i));
a61af66fc99e Initial load
duke
parents:
diff changeset
116 sum += b_i << lg_H_i; // sum += b[i]*(64**i)
a61af66fc99e Initial load
duke
parents:
diff changeset
117 if (b_i < L || i == MAX_i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
118 setPosition(pos+i+1);
a61af66fc99e Initial load
duke
parents:
diff changeset
119 return sum;
a61af66fc99e Initial load
duke
parents:
diff changeset
120 }
a61af66fc99e Initial load
duke
parents:
diff changeset
121 lg_H_i += lg_H;
a61af66fc99e Initial load
duke
parents:
diff changeset
122 }
a61af66fc99e Initial load
duke
parents:
diff changeset
123 }
a61af66fc99e Initial load
duke
parents:
diff changeset
124
a61af66fc99e Initial load
duke
parents:
diff changeset
125 private short read(int index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
126 return (short) buffer.getCIntegerAt(index, 1, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
127 }
a61af66fc99e Initial load
duke
parents:
diff changeset
128
a61af66fc99e Initial load
duke
parents:
diff changeset
129 /** Reads an unsigned byte, but returns it as a short */
a61af66fc99e Initial load
duke
parents:
diff changeset
130 private short read() {
a61af66fc99e Initial load
duke
parents:
diff changeset
131 short retval = (short) buffer.getCIntegerAt(position, 1, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
132 ++position;
a61af66fc99e Initial load
duke
parents:
diff changeset
133 return retval;
a61af66fc99e Initial load
duke
parents:
diff changeset
134 }
a61af66fc99e Initial load
duke
parents:
diff changeset
135 }