hotspot/src/share/vm/code/compressedStream.cpp
author ant
Fri, 04 Dec 2009 15:07:15 +0300
changeset 4369 18b883ed2b58
parent 1 489c9b5090e2
child 5547 f4b087cbb361
permissions -rw-r--r--
6903354: deadlock involving Component.show & SunToolkit.getImageFromHash Reviewed-by: art, bae
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1997-2006 Sun Microsystems, Inc.  All Rights Reserved.
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
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
#include "incls/_precompiled.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
#include "incls/_compressedStream.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
// 32-bit one-to-one sign encoding taken from Pack200
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
// converts leading sign bits into leading zeroes with trailing sign bit
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
inline juint CompressedStream::encode_sign(jint  value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
  return (value << 1) ^ (value >> 31);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
inline jint  CompressedStream::decode_sign(juint value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  return (value >> 1) ^ -(jint)(value & 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// 32-bit self-inverse encoding of float bits
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
// converts trailing zeroes (common in floats) to leading zeroes
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
inline juint CompressedStream::reverse_int(juint i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  // Hacker's Delight, Figure 7-1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  i = (i & 0x55555555) << 1 | (i >> 1) & 0x55555555;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  i = (i & 0x33333333) << 2 | (i >> 2) & 0x33333333;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  i = (i & 0x0f0f0f0f) << 4 | (i >> 4) & 0x0f0f0f0f;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  i = (i << 24) | ((i & 0xff00) << 8) | ((i >> 8) & 0xff00) | (i >> 24);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  return i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
jint CompressedReadStream::read_signed_int() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  return decode_sign(read_int());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
// Compressing floats is simple, because the only common pattern
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
// is trailing zeroes.  (Compare leading sign bits on ints.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
// Since floats are left-justified, as opposed to right-justified
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
// ints, we can bit-reverse them in order to take advantage of int
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
// compression.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
jfloat CompressedReadStream::read_float() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  int rf = read_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  int f  = reverse_int(rf);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  return jfloat_cast(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
jdouble CompressedReadStream::read_double() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  jint rh = read_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  jint rl = read_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  jint h  = reverse_int(rh);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  jint l  = reverse_int(rl);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  return jdouble_cast(jlong_from(h, l));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
jlong CompressedReadStream::read_long() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  jint low  = read_signed_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  jint high = read_signed_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  return jlong_from(high, low);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
CompressedWriteStream::CompressedWriteStream(int initial_size) : CompressedStream(NULL, 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  _buffer   = NEW_RESOURCE_ARRAY(u_char, initial_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  _size     = initial_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  _position = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
void CompressedWriteStream::grow() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  u_char* _new_buffer = NEW_RESOURCE_ARRAY(u_char, _size * 2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  memcpy(_new_buffer, _buffer, _position);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  _buffer = _new_buffer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  _size   = _size * 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
void CompressedWriteStream::write_signed_int(jint value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  // this encoding, called SIGNED5, is taken from Pack200
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  write_int(encode_sign(value));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
void CompressedWriteStream::write_float(jfloat value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  juint f = jint_cast(value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  juint rf = reverse_int(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  assert(f == reverse_int(rf), "can re-read same bits");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  write_int(rf);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
void CompressedWriteStream::write_double(jdouble value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  juint h  = high(jlong_cast(value));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  juint l  = low( jlong_cast(value));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  juint rh = reverse_int(h);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  juint rl = reverse_int(l);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  assert(h == reverse_int(rh), "can re-read same bits");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  assert(l == reverse_int(rl), "can re-read same bits");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  write_int(rh);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  write_int(rl);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
void CompressedWriteStream::write_long(jlong value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  write_signed_int(low(value));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  write_signed_int(high(value));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
/// The remaining details
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
// set this to trigger unit test
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
void test_compressed_stream(int trace);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
bool test_compressed_stream_enabled = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
// This encoding, called UNSIGNED5, is taken from J2SE Pack200.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
// It assumes that most values have lots of leading zeroes.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
// Very small values, in the range [0..191], code in one byte.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
// Any 32-bit value (including negatives) can be coded, in
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
// up to five bytes.  The grammar is:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
//    low_byte  = [0..191]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
//    high_byte = [192..255]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
//    any_byte  = low_byte | high_byte
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
//    coding = low_byte
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
//           | high_byte low_byte
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
//           | high_byte high_byte low_byte
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
//           | high_byte high_byte high_byte low_byte
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
//           | high_byte high_byte high_byte high_byte any_byte
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
// Each high_byte contributes six bits of payload.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
// The encoding is one-to-one (except for integer overflow)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
// and easy to parse and unparse.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
jint CompressedReadStream::read_int_mb(jint b0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  int     pos = position() - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  u_char* buf = buffer() + pos;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  assert(buf[0] == b0 && b0 >= L, "correctly called");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  jint    sum = b0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  // must collect more bytes:  b[1]...b[4]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  int lg_H_i = lg_H;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  for (int i = 0; ; ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
    jint b_i = buf[++i]; // b_i = read(); ++i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
    sum += b_i << lg_H_i;  // sum += b[i]*(64**i)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
    if (b_i < L || i == MAX_i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
      set_position(pos+i+1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
      return sum;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
    lg_H_i += lg_H;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
void CompressedWriteStream::write_int_mb(jint value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  debug_only(int pos1 = position());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  juint sum = value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  for (int i = 0; ; ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
    if (sum < L || i == MAX_i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
      // remainder is either a "low code" or the 5th byte
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
      assert(sum == (u_char)sum, "valid byte");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
      write((u_char)sum);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
    sum -= L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
    int b_i = L + (sum % H);  // this is a "high code"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
    sum >>= lg_H;             // extracted 6 bits
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
    write(b_i); ++i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  if (test_compressed_stream_enabled) {  // hack to enable this stress test
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
    test_compressed_stream_enabled = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
    test_compressed_stream(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
/// a unit test (can be run by hand from a debugger)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
// Avoid a VS2005 compiler stack overflow w/ fastdebug build.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
// The following pragma optimize turns off optimization ONLY
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
// for this block (a matching directive turns it back on later).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
// These directives can be removed once the MS VS.NET 2005
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
// compiler stack overflow is fixed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
#if _MSC_VER >=1400 && !defined(_WIN64)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
#pragma optimize("", off)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
// generator for an "interesting" set of critical values
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
enum { stretch_limit = (1<<16) * (64-16+1) };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
static jlong stretch(jint x, int bits) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  // put x[high 4] into place
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  jlong h = (jlong)((x >> (16-4))) << (bits - 4);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  // put x[low 12] into place, sign extended
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  jlong l = ((jlong)x << (64-12)) >> (64-12);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  // move l upwards, maybe
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  l <<= (x >> 16);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  return h ^ l;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
void test_compressed_stream(int trace) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  CompressedWriteStream bytes(stretch_limit * 100);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  jint n;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  int step = 0, fails = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
#define CHECKXY(x, y, fmt) { \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
    ++step; \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
    int xlen = (pos = decode.position()) - lastpos; lastpos = pos; \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
    if (trace > 0 && (step % trace) == 0) { \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
      tty->print_cr("step %d, n=%08x: value=" fmt " (len=%d)", \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
                    step, n, x, xlen); } \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
    if (x != y) {                                                     \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
      tty->print_cr("step %d, n=%d: " fmt " != " fmt, step, n, x, y); \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
      fails++; \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
    } }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  for (n = 0; n < (1<<8); n++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
    jbyte x = (jbyte)n;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
    bytes.write_byte(x); ++step;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  for (n = 0; n < stretch_limit; n++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
    jint x = (jint)stretch(n, 32);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
    bytes.write_int(x); ++step;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
    bytes.write_signed_int(x); ++step;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
    bytes.write_float(jfloat_cast(x)); ++step;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  for (n = 0; n < stretch_limit; n++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
    jlong x = stretch(n, 64);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
    bytes.write_long(x); ++step;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
    bytes.write_double(jdouble_cast(x)); ++step;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
  int length = bytes.position();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  if (trace != 0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
    tty->print_cr("set up test of %d stream values, size %d", step, length);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  step = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
  // now decode it all
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
  CompressedReadStream decode(bytes.buffer());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  int pos, lastpos = decode.position();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
  for (n = 0; n < (1<<8); n++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
    jbyte x = (jbyte)n;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
    jbyte y = decode.read_byte();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
    CHECKXY(x, y, "%db");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  for (n = 0; n < stretch_limit; n++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
    jint x = (jint)stretch(n, 32);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
    jint y1 = decode.read_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
    CHECKXY(x, y1, "%du");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
    jint y2 = decode.read_signed_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
    CHECKXY(x, y2, "%di");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
    jint y3 = jint_cast(decode.read_float());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
    CHECKXY(x, y3, "%df");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
  for (n = 0; n < stretch_limit; n++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
    jlong x = stretch(n, 64);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
    jlong y1 = decode.read_long();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
    CHECKXY(x, y1, INT64_FORMAT "l");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
    jlong y2 = jlong_cast(decode.read_double());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
    CHECKXY(x, y2, INT64_FORMAT "d");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  int length2 = decode.position();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
  if (trace != 0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
    tty->print_cr("finished test of %d stream values, size %d", step, length2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
  guarantee(length == length2, "bad length");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
  guarantee(fails == 0, "test failures");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
#if _MSC_VER >=1400 && !defined(_WIN64)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
#pragma optimize("", on)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
#endif // PRODUCT