jdk/src/jdk.pack200/share/native/common-unpack/unpack.cpp
author goetz
Fri, 02 Dec 2016 15:02:10 +0100
changeset 42687 7a5929518e6a
parent 41573 3771d7eaab2c
permissions -rw-r--r--
8170663: Fix minor issues in corelib and servicabilty coding. Reviewed-by: dsamersoff, dholmes Contributed-by: David CARLIER <devnexen@gmail.com>, goetz.lindenmaier@sap.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
41572
0b3abcb3879a 8160094: Improve pack200 layout
ksrini
parents: 29591
diff changeset
     2
 * Copyright (c) 2001, 2016, 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: 5191
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: 5191
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: 5191
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5191
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5191
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
// 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
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
    30
/*
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
    31
 * When compiling for a 64bit LP64 system (longs and pointers being 64bits),
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
    32
 *    the printf format %ld is correct and use of %lld will cause warning
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
    33
 *    errors from some compilers (gcc/g++).
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
    34
 * _LP64 can be explicitly set (used on Linux).
26457
1c341086cc51 8051989: Unportable format string argument mismatch in jdk/src/share/native/com/sun/java/util/jar/pack/unpack.cpp
kizune
parents: 25859
diff changeset
    35
 * Should be checking for the Visual C++ since the _LP64 is set on the 64-bit
1c341086cc51 8051989: Unportable format string argument mismatch in jdk/src/share/native/com/sun/java/util/jar/pack/unpack.cpp
kizune
parents: 25859
diff changeset
    36
 * systems but the correct format prefix for 64-bit integers is ll.
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
    37
 * Solaris compilers will define __sparcv9 or __x86_64 on 64bit compilations.
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
    38
 */
26457
1c341086cc51 8051989: Unportable format string argument mismatch in jdk/src/share/native/com/sun/java/util/jar/pack/unpack.cpp
kizune
parents: 25859
diff changeset
    39
#if !defined (_MSC_VER) && \
1c341086cc51 8051989: Unportable format string argument mismatch in jdk/src/share/native/com/sun/java/util/jar/pack/unpack.cpp
kizune
parents: 25859
diff changeset
    40
    (defined(_LP64) || defined(__sparcv9) || defined(__x86_64))
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
    41
  #define LONG_LONG_FORMAT "%ld"
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
    42
  #define LONG_LONG_HEX_FORMAT "%lx"
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
    43
#else
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
    44
  #define LONG_LONG_FORMAT "%lld"
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
    45
  #define LONG_LONG_HEX_FORMAT "%016llx"
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
    46
#endif
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
    47
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
#include <sys/types.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
#include <stdio.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
#include <string.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
#include <stdlib.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
#include <stdarg.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
#include <limits.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
#include <time.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
#include "defines.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
#include "bytes.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
#include "utils.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
#include "coding.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
#include "bands.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
#include "constants.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
#include "zip.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
#include "unpack.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
// tags, in canonical order:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
static const byte TAGS_IN_ORDER[] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
  CONSTANT_Utf8,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
  CONSTANT_Integer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
  CONSTANT_Float,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
  CONSTANT_Long,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
  CONSTANT_Double,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
  CONSTANT_String,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
  CONSTANT_Class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
  CONSTANT_Signature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
  CONSTANT_NameandType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
  CONSTANT_Fieldref,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
  CONSTANT_Methodref,
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
    87
  CONSTANT_InterfaceMethodref,
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
    88
  // constants defined as of JDK 7
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
    89
  CONSTANT_MethodHandle,
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
    90
  CONSTANT_MethodType,
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
    91
  CONSTANT_BootstrapMethod,
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
    92
  CONSTANT_InvokeDynamic
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
#define N_TAGS_IN_ORDER (sizeof TAGS_IN_ORDER)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
#ifndef PRODUCT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
static const char* TAG_NAME[] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
  "*None",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
  "Utf8",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
  "*Unicode",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
  "Integer",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
  "Float",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
  "Long",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
  "Double",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
  "Class",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
  "String",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
  "Fieldref",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
  "Methodref",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
  "InterfaceMethodref",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
  "NameandType",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
  "*Signature",
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   112
  "unused14",
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   113
  "MethodHandle",
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   114
  "MethodType",
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   115
  "*BootstrapMethod",
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   116
  "InvokeDynamic",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
  0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
