Path: blob/master/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/code/CompressedReadStream.java
41171 views
/*1* Copyright (c) 2000, 2020, 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*/2324package sun.jvm.hotspot.code;2526import sun.jvm.hotspot.debugger.*;2728public class CompressedReadStream extends CompressedStream {29/** Equivalent to CompressedReadStream(buffer, 0) */30public CompressedReadStream(Address buffer) {31this(buffer, 0);32}3334public CompressedReadStream(Address buffer, int position) {35super(buffer, position);36}3738public boolean readBoolean() {39return (read() != 0);40}4142public byte readByte() {43return (byte) read();44}4546public char readChar() {47return (char) readInt();48}4950public short readShort() {51return (short) readSignedInt();52}5354public int readSignedInt() {55return decodeSign(readInt());56}5758public int readInt() {59int b0 = read();60if (b0 < L) {61return b0;62} else {63return readIntMb(b0);64}65}666768public float readFloat() {69return Float.intBitsToFloat(reverseInt(readInt()));70}7172public double readDouble() {73int rh = readInt();74int rl = readInt();75int h = reverseInt(rh);76int l = reverseInt(rl);77return Double.longBitsToDouble(((long)h << 32) | ((long)l & 0x00000000FFFFFFFFL));78}7980public long readLong() {81long low = readSignedInt() & 0x00000000FFFFFFFFL;82long high = readSignedInt();83return (high << 32) | low;84}8586//--------------------------------------------------------------------------------87// Internals only below this point88//899091// This encoding, called UNSIGNED5, is taken from J2SE Pack200.92// It assumes that most values have lots of leading zeroes.93// Very small values, in the range [0..191], code in one byte.94// Any 32-bit value (including negatives) can be coded, in95// up to five bytes. The grammar is:96// low_byte = [0..191]97// high_byte = [192..255]98// any_byte = low_byte | high_byte99// coding = low_byte100// | high_byte low_byte101// | high_byte high_byte low_byte102// | high_byte high_byte high_byte low_byte103// | high_byte high_byte high_byte high_byte any_byte104// Each high_byte contributes six bits of payload.105// The encoding is one-to-one (except for integer overflow)106// and easy to parse and unparse.107108private int readIntMb(int b0) {109int pos = position - 1;110int sum = b0;111// must collect more bytes: b[1]...b[4]112int lg_H_i = lg_H;113for (int i = 0; ;) {114int b_i = read(pos + (++i));115sum += b_i << lg_H_i; // sum += b[i]*(64**i)116if (b_i < L || i == MAX_i) {117setPosition(pos+i+1);118return sum;119}120lg_H_i += lg_H;121}122}123124private short read(int index) {125return (short) buffer.getCIntegerAt(index, 1, true);126}127128/** Reads an unsigned byte, but returns it as a short */129private short read() {130short retval = (short) buffer.getCIntegerAt(position, 1, true);131++position;132return retval;133}134}135136137