src/hotspot/share/code/compressedStream.cpp
author coleenp
Wed, 13 Nov 2019 08:23:23 -0500
changeset 59056 15936b142f86
parent 54042 6dd6f988b4e4
permissions -rw-r--r--
8233913: Remove implicit conversion from Method* to methodHandle Summary: Fix call sites to use existing THREAD local or pass down THREAD local for shallower callsites. Make linkResolver methods return Method* for caller to handleize if needed. Reviewed-by: iklam, thartmann, hseigel
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46600
diff changeset
     2
 * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#include "code/compressedStream.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "utilities/ostream.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
// 32-bit self-inverse encoding of float bits
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
// converts trailing zeroes (common in floats) to leading zeroes
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
inline juint CompressedStream::reverse_int(juint i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
  // Hacker's Delight, Figure 7-1
46630
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46600
diff changeset
    33
  i = (i & 0x55555555) << 1 | ((i >> 1) & 0x55555555);
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46600
diff changeset
    34
  i = (i & 0x33333333) << 2 | ((i >> 2) & 0x33333333);
75aa3e39d02c 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
jwilhelm
parents: 46600
diff changeset
    35
  i = (i & 0x0f0f0f0f) << 4 | ((i >> 4) & 0x0f0f0f0f);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  i = (i << 24) | ((i & 0xff00) << 8) | ((i >> 8) & 0xff00) | (i >> 24);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  return i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
jint CompressedReadStream::read_signed_int() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  return decode_sign(read_int());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
// Compressing floats is simple, because the only common pattern
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
// is trailing zeroes.  (Compare leading sign bits on ints.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
// Since floats are left-justified, as opposed to right-justified
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
// ints, we can bit-reverse them in order to take advantage of int
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
// compression.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
jfloat CompressedReadStream::read_float() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  int rf = read_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  int f  = reverse_int(rf);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  return jfloat_cast(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
jdouble CompressedReadStream::read_double() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  jint rh = read_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  jint rl = read_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  jint h  = reverse_int(rh);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  jint l  = reverse_int(rl);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  return jdouble_cast(jlong_from(h, l));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
jlong CompressedReadStream::read_long() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  jint low  = read_signed_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  jint high = read_signed_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  return jlong_from(high, low);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
CompressedWriteStream::CompressedWriteStream(int initial_size) : CompressedStream(NULL, 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  _buffer   = NEW_RESOURCE_ARRAY(u_char, initial_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  _size     = initial_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  _position = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
void CompressedWriteStream::grow() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  u_char* _new_buffer = NEW_RESOURCE_ARRAY(u_char, _size * 2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  memcpy(_new_buffer, _buffer, _position);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  _buffer = _new_buffer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  _size   = _size * 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
void CompressedWriteStream::write_float(jfloat value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  juint f = jint_cast(value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  juint rf = reverse_int(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  assert(f == reverse_int(rf), "can re-read same bits");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  write_int(rf);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
void CompressedWriteStream::write_double(jdouble value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  juint h  = high(jlong_cast(value));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  juint l  = low( jlong_cast(value));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  juint rh = reverse_int(h);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  juint rl = reverse_int(l);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  assert(h == reverse_int(rh), "can re-read same bits");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  assert(l == reverse_int(rl), "can re-read same bits");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  write_int(rh);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  write_int(rl);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
void CompressedWriteStream::write_long(jlong value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  write_signed_int(low(value));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  write_signed_int(high(value));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
}