static const char* ATTR_CONTEXT_NAME[] = {  // match ATTR_CONTEXT_NAME, etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
  "class", "field", "method", "code"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
#define ATTR_CONTEXT_NAME ((const char**)null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   130
// Note that REQUESTED_LDC comes first, then the normal REQUESTED,
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   131
// in the regular constant pool.
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   132
enum { REQUESTED_NONE = -1,
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   133
       // The codes below REQUESTED_NONE are in constant pool output order,
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   134
       // for the sake of outputEntry_cmp:
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   135
       REQUESTED_LDC = -99, REQUESTED
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   136
};
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
#define NO_INORD ((uint)-1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
struct entry {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
  byte tag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
  #if 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
  byte bits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
  enum {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    //EB_EXTRA = 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    EB_SUPER = 2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
  };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
  #endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
  unsigned short nrefs;  // pack w/ tag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
  int  outputIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
  uint inord;   // &cp.entries[cp.tag_base[this->tag]+this->inord] == this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
  entry* *refs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
  // put last to pack best
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
  union {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    bytes b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    jlong l;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
  } value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
  void requestOutputIndex(cpool& cp, int req = REQUESTED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
  int getOutputIndex() {
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   166
    assert(outputIndex > REQUESTED_NONE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    return outputIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
  entry* ref(int refnum) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    assert((uint)refnum < nrefs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    return refs[refnum];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
  const char* utf8String() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    assert(tagMatches(CONSTANT_Utf8));
41573
3771d7eaab2c 8160090: Better signature handling in pack200
ksrini
parents: 41572
diff changeset
   177
    if (value.b.len != strlen((const char*)value.b.ptr)) {
3771d7eaab2c 8160090: Better signature handling in pack200
ksrini
parents: 41572
diff changeset
   178
      unpack_abort("bad utf8 encoding");
3771d7eaab2c 8160090: Better signature handling in pack200
ksrini
parents: 41572
diff changeset
   179
      // and fall through
3771d7eaab2c 8160090: Better signature handling in pack200
ksrini
parents: 41572
diff changeset
   180
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    return (const char*)value.b.ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
  entry* className() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    assert(tagMatches(CONSTANT_Class));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    return ref(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
  entry* memberClass() {
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   190
    assert(tagMatches(CONSTANT_AnyMember));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    return ref(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
  entry* memberDescr() {
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   195
    assert(tagMatches(CONSTANT_AnyMember));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    return ref(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
  entry* descrName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    assert(tagMatches(CONSTANT_NameandType));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    return ref(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
  entry* descrType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    assert(tagMatches(CONSTANT_NameandType));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    return ref(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
  int typeSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
  bytes& asUtf8();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
  int    asInteger() { assert(tag == CONSTANT_Integer); return value.i; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
  bool isUtf8(bytes& b) { return tagMatches(CONSTANT_Utf8) && value.b.equals(b); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
  bool isDoubleWord() { return tag == CONSTANT_Double || tag == CONSTANT_Long; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
  bool tagMatches(byte tag2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    return (tag2 == tag)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
      || (tag2 == CONSTANT_Utf8 && tag == CONSTANT_Signature)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
      #ifndef PRODUCT
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   222
      || (tag2 == CONSTANT_FieldSpecific
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
          && tag >= CONSTANT_Integer && tag <= CONSTANT_String && tag != CONSTANT_Class)
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   224
      || (tag2 == CONSTANT_AnyMember
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
          && tag >= CONSTANT_Fieldref && tag <= CONSTANT_InterfaceMethodref)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
      #endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
      ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
#ifdef PRODUCT
29591
51244d1ddffc 8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents: 29368
diff changeset
   231
  const char* string() { return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
#else
29591
51244d1ddffc 8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents: 29368
diff changeset
   233
  const char* string();  // see far below
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
entry* cpindex::get(uint i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
  if (i >= len)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
  else if (base1 != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    // primary index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    return &base1[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
  else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    // secondary index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    return base2[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
inline bytes& entry::asUtf8() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
  assert(tagMatches(CONSTANT_Utf8));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
  return value.b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
int entry::typeSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
  assert(tagMatches(CONSTANT_Utf8));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
  const char* sigp = (char*) value.b.ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
  switch (*sigp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
  case '(': sigp++; break;  // skip opening '('
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
  case 'D':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
  case 'J': return 2; // double field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
  default:  return 1; // field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
  int siglen = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
  for (;;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    int ch = *sigp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    switch (ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    case 'D': case 'J':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
      siglen += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    case '[':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
      // Skip rest of array info.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
      while (ch == '[') { ch = *sigp++; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
      if (ch != 'L')  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
      // else fall through
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    case 'L':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
      sigp = strchr(sigp, ';');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
      if (sigp == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
          unpack_abort("bad data");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
          return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
      sigp += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    case ')':  // closing ')'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
      return siglen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    siglen += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
inline cpindex* cpool::getFieldIndex(entry* classRef) {
16075
32c3bc19bba7 7186957: Improve Pack200 data validation
ksrini
parents: 12544
diff changeset
   290
  if (classRef == NULL) { abort("missing class reference"); return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
  assert(classRef->tagMatches(CONSTANT_Class));
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   292
  assert((uint)classRef->inord < (uint)tag_count[CONSTANT_Class]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
  return &member_indexes[classRef->inord*2+0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
inline cpindex* cpool::getMethodIndex(entry* classRef) {
16075
32c3bc19bba7 7186957: Improve Pack200 data validation
ksrini
parents: 12544
diff changeset
   296
  if (classRef == NULL) { abort("missing class reference"); return NULL; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
  assert(classRef->tagMatches(CONSTANT_Class));
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   298
  assert((uint)classRef->inord < (uint)tag_count[CONSTANT_Class]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
  return &member_indexes[classRef->inord*2+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
struct inner_class {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
  entry* inner;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
  entry* outer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
  entry* name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
  int    flags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
  inner_class* next_sibling;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
  bool   requested;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
// Here is where everything gets deallocated:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
void unpacker::free() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
  int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
  assert(jniobj == null); // caller resp.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
  assert(infileptr == null);  // caller resp.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
  if (jarout != null)  jarout->reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
  if (gzin != null)    { gzin->free(); gzin = null; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
  if (free_input)  input.free();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
  // free everybody ever allocated with U_NEW or (recently) with T_NEW
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
  assert(smallbuf.base()  == null || mallocs.contains(smallbuf.base()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
  assert(tsmallbuf.base() == null || tmallocs.contains(tsmallbuf.base()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
  mallocs.freeAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
  tmallocs.freeAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
  smallbuf.init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
  tsmallbuf.init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
  bcimap.free();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
  class_fixup_type.free();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
  class_fixup_offset.free();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
  class_fixup_ref.free();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
  code_fixup_type.free();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
  code_fixup_offset.free();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
  code_fixup_source.free();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
  requested_ics.free();
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   334
  cp.requested_bsms.free();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
  cur_classfile_head.free();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
  cur_classfile_tail.free();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
  for (i = 0; i < ATTR_CONTEXT_LIMIT; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    attr_defs[i].free();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
  // free CP state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
  cp.outputEntries.free();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
  for (i = 0; i < CONSTANT_Limit; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    cp.tag_extras[i].free();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
// input handling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
// Attempts to advance rplimit so that (rplimit-rp) is at least 'more'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
// Will eagerly read ahead by larger chunks, if possible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
// Returns false if (rplimit-rp) is not at least 'more',
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
// unless rplimit hits input.limit().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
bool unpacker::ensure_input(jlong more) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
  julong want = more - input_remaining();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
  if ((jlong)want <= 0)          return true;  // it's already in the buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
  if (rplimit == input.limit())  return true;  // not expecting any more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
  if (read_input_fn == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    // assume it is already all there
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    bytes_read += input.limit() - rplimit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    rplimit = input.limit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
  CHECK_0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
  julong remaining = (input.limit() - rplimit);  // how much left to read?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
  byte* rpgoal = (want >= remaining)? input.limit(): rplimit + (size_t)want;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
  enum { CHUNK_SIZE = (1<<14) };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
  julong fetch = want;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
  if (fetch < CHUNK_SIZE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    fetch = CHUNK_SIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
  if (fetch > remaining*3/4)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    fetch = remaining;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
  // Try to fetch at least "more" bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
  while ((jlong)fetch > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    jlong nr = (*read_input_fn)(this, rplimit, fetch, remaining);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    if (nr <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
      return (rplimit >= rpgoal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    remaining -= nr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    rplimit += nr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    fetch -= nr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    bytes_read += nr;
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   382
    assert(remaining == (julong)(input.limit() - rplimit));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
  return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
// output handling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
fillbytes* unpacker::close_output(fillbytes* which) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
  assert(wp != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
  if (which == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    if (wpbase == cur_classfile_head.base()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
      which = &cur_classfile_head;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
      which = &cur_classfile_tail;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
  assert(wpbase  == which->base());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
  assert(wplimit == which->end());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
  which->setLimit(wp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
  wp      = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
  wplimit = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
  //wpbase = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
  return which;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
//maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
void unpacker::ensure_put_space(size_t size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
  if (wp + size <= wplimit)  return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
  // Determine which segment needs expanding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
  fillbytes* which = close_output();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
  byte* wp0 = which->grow(size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
  wpbase  = which->base();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
  wplimit = which->end();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
  wp = wp0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
byte* unpacker::put_space(size_t size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
  byte* wp0 = wp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
  byte* wp1 = wp0 + size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
  if (wp1 > wplimit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    ensure_put_space(size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    wp0 = wp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    wp1 = wp0 + size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
  wp = wp1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
  return wp0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
void unpacker::putu2_at(byte* wp, int n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
  if (n != (unsigned short)n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    unpack_abort(ERROR_OVERFLOW);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
  wp[0] = (n) >> 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
  wp[1] = (n) >> 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
void unpacker::putu4_at(byte* wp, int n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
  wp[0] = (n) >> 24;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
  wp[1] = (n) >> 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
  wp[2] = (n) >> 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
  wp[3] = (n) >> 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
void unpacker::putu8_at(byte* wp, jlong n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
  putu4_at(wp+0, (int)((julong)n >> 32));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
  putu4_at(wp+4, (int)((julong)n >> 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
void unpacker::putu2(int n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
  putu2_at(put_space(2), n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
void unpacker::putu4(int n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
  putu4_at(put_space(4), n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
void unpacker::putu8(jlong n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
  putu8_at(put_space(8), n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
int unpacker::putref_index(entry* e, int size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
  if (e == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    return 0;
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   474
  else if (e->outputIndex > REQUESTED_NONE)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    return e->outputIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
  else if (e->tag == CONSTANT_Signature)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    return putref_index(e->ref(0), size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
  else {
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   479
    e->requestOutputIndex(cp, (size == 1 ? REQUESTED_LDC : REQUESTED));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    // Later on we'll fix the bits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    class_fixup_type.addByte(size);
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   482
    class_fixup_offset.add((int)wpoffset());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    class_fixup_ref.add(e);
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   484
#ifdef PRODUCT
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   485
    return 0;
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   486
#else
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   487
    return 0x20+size;  // 0x22 is easy to eyeball
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   488
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
void unpacker::putref(entry* e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
  int oidx = putref_index(e, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
  putu2_at(put_space(2), oidx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
void unpacker::putu1ref(entry* e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
  int oidx = putref_index(e, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
  putu1_at(put_space(1), oidx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
static int total_cp_size[] = {0, 0};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
static int largest_cp_ref[] = {0, 0};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
static int hash_probes[] = {0, 0};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
// Allocation of small and large blocks.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
enum { CHUNK = (1 << 14), SMALL = (1 << 9) };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
// Call malloc.  Try to combine small blocks and free much later.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
void* unpacker::alloc_heap(size_t size, bool smallOK, bool temp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
  if (!smallOK || size > SMALL) {
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   516
    void* res = must_malloc((int)size);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    (temp ? &tmallocs : &mallocs)->add(res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
  fillbytes& xsmallbuf = *(temp ? &tsmallbuf : &smallbuf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
  if (!xsmallbuf.canAppend(size+1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    xsmallbuf.init(CHUNK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    (temp ? &tmallocs : &mallocs)->add(xsmallbuf.base());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
  }
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   525
  int growBy = (int)size;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
  growBy += -growBy & 7;  // round up mod 8
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
  return xsmallbuf.grow(growBy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
void unpacker::saveTo(bytes& b, byte* ptr, size_t len) {
5191
79b41f733e33 6902299: Java JAR "unpack200" must verify input parameters
ksrini
parents: 3463
diff changeset
   532
  b.ptr = U_NEW(byte, add_size(len,1));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
  if (aborting()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    b.len = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
  b.len = len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
  b.copyFrom(ptr, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   541
bool testBit(int archive_options, int bitMask) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   542
    return (archive_options & bitMask) != 0;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   543
}
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   544
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
// Read up through band_headers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
// Do the archive_size dance to set the size of the input mega-buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
void unpacker::read_file_header() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
  // Read file header to determine file type and total size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
  enum {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
    MAGIC_BYTES = 4,
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   551
    AH_LENGTH_0 = 3,  // archive_header_0 = {minver, majver, options}
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   552
    AH_LENGTH_MIN = 15, // observed in spec {header_0[3], cp_counts[8], class_counts[4]}
2607
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
   553
    AH_LENGTH_0_MAX = AH_LENGTH_0 + 1,  // options might have 2 bytes
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   554
    AH_LENGTH   = 30, //maximum archive header length (w/ all fields)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    // Length contributions from optional header fields:
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   556
    AH_LENGTH_S = 2, // archive_header_S = optional {size_hi, size_lo}
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   557
    AH_ARCHIVE_SIZE_HI = 0, // offset in archive_header_S
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   558
    AH_ARCHIVE_SIZE_LO = 1, // offset in archive_header_S
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   559
    AH_FILE_HEADER_LEN = 5, // file_counts = {{size_hi, size_lo), next, modtile, files}
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   560
    AH_SPECIAL_FORMAT_LEN = 2, // special_count = {layouts, band_headers}
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   561
    AH_CP_NUMBER_LEN = 4,      // cp_number_counts = {int, float, long, double}
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   562
    AH_CP_EXTRA_LEN = 4,        // cp_attr_counts = {MH, MT, InDy, BSM}
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   563
    ARCHIVE_SIZE_MIN = AH_LENGTH_MIN - AH_LENGTH_0 - AH_LENGTH_S,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    FIRST_READ  = MAGIC_BYTES + AH_LENGTH_MIN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
  };
2607
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
   566
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
   567
  assert(AH_LENGTH_MIN    == 15); // # of UNSIGNED5 fields required after archive_magic
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
   568
  // An absolute minimum null archive is magic[4], {minver,majver,options}[3],
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
   569
  // archive_size[0], cp_counts[8], class_counts[4], for a total of 19 bytes.
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
   570
  // (Note that archive_size is optional; it may be 0..10 bytes in length.)
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
   571
  // The first read must capture everything up through the options field.
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
   572
  // This happens to work even if {minver,majver,options} is a pathological
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
   573
  // 15 bytes long.  Legal pack files limit those three fields to 1+1+2 bytes.
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
   574
  assert(FIRST_READ >= MAGIC_BYTES + AH_LENGTH_0 * B_MAX);
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
   575
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
   576
  // Up through archive_size, the largest possible archive header is
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
   577
  // magic[4], {minver,majver,options}[4], archive_size[10].
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
   578
  // (Note only the low 12 bits of options are allowed to be non-zero.)
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
   579
  // In order to parse archive_size, we need at least this many bytes
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
   580
  // in the first read.  Of course, if archive_size_hi is more than
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
   581
  // a byte, we probably will fail to allocate the buffer, since it
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
   582
  // will be many gigabytes long.  This is a practical, not an
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
   583
  // architectural limit to Pack200 archive sizes.
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
   584
  assert(FIRST_READ >= MAGIC_BYTES + AH_LENGTH_0_MAX + 2*B_MAX);
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
   585
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
  bool foreign_buf = (read_input_fn == null);
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   587
  byte initbuf[(int)FIRST_READ + (int)C_SLOP + 200];  // 200 is for JAR I/O
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
  if (foreign_buf) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    // inbytes is all there is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    input.set(inbytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    rp      = input.base();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    rplimit = input.limit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    // inbytes, if not empty, contains some read-ahead we must use first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    // ensure_input will take care of copying it into initbuf,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    // then querying read_input_fn for any additional data needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
    // However, the caller must assume that we use up all of inbytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    // There is no way to tell the caller that we used only part of them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    // Therefore, the caller must use only a bare minimum of read-ahead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    if (inbytes.len > FIRST_READ) {
2607
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
   601
      abort("too much read-ahead");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
      return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
    input.set(initbuf, sizeof(initbuf));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    input.b.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    input.b.copyFrom(inbytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    rplimit = rp = input.base();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
    rplimit += inbytes.len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    bytes_read += inbytes.len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
  }
2607
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
   611
  // Read only 19 bytes, which is certain to contain #archive_options fields,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
  // but is certain not to overflow past the archive_header.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
  input.b.len = FIRST_READ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
  if (!ensure_input(FIRST_READ))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
    abort("EOF reading archive magic number");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
  if (rp[0] == 'P' && rp[1] == 'K') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
#ifdef UNPACK_JNI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
    // Java driver must handle this case before we get this far.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
    abort("encountered a JAR header in unpacker");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    // In the Unix-style program, we simply simulate a copy command.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    // Copy until EOF; assume the JAR file is the last segment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    fprintf(errstrm, "Copy-mode.\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
    for (;;) {
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   626
      jarout->write_data(rp, (int)input_remaining());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
      if (foreign_buf)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        break;  // one-time use of a passed in buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
      if (input.size() < CHUNK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        // Get some breathing room.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        input.set(U_NEW(byte, (size_t) CHUNK + C_SLOP), (size_t) CHUNK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
      rp = rplimit = input.base();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
      if (!ensure_input(1))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    jarout->closeJarFile(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
  // Read the magic number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
  magic = 0;
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   645
  for (int i1 = 0; i1 < (int)sizeof(magic); i1++) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
    magic <<= 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    magic += (*rp++ & 0xFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
  // Read the first 3 values from the header.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
  value_stream hdr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
  int          hdrVals = 0;
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   653
  int          hdrValsSkipped = 0;  // for assert
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
  hdr.init(rp, rplimit, UNSIGNED5_spec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
  minver = hdr.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
  majver = hdr.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
  hdrVals += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
15261
c5b882836677 8005252: pack200 should support MethodParameters
ksrini
parents: 12544
diff changeset
   659
  int majmin[4][2] = {
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   660
      {JAVA5_PACKAGE_MAJOR_VERSION, JAVA5_PACKAGE_MINOR_VERSION},
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   661
      {JAVA6_PACKAGE_MAJOR_VERSION, JAVA6_PACKAGE_MINOR_VERSION},
15261
c5b882836677 8005252: pack200 should support MethodParameters
ksrini
parents: 12544
diff changeset
   662
      {JAVA7_PACKAGE_MAJOR_VERSION, JAVA7_PACKAGE_MINOR_VERSION},
c5b882836677 8005252: pack200 should support MethodParameters
ksrini
parents: 12544
diff changeset
   663
      {JAVA8_PACKAGE_MAJOR_VERSION, JAVA8_PACKAGE_MINOR_VERSION}
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   664
  };
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   665
  int majminfound = false;
15261
c5b882836677 8005252: pack200 should support MethodParameters
ksrini
parents: 12544
diff changeset
   666
  for (int i = 0 ; i < 4 ; i++) {
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   667
      if (majver == majmin[i][0] && minver == majmin[i][1]) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   668
          majminfound = true;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   669
          break;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   670
      }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   671
  }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   672
  if (majminfound == null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
    char message[200];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
    sprintf(message, "@" ERROR_FORMAT ": magic/ver = "
15261
c5b882836677 8005252: pack200 should support MethodParameters
ksrini
parents: 12544
diff changeset
   675
            "%08X/%d.%d should be %08X/%d.%d OR %08X/%d.%d OR %08X/%d.%d OR %08X/%d.%d\n",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
            magic, majver, minver,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
            JAVA_PACKAGE_MAGIC, JAVA5_PACKAGE_MAJOR_VERSION, JAVA5_PACKAGE_MINOR_VERSION,
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   678
            JAVA_PACKAGE_MAGIC, JAVA6_PACKAGE_MAJOR_VERSION, JAVA6_PACKAGE_MINOR_VERSION,
15261
c5b882836677 8005252: pack200 should support MethodParameters
ksrini
parents: 12544
diff changeset
   679
            JAVA_PACKAGE_MAGIC, JAVA7_PACKAGE_MAJOR_VERSION, JAVA7_PACKAGE_MINOR_VERSION,
c5b882836677 8005252: pack200 should support MethodParameters
ksrini
parents: 12544
diff changeset
   680
            JAVA_PACKAGE_MAGIC, JAVA8_PACKAGE_MAJOR_VERSION, JAVA8_PACKAGE_MINOR_VERSION);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
    abort(message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
  archive_options = hdr.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
  hdrVals += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
  assert(hdrVals == AH_LENGTH_0);  // first three fields only
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   688
  bool haveSizeHi = testBit(archive_options, AO_HAVE_FILE_SIZE_HI);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   689
  bool haveModTime = testBit(archive_options, AO_HAVE_FILE_MODTIME);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   690
  bool haveFileOpt = testBit(archive_options, AO_HAVE_FILE_OPTIONS);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   691
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   692
  bool haveSpecial = testBit(archive_options, AO_HAVE_SPECIAL_FORMATS);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   693
  bool haveFiles = testBit(archive_options, AO_HAVE_FILE_HEADERS);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   694
  bool haveNumbers = testBit(archive_options, AO_HAVE_CP_NUMBERS);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   695
  bool haveCPExtra = testBit(archive_options, AO_HAVE_CP_EXTRAS);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   696
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   697
  if (majver < JAVA7_PACKAGE_MAJOR_VERSION) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   698
    if (haveCPExtra) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   699
        abort("Format bits for Java 7 must be zero in previous releases");
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   700
        return;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   701
    }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   702
  }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   703
  if (testBit(archive_options, AO_UNUSED_MBZ)) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   704
    abort("High archive option bits are reserved and must be zero");
2607
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
   705
    return;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
  }
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   707
  if (haveFiles) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    uint hi = hdr.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
    uint lo = hdr.getInt();
2602
5b394a4b6ce1 6755943: Java JAR Pack200 Decompression should enforce stricter header checks
ksrini
parents: 2
diff changeset
   710
    julong x = band::makeLong(hi, lo);
5b394a4b6ce1 6755943: Java JAR Pack200 Decompression should enforce stricter header checks
ksrini
parents: 2
diff changeset
   711
    archive_size = (size_t) x;
5b394a4b6ce1 6755943: Java JAR Pack200 Decompression should enforce stricter header checks
ksrini
parents: 2
diff changeset
   712
    if (archive_size != x) {
5b394a4b6ce1 6755943: Java JAR Pack200 Decompression should enforce stricter header checks
ksrini
parents: 2
diff changeset
   713
      // Silly size specified; force overflow.
5b394a4b6ce1 6755943: Java JAR Pack200 Decompression should enforce stricter header checks
ksrini
parents: 2
diff changeset
   714
      archive_size = PSIZE_MAX+1;
5b394a4b6ce1 6755943: Java JAR Pack200 Decompression should enforce stricter header checks
ksrini
parents: 2
diff changeset
   715
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
    hdrVals += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
    hdrValsSkipped += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
  // Now we can size the whole archive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
  // Read everything else into a mega-buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
  rp = hdr.rp;
29591
51244d1ddffc 8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents: 29368
diff changeset
   724
  size_t header_size_0 = (rp - input.base()); // used-up header (4byte + 3int)
51244d1ddffc 8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents: 29368
diff changeset
   725
  size_t header_size_1 = (rplimit - rp);      // buffered unused initial fragment
51244d1ddffc 8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents: 29368
diff changeset
   726
  size_t header_size   = header_size_0 + header_size_1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
  unsized_bytes_read = header_size_0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
  if (foreign_buf) {
29591
51244d1ddffc 8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents: 29368
diff changeset
   730
    if (archive_size > header_size_1) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
      abort("EOF reading fixed input buffer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
      return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
    }
2602
5b394a4b6ce1 6755943: Java JAR Pack200 Decompression should enforce stricter header checks
ksrini
parents: 2
diff changeset
   734
  } else if (archive_size != 0) {
2607
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
   735
    if (archive_size < ARCHIVE_SIZE_MIN) {
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
   736
      abort("impossible archive size");  // bad input data
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
   737
      return;
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
   738
    }
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
   739
    if (archive_size < header_size_1) {
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
   740
      abort("too much read-ahead");  // somehow we pre-fetched too much?
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
   741
      return;
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
   742
    }
2602
5b394a4b6ce1 6755943: Java JAR Pack200 Decompression should enforce stricter header checks
ksrini
parents: 2
diff changeset
   743
    input.set(U_NEW(byte, add_size(header_size_0, archive_size, C_SLOP)),
29591
51244d1ddffc 8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents: 29368
diff changeset
   744
              header_size_0 + archive_size);
2607
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
   745
    CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
    assert(input.limit()[0] == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
    // Move all the bytes we read initially into the real buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
    input.b.copyFrom(initbuf, header_size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
    rp      = input.b.ptr + header_size_0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    rplimit = input.b.ptr + header_size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
    // It's more complicated and painful.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
    // A zero archive_size means that we must read until EOF.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
    input.init(CHUNK*2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
    CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
    input.b.len = input.allocated;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
    rp = rplimit = input.base();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
    // Set up input buffer as if we already read the header:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
    input.b.copyFrom(initbuf, header_size);
2607
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
   760
    CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
    rplimit += header_size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
    while (ensure_input(input.limit() - rp)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
      size_t dataSoFar = input_remaining();
2602
5b394a4b6ce1 6755943: Java JAR Pack200 Decompression should enforce stricter header checks
ksrini
parents: 2
diff changeset
   764
      size_t nextSize = add_size(dataSoFar, CHUNK);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
      input.ensureSize(nextSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
      CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
      input.b.len = input.allocated;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
      rp = rplimit = input.base();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
      rplimit += dataSoFar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
    size_t dataSize = (rplimit - input.base());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
    input.b.len = dataSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
    input.grow(C_SLOP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
    CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
    free_input = true;  // free it later
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
    input.b.len = dataSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
    assert(input.limit()[0] == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
    rp = rplimit = input.base();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
    rplimit += dataSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
    rp += header_size_0;  // already scanned these bytes...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
  live_input = true;    // mark as "do not reuse"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
  if (aborting()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
    abort("cannot allocate large input buffer for package file");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   788
  // read the rest of the header fields  int assertSkipped = AH_LENGTH_MIN - AH_LENGTH_0 - AH_LENGTH_S;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   789
  int remainingHeaders = AH_LENGTH_MIN - AH_LENGTH_0 - AH_LENGTH_S;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   790
  if (haveSpecial)
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   791
    remainingHeaders += AH_SPECIAL_FORMAT_LEN;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   792
  if (haveFiles)
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   793
     remainingHeaders += AH_FILE_HEADER_LEN;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   794
  if (haveNumbers)
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   795
    remainingHeaders += AH_CP_NUMBER_LEN;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   796
  if (haveCPExtra)
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   797
    remainingHeaders += AH_CP_EXTRA_LEN;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   798
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   799
  ensure_input(remainingHeaders * B_MAX);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
  hdr.rp      = rp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
  hdr.rplimit = rplimit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   804
  if (haveFiles) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
    archive_next_count = hdr.getInt();
2607
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
   806
    CHECK_COUNT(archive_next_count);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
    archive_modtime = hdr.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
    file_count = hdr.getInt();
2607
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
   809
    CHECK_COUNT(file_count);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
    hdrVals += 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
    hdrValsSkipped += 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   815
  if (haveSpecial) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
    band_headers_size = hdr.getInt();
2607
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
   817
    CHECK_COUNT(band_headers_size);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
    attr_definition_count = hdr.getInt();
2607
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
   819
    CHECK_COUNT(attr_definition_count);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
    hdrVals += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
    hdrValsSkipped += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
  int cp_counts[N_TAGS_IN_ORDER];
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   826
  for (int k = 0; k < (int)N_TAGS_IN_ORDER; k++) {
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   827
    if (!haveNumbers) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
      switch (TAGS_IN_ORDER[k]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
      case CONSTANT_Integer:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
      case CONSTANT_Float:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
      case CONSTANT_Long:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
      case CONSTANT_Double:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        cp_counts[k] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
        hdrValsSkipped += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
    }
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   838
    if (!haveCPExtra) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   839
        switch(TAGS_IN_ORDER[k]) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   840
        case CONSTANT_MethodHandle:
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   841
        case CONSTANT_MethodType:
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   842
        case CONSTANT_InvokeDynamic:
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   843
        case CONSTANT_BootstrapMethod:
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   844
          cp_counts[k] = 0;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   845
          hdrValsSkipped += 1;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   846
          continue;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   847
        }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   848
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
    cp_counts[k] = hdr.getInt();
2607
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
   850
    CHECK_COUNT(cp_counts[k]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
    hdrVals += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
  ic_count = hdr.getInt();
2607
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
   855
  CHECK_COUNT(ic_count);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
  default_class_minver = hdr.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
  default_class_majver = hdr.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
  class_count = hdr.getInt();
2607
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
   859
  CHECK_COUNT(class_count);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
  hdrVals += 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   862
  // done with archive_header, time to reconcile to ensure
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   863
  // we have read everything correctly
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
  hdrVals += hdrValsSkipped;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
  assert(hdrVals == AH_LENGTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
  rp = hdr.rp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
  if (rp > rplimit)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
    abort("EOF reading archive header");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
  // Now size the CP.
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   871
#ifndef PRODUCT
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   872
  // bool x = (N_TAGS_IN_ORDER == CONSTANT_Limit);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   873
  // assert(x);
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   874
#endif //PRODUCT
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
  cp.init(this, cp_counts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
  default_file_modtime = archive_modtime;
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   879
  if (default_file_modtime == 0 && haveModTime)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
    default_file_modtime = DEFAULT_ARCHIVE_MODTIME;  // taken from driver
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   881
  if (testBit(archive_options, AO_DEFLATE_HINT))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
    default_file_options |= FO_DEFLATE_HINT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
  // meta-bytes, if any, immediately follow archive header
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
  //band_headers.readData(band_headers_size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
  ensure_input(band_headers_size);
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   887
  if (input_remaining() < (size_t)band_headers_size) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
    abort("EOF reading band headers");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
  bytes band_headers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
  // The "1+" allows an initial byte to be pushed on the front.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
  band_headers.set(1+U_NEW(byte, 1+band_headers_size+C_SLOP),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
                   band_headers_size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
  // Start scanning band headers here:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
  band_headers.copyFrom(rp, band_headers.len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
  rp += band_headers.len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
  assert(rp <= rplimit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
  meta_rp = band_headers.ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
  // Put evil meta-codes at the end of the band headers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
  // so we are sure to throw an error if we run off the end.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
  bytes::of(band_headers.limit(), C_SLOP).clear(_meta_error);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
void unpacker::finish() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
  if (verbose >= 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
    fprintf(errstrm,
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   909
            "A total of "
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   910
            LONG_LONG_FORMAT " bytes were read in %d segment(s).\n",
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   911
            (bytes_read_before_reset+bytes_read),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
            segments_read_before_reset+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
    fprintf(errstrm,
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   914
            "A total of "
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   915
            LONG_LONG_FORMAT " file content bytes were written.\n",
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   916
            (bytes_written_before_reset+bytes_written));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
    fprintf(errstrm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
            "A total of %d files (of which %d are classes) were written to output.\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
            files_written_before_reset+files_written,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
            classes_written_before_reset+classes_written);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
  if (jarout != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
    jarout->closeJarFile(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
  if (errstrm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
    if (errstrm == stdout || errstrm == stderr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
      fflush(errstrm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
      fclose(errstrm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
    errstrm = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
    errstrm_name = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
// Cf. PackageReader.readConstantPoolCounts
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   937
void cpool::init(unpacker* u_, int counts[CONSTANT_Limit]) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
  this->u = u_;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
  // Fill-pointer for CP.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
  int next_entry = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
  // Size the constant pool:
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   944
  for (int k = 0; k < (int)N_TAGS_IN_ORDER; k++) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
    byte tag = TAGS_IN_ORDER[k];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
    int  len = counts[k];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
    tag_count[tag] = len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
    tag_base[tag] = next_entry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
    next_entry += len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
    // Detect and defend against constant pool size overflow.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
    // (Pack200 forbids the sum of CP counts to exceed 2^29-1.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
    enum {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
      CP_SIZE_LIMIT = (1<<29),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
      IMPLICIT_ENTRY_COUNT = 1  // empty Utf8 string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
    if (len >= (1<<29) || len < 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
        || next_entry >= CP_SIZE_LIMIT+IMPLICIT_ENTRY_COUNT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
      abort("archive too large:  constant pool limit exceeded");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
      return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
  // Close off the end of the CP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
  nentries = next_entry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
  // place a limit on future CP growth:
29591
51244d1ddffc 8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents: 29368
diff changeset
   967
  size_t generous = 0;
3463
054c9c1f9fd9 6830335: Java JAR Pack200 Decompression Integer Overflow Vulnerability
ksrini
parents: 2624
diff changeset
   968
  generous = add_size(generous, u->ic_count); // implicit name
054c9c1f9fd9 6830335: Java JAR Pack200 Decompression Integer Overflow Vulnerability
ksrini
parents: 2624
diff changeset
   969
  generous = add_size(generous, u->ic_count); // outer
054c9c1f9fd9 6830335: Java JAR Pack200 Decompression Integer Overflow Vulnerability
ksrini
parents: 2624
diff changeset
   970
  generous = add_size(generous, u->ic_count); // outer.utf8
054c9c1f9fd9 6830335: Java JAR Pack200 Decompression Integer Overflow Vulnerability
ksrini
parents: 2624
diff changeset
   971
  generous = add_size(generous, 40); // WKUs, misc
054c9c1f9fd9 6830335: Java JAR Pack200 Decompression Integer Overflow Vulnerability
ksrini
parents: 2624
diff changeset
   972
  generous = add_size(generous, u->class_count); // implicit SourceFile strings
29591
51244d1ddffc 8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents: 29368
diff changeset
   973
  maxentries = (uint)add_size(nentries, generous);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
  // Note that this CP does not include "empty" entries
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
  // for longs and doubles.  Those are introduced when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
  // the entries are renumbered for classfile output.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
  entries = U_NEW(entry, maxentries);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
  first_extra_entry = &entries[nentries];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
  // Initialize the standard indexes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
  for (int tag = 0; tag < CONSTANT_Limit; tag++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
    entry* cpMap = &entries[tag_base[tag]];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
    tag_index[tag].init(tag_count[tag], cpMap, tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   990
  // Initialize *all* our entries once
29591
51244d1ddffc 8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents: 29368
diff changeset
   991
  for (uint i = 0 ; i < maxentries ; i++) {
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   992
    entries[i].outputIndex = REQUESTED_NONE;
29591
51244d1ddffc 8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents: 29368
diff changeset
   993
  }
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   994
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
   995
  initGroupIndexes();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
  // Initialize hashTab to a generous power-of-two size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
  uint pow2 = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
  uint target = maxentries + maxentries/2;  // 60% full
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
  while (pow2 < target)  pow2 <<= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
  hashTab = U_NEW(entry*, hashTabLength = pow2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
static byte* store_Utf8_char(byte* cp, unsigned short ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
  if (ch >= 0x001 && ch <= 0x007F) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
    *cp++ = (byte) ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
  } else if (ch <= 0x07FF) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
    *cp++ = (byte) (0xC0 | ((ch >>  6) & 0x1F));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
    *cp++ = (byte) (0x80 | ((ch >>  0) & 0x3F));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
    *cp++ = (byte) (0xE0 | ((ch >> 12) & 0x0F));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
    *cp++ = (byte) (0x80 | ((ch >>  6) & 0x3F));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
    *cp++ = (byte) (0x80 | ((ch >>  0) & 0x3F));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
  return cp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
static byte* skip_Utf8_chars(byte* cp, int len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
  for (;; cp++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
    int ch = *cp & 0xFF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
    if ((ch & 0xC0) != 0x80) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
      if (len-- == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
        return cp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
      if (ch < 0x80 && len == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
        return cp+1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
static int compare_Utf8_chars(bytes& b1, bytes& b2) {
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  1030
  int l1 = (int)b1.len;
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  1031
  int l2 = (int)b2.len;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
  int l0 = (l1 < l2) ? l1 : l2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
  byte* p1 = b1.ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
  byte* p2 = b2.ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
  int c0 = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
  for (int i = 0; i < l0; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
    int c1 = p1[i] & 0xFF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
    int c2 = p2[i] & 0xFF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
    if (c1 != c2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
      // Before returning the obvious answer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
      // check to see if c1 or c2 is part of a 0x0000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
      // which encodes as {0xC0,0x80}.  The 0x0000 is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
      // lowest-sorting Java char value, and yet it encodes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
      // as if it were the first char after 0x7F, which causes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
      // strings containing nulls to sort too high.  All other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
      // comparisons are consistent between Utf8 and Java chars.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
      if (c1 == 0xC0 && (p1[i+1] & 0xFF) == 0x80)  c1 = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
      if (c2 == 0xC0 && (p2[i+1] & 0xFF) == 0x80)  c2 = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
      if (c0 == 0xC0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
        assert(((c1|c2) & 0xC0) == 0x80);  // c1 & c2 are extension chars
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
        if (c1 == 0x80)  c1 = 0;  // will sort below c2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
        if (c2 == 0x80)  c2 = 0;  // will sort below c1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
      return c1 - c2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
    c0 = c1;  // save away previous char
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
  // common prefix is identical; return length difference if any
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
  return l1 - l2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
// Cf. PackageReader.readUtf8Bands
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
local_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
void unpacker::read_Utf8_values(entry* cpMap, int len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
  // Implicit first Utf8 string is the empty string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
  enum {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
    // certain bands begin with implicit zeroes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
    PREFIX_SKIP_2 = 2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
    SUFFIX_SKIP_1 = 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
  };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
  int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
  // First band:  Read lengths of shared prefixes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
  if (len > PREFIX_SKIP_2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
    cp_Utf8_prefix.readData(len - PREFIX_SKIP_2);
2602
5b394a4b6ce1 6755943: Java JAR Pack200 Decompression should enforce stricter header checks
ksrini
parents: 2
diff changeset
  1077
    NOT_PRODUCT(else cp_Utf8_prefix.readData(0));  // for asserts
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
  // Second band:  Read lengths of unshared suffixes:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
  if (len > SUFFIX_SKIP_1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
    cp_Utf8_suffix.readData(len - SUFFIX_SKIP_1);
2602
5b394a4b6ce1 6755943: Java JAR Pack200 Decompression should enforce stricter header checks
ksrini
parents: 2
diff changeset
  1082
    NOT_PRODUCT(else cp_Utf8_suffix.readData(0));  // for asserts
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
  bytes* allsuffixes = T_NEW(bytes, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
  int nbigsuf = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
  fillbytes charbuf;    // buffer to allocate small strings
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
  charbuf.init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
  // Third band:  Read the char values in the unshared suffixes:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
  cp_Utf8_chars.readData(cp_Utf8_suffix.getIntTotal());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
  for (i = 0; i < len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
    int suffix = (i < SUFFIX_SKIP_1)? 0: cp_Utf8_suffix.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
    if (suffix < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
      abort("bad utf8 suffix");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
      return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
    if (suffix == 0 && i >= SUFFIX_SKIP_1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
      // chars are packed in cp_Utf8_big_chars
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
      nbigsuf += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
      continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
    bytes& chars  = allsuffixes[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
    uint size3    = suffix * 3;     // max Utf8 length
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
    bool isMalloc = (suffix > SMALL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
    if (isMalloc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
      chars.malloc(size3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
      if (!charbuf.canAppend(size3+1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
        assert(charbuf.allocated == 0 || tmallocs.contains(charbuf.base()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
        charbuf.init(CHUNK);  // Reset to new buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
        tmallocs.add(charbuf.base());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
      chars.set(charbuf.grow(size3+1), size3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
    CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
    byte* chp = chars.ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
    for (int j = 0; j < suffix; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
      unsigned short ch = cp_Utf8_chars.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
      chp = store_Utf8_char(chp, ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
    // shrink to fit:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
    if (isMalloc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
      chars.realloc(chp - chars.ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
      CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
      tmallocs.add(chars.ptr); // free it later
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
    } else {
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  1129
      int shrink = (int)(chars.limit() - chp);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
      chars.len -= shrink;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
      charbuf.b.len -= shrink;  // ungrow to reclaim buffer space
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
      // Note that we did not reclaim the final '\0'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
      assert(chars.limit() == charbuf.limit()-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
      assert(strlen((char*)chars.ptr) == chars.len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
  //cp_Utf8_chars.done();
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  1138
#ifndef PRODUCT
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  1139
  charbuf.b.set(null, 0); // tidy
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  1140
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
  // Fourth band:  Go back and size the specially packed strings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
  int maxlen = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
  cp_Utf8_big_suffix.readData(nbigsuf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
  cp_Utf8_suffix.rewind();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
  for (i = 0; i < len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
    int suffix = (i < SUFFIX_SKIP_1)? 0: cp_Utf8_suffix.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
    int prefix = (i < PREFIX_SKIP_2)? 0: cp_Utf8_prefix.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
    if (prefix < 0 || prefix+suffix < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
       abort("bad utf8 prefix");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
       return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
    bytes& chars = allsuffixes[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
    if (suffix == 0 && i >= SUFFIX_SKIP_1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
      suffix = cp_Utf8_big_suffix.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
      assert(chars.ptr == null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
      chars.len = suffix;  // just a momentary hack
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
      assert(chars.ptr != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
    if (maxlen < prefix + suffix) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
      maxlen = prefix + suffix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
  //cp_Utf8_suffix.done();      // will use allsuffixes[i].len (ptr!=null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
  //cp_Utf8_big_suffix.done();  // will use allsuffixes[i].len
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
  // Fifth band(s):  Get the specially packed characters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
  cp_Utf8_big_suffix.rewind();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
  for (i = 0; i < len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
    bytes& chars = allsuffixes[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
    if (chars.ptr != null)  continue;  // already input
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  1173
    int suffix = (int)chars.len;  // pick up the hack
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
    uint size3 = suffix * 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
    if (suffix == 0)  continue;  // done with empty string
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
    chars.malloc(size3);
10907
ea32ea5b72d7 7057857: SIGSEGV [libunpack.so] store_Utf8_char(signed char*, unsigned short) in java.util.jar.pack200
ksrini
parents: 9035
diff changeset
  1177
    CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
    byte* chp = chars.ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
    band saved_band = cp_Utf8_big_chars;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
    cp_Utf8_big_chars.readData(suffix);
10907
ea32ea5b72d7 7057857: SIGSEGV [libunpack.so] store_Utf8_char(signed char*, unsigned short) in java.util.jar.pack200
ksrini
parents: 9035
diff changeset
  1181
    CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
    for (int j = 0; j < suffix; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
      unsigned short ch = cp_Utf8_big_chars.getInt();
10907
ea32ea5b72d7 7057857: SIGSEGV [libunpack.so] store_Utf8_char(signed char*, unsigned short) in java.util.jar.pack200
ksrini
parents: 9035
diff changeset
  1184
      CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
      chp = store_Utf8_char(chp, ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
    chars.realloc(chp - chars.ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
    CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
    tmallocs.add(chars.ptr);  // free it later
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
    //cp_Utf8_big_chars.done();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
    cp_Utf8_big_chars = saved_band;  // reset the band for the next string
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
  cp_Utf8_big_chars.readData(0);  // zero chars
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
  //cp_Utf8_big_chars.done();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
  // Finally, sew together all the prefixes and suffixes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
  bytes bigbuf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
  bigbuf.malloc(maxlen * 3 + 1);  // max Utf8 length, plus slop for null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
  int prevlen = 0;  // previous string length (in chars)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
  tmallocs.add(bigbuf.ptr);  // free after this block
10907
ea32ea5b72d7 7057857: SIGSEGV [libunpack.so] store_Utf8_char(signed char*, unsigned short) in java.util.jar.pack200
ksrini
parents: 9035
diff changeset
  1202
  CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
  cp_Utf8_prefix.rewind();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
  for (i = 0; i < len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
    bytes& chars = allsuffixes[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
    int prefix = (i < PREFIX_SKIP_2)? 0: cp_Utf8_prefix.getInt();
10907
ea32ea5b72d7 7057857: SIGSEGV [libunpack.so] store_Utf8_char(signed char*, unsigned short) in java.util.jar.pack200
ksrini
parents: 9035
diff changeset
  1207
    CHECK;
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  1208
    int suffix = (int)chars.len;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
    byte* fillp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
    // by induction, the buffer is already filled with the prefix
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
    // make sure the prefix value is not corrupted, though:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
    if (prefix > prevlen) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
       abort("utf8 prefix overflow");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
       return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
    fillp = skip_Utf8_chars(bigbuf.ptr, prefix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
    // copy the suffix into the same buffer:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
    fillp = chars.writeTo(fillp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
    assert(bigbuf.inBounds(fillp));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
    *fillp = 0;  // bigbuf must contain a well-formed Utf8 string
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  1221
    int length = (int)(fillp - bigbuf.ptr);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
    bytes& value = cpMap[i].value.b;
5191
79b41f733e33 6902299: Java JAR "unpack200" must verify input parameters
ksrini
parents: 3463
diff changeset
  1223
    value.set(U_NEW(byte, add_size(length,1)), length);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
    value.copyFrom(bigbuf.ptr, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
    CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
    // Index all Utf8 strings
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
    entry* &htref = cp.hashTabRef(CONSTANT_Utf8, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
    if (htref == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
      // Note that if two identical strings are transmitted,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
      // the first is taken to be the canonical one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
      htref = &cpMap[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
    prevlen = prefix + suffix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
  //cp_Utf8_prefix.done();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
  // Free intermediate buffers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
  free_temps();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
local_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
void unpacker::read_single_words(band& cp_band, entry* cpMap, int len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
  cp_band.readData(len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
  for (int i = 0; i < len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
    cpMap[i].value.i = cp_band.getInt();  // coding handles signs OK
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
void unpacker::read_double_words(band& cp_bands, entry* cpMap, int len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
  band& cp_band_hi = cp_bands;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
  band& cp_band_lo = cp_bands.nextBand();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
  cp_band_hi.readData(len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
  cp_band_lo.readData(len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
  for (int i = 0; i < len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
    cpMap[i].value.l = cp_band_hi.getLong(cp_band_lo, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
  //cp_band_hi.done();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
  //cp_band_lo.done();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
void unpacker::read_single_refs(band& cp_band, byte refTag, entry* cpMap, int len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
  assert(refTag == CONSTANT_Utf8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
  cp_band.setIndexByTag(refTag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
  cp_band.readData(len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
  int indexTag = (cp_band.bn == e_cp_Class) ? CONSTANT_Class : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
  for (int i = 0; i < len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
    entry& e = cpMap[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
    e.refs = U_NEW(entry*, e.nrefs = 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
    entry* utf = cp_band.getRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
    CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
    e.refs[0] = utf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
    e.value.b = utf->value.b;  // copy value of Utf8 string to self
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
    if (indexTag != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
      // Maintain cross-reference:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
      entry* &htref = cp.hashTabRef(indexTag, e.value.b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
      if (htref == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
        // Note that if two identical classes are transmitted,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
        // the first is taken to be the canonical one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
        htref = &e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
  //cp_band.done();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
void unpacker::read_double_refs(band& cp_band, byte ref1Tag, byte ref2Tag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
                                entry* cpMap, int len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
  band& cp_band1 = cp_band;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
  band& cp_band2 = cp_band.nextBand();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
  cp_band1.setIndexByTag(ref1Tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
  cp_band2.setIndexByTag(ref2Tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
  cp_band1.readData(len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
  cp_band2.readData(len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
  for (int i = 0; i < len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
    entry& e = cpMap[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
    e.refs = U_NEW(entry*, e.nrefs = 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
    e.refs[0] = cp_band1.getRef();
16075
32c3bc19bba7 7186957: Improve Pack200 data validation
ksrini
parents: 12544
diff changeset
  1303
    CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
    e.refs[1] = cp_band2.getRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
    CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
  //cp_band1.done();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
  //cp_band2.done();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
// Cf. PackageReader.readSignatureBands
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
void unpacker::read_signature_values(entry* cpMap, int len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
  cp_Signature_form.setIndexByTag(CONSTANT_Utf8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
  cp_Signature_form.readData(len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
  int ncTotal = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
  int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
  for (i = 0; i < len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
    entry& e = cpMap[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
    entry& form = *cp_Signature_form.getRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
    CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
    int nc = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
41573
3771d7eaab2c 8160090: Better signature handling in pack200
ksrini
parents: 41572
diff changeset
  1325
    for (int j = 0; j < (int)form.value.b.len; j++) {
3771d7eaab2c 8160090: Better signature handling in pack200
ksrini
parents: 41572
diff changeset
  1326
      int c = form.value.b.ptr[j];
3771d7eaab2c 8160090: Better signature handling in pack200
ksrini
parents: 41572
diff changeset
  1327
      if (c == 'L') nc++;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
    ncTotal += nc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
    e.refs = U_NEW(entry*, cpMap[i].nrefs = 1 + nc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
    CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
    e.refs[0] = &form;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
  //cp_Signature_form.done();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
  cp_Signature_classes.setIndexByTag(CONSTANT_Class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
  cp_Signature_classes.readData(ncTotal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
  for (i = 0; i < len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
    entry& e = cpMap[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
    for (int j = 1; j < e.nrefs; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
      e.refs[j] = cp_Signature_classes.getRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
      CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
  //cp_Signature_classes.done();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1347
maybe_inline
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1348
void unpacker::checkLegacy(const char* name) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1349
  if (u->majver < JAVA7_PACKAGE_MAJOR_VERSION) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1350
      char message[100];
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1351
      snprintf(message, 99, "unexpected band %s\n", name);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1352
      abort(message);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1353
  }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1354
}
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1355
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1356
maybe_inline
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1357
void unpacker::read_method_handle(entry* cpMap, int len) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1358
  if (len > 0) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1359
    checkLegacy(cp_MethodHandle_refkind.name);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1360
  }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1361
  cp_MethodHandle_refkind.readData(len);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1362
  cp_MethodHandle_member.setIndexByTag(CONSTANT_AnyMember);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1363
  cp_MethodHandle_member.readData(len);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1364
  for (int i = 0 ; i < len ; i++) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1365
    entry& e = cpMap[i];
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1366
    e.value.i = cp_MethodHandle_refkind.getInt();
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1367
    e.refs = U_NEW(entry*, e.nrefs = 1);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1368
    e.refs[0] = cp_MethodHandle_member.getRef();
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1369
    CHECK;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1370
  }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1371
}
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1372
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1373
maybe_inline
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1374
void unpacker::read_method_type(entry* cpMap, int len) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1375
  if (len > 0) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1376
    checkLegacy(cp_MethodType.name);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1377
  }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1378
  cp_MethodType.setIndexByTag(CONSTANT_Signature);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1379
  cp_MethodType.readData(len);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1380
  for (int i = 0 ; i < len ; i++) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1381
      entry& e = cpMap[i];
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1382
      e.refs = U_NEW(entry*, e.nrefs = 1);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1383
      e.refs[0] = cp_MethodType.getRef();
16075
32c3bc19bba7 7186957: Improve Pack200 data validation
ksrini
parents: 12544
diff changeset
  1384
      CHECK;
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1385
  }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1386
}
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1387
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1388
maybe_inline
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1389
void unpacker::read_bootstrap_methods(entry* cpMap, int len) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1390
  if (len > 0) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1391
    checkLegacy(cp_BootstrapMethod_ref.name);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1392
  }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1393
  cp_BootstrapMethod_ref.setIndexByTag(CONSTANT_MethodHandle);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1394
  cp_BootstrapMethod_ref.readData(len);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1395
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1396
  cp_BootstrapMethod_arg_count.readData(len);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1397
  int totalArgCount = cp_BootstrapMethod_arg_count.getIntTotal();
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1398
  cp_BootstrapMethod_arg.setIndexByTag(CONSTANT_LoadableValue);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1399
  cp_BootstrapMethod_arg.readData(totalArgCount);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1400
  for (int i = 0; i < len; i++) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1401
    entry& e = cpMap[i];
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1402
    int argc = cp_BootstrapMethod_arg_count.getInt();
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1403
    e.value.i = argc;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1404
    e.refs = U_NEW(entry*, e.nrefs = argc + 1);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1405
    e.refs[0] = cp_BootstrapMethod_ref.getRef();
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1406
    for (int j = 1 ; j < e.nrefs ; j++) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1407
      e.refs[j] = cp_BootstrapMethod_arg.getRef();
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1408
      CHECK;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1409
    }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1410
  }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1411
}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
// Cf. PackageReader.readConstantPool
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
void unpacker::read_cp() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
  byte* rp0 = rp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
  int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  1418
  for (int k = 0; k < (int)N_TAGS_IN_ORDER; k++) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
    byte tag = TAGS_IN_ORDER[k];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
    int  len = cp.tag_count[tag];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
    int base = cp.tag_base[tag];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  1423
    PRINTCR((1,"Reading %d %s entries...", len, NOT_PRODUCT(TAG_NAME[tag])+0));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
    entry* cpMap = &cp.entries[base];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
    for (i = 0; i < len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
      cpMap[i].tag = tag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
      cpMap[i].inord = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
    }
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1429
    // Initialize the tag's CP index right away, since it might be needed
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1430
    // in the next pass to initialize the CP for another tag.
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1431
#ifndef PRODUCT
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1432
    cpindex* ix = &cp.tag_index[tag];
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1433
    assert(ix->ixTag == tag);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1434
    assert((int)ix->len   == len);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1435
    assert(ix->base1 == cpMap);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1436
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
    switch (tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
    case CONSTANT_Utf8:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
      read_Utf8_values(cpMap, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
    case CONSTANT_Integer:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
      read_single_words(cp_Int, cpMap, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
    case CONSTANT_Float:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
      read_single_words(cp_Float, cpMap, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
    case CONSTANT_Long:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
      read_double_words(cp_Long_hi /*& cp_Long_lo*/, cpMap, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
    case CONSTANT_Double:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
      read_double_words(cp_Double_hi /*& cp_Double_lo*/, cpMap, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
    case CONSTANT_String:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
      read_single_refs(cp_String, CONSTANT_Utf8, cpMap, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
    case CONSTANT_Class:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
      read_single_refs(cp_Class, CONSTANT_Utf8, cpMap, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
    case CONSTANT_Signature:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
      read_signature_values(cpMap, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
    case CONSTANT_NameandType:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
      read_double_refs(cp_Descr_name /*& cp_Descr_type*/,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
                       CONSTANT_Utf8, CONSTANT_Signature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
                       cpMap, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
    case CONSTANT_Fieldref:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
      read_double_refs(cp_Field_class /*& cp_Field_desc*/,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
                       CONSTANT_Class, CONSTANT_NameandType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
                       cpMap, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
    case CONSTANT_Methodref:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
      read_double_refs(cp_Method_class /*& cp_Method_desc*/,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
                       CONSTANT_Class, CONSTANT_NameandType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
                       cpMap, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
    case CONSTANT_InterfaceMethodref:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
      read_double_refs(cp_Imethod_class /*& cp_Imethod_desc*/,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
                       CONSTANT_Class, CONSTANT_NameandType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
                       cpMap, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
      break;
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1483
    case CONSTANT_MethodHandle:
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1484
      // consumes cp_MethodHandle_refkind and cp_MethodHandle_member
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1485
      read_method_handle(cpMap, len);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1486
      break;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1487
    case CONSTANT_MethodType:
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1488
      // consumes cp_MethodType
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1489
      read_method_type(cpMap, len);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1490
      break;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1491
    case CONSTANT_InvokeDynamic:
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1492
      read_double_refs(cp_InvokeDynamic_spec, CONSTANT_BootstrapMethod,
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1493
                       CONSTANT_NameandType,
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1494
                       cpMap, len);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1495
      break;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1496
    case CONSTANT_BootstrapMethod:
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1497
      // consumes cp_BootstrapMethod_ref, cp_BootstrapMethod_arg_count and cp_BootstrapMethod_arg
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1498
      read_bootstrap_methods(cpMap, len);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1499
      break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
    default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
      assert(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
    CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
  cp.expandSignatures();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
  cp.initMemberIndexes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  1512
  PRINTCR((1,"parsed %d constant pool entries in %d bytes", cp.nentries, (rp - rp0)));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
  #define SNAME(n,s) #s "\0"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
  const char* symNames = (
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
    ALL_ATTR_DO(SNAME)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
    "<init>"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
  );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
  #undef SNAME
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
  for (int sn = 0; sn < cpool::s_LIMIT; sn++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
    assert(symNames[0] >= '0' && symNames[0] <= 'Z');  // sanity
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
    bytes name; name.set(symNames);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
    if (name.len > 0 && name.ptr[0] != '0') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
      cp.sym[sn] = cp.ensureUtf8(name);
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  1526
      PRINTCR((4, "well-known sym %d=%s", sn, cp.sym[sn]->string()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
    symNames += name.len + 1;  // skip trailing null to next name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
  band::initIndexes(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
static band* no_bands[] = { null };  // shared empty body
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
band& unpacker::attr_definitions::fixed_band(int e_class_xxx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
  return u->all_bands[xxx_flags_hi_bn + (e_class_xxx-e_class_flags_hi)];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
inline band& unpacker::attr_definitions::xxx_flags_hi()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
  { return fixed_band(e_class_flags_hi); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
inline band& unpacker::attr_definitions::xxx_flags_lo()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
  { return fixed_band(e_class_flags_lo); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
inline band& unpacker::attr_definitions::xxx_attr_count()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
  { return fixed_band(e_class_attr_count); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
inline band& unpacker::attr_definitions::xxx_attr_indexes()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
  { return fixed_band(e_class_attr_indexes); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
inline band& unpacker::attr_definitions::xxx_attr_calls()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
  { return fixed_band(e_class_attr_calls); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
unpacker::layout_definition*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
unpacker::attr_definitions::defineLayout(int idx,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
                                         entry* nameEntry,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
                                         const char* layout) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
  const char* name = nameEntry->value.b.strval();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
  layout_definition* lo = defineLayout(idx, name, layout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
  CHECK_0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
  lo->nameEntry = nameEntry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
  return lo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
unpacker::layout_definition*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
unpacker::attr_definitions::defineLayout(int idx,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
                                         const char* name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
                                         const char* layout) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
  assert(flag_limit != 0);  // must be set up already
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
  if (idx >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
    // Fixed attr.
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  1571
    if (idx >= (int)flag_limit)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
      abort("attribute index too large");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
    if (isRedefined(idx))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
      abort("redefined attribute index");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
    redef |= ((julong)1<<idx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
    idx = flag_limit + overflow_count.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
    overflow_count.add(0);  // make a new counter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
  layout_definition* lo = U_NEW(layout_definition, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
  CHECK_0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
  lo->idx = idx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
  lo->name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
  lo->layout = layout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
  for (int adds = (idx+1) - layouts.length(); adds > 0; adds--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
    layouts.add(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
  CHECK_0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
  layouts.get(idx) = lo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
  return lo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
band**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
unpacker::attr_definitions::buildBands(unpacker::layout_definition* lo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
  int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
  if (lo->elems != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
    return lo->bands();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
  if (lo->layout[0] == '\0') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
    lo->elems = no_bands;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
    // Create bands for this attribute by parsing the layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
    bool hasCallables = lo->hasCallables();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
    bands_made = 0x10000;  // base number for bands made
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
    const char* lp = lo->layout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
    lp = parseLayout(lp, lo->elems, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
    CHECK_0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
    if (lp[0] != '\0' || band_stack.length() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
      abort("garbage at end of layout");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
    band_stack.popTo(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
    CHECK_0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
    // Fix up callables to point at their callees.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
    band** bands = lo->elems;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
    assert(bands == lo->bands());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
    int num_callables = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
    if (hasCallables) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
      while (bands[num_callables] != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
        if (bands[num_callables]->le_kind != EK_CBLE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
          abort("garbage mixed with callables");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
          break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
        num_callables += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
    for (i = 0; i < calls_to_link.length(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
      band& call = *(band*) calls_to_link.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
      assert(call.le_kind == EK_CALL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
      // Determine the callee.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
      int call_num = call.le_len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
      if (call_num < 0 || call_num >= num_callables) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
        abort("bad call in layout");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
      band& cble = *bands[call_num];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
      // Link the call to it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
      call.le_body[0] = &cble;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
      // Distinguish backward calls and callables:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
      assert(cble.le_kind == EK_CBLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
      assert(cble.le_len == call_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
      cble.le_back |= call.le_back;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
    calls_to_link.popTo(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
  return lo->elems;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
/* attribute layout language parser
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
  attribute_layout:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
        ( layout_element )* | ( callable )+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
  layout_element:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
        ( integral | replication | union | call | reference )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
  callable:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
        '[' body ']'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
  body:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
        ( layout_element )+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
  integral:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
        ( unsigned_int | signed_int | bc_index | bc_offset | flag )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
  unsigned_int:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
        uint_type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
  signed_int:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
        'S' uint_type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
  any_int:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
        ( unsigned_int | signed_int )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
  bc_index:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
        ( 'P' uint_type | 'PO' uint_type )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
  bc_offset:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
        'O' any_int
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
  flag:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
        'F' uint_type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
  uint_type:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
        ( 'B' | 'H' | 'I' | 'V' )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
  replication:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
        'N' uint_type '[' body ']'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
  union:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
        'T' any_int (union_case)* '(' ')' '[' (body)? ']'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
  union_case:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
        '(' union_case_tag (',' union_case_tag)* ')' '[' (body)? ']'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
  union_case_tag:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
        ( numeral | numeral '-' numeral )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
  call:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
        '(' numeral ')'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
  reference:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
        reference_type ( 'N' )? uint_type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
  reference_type:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
        ( constant_ref | schema_ref | utf8_ref | untyped_ref )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
  constant_ref:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
        ( 'KI' | 'KJ' | 'KF' | 'KD' | 'KS' | 'KQ' )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
  schema_ref:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
        ( 'RC' | 'RS' | 'RD' | 'RF' | 'RM' | 'RI' )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
  utf8_ref:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
        'RU'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
  untyped_ref:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
        'RQ'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
  numeral:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
        '(' ('-')? (digit)+ ')'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
  digit:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
        ( '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
const char*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
unpacker::attr_definitions::parseIntLayout(const char* lp, band* &res,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
                                           byte le_kind, bool can_be_signed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
  const char* lp0 = lp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
  band* b = U_NEW(band, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
  CHECK_(lp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
  char le = *lp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
  int spec = UNSIGNED5_spec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
  if (le == 'S' && can_be_signed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
    // Note:  This is the last use of sign.  There is no 'EF_SIGN'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
    spec = SIGNED5_spec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
    le = *lp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
  } else if (le == 'B') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
    spec = BYTE1_spec;  // unsigned byte
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
  b->init(u, bands_made++, spec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
  b->le_kind = le_kind;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
  int le_len = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
  switch (le) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
  case 'B': le_len = 1; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
  case 'H': le_len = 2; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
  case 'I': le_len = 4; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
  case 'V': le_len = 0; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
  default:  abort("bad layout element");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
  b->le_len = le_len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
  band_stack.add(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
  res = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
  return lp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
const char*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
unpacker::attr_definitions::parseNumeral(const char* lp, int &res) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
  const char* lp0 = lp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
  bool sgn = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
  if (*lp == '0') { res = 0; return lp+1; }  // special case '0'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
  if (*lp == '-') { sgn = true; lp++; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
  const char* dp = lp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
  int con = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
  while (*dp >= '0' && *dp <= '9') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
    int con0 = con;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
    con *= 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
    con += (*dp++) - '0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
    if (con <= con0) { con = -1; break; }  //  numeral overflow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
  if (lp == dp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
    abort("missing numeral in layout");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
    return "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
  lp = dp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
  if (con < 0 && !(sgn && con == -con)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
    // (Portability note:  Misses the error if int is not 32 bits.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
    abort("numeral overflow");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
    return "" ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
  if (sgn)  con = -con;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
  res = con;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
  return lp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
band**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
unpacker::attr_definitions::popBody(int bs_base) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
  // Return everything that was pushed, as a null-terminated pointer array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
  int bs_limit = band_stack.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
  if (bs_base == bs_limit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
    return no_bands;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
    int nb = bs_limit - bs_base;
5191
79b41f733e33 6902299: Java JAR "unpack200" must verify input parameters
ksrini
parents: 3463
diff changeset
  1777
    band** res = U_NEW(band*, add_size(nb, 1));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
    CHECK_(no_bands);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
    for (int i = 0; i < nb; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
      band* b = (band*) band_stack.get(bs_base + i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
      res[i] = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
    band_stack.popTo(bs_base);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
    return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
const char*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
unpacker::attr_definitions::parseLayout(const char* lp, band** &res,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
                                        int curCble) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
  const char* lp0 = lp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
  int bs_base = band_stack.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
  bool top_level = (bs_base == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
  band* b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
  enum { can_be_signed = true };  // optional arg to parseIntLayout
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
  for (bool done = false; !done; ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
    switch (*lp++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
    case 'B': case 'H': case 'I': case 'V': // unsigned_int
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
    case 'S': // signed_int
17490
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  1801
      --lp; // reparse
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
    case 'F':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
      lp = parseIntLayout(lp, b, EK_INT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
    case 'P':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
        int le_bci = EK_BCI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
        if (*lp == 'O') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
          ++lp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
          le_bci = EK_BCID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
        assert(*lp != 'S');  // no PSH, etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
        lp = parseIntLayout(lp, b, EK_INT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
        b->le_bci = le_bci;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
        if (le_bci == EK_BCI)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
          b->defc = coding::findBySpec(BCI5_spec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
          b->defc = coding::findBySpec(BRANCH5_spec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
    case 'O':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
      lp = parseIntLayout(lp, b, EK_INT, can_be_signed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
      b->le_bci = EK_BCO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
      b->defc = coding::findBySpec(BRANCH5_spec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
    case 'N': // replication: 'N' uint '[' elem ... ']'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
      lp = parseIntLayout(lp, b, EK_REPL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
      assert(*lp == '[');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
      ++lp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
      lp = parseLayout(lp, b->le_body, curCble);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
      CHECK_(lp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
    case 'T': // union: 'T' any_int union_case* '(' ')' '[' body ']'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
      lp = parseIntLayout(lp, b, EK_UN, can_be_signed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
        int union_base = band_stack.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
        for (;;) {   // for each case
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
          band& k_case = *U_NEW(band, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
          CHECK_(lp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
          band_stack.add(&k_case);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
          k_case.le_kind = EK_CASE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
          k_case.bn = bands_made++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
          if (*lp++ != '(') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
            abort("bad union case");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
            return "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
          if (*lp++ != ')') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
            --lp;  // reparse
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
            // Read some case values.  (Use band_stack for temp. storage.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
            int case_base = band_stack.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
            for (;;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
              int caseval = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
              lp = parseNumeral(lp, caseval);
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  1854
              band_stack.add((void*)(size_t)caseval);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
              if (*lp == '-') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
                // new in version 160, allow (1-5) for (1,2,3,4,5)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
                if (u->majver < JAVA6_PACKAGE_MAJOR_VERSION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
                  abort("bad range in union case label (old archive format)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
                  return "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
                int caselimit = caseval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
                lp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
                lp = parseNumeral(lp, caselimit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
                if (caseval >= caselimit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
                    || (uint)(caselimit - caseval) > 0x10000) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
                  // Note:  0x10000 is arbitrary implementation restriction.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
                  // We can remove it later if it's important to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
                  abort("bad range in union case label");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
                  return "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
                for (;;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
                  ++caseval;
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  1873
                  band_stack.add((void*)(size_t)caseval);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
                  if (caseval == caselimit)  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
              if (*lp != ',')  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
              lp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
            if (*lp++ != ')') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
              abort("bad case label");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
              return "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
            // save away the case labels
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
            int ntags = band_stack.length() - case_base;
5191
79b41f733e33 6902299: Java JAR "unpack200" must verify input parameters
ksrini
parents: 3463
diff changeset
  1886
            int* tags = U_NEW(int, add_size(ntags, 1));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
            CHECK_(lp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
            k_case.le_casetags = tags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
            *tags++ = ntags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
            for (int i = 0; i < ntags; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
              *tags++ = ptrlowbits(band_stack.get(case_base+i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
            band_stack.popTo(case_base);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
            CHECK_(lp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
          // Got le_casetags.  Now grab the body.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
          assert(*lp == '[');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
          ++lp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
          lp = parseLayout(lp, k_case.le_body, curCble);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
          CHECK_(lp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
          if (k_case.le_casetags == null)  break;  // done
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
        b->le_body = popBody(union_base);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
    case '(': // call: '(' -?NN* ')'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
        band& call = *U_NEW(band, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
        CHECK_(lp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
        band_stack.add(&call);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
        call.le_kind = EK_CALL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
        call.bn = bands_made++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
        call.le_body = U_NEW(band*, 2); // fill in later
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
        int call_num = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
        lp = parseNumeral(lp, call_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
        call.le_back = (call_num <= 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
        call_num += curCble;  // numeral is self-relative offset
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
        call.le_len = call_num;  //use le_len as scratch
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
        calls_to_link.add(&call);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
        CHECK_(lp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
        if (*lp++ != ')') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
          abort("bad call label");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
          return "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
    case 'K': // reference_type: constant_ref
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
    case 'R': // reference_type: schema_ref
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
        int ixTag = CONSTANT_None;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
        if (lp[-1] == 'K') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
          switch (*lp++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
          case 'I': ixTag = CONSTANT_Integer; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
          case 'J': ixTag = CONSTANT_Long; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
          case 'F': ixTag = CONSTANT_Float; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
          case 'D': ixTag = CONSTANT_Double; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
          case 'S': ixTag = CONSTANT_String; break;
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1938
          case 'Q': ixTag = CONSTANT_FieldSpecific; break;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1939
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1940
          // new in 1.7
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1941
          case 'M': ixTag = CONSTANT_MethodHandle; break;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1942
          case 'T': ixTag = CONSTANT_MethodType; break;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1943
          case 'L': ixTag = CONSTANT_LoadableValue; break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
          switch (*lp++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
          case 'C': ixTag = CONSTANT_Class; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
          case 'S': ixTag = CONSTANT_Signature; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
          case 'D': ixTag = CONSTANT_NameandType; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
          case 'F': ixTag = CONSTANT_Fieldref; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
          case 'M': ixTag = CONSTANT_Methodref; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
          case 'I': ixTag = CONSTANT_InterfaceMethodref; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
          case 'U': ixTag = CONSTANT_Utf8; break; //utf8_ref
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
          case 'Q': ixTag = CONSTANT_All; break; //untyped_ref
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1955
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1956
          // new in 1.7
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1957
          case 'Y': ixTag = CONSTANT_InvokeDynamic; break;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1958
          case 'B': ixTag = CONSTANT_BootstrapMethod; break;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  1959
          case 'N': ixTag = CONSTANT_AnyMember; break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
        if (ixTag == CONSTANT_None) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
          abort("bad reference layout");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
          break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
        bool nullOK = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
        if (*lp == 'N') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
          nullOK = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
          lp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
        lp = parseIntLayout(lp, b, EK_REF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
        b->defc = coding::findBySpec(UNSIGNED5_spec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
        b->initRef(ixTag, nullOK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
    case '[':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
        // [callable1][callable2]...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
        if (!top_level) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
          abort("bad nested callable");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
          break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
        curCble += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
        NOT_PRODUCT(int call_num = band_stack.length() - bs_base);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
        band& cble = *U_NEW(band, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
        CHECK_(lp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
        band_stack.add(&cble);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
        cble.le_kind = EK_CBLE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
        NOT_PRODUCT(cble.le_len = call_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
        cble.bn = bands_made++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
        lp = parseLayout(lp, cble.le_body, curCble);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
    case ']':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
      // Hit a closing brace.  This ends whatever body we were in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
      done = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
    case '\0':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
      // Hit a null.  Also ends the (top-level) body.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
      --lp;  // back up, so caller can see the null also
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
      done = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
    default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
      abort("bad layout");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
    CHECK_(lp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
  // Return the accumulated bands:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
  res = popBody(bs_base);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2012
  return lp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
void unpacker::read_attr_defs() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
  int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2018
  // Tell each AD which attrc it is and where its fixed flags are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
  attr_defs[ATTR_CONTEXT_CLASS].attrc            = ATTR_CONTEXT_CLASS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
  attr_defs[ATTR_CONTEXT_CLASS].xxx_flags_hi_bn  = e_class_flags_hi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
  attr_defs[ATTR_CONTEXT_FIELD].attrc            = ATTR_CONTEXT_FIELD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
  attr_defs[ATTR_CONTEXT_FIELD].xxx_flags_hi_bn  = e_field_flags_hi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
  attr_defs[ATTR_CONTEXT_METHOD].attrc           = ATTR_CONTEXT_METHOD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
  attr_defs[ATTR_CONTEXT_METHOD].xxx_flags_hi_bn = e_method_flags_hi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
  attr_defs[ATTR_CONTEXT_CODE].attrc             = ATTR_CONTEXT_CODE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2026
  attr_defs[ATTR_CONTEXT_CODE].xxx_flags_hi_bn   = e_code_flags_hi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2028
  // Decide whether bands for the optional high flag words are present.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
  attr_defs[ATTR_CONTEXT_CLASS]
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  2030
    .setHaveLongFlags(testBit(archive_options, AO_HAVE_CLASS_FLAGS_HI));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
  attr_defs[ATTR_CONTEXT_FIELD]
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  2032
    .setHaveLongFlags(testBit(archive_options, AO_HAVE_FIELD_FLAGS_HI));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
  attr_defs[ATTR_CONTEXT_METHOD]
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  2034
    .setHaveLongFlags(testBit(archive_options, AO_HAVE_METHOD_FLAGS_HI));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
  attr_defs[ATTR_CONTEXT_CODE]
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  2036
    .setHaveLongFlags(testBit(archive_options, AO_HAVE_CODE_FLAGS_HI));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2037
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2038
  // Set up built-in attrs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
  // (The simple ones are hard-coded.  The metadata layouts are not.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
  const char* md_layout = (
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
    // parameter annotations:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
#define MDL0 \
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2043
    "[NB[(1)]]"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
    MDL0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2045
    // annotations:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2046
#define MDL1 \
17490
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2047
    "[NH[(1)]]"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
    MDL1
17490
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2049
#define MDL2 \
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2050
    "[RSHNH[RUH(1)]]"
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2051
    MDL2
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2052
    // element_value:
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2053
#define MDL3 \
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2054
    "[TB"                        \
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2055
      "(66,67,73,83,90)[KIH]"    \
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2056
      "(68)[KDH]"                \
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2057
      "(70)[KFH]"                \
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2058
      "(74)[KJH]"                \
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2059
      "(99)[RSH]"                \
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2060
      "(101)[RSHRUH]"            \
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2061
      "(115)[RUH]"               \
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2062
      "(91)[NH[(0)]]"            \
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2063
      "(64)["                    \
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2064
        /* nested annotation: */ \
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2065
        "RSH"                    \
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2066
        "NH[RUH(0)]"             \
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2067
        "]"                      \
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2068
      "()[]"                     \
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2069
    "]"
17490
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2070
    MDL3
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
    );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
  const char* md_layout_P = md_layout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2074
  const char* md_layout_A = md_layout+strlen(MDL0);
17490
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2075
  const char* md_layout_V = md_layout+strlen(MDL0 MDL1 MDL2);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2076
  assert(0 == strncmp(&md_layout_A[-3], ")]][", 4));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2077
  assert(0 == strncmp(&md_layout_V[-3], ")]][", 4));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
17490
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2079
const char* type_md_layout(
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2080
    "[NH[(1)(2)(3)]]"
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2081
    // target-type + target_info
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2082
    "[TB"
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2083
       "(0,1)[B]"
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2084
       "(16)[FH]"
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2085
       "(17,18)[BB]"
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2086
       "(19,20,21)[]"
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2087
       "(22)[B]"
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2088
       "(23)[H]"
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2089
       "(64,65)[NH[PHOHH]]"
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2090
       "(66)[H]"
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2091
       "(67,68,69,70)[PH]"
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2092
       "(71,72,73,74,75)[PHB]"
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2093
       "()[]]"
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2094
    // target-path
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2095
    "[NB[BB]]"
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2096
    // annotation + element_value
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2097
    MDL2
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2098
    MDL3
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2099
);
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2100
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2101
  for (i = 0; i < ATTR_CONTEXT_LIMIT; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2102
    attr_definitions& ad = attr_defs[i];
17490
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2103
    if (i != ATTR_CONTEXT_CODE) {
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2104
      ad.defineLayout(X_ATTR_RuntimeVisibleAnnotations,
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2105
                      "RuntimeVisibleAnnotations", md_layout_A);
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2106
      ad.defineLayout(X_ATTR_RuntimeInvisibleAnnotations,
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2107
                      "RuntimeInvisibleAnnotations", md_layout_A);
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2108
      if (i == ATTR_CONTEXT_METHOD) {
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2109
        ad.defineLayout(METHOD_ATTR_RuntimeVisibleParameterAnnotations,
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2110
                        "RuntimeVisibleParameterAnnotations", md_layout_P);
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2111
        ad.defineLayout(METHOD_ATTR_RuntimeInvisibleParameterAnnotations,
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2112
                        "RuntimeInvisibleParameterAnnotations", md_layout_P);
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2113
        ad.defineLayout(METHOD_ATTR_AnnotationDefault,
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2114
                        "AnnotationDefault", md_layout_V);
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2115
      }
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2116
    }
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2117
    ad.defineLayout(X_ATTR_RuntimeVisibleTypeAnnotations,
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2118
                    "RuntimeVisibleTypeAnnotations", type_md_layout);
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2119
    ad.defineLayout(X_ATTR_RuntimeInvisibleTypeAnnotations,
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2120
                    "RuntimeInvisibleTypeAnnotations", type_md_layout);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2121
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2122
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2123
  attr_definition_headers.readData(attr_definition_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
  attr_definition_name.readData(attr_definition_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2125
  attr_definition_layout.readData(attr_definition_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2126
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2127
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2128
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2129
  // Initialize correct predef bits, to distinguish predefs from new defs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2130
#define ORBIT(n,s) |((julong)1<<n)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2131
  attr_defs[ATTR_CONTEXT_CLASS].predef
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2132
    = (0 X_ATTR_DO(ORBIT) CLASS_ATTR_DO(ORBIT));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2133
  attr_defs[ATTR_CONTEXT_FIELD].predef
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2134
    = (0 X_ATTR_DO(ORBIT) FIELD_ATTR_DO(ORBIT));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2135
  attr_defs[ATTR_CONTEXT_METHOD].predef
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2136
    = (0 X_ATTR_DO(ORBIT) METHOD_ATTR_DO(ORBIT));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2137
  attr_defs[ATTR_CONTEXT_CODE].predef
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2138
    = (0 O_ATTR_DO(ORBIT) CODE_ATTR_DO(ORBIT));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2139
#undef ORBIT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2140
  // Clear out the redef bits, folding them back into predef.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2141
  for (i = 0; i < ATTR_CONTEXT_LIMIT; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2142
    attr_defs[i].predef |= attr_defs[i].redef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2143
    attr_defs[i].redef = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2144
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2145
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2146
  // Now read the transmitted locally defined attrs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2147
  // This will set redef bits again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2148
  for (i = 0; i < attr_definition_count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2149
    int    header  = attr_definition_headers.getByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2150
    int    attrc   = ADH_BYTE_CONTEXT(header);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2151
    int    idx     = ADH_BYTE_INDEX(header);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
    entry* name    = attr_definition_name.getRef();
16075
32c3bc19bba7 7186957: Improve Pack200 data validation
ksrini
parents: 12544
diff changeset
  2153
    CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2154
    entry* layout  = attr_definition_layout.getRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2155
    CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2156
    attr_defs[attrc].defineLayout(idx, name, layout->value.b.strval());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2157
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2158
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2159
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2160
#define NO_ENTRY_YET ((entry*)-1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2161
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2162
static bool isDigitString(bytes& x, int beg, int end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2163
  if (beg == end)  return false;  // null string
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2164
  byte* xptr = x.ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2165
  for (int i = beg; i < end; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2166
    char ch = xptr[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2167
    if (!(ch >= '0' && ch <= '9'))  return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2168
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2169
  return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2170
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2171
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2172
enum {  // constants for parsing class names
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2173
  SLASH_MIN = '.',
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2174
  SLASH_MAX = '/',
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2175
  DOLLAR_MIN = 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2176
  DOLLAR_MAX = '-'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2177
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2178
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2179
static int lastIndexOf(int chmin, int chmax, bytes& x, int pos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2180
  byte* ptr = x.ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2181
  for (byte* cp = ptr + pos; --cp >= ptr; ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2182
    assert(x.inBounds(cp));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2183
    if (*cp >= chmin && *cp <= chmax)
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  2184
      return (int)(cp - ptr);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2185
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2186
  return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2187
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2188
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2190
inner_class* cpool::getIC(entry* inner) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2191
  if (inner == null)  return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2192
  assert(inner->tag == CONSTANT_Class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2193
  if (inner->inord == NO_INORD)  return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2194
  inner_class* ic = ic_index[inner->inord];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2195
  assert(ic == null || ic->inner == inner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2196
  return ic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2197
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2198
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2199
maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2200
inner_class* cpool::getFirstChildIC(entry* outer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2201
  if (outer == null)  return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2202
  assert(outer->tag == CONSTANT_Class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2203
  if (outer->inord == NO_INORD)  return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2204
  inner_class* ic = ic_child_index[outer->inord];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2205
  assert(ic == null || ic->outer == outer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2206
  return ic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2207
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2208
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2209
maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2210
inner_class* cpool::getNextChildIC(inner_class* child) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2211
  inner_class* ic = child->next_sibling;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2212
  assert(ic == null || ic->outer == child->outer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2213
  return ic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2214
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2215
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2216
void unpacker::read_ics() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2217
  int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2218
  int index_size = cp.tag_count[CONSTANT_Class];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2219
  inner_class** ic_index       = U_NEW(inner_class*, index_size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2220
  inner_class** ic_child_index = U_NEW(inner_class*, index_size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2221
  cp.ic_index = ic_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2222
  cp.ic_child_index = ic_child_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2223
  ics = U_NEW(inner_class, ic_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2224
  ic_this_class.readData(ic_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2225
  ic_flags.readData(ic_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2226
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2227
  // Scan flags to get count of long-form bands.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2228
  int long_forms = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2229
  for (i = 0; i < ic_count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2230
    int flags = ic_flags.getInt();  // may be long form!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2231
    if ((flags & ACC_IC_LONG_FORM) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2232
      long_forms += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2233
      ics[i].name = NO_ENTRY_YET;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2234
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2235
    flags &= ~ACC_IC_LONG_FORM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2236
    entry* inner = ic_this_class.getRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2237
    CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2238
    uint inord = inner->inord;
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  2239
    assert(inord < (uint)cp.tag_count[CONSTANT_Class]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2240
    if (ic_index[inord] != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2241
      abort("identical inner class");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2242
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2243
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2244
    ic_index[inord] = &ics[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2245
    ics[i].inner = inner;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2246
    ics[i].flags = flags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2247
    assert(cp.getIC(inner) == &ics[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2248
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2249
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2250
  //ic_this_class.done();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2251
  //ic_flags.done();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2252
  ic_outer_class.readData(long_forms);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2253
  ic_name.readData(long_forms);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2254
  for (i = 0; i < ic_count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2255
    if (ics[i].name == NO_ENTRY_YET) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2256
      // Long form.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2257
      ics[i].outer = ic_outer_class.getRefN();
16075
32c3bc19bba7 7186957: Improve Pack200 data validation
ksrini
parents: 12544
diff changeset
  2258
      CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2259
      ics[i].name  = ic_name.getRefN();
16075
32c3bc19bba7 7186957: Improve Pack200 data validation
ksrini
parents: 12544
diff changeset
  2260
      CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2261
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2262
      // Fill in outer and name based on inner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2263
      bytes& n = ics[i].inner->value.b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2264
      bytes pkgOuter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2265
      bytes number;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2266
      bytes name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2267
      // Parse n into pkgOuter and name (and number).
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  2268
      PRINTCR((5, "parse short IC name %s", n.ptr));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2269
      int dollar1, dollar2;  // pointers to $ in the pattern
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2270
      // parse n = (<pkg>/)*<outer>($<number>)?($<name>)?
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  2271
      int nlen = (int)n.len;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2272
      int pkglen = lastIndexOf(SLASH_MIN,  SLASH_MAX,  n, nlen) + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2273
      dollar2    = lastIndexOf(DOLLAR_MIN, DOLLAR_MAX, n, nlen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2274
      if (dollar2 < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2275
         abort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2276
         return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2277
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2278
      assert(dollar2 >= pkglen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2279
      if (isDigitString(n, dollar2+1, nlen)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2280
        // n = (<pkg>/)*<outer>$<number>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2281
        number = n.slice(dollar2+1, nlen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2282
        name.set(null,0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2283
        dollar1 = dollar2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2284
      } else if (pkglen < (dollar1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2285
                           = lastIndexOf(DOLLAR_MIN, DOLLAR_MAX, n, dollar2-1))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2286
                 && isDigitString(n, dollar1+1, dollar2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2287
        // n = (<pkg>/)*<outer>$<number>$<name>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2288
        number = n.slice(dollar1+1, dollar2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2289
        name = n.slice(dollar2+1, nlen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2290
      } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2291
        // n = (<pkg>/)*<outer>$<name>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2292
        dollar1 = dollar2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2293
        number.set(null,0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2294
        name = n.slice(dollar2+1, nlen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2295
      }
42687
7a5929518e6a 8170663: Fix minor issues in corelib and servicabilty coding.
goetz
parents: 41573
diff changeset
  2296
      if (number.ptr == null) {
7a5929518e6a 8170663: Fix minor issues in corelib and servicabilty coding.
goetz
parents: 41573
diff changeset
  2297
        if (dollar1 < 0) {
7a5929518e6a 8170663: Fix minor issues in corelib and servicabilty coding.
goetz
parents: 41573
diff changeset
  2298
          abort();
7a5929518e6a 8170663: Fix minor issues in corelib and servicabilty coding.
goetz
parents: 41573
diff changeset
  2299
          return;
7a5929518e6a 8170663: Fix minor issues in corelib and servicabilty coding.
goetz
parents: 41573
diff changeset
  2300
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2301
        pkgOuter = n.slice(0, dollar1);
42687
7a5929518e6a 8170663: Fix minor issues in corelib and servicabilty coding.
goetz
parents: 41573
diff changeset
  2302
      } else {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2303
        pkgOuter.set(null,0);
42687
7a5929518e6a 8170663: Fix minor issues in corelib and servicabilty coding.
goetz
parents: 41573
diff changeset
  2304
      }
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  2305
      PRINTCR((5,"=> %s$ 0%s $%s",
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  2306
              pkgOuter.string(), number.string(), name.string()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2307
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2308
      if (pkgOuter.ptr != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2309
        ics[i].outer = cp.ensureClass(pkgOuter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2310
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2311
      if (name.ptr != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2312
        ics[i].name = cp.ensureUtf8(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2313
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2314
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2315
    // update child/sibling list
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2316
    if (ics[i].outer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2317
      uint outord = ics[i].outer->inord;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2318
      if (outord != NO_INORD) {
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  2319
        assert(outord < (uint)cp.tag_count[CONSTANT_Class]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2320
        ics[i].next_sibling = ic_child_index[outord];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2321
        ic_child_index[outord] = &ics[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2322
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2323
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2324
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2325
  //ic_outer_class.done();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2326
  //ic_name.done();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2327
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2328
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2329
void unpacker::read_classes() {
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  2330
  PRINTCR((1,"  ...scanning %d classes...", class_count));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2331
  class_this.readData(class_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2332
  class_super.readData(class_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2333
  class_interface_count.readData(class_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2334
  class_interface.readData(class_interface_count.getIntTotal());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2335
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2336
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2337
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2338
  #if 0
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  2339
  int i;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2340
  // Make a little mark on super-classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2341
  for (i = 0; i < class_count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2342
    entry* e = class_super.getRefN();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2343
    if (e != null)  e->bits |= entry::EB_SUPER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2344
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2345
  class_super.rewind();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2346
  #endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2347
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2348
  // Members.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2349
  class_field_count.readData(class_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2350
  class_method_count.readData(class_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2351
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2352
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2353
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2354
  int field_count = class_field_count.getIntTotal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2355
  int method_count = class_method_count.getIntTotal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2356
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2357
  field_descr.readData(field_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2358
  read_attrs(ATTR_CONTEXT_FIELD, field_count);
2607
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
  2359
  CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2360
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2361
  method_descr.readData(method_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2362
  read_attrs(ATTR_CONTEXT_METHOD, method_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2363
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2364
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2365
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2366
  read_attrs(ATTR_CONTEXT_CLASS, class_count);
2607
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
  2367
  CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2368
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2369
  read_code_headers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2370
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  2371
  PRINTCR((1,"scanned %d classes, %d fields, %d methods, %d code headers",
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  2372
          class_count, field_count, method_count, code_count));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2373
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2374
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2375
maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2376
int unpacker::attr_definitions::predefCount(uint idx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2377
  return isPredefined(idx) ? flag_count[idx] : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2378
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2379
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2380
void unpacker::read_attrs(int attrc, int obj_count) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2381
  attr_definitions& ad = attr_defs[attrc];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2382
  assert(ad.attrc == attrc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2383
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2384
  int i, idx, count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2385
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2386
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2387
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2388
  bool haveLongFlags = ad.haveLongFlags();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2389
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2390
  band& xxx_flags_hi = ad.xxx_flags_hi();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2391
  assert(endsWith(xxx_flags_hi.name, "_flags_hi"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2392
  if (haveLongFlags)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2393
    xxx_flags_hi.readData(obj_count);
2607
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
  2394
  CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2395
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2396
  band& xxx_flags_lo = ad.xxx_flags_lo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2397
  assert(endsWith(xxx_flags_lo.name, "_flags_lo"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2398
  xxx_flags_lo.readData(obj_count);
2607
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
  2399
  CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2400
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2401
  // pre-scan flags, counting occurrences of each index bit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2402
  julong indexMask = ad.flagIndexMask();  // which flag bits are index bits?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2403
  for (i = 0; i < obj_count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2404
    julong indexBits = xxx_flags_hi.getLong(xxx_flags_lo, haveLongFlags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2405
    if ((indexBits & ~indexMask) > (ushort)-1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2406
      abort("undefined attribute flag bit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2407
      return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2408
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2409
    indexBits &= indexMask;  // ignore classfile flag bits
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2410
    for (idx = 0; indexBits != 0; idx++, indexBits >>= 1) {
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  2411
      ad.flag_count[idx] += (int)(indexBits & 1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2412
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2413
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2414
  // we'll scan these again later for output:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2415
  xxx_flags_lo.rewind();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2416
  xxx_flags_hi.rewind();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2417
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2418
  band& xxx_attr_count = ad.xxx_attr_count();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2419
  assert(endsWith(xxx_attr_count.name, "_attr_count"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2420
  // There is one count element for each 1<<16 bit set in flags:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2421
  xxx_attr_count.readData(ad.predefCount(X_ATTR_OVERFLOW));
2607
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
  2422
  CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2423
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2424
  band& xxx_attr_indexes = ad.xxx_attr_indexes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2425
  assert(endsWith(xxx_attr_indexes.name, "_attr_indexes"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2426
  int overflowIndexCount = xxx_attr_count.getIntTotal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2427
  xxx_attr_indexes.readData(overflowIndexCount);
2607
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
  2428
  CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2429
  // pre-scan attr indexes, counting occurrences of each value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2430
  for (i = 0; i < overflowIndexCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2431
    idx = xxx_attr_indexes.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2432
    if (!ad.isIndex(idx)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2433
      abort("attribute index out of bounds");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2434
      return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2435
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2436
    ad.getCount(idx) += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2437
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2438
  xxx_attr_indexes.rewind();  // we'll scan it again later for output
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2439
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2440
  // We will need a backward call count for each used backward callable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2441
  int backwardCounts = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2442
  for (idx = 0; idx < ad.layouts.length(); idx++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2443
    layout_definition* lo = ad.getLayout(idx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2444
    if (lo != null && ad.getCount(idx) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2445
      // Build the bands lazily, only when they are used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2446
      band** bands = ad.buildBands(lo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2447
      CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2448
      if (lo->hasCallables()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2449
        for (i = 0; bands[i] != null; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2450
          if (bands[i]->le_back) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2451
            assert(bands[i]->le_kind == EK_CBLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2452
            backwardCounts += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2453
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2454
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2455
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2456
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2457
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2458
  ad.xxx_attr_calls().readData(backwardCounts);
2607
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
  2459
  CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2460
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2461
  // Read built-in bands.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2462
  // Mostly, these are hand-coded equivalents to readBandData().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2463
  switch (attrc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2464
  case ATTR_CONTEXT_CLASS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2465
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2466
    count = ad.predefCount(CLASS_ATTR_SourceFile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2467
    class_SourceFile_RUN.readData(count);
2607
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
  2468
    CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2469
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2470
    count = ad.predefCount(CLASS_ATTR_EnclosingMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2471
    class_EnclosingMethod_RC.readData(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2472
    class_EnclosingMethod_RDN.readData(count);
2607
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
  2473
    CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2474
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2475
    count = ad.predefCount(X_ATTR_Signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2476
    class_Signature_RS.readData(count);
2607
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
  2477
    CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2478
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2479
    ad.readBandData(X_ATTR_RuntimeVisibleAnnotations);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2480
    ad.readBandData(X_ATTR_RuntimeInvisibleAnnotations);
17490
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2481
    CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2482
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2483
    count = ad.predefCount(CLASS_ATTR_InnerClasses);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2484
    class_InnerClasses_N.readData(count);
2607
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
  2485
    CHECK;
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
  2486
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2487
    count = class_InnerClasses_N.getIntTotal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2488
    class_InnerClasses_RC.readData(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2489
    class_InnerClasses_F.readData(count);
2607
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
  2490
    CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2491
    // Drop remaining columns wherever flags are zero:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2492
    count -= class_InnerClasses_F.getIntCount(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2493
    class_InnerClasses_outer_RCN.readData(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2494
    class_InnerClasses_name_RUN.readData(count);
2607
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
  2495
    CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2496
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2497
    count = ad.predefCount(CLASS_ATTR_ClassFile_version);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2498
    class_ClassFile_version_minor_H.readData(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2499
    class_ClassFile_version_major_H.readData(count);
2607
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
  2500
    CHECK;
17490
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2501
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2502
    ad.readBandData(X_ATTR_RuntimeVisibleTypeAnnotations);
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2503
    ad.readBandData(X_ATTR_RuntimeInvisibleTypeAnnotations);
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2504
    CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2505
    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2506
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2507
  case ATTR_CONTEXT_FIELD:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2508
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2509
    count = ad.predefCount(FIELD_ATTR_ConstantValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2510
    field_ConstantValue_KQ.readData(count);
2607
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
  2511
    CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2512
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2513
    count = ad.predefCount(X_ATTR_Signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2514
    field_Signature_RS.readData(count);
2607
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
  2515
    CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2516
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2517
    ad.readBandData(X_ATTR_RuntimeVisibleAnnotations);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2518
    ad.readBandData(X_ATTR_RuntimeInvisibleAnnotations);
2607
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
  2519
    CHECK;
17490
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2520
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2521
    ad.readBandData(X_ATTR_RuntimeVisibleTypeAnnotations);
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2522
    ad.readBandData(X_ATTR_RuntimeInvisibleTypeAnnotations);
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2523
    CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2524
    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2525
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2526
  case ATTR_CONTEXT_METHOD:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2527
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2528
    code_count = ad.predefCount(METHOD_ATTR_Code);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2529
    // Code attrs are handled very specially below...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2530
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2531
    count = ad.predefCount(METHOD_ATTR_Exceptions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2532
    method_Exceptions_N.readData(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2533
    count = method_Exceptions_N.getIntTotal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2534
    method_Exceptions_RC.readData(count);
2607
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
  2535
    CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2536
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2537
    count = ad.predefCount(X_ATTR_Signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2538
    method_Signature_RS.readData(count);
2607
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
  2539
    CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2540
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2541
    ad.readBandData(X_ATTR_RuntimeVisibleAnnotations);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2542
    ad.readBandData(X_ATTR_RuntimeInvisibleAnnotations);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2543
    ad.readBandData(METHOD_ATTR_RuntimeVisibleParameterAnnotations);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2544
    ad.readBandData(METHOD_ATTR_RuntimeInvisibleParameterAnnotations);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2545
    ad.readBandData(METHOD_ATTR_AnnotationDefault);
2607
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
  2546
    CHECK;
15261
c5b882836677 8005252: pack200 should support MethodParameters
ksrini
parents: 12544
diff changeset
  2547
c5b882836677 8005252: pack200 should support MethodParameters
ksrini
parents: 12544
diff changeset
  2548
    count = ad.predefCount(METHOD_ATTR_MethodParameters);
c5b882836677 8005252: pack200 should support MethodParameters
ksrini
parents: 12544
diff changeset
  2549
    method_MethodParameters_NB.readData(count);
c5b882836677 8005252: pack200 should support MethodParameters
ksrini
parents: 12544
diff changeset
  2550
    count = method_MethodParameters_NB.getIntTotal();
c5b882836677 8005252: pack200 should support MethodParameters
ksrini
parents: 12544
diff changeset
  2551
    method_MethodParameters_name_RUN.readData(count);
16013
3569e84e7429 8008262: pack200 should support MethodParameters - part 2
ksrini
parents: 15652
diff changeset
  2552
    method_MethodParameters_flag_FH.readData(count);
15261
c5b882836677 8005252: pack200 should support MethodParameters
ksrini
parents: 12544
diff changeset
  2553
    CHECK;
17490
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2554
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2555
    ad.readBandData(X_ATTR_RuntimeVisibleTypeAnnotations);
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2556
    ad.readBandData(X_ATTR_RuntimeInvisibleTypeAnnotations);
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2557
    CHECK;
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2558
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2559
    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2560
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2561
  case ATTR_CONTEXT_CODE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2562
    // (keep this code aligned with its brother in unpacker::write_attrs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2563
    count = ad.predefCount(CODE_ATTR_StackMapTable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2564
    // disable this feature in old archives!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2565
    if (count != 0 && majver < JAVA6_PACKAGE_MAJOR_VERSION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2566
      abort("undefined StackMapTable attribute (old archive format)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2567
      return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2568
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2569
    code_StackMapTable_N.readData(count);
2607
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
  2570
    CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2571
    count = code_StackMapTable_N.getIntTotal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2572
    code_StackMapTable_frame_T.readData(count);
2607
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
  2573
    CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2574
    // the rest of it depends in a complicated way on frame tags
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2575
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2576
      int fat_frame_count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2577
      int offset_count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2578
      int type_count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2579
      for (int k = 0; k < count; k++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2580
        int tag = code_StackMapTable_frame_T.getByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2581
        if (tag <= 127) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2582
          // (64-127)  [(2)]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2583
          if (tag >= 64)  type_count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2584
        } else if (tag <= 251) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2585
          // (247)     [(1)(2)]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2586
          // (248-251) [(1)]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2587
          if (tag >= 247)  offset_count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2588
          if (tag == 247)  type_count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2589
        } else if (tag <= 254) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2590
          // (252)     [(1)(2)]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2591
          // (253)     [(1)(2)(2)]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2592
          // (254)     [(1)(2)(2)(2)]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2593
          offset_count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2594
          type_count += (tag - 251);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2595
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2596
          // (255)     [(1)NH[(2)]NH[(2)]]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2597
          fat_frame_count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2598
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2599
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2600
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2601
      // done pre-scanning frame tags:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2602
      code_StackMapTable_frame_T.rewind();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2603
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2604
      // deal completely with fat frames:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2605
      offset_count += fat_frame_count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2606
      code_StackMapTable_local_N.readData(fat_frame_count);
2607
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
  2607
      CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2608
      type_count += code_StackMapTable_local_N.getIntTotal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2609
      code_StackMapTable_stack_N.readData(fat_frame_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2610
      type_count += code_StackMapTable_stack_N.getIntTotal();
2607
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
  2611
      CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2612
      // read the rest:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2613
      code_StackMapTable_offset.readData(offset_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2614
      code_StackMapTable_T.readData(type_count);
2607
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
  2615
      CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2616
      // (7) [RCH]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2617
      count = code_StackMapTable_T.getIntCount(7);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2618
      code_StackMapTable_RC.readData(count);
2607
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
  2619
      CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2620
      // (8) [PH]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2621
      count = code_StackMapTable_T.getIntCount(8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2622
      code_StackMapTable_P.readData(count);
2607
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
  2623
      CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2624
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2625
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2626
    count = ad.predefCount(CODE_ATTR_LineNumberTable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2627
    code_LineNumberTable_N.readData(count);
17490
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2628
    CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2629
    count = code_LineNumberTable_N.getIntTotal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2630
    code_LineNumberTable_bci_P.readData(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2631
    code_LineNumberTable_line.readData(count);
17490
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2632
    CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2633
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2634
    count = ad.predefCount(CODE_ATTR_LocalVariableTable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2635
    code_LocalVariableTable_N.readData(count);
17490
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2636
    CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2637
    count = code_LocalVariableTable_N.getIntTotal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2638
    code_LocalVariableTable_bci_P.readData(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2639
    code_LocalVariableTable_span_O.readData(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2640
    code_LocalVariableTable_name_RU.readData(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2641
    code_LocalVariableTable_type_RS.readData(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2642
    code_LocalVariableTable_slot.readData(count);
17490
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2643
    CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2644
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2645
    count = ad.predefCount(CODE_ATTR_LocalVariableTypeTable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2646
    code_LocalVariableTypeTable_N.readData(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2647
    count = code_LocalVariableTypeTable_N.getIntTotal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2648
    code_LocalVariableTypeTable_bci_P.readData(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2649
    code_LocalVariableTypeTable_span_O.readData(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2650
    code_LocalVariableTypeTable_name_RU.readData(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2651
    code_LocalVariableTypeTable_type_RS.readData(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2652
    code_LocalVariableTypeTable_slot.readData(count);
17490
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2653
    CHECK;
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2654
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2655
    ad.readBandData(X_ATTR_RuntimeVisibleTypeAnnotations);
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2656
    ad.readBandData(X_ATTR_RuntimeInvisibleTypeAnnotations);
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2657
    CHECK;
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  2658
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2659
    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2660
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2661
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2662
  // Read compressor-defined bands.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2663
  for (idx = 0; idx < ad.layouts.length(); idx++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2664
    if (ad.getLayout(idx) == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2665
      continue;  // none at this fixed index <32
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  2666
    if (idx < (int)ad.flag_limit && ad.isPredefined(idx))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2667
      continue;  // already handled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2668
    if (ad.getCount(idx) == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2669
      continue;  // no attributes of this type (then why transmit layouts?)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2670
    ad.readBandData(idx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2671
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2672
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2673
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2674
void unpacker::attr_definitions::readBandData(int idx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2675
  int j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2676
  uint count = getCount(idx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2677
  if (count == 0)  return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2678
  layout_definition* lo = getLayout(idx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2679
  if (lo != null) {
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  2680
    PRINTCR((1, "counted %d [redefined = %d predefined = %d] attributes of type %s.%s",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2681
            count, isRedefined(idx), isPredefined(idx),
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  2682
            ATTR_CONTEXT_NAME[attrc], lo->name));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2683
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2684
  bool hasCallables = lo->hasCallables();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2685
  band** bands = lo->bands();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2686
  if (!hasCallables) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2687
    // Read through the rest of the bands in a regular way.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2688
    readBandData(bands, count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2689
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2690
    // Deal with the callables.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2691
    // First set up the forward entry count for each callable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2692
    // This is stored on band::length of the callable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2693
    bands[0]->expectMoreLength(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2694
    for (j = 0; bands[j] != null; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2695
      band& j_cble = *bands[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2696
      assert(j_cble.le_kind == EK_CBLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2697
      if (j_cble.le_back) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2698
        // Add in the predicted effects of backward calls, too.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2699
        int back_calls = xxx_attr_calls().getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2700
        j_cble.expectMoreLength(back_calls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2701
        // In a moment, more forward calls may increment j_cble.length.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2702
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2703
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2704
    // Now consult whichever callables have non-zero entry counts.
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  2705
    readBandData(bands, (uint)-1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2706
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2707
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2708
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2709
// Recursive helper to the previous function:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2710
void unpacker::attr_definitions::readBandData(band** body, uint count) {
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  2711
  int j, k;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2712
  for (j = 0; body[j] != null; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2713
    band& b = *body[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2714
    if (b.defc != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2715
      // It has data, so read it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2716
      b.readData(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2717
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2718
    switch (b.le_kind) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2719
    case EK_REPL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2720
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2721
        int reps = b.getIntTotal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2722
        readBandData(b.le_body, reps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2723
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2724
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2725
    case EK_UN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2726
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2727
        int remaining = count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2728
        for (k = 0; b.le_body[k] != null; k++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2729
          band& k_case = *b.le_body[k];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2730
          int   k_count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2731
          if (k_case.le_casetags == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2732
            k_count = remaining;  // last (empty) case
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2733
          } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2734
            int* tags = k_case.le_casetags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2735
            int ntags = *tags++;  // 1st element is length (why not?)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2736
            while (ntags-- > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2737
              int tag = *tags++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2738
              k_count += b.getIntCount(tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2739
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2740
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2741
          readBandData(k_case.le_body, k_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2742
          remaining -= k_count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2743
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2744
        assert(remaining == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2745
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2746
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2747
    case EK_CALL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2748
      // Push the count forward, if it is not a backward call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2749
      if (!b.le_back) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2750
        band& cble = *b.le_body[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2751
        assert(cble.le_kind == EK_CBLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2752
        cble.expectMoreLength(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2753
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2754
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2755
    case EK_CBLE:
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  2756
      assert((int)count == -1);  // incoming count is meaningless
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2757
      k = b.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2758
      assert(k >= 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2759
      // This is intended and required for non production mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2760
      assert((b.length = -1)); // make it unable to accept more calls now.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2761
      readBandData(b.le_body, k);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2762
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2763
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2764
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2765
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2766
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2767
static inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2768
band** findMatchingCase(int matchTag, band** cases) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2769
  for (int k = 0; cases[k] != null; k++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2770
    band& k_case = *cases[k];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2771
    if (k_case.le_casetags != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2772
      // If it has tags, it must match a tag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2773
      int* tags = k_case.le_casetags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2774
      int ntags = *tags++;  // 1st element is length
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2775
      for (; ntags > 0; ntags--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2776
        int tag = *tags++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2777
        if (tag == matchTag)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2778
          break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2779
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2780
      if (ntags == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2781
        continue;   // does not match
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2782
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2783
    return k_case.le_body;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2784
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2785
  return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2786
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2787
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2788
// write attribute band data:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2789
void unpacker::putlayout(band** body) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2790
  int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2791
  int prevBII = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2792
  int prevBCI = -1;
8779
d84abc7b455f 7023416: (pack200) fix parfait issues
ksrini
parents: 7668
diff changeset
  2793
  if (body == NULL) {
d84abc7b455f 7023416: (pack200) fix parfait issues
ksrini
parents: 7668
diff changeset
  2794
    abort("putlayout: unexpected NULL for body");
d84abc7b455f 7023416: (pack200) fix parfait issues
ksrini
parents: 7668
diff changeset
  2795
    return;
d84abc7b455f 7023416: (pack200) fix parfait issues
ksrini
parents: 7668
diff changeset
  2796
  }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2797
  for (i = 0; body[i] != null; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2798
    band& b = *body[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2799
    byte le_kind = b.le_kind;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2800
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2801
    // Handle scalar part, if any.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2802
    int    x = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2803
    entry* e = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2804
    if (b.defc != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2805
      // It has data, so unparse an element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2806
      if (b.ixTag != CONSTANT_None) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2807
        assert(le_kind == EK_REF);
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  2808
        if (b.ixTag == CONSTANT_FieldSpecific)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2809
          e = b.getRefUsing(cp.getKQIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2810
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2811
          e = b.getRefN();
16075
32c3bc19bba7 7186957: Improve Pack200 data validation
ksrini
parents: 12544
diff changeset
  2812
        CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2813
        switch (b.le_len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2814
        case 0: break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2815
        case 1: putu1ref(e); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2816
        case 2: putref(e); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2817
        case 4: putu2(0); putref(e); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2818
        default: assert(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2819
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2820
      } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2821
        assert(le_kind == EK_INT || le_kind == EK_REPL || le_kind == EK_UN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2822
        x = b.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2823
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  2824
        assert(!b.le_bci || prevBCI == (int)to_bci(prevBII));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2825
        switch (b.le_bci) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2826
        case EK_BCI:   // PH:  transmit R(bci), store bci
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2827
          x = to_bci(prevBII = x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2828
          prevBCI = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2829
          break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2830
        case EK_BCID:  // POH: transmit D(R(bci)), store bci
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2831
          x = to_bci(prevBII += x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2832
          prevBCI = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2833
          break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2834
        case EK_BCO:   // OH:  transmit D(R(bci)), store D(bci)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2835
          x = to_bci(prevBII += x) - prevBCI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2836
          prevBCI += x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2837
          break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2838
        }
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  2839
        assert(!b.le_bci || prevBCI == (int)to_bci(prevBII));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2840
41572
0b3abcb3879a 8160094: Improve pack200 layout
ksrini
parents: 29591
diff changeset
  2841
        CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2842
        switch (b.le_len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2843
        case 0: break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2844
        case 1: putu1(x); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2845
        case 2: putu2(x); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2846
        case 4: putu4(x); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2847
        default: assert(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2848
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2849
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2850
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2851
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2852
    // Handle subparts, if any.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2853
    switch (le_kind) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2854
    case EK_REPL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2855
      // x is the repeat count
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2856
      while (x-- > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2857
        putlayout(b.le_body);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2858
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2859
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2860
    case EK_UN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2861
      // x is the tag
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2862
      putlayout(findMatchingCase(x, b.le_body));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2863
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2864
    case EK_CALL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2865
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2866
        band& cble = *b.le_body[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2867
        assert(cble.le_kind == EK_CBLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2868
        assert(cble.le_len == b.le_len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2869
        putlayout(cble.le_body);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2870
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2871
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2872
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2873
    #ifndef PRODUCT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2874
    case EK_CBLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2875
    case EK_CASE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2876
      assert(false);  // should not reach here
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2877
    #endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2878
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2879
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2880
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2881
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2882
void unpacker::read_files() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2883
  file_name.readData(file_count);
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  2884
  if (testBit(archive_options, AO_HAVE_FILE_SIZE_HI))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2885
    file_size_hi.readData(file_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2886
  file_size_lo.readData(file_count);
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  2887
  if (testBit(archive_options, AO_HAVE_FILE_MODTIME))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2888
    file_modtime.readData(file_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2889
  int allFiles = file_count + class_count;
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  2890
  if (testBit(archive_options, AO_HAVE_FILE_OPTIONS)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2891
    file_options.readData(file_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2892
    // FO_IS_CLASS_STUB might be set, causing overlap between classes and files
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2893
    for (int i = 0; i < file_count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2894
      if ((file_options.getInt() & FO_IS_CLASS_STUB) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2895
        allFiles -= 1;  // this one counts as both class and file
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2896
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2897
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2898
    file_options.rewind();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2899
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2900
  assert((default_file_options & FO_IS_CLASS_STUB) == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2901
  files_remaining = allFiles;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2902
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2903
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2904
maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2905
void unpacker::get_code_header(int& max_stack,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2906
                               int& max_na_locals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2907
                               int& handler_count,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2908
                               int& cflags) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2909
  int sc = code_headers.getByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2910
  if (sc == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2911
    max_stack = max_na_locals = handler_count = cflags = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2912
    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2913
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2914
  // Short code header is the usual case:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2915
  int nh;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2916
  int mod;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2917
  if (sc < 1 + 12*12) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2918
    sc -= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2919
    nh = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2920
    mod = 12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2921
  } else if (sc < 1 + 12*12 + 8*8) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2922
    sc -= 1 + 12*12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2923
    nh = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2924
    mod = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2925
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2926
    assert(sc < 1 + 12*12 + 8*8 + 7*7);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2927
    sc -= 1 + 12*12 + 8*8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2928
    nh = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2929
    mod = 7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2930
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2931
  max_stack     = sc % mod;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2932
  max_na_locals = sc / mod;  // caller must add static, siglen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2933
  handler_count = nh;
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  2934
  if (testBit(archive_options, AO_HAVE_ALL_CODE_FLAGS))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2935
    cflags      = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2936
  else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2937
    cflags      = 0;  // this one has no attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2938
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2939
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2940
// Cf. PackageReader.readCodeHeaders
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2941
void unpacker::read_code_headers() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2942
  code_headers.readData(code_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2943
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2944
  int totalHandlerCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2945
  int totalFlagsCount   = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2946
  for (int i = 0; i < code_count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2947
    int max_stack, max_locals, handler_count, cflags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2948
    get_code_header(max_stack, max_locals, handler_count, cflags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2949
    if (max_stack < 0)      code_max_stack.expectMoreLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2950
    if (max_locals < 0)     code_max_na_locals.expectMoreLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2951
    if (handler_count < 0)  code_handler_count.expectMoreLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2952
    else                    totalHandlerCount += handler_count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2953
    if (cflags < 0)         totalFlagsCount += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2954
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2955
  code_headers.rewind();  // replay later during writing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2956
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2957
  code_max_stack.readData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2958
  code_max_na_locals.readData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2959
  code_handler_count.readData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2960
  totalHandlerCount += code_handler_count.getIntTotal();
2607
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
  2961
  CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2962
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2963
  // Read handler specifications.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2964
  // Cf. PackageReader.readCodeHandlers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2965
  code_handler_start_P.readData(totalHandlerCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2966
  code_handler_end_PO.readData(totalHandlerCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2967
  code_handler_catch_PO.readData(totalHandlerCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2968
  code_handler_class_RCN.readData(totalHandlerCount);
2607
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
  2969
  CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2970
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2971
  read_attrs(ATTR_CONTEXT_CODE, totalFlagsCount);
2607
7a11e5916dda 6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents: 2602
diff changeset
  2972
  CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2973
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2974
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2975
static inline bool is_in_range(uint n, uint min, uint max) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2976
  return n - min <= max - min;  // unsigned arithmetic!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2977
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2978
static inline bool is_field_op(int bc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2979
  return is_in_range(bc, bc_getstatic, bc_putfield);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2980
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2981
static inline bool is_invoke_init_op(int bc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2982
  return is_in_range(bc, _invokeinit_op, _invokeinit_limit-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2983
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2984
static inline bool is_self_linker_op(int bc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2985
  return is_in_range(bc, _self_linker_op, _self_linker_limit-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2986
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2987
static bool is_branch_op(int bc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2988
  return is_in_range(bc, bc_ifeq,   bc_jsr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2989
      || is_in_range(bc, bc_ifnull, bc_jsr_w);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2990
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2991
static bool is_local_slot_op(int bc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2992
  return is_in_range(bc, bc_iload,  bc_aload)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2993
      || is_in_range(bc, bc_istore, bc_astore)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2994
      || bc == bc_iinc || bc == bc_ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2995
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2996
band* unpacker::ref_band_for_op(int bc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2997
  switch (bc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2998
  case bc_ildc:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2999
  case bc_ildc_w:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3000
    return &bc_intref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3001
  case bc_fldc:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3002
  case bc_fldc_w:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3003
    return &bc_floatref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3004
  case bc_lldc2_w:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3005
    return &bc_longref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3006
  case bc_dldc2_w:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3007
    return &bc_doubleref;
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3008
  case bc_sldc:
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3009
  case bc_sldc_w:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3010
    return &bc_stringref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3011
  case bc_cldc:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3012
  case bc_cldc_w:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3013
    return &bc_classref;
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3014
  case bc_qldc: case bc_qldc_w:
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3015
    return &bc_loadablevalueref;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3016
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3017
  case bc_getstatic:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3018
  case bc_putstatic:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3019
  case bc_getfield:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3020
  case bc_putfield:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3021
    return &bc_fieldref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3022
16050
1eee624cddb3 8007297: [pack200] allow opcodes with InterfaceMethodRefs
ksrini
parents: 16013
diff changeset
  3023
  case _invokespecial_int:
1eee624cddb3 8007297: [pack200] allow opcodes with InterfaceMethodRefs
ksrini
parents: 16013
diff changeset
  3024
  case _invokestatic_int:
1eee624cddb3 8007297: [pack200] allow opcodes with InterfaceMethodRefs
ksrini
parents: 16013
diff changeset
  3025
    return &bc_imethodref;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3026
  case bc_invokevirtual:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3027
  case bc_invokespecial:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3028
  case bc_invokestatic:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3029
    return &bc_methodref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3030
  case bc_invokeinterface:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3031
    return &bc_imethodref;
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3032
  case bc_invokedynamic:
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3033
    return &bc_indyref;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3034
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3035
  case bc_new:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3036
  case bc_anewarray:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3037
  case bc_checkcast:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3038
  case bc_instanceof:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3039
  case bc_multianewarray:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3040
    return &bc_classref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3041
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3042
  return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3043
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3044
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3045
maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3046
band* unpacker::ref_band_for_self_op(int bc, bool& isAloadVar, int& origBCVar) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3047
  if (!is_self_linker_op(bc))  return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3048
  int idx = (bc - _self_linker_op);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3049
  bool isSuper = (idx >= _self_linker_super_flag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3050
  if (isSuper)  idx -= _self_linker_super_flag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3051
  bool isAload = (idx >= _self_linker_aload_flag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3052
  if (isAload)  idx -= _self_linker_aload_flag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3053
  int origBC = _first_linker_op + idx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3054
  bool isField = is_field_op(origBC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3055
  isAloadVar = isAload;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3056
  origBCVar  = _first_linker_op + idx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3057
  if (!isSuper)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3058
    return isField? &bc_thisfield: &bc_thismethod;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3059
  else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3060
    return isField? &bc_superfield: &bc_supermethod;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3061
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3062
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3063
// Cf. PackageReader.readByteCodes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3064
inline  // called exactly once => inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3065
void unpacker::read_bcs() {
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  3066
  PRINTCR((3, "reading compressed bytecodes and operands for %d codes...",
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  3067
          code_count));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3068
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3069
  // read from bc_codes and bc_case_count
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3070
  fillbytes all_switch_ops;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3071
  all_switch_ops.init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3072
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3073
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3074
  // Read directly from rp/rplimit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3075
  //Do this later:  bc_codes.readData(...)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3076
  byte* rp0 = rp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3077
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3078
  band* bc_which;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3079
  byte* opptr = rp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3080
  byte* oplimit = rplimit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3081
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3082
  bool  isAload;  // passed by ref and then ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3083
  int   junkBC;   // passed by ref and then ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3084
  for (int k = 0; k < code_count; k++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3085
    // Scan one method:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3086
    for (;;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3087
      if (opptr+2 > oplimit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3088
        rp = opptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3089
        ensure_input(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3090
        oplimit = rplimit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3091
        rp = rp0;  // back up
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3092
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3093
      if (opptr == oplimit) { abort(); break; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3094
      int bc = *opptr++ & 0xFF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3095
      bool isWide = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3096
      if (bc == bc_wide) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3097
        if (opptr == oplimit) { abort(); break; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3098
        bc = *opptr++ & 0xFF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3099
        isWide = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3100
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3101
      // Adjust expectations of various band sizes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3102
      switch (bc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3103
      case bc_tableswitch:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3104
      case bc_lookupswitch:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3105
        all_switch_ops.addByte(bc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3106
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3107
      case bc_iinc:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3108
        bc_local.expectMoreLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3109
        bc_which = isWide ? &bc_short : &bc_byte;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3110
        bc_which->expectMoreLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3111
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3112
      case bc_sipush:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3113
        bc_short.expectMoreLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3114
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3115
      case bc_bipush:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3116
        bc_byte.expectMoreLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3117
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3118
      case bc_newarray:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3119
        bc_byte.expectMoreLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3120
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3121
      case bc_multianewarray:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3122
        assert(ref_band_for_op(bc) == &bc_classref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3123
        bc_classref.expectMoreLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3124
        bc_byte.expectMoreLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3125
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3126
      case bc_ref_escape:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3127
        bc_escrefsize.expectMoreLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3128
        bc_escref.expectMoreLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3129
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3130
      case bc_byte_escape:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3131
        bc_escsize.expectMoreLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3132
        // bc_escbyte will have to be counted too
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3133
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3134
      default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3135
        if (is_invoke_init_op(bc)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3136
          bc_initref.expectMoreLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3137
          break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3138
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3139
        bc_which = ref_band_for_self_op(bc, isAload, junkBC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3140
        if (bc_which != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3141
          bc_which->expectMoreLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3142
          break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3143
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3144
        if (is_branch_op(bc)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3145
          bc_label.expectMoreLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3146
          break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3147
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3148
        bc_which = ref_band_for_op(bc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3149
        if (bc_which != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3150
          bc_which->expectMoreLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3151
          assert(bc != bc_multianewarray);  // handled elsewhere
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3152
          break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3154
        if (is_local_slot_op(bc)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3155
          bc_local.expectMoreLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3156
          break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3157
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3158
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3159
      case bc_end_marker:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3160
        // Increment k and test against code_count.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3161
        goto doneScanningMethod;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3162
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3164
  doneScanningMethod:{}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3165
    if (aborting())  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3166
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3167
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3168
  // Go through the formality, so we can use it in a regular fashion later:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3169
  assert(rp == rp0);
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  3170
  bc_codes.readData((int)(opptr - rp));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3171
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3172
  int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3173
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3174
  // To size instruction bands correctly, we need info on switches:
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  3175
  bc_case_count.readData((int)all_switch_ops.size());
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  3176
  for (i = 0; i < (int)all_switch_ops.size(); i++) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3177
    int caseCount = bc_case_count.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3178
    int bc        = all_switch_ops.getByte(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3179
    bc_label.expectMoreLength(1+caseCount); // default label + cases
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3180
    bc_case_value.expectMoreLength(bc == bc_tableswitch ? 1 : caseCount);
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  3181
    PRINTCR((2, "switch bc=%d caseCount=%d", bc, caseCount));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3182
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3183
  bc_case_count.rewind();  // uses again for output
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3184
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3185
  all_switch_ops.free();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3186
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3187
  for (i = e_bc_case_value; i <= e_bc_escsize; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3188
    all_bands[i].readData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3189
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3190
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3191
  // The bc_escbyte band is counted by the immediately previous band.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3192
  bc_escbyte.readData(bc_escsize.getIntTotal());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3193
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  3194
  PRINTCR((3, "scanned %d opcode and %d operand bytes for %d codes...",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3195
          (int)(bc_codes.size()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3196
          (int)(bc_escsize.maxRP() - bc_case_value.minRP()),
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  3197
          code_count));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3198
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3199
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3200
void unpacker::read_bands() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3201
  byte* rp0 = rp;
16076
d7183f4305e5 7186946: Refine unpacker resource usage
ksrini
parents: 16075
diff changeset
  3202
  CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3203
  read_file_header();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3204
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3205
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3206
  if (cp.nentries == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3207
    // read_file_header failed to read a CP, because it copied a JAR.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3208
    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3209
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3210
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3211
  // Do this after the file header has been read:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3212
  check_options();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3213
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3214
  read_cp();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3215
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3216
  read_attr_defs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3217
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3218
  read_ics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3219
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3220
  read_classes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3221
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3222
  read_bcs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3223
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3224
  read_files();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3225
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3226
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3227
/// CP routines
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3228
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3229
entry*& cpool::hashTabRef(byte tag, bytes& b) {
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  3230
  PRINTCR((5, "hashTabRef tag=%d %s[%d]", tag, b.string(), b.len));
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  3231
  uint hash = tag + (int)b.len;
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  3232
  for (int i = 0; i < (int)b.len; i++) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3233
    hash = hash * 31 + (0xFF & b.ptr[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3234
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3235
  entry**  ht = hashTab;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3236
  int    hlen = hashTabLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3237
  assert((hlen & (hlen-1)) == 0);  // must be power of 2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3238
  uint hash1 = hash & (hlen-1);    // == hash % hlen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3239
  uint hash2 = 0;                  // lazily computed (requires mod op.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3240
  int probes = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3241
  while (ht[hash1] != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3242
    entry& e = *ht[hash1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3243
    if (e.value.b.equals(b) && e.tag == tag)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3244
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3245
    if (hash2 == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3246
      // Note:  hash2 must be relatively prime to hlen, hence the "|1".
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3247
      hash2 = (((hash % 499) & (hlen-1)) | 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3248
    hash1 += hash2;
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  3249
    if (hash1 >= (uint)hlen)  hash1 -= hlen;
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  3250
    assert(hash1 < (uint)hlen);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3251
    assert(++probes < hlen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3252
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3253
  #ifndef PRODUCT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3254
  hash_probes[0] += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3255
  hash_probes[1] += probes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3256
  #endif
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  3257
  PRINTCR((5, " => @%d %p", hash1, ht[hash1]));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3258
  return ht[hash1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3259
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3260
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3261
maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3262
static void insert_extra(entry* e, ptrlist& extras) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3263
  // This ordering helps implement the Pack200 requirement
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3264
  // of a predictable CP order in the class files produced.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3265
  e->inord = NO_INORD;  // mark as an "extra"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3266
  extras.add(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3267
  // Note:  We will sort the list (by string-name) later.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3268
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3269
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3270
entry* cpool::ensureUtf8(bytes& b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3271
  entry*& ix = hashTabRef(CONSTANT_Utf8, b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3272
  if (ix != null)  return ix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3273
  // Make one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3274
  if (nentries == maxentries) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3275
    abort("cp utf8 overflow");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3276
    return &entries[tag_base[CONSTANT_Utf8]];  // return something
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3277
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3278
  entry& e = entries[nentries++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3279
  e.tag = CONSTANT_Utf8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3280
  u->saveTo(e.value.b, b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3281
  assert(&e >= first_extra_entry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3282
  insert_extra(&e, tag_extras[CONSTANT_Utf8]);
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  3283
  PRINTCR((4,"ensureUtf8 miss %s", e.string()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3284
  return ix = &e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3285
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3286
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3287
entry* cpool::ensureClass(bytes& b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3288
  entry*& ix = hashTabRef(CONSTANT_Class, b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3289
  if (ix != null)  return ix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3290
  // Make one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3291
  if (nentries == maxentries) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3292
    abort("cp class overflow");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3293
    return &entries[tag_base[CONSTANT_Class]];  // return something
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3294
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3295
  entry& e = entries[nentries++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3296
  e.tag = CONSTANT_Class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3297
  e.nrefs = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3298
  e.refs = U_NEW(entry*, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3299
  ix = &e;  // hold my spot in the index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3300
  entry* utf = ensureUtf8(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3301
  e.refs[0] = utf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3302
  e.value.b = utf->value.b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3303
  assert(&e >= first_extra_entry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3304
  insert_extra(&e, tag_extras[CONSTANT_Class]);
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  3305
  PRINTCR((4,"ensureClass miss %s", e.string()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3306
  return &e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3307
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3308
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3309
void cpool::expandSignatures() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3310
  int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3311
  int nsigs = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3312
  int nreused = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3313
  int first_sig = tag_base[CONSTANT_Signature];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3314
  int sig_limit = tag_count[CONSTANT_Signature] + first_sig;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3315
  fillbytes buf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3316
  buf.init(1<<10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3317
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3318
  for (i = first_sig; i < sig_limit; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3319
    entry& e = entries[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3320
    assert(e.tag == CONSTANT_Signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3321
    int refnum = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3322
    bytes form = e.refs[refnum++]->asUtf8();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3323
    buf.empty();
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  3324
    for (int j = 0; j < (int)form.len; j++) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3325
      int c = form.ptr[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3326
      buf.addByte(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3327
      if (c == 'L') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3328
        entry* cls = e.refs[refnum++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3329
        buf.append(cls->className()->asUtf8());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3330
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3331
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3332
    assert(refnum == e.nrefs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3333
    bytes& sig = buf.b;
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  3334
    PRINTCR((5,"signature %d %s -> %s", i, form.ptr, sig.ptr));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3335
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3336
    // try to find a pre-existing Utf8:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3337
    entry* &e2 = hashTabRef(CONSTANT_Utf8, sig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3338
    if (e2 != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3339
      assert(e2->isUtf8(sig));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3340
      e.value.b = e2->value.b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3341
      e.refs[0] = e2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3342
      e.nrefs = 1;
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  3343
      PRINTCR((5,"signature replaced %d => %s", i, e.string()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3344
      nreused++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3345
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3346
      // there is no other replacement; reuse this CP entry as a Utf8
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3347
      u->saveTo(e.value.b, sig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3348
      e.tag = CONSTANT_Utf8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3349
      e.nrefs = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3350
      e2 = &e;
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  3351
      PRINTCR((5,"signature changed %d => %s", e.inord, e.string()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3352
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3353
    nsigs++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3354
  }
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  3355
  PRINTCR((1,"expanded %d signatures (reused %d utfs)", nsigs, nreused));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3356
  buf.free();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3357
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3358
  // go expunge all references to remaining signatures:
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  3359
  for (i = 0; i < (int)nentries; i++) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3360
    entry& e = entries[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3361
    for (int j = 0; j < e.nrefs; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3362
      entry*& e2 = e.refs[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3363
      if (e2 != null && e2->tag == CONSTANT_Signature)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3364
        e2 = e2->refs[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3365
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3366
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3367
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3368
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3369
bool isLoadableValue(int tag) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3370
  switch(tag) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3371
    case CONSTANT_Integer:
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3372
    case CONSTANT_Float:
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3373
    case CONSTANT_Long:
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3374
    case CONSTANT_Double:
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3375
    case CONSTANT_String:
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3376
    case CONSTANT_Class:
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3377
    case CONSTANT_MethodHandle:
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3378
    case CONSTANT_MethodType:
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3379
      return true;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3380
    default:
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3381
      return false;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3382
  }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3383
}
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3384
/*
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3385
 * this method can be used to size an array using null as the parameter,
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3386
 * thereafter can be reused to initialize the array using a valid pointer
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3387
 * as a parameter.
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3388
 */
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3389
int cpool::initLoadableValues(entry** loadable_entries) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3390
  int loadable_count = 0;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3391
  for (int i = 0; i < (int)N_TAGS_IN_ORDER; i++) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3392
    int tag = TAGS_IN_ORDER[i];
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3393
    if (!isLoadableValue(tag))
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3394
      continue;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3395
    if (loadable_entries != NULL) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3396
      for (int n = 0 ; n < tag_count[tag] ; n++) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3397
        loadable_entries[loadable_count + n] = &entries[tag_base[tag] + n];
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3398
      }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3399
    }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3400
    loadable_count += tag_count[tag];
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3401
  }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3402
  return loadable_count;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3403
}
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3404
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3405
// Initialize various views into the constant pool.
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3406
void cpool::initGroupIndexes() {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3407
  // Initialize All
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3408
  int all_count = 0;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3409
  for (int tag = CONSTANT_None ; tag < CONSTANT_Limit ; tag++) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3410
    all_count += tag_count[tag];
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3411
  }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3412
  entry* all_entries = &entries[tag_base[CONSTANT_None]];
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3413
  tag_group_count[CONSTANT_All - CONSTANT_All] = all_count;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3414
  tag_group_index[CONSTANT_All - CONSTANT_All].init(all_count, all_entries, CONSTANT_All);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3415
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3416
  // Initialize LoadableValues
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3417
  int loadable_count = initLoadableValues(NULL);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3418
  entry** loadable_entries = U_NEW(entry*, loadable_count);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3419
  initLoadableValues(loadable_entries);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3420
  tag_group_count[CONSTANT_LoadableValue - CONSTANT_All] = loadable_count;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3421
  tag_group_index[CONSTANT_LoadableValue - CONSTANT_All].init(loadable_count,
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3422
                  loadable_entries, CONSTANT_LoadableValue);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3423
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3424
// Initialize AnyMembers
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3425
  int any_count = tag_count[CONSTANT_Fieldref] +
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3426
                  tag_count[CONSTANT_Methodref] +
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3427
                  tag_count[CONSTANT_InterfaceMethodref];
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3428
  entry *any_entries = &entries[tag_base[CONSTANT_Fieldref]];
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3429
  tag_group_count[CONSTANT_AnyMember - CONSTANT_All] = any_count;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3430
  tag_group_index[CONSTANT_AnyMember - CONSTANT_All].init(any_count,
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3431
                                               any_entries, CONSTANT_AnyMember);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3432
}
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3433
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3434
void cpool::initMemberIndexes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3435
  // This function does NOT refer to any class schema.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3436
  // It is totally internal to the cpool.
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  3437
  int i, j;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3438
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3439
  // Get the pre-existing indexes:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3440
  int   nclasses = tag_count[CONSTANT_Class];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3441
  entry* classes = tag_base[CONSTANT_Class] + entries;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3442
  int   nfields  = tag_count[CONSTANT_Fieldref];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3443
  entry* fields  = tag_base[CONSTANT_Fieldref] + entries;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3444
  int   nmethods = tag_count[CONSTANT_Methodref];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3445
  entry* methods = tag_base[CONSTANT_Methodref] + entries;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3446
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3447
  int*     field_counts  = T_NEW(int, nclasses);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3448
  int*     method_counts = T_NEW(int, nclasses);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3449
  cpindex* all_indexes   = U_NEW(cpindex, nclasses*2);
5191
79b41f733e33 6902299: Java JAR "unpack200" must verify input parameters
ksrini
parents: 3463
diff changeset
  3450
  entry**  field_ix      = U_NEW(entry*, add_size(nfields, nclasses));
79b41f733e33 6902299: Java JAR "unpack200" must verify input parameters
ksrini
parents: 3463
diff changeset
  3451
  entry**  method_ix     = U_NEW(entry*, add_size(nmethods, nclasses));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3452
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3453
  for (j = 0; j < nfields; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3454
    entry& f = fields[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3455
    i = f.memberClass()->inord;
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  3456
    assert(i < nclasses);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3457
    field_counts[i]++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3458
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3459
  for (j = 0; j < nmethods; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3460
    entry& m = methods[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3461
    i = m.memberClass()->inord;
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  3462
    assert(i < nclasses);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3463
    method_counts[i]++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3464
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3465
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3466
  int fbase = 0, mbase = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3467
  for (i = 0; i < nclasses; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3468
    int fc = field_counts[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3469
    int mc = method_counts[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3470
    all_indexes[i*2+0].init(fc, field_ix+fbase,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3471
                            CONSTANT_Fieldref  + SUBINDEX_BIT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3472
    all_indexes[i*2+1].init(mc, method_ix+mbase,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3473
                            CONSTANT_Methodref + SUBINDEX_BIT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3474
    // reuse field_counts and member_counts as fill pointers:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3475
    field_counts[i] = fbase;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3476
    method_counts[i] = mbase;
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  3477
    PRINTCR((3, "class %d fields @%d[%d] methods @%d[%d]",
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  3478
            i, fbase, fc, mbase, mc));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3479
    fbase += fc+1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3480
    mbase += mc+1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3481
    // (the +1 leaves a space between every subarray)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3482
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3483
  assert(fbase == nfields+nclasses);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3484
  assert(mbase == nmethods+nclasses);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3485
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3486
  for (j = 0; j < nfields; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3487
    entry& f = fields[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3488
    i = f.memberClass()->inord;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3489
    field_ix[field_counts[i]++] = &f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3490
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3491
  for (j = 0; j < nmethods; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3492
    entry& m = methods[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3493
    i = m.memberClass()->inord;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3494
    method_ix[method_counts[i]++] = &m;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3495
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3496
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3497
  member_indexes = all_indexes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3498
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3499
#ifndef PRODUCT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3500
  // Test the result immediately on every class and field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3501
  int fvisited = 0, mvisited = 0;
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  3502
  int prevord, len;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3503
  for (i = 0; i < nclasses; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3504
    entry*   cls = &classes[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3505
    cpindex* fix = getFieldIndex(cls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3506
    cpindex* mix = getMethodIndex(cls);
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  3507
    PRINTCR((2, "field and method index for %s [%d] [%d]",
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  3508
            cls->string(), mix->len, fix->len));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3509
    prevord = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3510
    for (j = 0, len = fix->len; j < len; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3511
      entry* f = fix->get(j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3512
      assert(f != null);
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  3513
      PRINTCR((3, "- field %s", f->string()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3514
      assert(f->memberClass() == cls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3515
      assert(prevord < (int)f->inord);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3516
      prevord = f->inord;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3517
      fvisited++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3518
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3519
    assert(fix->base2[j] == null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3520
    prevord = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3521
    for (j = 0, len = mix->len; j < len; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3522
      entry* m = mix->get(j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3523
      assert(m != null);
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  3524
      PRINTCR((3, "- method %s", m->string()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3525
      assert(m->memberClass() == cls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3526
      assert(prevord < (int)m->inord);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3527
      prevord = m->inord;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3528
      mvisited++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3529
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3530
    assert(mix->base2[j] == null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3531
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3532
  assert(fvisited == nfields);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3533
  assert(mvisited == nmethods);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3534
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3535
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3536
  // Free intermediate buffers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3537
  u->free_temps();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3538
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3539
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3540
void entry::requestOutputIndex(cpool& cp, int req) {
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3541
  assert(outputIndex <= REQUESTED_NONE);  // must not have assigned indexes yet
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3542
  if (tag == CONSTANT_Signature) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3543
    ref(0)->requestOutputIndex(cp, req);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3544
    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3545
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3546
  assert(req == REQUESTED || req == REQUESTED_LDC);
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3547
  if (outputIndex != REQUESTED_NONE) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3548
    if (req == REQUESTED_LDC)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3549
      outputIndex = req;  // this kind has precedence
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3550
    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3551
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3552
  outputIndex = req;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3553
  //assert(!cp.outputEntries.contains(this));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3554
  assert(tag != CONSTANT_Signature);
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3555
  // The BSMs are jetisoned to a side table, however all references
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3556
  // that the BSMs refer to,  need to be considered.
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3557
  if (tag == CONSTANT_BootstrapMethod) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3558
    // this is a a pseudo-op entry; an attribute will be generated later on
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3559
    cp.requested_bsms.add(this);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3560
  } else {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3561
    // all other tag types go into real output file CP:
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3562
    cp.outputEntries.add(this);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3563
  }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3564
  for (int j = 0; j < nrefs; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3565
    ref(j)->requestOutputIndex(cp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3566
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3567
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3568
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3569
void cpool::resetOutputIndexes() {
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3570
    /*
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3571
     * reset those few entries that are being used in the current class
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3572
     * (Caution since this method is called after every class written, a loop
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3573
     * over every global constant pool entry would be a quadratic cost.)
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3574
     */
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3575
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3576
  int noes    = outputEntries.length();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3577
  entry** oes = (entry**) outputEntries.base();
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3578
  for (int i = 0 ; i < noes ; i++) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3579
    entry& e = *oes[i];
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3580
    e.outputIndex = REQUESTED_NONE;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3581
  }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3582
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3583
  // do the same for bsms and reset them if required
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3584
  int nbsms = requested_bsms.length();
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3585
  entry** boes = (entry**) requested_bsms.base();
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3586
  for (int i = 0 ; i < nbsms ; i++) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3587
    entry& e = *boes[i];
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3588
    e.outputIndex = REQUESTED_NONE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3589
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3590
  outputIndexLimit = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3591
  outputEntries.empty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3592
#ifndef PRODUCT
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3593
  // ensure things are cleared out
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3594
  for (int i = 0; i < (int)maxentries; i++)
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3595
    assert(entries[i].outputIndex == REQUESTED_NONE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3596
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3597
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3598
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3599
static const byte TAG_ORDER[CONSTANT_Limit] = {
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3600
  0, 1, 0, 2, 3, 4, 5, 7, 6, 10, 11, 12, 9, 8, 0, 13, 14, 15, 16
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3601
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3602
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3603
extern "C"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3604
int outputEntry_cmp(const void* e1p, const void* e2p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3605
  // Sort entries according to the Pack200 rules for deterministic
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3606
  // constant pool ordering.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3607
  //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3608
  // The four sort keys as follows, in order of decreasing importance:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3609
  //   1. ldc first, then non-ldc guys
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3610
  //   2. normal cp_All entries by input order (i.e., address order)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3611
  //   3. after that, extra entries by lexical order (as in tag_extras[*])
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3612
  entry& e1 = *(entry*) *(void**) e1p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3613
  entry& e2 = *(entry*) *(void**) e2p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3614
  int   oi1 = e1.outputIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3615
  int   oi2 = e2.outputIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3616
  assert(oi1 == REQUESTED || oi1 == REQUESTED_LDC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3617
  assert(oi2 == REQUESTED || oi2 == REQUESTED_LDC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3618
  if (oi1 != oi2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3619
    if (oi1 == REQUESTED_LDC)  return 0-1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3620
    if (oi2 == REQUESTED_LDC)  return 1-0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3621
    // Else fall through; neither is an ldc request.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3622
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3623
  if (e1.inord != NO_INORD || e2.inord != NO_INORD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3624
    // One or both is normal.  Use input order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3625
    if (&e1 > &e2)  return 1-0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3626
    if (&e1 < &e2)  return 0-1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3627
    return 0;  // equal pointers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3628
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3629
  // Both are extras.  Sort by tag and then by value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3630
  if (e1.tag != e2.tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3631
    return TAG_ORDER[e1.tag] - TAG_ORDER[e2.tag];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3632
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3633
  // If the tags are the same, use string comparison.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3634
  return compare_Utf8_chars(e1.value.b, e2.value.b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3635
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3636
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3637
void cpool::computeOutputIndexes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3638
  int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3639
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3640
#ifndef PRODUCT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3641
  // outputEntries must be a complete list of those requested:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3642
  static uint checkStart = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3643
  int checkStep = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3644
  if (nentries > 100)  checkStep = nentries / 100;
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  3645
  for (i = (int)(checkStart++ % checkStep); i < (int)nentries; i += checkStep) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3646
    entry& e = entries[i];
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3647
    if (e.tag == CONSTANT_BootstrapMethod) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3648
      if (e.outputIndex != REQUESTED_NONE) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3649
        assert(requested_bsms.contains(&e));
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3650
      } else {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3651
        assert(!requested_bsms.contains(&e));
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3652
      }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3653
    } else {
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3654
      if (e.outputIndex != REQUESTED_NONE) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3655
        assert(outputEntries.contains(&e));
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3656
      } else {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3657
        assert(!outputEntries.contains(&e));
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3658
      }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3659
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3660
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3661
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3662
  // check hand-initialization of TAG_ORDER
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  3663
  for (i = 0; i < (int)N_TAGS_IN_ORDER; i++) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3664
    byte tag = TAGS_IN_ORDER[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3665
    assert(TAG_ORDER[tag] == i+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3666
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3667
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3668
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3669
  int    noes =           outputEntries.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3670
  entry** oes = (entry**) outputEntries.base();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3671
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3672
  // Sort the output constant pool into the order required by Pack200.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3673
  PTRLIST_QSORT(outputEntries, outputEntry_cmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3674
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3675
  // Allocate a new index for each entry that needs one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3676
  // We do this in two passes, one for LDC entries and one for the rest.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3677
  int nextIndex = 1;  // always skip index #0 in output cpool
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3678
  for (i = 0; i < noes; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3679
    entry& e = *oes[i];
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  3680
    assert(e.outputIndex >= REQUESTED_LDC);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3681
    e.outputIndex = nextIndex++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3682
    if (e.isDoubleWord())  nextIndex++;  // do not use the next index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3683
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3684
  outputIndexLimit = nextIndex;
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  3685
  PRINTCR((3,"renumbering CP to %d entries", outputIndexLimit));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3686
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3687
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3688
#ifndef PRODUCT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3689
// debugging goo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3690
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3691
unpacker* debug_u;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3692
29591
51244d1ddffc 8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents: 29368
diff changeset
  3693
static bytes& getbuf(size_t len) {  // for debugging only!
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3694
  static int bn = 0;
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  3695
  static bytes bufs[8];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3696
  bytes& buf = bufs[bn++ & 7];
29591
51244d1ddffc 8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents: 29368
diff changeset
  3697
  while (buf.len < len + 10) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3698
    buf.realloc(buf.len ? buf.len * 2 : 1000);
29591
51244d1ddffc 8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents: 29368
diff changeset
  3699
  }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3700
  buf.ptr[0] = 0;  // for the sake of strcat
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3701
  return buf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3702
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3703
29591
51244d1ddffc 8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents: 29368
diff changeset
  3704
const char* entry::string() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3705
  bytes buf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3706
  switch (tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3707
  case CONSTANT_None:
29591
51244d1ddffc 8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents: 29368
diff changeset
  3708
    return "<empty>";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3709
  case CONSTANT_Signature:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3710
    if (value.b.ptr == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3711
      return ref(0)->string();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3712
    // else fall through:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3713
  case CONSTANT_Utf8:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3714
    buf = value.b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3715
    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3716
  case CONSTANT_Integer:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3717
  case CONSTANT_Float:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3718
    buf = getbuf(12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3719
    sprintf((char*)buf.ptr, "0x%08x", value.i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3720
    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3721
  case CONSTANT_Long:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3722
  case CONSTANT_Double:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3723
    buf = getbuf(24);
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  3724
    sprintf((char*)buf.ptr, "0x" LONG_LONG_HEX_FORMAT, value.l);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3725
    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3726
  default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3727
    if (nrefs == 0) {
29591
51244d1ddffc 8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents: 29368
diff changeset
  3728
      return TAG_NAME[tag];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3729
    } else if (nrefs == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3730
      return refs[0]->string();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3731
    } else {
29591
51244d1ddffc 8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents: 29368
diff changeset
  3732
      const char* s1 = refs[0]->string();
51244d1ddffc 8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents: 29368
diff changeset
  3733
      const char* s2 = refs[1]->string();
51244d1ddffc 8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents: 29368
diff changeset
  3734
      buf = getbuf(strlen(s1) + 1 + strlen(s2) + 4 + 1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3735
      buf.strcat(s1).strcat(" ").strcat(s2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3736
      if (nrefs > 2)  buf.strcat(" ...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3737
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3738
  }
29591
51244d1ddffc 8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents: 29368
diff changeset
  3739
  return (const char*)buf.ptr;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3740
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3741
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3742
void print_cp_entry(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3743
  entry& e = debug_u->cp.entries[i];
29591
51244d1ddffc 8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents: 29368
diff changeset
  3744
51244d1ddffc 8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents: 29368
diff changeset
  3745
  if ((uint)e.tag < CONSTANT_Limit) {
51244d1ddffc 8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents: 29368
diff changeset
  3746
    printf(" %d\t%s %s\n", i, TAG_NAME[e.tag], e.string());
51244d1ddffc 8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents: 29368
diff changeset
  3747
  } else {
51244d1ddffc 8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents: 29368
diff changeset
  3748
    printf(" %d\t%d %s\n", i, e.tag, e.string());
51244d1ddffc 8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents: 29368
diff changeset
  3749
  }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3750
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3751
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3752
void print_cp_entries(int beg, int end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3753
  for (int i = beg; i < end; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3754
    print_cp_entry(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3755
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3756
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3757
void print_cp() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3758
  print_cp_entries(0, debug_u->cp.nentries);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3759
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3760
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3761
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3762
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3763
// Unpacker Start
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3764
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3765
const char str_tf[] = "true\0false";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3766
#undef STR_TRUE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3767
#undef STR_FALSE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3768
#define STR_TRUE   (&str_tf[0])
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3769
#define STR_FALSE  (&str_tf[5])
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3770
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3771
const char* unpacker::get_option(const char* prop) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3772
  if (prop == null )  return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3773
  if (strcmp(prop, UNPACK_DEFLATE_HINT) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3774
    return deflate_hint_or_zero == 0? null : STR_TF(deflate_hint_or_zero > 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3775
#ifdef HAVE_STRIP
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3776
  } else if (strcmp(prop, UNPACK_STRIP_COMPILE) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3777
    return STR_TF(strip_compile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3778
  } else if (strcmp(prop, UNPACK_STRIP_DEBUG) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3779
    return STR_TF(strip_debug);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3780
  } else if (strcmp(prop, UNPACK_STRIP_JCOV) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3781
    return STR_TF(strip_jcov);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3782
#endif /*HAVE_STRIP*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3783
  } else if (strcmp(prop, UNPACK_REMOVE_PACKFILE) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3784
    return STR_TF(remove_packfile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3785
  } else if (strcmp(prop, DEBUG_VERBOSE) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3786
    return saveIntStr(verbose);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3787
  } else if (strcmp(prop, UNPACK_MODIFICATION_TIME) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3788
    return (modification_time_or_zero == 0)? null:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3789
      saveIntStr(modification_time_or_zero);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3790
  } else if (strcmp(prop, UNPACK_LOG_FILE) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3791
    return log_file;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3792
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3793
    return NULL; // unknown option ignore
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3794
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3795
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3796
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3797
bool unpacker::set_option(const char* prop, const char* value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3798
  if (prop == NULL)  return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3799
  if (strcmp(prop, UNPACK_DEFLATE_HINT) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3800
    deflate_hint_or_zero = ( (value == null || strcmp(value, "keep") == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3801
                                ? 0: BOOL_TF(value) ? +1: -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3802
#ifdef HAVE_STRIP
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3803
  } else if (strcmp(prop, UNPACK_STRIP_COMPILE) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3804
    strip_compile = STR_TF(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3805
  } else if (strcmp(prop, UNPACK_STRIP_DEBUG) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3806
    strip_debug = STR_TF(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3807
  } else if (strcmp(prop, UNPACK_STRIP_JCOV) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3808
    strip_jcov = STR_TF(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3809
#endif /*HAVE_STRIP*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3810
  } else if (strcmp(prop, UNPACK_REMOVE_PACKFILE) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3811
    remove_packfile = STR_TF(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3812
  } else if (strcmp(prop, DEBUG_VERBOSE) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3813
    verbose = (value == null)? 0: atoi(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3814
  } else if (strcmp(prop, DEBUG_VERBOSE ".bands") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3815
#ifndef PRODUCT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3816
    verbose_bands = (value == null)? 0: atoi(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3817
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3818
  } else if (strcmp(prop, UNPACK_MODIFICATION_TIME) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3819
    if (value == null || (strcmp(value, "keep") == 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3820
      modification_time_or_zero = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3821
    } else if (strcmp(value, "now") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3822
      time_t now;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3823
      time(&now);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3824
      modification_time_or_zero = (int) now;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3825
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3826
      modification_time_or_zero = atoi(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3827
      if (modification_time_or_zero == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3828
        modification_time_or_zero = 1;  // make non-zero
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3829
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3830
  } else if (strcmp(prop, UNPACK_LOG_FILE) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3831
    log_file = (value == null)? value: saveStr(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3832
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3833
    return false; // unknown option ignore
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3834
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3835
  return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3836
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3837
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3838
// Deallocate all internal storage and reset to a clean state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3839
// Do not disturb any input or output connections, including
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3840
// infileptr, infileno, inbytes, read_input_fn, jarout, or errstrm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3841
// Do not reset any unpack options.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3842
void unpacker::reset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3843
  bytes_read_before_reset      += bytes_read;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3844
  bytes_written_before_reset   += bytes_written;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3845
  files_written_before_reset   += files_written;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3846
  classes_written_before_reset += classes_written;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3847
  segments_read_before_reset   += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3848
  if (verbose >= 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3849
    fprintf(errstrm,
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  3850
            "After segment %d, "
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  3851
            LONG_LONG_FORMAT " bytes read and "
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  3852
            LONG_LONG_FORMAT " bytes written.\n",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3853
            segments_read_before_reset-1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3854
            bytes_read_before_reset, bytes_written_before_reset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3855
    fprintf(errstrm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3856
            "After segment %d, %d files (of which %d are classes) written to output.\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3857
            segments_read_before_reset-1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3858
            files_written_before_reset, classes_written_before_reset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3859
    if (archive_next_count != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3860
      fprintf(errstrm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3861
              "After segment %d, %d segment%s remaining (estimated).\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3862
              segments_read_before_reset-1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3863
              archive_next_count, archive_next_count==1?"":"s");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3864
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3865
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3866
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3867
  unpacker save_u = (*this);  // save bytewise image
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3868
  infileptr = null;  // make asserts happy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3869
  jniobj = null;  // make asserts happy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3870
  jarout = null;  // do not close the output jar
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3871
  gzin = null;  // do not close the input gzip stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3872
  bytes esn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3873
  if (errstrm_name != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3874
    esn.saveFrom(errstrm_name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3875
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3876
    esn.set(null, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3877
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3878
  this->free();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3879
  mtrace('s', 0, 0);  // note the boundary between segments
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3880
  this->init(read_input_fn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3881
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3882
  // restore selected interface state:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3883
#define SAVE(x) this->x = save_u.x
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3884
  SAVE(jniobj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3885
  SAVE(jnienv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3886
  SAVE(infileptr);  // buffered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3887
  SAVE(infileno);   // unbuffered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3888
  SAVE(inbytes);    // direct
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3889
  SAVE(jarout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3890
  SAVE(gzin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3891
  //SAVE(read_input_fn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3892
  SAVE(errstrm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3893
  SAVE(verbose);  // verbose level, 0 means no output
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3894
  SAVE(strip_compile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3895
  SAVE(strip_debug);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3896
  SAVE(strip_jcov);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3897
  SAVE(remove_packfile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3898
  SAVE(deflate_hint_or_zero);  // ==0 means not set, otherwise -1 or 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3899
  SAVE(modification_time_or_zero);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3900
  SAVE(bytes_read_before_reset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3901
  SAVE(bytes_written_before_reset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3902
  SAVE(files_written_before_reset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3903
  SAVE(classes_written_before_reset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3904
  SAVE(segments_read_before_reset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3905
#undef SAVE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3906
  if (esn.len > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3907
    errstrm_name = saveStr(esn.strval());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3908
    esn.free();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3909
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3910
  log_file = errstrm_name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3911
  // Note:  If we use strip_names, watch out:  They get nuked here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3912
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3913
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3914
void unpacker::init(read_input_fn_t input_fn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3915
  int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3916
  NOT_PRODUCT(debug_u = this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3917
  BYTES_OF(*this).clear();
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  3918
#ifndef PRODUCT
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  3919
  free();  // just to make sure freeing is idempotent
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  3920
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3921
  this->u = this;    // self-reference for U_NEW macro
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3922
  errstrm = stdout;  // default error-output
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3923
  log_file = LOGFILE_STDOUT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3924
  read_input_fn = input_fn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3925
  all_bands = band::makeBands(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3926
  // Make a default jar buffer; caller may safely overwrite it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3927
  jarout = U_NEW(jar, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3928
  jarout->init(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3929
  for (i = 0; i < ATTR_CONTEXT_LIMIT; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3930
    attr_defs[i].u = u;  // set up outer ptr
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3931
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3932
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3933
const char* unpacker::get_abort_message() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3934
   return abort_message;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3935
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3936
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3937
void unpacker::dump_options() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3938
  static const char* opts[] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3939
    UNPACK_LOG_FILE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3940
    UNPACK_DEFLATE_HINT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3941
#ifdef HAVE_STRIP
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3942
    UNPACK_STRIP_COMPILE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3943
    UNPACK_STRIP_DEBUG,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3944
    UNPACK_STRIP_JCOV,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3945
#endif /*HAVE_STRIP*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3946
    UNPACK_REMOVE_PACKFILE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3947
    DEBUG_VERBOSE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3948
    UNPACK_MODIFICATION_TIME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3949
    null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3950
  };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3951
  for (int i = 0; opts[i] != null; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3952
    const char* str = get_option(opts[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3953
    if (str == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3954
      if (verbose == 0)  continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3955
      str = "(not set)";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3956
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3957
    fprintf(errstrm, "%s=%s\n", opts[i], str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3958
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3959
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3960
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3961
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3962
// Usage: unpack a byte buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3963
// packptr is a reference to byte buffer containing a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3964
// packed file and len is the length of the buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3965
// If null, the callback is used to fill an internal buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3966
void unpacker::start(void* packptr, size_t len) {
16076
d7183f4305e5 7186946: Refine unpacker resource usage
ksrini
parents: 16075
diff changeset
  3967
  CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3968
  NOT_PRODUCT(debug_u = this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3969
  if (packptr != null && len != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3970
    inbytes.set((byte*) packptr, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3971
  }
16076
d7183f4305e5 7186946: Refine unpacker resource usage
ksrini
parents: 16075
diff changeset
  3972
  CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3973
  read_bands();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3974
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3975
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3976
void unpacker::check_options() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3977
  const char* strue  = "true";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3978
  const char* sfalse = "false";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3979
  if (deflate_hint_or_zero != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3980
    bool force_deflate_hint = (deflate_hint_or_zero > 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3981
    if (force_deflate_hint)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3982
      default_file_options |= FO_DEFLATE_HINT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3983
    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3984
      default_file_options &= ~FO_DEFLATE_HINT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3985
    // Turn off per-file deflate hint by force.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3986
    suppress_file_options |= FO_DEFLATE_HINT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3987
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3988
  if (modification_time_or_zero != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3989
    default_file_modtime = modification_time_or_zero;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3990
    // Turn off per-file modtime by force.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3991
    archive_options &= ~AO_HAVE_FILE_MODTIME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3992
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3993
  // %%% strip_compile, etc...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3994
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3995
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3996
// classfile writing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3997
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3998
void unpacker::reset_cur_classfile() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3999
  // set defaults
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4000
  cur_class_minver = default_class_minver;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4001
  cur_class_majver = default_class_majver;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4002
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4003
  // reset constant pool state
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4004
  cp.resetOutputIndexes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4005
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4006
  // reset fixups
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4007
  class_fixup_type.empty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4008
  class_fixup_offset.empty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4009
  class_fixup_ref.empty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4010
  requested_ics.empty();
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4011
  cp.requested_bsms.empty();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4012
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4013
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4014
cpindex* cpool::getKQIndex() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4015
  char ch = '?';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4016
  if (u->cur_descr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4017
    entry* type = u->cur_descr->descrType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4018
    ch = type->value.b.ptr[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4019
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4020
  byte tag = CONSTANT_Integer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4021
  switch (ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4022
  case 'L': tag = CONSTANT_String;   break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4023
  case 'I': tag = CONSTANT_Integer;  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4024
  case 'J': tag = CONSTANT_Long;     break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4025
  case 'F': tag = CONSTANT_Float;    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4026
  case 'D': tag = CONSTANT_Double;   break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4027
  case 'B': case 'S': case 'C':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4028
  case 'Z': tag = CONSTANT_Integer;  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4029
  default:  abort("bad KQ reference"); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4030
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4031
  return getIndex(tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4032
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4033
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4034
uint unpacker::to_bci(uint bii) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4035
  uint  len =         bcimap.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4036
  uint* map = (uint*) bcimap.base();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4037
  assert(len > 0);  // must be initialized before using to_bci
41572
0b3abcb3879a 8160094: Improve pack200 layout
ksrini
parents: 29591
diff changeset
  4038
  if (len == 0) {
41573
3771d7eaab2c 8160090: Better signature handling in pack200
ksrini
parents: 41572
diff changeset
  4039
    abort("bad bcimap");
3771d7eaab2c 8160090: Better signature handling in pack200
ksrini
parents: 41572
diff changeset
  4040
    return 0;
41572
0b3abcb3879a 8160094: Improve pack200 layout
ksrini
parents: 29591
diff changeset
  4041
  }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4042
  if (bii < len)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4043
    return map[bii];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4044
  // Else it's a fractional or out-of-range BCI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4045
  uint key = bii-len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4046
  for (int i = len; ; i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4047
    if (map[i-1]-(i-1) <= key)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4048
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4049
    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4050
      --bii;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4051
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4052
  return bii;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4053
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4054
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4055
void unpacker::put_stackmap_type() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4056
  int tag = code_StackMapTable_T.getByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4057
  putu1(tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4058
  switch (tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4059
  case 7: // (7) [RCH]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4060
    putref(code_StackMapTable_RC.getRef());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4061
    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4062
  case 8: // (8) [PH]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4063
    putu2(to_bci(code_StackMapTable_P.getInt()));
41572
0b3abcb3879a 8160094: Improve pack200 layout
ksrini
parents: 29591
diff changeset
  4064
    CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4065
    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4066
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4067
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4068
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4069
// Functions for writing code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4070
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4071
maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4072
void unpacker::put_label(int curIP, int size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4073
  code_fixup_type.addByte(size);
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  4074
  code_fixup_offset.add((int)put_empty(size));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4075
  code_fixup_source.add(curIP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4076
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4077
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4078
inline  // called exactly once => inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4079
void unpacker::write_bc_ops() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4080
  bcimap.empty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4081
  code_fixup_type.empty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4082
  code_fixup_offset.empty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4083
  code_fixup_source.empty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4084
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4085
  band* bc_which;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4086
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4087
  byte*  opptr = bc_codes.curRP();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4088
  // No need for oplimit, since the codes are pre-counted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4089
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4090
  size_t codeBase = wpoffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4091
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4092
  bool   isAload;  // copy-out result
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4093
  int    origBC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4094
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4095
  entry* thisClass  = cur_class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4096
  entry* superClass = cur_super;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4097
  entry* newClass   = null;  // class of last _new opcode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4098
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4099
  // overwrite any prior index on these bands; it changes w/ current class:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4100
  bc_thisfield.setIndex(    cp.getFieldIndex( thisClass));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4101
  bc_thismethod.setIndex(   cp.getMethodIndex(thisClass));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4102
  if (superClass != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4103
    bc_superfield.setIndex( cp.getFieldIndex( superClass));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4104
    bc_supermethod.setIndex(cp.getMethodIndex(superClass));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4105
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4106
    NOT_PRODUCT(bc_superfield.setIndex(null));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4107
    NOT_PRODUCT(bc_supermethod.setIndex(null));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4108
  }
16075
32c3bc19bba7 7186957: Improve Pack200 data validation
ksrini
parents: 12544
diff changeset
  4109
  CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4110
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4111
  for (int curIP = 0; ; curIP++) {
41572
0b3abcb3879a 8160094: Improve pack200 layout
ksrini
parents: 29591
diff changeset
  4112
    CHECK;
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  4113
    int curPC = (int)(wpoffset() - codeBase);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4114
    bcimap.add(curPC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4115
    ensure_put_space(10);  // covers most instrs w/o further bounds check
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4116
    int bc = *opptr++ & 0xFF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4117
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4118
    putu1_fast(bc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4119
    // Note:  See '--wp' below for pseudo-bytecodes like bc_end_marker.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4120
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4121
    bool isWide = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4122
    if (bc == bc_wide) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4123
      bc = *opptr++ & 0xFF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4124
      putu1_fast(bc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4125
      isWide = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4127
    switch (bc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4128
    case bc_end_marker:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4129
      --wp;  // not really part of the code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4130
      assert(opptr <= bc_codes.maxRP());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4131
      bc_codes.curRP() = opptr;  // advance over this in bc_codes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4132
      goto doneScanningMethod;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4133
    case bc_tableswitch: // apc:  (df, lo, hi, (hi-lo+1)*(label))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4134
    case bc_lookupswitch: // apc:  (df, nc, nc*(case, label))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4135
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4136
        int caseCount = bc_case_count.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4137
        while (((wpoffset() - codeBase) % 4) != 0)  putu1_fast(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4138
        ensure_put_space(30 + caseCount*8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4139
        put_label(curIP, 4);  //int df = bc_label.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4140
        if (bc == bc_tableswitch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4141
          int lo = bc_case_value.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4142
          int hi = lo + caseCount-1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4143
          putu4(lo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4144
          putu4(hi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4145
          for (int j = 0; j < caseCount; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4146
            put_label(curIP, 4); //int lVal = bc_label.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4147
            //int cVal = lo + j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4148
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4149
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4150
          putu4(caseCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4151
          for (int j = 0; j < caseCount; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4152
            int cVal = bc_case_value.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4153
            putu4(cVal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4154
            put_label(curIP, 4); //int lVal = bc_label.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4155
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4156
        }
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  4157
        assert((int)to_bci(curIP) == curPC);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4158
        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4159
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4160
    case bc_iinc:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4161
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4162
        int local = bc_local.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4163
        int delta = (isWide ? bc_short : bc_byte).getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4164
        if (isWide) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4165
          putu2(local);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4166
          putu2(delta);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4167
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4168
          putu1_fast(local);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4169
          putu1_fast(delta);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4170
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4171
        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4172
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4173
    case bc_sipush:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4174
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4175
        int val = bc_short.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4176
        putu2(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4177
        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4178
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4179
    case bc_bipush:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4180
    case bc_newarray:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4181
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4182
        int val = bc_byte.getByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4183
        putu1_fast(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4184
        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4185
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4186
    case bc_ref_escape:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4187
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4188
        // Note that insnMap has one entry for this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4189
        --wp;  // not really part of the code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4190
        int size = bc_escrefsize.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4191
        entry* ref = bc_escref.getRefN();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4192
        CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4193
        switch (size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4194
        case 1: putu1ref(ref); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4195
        case 2: putref(ref);   break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4196
        default: assert(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4197
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4198
        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4199
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4200
    case bc_byte_escape:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4201
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4202
        // Note that insnMap has one entry for all these bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4203
        --wp;  // not really part of the code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4204
        int size = bc_escsize.getInt();
42687
7a5929518e6a 8170663: Fix minor issues in corelib and servicabilty coding.
goetz
parents: 41573
diff changeset
  4205
        if (size < 0) { assert(false); continue; }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4206
        ensure_put_space(size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4207
        for (int j = 0; j < size; j++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4208
          putu1_fast(bc_escbyte.getByte());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4209
        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4210
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4211
    default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4212
      if (is_invoke_init_op(bc)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4213
        origBC = bc_invokespecial;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4214
        entry* classRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4215
        switch (bc - _invokeinit_op) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4216
        case _invokeinit_self_option:   classRef = thisClass;  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4217
        case _invokeinit_super_option:  classRef = superClass; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4218
        default: assert(bc == _invokeinit_op+_invokeinit_new_option);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4219
        case _invokeinit_new_option:    classRef = newClass;   break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4220
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4221
        wp[-1] = origBC;  // overwrite with origBC
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4222
        int coding = bc_initref.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4223
        // Find the nth overloading of <init> in classRef.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4224
        entry*   ref = null;
16075
32c3bc19bba7 7186957: Improve Pack200 data validation
ksrini
parents: 12544
diff changeset
  4225
        cpindex* ix = cp.getMethodIndex(classRef);
32c3bc19bba7 7186957: Improve Pack200 data validation
ksrini
parents: 12544
diff changeset
  4226
        CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4227
        for (int j = 0, which_init = 0; ; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4228
          ref = (ix == null)? null: ix->get(j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4229
          if (ref == null)  break;  // oops, bad input
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4230
          assert(ref->tag == CONSTANT_Methodref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4231
          if (ref->memberDescr()->descrName() == cp.sym[cpool::s_lt_init_gt]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4232
            if (which_init++ == coding)  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4233
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4234
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4235
        putref(ref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4236
        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4237
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4238
      bc_which = ref_band_for_self_op(bc, isAload, origBC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4239
      if (bc_which != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4240
        if (!isAload) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4241
          wp[-1] = origBC;  // overwrite with origBC
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4242
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4243
          wp[-1] = bc_aload_0;  // overwrite with _aload_0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4244
          // Note: insnMap keeps the _aload_0 separate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4245
          bcimap.add(++curPC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4246
          ++curIP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4247
          putu1_fast(origBC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4248
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4249
        entry* ref = bc_which->getRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4250
        CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4251
        putref(ref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4252
        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4253
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4254
      if (is_branch_op(bc)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4255
        //int lVal = bc_label.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4256
        if (bc < bc_goto_w) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4257
          put_label(curIP, 2);  //putu2(lVal & 0xFFFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4258
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4259
          assert(bc <= bc_jsr_w);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4260
          put_label(curIP, 4);  //putu4(lVal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4261
        }
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  4262
        assert((int)to_bci(curIP) == curPC);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4263
        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4264
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4265
      bc_which = ref_band_for_op(bc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4266
      if (bc_which != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4267
        entry* ref = bc_which->getRefCommon(bc_which->ix, bc_which->nullOK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4268
        CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4269
        if (ref == null && bc_which == &bc_classref) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4270
          // Shorthand for class self-references.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4271
          ref = thisClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4272
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4273
        origBC = bc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4274
        switch (bc) {
16050
1eee624cddb3 8007297: [pack200] allow opcodes with InterfaceMethodRefs
ksrini
parents: 16013
diff changeset
  4275
        case _invokestatic_int:
1eee624cddb3 8007297: [pack200] allow opcodes with InterfaceMethodRefs
ksrini
parents: 16013
diff changeset
  4276
          origBC = bc_invokestatic;
1eee624cddb3 8007297: [pack200] allow opcodes with InterfaceMethodRefs
ksrini
parents: 16013
diff changeset
  4277
          break;
1eee624cddb3 8007297: [pack200] allow opcodes with InterfaceMethodRefs
ksrini
parents: 16013
diff changeset
  4278
        case _invokespecial_int:
1eee624cddb3 8007297: [pack200] allow opcodes with InterfaceMethodRefs
ksrini
parents: 16013
diff changeset
  4279
          origBC = bc_invokespecial;
1eee624cddb3 8007297: [pack200] allow opcodes with InterfaceMethodRefs
ksrini
parents: 16013
diff changeset
  4280
          break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4281
        case bc_ildc:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4282
        case bc_cldc:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4283
        case bc_fldc:
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4284
        case bc_sldc:
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4285
        case bc_qldc:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4286
          origBC = bc_ldc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4287
          break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4288
        case bc_ildc_w:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4289
        case bc_cldc_w:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4290
        case bc_fldc_w:
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4291
        case bc_sldc_w:
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4292
        case bc_qldc_w:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4293
          origBC = bc_ldc_w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4294
          break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4295
        case bc_lldc2_w:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4296
        case bc_dldc2_w:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4297
          origBC = bc_ldc2_w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4298
          break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4299
        case bc_new:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4300
          newClass = ref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4301
          break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4302
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4303
        wp[-1] = origBC;  // overwrite with origBC
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4304
        if (origBC == bc_ldc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4305
          putu1ref(ref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4306
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4307
          putref(ref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4308
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4309
        if (origBC == bc_multianewarray) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4310
          // Copy the trailing byte also.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4311
          int val = bc_byte.getByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4312
          putu1_fast(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4313
        } else if (origBC == bc_invokeinterface) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4314
          int argSize = ref->memberDescr()->descrType()->typeSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4315
          putu1_fast(1 + argSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4316
          putu1_fast(0);
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4317
        } else if (origBC == bc_invokedynamic) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4318
          // pad the next two byte
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4319
          putu1_fast(0);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4320
          putu1_fast(0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4321
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4322
        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4323
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4324
      if (is_local_slot_op(bc)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4325
        int local = bc_local.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4326
        if (isWide) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4327
          putu2(local);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4328
          if (bc == bc_iinc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4329
            int iVal = bc_short.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4330
            putu2(iVal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4331
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4332
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4333
          putu1_fast(local);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4334
          if (bc == bc_iinc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4335
            int iVal = bc_byte.getByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4336
            putu1_fast(iVal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4337
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4338
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4339
        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4340
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4341
      // Random bytecode.  Just copy it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4342
      assert(bc < bc_bytecode_limit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4343
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4344
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4345
 doneScanningMethod:{}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4346
  //bcimap.add(curPC);  // PC limit is already also in map, from bc_end_marker
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4347
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4348
  // Armed with a bcimap, we can now fix up all the labels.
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  4349
  for (int i = 0; i < (int)code_fixup_type.size(); i++) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4350
    int   type   = code_fixup_type.getByte(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4351
    byte* bp     = wp_at(code_fixup_offset.get(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4352
    int   curIP  = code_fixup_source.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4353
    int   destIP = curIP + bc_label.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4354
    int   span   = to_bci(destIP) - to_bci(curIP);
41572
0b3abcb3879a 8160094: Improve pack200 layout
ksrini
parents: 29591
diff changeset
  4355
    CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4356
    switch (type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4357
    case 2: putu2_at(bp, (ushort)span); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4358
    case 4: putu4_at(bp,         span); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4359
    default: assert(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4360
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4361
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4362
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4363
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4364
inline  // called exactly once => inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4365
void unpacker::write_code() {
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  4366
  int j;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4367
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4368
  int max_stack, max_locals, handler_count, cflags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4369
  get_code_header(max_stack, max_locals, handler_count, cflags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4370
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4371
  if (max_stack < 0)      max_stack = code_max_stack.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4372
  if (max_locals < 0)     max_locals = code_max_na_locals.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4373
  if (handler_count < 0)  handler_count = code_handler_count.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4374
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4375
  int siglen = cur_descr->descrType()->typeSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4376
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4377
  if ((cur_descr_flags & ACC_STATIC) == 0)  siglen++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4378
  max_locals += siglen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4379
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4380
  putu2(max_stack);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4381
  putu2(max_locals);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4382
  size_t bcbase = put_empty(4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4383
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4384
  // Write the bytecodes themselves.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4385
  write_bc_ops();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4386
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4387
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4388
  byte* bcbasewp = wp_at(bcbase);
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  4389
  putu4_at(bcbasewp, (int)(wp - (bcbasewp+4)));  // size of code attr
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4390
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4391
  putu2(handler_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4392
  for (j = 0; j < handler_count; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4393
    int bii = code_handler_start_P.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4394
    putu2(to_bci(bii));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4395
    bii    += code_handler_end_PO.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4396
    putu2(to_bci(bii));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4397
    bii    += code_handler_catch_PO.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4398
    putu2(to_bci(bii));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4399
    putref(code_handler_class_RCN.getRefN());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4400
    CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4401
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4402
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4403
  julong indexBits = cflags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4404
  if (cflags < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4405
    bool haveLongFlags = attr_defs[ATTR_CONTEXT_CODE].haveLongFlags();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4406
    indexBits = code_flags_hi.getLong(code_flags_lo, haveLongFlags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4407
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4408
  write_attrs(ATTR_CONTEXT_CODE, indexBits);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4409
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4410
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4411
int unpacker::write_attrs(int attrc, julong indexBits) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4412
  CHECK_0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4413
  if (indexBits == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4414
    // Quick short-circuit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4415
    putu2(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4416
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4417
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4418
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4419
  attr_definitions& ad = attr_defs[attrc];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4420
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4421
  int i, j, j2, idx, count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4422
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4423
  int oiCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4424
  if (ad.isPredefined(X_ATTR_OVERFLOW)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4425
      && (indexBits & ((julong)1<<X_ATTR_OVERFLOW)) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4426
    indexBits -= ((julong)1<<X_ATTR_OVERFLOW);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4427
    oiCount = ad.xxx_attr_count().getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4428
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4429
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4430
  int bitIndexes[X_ATTR_LIMIT_FLAGS_HI];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4431
  int biCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4432
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4433
  // Fill bitIndexes with index bits, in order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4434
  for (idx = 0; indexBits != 0; idx++, indexBits >>= 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4435
    if ((indexBits & 1) != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4436
      bitIndexes[biCount++] = idx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4437
  }
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  4438
  assert(biCount <= (int)lengthof(bitIndexes));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4439
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4440
  // Write a provisional attribute count, perhaps to be corrected later.
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  4441
  int naOffset = (int)wpoffset();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4442
  int na0 = biCount + oiCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4443
  putu2(na0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4444
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4445
  int na = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4446
  for (i = 0; i < na0; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4447
    if (i < biCount)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4448
      idx = bitIndexes[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4449
    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4450
      idx = ad.xxx_attr_indexes().getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4451
    assert(ad.isIndex(idx));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4452
    entry* aname = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4453
    entry* ref;  // scratch
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4454
    size_t abase = put_empty(2+4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4455
    CHECK_0;
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  4456
    if (idx < (int)ad.flag_limit && ad.isPredefined(idx)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4457
      // Switch on the attrc and idx simultaneously.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4458
      switch (ADH_BYTE(attrc, idx)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4459
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4460
      case ADH_BYTE(ATTR_CONTEXT_CLASS,  X_ATTR_OVERFLOW):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4461
      case ADH_BYTE(ATTR_CONTEXT_FIELD,  X_ATTR_OVERFLOW):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4462
      case ADH_BYTE(ATTR_CONTEXT_METHOD, X_ATTR_OVERFLOW):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4463
      case ADH_BYTE(ATTR_CONTEXT_CODE,   X_ATTR_OVERFLOW):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4464
        // no attribute at all, so back up on this one
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4465
        wp = wp_at(abase);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4466
        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4467
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4468
      case ADH_BYTE(ATTR_CONTEXT_CLASS, CLASS_ATTR_ClassFile_version):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4469
        cur_class_minver = class_ClassFile_version_minor_H.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4470
        cur_class_majver = class_ClassFile_version_major_H.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4471
        // back up; not a real attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4472
        wp = wp_at(abase);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4473
        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4474
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4475
      case ADH_BYTE(ATTR_CONTEXT_CLASS, CLASS_ATTR_InnerClasses):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4476
        // note the existence of this attr, but save for later
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4477
        if (cur_class_has_local_ics)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4478
          abort("too many InnerClasses attrs");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4479
        cur_class_has_local_ics = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4480
        wp = wp_at(abase);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4481
        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4482
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4483
      case ADH_BYTE(ATTR_CONTEXT_CLASS, CLASS_ATTR_SourceFile):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4484
        aname = cp.sym[cpool::s_SourceFile];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4485
        ref = class_SourceFile_RUN.getRefN();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4486
        CHECK_0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4487
        if (ref == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4488
          bytes& n = cur_class->ref(0)->value.b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4489
          // parse n = (<pkg>/)*<outer>?($<id>)*
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  4490
          int pkglen = lastIndexOf(SLASH_MIN,  SLASH_MAX,  n, (int)n.len)+1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4491
          bytes prefix = n.slice(pkglen, n.len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4492
          for (;;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4493
            // Work backwards, finding all '$', '#', etc.
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  4494
            int dollar = lastIndexOf(DOLLAR_MIN, DOLLAR_MAX, prefix, (int)prefix.len);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4495
            if (dollar < 0)  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4496
            prefix = prefix.slice(0, dollar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4497
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4498
          const char* suffix = ".java";
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  4499
          int len = (int)(prefix.len + strlen(suffix));
5191
79b41f733e33 6902299: Java JAR "unpack200" must verify input parameters
ksrini
parents: 3463
diff changeset
  4500
          bytes name; name.set(T_NEW(byte, add_size(len, 1)), len);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4501
          name.strcat(prefix).strcat(suffix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4502
          ref = cp.ensureUtf8(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4503
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4504
        putref(ref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4505
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4506
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4507
      case ADH_BYTE(ATTR_CONTEXT_CLASS, CLASS_ATTR_EnclosingMethod):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4508
        aname = cp.sym[cpool::s_EnclosingMethod];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4509
        putref(class_EnclosingMethod_RC.getRefN());
16075
32c3bc19bba7 7186957: Improve Pack200 data validation
ksrini
parents: 12544
diff changeset
  4510
        CHECK_0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4511
        putref(class_EnclosingMethod_RDN.getRefN());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4512
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4513
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4514
      case ADH_BYTE(ATTR_CONTEXT_FIELD, FIELD_ATTR_ConstantValue):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4515
        aname = cp.sym[cpool::s_ConstantValue];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4516
        putref(field_ConstantValue_KQ.getRefUsing(cp.getKQIndex()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4517
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4518
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4519
      case ADH_BYTE(ATTR_CONTEXT_METHOD, METHOD_ATTR_Code):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4520
        aname = cp.sym[cpool::s_Code];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4521
        write_code();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4522
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4523
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4524
      case ADH_BYTE(ATTR_CONTEXT_METHOD, METHOD_ATTR_Exceptions):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4525
        aname = cp.sym[cpool::s_Exceptions];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4526
        putu2(count = method_Exceptions_N.getInt());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4527
        for (j = 0; j < count; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4528
          putref(method_Exceptions_RC.getRefN());
16075
32c3bc19bba7 7186957: Improve Pack200 data validation
ksrini
parents: 12544
diff changeset
  4529
          CHECK_0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4530
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4531
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4532
15261
c5b882836677 8005252: pack200 should support MethodParameters
ksrini
parents: 12544
diff changeset
  4533
      case ADH_BYTE(ATTR_CONTEXT_METHOD, METHOD_ATTR_MethodParameters):
c5b882836677 8005252: pack200 should support MethodParameters
ksrini
parents: 12544
diff changeset
  4534
        aname = cp.sym[cpool::s_MethodParameters];
c5b882836677 8005252: pack200 should support MethodParameters
ksrini
parents: 12544
diff changeset
  4535
        putu1(count = method_MethodParameters_NB.getByte());
c5b882836677 8005252: pack200 should support MethodParameters
ksrini
parents: 12544
diff changeset
  4536
        for (j = 0; j < count; j++) {
c5b882836677 8005252: pack200 should support MethodParameters
ksrini
parents: 12544
diff changeset
  4537
          putref(method_MethodParameters_name_RUN.getRefN());
16013
3569e84e7429 8008262: pack200 should support MethodParameters - part 2
ksrini
parents: 15652
diff changeset
  4538
          putu2(method_MethodParameters_flag_FH.getInt());
15261
c5b882836677 8005252: pack200 should support MethodParameters
ksrini
parents: 12544
diff changeset
  4539
        }
c5b882836677 8005252: pack200 should support MethodParameters
ksrini
parents: 12544
diff changeset
  4540
        break;
c5b882836677 8005252: pack200 should support MethodParameters
ksrini
parents: 12544
diff changeset
  4541
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4542
      case ADH_BYTE(ATTR_CONTEXT_CODE, CODE_ATTR_StackMapTable):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4543
        aname = cp.sym[cpool::s_StackMapTable];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4544
        // (keep this code aligned with its brother in unpacker::read_attrs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4545
        putu2(count = code_StackMapTable_N.getInt());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4546
        for (j = 0; j < count; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4547
          int tag = code_StackMapTable_frame_T.getByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4548
          putu1(tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4549
          if (tag <= 127) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4550
            // (64-127)  [(2)]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4551
            if (tag >= 64)  put_stackmap_type();
41572
0b3abcb3879a 8160094: Improve pack200 layout
ksrini
parents: 29591
diff changeset
  4552
            CHECK_0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4553
          } else if (tag <= 251) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4554
            // (247)     [(1)(2)]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4555
            // (248-251) [(1)]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4556
            if (tag >= 247)  putu2(code_StackMapTable_offset.getInt());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4557
            if (tag == 247)  put_stackmap_type();
41572
0b3abcb3879a 8160094: Improve pack200 layout
ksrini
parents: 29591
diff changeset
  4558
            CHECK_0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4559
          } else if (tag <= 254) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4560
            // (252)     [(1)(2)]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4561
            // (253)     [(1)(2)(2)]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4562
            // (254)     [(1)(2)(2)(2)]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4563
            putu2(code_StackMapTable_offset.getInt());
16075
32c3bc19bba7 7186957: Improve Pack200 data validation
ksrini
parents: 12544
diff changeset
  4564
            CHECK_0;
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  4565
            for (int k = (tag - 251); k > 0; k--) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4566
              put_stackmap_type();
16075
32c3bc19bba7 7186957: Improve Pack200 data validation
ksrini
parents: 12544
diff changeset
  4567
              CHECK_0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4568
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4569
          } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4570
            // (255)     [(1)NH[(2)]NH[(2)]]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4571
            putu2(code_StackMapTable_offset.getInt());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4572
            putu2(j2 = code_StackMapTable_local_N.getInt());
16075
32c3bc19bba7 7186957: Improve Pack200 data validation
ksrini
parents: 12544
diff changeset
  4573
            while (j2-- > 0) {put_stackmap_type(); CHECK_0;}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4574
            putu2(j2 = code_StackMapTable_stack_N.getInt());
16075
32c3bc19bba7 7186957: Improve Pack200 data validation
ksrini
parents: 12544
diff changeset
  4575
            while (j2-- > 0)  {put_stackmap_type(); CHECK_0;}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4576
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4577
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4578
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4579
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4580
      case ADH_BYTE(ATTR_CONTEXT_CODE, CODE_ATTR_LineNumberTable):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4581
        aname = cp.sym[cpool::s_LineNumberTable];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4582
        putu2(count = code_LineNumberTable_N.getInt());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4583
        for (j = 0; j < count; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4584
          putu2(to_bci(code_LineNumberTable_bci_P.getInt()));
41572
0b3abcb3879a 8160094: Improve pack200 layout
ksrini
parents: 29591
diff changeset
  4585
          CHECK_0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4586
          putu2(code_LineNumberTable_line.getInt());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4587
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4588
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4589
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4590
      case ADH_BYTE(ATTR_CONTEXT_CODE, CODE_ATTR_LocalVariableTable):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4591
        aname = cp.sym[cpool::s_LocalVariableTable];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4592
        putu2(count = code_LocalVariableTable_N.getInt());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4593
        for (j = 0; j < count; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4594
          int bii = code_LocalVariableTable_bci_P.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4595
          int bci = to_bci(bii);
41572
0b3abcb3879a 8160094: Improve pack200 layout
ksrini
parents: 29591
diff changeset
  4596
          CHECK_0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4597
          putu2(bci);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4598
          bii    += code_LocalVariableTable_span_O.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4599
          putu2(to_bci(bii) - bci);
41572
0b3abcb3879a 8160094: Improve pack200 layout
ksrini
parents: 29591
diff changeset
  4600
          CHECK_0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4601
          putref(code_LocalVariableTable_name_RU.getRefN());
16075
32c3bc19bba7 7186957: Improve Pack200 data validation
ksrini
parents: 12544
diff changeset
  4602
          CHECK_0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4603
          putref(code_LocalVariableTable_type_RS.getRefN());
16075
32c3bc19bba7 7186957: Improve Pack200 data validation
ksrini
parents: 12544
diff changeset
  4604
          CHECK_0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4605
          putu2(code_LocalVariableTable_slot.getInt());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4606
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4607
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4608
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4609
      case ADH_BYTE(ATTR_CONTEXT_CODE, CODE_ATTR_LocalVariableTypeTable):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4610
        aname = cp.sym[cpool::s_LocalVariableTypeTable];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4611
        putu2(count = code_LocalVariableTypeTable_N.getInt());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4612
        for (j = 0; j < count; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4613
          int bii = code_LocalVariableTypeTable_bci_P.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4614
          int bci = to_bci(bii);
41572
0b3abcb3879a 8160094: Improve pack200 layout
ksrini
parents: 29591
diff changeset
  4615
          CHECK_0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4616
          putu2(bci);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4617
          bii    += code_LocalVariableTypeTable_span_O.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4618
          putu2(to_bci(bii) - bci);
41572
0b3abcb3879a 8160094: Improve pack200 layout
ksrini
parents: 29591
diff changeset
  4619
          CHECK_0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4620
          putref(code_LocalVariableTypeTable_name_RU.getRefN());
16075
32c3bc19bba7 7186957: Improve Pack200 data validation
ksrini
parents: 12544
diff changeset
  4621
          CHECK_0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4622
          putref(code_LocalVariableTypeTable_type_RS.getRefN());
16075
32c3bc19bba7 7186957: Improve Pack200 data validation
ksrini
parents: 12544
diff changeset
  4623
          CHECK_0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4624
          putu2(code_LocalVariableTypeTable_slot.getInt());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4625
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4626
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4627
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4628
      case ADH_BYTE(ATTR_CONTEXT_CLASS, X_ATTR_Signature):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4629
        aname = cp.sym[cpool::s_Signature];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4630
        putref(class_Signature_RS.getRefN());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4631
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4632
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4633
      case ADH_BYTE(ATTR_CONTEXT_FIELD, X_ATTR_Signature):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4634
        aname = cp.sym[cpool::s_Signature];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4635
        putref(field_Signature_RS.getRefN());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4636
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4637
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4638
      case ADH_BYTE(ATTR_CONTEXT_METHOD, X_ATTR_Signature):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4639
        aname = cp.sym[cpool::s_Signature];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4640
        putref(method_Signature_RS.getRefN());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4641
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4642
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4643
      case ADH_BYTE(ATTR_CONTEXT_CLASS,  X_ATTR_Deprecated):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4644
      case ADH_BYTE(ATTR_CONTEXT_FIELD,  X_ATTR_Deprecated):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4645
      case ADH_BYTE(ATTR_CONTEXT_METHOD, X_ATTR_Deprecated):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4646
        aname = cp.sym[cpool::s_Deprecated];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4647
        // no data
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4648
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4649
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4650
    }
16075
32c3bc19bba7 7186957: Improve Pack200 data validation
ksrini
parents: 12544
diff changeset
  4651
    CHECK_0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4652
    if (aname == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4653
      // Unparse a compressor-defined attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4654
      layout_definition* lo = ad.getLayout(idx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4655
      if (lo == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4656
        abort("bad layout index");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4657
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4658
      }
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  4659
      assert((int)lo->idx == idx);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4660
      aname = lo->nameEntry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4661
      if (aname == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4662
        bytes nameb; nameb.set(lo->name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4663
        aname = cp.ensureUtf8(nameb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4664
        // Cache the name entry for next time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4665
        lo->nameEntry = aname;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4666
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4667
      // Execute all the layout elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4668
      band** bands = lo->bands();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4669
      if (lo->hasCallables()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4670
        band& cble = *bands[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4671
        assert(cble.le_kind == EK_CBLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4672
        bands = cble.le_body;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4673
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4674
      putlayout(bands);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4675
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4676
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4677
    if (aname == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4678
      abort("bad attribute index");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4679
    CHECK_0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4680
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4681
    byte* wp1 = wp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4682
    wp = wp_at(abase);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4683
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4684
    // DTRT if this attr is on the strip-list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4685
    // (Note that we emptied the data out of the band first.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4686
    if (ad.strip_names.contains(aname)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4687
      continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4688
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4689
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4690
    // patch the name and length
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4691
    putref(aname);
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  4692
    putu4((int)(wp1 - (wp+4)));  // put the attr size
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4693
    wp = wp1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4694
    na++;  // count the attrs actually written
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4695
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4696
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4697
  if (na != na0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4698
    // Refresh changed count.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4699
    putu2_at(wp_at(naOffset), na);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4700
  return na;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4701
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4702
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4703
void unpacker::write_members(int num, int attrc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4704
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4705
  attr_definitions& ad = attr_defs[attrc];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4706
  band& member_flags_hi = ad.xxx_flags_hi();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4707
  band& member_flags_lo = ad.xxx_flags_lo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4708
  band& member_descr = (&member_flags_hi)[e_field_descr-e_field_flags_hi];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4709
  assert(endsWith(member_descr.name, "_descr"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4710
  assert(endsWith(member_flags_lo.name, "_flags_lo"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4711
  assert(endsWith(member_flags_lo.name, "_flags_lo"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4712
  bool haveLongFlags = ad.haveLongFlags();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4713
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4714
  putu2(num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4715
  julong indexMask = attr_defs[attrc].flagIndexMask();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4716
  for (int i = 0; i < num; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4717
    julong mflags = member_flags_hi.getLong(member_flags_lo, haveLongFlags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4718
    entry* mdescr = member_descr.getRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4719
    cur_descr = mdescr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4720
    putu2(cur_descr_flags = (ushort)(mflags & ~indexMask));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4721
    CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4722
    putref(mdescr->descrName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4723
    putref(mdescr->descrType());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4724
    write_attrs(attrc, (mflags & indexMask));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4725
    CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4726
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4727
  cur_descr = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4728
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4729
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4730
extern "C"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4731
int raw_address_cmp(const void* p1p, const void* p2p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4732
  void* p1 = *(void**) p1p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4733
  void* p2 = *(void**) p2p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4734
  return (p1 > p2)? 1: (p1 < p2)? -1: 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4735
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4736
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4737
/*
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4738
 * writes the InnerClass attributes and returns the updated attribute
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4739
 */
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4740
int  unpacker::write_ics(int naOffset, int na) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4741
#ifdef ASSERT
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4742
  for (int i = 0; i < ic_count; i++) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4743
    assert(!ics[i].requested);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4744
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4745
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4746
  // First, consult the global table and the local constant pool,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4747
  // and decide on the globally implied inner classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4748
  // (Note that we read the cpool's outputIndex fields, but we
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4749
  // do not yet write them, since the local IC attribute might
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4750
  // reverse a global decision to declare an IC.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4751
  assert(requested_ics.length() == 0);  // must start out empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4752
  // Always include all members of the current class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4753
  for (inner_class* child = cp.getFirstChildIC(cur_class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4754
       child != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4755
       child = cp.getNextChildIC(child)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4756
    child->requested = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4757
    requested_ics.add(child);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4758
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4759
  // And, for each inner class mentioned in the constant pool,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4760
  // include it and all its outers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4761
  int    noes =           cp.outputEntries.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4762
  entry** oes = (entry**) cp.outputEntries.base();
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4763
  for (int i = 0; i < noes; i++) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4764
    entry& e = *oes[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4765
    if (e.tag != CONSTANT_Class)  continue;  // wrong sort
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4766
    for (inner_class* ic = cp.getIC(&e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4767
         ic != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4768
         ic = cp.getIC(ic->outer)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4769
      if (ic->requested)  break;  // already processed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4770
      ic->requested = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4771
      requested_ics.add(ic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4772
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4773
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4774
  int local_ics = requested_ics.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4775
  // Second, consult a local attribute (if any) and adjust the global set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4776
  inner_class* extra_ics = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4777
  int      num_extra_ics = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4778
  if (cur_class_has_local_ics) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4779
    // adjust the set of ICs by symmetric set difference w/ the locals
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4780
    num_extra_ics = class_InnerClasses_N.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4781
    if (num_extra_ics == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4782
      // Explicit zero count has an irregular meaning:  It deletes the attr.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4783
      local_ics = 0;  // (short-circuit all tests of requested bits)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4784
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4785
      extra_ics = T_NEW(inner_class, num_extra_ics);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4786
      // Note:  extra_ics will be freed up by next call to get_next_file().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4787
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4788
  }
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4789
  for (int i = 0; i < num_extra_ics; i++) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4790
    inner_class& extra_ic = extra_ics[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4791
    extra_ic.inner = class_InnerClasses_RC.getRef();
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4792
    CHECK_0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4793
    // Find the corresponding equivalent global IC:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4794
    inner_class* global_ic = cp.getIC(extra_ic.inner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4795
    int flags = class_InnerClasses_F.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4796
    if (flags == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4797
      // The extra IC is simply a copy of a global IC.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4798
      if (global_ic == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4799
        abort("bad reference to inner class");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4800
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4801
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4802
      extra_ic = (*global_ic);  // fill in rest of fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4803
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4804
      flags &= ~ACC_IC_LONG_FORM;  // clear high bit if set to get clean zero
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4805
      extra_ic.flags = flags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4806
      extra_ic.outer = class_InnerClasses_outer_RCN.getRefN();
16075
32c3bc19bba7 7186957: Improve Pack200 data validation
ksrini
parents: 12544
diff changeset
  4807
      CHECK_0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4808
      extra_ic.name  = class_InnerClasses_name_RUN.getRefN();
16075
32c3bc19bba7 7186957: Improve Pack200 data validation
ksrini
parents: 12544
diff changeset
  4809
      CHECK_0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4810
      // Detect if this is an exact copy of the global tuple.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4811
      if (global_ic != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4812
        if (global_ic->flags != extra_ic.flags ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4813
            global_ic->outer != extra_ic.outer ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4814
            global_ic->name  != extra_ic.name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4815
          global_ic = null;  // not really the same, so break the link
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4816
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4817
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4818
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4819
    if (global_ic != null && global_ic->requested) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4820
      // This local repetition reverses the globally implied request.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4821
      global_ic->requested = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4822
      extra_ic.requested = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4823
      local_ics -= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4824
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4825
      // The global either does not exist, or is not yet requested.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4826
      extra_ic.requested = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4827
      local_ics += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4828
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4829
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4830
  // Finally, if there are any that survived, put them into an attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4831
  // (Note that a zero-count attribute is always deleted.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4832
  // The putref calls below will tell the constant pool to add any
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4833
  // necessary local CP references to support the InnerClasses attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4834
  // This step must be the last round of additions to the local CP.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4835
  if (local_ics > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4836
    // append the new attribute:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4837
    putref(cp.sym[cpool::s_InnerClasses]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4838
    putu4(2 + 2*4*local_ics);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4839
    putu2(local_ics);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4840
    PTRLIST_QSORT(requested_ics, raw_address_cmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4841
    int num_global_ics = requested_ics.length();
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4842
    for (int i = -num_global_ics; i < num_extra_ics; i++) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4843
      inner_class* ic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4844
      if (i < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4845
        ic = (inner_class*) requested_ics.get(num_global_ics+i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4846
      else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4847
        ic = &extra_ics[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4848
      if (ic->requested) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4849
        putref(ic->inner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4850
        putref(ic->outer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4851
        putref(ic->name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4852
        putu2(ic->flags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4853
        NOT_PRODUCT(local_ics--);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4854
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4855
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4856
    assert(local_ics == 0);           // must balance
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4857
    putu2_at(wp_at(naOffset), ++na);  // increment class attr count
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4858
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4859
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4860
  // Tidy up global 'requested' bits:
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4861
  for (int i = requested_ics.length(); --i >= 0; ) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4862
    inner_class* ic = (inner_class*) requested_ics.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4863
    ic->requested = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4864
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4865
  requested_ics.empty();
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4866
  return na;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4867
}
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4868
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4869
/*
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4870
 * Writes the BootstrapMethods attribute and returns the updated attribute count
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4871
 */
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4872
int unpacker::write_bsms(int naOffset, int na) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4873
  cur_class_local_bsm_count = cp.requested_bsms.length();
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4874
  if (cur_class_local_bsm_count > 0) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4875
    int    noes =           cp.outputEntries.length();
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4876
    entry** oes = (entry**) cp.outputEntries.base();
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4877
    PTRLIST_QSORT(cp.requested_bsms, outputEntry_cmp);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4878
    // append the BootstrapMethods attribute (after the InnerClasses attr):
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4879
    putref(cp.sym[cpool::s_BootstrapMethods]);
15652
edc2e7c83709 8007902: [unpack200] incorrect BootstrapMethods attribute
ksrini
parents: 15261
diff changeset
  4880
    // make a note of the offset, for lazy patching
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4881
    int sizeOffset = (int)wpoffset();
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4882
    putu4(-99);  // attr size will be patched
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4883
    putu2(cur_class_local_bsm_count);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4884
    int written_bsms = 0;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4885
    for (int i = 0 ; i < cur_class_local_bsm_count ; i++) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4886
      entry* e = (entry*)cp.requested_bsms.get(i);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4887
      assert(e->outputIndex != REQUESTED_NONE);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4888
      // output index is the index within the array
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4889
      e->outputIndex = i;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4890
      putref(e->refs[0]);  // bsm
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4891
      putu2(e->nrefs-1);  // number of args after bsm
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4892
      for (int j = 1; j < e->nrefs; j++) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4893
        putref(e->refs[j]);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4894
      }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4895
      written_bsms += 1;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4896
    }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4897
    assert(written_bsms == cur_class_local_bsm_count);  // else insane
15652
edc2e7c83709 8007902: [unpack200] incorrect BootstrapMethods attribute
ksrini
parents: 15261
diff changeset
  4898
    byte* sizewp = wp_at(sizeOffset);
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4899
    putu4_at(sizewp, (int)(wp - (sizewp+4)));  // size of code attr
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4900
    putu2_at(wp_at(naOffset), ++na);  // increment class attr count
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4901
  }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4902
  return na;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4903
}
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4904
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4905
void unpacker::write_classfile_tail() {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4906
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4907
  cur_classfile_tail.empty();
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4908
  set_output(&cur_classfile_tail);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4909
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4910
  int i, num;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4911
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4912
  attr_definitions& ad = attr_defs[ATTR_CONTEXT_CLASS];
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4913
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4914
  bool haveLongFlags = ad.haveLongFlags();
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4915
  julong kflags = class_flags_hi.getLong(class_flags_lo, haveLongFlags);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4916
  julong indexMask = ad.flagIndexMask();
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4917
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4918
  cur_class = class_this.getRef();
16075
32c3bc19bba7 7186957: Improve Pack200 data validation
ksrini
parents: 12544
diff changeset
  4919
  CHECK;
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4920
  cur_super = class_super.getRef();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4921
  CHECK;
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4922
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4923
  if (cur_super == cur_class)  cur_super = null;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4924
  // special representation for java/lang/Object
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4925
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4926
  putu2((ushort)(kflags & ~indexMask));
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4927
  putref(cur_class);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4928
  putref(cur_super);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4929
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4930
  putu2(num = class_interface_count.getInt());
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4931
  for (i = 0; i < num; i++) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4932
    putref(class_interface.getRef());
16075
32c3bc19bba7 7186957: Improve Pack200 data validation
ksrini
parents: 12544
diff changeset
  4933
    CHECK;
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4934
  }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4935
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4936
  write_members(class_field_count.getInt(),  ATTR_CONTEXT_FIELD);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4937
  write_members(class_method_count.getInt(), ATTR_CONTEXT_METHOD);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4938
  CHECK;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4939
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4940
  cur_class_has_local_ics = false;  // may be set true by write_attrs
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4941
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4942
  int naOffset = (int)wpoffset();   // note the attr count location
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4943
  int na = write_attrs(ATTR_CONTEXT_CLASS, (kflags & indexMask));
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4944
  CHECK;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4945
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4946
  na = write_bsms(naOffset, na);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4947
  CHECK;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4948
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4949
  // choose which inner classes (if any) pertain to k:
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4950
  na = write_ics(naOffset, na);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4951
  CHECK;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4952
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4953
  close_output();
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  4954
  cp.computeOutputIndexes();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4955
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4956
  // rewrite CP references in the tail
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4957
  int nextref = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4958
  for (i = 0; i < (int)class_fixup_type.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4959
    int    type = class_fixup_type.getByte(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4960
    byte*  fixp = wp_at(class_fixup_offset.get(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4961
    entry* e    = (entry*)class_fixup_ref.get(nextref++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4962
    int    idx  = e->getOutputIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4963
    switch (type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4964
    case 1:  putu1_at(fixp, idx);  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4965
    case 2:  putu2_at(fixp, idx);  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4966
    default: assert(false);  // should not reach here
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4967
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4968
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4969
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4970
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4971
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4972
void unpacker::write_classfile_head() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4973
  cur_classfile_head.empty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4974
  set_output(&cur_classfile_head);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4975
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4976
  putu4(JAVA_MAGIC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4977
  putu2(cur_class_minver);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4978
  putu2(cur_class_majver);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4979
  putu2(cp.outputIndexLimit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4980
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4981
  int checkIndex = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4982
  int    noes =           cp.outputEntries.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4983
  entry** oes = (entry**) cp.outputEntries.base();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4984
  for (int i = 0; i < noes; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4985
    entry& e = *oes[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4986
    assert(e.getOutputIndex() == checkIndex++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4987
    byte tag = e.tag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4988
    assert(tag != CONSTANT_Signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4989
    putu1(tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4990
    switch (tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4991
    case CONSTANT_Utf8:
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  4992
      putu2((int)e.value.b.len);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4993
      put_bytes(e.value.b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4994
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4995
    case CONSTANT_Integer:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4996
    case CONSTANT_Float:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4997
      putu4(e.value.i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4998
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4999
    case CONSTANT_Long:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5000
    case CONSTANT_Double:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5001
      putu8(e.value.l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5002
      assert(checkIndex++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5003
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5004
    case CONSTANT_Class:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5005
    case CONSTANT_String:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5006
      // just write the ref
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5007
      putu2(e.refs[0]->getOutputIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5008
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5009
    case CONSTANT_Fieldref:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5010
    case CONSTANT_Methodref:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5011
    case CONSTANT_InterfaceMethodref:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5012
    case CONSTANT_NameandType:
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  5013
    case CONSTANT_InvokeDynamic:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5014
      putu2(e.refs[0]->getOutputIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5015
      putu2(e.refs[1]->getOutputIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5016
      break;
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  5017
    case CONSTANT_MethodHandle:
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  5018
        putu1(e.value.i);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  5019
        putu2(e.refs[0]->getOutputIndex());
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  5020
        break;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  5021
    case CONSTANT_MethodType:
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  5022
      putu2(e.refs[0]->getOutputIndex());
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  5023
      break;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  5024
    case CONSTANT_BootstrapMethod: // should not happen
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5025
    default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5026
      abort(ERROR_INTERNAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5027
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5028
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5029
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5030
#ifndef PRODUCT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5031
  total_cp_size[0] += cp.outputIndexLimit;
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  5032
  total_cp_size[1] += (int)cur_classfile_head.size();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5033
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5034
  close_output();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5035
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5036
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5037
unpacker::file* unpacker::get_next_file() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5038
  CHECK_0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5039
  free_temps();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5040
  if (files_remaining == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5041
    // Leave a clue that we're exhausted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5042
    cur_file.name = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5043
    cur_file.size = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5044
    if (archive_size != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5045
      julong predicted_size = unsized_bytes_read + archive_size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5046
      if (predicted_size != bytes_read)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5047
        abort("archive header had incorrect size");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5048
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5049
    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5050
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5051
  files_remaining -= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5052
  assert(files_written < file_count || classes_written < class_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5053
  cur_file.name = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5054
  cur_file.size = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5055
  cur_file.modtime = default_file_modtime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5056
  cur_file.options = default_file_options;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5057
  cur_file.data[0].set(null, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5058
  cur_file.data[1].set(null, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5059
  if (files_written < file_count) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5060
    entry* e = file_name.getRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5061
    CHECK_0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5062
    cur_file.name = e->utf8String();
41573
3771d7eaab2c 8160090: Better signature handling in pack200
ksrini
parents: 41572
diff changeset
  5063
    CHECK_0;
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  5064
    bool haveLongSize = (testBit(archive_options, AO_HAVE_FILE_SIZE_HI));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5065
    cur_file.size = file_size_hi.getLong(file_size_lo, haveLongSize);
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  5066
    if (testBit(archive_options, AO_HAVE_FILE_MODTIME))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5067
      cur_file.modtime += file_modtime.getInt();  //relative to archive modtime
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10907
diff changeset
  5068
    if (testBit(archive_options, AO_HAVE_FILE_OPTIONS))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5069
      cur_file.options |= file_options.getInt() & ~suppress_file_options;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5070
  } else if (classes_written < class_count) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5071
    // there is a class for a missing file record
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5072
    cur_file.options |= FO_IS_CLASS_STUB;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5073
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5074
  if ((cur_file.options & FO_IS_CLASS_STUB) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5075
    assert(classes_written < class_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5076
    classes_written += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5077
    if (cur_file.size != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5078
      abort("class file size transmitted");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5079
      return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5080
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5081
    reset_cur_classfile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5082
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5083
    // write the meat of the classfile:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5084
    write_classfile_tail();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5085
    cur_file.data[1] = cur_classfile_tail.b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5086
    CHECK_0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5087
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5088
    // write the CP of the classfile, second:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5089
    write_classfile_head();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5090
    cur_file.data[0] = cur_classfile_head.b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5091
    CHECK_0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5092
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5093
    cur_file.size += cur_file.data[0].len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5094
    cur_file.size += cur_file.data[1].len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5095
    if (cur_file.name[0] == '\0') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5096
      bytes& prefix = cur_class->ref(0)->value.b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5097
      const char* suffix = ".class";
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  5098
      int len = (int)(prefix.len + strlen(suffix));
5191
79b41f733e33 6902299: Java JAR "unpack200" must verify input parameters
ksrini
parents: 3463
diff changeset
  5099
      bytes name; name.set(T_NEW(byte, add_size(len, 1)), len);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5100
      cur_file.name = name.strcat(prefix).strcat(suffix).strval();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5102
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5103
    // If there is buffered file data, produce a pointer to it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5104
    if (cur_file.size != (size_t) cur_file.size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5105
      // Silly size specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5106
      abort("resource file too large");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5107
      return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5108
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5109
    size_t rpleft = input_remaining();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5110
    if (rpleft > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5111
      if (rpleft > cur_file.size)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5112
        rpleft = (size_t) cur_file.size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5113
      cur_file.data[0].set(rp, rpleft);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5114
      rp += rpleft;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5116
    if (rpleft < cur_file.size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5117
      // Caller must read the rest.
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  5118
      size_t fleft = (size_t)cur_file.size - rpleft;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5119
      bytes_read += fleft;  // Credit it to the overall archive size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5120
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5121
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5122
  CHECK_0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5123
  bytes_written += cur_file.size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5124
  files_written += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5125
  return &cur_file;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5126
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5127
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5128
// Write a file to jarout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5129
void unpacker::write_file_to_jar(unpacker::file* f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5130
  size_t htsize = f->data[0].len + f->data[1].len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5131
  julong fsize = f->size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5132
#ifndef PRODUCT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5133
  if (nowrite NOT_PRODUCT(|| skipfiles-- > 0)) {
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  5134
    PRINTCR((2,"would write %d bytes to %s", (int) fsize, f->name));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5135
    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5136
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5137
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5138
  if (htsize == fsize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5139
    jarout->addJarEntry(f->name, f->deflate_hint(), f->modtime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5140
                        f->data[0], f->data[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5141
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5142
    assert(input_remaining() == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5143
    bytes part1, part2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5144
    part1.len = f->data[0].len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5145
    part1.set(T_NEW(byte, part1.len), part1.len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5146
    part1.copyFrom(f->data[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5147
    assert(f->data[1].len == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5148
    part2.set(null, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5149
    size_t fleft = (size_t) fsize - part1.len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5150
    assert(bytes_read > fleft);  // part2 already credited by get_next_file
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5151
    bytes_read -= fleft;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5152
    if (fleft > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5153
      // Must read some more.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5154
      if (live_input) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5155
        // Stop using the input buffer.  Make a new one:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5156
        if (free_input)  input.free();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5157
        input.init(fleft > (1<<12) ? fleft : (1<<12));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5158
        free_input = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5159
        live_input = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5160
      } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5161
        // Make it large enough.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5162
        assert(free_input);  // must be reallocable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5163
        input.ensureSize(fleft);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5164
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5165
      rplimit = rp = input.base();
5191
79b41f733e33 6902299: Java JAR "unpack200" must verify input parameters
ksrini
parents: 3463
diff changeset
  5166
      CHECK;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5167
      input.setLimit(rp + fleft);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5168
      if (!ensure_input(fleft))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5169
        abort("EOF reading resource file");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5170
      part2.ptr = input_scan();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5171
      part2.len = input_remaining();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5172
      rplimit = rp = input.base();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5173
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5174
    jarout->addJarEntry(f->name, f->deflate_hint(), f->modtime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5175
                        part1, part2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5176
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5177
  if (verbose >= 3) {
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  5178
    fprintf(errstrm, "Wrote "
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  5179
                     LONG_LONG_FORMAT " bytes to: %s\n", fsize, f->name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5180
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5181
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5182
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5183
// Redirect the stdio to the specified file in the unpack.log.file option
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5184
void unpacker::redirect_stdio() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5185
  if (log_file == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5186
    log_file = LOGFILE_STDOUT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5187
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5188
  if (log_file == errstrm_name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5189
    // Nothing more to be done.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5190
    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5191
  errstrm_name = log_file;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5192
  if (strcmp(log_file, LOGFILE_STDERR) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5193
    errstrm = stderr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5194
    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5195
  } else if (strcmp(log_file, LOGFILE_STDOUT) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5196
    errstrm = stdout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5197
    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5198
  } else if (log_file[0] != '\0' && (errstrm = fopen(log_file,"a+")) != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5199
    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5200
  } else {
23920
dc17ca1e4cf9 8033618: Correct logging output
kizune
parents: 17490
diff changeset
  5201
    fprintf(stderr, "Can not open log file %s\n", log_file);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5202
    // Last resort
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5203
    // (Do not use stdout, since it might be jarout->jarfp.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5204
    errstrm = stderr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5205
    log_file = errstrm_name = LOGFILE_STDERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5206
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5207
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5208
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5209
#ifndef PRODUCT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5210
int unpacker::printcr_if_verbose(int level, const char* fmt ...) {
17490
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16126
diff changeset
  5211
  if (verbose < level)  return 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5212
  va_list vl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5213
  va_start(vl, fmt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5214
  char fmtbuf[300];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5215
  strcpy(fmtbuf+100, fmt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5216
  strcat(fmtbuf+100, "\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5217
  char* fmt2 = fmtbuf+100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5218
  while (level-- > 0)  *--fmt2 = ' ';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5219
  vfprintf(errstrm, fmt2, vl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5220
  return 1;  // for ?: usage
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5221
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5222
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5223
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5224
void unpacker::abort(const char* message) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5225
  if (message == null)  message = "error unpacking archive";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5226
#ifdef UNPACK_JNI
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5227
  if (message[0] == '@') {  // secret convention for sprintf
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5228
     bytes saved;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5229
     saved.saveFrom(message+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5230
     mallocs.add(message = saved.strval());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5231
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5232
  abort_message = message;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5233
  return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5234
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5235
  if (message[0] == '@')  ++message;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5236
  fprintf(errstrm, "%s\n", message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5237
#ifndef PRODUCT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5238
  fflush(errstrm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5239
  ::abort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5240
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5241
  exit(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5242
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5243
#endif // JNI
90ce3da70b43 Initial load
duke
parents:
diff changeset
  5244
}