src/jdk.pack/share/native/common-unpack/coding.cpp
author jwilhelm
Thu, 27 Jun 2019 03:13:54 +0200
changeset 55515 4c52949a3487
parent 47216 71c04702a3d5
permissions -rw-r--r--
Added tag jdk-13+27 for changeset b7f68ddec66f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2624
diff changeset
     2
 * Copyright (c) 2002, 2009, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2624
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2624
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2624
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2624
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2624
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
// -*- C++ -*-
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
// Small program for unpacking specially compressed Java packages.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
// John R. Rose
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include <stdio.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include <string.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include <stdlib.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include <stdarg.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
22258
db80f864ed8f 8030875: Macros for checking and returning on exceptions
rriggs
parents: 5506
diff changeset
    35
#include "jni_util.h"
db80f864ed8f 8030875: Macros for checking and returning on exceptions
rriggs
parents: 5506
diff changeset
    36
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#include "defines.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
#include "bytes.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#include "utils.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
#include "coding.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
#include "constants.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
#include "unpack.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
extern coding basic_codings[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
#define CODING_PRIVATE(spec) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
  int spec_ = spec; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
  int B = CODING_B(spec_); \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
  int H = CODING_H(spec_); \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
  int L = 256 - H; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
  int S = CODING_S(spec_); \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
  int D = CODING_D(spec_)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
#define IS_NEG_CODE(S, codeVal) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
  ( (((int)(codeVal)+1) & ((1<<S)-1)) == 0 )
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
#define DECODE_SIGN_S1(ux) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
  ( ((uint)(ux) >> 1) ^ -((int)(ux) & 1) )
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
static maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
int decode_sign(int S, uint ux) {  // == Coding.decodeSign32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
  assert(S > 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
  uint sigbits = (ux >> S);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
  if (IS_NEG_CODE(S, ux))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    return (int)(    ~sigbits);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
  else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    return (int)(ux - sigbits);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
  // Note that (int)(ux-sigbits) can be negative, if ux is large enough.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
coding* coding::init() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
  if (umax > 0)  return this;  // already done
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
  assert(spec != 0);  // sanity
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
  // fill in derived fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
  CODING_PRIVATE(spec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
  // Return null if 'arb(BHSD)' parameter constraints are not met:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
  if (B < 1 || B > B_MAX)  return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
  if (H < 1 || H > 256)    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
  if (S < 0 || S > 2)      return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
  if (D < 0 || D > 1)      return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
  if (B == 1 && H != 256)  return null;  // 1-byte coding must be fixed-size
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
  if (B >= 5 && H == 256)  return null;  // no 5-byte fixed-size coding
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
  // first compute the range of the coding, in 64 bits
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
  jlong range = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    jlong H_i = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    for (int i = 0; i < B; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
      range += H_i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
      H_i *= H;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    range *= L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    range += H_i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
  assert(range > 0);  // no useless codings, please
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
  int this_umax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
  // now, compute min and max
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
  if (range >= ((jlong)1 << 32)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    this_umax  = INT_MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    this->umin = INT_MIN_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    this->max  = INT_MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    this->min  = INT_MIN_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    this_umax = (range > INT_MAX_VALUE) ? INT_MAX_VALUE : (int)range-1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    this->max = this_umax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    this->min = this->umin = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    if (S != 0 && range != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
      int Smask = (1<<S)-1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
      jlong maxPosCode = range-1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
      jlong maxNegCode = range-1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
      while (IS_NEG_CODE(S,  maxPosCode))  --maxPosCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
      while (!IS_NEG_CODE(S, maxNegCode))  --maxNegCode;
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   118
      int maxPos = decode_sign(S, (uint)maxPosCode);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
      if (maxPos < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        this->max = INT_MAX_VALUE;  // 32-bit wraparound
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
      else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        this->max = maxPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
      if (maxNegCode < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        this->min = 0;  // No negative codings at all.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
      else
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   126
        this->min = decode_sign(S, (uint)maxNegCode);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
  assert(!(isFullRange | isSigned | isSubrange)); // init
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
  if (min < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    this->isSigned = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
  if (max < INT_MAX_VALUE && range <= INT_MAX_VALUE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    this->isSubrange = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
  if (max == INT_MAX_VALUE && min == INT_MIN_VALUE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    this->isFullRange = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
  // do this last, to reduce MT exposure (should have a membar too)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
  this->umax = this_umax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
  return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
coding* coding::findBySpec(int spec) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
  for (coding* scan = &basic_codings[0]; ; scan++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    if (scan->spec == spec)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
      return scan->init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    if (scan->spec == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
  coding* ptr = NEW(coding, 1);
22258
db80f864ed8f 8030875: Macros for checking and returning on exceptions
rriggs
parents: 5506
diff changeset
   152
  CHECK_NULL_RETURN(ptr, 0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
  coding* c = ptr->initFrom(spec);
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   154
  if (c == null) {
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   155
    mtrace('f', ptr, 0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    ::free(ptr);
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   157
  } else
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    // else caller should free it...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    c->isMalloc = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
  return c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
coding* coding::findBySpec(int B, int H, int S, int D) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
  if (B < 1 || B > B_MAX)  return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
  if (H < 1 || H > 256)    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
  if (S < 0 || S > 2)      return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
  if (D < 0 || D > 1)      return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
  return findBySpec(CODING_SPEC(B, H, S, D));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
void coding::free() {
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   172
  if (isMalloc) {
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   173
    mtrace('f', this, 0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    ::free(this);
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   175
  }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
void coding_method::reset(value_stream* state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
  assert(state->rp == state->rplimit);  // not in mid-stream, please
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
  //assert(this == vs0.cm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
  state[0] = vs0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
  if (uValues != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    uValues->reset(state->helper());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
uint coding::parse(byte* &rp, int B, int H) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
  int L = 256-H;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
  byte* ptr = rp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
  // hand peel the i==0 part of the loop:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
  uint b_i = *ptr++ & 0xFF;
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   193
  if (B == 1 || b_i < (uint)L)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    { rp = ptr; return b_i; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
  uint sum = b_i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
  uint H_i = H;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
  assert(B <= B_MAX);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
  for (int i = 2; i <= B_MAX; i++) { // easy for compilers to unroll if desired
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    b_i = *ptr++ & 0xFF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    sum += b_i * H_i;
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   201
    if (i == B || b_i < (uint)L)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
      { rp = ptr; return sum; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    H_i *= H;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
  assert(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
  return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
uint coding::parse_lgH(byte* &rp, int B, int H, int lgH) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
  assert(H == (1<<lgH));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
  int L = 256-(1<<lgH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
  byte* ptr = rp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
  // hand peel the i==0 part of the loop:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
  uint b_i = *ptr++ & 0xFF;
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   216
  if (B == 1 || b_i < (uint)L)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    { rp = ptr; return b_i; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
  uint sum = b_i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
  uint lg_H_i = lgH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
  assert(B <= B_MAX);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
  for (int i = 2; i <= B_MAX; i++) { // easy for compilers to unroll if desired
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    b_i = *ptr++ & 0xFF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    sum += b_i << lg_H_i;
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   224
    if (i == B || b_i < (uint)L)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
      { rp = ptr; return sum; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    lg_H_i += lgH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
  assert(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
  return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
static const char ERB[] = "EOF reading band";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
void coding::parseMultiple(byte* &rp, int N, byte* limit, int B, int H) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
  if (N < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    abort("bad value count");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
  byte* ptr = rp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
  if (B == 1 || H == 256) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    size_t len = (size_t)N*B;
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   243
    if (len / B != (size_t)N || ptr+len > limit) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
      abort(ERB);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
      return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    rp = ptr+len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
  // Note:  We assume rp has enough zero-padding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
  int L = 256-H;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
  int n = B;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
  while (N > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    ptr += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    if (--n == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
      // end of encoding at B bytes, regardless of byte value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
      int b = (ptr[-1] & 0xFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
      if (b >= L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        // keep going, unless we find a byte < L
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    // found the last byte
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    N -= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    n = B;   // reset length counter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    // do an error check here
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    if (ptr > limit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
      abort(ERB);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
      return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
  rp = ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
  return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
bool value_stream::hasHelper() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
  // If my coding method is a pop-style method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
  // then I need a second value stream to transmit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
  // unfavored values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
  // This can be determined by examining fValues.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
  return cm->fValues != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
void value_stream::init(byte* rp_, byte* rplimit_, coding* defc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
  rp = rp_;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
  rplimit = rplimit_;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
  sum = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
  cm = null;  // no need in the simple case
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
  setCoding(defc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
void value_stream::setCoding(coding* defc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
  if (defc == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    unpack_abort("bad coding");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    defc = coding::findByIndex(_meta_canon_min);  // random pick for recovery
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
  c = (*defc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
  // choose cmk
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
  cmk = cmk_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
  switch (c.spec) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
  case BYTE1_spec:      cmk = cmk_BYTE1;        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
  case CHAR3_spec:      cmk = cmk_CHAR3;        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
  case UNSIGNED5_spec:  cmk = cmk_UNSIGNED5;    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
  case DELTA5_spec:     cmk = cmk_DELTA5;       break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
  case BCI5_spec:       cmk = cmk_BCI5;         break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
  case BRANCH5_spec:    cmk = cmk_BRANCH5;      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
  default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    if (c.D() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
      switch (c.S()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
      case 0:  cmk = cmk_BHS0;  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
      case 1:  cmk = cmk_BHS1;  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
      default: cmk = cmk_BHS;   break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
      if (c.S() == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        if (c.isFullRange)   cmk = cmk_BHS1D1full;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        if (c.isSubrange)    cmk = cmk_BHS1D1sub;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
      if (cmk == cmk_ERROR)  cmk = cmk_BHSD1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
static maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
int getPopValue(value_stream* self, uint uval) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
  if (uval > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    // note that the initial parse performed a range check
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   331
    assert(uval <= (uint)self->cm->fVlength);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    return self->cm->fValues[uval-1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    // take an unfavored value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    return self->helper()->getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
int coding::sumInUnsignedRange(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
  assert(isSubrange);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
  int range = (int)(umax+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
  assert(range > 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
  x += y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
  if (x != (int)((jlong)(x-y) + (jlong)y)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    // 32-bit overflow interferes with range reduction.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    // Back off from the overflow by adding a multiple of range:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    if (x < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
      x -= range;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
      assert(x >= 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
      x += range;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
      assert(x < 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
  if (x < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    x += range;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    if (x >= 0)  return x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
  } else if (x >= range) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    x -= range;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    if (x < range)  return x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    // in range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    return x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
  // do it the hard way
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
  x %= range;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
  if (x < 0)  x += range;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
  return x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
static maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
int getDeltaValue(value_stream* self, uint uval, bool isSubrange) {
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   374
  assert((uint)(self->c.isSubrange) == (uint)isSubrange);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
  assert(self->c.isSubrange | self->c.isFullRange);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
  if (isSubrange)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    return self->sum = self->c.sumInUnsignedRange(self->sum, (int)uval);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
  else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    return self->sum += (int) uval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
bool value_stream::hasValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
  if (rp < rplimit)      return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
  if (cm == null)        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
  if (cm->next == null)  return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
  cm->next->reset(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
  return hasValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
int value_stream::getInt() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
  if (rp >= rplimit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    // Advance to next coding segment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    if (rp > rplimit || cm == null || cm->next == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
      // Must perform this check and throw an exception on bad input.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
      unpack_abort(ERB);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
      return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    cm->next->reset(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    return getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
  CODING_PRIVATE(c.spec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
  uint uval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
  enum {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    B5 = 5,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    B3 = 3,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    H128 = 128,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    H64 = 64,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    H4 = 4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
  };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
  switch (cmk) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
  case cmk_BHS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    assert(D == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    uval = coding::parse(rp, B, H);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    if (S == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
      return (int) uval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    return decode_sign(S, uval);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
  case cmk_BHS0:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    assert(S == 0 && D == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    uval = coding::parse(rp, B, H);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    return (int) uval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
  case cmk_BHS1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    assert(S == 1 && D == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    uval = coding::parse(rp, B, H);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    return DECODE_SIGN_S1(uval);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
  case cmk_BYTE1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    assert(c.spec == BYTE1_spec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    assert(B == 1 && H == 256 && S == 0 && D == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    return *rp++ & 0xFF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
  case cmk_CHAR3:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    assert(c.spec == CHAR3_spec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    assert(B == B3 && H == H128 && S == 0 && D == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    return coding::parse_lgH(rp, B3, H128, 7);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
  case cmk_UNSIGNED5:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    assert(c.spec == UNSIGNED5_spec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    assert(B == B5 && H == H64 && S == 0 && D == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    return coding::parse_lgH(rp, B5, H64, 6);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
  case cmk_BHSD1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    assert(D == 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    uval = coding::parse(rp, B, H);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    if (S != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
      uval = (uint) decode_sign(S, uval);
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   449
    return getDeltaValue(this, uval, (bool)c.isSubrange);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
  case cmk_BHS1D1full:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    assert(S == 1 && D == 1 && c.isFullRange);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    uval = coding::parse(rp, B, H);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    uval = (uint) DECODE_SIGN_S1(uval);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    return getDeltaValue(this, uval, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
  case cmk_BHS1D1sub:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    assert(S == 1 && D == 1 && c.isSubrange);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    uval = coding::parse(rp, B, H);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    uval = (uint) DECODE_SIGN_S1(uval);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    return getDeltaValue(this, uval, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
  case cmk_DELTA5:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    assert(c.spec == DELTA5_spec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    assert(B == B5 && H == H64 && S == 1 && D == 1 && c.isFullRange);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    uval = coding::parse_lgH(rp, B5, H64, 6);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    sum += DECODE_SIGN_S1(uval);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    return sum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
  case cmk_BCI5:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    assert(c.spec == BCI5_spec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    assert(B == B5 && H == H4 && S == 0 && D == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    return coding::parse_lgH(rp, B5, H4, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
  case cmk_BRANCH5:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    assert(c.spec == BRANCH5_spec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    assert(B == B5 && H == H4 && S == 2 && D == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    uval = coding::parse_lgH(rp, B5, H4, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    return decode_sign(S, uval);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
  case cmk_pop:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    uval = coding::parse(rp, B, H);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    if (S != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
      uval = (uint) decode_sign(S, uval);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    if (D != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
      assert(c.isSubrange | c.isFullRange);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
      if (c.isSubrange)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        sum = c.sumInUnsignedRange(sum, (int) uval);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
      else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        sum += (int) uval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
      uval = (uint) sum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    return getPopValue(this, uval);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
  case cmk_pop_BHS0:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    assert(S == 0 && D == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    uval = coding::parse(rp, B, H);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    return getPopValue(this, uval);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
  case cmk_pop_BYTE1:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    assert(c.spec == BYTE1_spec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    assert(B == 1 && H == 256 && S == 0 && D == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    return getPopValue(this, *rp++ & 0xFF);
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   505
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   506
  default:
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   507
    break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
  assert(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
  return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
static maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
int moreCentral(int x, int y) {  // used to find end of Pop.{F}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
  // Suggested implementation from the Pack200 specification:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
  uint kx = (x >> 31) ^ (x << 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
  uint ky = (y >> 31) ^ (y << 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
  return (kx < ky? x: y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
//static maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
//int moreCentral2(int x, int y, int min) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
//  // Strict implementation of buggy 150.7 specification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
//  // The bug is that the spec. says absolute-value ties are broken
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
//  // in favor of positive numbers, but the suggested implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
//  // (also mentioned in the spec.) breaks ties in favor of negative numbers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
//  if ((x + y) != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
//    return min;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
//  else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
//    // return the other value, which breaks a tie in the positive direction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
//    return (x > y)? x: y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
//}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
static const byte* no_meta[] = {null};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
#define NO_META (*(byte**)no_meta)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
enum { POP_FAVORED_N = -2 };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
// mode bits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
#define DISABLE_RUN  1  // used immediately inside ACodee
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
#define DISABLE_POP  2  // used recursively in all pop sub-bands
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
// This function knows all about meta-coding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
void coding_method::init(byte* &band_rp, byte* band_limit,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                         byte* &meta_rp, int mode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                         coding* defc, int N,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                         intlist* valueSink) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
  assert(N != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
  assert(u != null);  // must be pre-initialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
  //if (u == null)  u = unpacker::current();  // expensive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
  int op = (meta_rp == null) ? _meta_default :  (*meta_rp++ & 0xFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
  coding* foundc = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
  coding* to_free = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
  if (op == _meta_default) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    foundc = defc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    // and fall through
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
  } else if (op >= _meta_canon_min && op <= _meta_canon_max) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    foundc = coding::findByIndex(op);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    // and fall through
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
  } else if (op == _meta_arb) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    int args = (*meta_rp++ & 0xFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    // args = (D:[0..1] + 2*S[0..2] + 8*(B:[1..5]-1))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    int D = ((args >> 0) & 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    int S = ((args >> 1) & 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    int B = ((args >> 3) & -1) + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    // & (H[1..256]-1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    int H = (*meta_rp++ & 0xFF) + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    foundc = coding::findBySpec(B, H, S, D);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    to_free = foundc;  // findBySpec may dynamically allocate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    if (foundc == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
      abort("illegal arb. coding");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
      return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    // and fall through
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
  } else if (op >= _meta_run && op < _meta_pop) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    int args = (op - _meta_run);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    // args: KX:[0..3] + 4*(KBFlag:[0..1]) + 8*(ABDef:[0..2])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    int KX     = ((args >> 0) & 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    int KBFlag = ((args >> 2) & 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
    int ABDef  = ((args >> 3) & -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    assert(ABDef <= 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    // & KB: one of [0..255] if KBFlag=1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    int KB     = (!KBFlag? 3: (*meta_rp++ & 0xFF));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    int K      = (KB+1) << (KX * 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    int N2 = (N >= 0) ? N-K : N;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    if (N == 0 || (N2 <= 0 && N2 != N)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
      abort("illegal run encoding");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
      return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    if ((mode & DISABLE_RUN) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
      abort("illegal nested run encoding");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
      return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    // & Enc{ ACode } if ADef=0  (ABDef != 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    // No direct nesting of 'run' in ACode, but in BCode it's OK.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
    int disRun = mode | DISABLE_RUN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    if (ABDef == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
      this->init(band_rp, band_limit, NO_META, disRun, defc, K, valueSink);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
      this->init(band_rp, band_limit, meta_rp, disRun, defc, K, valueSink);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    // & Enc{ BCode } if BDef=0  (ABDef != 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
    coding_method* tail = U_NEW(coding_method, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
    CHECK_NULL(tail);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    tail->u = u;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    // The 'run' codings may be nested indirectly via 'pop' codings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
    // This means that this->next may already be filled in, if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
    // ACode was of type 'pop' with a 'run' token coding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
    // No problem:  Just chain the upcoming BCode onto the end.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    for (coding_method* self = this; ; self = self->next) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
      if (self->next == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        self->next = tail;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
    if (ABDef == 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
      tail->init(band_rp, band_limit, NO_META, mode, defc, N2, valueSink);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
      tail->init(band_rp, band_limit, meta_rp, mode, defc, N2, valueSink);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    // Note:  The preceding calls to init should be tail-recursive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
    return;  // done; no falling through
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
  } else if (op >= _meta_pop && op < _meta_limit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
    int args = (op - _meta_pop);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    // args: (FDef:[0..1]) + 2*UDef:[0..1] + 4*(TDefL:[0..11])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    int FDef  = ((args >> 0) & 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    int UDef  = ((args >> 1) & 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    int TDefL = ((args >> 2) & -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
    assert(TDefL <= 11);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
    int TDef  = (TDefL > 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    int TL    = (TDefL <= 6) ? (2 << TDefL) : (256 - (4 << (11-TDefL)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
    int TH    = (256-TL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
    if (N <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
      abort("illegal pop encoding");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
      return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
    if ((mode & DISABLE_POP) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
      abort("illegal nested pop encoding");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
      return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
    // No indirect nesting of 'pop', but 'run' is OK.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    int disPop = DISABLE_POP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
    // & Enc{ FCode } if FDef=0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
    int FN = POP_FAVORED_N;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    assert(valueSink == null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
    intlist fValueSink; fValueSink.init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
    coding_method fval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    BYTES_OF(fval).clear(); fval.u = u;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
    if (FDef != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
      fval.init(band_rp, band_limit, NO_META, disPop, defc, FN, &fValueSink);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
      fval.init(band_rp, band_limit, meta_rp, disPop, defc, FN, &fValueSink);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
    bytes fvbuf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
    fValues  = (u->saveTo(fvbuf, fValueSink.b), (int*) fvbuf.ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    fVlength = fValueSink.length();  // i.e., the parameter K
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
    fValueSink.free();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
    CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
    // Skip the first {F} run in all subsequent passes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
    // The next call to this->init(...) will set vs0.rp to point after the {F}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
    // & Enc{ TCode } if TDef=0  (TDefL==0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    if (TDef != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
      coding* tcode = coding::findBySpec(1, 256);  // BYTE1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
      // find the most narrowly sufficient code:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
      for (int B = 2; B <= B_MAX; B++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        if (fVlength <= tcode->umax)  break;  // found it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        tcode->free();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
        tcode = coding::findBySpec(B, TH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        CHECK_NULL(tcode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
      if (!(fVlength <= tcode->umax)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        abort("pop.L value too small");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
      this->init(band_rp, band_limit, NO_META, disPop, tcode, N, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
      tcode->free();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
      this->init(band_rp, band_limit, meta_rp, disPop,  defc, N, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
    CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
    // Count the number of zero tokens right now.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    // Also verify that they are in bounds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
    int UN = 0;   // one {U} for each zero in {T}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
    value_stream vs = vs0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
    for (int i = 0; i < N; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
      uint val = vs.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
      if (val == 0)  UN += 1;
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   704
      if (!(val <= (uint)fVlength)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        abort("pop token out of range");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
    vs.done();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
    // & Enc{ UCode } if UDef=0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
    if (UN != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
      uValues = U_NEW(coding_method, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
      CHECK_NULL(uValues);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
      uValues->u = u;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
      if (UDef != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        uValues->init(band_rp, band_limit, NO_META, disPop, defc, UN, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
      } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        uValues->init(band_rp, band_limit, meta_rp, disPop, defc, UN, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
      if (UDef == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
        int uop = (*meta_rp++ & 0xFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        if (uop > _meta_canon_max)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
          // %%% Spec. requires the more strict (uop != _meta_default).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
          abort("bad meta-coding for empty pop/U");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
    // Bug fix for 6259542
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
    // Last of all, adjust vs0.cmk to the 'pop' flavor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
    for (coding_method* self = this; self != null; self = self->next) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        coding_method_kind cmk2 = cmk_pop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        switch (self->vs0.cmk) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        case cmk_BHS0:   cmk2 = cmk_pop_BHS0;   break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        case cmk_BYTE1:  cmk2 = cmk_pop_BYTE1;  break;
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   737
        default: break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        self->vs0.cmk = cmk2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        if (self != this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
          assert(self->fValues == null); // no double init
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
          self->fValues  = this->fValues;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
          self->fVlength = this->fVlength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
          assert(self->uValues == null); // must stay null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
    return;  // done; no falling through
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    abort("bad meta-coding");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
  // Common code here skips a series of values with one coding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
  assert(foundc != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
  assert(vs0.cmk == cmk_ERROR);  // no garbage, please
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
  assert(vs0.rp == null);  // no garbage, please
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
  assert(vs0.rplimit == null);  // no garbage, please
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
  assert(vs0.sum == 0);  // no garbage, please
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
  vs0.init(band_rp, band_limit, foundc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
  // Done with foundc.  Free if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
  if (to_free != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
    to_free->free();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
    to_free = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
  foundc = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
  coding& c = vs0.c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
  CODING_PRIVATE(c.spec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
  // assert sane N
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
  assert((uint)N < INT_MAX_VALUE || N == POP_FAVORED_N);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
  // Look at the values, or at least skip over them quickly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
  if (valueSink == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
    // Skip and ignore values in the first pass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
    c.parseMultiple(band_rp, N, band_limit, B, H);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
  } else if (N >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
    // Pop coding, {F} sequence, initial run of values...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
    assert((mode & DISABLE_POP) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
    value_stream vs = vs0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
    for (int n = 0; n < N; n++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
      int val = vs.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
      valueSink->add(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
    band_rp = vs.rp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
    // Pop coding, {F} sequence, final run of values...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
    assert((mode & DISABLE_POP) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
    assert(N == POP_FAVORED_N);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
    int min = INT_MIN_VALUE;  // farthest from the center
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
    // min2 is based on the buggy specification of centrality in version 150.7
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
    // no known implementations transmit this value, but just in case...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
    //int min2 = INT_MIN_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
    int last = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
    // if there were initial runs, find the potential sentinels in them:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
    for (int i = 0; i < valueSink->length(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
      last = valueSink->get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
      min = moreCentral(min, last);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
      //min2 = moreCentral2(min2, last, min);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
    value_stream vs = vs0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
    for (;;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
      int val = vs.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
      if (valueSink->length() > 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
          (val == last || val == min)) //|| val == min2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
      valueSink->add(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
      CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
      last = val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
      min = moreCentral(min, last);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
      //min2 = moreCentral2(min2, last, min);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
    band_rp = vs.rp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
  }
2607
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2
diff changeset
   819
  CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
  // Get an accurate upper limit now.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
  vs0.rplimit = band_rp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
  vs0.cm = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
  return; // success
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
coding basic_codings[] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
  // This one is not a usable irregular coding, but is used by cp_Utf8_chars.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
  CODING_INIT(3,128,0,0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
  // Fixed-length codings:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
  CODING_INIT(1,256,0,0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
  CODING_INIT(1,256,1,0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
  CODING_INIT(1,256,0,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
  CODING_INIT(1,256,1,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
  CODING_INIT(2,256,0,0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
  CODING_INIT(2,256,1,0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
  CODING_INIT(2,256,0,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
  CODING_INIT(2,256,1,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
  CODING_INIT(3,256,0,0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
  CODING_INIT(3,256,1,0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
  CODING_INIT(3,256,0,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
  CODING_INIT(3,256,1,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
  CODING_INIT(4,256,0,0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
  CODING_INIT(4,256,1,0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
  CODING_INIT(4,256,0,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
  CODING_INIT(4,256,1,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
  // Full-range variable-length codings:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
  CODING_INIT(5,  4,0,0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
  CODING_INIT(5,  4,1,0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
  CODING_INIT(5,  4,2,0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
  CODING_INIT(5, 16,0,0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
  CODING_INIT(5, 16,1,0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
  CODING_INIT(5, 16,2,0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
  CODING_INIT(5, 32,0,0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
  CODING_INIT(5, 32,1,0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
  CODING_INIT(5, 32,2,0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
  CODING_INIT(5, 64,0,0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
  CODING_INIT(5, 64,1,0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
  CODING_INIT(5, 64,2,0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
  CODING_INIT(5,128,0,0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
  CODING_INIT(5,128,1,0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
  CODING_INIT(5,128,2,0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
  CODING_INIT(5,  4,0,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
  CODING_INIT(5,  4,1,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
  CODING_INIT(5,  4,2,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
  CODING_INIT(5, 16,0,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
  CODING_INIT(5, 16,1,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
  CODING_INIT(5, 16,2,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
  CODING_INIT(5, 32,0,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
  CODING_INIT(5, 32,1,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
  CODING_INIT(5, 32,2,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
  CODING_INIT(5, 64,0,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
  CODING_INIT(5, 64,1,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
  CODING_INIT(5, 64,2,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
  CODING_INIT(5,128,0,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
  CODING_INIT(5,128,1,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
  CODING_INIT(5,128,2,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
  // Variable length subrange codings:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
  CODING_INIT(2,192,0,0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
  CODING_INIT(2,224,0,0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
  CODING_INIT(2,240,0,0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
  CODING_INIT(2,248,0,0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
  CODING_INIT(2,252,0,0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
  CODING_INIT(2,  8,0,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
  CODING_INIT(2,  8,1,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
  CODING_INIT(2, 16,0,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
  CODING_INIT(2, 16,1,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
  CODING_INIT(2, 32,0,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
  CODING_INIT(2, 32,1,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
  CODING_INIT(2, 64,0,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
  CODING_INIT(2, 64,1,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
  CODING_INIT(2,128,0,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
  CODING_INIT(2,128,1,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
  CODING_INIT(2,192,0,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
  CODING_INIT(2,192,1,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
  CODING_INIT(2,224,0,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
  CODING_INIT(2,224,1,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
  CODING_INIT(2,240,0,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
  CODING_INIT(2,240,1,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
  CODING_INIT(2,248,0,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
  CODING_INIT(2,248,1,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
  CODING_INIT(3,192,0,0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
  CODING_INIT(3,224,0,0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
  CODING_INIT(3,240,0,0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
  CODING_INIT(3,248,0,0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
  CODING_INIT(3,252,0,0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
  CODING_INIT(3,  8,0,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
  CODING_INIT(3,  8,1,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
  CODING_INIT(3, 16,0,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
  CODING_INIT(3, 16,1,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
  CODING_INIT(3, 32,0,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
  CODING_INIT(3, 32,1,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
  CODING_INIT(3, 64,0,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
  CODING_INIT(3, 64,1,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
  CODING_INIT(3,128,0,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
  CODING_INIT(3,128,1,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
  CODING_INIT(3,192,0,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
  CODING_INIT(3,192,1,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
  CODING_INIT(3,224,0,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
  CODING_INIT(3,224,1,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
  CODING_INIT(3,240,0,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
  CODING_INIT(3,240,1,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
  CODING_INIT(3,248,0,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
  CODING_INIT(3,248,1,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
  CODING_INIT(4,192,0,0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
  CODING_INIT(4,224,0,0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
  CODING_INIT(4,240,0,0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
  CODING_INIT(4,248,0,0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
  CODING_INIT(4,252,0,0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
  CODING_INIT(4,  8,0,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
  CODING_INIT(4,  8,1,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
  CODING_INIT(4, 16,0,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
  CODING_INIT(4, 16,1,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
  CODING_INIT(4, 32,0,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
  CODING_INIT(4, 32,1,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
  CODING_INIT(4, 64,0,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
  CODING_INIT(4, 64,1,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
  CODING_INIT(4,128,0,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
  CODING_INIT(4,128,1,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
  CODING_INIT(4,192,0,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
  CODING_INIT(4,192,1,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
  CODING_INIT(4,224,0,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
  CODING_INIT(4,224,1,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
  CODING_INIT(4,240,0,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
  CODING_INIT(4,240,1,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
  CODING_INIT(4,248,0,1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
  CODING_INIT(4,248,1,1),
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   958
  CODING_INIT(0,0,0,0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
#define BASIC_INDEX_LIMIT \
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   961
        (int)(sizeof(basic_codings)/sizeof(basic_codings[0])-1)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
coding* coding::findByIndex(int idx) {
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   964
#ifndef PRODUCT
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   965
  /* Tricky assert here, constants and gcc complains about it without local. */
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   966
  int index_limit = BASIC_INDEX_LIMIT;
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   967
  assert(_meta_canon_min == 1 && _meta_canon_max+1 == index_limit);
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   968
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
  if (idx >= _meta_canon_min && idx <= _meta_canon_max)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
    return basic_codings[idx].init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
  else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
#ifndef PRODUCT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
const char* coding::string() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
  CODING_PRIVATE(spec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
  bytes buf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
  buf.malloc(100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
  char maxS[20], minS[20];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
  sprintf(maxS, "%d", max);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
  sprintf(minS, "%d", min);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
  if (max == INT_MAX_VALUE)  strcpy(maxS, "max");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
  if (min == INT_MIN_VALUE)  strcpy(minS, "min");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
  sprintf((char*)buf.ptr, "(%d,%d,%d,%d) L=%d r=[%s,%s]",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
          B,H,S,D,L,minS,maxS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
  return (const char*) buf.ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
#endif