annotate src/hotspot/share/code/compressedStream.cpp @ 54531:6dd6f988b4e4

8219860: Cleanup ClassFileParser::parse_linenumber_table Reviewed-by: rehn, lfoltan, hseigel
author redestad
date Fri, 08 Mar 2019 23:02:06 +0100
parents 71c04702a3d5
children
rev   line source
duke@1 1 /*
jwilhelm@46630 2 * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
duke@1 7 * published by the Free Software Foundation.
duke@1 8 *
duke@1 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 13 * accompanied this code).
duke@1 14 *
duke@1 15 * You should have received a copy of the GNU General Public License version
duke@1 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 18 *
trims@5547 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@5547 20 * or visit www.oracle.com if you need additional information or have any
trims@5547 21 * questions.
duke@1 22 *
duke@1 23 */
duke@1 24
stefank@7397 25 #include "precompiled.hpp"
stefank@7397 26 #include "code/compressedStream.hpp"
stefank@7397 27 #include "utilities/ostream.hpp"
duke@1 28
duke@1 29 // 32-bit self-inverse encoding of float bits
duke@1 30 // converts trailing zeroes (common in floats) to leading zeroes
duke@1 31 inline juint CompressedStream::reverse_int(juint i) {
duke@1 32 // Hacker's Delight, Figure 7-1
jwilhelm@46630 33 i = (i & 0x55555555) << 1 | ((i >> 1) & 0x55555555);
jwilhelm@46630 34 i = (i & 0x33333333) << 2 | ((i >> 2) & 0x33333333);
jwilhelm@46630 35 i = (i & 0x0f0f0f0f) << 4 | ((i >> 4) & 0x0f0f0f0f);
duke@1 36 i = (i << 24) | ((i & 0xff00) << 8) | ((i >> 8) & 0xff00) | (i >> 24);
duke@1 37 return i;
duke@1 38 }
duke@1 39
duke@1 40 jint CompressedReadStream::read_signed_int() {
duke@1 41 return decode_sign(read_int());
duke@1 42 }
duke@1 43
duke@1 44 // Compressing floats is simple, because the only common pattern
duke@1 45 // is trailing zeroes. (Compare leading sign bits on ints.)
duke@1 46 // Since floats are left-justified, as opposed to right-justified
duke@1 47 // ints, we can bit-reverse them in order to take advantage of int
duke@1 48 // compression.
duke@1 49
duke@1 50 jfloat CompressedReadStream::read_float() {
duke@1 51 int rf = read_int();
duke@1 52 int f = reverse_int(rf);
duke@1 53 return jfloat_cast(f);
duke@1 54 }
duke@1 55
duke@1 56 jdouble CompressedReadStream::read_double() {
duke@1 57 jint rh = read_int();
duke@1 58 jint rl = read_int();
duke@1 59 jint h = reverse_int(rh);
duke@1 60 jint l = reverse_int(rl);
duke@1 61 return jdouble_cast(jlong_from(h, l));
duke@1 62 }
duke@1 63
duke@1 64 jlong CompressedReadStream::read_long() {
duke@1 65 jint low = read_signed_int();
duke@1 66 jint high = read_signed_int();
duke@1 67 return jlong_from(high, low);
duke@1 68 }
duke@1 69
duke@1 70 CompressedWriteStream::CompressedWriteStream(int initial_size) : CompressedStream(NULL, 0) {
duke@1 71 _buffer = NEW_RESOURCE_ARRAY(u_char, initial_size);
duke@1 72 _size = initial_size;
duke@1 73 _position = 0;
duke@1 74 }
duke@1 75
duke@1 76 void CompressedWriteStream::grow() {
duke@1 77 u_char* _new_buffer = NEW_RESOURCE_ARRAY(u_char, _size * 2);
duke@1 78 memcpy(_new_buffer, _buffer, _position);
duke@1 79 _buffer = _new_buffer;
duke@1 80 _size = _size * 2;
duke@1 81 }
duke@1 82
duke@1 83 void CompressedWriteStream::write_float(jfloat value) {
duke@1 84 juint f = jint_cast(value);
duke@1 85 juint rf = reverse_int(f);
duke@1 86 assert(f == reverse_int(rf), "can re-read same bits");
duke@1 87 write_int(rf);
duke@1 88 }
duke@1 89
duke@1 90 void CompressedWriteStream::write_double(jdouble value) {
duke@1 91 juint h = high(jlong_cast(value));
duke@1 92 juint l = low( jlong_cast(value));
duke@1 93 juint rh = reverse_int(h);
duke@1 94 juint rl = reverse_int(l);
duke@1 95 assert(h == reverse_int(rh), "can re-read same bits");
duke@1 96 assert(l == reverse_int(rl), "can re-read same bits");
duke@1 97 write_int(rh);
duke@1 98 write_int(rl);
duke@1 99 }
duke@1 100
duke@1 101 void CompressedWriteStream::write_long(jlong value) {
duke@1 102 write_signed_int(low(value));
duke@1 103 write_signed_int(high(value));
duke@1 104 }