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