hotspot/src/share/vm/code/compressedStream.hpp
author dlong
Thu, 17 Dec 2015 09:39:07 -0800
changeset 35132 07bc696c7fdb
parent 7397 5b173b4ca846
child 46600 fdde0f192cde
permissions -rw-r--r--
8144852: Corrupted oop in nmethod Reviewed-by: vlivanov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
     2
 * Copyright (c) 1997, 2010, 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
#ifndef SHARE_VM_CODE_COMPRESSEDSTREAM_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#define SHARE_VM_CODE_COMPRESSEDSTREAM_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "memory/allocation.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
// Simple interface for filing out and filing in basic types
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
// Used for writing out and reading in debugging information.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
class CompressedStream : public ResourceObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  u_char* _buffer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  int     _position;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  enum {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
    // Constants for UNSIGNED5 coding of Pack200
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
    lg_H = 6, H = 1<<lg_H,    // number of high codes (64)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
    L = (1<<BitsPerByte)-H,   // number of low codes (192)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
    MAX_i = 4                 // bytes are numbered in (0..4), max 5 bytes
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  // these inlines are defined only in compressedStream.cpp
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  static inline juint encode_sign(jint  value);  // for Pack200 SIGNED5
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  static inline jint  decode_sign(juint value);  // for Pack200 SIGNED5
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  static inline juint reverse_int(juint bits);   // to trim trailing float 0's
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  CompressedStream(u_char* buffer, int position = 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
    _buffer   = buffer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
    _position = position;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  u_char* buffer() const               { return _buffer; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  // Positioning
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  int position() const                 { return _position; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  void set_position(int position)      { _position = position; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
class CompressedReadStream : public CompressedStream {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  inline u_char read()                 { return _buffer[_position++]; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  jint     read_int_mb(jint b0);  // UNSIGNED5 coding, 2-5 byte cases
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  CompressedReadStream(u_char* buffer, int position = 0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  : CompressedStream(buffer, position) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  jboolean read_bool()                 { return (jboolean) read();      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  jbyte    read_byte()                 { return (jbyte   ) read();      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  jchar    read_char()                 { return (jchar   ) read_int();  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  jshort   read_short()                { return (jshort  ) read_signed_int(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  jint     read_int()                  { jint   b0 = read();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
                                         if (b0 < L)  return b0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
                                         else         return read_int_mb(b0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
                                       }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  jint     read_signed_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  jfloat   read_float();               // jfloat_cast(reverse_int(read_int()))
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  jdouble  read_double();              // jdouble_cast(2*reverse_int(read_int))
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  jlong    read_long();                // jlong_from(2*read_signed_int())
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
class CompressedWriteStream : public CompressedStream {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  bool full() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
    return _position >= _size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  void store(u_char b) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
    _buffer[_position++] = b;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  void write(u_char b) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
    if (full()) grow();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    store(b);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  void grow();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  void write_int_mb(jint value);  // UNSIGNED5 coding, 1-5 byte cases
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  int _size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  CompressedWriteStream(int initial_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  CompressedWriteStream(u_char* buffer, int initial_size, int position = 0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  : CompressedStream(buffer, position) { _size = initial_size; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  void write_bool(jboolean value)      { write(value);      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  void write_byte(jbyte value)         { write(value);      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  void write_char(jchar value)         { write_int(value); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  void write_short(jshort value)       { write_signed_int(value);  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  void write_int(jint value)           { if ((juint)value < L && !full())
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
                                               store((u_char)value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
                                         else  write_int_mb(value);  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  void write_signed_int(jint value);   // write_int(encode_sign(value))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  void write_float(jfloat value);      // write_int(reverse_int(jint_cast(v)))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  void write_double(jdouble value);    // write_int(reverse_int(<low,high>))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  void write_long(jlong value);        // write_signed_int(<low,high>)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   126
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   127
#endif // SHARE_VM_CODE_COMPRESSEDSTREAM_HPP