Path: blob/master/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/code/CompressedStream.java
41171 views
/*1* Copyright (c) 2000, 2005, 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.*;2728/** NOTE that this class takes the address of a buffer. This means29that it can read previously-generated debug information directly30from the target VM. However, it also means that you can't create a31"wrapper" object for a CompressedStream down in the VM. It looks32like these are only kept persistently in OopMaps, and the code has33been special-cased in OopMap.java to handle this. */3435public class CompressedStream {36protected Address buffer;37protected int position;3839/** Equivalent to CompressedStream(buffer, 0) */40public CompressedStream(Address buffer) {41this(buffer, 0);42}4344public CompressedStream(Address buffer, int position) {45this.buffer = buffer;46this.position = position;47}4849public Address getBuffer() {50return buffer;51}5253public static final int LogBitsPerByte = 3;54public static final int BitsPerByte = 1 << 3;5556// Constants for UNSIGNED5 coding of Pack20057public static final int lg_H = 6;58public static final int H = 1<<lg_H; // number of high codes (64)59public static final int L = (1<<BitsPerByte) - H; // number of low codes (192)60public static final int MAX_i = 4; // bytes are numbered in (0..4)6162// Positioning63public int getPosition() {64return position;65}66public void setPosition(int position) {67this.position = position;68}6970// 32-bit one-to-one sign encoding taken from Pack20071// converts leading sign bits into leading zeros with trailing sign bit72public int encodeSign(int value) {73return (value << 1) ^ (value >> 31);74}7576public int decodeSign(int value) {77return (value >>> 1) ^ -(value & 1);78}7980// 32-bit self-inverse encoding of float bits81// converts trailing zeros (common in floats) to leading zeros82public int reverseInt(int i) {83// Hacker's Delight, Figure 7-184i = (i & 0x55555555) << 1 | (i >>> 1) & 0x55555555;85i = (i & 0x33333333) << 3 | (i >>> 2) & 0x33333333;86i = (i & 0x0f0f0f0f) << 4 | (i >>> 4) & 0x0f0f0f0f;87i = (i << 24) | ((i & 0xff00) << 8) | ((i >>> 8) & 0xff00) | (i >>> 24);88return i;89}90}919293