jdk/src/share/native/com/sun/java/util/jar/pack/unpack.cpp
author ohair
Sun, 17 Aug 2008 17:02:04 -0700
changeset 1082 53833ff90c45
parent 2 90ce3da70b43
child 2624 1ae5a9028dd4
permissions -rw-r--r--
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux Summary: Removal of compiler warnings and fixing of assert logic. Reviewed-by: jrose, ksrini, bristor
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
     2
 * Copyright 2001-2008 Sun Microsystems, Inc.  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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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).
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
    35
 * 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
    36
 */
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
    37
#if defined(_LP64) || defined(__sparcv9) || defined(__x86_64)
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
    38
  #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
    39
  #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
    40
#else
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 "%lld"
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 "%016llx"
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
    43
#endif
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
    44
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
#include <sys/types.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
#include <stdio.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
#include <string.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
#include <stdlib.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
#include <stdarg.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
#include <limits.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
#include <time.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
#include "defines.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
#include "bytes.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
#include "utils.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
#include "coding.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
#include "bands.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
#include "constants.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
#include "zip.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
#include "unpack.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
// tags, in canonical order:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
static const byte TAGS_IN_ORDER[] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
  CONSTANT_Utf8,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
  CONSTANT_Integer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
  CONSTANT_Float,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
  CONSTANT_Long,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
  CONSTANT_Double,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
  CONSTANT_String,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
  CONSTANT_Class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
  CONSTANT_Signature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
  CONSTANT_NameandType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
  CONSTANT_Fieldref,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
  CONSTANT_Methodref,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
  CONSTANT_InterfaceMethodref
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
#define N_TAGS_IN_ORDER (sizeof TAGS_IN_ORDER)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
#ifndef PRODUCT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
static const char* TAG_NAME[] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
  "*None",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
  "Utf8",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
  "*Unicode",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
  "Integer",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
  "Float",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
  "Long",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
  "Double",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
  "Class",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
  "String",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
  "Fieldref",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
  "Methodref",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
  "InterfaceMethodref",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
  "NameandType",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
  "*Signature",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
  0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
static const char* ATTR_CONTEXT_NAME[] = {  // match ATTR_CONTEXT_NAME, etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
  "class", "field", "method", "code"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
#define ATTR_CONTEXT_NAME ((const char**)null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
// REQUESTED must be -2 for u2 and REQUESTED_LDC must be -1 for u1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
enum { NOT_REQUESTED = 0, REQUESTED = -2, REQUESTED_LDC = -1 };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
#define NO_INORD ((uint)-1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
struct entry {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
  byte tag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
  #if 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
  byte bits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
  enum {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    //EB_EXTRA = 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    EB_SUPER = 2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
  };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
  #endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
  unsigned short nrefs;  // pack w/ tag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
  int  outputIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
  uint inord;   // &cp.entries[cp.tag_base[this->tag]+this->inord] == this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
  entry* *refs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
  // put last to pack best
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
  union {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    bytes b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    jlong l;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
  } value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
  void requestOutputIndex(cpool& cp, int req = REQUESTED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
  int getOutputIndex() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    assert(outputIndex > NOT_REQUESTED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    return outputIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
  entry* ref(int refnum) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    assert((uint)refnum < nrefs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    return refs[refnum];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
  const char* utf8String() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    assert(tagMatches(CONSTANT_Utf8));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    assert(value.b.len == strlen((const char*)value.b.ptr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    return (const char*)value.b.ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
  entry* className() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    assert(tagMatches(CONSTANT_Class));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    return ref(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
  entry* memberClass() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    assert(tagMatches(CONSTANT_Member));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    return ref(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
  entry* memberDescr() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    assert(tagMatches(CONSTANT_Member));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    return ref(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
  entry* descrName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    assert(tagMatches(CONSTANT_NameandType));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    return ref(0);
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* descrType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    assert(tagMatches(CONSTANT_NameandType));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    return ref(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
  int typeSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
  bytes& asUtf8();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
  int    asInteger() { assert(tag == CONSTANT_Integer); return value.i; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
  bool isUtf8(bytes& b) { return tagMatches(CONSTANT_Utf8) && value.b.equals(b); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
  bool isDoubleWord() { return tag == CONSTANT_Double || tag == CONSTANT_Long; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
  bool tagMatches(byte tag2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    return (tag2 == tag)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
      || (tag2 == CONSTANT_Utf8 && tag == CONSTANT_Signature)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
      #ifndef PRODUCT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
      || (tag2 == CONSTANT_Literal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
          && tag >= CONSTANT_Integer && tag <= CONSTANT_String && tag != CONSTANT_Class)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
      || (tag2 == CONSTANT_Member
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
          && tag >= CONSTANT_Fieldref && tag <= CONSTANT_InterfaceMethodref)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
      #endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
      ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
#ifdef PRODUCT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
  char* string() { return 0; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
  char* string();  // see far below
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
entry* cpindex::get(uint i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
  if (i >= len)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
  else if (base1 != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    // primary index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    return &base1[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
  else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    // secondary index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    return base2[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
inline bytes& entry::asUtf8() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
  assert(tagMatches(CONSTANT_Utf8));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
  return value.b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
int entry::typeSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
  assert(tagMatches(CONSTANT_Utf8));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
  const char* sigp = (char*) value.b.ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
  switch (*sigp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
  case '(': sigp++; break;  // skip opening '('
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
  case 'D':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
  case 'J': return 2; // double field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
  default:  return 1; // field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
  int siglen = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
  for (;;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    int ch = *sigp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    switch (ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    case 'D': case 'J':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
      siglen += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    case '[':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
      // Skip rest of array info.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
      while (ch == '[') { ch = *sigp++; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
      if (ch != 'L')  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
      // else fall through
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    case 'L':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
      sigp = strchr(sigp, ';');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
      if (sigp == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
          unpack_abort("bad data");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
          return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
      sigp += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    case ')':  // closing ')'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
      return siglen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    siglen += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
inline cpindex* cpool::getFieldIndex(entry* classRef) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
  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
   271
  assert((uint)classRef->inord < (uint)tag_count[CONSTANT_Class]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
  return &member_indexes[classRef->inord*2+0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
inline cpindex* cpool::getMethodIndex(entry* classRef) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
  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
   276
  assert((uint)classRef->inord < (uint)tag_count[CONSTANT_Class]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
  return &member_indexes[classRef->inord*2+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
struct inner_class {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
  entry* inner;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
  entry* outer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
  entry* name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
  int    flags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
  inner_class* next_sibling;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
  bool   requested;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
// Here is where everything gets deallocated:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
void unpacker::free() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
  int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
  assert(jniobj == null); // caller resp.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
  assert(infileptr == null);  // caller resp.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
  if (jarout != null)  jarout->reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
  if (gzin != null)    { gzin->free(); gzin = null; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
  if (free_input)  input.free();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
  // free everybody ever allocated with U_NEW or (recently) with T_NEW
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
  assert(smallbuf.base()  == null || mallocs.contains(smallbuf.base()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
  assert(tsmallbuf.base() == null || tmallocs.contains(tsmallbuf.base()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
  mallocs.freeAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
  tmallocs.freeAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
  smallbuf.init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
  tsmallbuf.init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
  bcimap.free();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
  class_fixup_type.free();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
  class_fixup_offset.free();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
  class_fixup_ref.free();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
  code_fixup_type.free();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
  code_fixup_offset.free();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
  code_fixup_source.free();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
  requested_ics.free();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
  cur_classfile_head.free();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
  cur_classfile_tail.free();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
  for (i = 0; i < ATTR_CONTEXT_LIMIT; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    attr_defs[i].free();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
  // free CP state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
  cp.outputEntries.free();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
  for (i = 0; i < CONSTANT_Limit; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    cp.tag_extras[i].free();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
// input handling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
// Attempts to advance rplimit so that (rplimit-rp) is at least 'more'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
// Will eagerly read ahead by larger chunks, if possible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
// Returns false if (rplimit-rp) is not at least 'more',
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
// unless rplimit hits input.limit().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
bool unpacker::ensure_input(jlong more) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
  julong want = more - input_remaining();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
  if ((jlong)want <= 0)          return true;  // it's already in the buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
  if (rplimit == input.limit())  return true;  // not expecting any more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
  if (read_input_fn == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    // assume it is already all there
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    bytes_read += input.limit() - rplimit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    rplimit = input.limit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
  CHECK_0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
  julong remaining = (input.limit() - rplimit);  // how much left to read?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
  byte* rpgoal = (want >= remaining)? input.limit(): rplimit + (size_t)want;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
  enum { CHUNK_SIZE = (1<<14) };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
  julong fetch = want;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
  if (fetch < CHUNK_SIZE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    fetch = CHUNK_SIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
  if (fetch > remaining*3/4)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    fetch = remaining;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
  // Try to fetch at least "more" bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
  while ((jlong)fetch > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    jlong nr = (*read_input_fn)(this, rplimit, fetch, remaining);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    if (nr <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
      return (rplimit >= rpgoal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    remaining -= nr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    rplimit += nr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    fetch -= nr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    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
   359
    assert(remaining == (julong)(input.limit() - rplimit));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
  return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
// output handling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
fillbytes* unpacker::close_output(fillbytes* which) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
  assert(wp != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
  if (which == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    if (wpbase == cur_classfile_head.base()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
      which = &cur_classfile_head;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
      which = &cur_classfile_tail;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
  assert(wpbase  == which->base());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
  assert(wplimit == which->end());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
  which->setLimit(wp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
  wp      = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
  wplimit = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
  //wpbase = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
  return which;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
//maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
void unpacker::ensure_put_space(size_t size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
  if (wp + size <= wplimit)  return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
  // Determine which segment needs expanding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
  fillbytes* which = close_output();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
  byte* wp0 = which->grow(size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
  wpbase  = which->base();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
  wplimit = which->end();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
  wp = wp0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
byte* unpacker::put_space(size_t size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
  byte* wp0 = wp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
  byte* wp1 = wp0 + size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
  if (wp1 > wplimit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    ensure_put_space(size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    wp0 = wp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    wp1 = wp0 + size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
  wp = wp1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
  return wp0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
void unpacker::putu2_at(byte* wp, int n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
  if (n != (unsigned short)n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    unpack_abort(ERROR_OVERFLOW);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
  wp[0] = (n) >> 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
  wp[1] = (n) >> 0;
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
void unpacker::putu4_at(byte* wp, int n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
  wp[0] = (n) >> 24;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
  wp[1] = (n) >> 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
  wp[2] = (n) >> 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
  wp[3] = (n) >> 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
void unpacker::putu8_at(byte* wp, jlong n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
  putu4_at(wp+0, (int)((julong)n >> 32));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
  putu4_at(wp+4, (int)((julong)n >> 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
void unpacker::putu2(int n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
  putu2_at(put_space(2), n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
void unpacker::putu4(int n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
  putu4_at(put_space(4), n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
void unpacker::putu8(jlong n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
  putu8_at(put_space(8), n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
int unpacker::putref_index(entry* e, int size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
  if (e == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
  else if (e->outputIndex > NOT_REQUESTED)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    return e->outputIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
  else if (e->tag == CONSTANT_Signature)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    return putref_index(e->ref(0), size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
  else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    e->requestOutputIndex(cp, -size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    // Later on we'll fix the bits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    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
   459
    class_fixup_offset.add((int)wpoffset());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    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
   461
#ifdef PRODUCT
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   462
    return 0;
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   463
#else
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   464
    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
   465
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
void unpacker::putref(entry* e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
  int oidx = putref_index(e, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
  putu2_at(put_space(2), oidx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
void unpacker::putu1ref(entry* e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
  int oidx = putref_index(e, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
  putu1_at(put_space(1), oidx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
static int total_cp_size[] = {0, 0};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
static int largest_cp_ref[] = {0, 0};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
static int hash_probes[] = {0, 0};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
// Allocation of small and large blocks.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
enum { CHUNK = (1 << 14), SMALL = (1 << 9) };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
// Call malloc.  Try to combine small blocks and free much later.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
void* unpacker::alloc_heap(size_t size, bool smallOK, bool temp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
  CHECK_0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
  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
   494
    void* res = must_malloc((int)size);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    (temp ? &tmallocs : &mallocs)->add(res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
  fillbytes& xsmallbuf = *(temp ? &tsmallbuf : &smallbuf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
  if (!xsmallbuf.canAppend(size+1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    xsmallbuf.init(CHUNK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    (temp ? &tmallocs : &mallocs)->add(xsmallbuf.base());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
  }
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   503
  int growBy = (int)size;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
  growBy += -growBy & 7;  // round up mod 8
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
  return xsmallbuf.grow(growBy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
void unpacker::saveTo(bytes& b, byte* ptr, size_t len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
  b.ptr = U_NEW(byte, len+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
  if (aborting()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    b.len = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
  b.len = len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
  b.copyFrom(ptr, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
// Read up through band_headers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
// Do the archive_size dance to set the size of the input mega-buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
void unpacker::read_file_header() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
  // Read file header to determine file type and total size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
  enum {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    MAGIC_BYTES = 4,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    AH_LENGTH_0 = 3,  //minver, majver, options are outside of archive_size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    AH_LENGTH   = 26, //maximum archive header length (w/ all fields)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    // Length contributions from optional header fields:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    AH_FILE_HEADER_LEN = 5, // sizehi/lo/next/modtime/files
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    AH_CP_NUMBER_LEN = 4,  // int/float/long/double
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    AH_SPECIAL_FORMAT_LEN = 2, // layouts/band-headers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    AH_LENGTH_MIN = AH_LENGTH
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        -(AH_FILE_HEADER_LEN+AH_SPECIAL_FORMAT_LEN+AH_CP_NUMBER_LEN),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    FIRST_READ  = MAGIC_BYTES + AH_LENGTH_MIN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
  };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
  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
   536
  byte initbuf[(int)FIRST_READ + (int)C_SLOP + 200];  // 200 is for JAR I/O
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
  if (foreign_buf) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    // inbytes is all there is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    input.set(inbytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    rp      = input.base();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    rplimit = input.limit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    // inbytes, if not empty, contains some read-ahead we must use first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    // ensure_input will take care of copying it into initbuf,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    // then querying read_input_fn for any additional data needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    // However, the caller must assume that we use up all of inbytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    // There is no way to tell the caller that we used only part of them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    // Therefore, the caller must use only a bare minimum of read-ahead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    if (inbytes.len > FIRST_READ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
      abort("too much pushback");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
      return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    input.set(initbuf, sizeof(initbuf));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    input.b.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    input.b.copyFrom(inbytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    rplimit = rp = input.base();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    rplimit += inbytes.len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
    bytes_read += inbytes.len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
  // Read only 19 bytes, which is certain to contain #archive_size fields,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
  // but is certain not to overflow past the archive_header.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
  input.b.len = FIRST_READ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
  if (!ensure_input(FIRST_READ))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    abort("EOF reading archive magic number");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
  if (rp[0] == 'P' && rp[1] == 'K') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
#ifdef UNPACK_JNI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    // Java driver must handle this case before we get this far.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    abort("encountered a JAR header in unpacker");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    // In the Unix-style program, we simply simulate a copy command.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    // Copy until EOF; assume the JAR file is the last segment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    fprintf(errstrm, "Copy-mode.\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    for (;;) {
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   575
      jarout->write_data(rp, (int)input_remaining());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
      if (foreign_buf)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        break;  // one-time use of a passed in buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
      if (input.size() < CHUNK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        // Get some breathing room.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        input.set(U_NEW(byte, (size_t) CHUNK + C_SLOP), (size_t) CHUNK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
      rp = rplimit = input.base();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
      if (!ensure_input(1))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    jarout->closeJarFile(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
  // Read the magic number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
  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
   594
  for (int i1 = 0; i1 < (int)sizeof(magic); i1++) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    magic <<= 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    magic += (*rp++ & 0xFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
  // Read the first 3 values from the header.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
  value_stream hdr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
  int          hdrVals = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
  int          hdrValsSkipped = 0;  // debug only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
  hdr.init(rp, rplimit, UNSIGNED5_spec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
  minver = hdr.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
  majver = hdr.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
  hdrVals += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   608
  if (magic != (int)JAVA_PACKAGE_MAGIC ||
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
      (majver != JAVA5_PACKAGE_MAJOR_VERSION  &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
       majver != JAVA6_PACKAGE_MAJOR_VERSION) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
      (minver != JAVA5_PACKAGE_MINOR_VERSION  &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
       minver != JAVA6_PACKAGE_MINOR_VERSION)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
    char message[200];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    sprintf(message, "@" ERROR_FORMAT ": magic/ver = "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            "%08X/%d.%d should be %08X/%d.%d OR %08X/%d.%d\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
            magic, majver, minver,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            JAVA_PACKAGE_MAGIC, JAVA5_PACKAGE_MAJOR_VERSION, JAVA5_PACKAGE_MINOR_VERSION,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            JAVA_PACKAGE_MAGIC, JAVA6_PACKAGE_MAJOR_VERSION, JAVA6_PACKAGE_MINOR_VERSION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
    abort(message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
  archive_options = hdr.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
  hdrVals += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
  assert(hdrVals == AH_LENGTH_0);  // first three fields only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
#define ORBIT(bit) |(bit)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
  int OPTION_LIMIT = (0 ARCHIVE_BIT_DO(ORBIT));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
#undef ORBIT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
  if ((archive_options & ~OPTION_LIMIT) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    fprintf(errstrm, "Warning: Illegal archive options 0x%x\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
            archive_options);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    // Do not abort.  If the format really changes, version numbers will bump.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
    //abort("illegal archive options");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
  if ((archive_options & AO_HAVE_FILE_HEADERS) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    uint hi = hdr.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    uint lo = hdr.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
    archive_size = band::makeLong(hi, lo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
    hdrVals += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
    hdrValsSkipped += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
  if (archive_size != (size_t)archive_size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    // Silly size specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
    abort("archive too large");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
  // Now we can size the whole archive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
  // Read everything else into a mega-buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
  rp = hdr.rp;
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   655
  int header_size_0 = (int)(rp - input.base()); // used-up header (4byte + 3int)
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   656
  int header_size_1 = (int)(rplimit - rp);      // buffered unused initial fragment
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
  int header_size   = header_size_0+header_size_1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
  unsized_bytes_read = header_size_0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
  if (foreign_buf) {
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   661
    if (archive_size > (size_t)header_size_1) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
      abort("EOF reading fixed input buffer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
      return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
  } else if (archive_size > 0) {
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   666
    input.set(U_NEW(byte, (size_t)(header_size_0 + archive_size + C_SLOP)),
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   667
              (size_t) header_size_0 + (size_t)archive_size);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
    assert(input.limit()[0] == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    // Move all the bytes we read initially into the real buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
    input.b.copyFrom(initbuf, header_size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
    rp      = input.b.ptr + header_size_0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    rplimit = input.b.ptr + header_size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
    // It's more complicated and painful.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    // A zero archive_size means that we must read until EOF.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
    assert(archive_size == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    input.init(CHUNK*2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
    CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
    input.b.len = input.allocated;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
    rp = rplimit = input.base();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
    // Set up input buffer as if we already read the header:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
    input.b.copyFrom(initbuf, header_size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
    rplimit += header_size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    while (ensure_input(input.limit() - rp)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
      size_t dataSoFar = input_remaining();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
      size_t nextSize = dataSoFar + CHUNK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
      input.ensureSize(nextSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
      CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
      input.b.len = input.allocated;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
      rp = rplimit = input.base();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
      rplimit += dataSoFar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
    size_t dataSize = (rplimit - input.base());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
    input.b.len = dataSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
    input.grow(C_SLOP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
    CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
    free_input = true;  // free it later
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    input.b.len = dataSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
    assert(input.limit()[0] == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
    rp = rplimit = input.base();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
    rplimit += dataSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
    rp += header_size_0;  // already scanned these bytes...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
  live_input = true;    // mark as "do not reuse"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
  if (aborting()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    abort("cannot allocate large input buffer for package file");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
  // read the rest of the header fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
  ensure_input((AH_LENGTH-AH_LENGTH_0) * B_MAX);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
  hdr.rp      = rp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
  hdr.rplimit = rplimit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
  if ((archive_options & AO_HAVE_FILE_HEADERS) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
    archive_next_count = hdr.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
    archive_modtime = hdr.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
    file_count = hdr.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
    hdrVals += 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
    hdrValsSkipped += 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
  if ((archive_options & AO_HAVE_SPECIAL_FORMATS) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
    band_headers_size = hdr.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
    attr_definition_count = hdr.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
    hdrVals += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
    hdrValsSkipped += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
  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
   734
  for (int k = 0; k < (int)N_TAGS_IN_ORDER; k++) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    if (!(archive_options & AO_HAVE_CP_NUMBERS)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
      switch (TAGS_IN_ORDER[k]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
      case CONSTANT_Integer:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
      case CONSTANT_Float:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
      case CONSTANT_Long:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
      case CONSTANT_Double:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        cp_counts[k] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        hdrValsSkipped += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
    cp_counts[k] = hdr.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
    hdrVals += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
  ic_count = hdr.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
  default_class_minver = hdr.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
  default_class_majver = hdr.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
  class_count = hdr.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
  hdrVals += 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
  // done with archive_header
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
  hdrVals += hdrValsSkipped;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
  assert(hdrVals == AH_LENGTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
#ifndef PRODUCT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
  int assertSkipped = AH_LENGTH - AH_LENGTH_MIN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
  if ((archive_options & AO_HAVE_FILE_HEADERS) != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
    assertSkipped -= AH_FILE_HEADER_LEN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
  if ((archive_options & AO_HAVE_SPECIAL_FORMATS) != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
    assertSkipped -= AH_SPECIAL_FORMAT_LEN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
  if ((archive_options & AO_HAVE_CP_NUMBERS) != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
    assertSkipped -= AH_CP_NUMBER_LEN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
  assert(hdrValsSkipped == assertSkipped);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
#endif //PRODUCT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
  rp = hdr.rp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
  if (rp > rplimit)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
    abort("EOF reading archive header");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
  // 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
   775
#ifndef PRODUCT
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   776
  bool x = (N_TAGS_IN_ORDER == cpool::NUM_COUNTS);
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   777
  assert(x);
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   778
#endif //PRODUCT
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
  cp.init(this, cp_counts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
  default_file_modtime = archive_modtime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
  if (default_file_modtime == 0 && !(archive_options & AO_HAVE_FILE_MODTIME))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
    default_file_modtime = DEFAULT_ARCHIVE_MODTIME;  // taken from driver
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
  if ((archive_options & AO_DEFLATE_HINT) != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
    default_file_options |= FO_DEFLATE_HINT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
  // meta-bytes, if any, immediately follow archive header
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
  //band_headers.readData(band_headers_size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
  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
   791
  if (input_remaining() < (size_t)band_headers_size) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
    abort("EOF reading band headers");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
  bytes band_headers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
  // The "1+" allows an initial byte to be pushed on the front.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
  band_headers.set(1+U_NEW(byte, 1+band_headers_size+C_SLOP),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
                   band_headers_size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
  // Start scanning band headers here:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
  band_headers.copyFrom(rp, band_headers.len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
  rp += band_headers.len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
  assert(rp <= rplimit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
  meta_rp = band_headers.ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
  // Put evil meta-codes at the end of the band headers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
  // so we are sure to throw an error if we run off the end.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
  bytes::of(band_headers.limit(), C_SLOP).clear(_meta_error);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
void unpacker::finish() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
  if (verbose >= 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
    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
   814
            "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
   815
            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
   816
            (bytes_read_before_reset+bytes_read),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
            segments_read_before_reset+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
    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
   819
            "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
   820
            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
   821
            (bytes_written_before_reset+bytes_written));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
    fprintf(errstrm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
            "A total of %d files (of which %d are classes) were written to output.\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
            files_written_before_reset+files_written,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
            classes_written_before_reset+classes_written);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
  if (jarout != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
    jarout->closeJarFile(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
  if (errstrm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
    if (errstrm == stdout || errstrm == stderr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
      fflush(errstrm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
      fclose(errstrm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
    errstrm = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
    errstrm_name = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
// Cf. PackageReader.readConstantPoolCounts
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
void cpool::init(unpacker* u_, int counts[NUM_COUNTS]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
  this->u = u_;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
  // Fill-pointer for CP.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
  int next_entry = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
  // 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
   849
  for (int k = 0; k < (int)N_TAGS_IN_ORDER; k++) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
    byte tag = TAGS_IN_ORDER[k];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
    int  len = counts[k];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
    tag_count[tag] = len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
    tag_base[tag] = next_entry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
    next_entry += len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
    // Detect and defend against constant pool size overflow.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
    // (Pack200 forbids the sum of CP counts to exceed 2^29-1.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
    enum {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
      CP_SIZE_LIMIT = (1<<29),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
      IMPLICIT_ENTRY_COUNT = 1  // empty Utf8 string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
    if (len >= (1<<29) || len < 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
        || next_entry >= CP_SIZE_LIMIT+IMPLICIT_ENTRY_COUNT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
      abort("archive too large:  constant pool limit exceeded");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
      return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
  // Close off the end of the CP:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
  nentries = next_entry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
  // place a limit on future CP growth:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
  int generous = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
  generous += u->ic_count*3; // implicit name, outer, outer.utf8
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
  generous += 40;  // WKUs, misc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
  generous += u->class_count;  // implicit SourceFile strings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
  maxentries = nentries + generous;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
  // Note that this CP does not include "empty" entries
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
  // for longs and doubles.  Those are introduced when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
  // the entries are renumbered for classfile output.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
  entries = U_NEW(entry, maxentries);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
  first_extra_entry = &entries[nentries];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
  // Initialize the standard indexes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
  tag_count[CONSTANT_All] = nentries;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
  tag_base[ CONSTANT_All] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
  for (int tag = 0; tag < CONSTANT_Limit; tag++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
    entry* cpMap = &entries[tag_base[tag]];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
    tag_index[tag].init(tag_count[tag], cpMap, tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
  // Initialize hashTab to a generous power-of-two size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
  uint pow2 = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
  uint target = maxentries + maxentries/2;  // 60% full
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
  while (pow2 < target)  pow2 <<= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
  hashTab = U_NEW(entry*, hashTabLength = pow2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
static byte* store_Utf8_char(byte* cp, unsigned short ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
  if (ch >= 0x001 && ch <= 0x007F) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
    *cp++ = (byte) ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
  } else if (ch <= 0x07FF) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
    *cp++ = (byte) (0xC0 | ((ch >>  6) & 0x1F));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
    *cp++ = (byte) (0x80 | ((ch >>  0) & 0x3F));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
    *cp++ = (byte) (0xE0 | ((ch >> 12) & 0x0F));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
    *cp++ = (byte) (0x80 | ((ch >>  6) & 0x3F));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
    *cp++ = (byte) (0x80 | ((ch >>  0) & 0x3F));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
  return cp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
static byte* skip_Utf8_chars(byte* cp, int len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
  for (;; cp++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
    int ch = *cp & 0xFF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
    if ((ch & 0xC0) != 0x80) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
      if (len-- == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
        return cp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
      if (ch < 0x80 && len == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
        return cp+1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
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
   929
  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
   930
  int l2 = (int)b2.len;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
  int l0 = (l1 < l2) ? l1 : l2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
  byte* p1 = b1.ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
  byte* p2 = b2.ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
  int c0 = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
  for (int i = 0; i < l0; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
    int c1 = p1[i] & 0xFF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
    int c2 = p2[i] & 0xFF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
    if (c1 != c2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
      // Before returning the obvious answer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
      // check to see if c1 or c2 is part of a 0x0000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
      // which encodes as {0xC0,0x80}.  The 0x0000 is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
      // lowest-sorting Java char value, and yet it encodes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
      // as if it were the first char after 0x7F, which causes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
      // strings containing nulls to sort too high.  All other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
      // comparisons are consistent between Utf8 and Java chars.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
      if (c1 == 0xC0 && (p1[i+1] & 0xFF) == 0x80)  c1 = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
      if (c2 == 0xC0 && (p2[i+1] & 0xFF) == 0x80)  c2 = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
      if (c0 == 0xC0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
        assert(((c1|c2) & 0xC0) == 0x80);  // c1 & c2 are extension chars
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
        if (c1 == 0x80)  c1 = 0;  // will sort below c2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
        if (c2 == 0x80)  c2 = 0;  // will sort below c1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
      return c1 - c2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
    c0 = c1;  // save away previous char
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
  // common prefix is identical; return length difference if any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
  return l1 - l2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
// Cf. PackageReader.readUtf8Bands
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
local_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
void unpacker::read_Utf8_values(entry* cpMap, int len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
  // Implicit first Utf8 string is the empty string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
  enum {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
    // certain bands begin with implicit zeroes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
    PREFIX_SKIP_2 = 2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
    SUFFIX_SKIP_1 = 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
  };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
  int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
  // First band:  Read lengths of shared prefixes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
  if (len > PREFIX_SKIP_2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
    cp_Utf8_prefix.readData(len - PREFIX_SKIP_2);
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   976
  NOT_PRODUCT(else cp_Utf8_prefix.readData(0));  // for asserts
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
  // Second band:  Read lengths of unshared suffixes:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
  if (len > SUFFIX_SKIP_1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
    cp_Utf8_suffix.readData(len - SUFFIX_SKIP_1);
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   981
  NOT_PRODUCT(else cp_Utf8_suffix.readData(0));  // for asserts
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
  bytes* allsuffixes = T_NEW(bytes, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
  int nbigsuf = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
  fillbytes charbuf;    // buffer to allocate small strings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
  charbuf.init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
  // Third band:  Read the char values in the unshared suffixes:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
  cp_Utf8_chars.readData(cp_Utf8_suffix.getIntTotal());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
  for (i = 0; i < len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
    int suffix = (i < SUFFIX_SKIP_1)? 0: cp_Utf8_suffix.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
    if (suffix < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
      abort("bad utf8 suffix");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
      return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
    if (suffix == 0 && i >= SUFFIX_SKIP_1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
      // chars are packed in cp_Utf8_big_chars
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
      nbigsuf += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
      continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
    bytes& chars  = allsuffixes[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
    uint size3    = suffix * 3;     // max Utf8 length
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
    bool isMalloc = (suffix > SMALL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
    if (isMalloc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
      chars.malloc(size3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
      if (!charbuf.canAppend(size3+1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
        assert(charbuf.allocated == 0 || tmallocs.contains(charbuf.base()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
        charbuf.init(CHUNK);  // Reset to new buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
        tmallocs.add(charbuf.base());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
      chars.set(charbuf.grow(size3+1), size3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
    CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
    byte* chp = chars.ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
    for (int j = 0; j < suffix; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
      unsigned short ch = cp_Utf8_chars.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
      chp = store_Utf8_char(chp, ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
    // shrink to fit:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
    if (isMalloc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
      chars.realloc(chp - chars.ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
      CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
      tmallocs.add(chars.ptr); // free it later
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
    } else {
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  1028
      int shrink = (int)(chars.limit() - chp);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
      chars.len -= shrink;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
      charbuf.b.len -= shrink;  // ungrow to reclaim buffer space
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
      // Note that we did not reclaim the final '\0'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
      assert(chars.limit() == charbuf.limit()-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
      assert(strlen((char*)chars.ptr) == chars.len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
  //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
  1037
#ifndef PRODUCT
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  1038
  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
  1039
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
  // Fourth band:  Go back and size the specially packed strings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
  int maxlen = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
  cp_Utf8_big_suffix.readData(nbigsuf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
  cp_Utf8_suffix.rewind();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
  for (i = 0; i < len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
    int suffix = (i < SUFFIX_SKIP_1)? 0: cp_Utf8_suffix.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
    int prefix = (i < PREFIX_SKIP_2)? 0: cp_Utf8_prefix.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
    if (prefix < 0 || prefix+suffix < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
       abort("bad utf8 prefix");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
       return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
    bytes& chars = allsuffixes[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
    if (suffix == 0 && i >= SUFFIX_SKIP_1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
      suffix = cp_Utf8_big_suffix.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
      assert(chars.ptr == null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
      chars.len = suffix;  // just a momentary hack
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
      assert(chars.ptr != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
    if (maxlen < prefix + suffix) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
      maxlen = prefix + suffix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
  //cp_Utf8_suffix.done();      // will use allsuffixes[i].len (ptr!=null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
  //cp_Utf8_big_suffix.done();  // will use allsuffixes[i].len
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
  // Fifth band(s):  Get the specially packed characters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
  cp_Utf8_big_suffix.rewind();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
  for (i = 0; i < len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
    bytes& chars = allsuffixes[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
    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
  1072
    int suffix = (int)chars.len;  // pick up the hack
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
    uint size3 = suffix * 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
    if (suffix == 0)  continue;  // done with empty string
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
    chars.malloc(size3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
    byte* chp = chars.ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
    band saved_band = cp_Utf8_big_chars;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
    cp_Utf8_big_chars.readData(suffix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
    for (int j = 0; j < suffix; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
      unsigned short ch = cp_Utf8_big_chars.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
      chp = store_Utf8_char(chp, ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
    chars.realloc(chp - chars.ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
    CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
    tmallocs.add(chars.ptr);  // free it later
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
    //cp_Utf8_big_chars.done();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
    cp_Utf8_big_chars = saved_band;  // reset the band for the next string
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
  cp_Utf8_big_chars.readData(0);  // zero chars
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
  //cp_Utf8_big_chars.done();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
  // Finally, sew together all the prefixes and suffixes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
  bytes bigbuf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
  bigbuf.malloc(maxlen * 3 + 1);  // max Utf8 length, plus slop for null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
  int prevlen = 0;  // previous string length (in chars)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
  tmallocs.add(bigbuf.ptr);  // free after this block
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
  cp_Utf8_prefix.rewind();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
  for (i = 0; i < len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
    bytes& chars = allsuffixes[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
    int prefix = (i < PREFIX_SKIP_2)? 0: cp_Utf8_prefix.getInt();
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  1102
    int suffix = (int)chars.len;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
    byte* fillp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
    // by induction, the buffer is already filled with the prefix
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
    // make sure the prefix value is not corrupted, though:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
    if (prefix > prevlen) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
       abort("utf8 prefix overflow");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
       return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
    fillp = skip_Utf8_chars(bigbuf.ptr, prefix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
    // copy the suffix into the same buffer:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
    fillp = chars.writeTo(fillp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
    assert(bigbuf.inBounds(fillp));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
    *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
  1115
    int length = (int)(fillp - bigbuf.ptr);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
    bytes& value = cpMap[i].value.b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
    value.set(U_NEW(byte, length+1), length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
    value.copyFrom(bigbuf.ptr, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
    CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
    // Index all Utf8 strings
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
    entry* &htref = cp.hashTabRef(CONSTANT_Utf8, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
    if (htref == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
      // Note that if two identical strings are transmitted,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
      // the first is taken to be the canonical one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
      htref = &cpMap[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
    prevlen = prefix + suffix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
  //cp_Utf8_prefix.done();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
  // Free intermediate buffers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
  free_temps();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
local_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
void unpacker::read_single_words(band& cp_band, entry* cpMap, int len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
  cp_band.readData(len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
  for (int i = 0; i < len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
    cpMap[i].value.i = cp_band.getInt();  // coding handles signs OK
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
void unpacker::read_double_words(band& cp_bands, entry* cpMap, int len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
  band& cp_band_hi = cp_bands;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
  band& cp_band_lo = cp_bands.nextBand();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
  cp_band_hi.readData(len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
  cp_band_lo.readData(len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
  for (int i = 0; i < len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
    cpMap[i].value.l = cp_band_hi.getLong(cp_band_lo, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
  //cp_band_hi.done();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
  //cp_band_lo.done();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
void unpacker::read_single_refs(band& cp_band, byte refTag, entry* cpMap, int len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
  assert(refTag == CONSTANT_Utf8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
  cp_band.setIndexByTag(refTag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
  cp_band.readData(len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
  int indexTag = (cp_band.bn == e_cp_Class) ? CONSTANT_Class : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
  for (int i = 0; i < len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
    entry& e = cpMap[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
    e.refs = U_NEW(entry*, e.nrefs = 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
    entry* utf = cp_band.getRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
    CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
    e.refs[0] = utf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
    e.value.b = utf->value.b;  // copy value of Utf8 string to self
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
    if (indexTag != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
      // Maintain cross-reference:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
      entry* &htref = cp.hashTabRef(indexTag, e.value.b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
      if (htref == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
        // Note that if two identical classes are transmitted,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
        // the first is taken to be the canonical one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
        htref = &e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
  //cp_band.done();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
void unpacker::read_double_refs(band& cp_band, byte ref1Tag, byte ref2Tag,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
                                entry* cpMap, int len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
  band& cp_band1 = cp_band;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
  band& cp_band2 = cp_band.nextBand();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
  cp_band1.setIndexByTag(ref1Tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
  cp_band2.setIndexByTag(ref2Tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
  cp_band1.readData(len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
  cp_band2.readData(len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
  for (int i = 0; i < len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
    entry& e = cpMap[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
    e.refs = U_NEW(entry*, e.nrefs = 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
    e.refs[0] = cp_band1.getRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
    e.refs[1] = cp_band2.getRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
    CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
  //cp_band1.done();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
  //cp_band2.done();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
// Cf. PackageReader.readSignatureBands
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
void unpacker::read_signature_values(entry* cpMap, int len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
  cp_Signature_form.setIndexByTag(CONSTANT_Utf8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
  cp_Signature_form.readData(len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
  int ncTotal = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
  int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
  for (i = 0; i < len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
    entry& e = cpMap[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
    entry& form = *cp_Signature_form.getRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
    CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
    int nc = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
    for ( const char* ncp = form.utf8String() ; *ncp; ncp++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
      if (*ncp == 'L')  nc++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
    ncTotal += nc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
    e.refs = U_NEW(entry*, cpMap[i].nrefs = 1 + nc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
    CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
    e.refs[0] = &form;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
  //cp_Signature_form.done();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
  cp_Signature_classes.setIndexByTag(CONSTANT_Class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
  cp_Signature_classes.readData(ncTotal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
  for (i = 0; i < len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
    entry& e = cpMap[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
    for (int j = 1; j < e.nrefs; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
      e.refs[j] = cp_Signature_classes.getRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
      CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
  //cp_Signature_classes.done();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
// Cf. PackageReader.readConstantPool
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
void unpacker::read_cp() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
  byte* rp0 = rp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
  int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  1246
  for (int k = 0; k < (int)N_TAGS_IN_ORDER; k++) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
    byte tag = TAGS_IN_ORDER[k];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
    int  len = cp.tag_count[tag];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
    int base = cp.tag_base[tag];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  1251
    PRINTCR((1,"Reading %d %s entries...", len, NOT_PRODUCT(TAG_NAME[tag])+0));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
    entry* cpMap = &cp.entries[base];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
    for (i = 0; i < len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
      cpMap[i].tag = tag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
      cpMap[i].inord = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
    switch (tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
    case CONSTANT_Utf8:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
      read_Utf8_values(cpMap, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
    case CONSTANT_Integer:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
      read_single_words(cp_Int, cpMap, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
    case CONSTANT_Float:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
      read_single_words(cp_Float, cpMap, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
    case CONSTANT_Long:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
      read_double_words(cp_Long_hi /*& cp_Long_lo*/, cpMap, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
    case CONSTANT_Double:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
      read_double_words(cp_Double_hi /*& cp_Double_lo*/, cpMap, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
    case CONSTANT_String:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
      read_single_refs(cp_String, CONSTANT_Utf8, cpMap, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
    case CONSTANT_Class:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
      read_single_refs(cp_Class, CONSTANT_Utf8, cpMap, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
    case CONSTANT_Signature:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
      read_signature_values(cpMap, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
    case CONSTANT_NameandType:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
      read_double_refs(cp_Descr_name /*& cp_Descr_type*/,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
                       CONSTANT_Utf8, CONSTANT_Signature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
                       cpMap, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
    case CONSTANT_Fieldref:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
      read_double_refs(cp_Field_class /*& cp_Field_desc*/,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
                       CONSTANT_Class, CONSTANT_NameandType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
                       cpMap, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
    case CONSTANT_Methodref:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
      read_double_refs(cp_Method_class /*& cp_Method_desc*/,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
                       CONSTANT_Class, CONSTANT_NameandType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
                       cpMap, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
    case CONSTANT_InterfaceMethodref:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
      read_double_refs(cp_Imethod_class /*& cp_Imethod_desc*/,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
                       CONSTANT_Class, CONSTANT_NameandType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
                       cpMap, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
    default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
      assert(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
    // Initialize the tag's CP index right away, since it might be needed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
    // in the next pass to initialize the CP for another tag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
#ifndef PRODUCT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
    cpindex* ix = &cp.tag_index[tag];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
    assert(ix->ixTag == tag);
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  1313
    assert((int)ix->len   == len);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
    assert(ix->base1 == cpMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
    CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
  cp.expandSignatures();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
  cp.initMemberIndexes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  1324
  PRINTCR((1,"parsed %d constant pool entries in %d bytes", cp.nentries, (rp - rp0)));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
  #define SNAME(n,s) #s "\0"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
  const char* symNames = (
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
    ALL_ATTR_DO(SNAME)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
    "<init>"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
  );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
  #undef SNAME
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
  for (int sn = 0; sn < cpool::s_LIMIT; sn++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
    assert(symNames[0] >= '0' && symNames[0] <= 'Z');  // sanity
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
    bytes name; name.set(symNames);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
    if (name.len > 0 && name.ptr[0] != '0') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
      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
  1338
      PRINTCR((4, "well-known sym %d=%s", sn, cp.sym[sn]->string()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
    symNames += name.len + 1;  // skip trailing null to next name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
  band::initIndexes(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
static band* no_bands[] = { null };  // shared empty body
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
band& unpacker::attr_definitions::fixed_band(int e_class_xxx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
  return u->all_bands[xxx_flags_hi_bn + (e_class_xxx-e_class_flags_hi)];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
inline band& unpacker::attr_definitions::xxx_flags_hi()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
  { return fixed_band(e_class_flags_hi); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
inline band& unpacker::attr_definitions::xxx_flags_lo()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
  { return fixed_band(e_class_flags_lo); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
inline band& unpacker::attr_definitions::xxx_attr_count()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
  { return fixed_band(e_class_attr_count); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
inline band& unpacker::attr_definitions::xxx_attr_indexes()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
  { return fixed_band(e_class_attr_indexes); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
inline band& unpacker::attr_definitions::xxx_attr_calls()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
  { return fixed_band(e_class_attr_calls); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
unpacker::layout_definition*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
unpacker::attr_definitions::defineLayout(int idx,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
                                         entry* nameEntry,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
                                         const char* layout) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
  const char* name = nameEntry->value.b.strval();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
  layout_definition* lo = defineLayout(idx, name, layout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
  CHECK_0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
  lo->nameEntry = nameEntry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
  return lo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
unpacker::layout_definition*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
unpacker::attr_definitions::defineLayout(int idx,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
                                         const char* name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
                                         const char* layout) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
  assert(flag_limit != 0);  // must be set up already
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
  if (idx >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
    // 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
  1383
    if (idx >= (int)flag_limit)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
      abort("attribute index too large");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
    if (isRedefined(idx))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
      abort("redefined attribute index");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
    redef |= ((julong)1<<idx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
    idx = flag_limit + overflow_count.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
    overflow_count.add(0);  // make a new counter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
  layout_definition* lo = U_NEW(layout_definition, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
  CHECK_0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
  lo->idx = idx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
  lo->name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
  lo->layout = layout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
  for (int adds = (idx+1) - layouts.length(); adds > 0; adds--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
    layouts.add(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
  CHECK_0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
  layouts.get(idx) = lo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
  return lo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
band**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
unpacker::attr_definitions::buildBands(unpacker::layout_definition* lo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
  int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
  if (lo->elems != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
    return lo->bands();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
  if (lo->layout[0] == '\0') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
    lo->elems = no_bands;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
    // Create bands for this attribute by parsing the layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
    bool hasCallables = lo->hasCallables();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
    bands_made = 0x10000;  // base number for bands made
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
    const char* lp = lo->layout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
    lp = parseLayout(lp, lo->elems, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
    CHECK_0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
    if (lp[0] != '\0' || band_stack.length() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
      abort("garbage at end of layout");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
    band_stack.popTo(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
    CHECK_0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
    // Fix up callables to point at their callees.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
    band** bands = lo->elems;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
    assert(bands == lo->bands());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
    int num_callables = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
    if (hasCallables) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
      while (bands[num_callables] != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
        if (bands[num_callables]->le_kind != EK_CBLE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
          abort("garbage mixed with callables");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
          break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
        num_callables += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
    for (i = 0; i < calls_to_link.length(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
      band& call = *(band*) calls_to_link.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
      assert(call.le_kind == EK_CALL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
      // Determine the callee.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
      int call_num = call.le_len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
      if (call_num < 0 || call_num >= num_callables) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
        abort("bad call in layout");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
      band& cble = *bands[call_num];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
      // Link the call to it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
      call.le_body[0] = &cble;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
      // Distinguish backward calls and callables:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
      assert(cble.le_kind == EK_CBLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
      assert(cble.le_len == call_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
      cble.le_back |= call.le_back;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
    calls_to_link.popTo(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
  return lo->elems;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
/* attribute layout language parser
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
  attribute_layout:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
        ( layout_element )* | ( callable )+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
  layout_element:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
        ( integral | replication | union | call | reference )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
  callable:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
        '[' body ']'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
  body:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
        ( layout_element )+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
  integral:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
        ( unsigned_int | signed_int | bc_index | bc_offset | flag )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
  unsigned_int:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
        uint_type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
  signed_int:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
        'S' uint_type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
  any_int:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
        ( unsigned_int | signed_int )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
  bc_index:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
        ( 'P' uint_type | 'PO' uint_type )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
  bc_offset:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
        'O' any_int
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
  flag:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
        'F' uint_type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
  uint_type:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
        ( 'B' | 'H' | 'I' | 'V' )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
  replication:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
        'N' uint_type '[' body ']'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
  union:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
        'T' any_int (union_case)* '(' ')' '[' (body)? ']'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
  union_case:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
        '(' union_case_tag (',' union_case_tag)* ')' '[' (body)? ']'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
  union_case_tag:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
        ( numeral | numeral '-' numeral )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
  call:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
        '(' numeral ')'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
  reference:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
        reference_type ( 'N' )? uint_type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
  reference_type:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
        ( constant_ref | schema_ref | utf8_ref | untyped_ref )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
  constant_ref:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
        ( 'KI' | 'KJ' | 'KF' | 'KD' | 'KS' | 'KQ' )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
  schema_ref:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
        ( 'RC' | 'RS' | 'RD' | 'RF' | 'RM' | 'RI' )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
  utf8_ref:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
        'RU'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
  untyped_ref:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
        'RQ'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
  numeral:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
        '(' ('-')? (digit)+ ')'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
  digit:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
        ( '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
const char*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
unpacker::attr_definitions::parseIntLayout(const char* lp, band* &res,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
                                           byte le_kind, bool can_be_signed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
  const char* lp0 = lp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
  band* b = U_NEW(band, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
  CHECK_(lp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
  char le = *lp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
  int spec = UNSIGNED5_spec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
  if (le == 'S' && can_be_signed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
    // Note:  This is the last use of sign.  There is no 'EF_SIGN'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
    spec = SIGNED5_spec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
    le = *lp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
  } else if (le == 'B') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
    spec = BYTE1_spec;  // unsigned byte
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
  b->init(u, bands_made++, spec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
  b->le_kind = le_kind;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
  int le_len = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
  switch (le) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
  case 'B': le_len = 1; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
  case 'H': le_len = 2; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
  case 'I': le_len = 4; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
  case 'V': le_len = 0; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
  default:  abort("bad layout element");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
  b->le_len = le_len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
  band_stack.add(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
  res = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
  return lp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
const char*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
unpacker::attr_definitions::parseNumeral(const char* lp, int &res) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
  const char* lp0 = lp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
  bool sgn = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
  if (*lp == '0') { res = 0; return lp+1; }  // special case '0'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
  if (*lp == '-') { sgn = true; lp++; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
  const char* dp = lp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
  int con = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
  while (*dp >= '0' && *dp <= '9') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
    int con0 = con;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
    con *= 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
    con += (*dp++) - '0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
    if (con <= con0) { con = -1; break; }  //  numeral overflow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
  if (lp == dp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
    abort("missing numeral in layout");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
    return "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
  lp = dp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
  if (con < 0 && !(sgn && con == -con)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
    // (Portability note:  Misses the error if int is not 32 bits.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
    abort("numeral overflow");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
    return "" ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
  if (sgn)  con = -con;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
  res = con;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
  return lp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
band**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
unpacker::attr_definitions::popBody(int bs_base) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
  // Return everything that was pushed, as a null-terminated pointer array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
  int bs_limit = band_stack.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
  if (bs_base == bs_limit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
    return no_bands;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
    int nb = bs_limit - bs_base;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
    band** res = U_NEW(band*, nb+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
    CHECK_(no_bands);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
    for (int i = 0; i < nb; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
      band* b = (band*) band_stack.get(bs_base + i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
      res[i] = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
    band_stack.popTo(bs_base);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
    return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
const char*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
unpacker::attr_definitions::parseLayout(const char* lp, band** &res,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
                                        int curCble) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
  const char* lp0 = lp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
  int bs_base = band_stack.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
  bool top_level = (bs_base == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
  band* b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
  enum { can_be_signed = true };  // optional arg to parseIntLayout
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
  for (bool done = false; !done; ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
    switch (*lp++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
    case 'B': case 'H': case 'I': case 'V': // unsigned_int
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
    case 'S': // signed_int
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
      --lp;  // reparse
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
    case 'F':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
      lp = parseIntLayout(lp, b, EK_INT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
    case 'P':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
        int le_bci = EK_BCI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
        if (*lp == 'O') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
          ++lp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
          le_bci = EK_BCID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
        assert(*lp != 'S');  // no PSH, etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
        lp = parseIntLayout(lp, b, EK_INT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
        b->le_bci = le_bci;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
        if (le_bci == EK_BCI)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
          b->defc = coding::findBySpec(BCI5_spec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
          b->defc = coding::findBySpec(BRANCH5_spec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
    case 'O':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
      lp = parseIntLayout(lp, b, EK_INT, can_be_signed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
      b->le_bci = EK_BCO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
      b->defc = coding::findBySpec(BRANCH5_spec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
    case 'N': // replication: 'N' uint '[' elem ... ']'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
      lp = parseIntLayout(lp, b, EK_REPL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
      assert(*lp == '[');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
      ++lp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
      lp = parseLayout(lp, b->le_body, curCble);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
      CHECK_(lp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
    case 'T': // union: 'T' any_int union_case* '(' ')' '[' body ']'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
      lp = parseIntLayout(lp, b, EK_UN, can_be_signed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
        int union_base = band_stack.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
        for (;;) {   // for each case
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
          band& k_case = *U_NEW(band, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
          CHECK_(lp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
          band_stack.add(&k_case);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
          k_case.le_kind = EK_CASE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
          k_case.bn = bands_made++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
          if (*lp++ != '(') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
            abort("bad union case");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
            return "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
          if (*lp++ != ')') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
            --lp;  // reparse
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
            // Read some case values.  (Use band_stack for temp. storage.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
            int case_base = band_stack.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
            for (;;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
              int caseval = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
              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
  1666
              band_stack.add((void*)(size_t)caseval);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
              if (*lp == '-') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
                // new in version 160, allow (1-5) for (1,2,3,4,5)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
                if (u->majver < JAVA6_PACKAGE_MAJOR_VERSION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
                  abort("bad range in union case label (old archive format)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
                  return "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
                int caselimit = caseval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
                lp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
                lp = parseNumeral(lp, caselimit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
                if (caseval >= caselimit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
                    || (uint)(caselimit - caseval) > 0x10000) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
                  // Note:  0x10000 is arbitrary implementation restriction.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
                  // We can remove it later if it's important to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
                  abort("bad range in union case label");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
                  return "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
                for (;;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
                  ++caseval;
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  1685
                  band_stack.add((void*)(size_t)caseval);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
                  if (caseval == caselimit)  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
              if (*lp != ',')  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
              lp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
            if (*lp++ != ')') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
              abort("bad case label");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
              return "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
            // save away the case labels
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
            int ntags = band_stack.length() - case_base;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
            int* tags = U_NEW(int, 1+ntags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
            CHECK_(lp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
            k_case.le_casetags = tags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
            *tags++ = ntags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
            for (int i = 0; i < ntags; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
              *tags++ = ptrlowbits(band_stack.get(case_base+i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
            band_stack.popTo(case_base);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
            CHECK_(lp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
          // Got le_casetags.  Now grab the body.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
          assert(*lp == '[');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
          ++lp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
          lp = parseLayout(lp, k_case.le_body, curCble);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
          CHECK_(lp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
          if (k_case.le_casetags == null)  break;  // done
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
        b->le_body = popBody(union_base);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
    case '(': // call: '(' -?NN* ')'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
        band& call = *U_NEW(band, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
        CHECK_(lp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
        band_stack.add(&call);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
        call.le_kind = EK_CALL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
        call.bn = bands_made++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
        call.le_body = U_NEW(band*, 2); // fill in later
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
        int call_num = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
        lp = parseNumeral(lp, call_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
        call.le_back = (call_num <= 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
        call_num += curCble;  // numeral is self-relative offset
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
        call.le_len = call_num;  //use le_len as scratch
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
        calls_to_link.add(&call);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
        CHECK_(lp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
        if (*lp++ != ')') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
          abort("bad call label");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
          return "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
    case 'K': // reference_type: constant_ref
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
    case 'R': // reference_type: schema_ref
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
        int ixTag = CONSTANT_None;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
        if (lp[-1] == 'K') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
          switch (*lp++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
          case 'I': ixTag = CONSTANT_Integer; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
          case 'J': ixTag = CONSTANT_Long; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
          case 'F': ixTag = CONSTANT_Float; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
          case 'D': ixTag = CONSTANT_Double; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
          case 'S': ixTag = CONSTANT_String; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
          case 'Q': ixTag = CONSTANT_Literal; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
          switch (*lp++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
          case 'C': ixTag = CONSTANT_Class; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
          case 'S': ixTag = CONSTANT_Signature; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
          case 'D': ixTag = CONSTANT_NameandType; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
          case 'F': ixTag = CONSTANT_Fieldref; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
          case 'M': ixTag = CONSTANT_Methodref; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
          case 'I': ixTag = CONSTANT_InterfaceMethodref; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
          case 'U': ixTag = CONSTANT_Utf8; break; //utf8_ref
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
          case 'Q': ixTag = CONSTANT_All; break; //untyped_ref
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
        if (ixTag == CONSTANT_None) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
          abort("bad reference layout");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
          break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
        bool nullOK = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
        if (*lp == 'N') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
          nullOK = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
          lp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
        lp = parseIntLayout(lp, b, EK_REF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
        b->defc = coding::findBySpec(UNSIGNED5_spec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
        b->initRef(ixTag, nullOK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
    case '[':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
        // [callable1][callable2]...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
        if (!top_level) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
          abort("bad nested callable");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
          break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
        curCble += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
        NOT_PRODUCT(int call_num = band_stack.length() - bs_base);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
        band& cble = *U_NEW(band, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
        CHECK_(lp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
        band_stack.add(&cble);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
        cble.le_kind = EK_CBLE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
        NOT_PRODUCT(cble.le_len = call_num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
        cble.bn = bands_made++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
        lp = parseLayout(lp, cble.le_body, curCble);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
    case ']':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
      // Hit a closing brace.  This ends whatever body we were in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
      done = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
    case '\0':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
      // Hit a null.  Also ends the (top-level) body.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
      --lp;  // back up, so caller can see the null also
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
      done = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
    default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
      abort("bad layout");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
    CHECK_(lp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
  // Return the accumulated bands:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
  res = popBody(bs_base);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
  return lp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
void unpacker::read_attr_defs() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
  int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
  // Tell each AD which attrc it is and where its fixed flags are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
  attr_defs[ATTR_CONTEXT_CLASS].attrc            = ATTR_CONTEXT_CLASS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
  attr_defs[ATTR_CONTEXT_CLASS].xxx_flags_hi_bn  = e_class_flags_hi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
  attr_defs[ATTR_CONTEXT_FIELD].attrc            = ATTR_CONTEXT_FIELD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
  attr_defs[ATTR_CONTEXT_FIELD].xxx_flags_hi_bn  = e_field_flags_hi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
  attr_defs[ATTR_CONTEXT_METHOD].attrc           = ATTR_CONTEXT_METHOD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
  attr_defs[ATTR_CONTEXT_METHOD].xxx_flags_hi_bn = e_method_flags_hi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
  attr_defs[ATTR_CONTEXT_CODE].attrc             = ATTR_CONTEXT_CODE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
  attr_defs[ATTR_CONTEXT_CODE].xxx_flags_hi_bn   = e_code_flags_hi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
  // Decide whether bands for the optional high flag words are present.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
  attr_defs[ATTR_CONTEXT_CLASS]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
    .setHaveLongFlags((archive_options & AO_HAVE_CLASS_FLAGS_HI) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
  attr_defs[ATTR_CONTEXT_FIELD]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
    .setHaveLongFlags((archive_options & AO_HAVE_FIELD_FLAGS_HI) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
  attr_defs[ATTR_CONTEXT_METHOD]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
    .setHaveLongFlags((archive_options & AO_HAVE_METHOD_FLAGS_HI) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
  attr_defs[ATTR_CONTEXT_CODE]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
    .setHaveLongFlags((archive_options & AO_HAVE_CODE_FLAGS_HI) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
  // Set up built-in attrs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
  // (The simple ones are hard-coded.  The metadata layouts are not.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
  const char* md_layout = (
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
    // parameter annotations:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
#define MDL0 \
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
    "[NB[(1)]]"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
    MDL0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
    // annotations:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
#define MDL1 \
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
    "[NH[(1)]]" \
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
    "[RSHNH[RUH(1)]]"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
    MDL1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
    // member_value:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
    "[TB"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
      "(66,67,73,83,90)[KIH]"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
      "(68)[KDH]"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
      "(70)[KFH]"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
      "(74)[KJH]"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
      "(99)[RSH]"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
      "(101)[RSHRUH]"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
      "(115)[RUH]"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
      "(91)[NH[(0)]]"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
      "(64)["
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
        // nested annotation:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
        "RSH"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
        "NH[RUH(0)]"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
        "]"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
      "()[]"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
    "]"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
    );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
  const char* md_layout_P = md_layout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
  const char* md_layout_A = md_layout+strlen(MDL0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
  const char* md_layout_V = md_layout+strlen(MDL0 MDL1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
  assert(0 == strncmp(&md_layout_A[-3], ")]][", 4));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
  assert(0 == strncmp(&md_layout_V[-3], ")]][", 4));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
  for (i = 0; i < ATTR_CONTEXT_LIMIT; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
    attr_definitions& ad = attr_defs[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
    ad.defineLayout(X_ATTR_RuntimeVisibleAnnotations,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
                    "RuntimeVisibleAnnotations", md_layout_A);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
    ad.defineLayout(X_ATTR_RuntimeInvisibleAnnotations,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
                    "RuntimeInvisibleAnnotations", md_layout_A);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
    if (i != ATTR_CONTEXT_METHOD)  continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
    ad.defineLayout(METHOD_ATTR_RuntimeVisibleParameterAnnotations,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
                    "RuntimeVisibleParameterAnnotations", md_layout_P);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
    ad.defineLayout(METHOD_ATTR_RuntimeInvisibleParameterAnnotations,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
                    "RuntimeInvisibleParameterAnnotations", md_layout_P);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
    ad.defineLayout(METHOD_ATTR_AnnotationDefault,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
                    "AnnotationDefault", md_layout_V);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
  attr_definition_headers.readData(attr_definition_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
  attr_definition_name.readData(attr_definition_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
  attr_definition_layout.readData(attr_definition_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
  // Initialize correct predef bits, to distinguish predefs from new defs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
#define ORBIT(n,s) |((julong)1<<n)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
  attr_defs[ATTR_CONTEXT_CLASS].predef
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
    = (0 X_ATTR_DO(ORBIT) CLASS_ATTR_DO(ORBIT));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
  attr_defs[ATTR_CONTEXT_FIELD].predef
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
    = (0 X_ATTR_DO(ORBIT) FIELD_ATTR_DO(ORBIT));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
  attr_defs[ATTR_CONTEXT_METHOD].predef
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
    = (0 X_ATTR_DO(ORBIT) METHOD_ATTR_DO(ORBIT));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
  attr_defs[ATTR_CONTEXT_CODE].predef
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
    = (0 O_ATTR_DO(ORBIT) CODE_ATTR_DO(ORBIT));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
#undef ORBIT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
  // Clear out the redef bits, folding them back into predef.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
  for (i = 0; i < ATTR_CONTEXT_LIMIT; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
    attr_defs[i].predef |= attr_defs[i].redef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
    attr_defs[i].redef = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
  // Now read the transmitted locally defined attrs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
  // This will set redef bits again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
  for (i = 0; i < attr_definition_count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
    int    header  = attr_definition_headers.getByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
    int    attrc   = ADH_BYTE_CONTEXT(header);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
    int    idx     = ADH_BYTE_INDEX(header);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
    entry* name    = attr_definition_name.getRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
    entry* layout  = attr_definition_layout.getRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
    CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
    attr_defs[attrc].defineLayout(idx, name, layout->value.b.strval());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
#define NO_ENTRY_YET ((entry*)-1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
static bool isDigitString(bytes& x, int beg, int end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
  if (beg == end)  return false;  // null string
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
  byte* xptr = x.ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
  for (int i = beg; i < end; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
    char ch = xptr[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
    if (!(ch >= '0' && ch <= '9'))  return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
  return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
enum {  // constants for parsing class names
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
  SLASH_MIN = '.',
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
  SLASH_MAX = '/',
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
  DOLLAR_MIN = 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
  DOLLAR_MAX = '-'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
static int lastIndexOf(int chmin, int chmax, bytes& x, int pos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
  byte* ptr = x.ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
  for (byte* cp = ptr + pos; --cp >= ptr; ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
    assert(x.inBounds(cp));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
    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
  1952
      return (int)(cp - ptr);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
  return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
inner_class* cpool::getIC(entry* inner) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
  if (inner == null)  return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
  assert(inner->tag == CONSTANT_Class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
  if (inner->inord == NO_INORD)  return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
  inner_class* ic = ic_index[inner->inord];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
  assert(ic == null || ic->inner == inner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
  return ic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
inner_class* cpool::getFirstChildIC(entry* outer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
  if (outer == null)  return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
  assert(outer->tag == CONSTANT_Class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
  if (outer->inord == NO_INORD)  return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
  inner_class* ic = ic_child_index[outer->inord];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
  assert(ic == null || ic->outer == outer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
  return ic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
inner_class* cpool::getNextChildIC(inner_class* child) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
  inner_class* ic = child->next_sibling;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
  assert(ic == null || ic->outer == child->outer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
  return ic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
void unpacker::read_ics() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
  int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
  int index_size = cp.tag_count[CONSTANT_Class];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
  inner_class** ic_index       = U_NEW(inner_class*, index_size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
  inner_class** ic_child_index = U_NEW(inner_class*, index_size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
  cp.ic_index = ic_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
  cp.ic_child_index = ic_child_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
  ics = U_NEW(inner_class, ic_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
  ic_this_class.readData(ic_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
  ic_flags.readData(ic_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
  // Scan flags to get count of long-form bands.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
  int long_forms = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
  for (i = 0; i < ic_count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
    int flags = ic_flags.getInt();  // may be long form!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
    if ((flags & ACC_IC_LONG_FORM) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
      long_forms += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
      ics[i].name = NO_ENTRY_YET;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
    flags &= ~ACC_IC_LONG_FORM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
    entry* inner = ic_this_class.getRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
    CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
    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
  2007
    assert(inord < (uint)cp.tag_count[CONSTANT_Class]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
    if (ic_index[inord] != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
      abort("identical inner class");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2012
    ic_index[inord] = &ics[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
    ics[i].inner = inner;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
    ics[i].flags = flags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
    assert(cp.getIC(inner) == &ics[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2018
  //ic_this_class.done();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
  //ic_flags.done();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
  ic_outer_class.readData(long_forms);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
  ic_name.readData(long_forms);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
  for (i = 0; i < ic_count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
    if (ics[i].name == NO_ENTRY_YET) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
      // Long form.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
      ics[i].outer = ic_outer_class.getRefN();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2026
      ics[i].name  = ic_name.getRefN();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2028
      // Fill in outer and name based on inner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
      bytes& n = ics[i].inner->value.b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
      bytes pkgOuter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
      bytes number;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
      bytes name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
      // 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
  2034
      PRINTCR((5, "parse short IC name %s", n.ptr));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
      int dollar1, dollar2;  // pointers to $ in the pattern
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2036
      // 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
  2037
      int nlen = (int)n.len;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2038
      int pkglen = lastIndexOf(SLASH_MIN,  SLASH_MAX,  n, nlen) + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
      dollar2    = lastIndexOf(DOLLAR_MIN, DOLLAR_MAX, n, nlen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
      if (dollar2 < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
         abort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
         return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2043
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
      assert(dollar2 >= pkglen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2045
      if (isDigitString(n, dollar2+1, nlen)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2046
        // n = (<pkg>/)*<outer>$<number>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2047
        number = n.slice(dollar2+1, nlen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
        name.set(null,0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
        dollar1 = dollar2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
      } else if (pkglen < (dollar1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2051
                           = lastIndexOf(DOLLAR_MIN, DOLLAR_MAX, n, dollar2-1))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2052
                 && isDigitString(n, dollar1+1, dollar2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2053
        // n = (<pkg>/)*<outer>$<number>$<name>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2054
        number = n.slice(dollar1+1, dollar2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
        name = n.slice(dollar2+1, nlen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2056
      } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2057
        // n = (<pkg>/)*<outer>$<name>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2058
        dollar1 = dollar2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2059
        number.set(null,0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2060
        name = n.slice(dollar2+1, nlen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2061
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2062
      if (number.ptr == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2063
        pkgOuter = n.slice(0, dollar1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2064
      else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
        pkgOuter.set(null,0);
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  2066
      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
  2067
              pkgOuter.string(), number.string(), name.string()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2068
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2069
      if (pkgOuter.ptr != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2070
        ics[i].outer = cp.ensureClass(pkgOuter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
      if (name.ptr != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
        ics[i].name = cp.ensureUtf8(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2074
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2075
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2076
    // update child/sibling list
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2077
    if (ics[i].outer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
      uint outord = ics[i].outer->inord;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2079
      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
  2080
        assert(outord < (uint)cp.tag_count[CONSTANT_Class]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2081
        ics[i].next_sibling = ic_child_index[outord];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
        ic_child_index[outord] = &ics[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2084
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2085
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2086
  //ic_outer_class.done();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
  //ic_name.done();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
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
  2091
  PRINTCR((1,"  ...scanning %d classes...", class_count));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2092
  class_this.readData(class_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2093
  class_super.readData(class_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
  class_interface_count.readData(class_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
  class_interface.readData(class_interface_count.getIntTotal());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2099
  #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
  2100
  int i;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2101
  // Make a little mark on super-classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2102
  for (i = 0; i < class_count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2103
    entry* e = class_super.getRefN();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2104
    if (e != null)  e->bits |= entry::EB_SUPER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2105
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2106
  class_super.rewind();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2107
  #endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2108
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2109
  // Members.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
  class_field_count.readData(class_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2111
  class_method_count.readData(class_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2112
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2113
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2114
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2115
  int field_count = class_field_count.getIntTotal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2116
  int method_count = class_method_count.getIntTotal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2117
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2118
  field_descr.readData(field_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2119
  read_attrs(ATTR_CONTEXT_FIELD, field_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2120
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2121
  method_descr.readData(method_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2122
  read_attrs(ATTR_CONTEXT_METHOD, method_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2123
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2125
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2126
  read_attrs(ATTR_CONTEXT_CLASS, class_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2127
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2128
  read_code_headers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2129
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  2130
  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
  2131
          class_count, field_count, method_count, code_count));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2132
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2133
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2134
maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2135
int unpacker::attr_definitions::predefCount(uint idx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2136
  return isPredefined(idx) ? flag_count[idx] : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2137
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2138
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2139
void unpacker::read_attrs(int attrc, int obj_count) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2140
  attr_definitions& ad = attr_defs[attrc];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2141
  assert(ad.attrc == attrc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2142
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2143
  int i, idx, count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2144
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2145
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2146
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2147
  bool haveLongFlags = ad.haveLongFlags();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2148
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2149
  band& xxx_flags_hi = ad.xxx_flags_hi();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2150
  assert(endsWith(xxx_flags_hi.name, "_flags_hi"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2151
  if (haveLongFlags)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
    xxx_flags_hi.readData(obj_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2153
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2154
  band& xxx_flags_lo = ad.xxx_flags_lo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2155
  assert(endsWith(xxx_flags_lo.name, "_flags_lo"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2156
  xxx_flags_lo.readData(obj_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2157
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2158
  // pre-scan flags, counting occurrences of each index bit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2159
  julong indexMask = ad.flagIndexMask();  // which flag bits are index bits?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2160
  for (i = 0; i < obj_count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2161
    julong indexBits = xxx_flags_hi.getLong(xxx_flags_lo, haveLongFlags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2162
    if ((indexBits & ~indexMask) > (ushort)-1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2163
      abort("undefined attribute flag bit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2164
      return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2166
    indexBits &= indexMask;  // ignore classfile flag bits
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2167
    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
  2168
      ad.flag_count[idx] += (int)(indexBits & 1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2170
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2171
  // we'll scan these again later for output:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2172
  xxx_flags_lo.rewind();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2173
  xxx_flags_hi.rewind();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2174
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2175
  band& xxx_attr_count = ad.xxx_attr_count();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2176
  assert(endsWith(xxx_attr_count.name, "_attr_count"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2177
  // There is one count element for each 1<<16 bit set in flags:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2178
  xxx_attr_count.readData(ad.predefCount(X_ATTR_OVERFLOW));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2179
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2180
  band& xxx_attr_indexes = ad.xxx_attr_indexes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2181
  assert(endsWith(xxx_attr_indexes.name, "_attr_indexes"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2182
  int overflowIndexCount = xxx_attr_count.getIntTotal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2183
  xxx_attr_indexes.readData(overflowIndexCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2184
  // pre-scan attr indexes, counting occurrences of each value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2185
  for (i = 0; i < overflowIndexCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2186
    idx = xxx_attr_indexes.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2187
    if (!ad.isIndex(idx)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2188
      abort("attribute index out of bounds");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
      return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2191
    ad.getCount(idx) += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2192
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2193
  xxx_attr_indexes.rewind();  // we'll scan it again later for output
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2194
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2195
  // We will need a backward call count for each used backward callable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2196
  int backwardCounts = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2197
  for (idx = 0; idx < ad.layouts.length(); idx++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2198
    layout_definition* lo = ad.getLayout(idx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2199
    if (lo != null && ad.getCount(idx) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2200
      // Build the bands lazily, only when they are used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2201
      band** bands = ad.buildBands(lo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2202
      CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2203
      if (lo->hasCallables()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2204
        for (i = 0; bands[i] != null; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2205
          if (bands[i]->le_back) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2206
            assert(bands[i]->le_kind == EK_CBLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2207
            backwardCounts += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2208
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2209
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2210
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2212
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2213
  ad.xxx_attr_calls().readData(backwardCounts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2214
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2215
  // Read built-in bands.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2216
  // Mostly, these are hand-coded equivalents to readBandData().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2217
  switch (attrc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2218
  case ATTR_CONTEXT_CLASS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2219
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2220
    count = ad.predefCount(CLASS_ATTR_SourceFile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2221
    class_SourceFile_RUN.readData(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2222
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2223
    count = ad.predefCount(CLASS_ATTR_EnclosingMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2224
    class_EnclosingMethod_RC.readData(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2225
    class_EnclosingMethod_RDN.readData(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2226
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2227
    count = ad.predefCount(X_ATTR_Signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2228
    class_Signature_RS.readData(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2229
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2230
    ad.readBandData(X_ATTR_RuntimeVisibleAnnotations);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2231
    ad.readBandData(X_ATTR_RuntimeInvisibleAnnotations);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2232
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2233
    count = ad.predefCount(CLASS_ATTR_InnerClasses);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2234
    class_InnerClasses_N.readData(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2235
    count = class_InnerClasses_N.getIntTotal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2236
    class_InnerClasses_RC.readData(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2237
    class_InnerClasses_F.readData(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2238
    // Drop remaining columns wherever flags are zero:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2239
    count -= class_InnerClasses_F.getIntCount(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2240
    class_InnerClasses_outer_RCN.readData(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2241
    class_InnerClasses_name_RUN.readData(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2242
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2243
    count = ad.predefCount(CLASS_ATTR_ClassFile_version);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2244
    class_ClassFile_version_minor_H.readData(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2245
    class_ClassFile_version_major_H.readData(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2246
    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2247
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2248
  case ATTR_CONTEXT_FIELD:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2249
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2250
    count = ad.predefCount(FIELD_ATTR_ConstantValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2251
    field_ConstantValue_KQ.readData(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2252
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2253
    count = ad.predefCount(X_ATTR_Signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2254
    field_Signature_RS.readData(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2255
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2256
    ad.readBandData(X_ATTR_RuntimeVisibleAnnotations);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2257
    ad.readBandData(X_ATTR_RuntimeInvisibleAnnotations);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2258
    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2259
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2260
  case ATTR_CONTEXT_METHOD:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2261
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2262
    code_count = ad.predefCount(METHOD_ATTR_Code);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2263
    // Code attrs are handled very specially below...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2264
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2265
    count = ad.predefCount(METHOD_ATTR_Exceptions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2266
    method_Exceptions_N.readData(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2267
    count = method_Exceptions_N.getIntTotal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2268
    method_Exceptions_RC.readData(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2269
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2270
    count = ad.predefCount(X_ATTR_Signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2271
    method_Signature_RS.readData(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2272
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2273
    ad.readBandData(X_ATTR_RuntimeVisibleAnnotations);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2274
    ad.readBandData(X_ATTR_RuntimeInvisibleAnnotations);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2275
    ad.readBandData(METHOD_ATTR_RuntimeVisibleParameterAnnotations);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2276
    ad.readBandData(METHOD_ATTR_RuntimeInvisibleParameterAnnotations);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2277
    ad.readBandData(METHOD_ATTR_AnnotationDefault);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2278
    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2279
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2280
  case ATTR_CONTEXT_CODE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2281
    // (keep this code aligned with its brother in unpacker::write_attrs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2282
    count = ad.predefCount(CODE_ATTR_StackMapTable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2283
    // disable this feature in old archives!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2284
    if (count != 0 && majver < JAVA6_PACKAGE_MAJOR_VERSION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2285
      abort("undefined StackMapTable attribute (old archive format)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2286
      return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2287
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2288
    code_StackMapTable_N.readData(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2289
    count = code_StackMapTable_N.getIntTotal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2290
    code_StackMapTable_frame_T.readData(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2291
    // the rest of it depends in a complicated way on frame tags
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2292
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2293
      int fat_frame_count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2294
      int offset_count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2295
      int type_count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2296
      for (int k = 0; k < count; k++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2297
        int tag = code_StackMapTable_frame_T.getByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2298
        if (tag <= 127) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2299
          // (64-127)  [(2)]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2300
          if (tag >= 64)  type_count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2301
        } else if (tag <= 251) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2302
          // (247)     [(1)(2)]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2303
          // (248-251) [(1)]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2304
          if (tag >= 247)  offset_count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2305
          if (tag == 247)  type_count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2306
        } else if (tag <= 254) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2307
          // (252)     [(1)(2)]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2308
          // (253)     [(1)(2)(2)]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2309
          // (254)     [(1)(2)(2)(2)]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2310
          offset_count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2311
          type_count += (tag - 251);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2312
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2313
          // (255)     [(1)NH[(2)]NH[(2)]]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2314
          fat_frame_count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2315
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2316
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2317
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2318
      // done pre-scanning frame tags:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2319
      code_StackMapTable_frame_T.rewind();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2320
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2321
      // deal completely with fat frames:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2322
      offset_count += fat_frame_count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2323
      code_StackMapTable_local_N.readData(fat_frame_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2324
      type_count += code_StackMapTable_local_N.getIntTotal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2325
      code_StackMapTable_stack_N.readData(fat_frame_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2326
      type_count += code_StackMapTable_stack_N.getIntTotal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2327
      // read the rest:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2328
      code_StackMapTable_offset.readData(offset_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2329
      code_StackMapTable_T.readData(type_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2330
      // (7) [RCH]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2331
      count = code_StackMapTable_T.getIntCount(7);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2332
      code_StackMapTable_RC.readData(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2333
      // (8) [PH]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2334
      count = code_StackMapTable_T.getIntCount(8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2335
      code_StackMapTable_P.readData(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2336
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2337
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2338
    count = ad.predefCount(CODE_ATTR_LineNumberTable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2339
    code_LineNumberTable_N.readData(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2340
    count = code_LineNumberTable_N.getIntTotal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2341
    code_LineNumberTable_bci_P.readData(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2342
    code_LineNumberTable_line.readData(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2343
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2344
    count = ad.predefCount(CODE_ATTR_LocalVariableTable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2345
    code_LocalVariableTable_N.readData(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2346
    count = code_LocalVariableTable_N.getIntTotal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2347
    code_LocalVariableTable_bci_P.readData(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2348
    code_LocalVariableTable_span_O.readData(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2349
    code_LocalVariableTable_name_RU.readData(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2350
    code_LocalVariableTable_type_RS.readData(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2351
    code_LocalVariableTable_slot.readData(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2352
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2353
    count = ad.predefCount(CODE_ATTR_LocalVariableTypeTable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2354
    code_LocalVariableTypeTable_N.readData(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2355
    count = code_LocalVariableTypeTable_N.getIntTotal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2356
    code_LocalVariableTypeTable_bci_P.readData(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2357
    code_LocalVariableTypeTable_span_O.readData(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2358
    code_LocalVariableTypeTable_name_RU.readData(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2359
    code_LocalVariableTypeTable_type_RS.readData(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2360
    code_LocalVariableTypeTable_slot.readData(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2361
    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2362
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2363
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2364
  // Read compressor-defined bands.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2365
  for (idx = 0; idx < ad.layouts.length(); idx++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2366
    if (ad.getLayout(idx) == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2367
      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
  2368
    if (idx < (int)ad.flag_limit && ad.isPredefined(idx))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2369
      continue;  // already handled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2370
    if (ad.getCount(idx) == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2371
      continue;  // no attributes of this type (then why transmit layouts?)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2372
    ad.readBandData(idx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2373
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2374
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2375
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2376
void unpacker::attr_definitions::readBandData(int idx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2377
  int j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2378
  uint count = getCount(idx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2379
  if (count == 0)  return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2380
  layout_definition* lo = getLayout(idx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2381
  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
  2382
    PRINTCR((1, "counted %d [redefined = %d predefined = %d] attributes of type %s.%s",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2383
            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
  2384
            ATTR_CONTEXT_NAME[attrc], lo->name));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2385
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2386
  bool hasCallables = lo->hasCallables();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2387
  band** bands = lo->bands();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2388
  if (!hasCallables) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2389
    // Read through the rest of the bands in a regular way.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2390
    readBandData(bands, count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2391
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2392
    // Deal with the callables.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2393
    // First set up the forward entry count for each callable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2394
    // This is stored on band::length of the callable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2395
    bands[0]->expectMoreLength(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2396
    for (j = 0; bands[j] != null; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2397
      band& j_cble = *bands[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2398
      assert(j_cble.le_kind == EK_CBLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2399
      if (j_cble.le_back) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2400
        // Add in the predicted effects of backward calls, too.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2401
        int back_calls = xxx_attr_calls().getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2402
        j_cble.expectMoreLength(back_calls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2403
        // In a moment, more forward calls may increment j_cble.length.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2404
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2405
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2406
    // 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
  2407
    readBandData(bands, (uint)-1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2408
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2409
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2410
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2411
// Recursive helper to the previous function:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2412
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
  2413
  int j, k;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2414
  for (j = 0; body[j] != null; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2415
    band& b = *body[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2416
    if (b.defc != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2417
      // It has data, so read it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2418
      b.readData(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2419
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2420
    switch (b.le_kind) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2421
    case EK_REPL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2422
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2423
        int reps = b.getIntTotal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2424
        readBandData(b.le_body, reps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2425
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2426
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2427
    case EK_UN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2428
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2429
        int remaining = count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2430
        for (k = 0; b.le_body[k] != null; k++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2431
          band& k_case = *b.le_body[k];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2432
          int   k_count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2433
          if (k_case.le_casetags == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2434
            k_count = remaining;  // last (empty) case
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2435
          } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2436
            int* tags = k_case.le_casetags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2437
            int ntags = *tags++;  // 1st element is length (why not?)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2438
            while (ntags-- > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2439
              int tag = *tags++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2440
              k_count += b.getIntCount(tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2441
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2442
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2443
          readBandData(k_case.le_body, k_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2444
          remaining -= k_count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2445
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2446
        assert(remaining == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2447
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2448
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2449
    case EK_CALL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2450
      // Push the count forward, if it is not a backward call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2451
      if (!b.le_back) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2452
        band& cble = *b.le_body[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2453
        assert(cble.le_kind == EK_CBLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2454
        cble.expectMoreLength(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2455
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2456
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2457
    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
  2458
      assert((int)count == -1);  // incoming count is meaningless
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2459
      k = b.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2460
      assert(k >= 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2461
      // This is intended and required for non production mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2462
      assert((b.length = -1)); // make it unable to accept more calls now.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2463
      readBandData(b.le_body, k);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2464
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2465
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2466
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2467
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2468
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2469
static inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2470
band** findMatchingCase(int matchTag, band** cases) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2471
  for (int k = 0; cases[k] != null; k++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2472
    band& k_case = *cases[k];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2473
    if (k_case.le_casetags != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2474
      // If it has tags, it must match a tag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2475
      int* tags = k_case.le_casetags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2476
      int ntags = *tags++;  // 1st element is length
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2477
      for (; ntags > 0; ntags--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2478
        int tag = *tags++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2479
        if (tag == matchTag)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2480
          break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2481
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2482
      if (ntags == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2483
        continue;   // does not match
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2484
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2485
    return k_case.le_body;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2486
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2487
  return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2488
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2489
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2490
// write attribute band data:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2491
void unpacker::putlayout(band** body) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2492
  int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2493
  int prevBII = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2494
  int prevBCI = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2495
  for (i = 0; body[i] != null; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2496
    band& b = *body[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2497
    byte le_kind = b.le_kind;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2498
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2499
    // Handle scalar part, if any.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2500
    int    x = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2501
    entry* e = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2502
    if (b.defc != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2503
      // It has data, so unparse an element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2504
      if (b.ixTag != CONSTANT_None) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2505
        assert(le_kind == EK_REF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2506
        if (b.ixTag == CONSTANT_Literal)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2507
          e = b.getRefUsing(cp.getKQIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2508
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2509
          e = b.getRefN();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2510
        switch (b.le_len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2511
        case 0: break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2512
        case 1: putu1ref(e); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2513
        case 2: putref(e); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2514
        case 4: putu2(0); putref(e); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2515
        default: assert(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2516
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2517
      } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2518
        assert(le_kind == EK_INT || le_kind == EK_REPL || le_kind == EK_UN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2519
        x = b.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2520
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  2521
        assert(!b.le_bci || prevBCI == (int)to_bci(prevBII));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2522
        switch (b.le_bci) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2523
        case EK_BCI:   // PH:  transmit R(bci), store bci
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2524
          x = to_bci(prevBII = x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2525
          prevBCI = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2526
          break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2527
        case EK_BCID:  // POH: transmit D(R(bci)), store bci
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2528
          x = to_bci(prevBII += x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2529
          prevBCI = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2530
          break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2531
        case EK_BCO:   // OH:  transmit D(R(bci)), store D(bci)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2532
          x = to_bci(prevBII += x) - prevBCI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2533
          prevBCI += x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2534
          break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2535
        }
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  2536
        assert(!b.le_bci || prevBCI == (int)to_bci(prevBII));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2537
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2538
        switch (b.le_len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2539
        case 0: break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2540
        case 1: putu1(x); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2541
        case 2: putu2(x); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2542
        case 4: putu4(x); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2543
        default: assert(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2544
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2545
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2546
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2547
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2548
    // Handle subparts, if any.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2549
    switch (le_kind) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2550
    case EK_REPL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2551
      // x is the repeat count
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2552
      while (x-- > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2553
        putlayout(b.le_body);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2554
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2555
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2556
    case EK_UN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2557
      // x is the tag
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2558
      putlayout(findMatchingCase(x, b.le_body));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2559
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2560
    case EK_CALL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2561
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2562
        band& cble = *b.le_body[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2563
        assert(cble.le_kind == EK_CBLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2564
        assert(cble.le_len == b.le_len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2565
        putlayout(cble.le_body);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2566
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2567
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2568
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2569
    #ifndef PRODUCT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2570
    case EK_CBLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2571
    case EK_CASE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2572
      assert(false);  // should not reach here
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2573
    #endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2574
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2575
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2576
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2577
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2578
void unpacker::read_files() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2579
  file_name.readData(file_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2580
  if ((archive_options & AO_HAVE_FILE_SIZE_HI) != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2581
    file_size_hi.readData(file_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2582
  file_size_lo.readData(file_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2583
  if ((archive_options & AO_HAVE_FILE_MODTIME) != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2584
    file_modtime.readData(file_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2585
  int allFiles = file_count + class_count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2586
  if ((archive_options & AO_HAVE_FILE_OPTIONS) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2587
    file_options.readData(file_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2588
    // FO_IS_CLASS_STUB might be set, causing overlap between classes and files
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2589
    for (int i = 0; i < file_count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2590
      if ((file_options.getInt() & FO_IS_CLASS_STUB) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2591
        allFiles -= 1;  // this one counts as both class and file
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2592
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2593
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2594
    file_options.rewind();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2595
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2596
  assert((default_file_options & FO_IS_CLASS_STUB) == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2597
  files_remaining = allFiles;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2598
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2599
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2600
maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2601
void unpacker::get_code_header(int& max_stack,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2602
                               int& max_na_locals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2603
                               int& handler_count,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2604
                               int& cflags) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2605
  int sc = code_headers.getByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2606
  if (sc == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2607
    max_stack = max_na_locals = handler_count = cflags = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2608
    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2609
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2610
  // Short code header is the usual case:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2611
  int nh;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2612
  int mod;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2613
  if (sc < 1 + 12*12) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2614
    sc -= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2615
    nh = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2616
    mod = 12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2617
  } else if (sc < 1 + 12*12 + 8*8) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2618
    sc -= 1 + 12*12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2619
    nh = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2620
    mod = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2621
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2622
    assert(sc < 1 + 12*12 + 8*8 + 7*7);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2623
    sc -= 1 + 12*12 + 8*8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2624
    nh = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2625
    mod = 7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2626
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2627
  max_stack     = sc % mod;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2628
  max_na_locals = sc / mod;  // caller must add static, siglen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2629
  handler_count = nh;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2630
  if ((archive_options & AO_HAVE_ALL_CODE_FLAGS) != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2631
    cflags      = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2632
  else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2633
    cflags      = 0;  // this one has no attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2634
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2635
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2636
// Cf. PackageReader.readCodeHeaders
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2637
void unpacker::read_code_headers() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2638
  code_headers.readData(code_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2639
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2640
  int totalHandlerCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2641
  int totalFlagsCount   = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2642
  for (int i = 0; i < code_count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2643
    int max_stack, max_locals, handler_count, cflags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2644
    get_code_header(max_stack, max_locals, handler_count, cflags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2645
    if (max_stack < 0)      code_max_stack.expectMoreLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2646
    if (max_locals < 0)     code_max_na_locals.expectMoreLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2647
    if (handler_count < 0)  code_handler_count.expectMoreLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2648
    else                    totalHandlerCount += handler_count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2649
    if (cflags < 0)         totalFlagsCount += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2650
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2651
  code_headers.rewind();  // replay later during writing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2652
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2653
  code_max_stack.readData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2654
  code_max_na_locals.readData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2655
  code_handler_count.readData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2656
  totalHandlerCount += code_handler_count.getIntTotal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2657
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2658
  // Read handler specifications.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2659
  // Cf. PackageReader.readCodeHandlers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2660
  code_handler_start_P.readData(totalHandlerCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2661
  code_handler_end_PO.readData(totalHandlerCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2662
  code_handler_catch_PO.readData(totalHandlerCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2663
  code_handler_class_RCN.readData(totalHandlerCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2664
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2665
  read_attrs(ATTR_CONTEXT_CODE, totalFlagsCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2666
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2667
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2668
static inline bool is_in_range(uint n, uint min, uint max) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2669
  return n - min <= max - min;  // unsigned arithmetic!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2670
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2671
static inline bool is_field_op(int bc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2672
  return is_in_range(bc, bc_getstatic, bc_putfield);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2673
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2674
static inline bool is_invoke_init_op(int bc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2675
  return is_in_range(bc, _invokeinit_op, _invokeinit_limit-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2676
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2677
static inline bool is_self_linker_op(int bc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2678
  return is_in_range(bc, _self_linker_op, _self_linker_limit-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2679
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2680
static bool is_branch_op(int bc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2681
  return is_in_range(bc, bc_ifeq,   bc_jsr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2682
      || is_in_range(bc, bc_ifnull, bc_jsr_w);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2683
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2684
static bool is_local_slot_op(int bc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2685
  return is_in_range(bc, bc_iload,  bc_aload)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2686
      || is_in_range(bc, bc_istore, bc_astore)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2687
      || bc == bc_iinc || bc == bc_ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2688
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2689
band* unpacker::ref_band_for_op(int bc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2690
  switch (bc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2691
  case bc_ildc:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2692
  case bc_ildc_w:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2693
    return &bc_intref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2694
  case bc_fldc:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2695
  case bc_fldc_w:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2696
    return &bc_floatref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2697
  case bc_lldc2_w:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2698
    return &bc_longref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2699
  case bc_dldc2_w:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2700
    return &bc_doubleref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2701
  case bc_aldc:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2702
  case bc_aldc_w:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2703
    return &bc_stringref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2704
  case bc_cldc:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2705
  case bc_cldc_w:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2706
    return &bc_classref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2707
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2708
  case bc_getstatic:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2709
  case bc_putstatic:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2710
  case bc_getfield:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2711
  case bc_putfield:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2712
    return &bc_fieldref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2713
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2714
  case bc_invokevirtual:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2715
  case bc_invokespecial:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2716
  case bc_invokestatic:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2717
    return &bc_methodref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2718
  case bc_invokeinterface:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2719
    return &bc_imethodref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2720
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2721
  case bc_new:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2722
  case bc_anewarray:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2723
  case bc_checkcast:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2724
  case bc_instanceof:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2725
  case bc_multianewarray:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2726
    return &bc_classref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2727
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2728
  return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2729
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2730
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2731
maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2732
band* unpacker::ref_band_for_self_op(int bc, bool& isAloadVar, int& origBCVar) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2733
  if (!is_self_linker_op(bc))  return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2734
  int idx = (bc - _self_linker_op);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2735
  bool isSuper = (idx >= _self_linker_super_flag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2736
  if (isSuper)  idx -= _self_linker_super_flag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2737
  bool isAload = (idx >= _self_linker_aload_flag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2738
  if (isAload)  idx -= _self_linker_aload_flag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2739
  int origBC = _first_linker_op + idx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2740
  bool isField = is_field_op(origBC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2741
  isAloadVar = isAload;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2742
  origBCVar  = _first_linker_op + idx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2743
  if (!isSuper)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2744
    return isField? &bc_thisfield: &bc_thismethod;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2745
  else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2746
    return isField? &bc_superfield: &bc_supermethod;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2747
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2748
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2749
// Cf. PackageReader.readByteCodes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2750
inline  // called exactly once => inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2751
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
  2752
  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
  2753
          code_count));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2754
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2755
  // read from bc_codes and bc_case_count
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2756
  fillbytes all_switch_ops;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2757
  all_switch_ops.init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2758
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2759
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2760
  // Read directly from rp/rplimit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2761
  //Do this later:  bc_codes.readData(...)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2762
  byte* rp0 = rp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2763
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2764
  band* bc_which;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2765
  byte* opptr = rp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2766
  byte* oplimit = rplimit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2767
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2768
  bool  isAload;  // passed by ref and then ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2769
  int   junkBC;   // passed by ref and then ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2770
  for (int k = 0; k < code_count; k++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2771
    // Scan one method:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2772
    for (;;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2773
      if (opptr+2 > oplimit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2774
        rp = opptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2775
        ensure_input(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2776
        oplimit = rplimit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2777
        rp = rp0;  // back up
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2778
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2779
      if (opptr == oplimit) { abort(); break; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2780
      int bc = *opptr++ & 0xFF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2781
      bool isWide = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2782
      if (bc == bc_wide) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2783
        if (opptr == oplimit) { abort(); break; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2784
        bc = *opptr++ & 0xFF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2785
        isWide = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2786
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2787
      // Adjust expectations of various band sizes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2788
      switch (bc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2789
      case bc_tableswitch:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2790
      case bc_lookupswitch:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2791
        all_switch_ops.addByte(bc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2792
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2793
      case bc_iinc:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2794
        bc_local.expectMoreLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2795
        bc_which = isWide ? &bc_short : &bc_byte;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2796
        bc_which->expectMoreLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2797
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2798
      case bc_sipush:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2799
        bc_short.expectMoreLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2800
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2801
      case bc_bipush:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2802
        bc_byte.expectMoreLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2803
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2804
      case bc_newarray:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2805
        bc_byte.expectMoreLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2806
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2807
      case bc_multianewarray:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2808
        assert(ref_band_for_op(bc) == &bc_classref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2809
        bc_classref.expectMoreLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2810
        bc_byte.expectMoreLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2811
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2812
      case bc_ref_escape:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2813
        bc_escrefsize.expectMoreLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2814
        bc_escref.expectMoreLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2815
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2816
      case bc_byte_escape:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2817
        bc_escsize.expectMoreLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2818
        // bc_escbyte will have to be counted too
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2819
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2820
      default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2821
        if (is_invoke_init_op(bc)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2822
          bc_initref.expectMoreLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2823
          break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2824
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2825
        bc_which = ref_band_for_self_op(bc, isAload, junkBC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2826
        if (bc_which != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2827
          bc_which->expectMoreLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2828
          break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2829
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2830
        if (is_branch_op(bc)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2831
          bc_label.expectMoreLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2832
          break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2833
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2834
        bc_which = ref_band_for_op(bc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2835
        if (bc_which != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2836
          bc_which->expectMoreLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2837
          assert(bc != bc_multianewarray);  // handled elsewhere
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2838
          break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2839
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2840
        if (is_local_slot_op(bc)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2841
          bc_local.expectMoreLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2842
          break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2843
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2844
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2845
      case bc_end_marker:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2846
        // Increment k and test against code_count.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2847
        goto doneScanningMethod;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2848
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2849
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2850
  doneScanningMethod:{}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2851
    if (aborting())  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2852
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2853
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2854
  // Go through the formality, so we can use it in a regular fashion later:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2855
  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
  2856
  bc_codes.readData((int)(opptr - rp));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2857
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2858
  int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2859
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2860
  // 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
  2861
  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
  2862
  for (i = 0; i < (int)all_switch_ops.size(); i++) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2863
    int caseCount = bc_case_count.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2864
    int bc        = all_switch_ops.getByte(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2865
    bc_label.expectMoreLength(1+caseCount); // default label + cases
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2866
    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
  2867
    PRINTCR((2, "switch bc=%d caseCount=%d", bc, caseCount));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2868
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2869
  bc_case_count.rewind();  // uses again for output
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2870
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2871
  all_switch_ops.free();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2872
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2873
  for (i = e_bc_case_value; i <= e_bc_escsize; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2874
    all_bands[i].readData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2875
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2876
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2877
  // The bc_escbyte band is counted by the immediately previous band.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2878
  bc_escbyte.readData(bc_escsize.getIntTotal());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2879
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  2880
  PRINTCR((3, "scanned %d opcode and %d operand bytes for %d codes...",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2881
          (int)(bc_codes.size()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2882
          (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
  2883
          code_count));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2884
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2885
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2886
void unpacker::read_bands() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2887
  byte* rp0 = rp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2888
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2889
  read_file_header();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2890
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2891
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2892
  if (cp.nentries == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2893
    // read_file_header failed to read a CP, because it copied a JAR.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2894
    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2895
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2896
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2897
  // Do this after the file header has been read:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2898
  check_options();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2899
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2900
  read_cp();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2901
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2902
  read_attr_defs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2903
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2904
  read_ics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2905
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2906
  read_classes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2907
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2908
  read_bcs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2909
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2910
  read_files();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2911
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2912
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2913
/// CP routines
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2914
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2915
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
  2916
  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
  2917
  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
  2918
  for (int i = 0; i < (int)b.len; i++) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2919
    hash = hash * 31 + (0xFF & b.ptr[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2920
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2921
  entry**  ht = hashTab;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2922
  int    hlen = hashTabLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2923
  assert((hlen & (hlen-1)) == 0);  // must be power of 2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2924
  uint hash1 = hash & (hlen-1);    // == hash % hlen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2925
  uint hash2 = 0;                  // lazily computed (requires mod op.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2926
  int probes = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2927
  while (ht[hash1] != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2928
    entry& e = *ht[hash1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2929
    if (e.value.b.equals(b) && e.tag == tag)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2930
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2931
    if (hash2 == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2932
      // Note:  hash2 must be relatively prime to hlen, hence the "|1".
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2933
      hash2 = (((hash % 499) & (hlen-1)) | 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2934
    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
  2935
    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
  2936
    assert(hash1 < (uint)hlen);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2937
    assert(++probes < hlen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2938
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2939
  #ifndef PRODUCT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2940
  hash_probes[0] += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2941
  hash_probes[1] += probes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2942
  #endif
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  2943
  PRINTCR((5, " => @%d %p", hash1, ht[hash1]));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2944
  return ht[hash1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2945
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2946
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2947
maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2948
static void insert_extra(entry* e, ptrlist& extras) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2949
  // This ordering helps implement the Pack200 requirement
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2950
  // of a predictable CP order in the class files produced.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2951
  e->inord = NO_INORD;  // mark as an "extra"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2952
  extras.add(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2953
  // Note:  We will sort the list (by string-name) later.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2954
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2955
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2956
entry* cpool::ensureUtf8(bytes& b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2957
  entry*& ix = hashTabRef(CONSTANT_Utf8, b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2958
  if (ix != null)  return ix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2959
  // Make one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2960
  if (nentries == maxentries) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2961
    abort("cp utf8 overflow");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2962
    return &entries[tag_base[CONSTANT_Utf8]];  // return something
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2963
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2964
  entry& e = entries[nentries++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2965
  e.tag = CONSTANT_Utf8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2966
  u->saveTo(e.value.b, b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2967
  assert(&e >= first_extra_entry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2968
  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
  2969
  PRINTCR((4,"ensureUtf8 miss %s", e.string()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2970
  return ix = &e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2971
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2972
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2973
entry* cpool::ensureClass(bytes& b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2974
  entry*& ix = hashTabRef(CONSTANT_Class, b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2975
  if (ix != null)  return ix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2976
  // Make one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2977
  if (nentries == maxentries) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2978
    abort("cp class overflow");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2979
    return &entries[tag_base[CONSTANT_Class]];  // return something
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2980
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2981
  entry& e = entries[nentries++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2982
  e.tag = CONSTANT_Class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2983
  e.nrefs = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2984
  e.refs = U_NEW(entry*, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2985
  ix = &e;  // hold my spot in the index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2986
  entry* utf = ensureUtf8(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2987
  e.refs[0] = utf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2988
  e.value.b = utf->value.b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2989
  assert(&e >= first_extra_entry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2990
  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
  2991
  PRINTCR((4,"ensureClass miss %s", e.string()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2992
  return &e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2993
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2994
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2995
void cpool::expandSignatures() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2996
  int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2997
  int nsigs = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2998
  int nreused = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2999
  int first_sig = tag_base[CONSTANT_Signature];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3000
  int sig_limit = tag_count[CONSTANT_Signature] + first_sig;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3001
  fillbytes buf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3002
  buf.init(1<<10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3003
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3004
  for (i = first_sig; i < sig_limit; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3005
    entry& e = entries[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3006
    assert(e.tag == CONSTANT_Signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3007
    int refnum = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3008
    bytes form = e.refs[refnum++]->asUtf8();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3009
    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
  3010
    for (int j = 0; j < (int)form.len; j++) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3011
      int c = form.ptr[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3012
      buf.addByte(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3013
      if (c == 'L') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3014
        entry* cls = e.refs[refnum++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3015
        buf.append(cls->className()->asUtf8());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3016
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3017
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3018
    assert(refnum == e.nrefs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3019
    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
  3020
    PRINTCR((5,"signature %d %s -> %s", i, form.ptr, sig.ptr));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3021
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3022
    // try to find a pre-existing Utf8:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3023
    entry* &e2 = hashTabRef(CONSTANT_Utf8, sig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3024
    if (e2 != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3025
      assert(e2->isUtf8(sig));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3026
      e.value.b = e2->value.b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3027
      e.refs[0] = e2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3028
      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
  3029
      PRINTCR((5,"signature replaced %d => %s", i, e.string()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3030
      nreused++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3031
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3032
      // there is no other replacement; reuse this CP entry as a Utf8
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3033
      u->saveTo(e.value.b, sig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3034
      e.tag = CONSTANT_Utf8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3035
      e.nrefs = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3036
      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
  3037
      PRINTCR((5,"signature changed %d => %s", e.inord, e.string()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3038
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3039
    nsigs++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3040
  }
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  3041
  PRINTCR((1,"expanded %d signatures (reused %d utfs)", nsigs, nreused));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3042
  buf.free();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3043
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3044
  // 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
  3045
  for (i = 0; i < (int)nentries; i++) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3046
    entry& e = entries[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3047
    for (int j = 0; j < e.nrefs; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3048
      entry*& e2 = e.refs[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3049
      if (e2 != null && e2->tag == CONSTANT_Signature)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3050
        e2 = e2->refs[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3051
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3052
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3053
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3054
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3055
void cpool::initMemberIndexes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3056
  // This function does NOT refer to any class schema.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3057
  // 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
  3058
  int i, j;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3059
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3060
  // Get the pre-existing indexes:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3061
  int   nclasses = tag_count[CONSTANT_Class];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3062
  entry* classes = tag_base[CONSTANT_Class] + entries;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3063
  int   nfields  = tag_count[CONSTANT_Fieldref];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3064
  entry* fields  = tag_base[CONSTANT_Fieldref] + entries;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3065
  int   nmethods = tag_count[CONSTANT_Methodref];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3066
  entry* methods = tag_base[CONSTANT_Methodref] + entries;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3067
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3068
  int*     field_counts  = T_NEW(int, nclasses);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3069
  int*     method_counts = T_NEW(int, nclasses);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3070
  cpindex* all_indexes   = U_NEW(cpindex, nclasses*2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3071
  entry**  field_ix      = U_NEW(entry*, nfields+nclasses);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3072
  entry**  method_ix     = U_NEW(entry*, nmethods+nclasses);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3073
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3074
  for (j = 0; j < nfields; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3075
    entry& f = fields[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3076
    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
  3077
    assert(i < nclasses);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3078
    field_counts[i]++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3079
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3080
  for (j = 0; j < nmethods; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3081
    entry& m = methods[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3082
    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
  3083
    assert(i < nclasses);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3084
    method_counts[i]++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3085
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3086
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3087
  int fbase = 0, mbase = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3088
  for (i = 0; i < nclasses; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3089
    int fc = field_counts[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3090
    int mc = method_counts[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3091
    all_indexes[i*2+0].init(fc, field_ix+fbase,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3092
                            CONSTANT_Fieldref  + SUBINDEX_BIT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3093
    all_indexes[i*2+1].init(mc, method_ix+mbase,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3094
                            CONSTANT_Methodref + SUBINDEX_BIT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3095
    // reuse field_counts and member_counts as fill pointers:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3096
    field_counts[i] = fbase;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3097
    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
  3098
    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
  3099
            i, fbase, fc, mbase, mc));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3100
    fbase += fc+1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3101
    mbase += mc+1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3102
    // (the +1 leaves a space between every subarray)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3103
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3104
  assert(fbase == nfields+nclasses);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3105
  assert(mbase == nmethods+nclasses);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3106
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3107
  for (j = 0; j < nfields; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3108
    entry& f = fields[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3109
    i = f.memberClass()->inord;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3110
    field_ix[field_counts[i]++] = &f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3111
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3112
  for (j = 0; j < nmethods; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3113
    entry& m = methods[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3114
    i = m.memberClass()->inord;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3115
    method_ix[method_counts[i]++] = &m;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3116
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3117
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3118
  member_indexes = all_indexes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3119
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3120
#ifndef PRODUCT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3121
  // Test the result immediately on every class and field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3122
  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
  3123
  int prevord, len;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3124
  for (i = 0; i < nclasses; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3125
    entry*   cls = &classes[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3126
    cpindex* fix = getFieldIndex(cls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3127
    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
  3128
    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
  3129
            cls->string(), mix->len, fix->len));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3130
    prevord = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3131
    for (j = 0, len = fix->len; j < len; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3132
      entry* f = fix->get(j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3133
      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
  3134
      PRINTCR((3, "- field %s", f->string()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3135
      assert(f->memberClass() == cls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3136
      assert(prevord < (int)f->inord);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3137
      prevord = f->inord;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3138
      fvisited++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3140
    assert(fix->base2[j] == null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3141
    prevord = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3142
    for (j = 0, len = mix->len; j < len; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3143
      entry* m = mix->get(j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3144
      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
  3145
      PRINTCR((3, "- method %s", m->string()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3146
      assert(m->memberClass() == cls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3147
      assert(prevord < (int)m->inord);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3148
      prevord = m->inord;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3149
      mvisited++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3151
    assert(mix->base2[j] == null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3152
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3153
  assert(fvisited == nfields);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3154
  assert(mvisited == nmethods);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3155
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3156
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3157
  // Free intermediate buffers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3158
  u->free_temps();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3159
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3160
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3161
void entry::requestOutputIndex(cpool& cp, int req) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3162
  assert(outputIndex <= NOT_REQUESTED);  // must not have assigned indexes yet
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3163
  if (tag == CONSTANT_Signature) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3164
    ref(0)->requestOutputIndex(cp, req);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3165
    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3166
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3167
  assert(req == REQUESTED || req == REQUESTED_LDC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3168
  if (outputIndex != NOT_REQUESTED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3169
    if (req == REQUESTED_LDC)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3170
      outputIndex = req;  // this kind has precedence
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3171
    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3172
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3173
  outputIndex = req;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3174
  //assert(!cp.outputEntries.contains(this));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3175
  assert(tag != CONSTANT_Signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3176
  cp.outputEntries.add(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3177
  for (int j = 0; j < nrefs; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3178
    ref(j)->requestOutputIndex(cp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3179
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3180
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3181
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3182
void cpool::resetOutputIndexes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3183
  int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3184
  int    noes =           outputEntries.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3185
  entry** oes = (entry**) outputEntries.base();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3186
  for (i = 0; i < noes; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3187
    entry& e = *oes[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3188
    e.outputIndex = NOT_REQUESTED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3189
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3190
  outputIndexLimit = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3191
  outputEntries.empty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3192
#ifndef PRODUCT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3193
  // they must all be clear now
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  3194
  for (i = 0; i < (int)nentries; i++)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3195
    assert(entries[i].outputIndex == NOT_REQUESTED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3196
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3197
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3198
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3199
static const byte TAG_ORDER[CONSTANT_Limit] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3200
  0, 1, 0, 2, 3, 4, 5, 7, 6, 10, 11, 12, 9, 8
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3201
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3202
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3203
extern "C"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3204
int outputEntry_cmp(const void* e1p, const void* e2p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3205
  // Sort entries according to the Pack200 rules for deterministic
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3206
  // constant pool ordering.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3207
  //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3208
  // The four sort keys as follows, in order of decreasing importance:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3209
  //   1. ldc first, then non-ldc guys
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3210
  //   2. normal cp_All entries by input order (i.e., address order)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3211
  //   3. after that, extra entries by lexical order (as in tag_extras[*])
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3212
  entry& e1 = *(entry*) *(void**) e1p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3213
  entry& e2 = *(entry*) *(void**) e2p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3214
  int   oi1 = e1.outputIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3215
  int   oi2 = e2.outputIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3216
  assert(oi1 == REQUESTED || oi1 == REQUESTED_LDC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3217
  assert(oi2 == REQUESTED || oi2 == REQUESTED_LDC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3218
  if (oi1 != oi2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3219
    if (oi1 == REQUESTED_LDC)  return 0-1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3220
    if (oi2 == REQUESTED_LDC)  return 1-0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3221
    // Else fall through; neither is an ldc request.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3222
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3223
  if (e1.inord != NO_INORD || e2.inord != NO_INORD) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3224
    // One or both is normal.  Use input order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3225
    if (&e1 > &e2)  return 1-0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3226
    if (&e1 < &e2)  return 0-1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3227
    return 0;  // equal pointers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3228
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3229
  // Both are extras.  Sort by tag and then by value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3230
  if (e1.tag != e2.tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3231
    return TAG_ORDER[e1.tag] - TAG_ORDER[e2.tag];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3232
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3233
  // If the tags are the same, use string comparison.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3234
  return compare_Utf8_chars(e1.value.b, e2.value.b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3235
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3236
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3237
void cpool::computeOutputIndexes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3238
  int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3239
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3240
#ifndef PRODUCT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3241
  // outputEntries must be a complete list of those requested:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3242
  static uint checkStart = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3243
  int checkStep = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3244
  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
  3245
  for (i = (int)(checkStart++ % checkStep); i < (int)nentries; i += checkStep) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3246
    entry& e = entries[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3247
    if (e.outputIndex != NOT_REQUESTED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3248
      assert(outputEntries.contains(&e));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3249
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3250
      assert(!outputEntries.contains(&e));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3252
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3253
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3254
  // 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
  3255
  for (i = 0; i < (int)N_TAGS_IN_ORDER; i++) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3256
    byte tag = TAGS_IN_ORDER[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3257
    assert(TAG_ORDER[tag] == i+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3258
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3259
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3260
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3261
  int    noes =           outputEntries.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3262
  entry** oes = (entry**) outputEntries.base();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3263
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3264
  // Sort the output constant pool into the order required by Pack200.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3265
  PTRLIST_QSORT(outputEntries, outputEntry_cmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3266
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3267
  // Allocate a new index for each entry that needs one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3268
  // We do this in two passes, one for LDC entries and one for the rest.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3269
  int nextIndex = 1;  // always skip index #0 in output cpool
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3270
  for (i = 0; i < noes; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3271
    entry& e = *oes[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3272
    assert(e.outputIndex == REQUESTED || e.outputIndex == REQUESTED_LDC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3273
    e.outputIndex = nextIndex++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3274
    if (e.isDoubleWord())  nextIndex++;  // do not use the next index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3275
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3276
  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
  3277
  PRINTCR((3,"renumbering CP to %d entries", outputIndexLimit));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3278
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3279
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3280
#ifndef PRODUCT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3281
// debugging goo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3282
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3283
unpacker* debug_u;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3284
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3285
static bytes& getbuf(int len) {  // for debugging only!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3286
  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
  3287
  static bytes bufs[8];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3288
  bytes& buf = bufs[bn++ & 7];
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  3289
  while ((int)buf.len < len+10)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3290
    buf.realloc(buf.len ? buf.len * 2 : 1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3291
  buf.ptr[0] = 0;  // for the sake of strcat
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3292
  return buf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3293
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3294
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3295
char* entry::string() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3296
  bytes buf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3297
  switch (tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3298
  case CONSTANT_None:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3299
    return (char*)"<empty>";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3300
  case CONSTANT_Signature:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3301
    if (value.b.ptr == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3302
      return ref(0)->string();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3303
    // else fall through:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3304
  case CONSTANT_Utf8:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3305
    buf = value.b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3306
    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3307
  case CONSTANT_Integer:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3308
  case CONSTANT_Float:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3309
    buf = getbuf(12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3310
    sprintf((char*)buf.ptr, "0x%08x", value.i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3311
    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3312
  case CONSTANT_Long:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3313
  case CONSTANT_Double:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3314
    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
  3315
    sprintf((char*)buf.ptr, "0x" LONG_LONG_HEX_FORMAT, value.l);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3316
    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3317
  default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3318
    if (nrefs == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3319
      buf = getbuf(20);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3320
      sprintf((char*)buf.ptr, "<tag=%d>", tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3321
    } else if (nrefs == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3322
      return refs[0]->string();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3323
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3324
      char* s1 = refs[0]->string();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3325
      char* s2 = refs[1]->string();
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  3326
      buf = getbuf((int)strlen(s1) + 1 + (int)strlen(s2) + 4 + 1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3327
      buf.strcat(s1).strcat(" ").strcat(s2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3328
      if (nrefs > 2)  buf.strcat(" ...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3329
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3330
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3331
  return (char*)buf.ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3332
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3333
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3334
void print_cp_entry(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3335
  entry& e = debug_u->cp.entries[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3336
  char buf[30];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3337
  sprintf(buf, ((uint)e.tag < CONSTANT_Limit)? TAG_NAME[e.tag]: "%d", e.tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3338
  printf(" %d\t%s %s\n", i, buf, e.string());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3339
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3340
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3341
void print_cp_entries(int beg, int end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3342
  for (int i = beg; i < end; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3343
    print_cp_entry(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3344
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3345
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3346
void print_cp() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3347
  print_cp_entries(0, debug_u->cp.nentries);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3348
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3349
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3350
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3351
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3352
// Unpacker Start
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3353
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3354
const char str_tf[] = "true\0false";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3355
#undef STR_TRUE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3356
#undef STR_FALSE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3357
#define STR_TRUE   (&str_tf[0])
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3358
#define STR_FALSE  (&str_tf[5])
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3359
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3360
const char* unpacker::get_option(const char* prop) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3361
  if (prop == null )  return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3362
  if (strcmp(prop, UNPACK_DEFLATE_HINT) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3363
    return deflate_hint_or_zero == 0? null : STR_TF(deflate_hint_or_zero > 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3364
#ifdef HAVE_STRIP
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3365
  } else if (strcmp(prop, UNPACK_STRIP_COMPILE) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3366
    return STR_TF(strip_compile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3367
  } else if (strcmp(prop, UNPACK_STRIP_DEBUG) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3368
    return STR_TF(strip_debug);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3369
  } else if (strcmp(prop, UNPACK_STRIP_JCOV) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3370
    return STR_TF(strip_jcov);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3371
#endif /*HAVE_STRIP*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3372
  } else if (strcmp(prop, UNPACK_REMOVE_PACKFILE) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3373
    return STR_TF(remove_packfile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3374
  } else if (strcmp(prop, DEBUG_VERBOSE) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3375
    return saveIntStr(verbose);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3376
  } else if (strcmp(prop, UNPACK_MODIFICATION_TIME) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3377
    return (modification_time_or_zero == 0)? null:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3378
      saveIntStr(modification_time_or_zero);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3379
  } else if (strcmp(prop, UNPACK_LOG_FILE) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3380
    return log_file;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3381
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3382
    return NULL; // unknown option ignore
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3383
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3384
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3385
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3386
bool unpacker::set_option(const char* prop, const char* value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3387
  if (prop == NULL)  return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3388
  if (strcmp(prop, UNPACK_DEFLATE_HINT) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3389
    deflate_hint_or_zero = ( (value == null || strcmp(value, "keep") == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3390
                                ? 0: BOOL_TF(value) ? +1: -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3391
#ifdef HAVE_STRIP
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3392
  } else if (strcmp(prop, UNPACK_STRIP_COMPILE) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3393
    strip_compile = STR_TF(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3394
  } else if (strcmp(prop, UNPACK_STRIP_DEBUG) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3395
    strip_debug = STR_TF(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3396
  } else if (strcmp(prop, UNPACK_STRIP_JCOV) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3397
    strip_jcov = STR_TF(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3398
#endif /*HAVE_STRIP*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3399
  } else if (strcmp(prop, UNPACK_REMOVE_PACKFILE) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3400
    remove_packfile = STR_TF(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3401
  } else if (strcmp(prop, DEBUG_VERBOSE) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3402
    verbose = (value == null)? 0: atoi(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3403
  } else if (strcmp(prop, DEBUG_VERBOSE ".bands") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3404
#ifndef PRODUCT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3405
    verbose_bands = (value == null)? 0: atoi(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3406
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3407
  } else if (strcmp(prop, UNPACK_MODIFICATION_TIME) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3408
    if (value == null || (strcmp(value, "keep") == 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3409
      modification_time_or_zero = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3410
    } else if (strcmp(value, "now") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3411
      time_t now;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3412
      time(&now);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3413
      modification_time_or_zero = (int) now;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3414
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3415
      modification_time_or_zero = atoi(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3416
      if (modification_time_or_zero == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3417
        modification_time_or_zero = 1;  // make non-zero
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3418
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3419
  } else if (strcmp(prop, UNPACK_LOG_FILE) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3420
    log_file = (value == null)? value: saveStr(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3421
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3422
    return false; // unknown option ignore
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3423
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3424
  return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3425
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3426
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3427
// Deallocate all internal storage and reset to a clean state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3428
// Do not disturb any input or output connections, including
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3429
// infileptr, infileno, inbytes, read_input_fn, jarout, or errstrm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3430
// Do not reset any unpack options.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3431
void unpacker::reset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3432
  bytes_read_before_reset      += bytes_read;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3433
  bytes_written_before_reset   += bytes_written;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3434
  files_written_before_reset   += files_written;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3435
  classes_written_before_reset += classes_written;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3436
  segments_read_before_reset   += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3437
  if (verbose >= 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3438
    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
  3439
            "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
  3440
            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
  3441
            LONG_LONG_FORMAT " bytes written.\n",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3442
            segments_read_before_reset-1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3443
            bytes_read_before_reset, bytes_written_before_reset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3444
    fprintf(errstrm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3445
            "After segment %d, %d files (of which %d are classes) written to output.\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3446
            segments_read_before_reset-1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3447
            files_written_before_reset, classes_written_before_reset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3448
    if (archive_next_count != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3449
      fprintf(errstrm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3450
              "After segment %d, %d segment%s remaining (estimated).\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3451
              segments_read_before_reset-1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3452
              archive_next_count, archive_next_count==1?"":"s");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3453
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3454
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3455
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3456
  unpacker save_u = (*this);  // save bytewise image
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3457
  infileptr = null;  // make asserts happy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3458
  jniobj = null;  // make asserts happy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3459
  jarout = null;  // do not close the output jar
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3460
  gzin = null;  // do not close the input gzip stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3461
  bytes esn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3462
  if (errstrm_name != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3463
    esn.saveFrom(errstrm_name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3464
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3465
    esn.set(null, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3466
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3467
  this->free();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3468
  mtrace('s', 0, 0);  // note the boundary between segments
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3469
  this->init(read_input_fn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3470
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3471
  // restore selected interface state:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3472
#define SAVE(x) this->x = save_u.x
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3473
  SAVE(jniobj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3474
  SAVE(jnienv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3475
  SAVE(infileptr);  // buffered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3476
  SAVE(infileno);   // unbuffered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3477
  SAVE(inbytes);    // direct
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3478
  SAVE(jarout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3479
  SAVE(gzin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3480
  //SAVE(read_input_fn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3481
  SAVE(errstrm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3482
  SAVE(verbose);  // verbose level, 0 means no output
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3483
  SAVE(strip_compile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3484
  SAVE(strip_debug);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3485
  SAVE(strip_jcov);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3486
  SAVE(remove_packfile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3487
  SAVE(deflate_hint_or_zero);  // ==0 means not set, otherwise -1 or 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3488
  SAVE(modification_time_or_zero);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3489
  SAVE(bytes_read_before_reset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3490
  SAVE(bytes_written_before_reset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3491
  SAVE(files_written_before_reset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3492
  SAVE(classes_written_before_reset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3493
  SAVE(segments_read_before_reset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3494
#undef SAVE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3495
  if (esn.len > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3496
    errstrm_name = saveStr(esn.strval());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3497
    esn.free();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3498
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3499
  log_file = errstrm_name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3500
  // Note:  If we use strip_names, watch out:  They get nuked here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3501
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3502
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3503
void unpacker::init(read_input_fn_t input_fn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3504
  int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3505
  NOT_PRODUCT(debug_u = this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3506
  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
  3507
#ifndef PRODUCT
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  3508
  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
  3509
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3510
  this->u = this;    // self-reference for U_NEW macro
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3511
  errstrm = stdout;  // default error-output
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3512
  log_file = LOGFILE_STDOUT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3513
  read_input_fn = input_fn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3514
  all_bands = band::makeBands(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3515
  // Make a default jar buffer; caller may safely overwrite it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3516
  jarout = U_NEW(jar, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3517
  jarout->init(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3518
  for (i = 0; i < ATTR_CONTEXT_LIMIT; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3519
    attr_defs[i].u = u;  // set up outer ptr
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3520
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3521
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3522
const char* unpacker::get_abort_message() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3523
   return abort_message;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3524
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3525
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3526
void unpacker::dump_options() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3527
  static const char* opts[] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3528
    UNPACK_LOG_FILE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3529
    UNPACK_DEFLATE_HINT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3530
#ifdef HAVE_STRIP
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3531
    UNPACK_STRIP_COMPILE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3532
    UNPACK_STRIP_DEBUG,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3533
    UNPACK_STRIP_JCOV,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3534
#endif /*HAVE_STRIP*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3535
    UNPACK_REMOVE_PACKFILE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3536
    DEBUG_VERBOSE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3537
    UNPACK_MODIFICATION_TIME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3538
    null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3539
  };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3540
  for (int i = 0; opts[i] != null; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3541
    const char* str = get_option(opts[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3542
    if (str == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3543
      if (verbose == 0)  continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3544
      str = "(not set)";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3545
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3546
    fprintf(errstrm, "%s=%s\n", opts[i], str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3547
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3548
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3549
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3550
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3551
// Usage: unpack a byte buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3552
// packptr is a reference to byte buffer containing a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3553
// packed file and len is the length of the buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3554
// If null, the callback is used to fill an internal buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3555
void unpacker::start(void* packptr, size_t len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3556
  NOT_PRODUCT(debug_u = this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3557
  if (packptr != null && len != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3558
    inbytes.set((byte*) packptr, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3559
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3560
  read_bands();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3561
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3562
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3563
void unpacker::check_options() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3564
  const char* strue  = "true";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3565
  const char* sfalse = "false";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3566
  if (deflate_hint_or_zero != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3567
    bool force_deflate_hint = (deflate_hint_or_zero > 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3568
    if (force_deflate_hint)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3569
      default_file_options |= FO_DEFLATE_HINT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3570
    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3571
      default_file_options &= ~FO_DEFLATE_HINT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3572
    // Turn off per-file deflate hint by force.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3573
    suppress_file_options |= FO_DEFLATE_HINT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3574
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3575
  if (modification_time_or_zero != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3576
    default_file_modtime = modification_time_or_zero;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3577
    // Turn off per-file modtime by force.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3578
    archive_options &= ~AO_HAVE_FILE_MODTIME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3579
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3580
  // %%% strip_compile, etc...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3581
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3582
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3583
// classfile writing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3584
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3585
void unpacker::reset_cur_classfile() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3586
  // set defaults
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3587
  cur_class_minver = default_class_minver;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3588
  cur_class_majver = default_class_majver;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3589
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3590
  // reset constant pool state
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3591
  cp.resetOutputIndexes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3592
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3593
  // reset fixups
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3594
  class_fixup_type.empty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3595
  class_fixup_offset.empty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3596
  class_fixup_ref.empty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3597
  requested_ics.empty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3598
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3599
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3600
cpindex* cpool::getKQIndex() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3601
  char ch = '?';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3602
  if (u->cur_descr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3603
    entry* type = u->cur_descr->descrType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3604
    ch = type->value.b.ptr[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3605
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3606
  byte tag = CONSTANT_Integer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3607
  switch (ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3608
  case 'L': tag = CONSTANT_String;   break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3609
  case 'I': tag = CONSTANT_Integer;  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3610
  case 'J': tag = CONSTANT_Long;     break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3611
  case 'F': tag = CONSTANT_Float;    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3612
  case 'D': tag = CONSTANT_Double;   break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3613
  case 'B': case 'S': case 'C':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3614
  case 'Z': tag = CONSTANT_Integer;  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3615
  default:  abort("bad KQ reference"); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3616
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3617
  return getIndex(tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3618
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3619
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3620
uint unpacker::to_bci(uint bii) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3621
  uint  len =         bcimap.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3622
  uint* map = (uint*) bcimap.base();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3623
  assert(len > 0);  // must be initialized before using to_bci
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3624
  if (bii < len)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3625
    return map[bii];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3626
  // Else it's a fractional or out-of-range BCI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3627
  uint key = bii-len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3628
  for (int i = len; ; i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3629
    if (map[i-1]-(i-1) <= key)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3630
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3631
    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3632
      --bii;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3633
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3634
  return bii;
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 unpacker::put_stackmap_type() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3638
  int tag = code_StackMapTable_T.getByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3639
  putu1(tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3640
  switch (tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3641
  case 7: // (7) [RCH]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3642
    putref(code_StackMapTable_RC.getRef());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3643
    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3644
  case 8: // (8) [PH]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3645
    putu2(to_bci(code_StackMapTable_P.getInt()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3646
    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3647
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3648
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3649
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3650
// Functions for writing code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3651
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3652
maybe_inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3653
void unpacker::put_label(int curIP, int size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3654
  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
  3655
  code_fixup_offset.add((int)put_empty(size));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3656
  code_fixup_source.add(curIP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3657
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3658
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3659
inline  // called exactly once => inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3660
void unpacker::write_bc_ops() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3661
  bcimap.empty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3662
  code_fixup_type.empty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3663
  code_fixup_offset.empty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3664
  code_fixup_source.empty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3665
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3666
  band* bc_which;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3667
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3668
  byte*  opptr = bc_codes.curRP();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3669
  // No need for oplimit, since the codes are pre-counted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3670
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3671
  size_t codeBase = wpoffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3672
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3673
  bool   isAload;  // copy-out result
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3674
  int    origBC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3675
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3676
  entry* thisClass  = cur_class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3677
  entry* superClass = cur_super;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3678
  entry* newClass   = null;  // class of last _new opcode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3679
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3680
  // overwrite any prior index on these bands; it changes w/ current class:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3681
  bc_thisfield.setIndex(    cp.getFieldIndex( thisClass));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3682
  bc_thismethod.setIndex(   cp.getMethodIndex(thisClass));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3683
  if (superClass != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3684
    bc_superfield.setIndex( cp.getFieldIndex( superClass));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3685
    bc_supermethod.setIndex(cp.getMethodIndex(superClass));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3686
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3687
    NOT_PRODUCT(bc_superfield.setIndex(null));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3688
    NOT_PRODUCT(bc_supermethod.setIndex(null));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3689
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3690
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3691
  for (int curIP = 0; ; curIP++) {
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  3692
    int curPC = (int)(wpoffset() - codeBase);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3693
    bcimap.add(curPC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3694
    ensure_put_space(10);  // covers most instrs w/o further bounds check
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3695
    int bc = *opptr++ & 0xFF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3696
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3697
    putu1_fast(bc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3698
    // Note:  See '--wp' below for pseudo-bytecodes like bc_end_marker.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3699
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3700
    bool isWide = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3701
    if (bc == bc_wide) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3702
      bc = *opptr++ & 0xFF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3703
      putu1_fast(bc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3704
      isWide = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3705
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3706
    switch (bc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3707
    case bc_end_marker:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3708
      --wp;  // not really part of the code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3709
      assert(opptr <= bc_codes.maxRP());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3710
      bc_codes.curRP() = opptr;  // advance over this in bc_codes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3711
      goto doneScanningMethod;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3712
    case bc_tableswitch: // apc:  (df, lo, hi, (hi-lo+1)*(label))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3713
    case bc_lookupswitch: // apc:  (df, nc, nc*(case, label))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3714
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3715
        int caseCount = bc_case_count.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3716
        while (((wpoffset() - codeBase) % 4) != 0)  putu1_fast(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3717
        ensure_put_space(30 + caseCount*8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3718
        put_label(curIP, 4);  //int df = bc_label.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3719
        if (bc == bc_tableswitch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3720
          int lo = bc_case_value.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3721
          int hi = lo + caseCount-1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3722
          putu4(lo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3723
          putu4(hi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3724
          for (int j = 0; j < caseCount; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3725
            put_label(curIP, 4); //int lVal = bc_label.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3726
            //int cVal = lo + j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3727
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3728
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3729
          putu4(caseCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3730
          for (int j = 0; j < caseCount; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3731
            int cVal = bc_case_value.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3732
            putu4(cVal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3733
            put_label(curIP, 4); //int lVal = bc_label.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3734
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3735
        }
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  3736
        assert((int)to_bci(curIP) == curPC);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3737
        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3738
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3739
    case bc_iinc:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3740
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3741
        int local = bc_local.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3742
        int delta = (isWide ? bc_short : bc_byte).getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3743
        if (isWide) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3744
          putu2(local);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3745
          putu2(delta);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3746
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3747
          putu1_fast(local);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3748
          putu1_fast(delta);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3749
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3750
        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3751
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3752
    case bc_sipush:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3753
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3754
        int val = bc_short.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3755
        putu2(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3756
        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3757
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3758
    case bc_bipush:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3759
    case bc_newarray:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3760
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3761
        int val = bc_byte.getByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3762
        putu1_fast(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3763
        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3764
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3765
    case bc_ref_escape:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3766
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3767
        // Note that insnMap has one entry for this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3768
        --wp;  // not really part of the code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3769
        int size = bc_escrefsize.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3770
        entry* ref = bc_escref.getRefN();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3771
        CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3772
        switch (size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3773
        case 1: putu1ref(ref); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3774
        case 2: putref(ref);   break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3775
        default: assert(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3776
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3777
        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3778
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3779
    case bc_byte_escape:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3780
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3781
        // Note that insnMap has one entry for all these bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3782
        --wp;  // not really part of the code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3783
        int size = bc_escsize.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3784
        ensure_put_space(size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3785
        for (int j = 0; j < size; j++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3786
          putu1_fast(bc_escbyte.getByte());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3787
        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3788
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3789
    default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3790
      if (is_invoke_init_op(bc)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3791
        origBC = bc_invokespecial;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3792
        entry* classRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3793
        switch (bc - _invokeinit_op) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3794
        case _invokeinit_self_option:   classRef = thisClass;  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3795
        case _invokeinit_super_option:  classRef = superClass; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3796
        default: assert(bc == _invokeinit_op+_invokeinit_new_option);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3797
        case _invokeinit_new_option:    classRef = newClass;   break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3798
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3799
        wp[-1] = origBC;  // overwrite with origBC
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3800
        int coding = bc_initref.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3801
        // Find the nth overloading of <init> in classRef.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3802
        entry*   ref = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3803
        cpindex* ix = (classRef == null)? null: cp.getMethodIndex(classRef);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3804
        for (int j = 0, which_init = 0; ; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3805
          ref = (ix == null)? null: ix->get(j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3806
          if (ref == null)  break;  // oops, bad input
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3807
          assert(ref->tag == CONSTANT_Methodref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3808
          if (ref->memberDescr()->descrName() == cp.sym[cpool::s_lt_init_gt]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3809
            if (which_init++ == coding)  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3810
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3811
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3812
        putref(ref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3813
        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3814
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3815
      bc_which = ref_band_for_self_op(bc, isAload, origBC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3816
      if (bc_which != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3817
        if (!isAload) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3818
          wp[-1] = origBC;  // overwrite with origBC
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3819
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3820
          wp[-1] = bc_aload_0;  // overwrite with _aload_0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3821
          // Note: insnMap keeps the _aload_0 separate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3822
          bcimap.add(++curPC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3823
          ++curIP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3824
          putu1_fast(origBC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3825
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3826
        entry* ref = bc_which->getRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3827
        CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3828
        putref(ref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3829
        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3830
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3831
      if (is_branch_op(bc)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3832
        //int lVal = bc_label.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3833
        if (bc < bc_goto_w) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3834
          put_label(curIP, 2);  //putu2(lVal & 0xFFFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3835
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3836
          assert(bc <= bc_jsr_w);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3837
          put_label(curIP, 4);  //putu4(lVal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3838
        }
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  3839
        assert((int)to_bci(curIP) == curPC);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3840
        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3841
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3842
      bc_which = ref_band_for_op(bc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3843
      if (bc_which != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3844
        entry* ref = bc_which->getRefCommon(bc_which->ix, bc_which->nullOK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3845
        CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3846
        if (ref == null && bc_which == &bc_classref) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3847
          // Shorthand for class self-references.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3848
          ref = thisClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3849
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3850
        origBC = bc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3851
        switch (bc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3852
        case bc_ildc:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3853
        case bc_cldc:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3854
        case bc_fldc:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3855
        case bc_aldc:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3856
          origBC = bc_ldc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3857
          break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3858
        case bc_ildc_w:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3859
        case bc_cldc_w:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3860
        case bc_fldc_w:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3861
        case bc_aldc_w:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3862
          origBC = bc_ldc_w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3863
          break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3864
        case bc_lldc2_w:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3865
        case bc_dldc2_w:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3866
          origBC = bc_ldc2_w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3867
          break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3868
        case bc_new:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3869
          newClass = ref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3870
          break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3871
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3872
        wp[-1] = origBC;  // overwrite with origBC
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3873
        if (origBC == bc_ldc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3874
          putu1ref(ref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3875
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3876
          putref(ref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3877
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3878
        if (origBC == bc_multianewarray) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3879
          // Copy the trailing byte also.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3880
          int val = bc_byte.getByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3881
          putu1_fast(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3882
        } else if (origBC == bc_invokeinterface) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3883
          int argSize = ref->memberDescr()->descrType()->typeSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3884
          putu1_fast(1 + argSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3885
          putu1_fast(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3886
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3887
        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3888
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3889
      if (is_local_slot_op(bc)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3890
        int local = bc_local.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3891
        if (isWide) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3892
          putu2(local);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3893
          if (bc == bc_iinc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3894
            int iVal = bc_short.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3895
            putu2(iVal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3896
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3897
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3898
          putu1_fast(local);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3899
          if (bc == bc_iinc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3900
            int iVal = bc_byte.getByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3901
            putu1_fast(iVal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3902
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3903
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3904
        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3905
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3906
      // Random bytecode.  Just copy it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3907
      assert(bc < bc_bytecode_limit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3908
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3909
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3910
 doneScanningMethod:{}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3911
  //bcimap.add(curPC);  // PC limit is already also in map, from bc_end_marker
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3912
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3913
  // 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
  3914
  for (int i = 0; i < (int)code_fixup_type.size(); i++) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3915
    int   type   = code_fixup_type.getByte(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3916
    byte* bp     = wp_at(code_fixup_offset.get(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3917
    int   curIP  = code_fixup_source.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3918
    int   destIP = curIP + bc_label.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3919
    int   span   = to_bci(destIP) - to_bci(curIP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3920
    switch (type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3921
    case 2: putu2_at(bp, (ushort)span); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3922
    case 4: putu4_at(bp,         span); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3923
    default: assert(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3924
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3925
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3926
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3927
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3928
inline  // called exactly once => inline
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3929
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
  3930
  int j;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3931
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3932
  int max_stack, max_locals, handler_count, cflags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3933
  get_code_header(max_stack, max_locals, handler_count, cflags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3934
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3935
  if (max_stack < 0)      max_stack = code_max_stack.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3936
  if (max_locals < 0)     max_locals = code_max_na_locals.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3937
  if (handler_count < 0)  handler_count = code_handler_count.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3938
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3939
  int siglen = cur_descr->descrType()->typeSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3940
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3941
  if ((cur_descr_flags & ACC_STATIC) == 0)  siglen++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3942
  max_locals += siglen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3943
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3944
  putu2(max_stack);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3945
  putu2(max_locals);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3946
  size_t bcbase = put_empty(4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3947
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3948
  // Write the bytecodes themselves.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3949
  write_bc_ops();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3950
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3951
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3952
  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
  3953
  putu4_at(bcbasewp, (int)(wp - (bcbasewp+4)));  // size of code attr
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3954
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3955
  putu2(handler_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3956
  for (j = 0; j < handler_count; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3957
    int bii = code_handler_start_P.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3958
    putu2(to_bci(bii));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3959
    bii    += code_handler_end_PO.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3960
    putu2(to_bci(bii));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3961
    bii    += code_handler_catch_PO.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3962
    putu2(to_bci(bii));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3963
    putref(code_handler_class_RCN.getRefN());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3964
    CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3965
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3966
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3967
  julong indexBits = cflags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3968
  if (cflags < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3969
    bool haveLongFlags = attr_defs[ATTR_CONTEXT_CODE].haveLongFlags();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3970
    indexBits = code_flags_hi.getLong(code_flags_lo, haveLongFlags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3971
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3972
  write_attrs(ATTR_CONTEXT_CODE, indexBits);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3973
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3974
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3975
int unpacker::write_attrs(int attrc, julong indexBits) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3976
  CHECK_0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3977
  if (indexBits == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3978
    // Quick short-circuit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3979
    putu2(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3980
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3981
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3982
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3983
  attr_definitions& ad = attr_defs[attrc];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3984
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3985
  int i, j, j2, idx, count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3986
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3987
  int oiCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3988
  if (ad.isPredefined(X_ATTR_OVERFLOW)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3989
      && (indexBits & ((julong)1<<X_ATTR_OVERFLOW)) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3990
    indexBits -= ((julong)1<<X_ATTR_OVERFLOW);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3991
    oiCount = ad.xxx_attr_count().getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3992
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3993
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3994
  int bitIndexes[X_ATTR_LIMIT_FLAGS_HI];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3995
  int biCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3996
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3997
  // Fill bitIndexes with index bits, in order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3998
  for (idx = 0; indexBits != 0; idx++, indexBits >>= 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3999
    if ((indexBits & 1) != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4000
      bitIndexes[biCount++] = idx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4001
  }
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  4002
  assert(biCount <= (int)lengthof(bitIndexes));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4003
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4004
  // 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
  4005
  int naOffset = (int)wpoffset();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4006
  int na0 = biCount + oiCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4007
  putu2(na0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4008
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4009
  int na = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4010
  for (i = 0; i < na0; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4011
    if (i < biCount)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4012
      idx = bitIndexes[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4013
    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4014
      idx = ad.xxx_attr_indexes().getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4015
    assert(ad.isIndex(idx));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4016
    entry* aname = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4017
    entry* ref;  // scratch
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4018
    size_t abase = put_empty(2+4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4019
    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
  4020
    if (idx < (int)ad.flag_limit && ad.isPredefined(idx)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4021
      // Switch on the attrc and idx simultaneously.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4022
      switch (ADH_BYTE(attrc, idx)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4023
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4024
      case ADH_BYTE(ATTR_CONTEXT_CLASS,  X_ATTR_OVERFLOW):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4025
      case ADH_BYTE(ATTR_CONTEXT_FIELD,  X_ATTR_OVERFLOW):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4026
      case ADH_BYTE(ATTR_CONTEXT_METHOD, X_ATTR_OVERFLOW):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4027
      case ADH_BYTE(ATTR_CONTEXT_CODE,   X_ATTR_OVERFLOW):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4028
        // no attribute at all, so back up on this one
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4029
        wp = wp_at(abase);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4030
        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4031
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4032
      case ADH_BYTE(ATTR_CONTEXT_CLASS, CLASS_ATTR_ClassFile_version):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4033
        cur_class_minver = class_ClassFile_version_minor_H.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4034
        cur_class_majver = class_ClassFile_version_major_H.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4035
        // back up; not a real attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4036
        wp = wp_at(abase);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4037
        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4038
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4039
      case ADH_BYTE(ATTR_CONTEXT_CLASS, CLASS_ATTR_InnerClasses):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4040
        // note the existence of this attr, but save for later
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4041
        if (cur_class_has_local_ics)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4042
          abort("too many InnerClasses attrs");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4043
        cur_class_has_local_ics = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4044
        wp = wp_at(abase);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4045
        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4046
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4047
      case ADH_BYTE(ATTR_CONTEXT_CLASS, CLASS_ATTR_SourceFile):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4048
        aname = cp.sym[cpool::s_SourceFile];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4049
        ref = class_SourceFile_RUN.getRefN();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4050
        CHECK_0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4051
        if (ref == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4052
          bytes& n = cur_class->ref(0)->value.b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4053
          // 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
  4054
          int pkglen = lastIndexOf(SLASH_MIN,  SLASH_MAX,  n, (int)n.len)+1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4055
          bytes prefix = n.slice(pkglen, n.len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4056
          for (;;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4057
            // 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
  4058
            int dollar = lastIndexOf(DOLLAR_MIN, DOLLAR_MAX, prefix, (int)prefix.len);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4059
            if (dollar < 0)  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4060
            prefix = prefix.slice(0, dollar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4061
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4062
          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
  4063
          int len = (int)(prefix.len + strlen(suffix));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4064
          bytes name; name.set(T_NEW(byte, len + 1), len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4065
          name.strcat(prefix).strcat(suffix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4066
          ref = cp.ensureUtf8(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4067
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4068
        putref(ref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4069
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4070
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4071
      case ADH_BYTE(ATTR_CONTEXT_CLASS, CLASS_ATTR_EnclosingMethod):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4072
        aname = cp.sym[cpool::s_EnclosingMethod];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4073
        putref(class_EnclosingMethod_RC.getRefN());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4074
        putref(class_EnclosingMethod_RDN.getRefN());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4075
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4076
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4077
      case ADH_BYTE(ATTR_CONTEXT_FIELD, FIELD_ATTR_ConstantValue):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4078
        aname = cp.sym[cpool::s_ConstantValue];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4079
        putref(field_ConstantValue_KQ.getRefUsing(cp.getKQIndex()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4080
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4081
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4082
      case ADH_BYTE(ATTR_CONTEXT_METHOD, METHOD_ATTR_Code):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4083
        aname = cp.sym[cpool::s_Code];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4084
        write_code();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4085
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4086
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4087
      case ADH_BYTE(ATTR_CONTEXT_METHOD, METHOD_ATTR_Exceptions):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4088
        aname = cp.sym[cpool::s_Exceptions];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4089
        putu2(count = method_Exceptions_N.getInt());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4090
        for (j = 0; j < count; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4091
          putref(method_Exceptions_RC.getRefN());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4092
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4093
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4094
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4095
      case ADH_BYTE(ATTR_CONTEXT_CODE, CODE_ATTR_StackMapTable):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4096
        aname = cp.sym[cpool::s_StackMapTable];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4097
        // (keep this code aligned with its brother in unpacker::read_attrs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4098
        putu2(count = code_StackMapTable_N.getInt());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4099
        for (j = 0; j < count; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4100
          int tag = code_StackMapTable_frame_T.getByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4101
          putu1(tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4102
          if (tag <= 127) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4103
            // (64-127)  [(2)]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4104
            if (tag >= 64)  put_stackmap_type();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4105
          } else if (tag <= 251) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4106
            // (247)     [(1)(2)]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4107
            // (248-251) [(1)]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4108
            if (tag >= 247)  putu2(code_StackMapTable_offset.getInt());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4109
            if (tag == 247)  put_stackmap_type();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4110
          } else if (tag <= 254) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4111
            // (252)     [(1)(2)]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4112
            // (253)     [(1)(2)(2)]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4113
            // (254)     [(1)(2)(2)(2)]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4114
            putu2(code_StackMapTable_offset.getInt());
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  4115
            for (int k = (tag - 251); k > 0; k--) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4116
              put_stackmap_type();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4117
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4118
          } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4119
            // (255)     [(1)NH[(2)]NH[(2)]]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4120
            putu2(code_StackMapTable_offset.getInt());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4121
            putu2(j2 = code_StackMapTable_local_N.getInt());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4122
            while (j2-- > 0)  put_stackmap_type();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4123
            putu2(j2 = code_StackMapTable_stack_N.getInt());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4124
            while (j2-- > 0)  put_stackmap_type();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4125
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4126
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4127
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4128
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4129
      case ADH_BYTE(ATTR_CONTEXT_CODE, CODE_ATTR_LineNumberTable):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4130
        aname = cp.sym[cpool::s_LineNumberTable];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4131
        putu2(count = code_LineNumberTable_N.getInt());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4132
        for (j = 0; j < count; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4133
          putu2(to_bci(code_LineNumberTable_bci_P.getInt()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4134
          putu2(code_LineNumberTable_line.getInt());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4135
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4136
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4137
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4138
      case ADH_BYTE(ATTR_CONTEXT_CODE, CODE_ATTR_LocalVariableTable):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4139
        aname = cp.sym[cpool::s_LocalVariableTable];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4140
        putu2(count = code_LocalVariableTable_N.getInt());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4141
        for (j = 0; j < count; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4142
          int bii = code_LocalVariableTable_bci_P.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4143
          int bci = to_bci(bii);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4144
          putu2(bci);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4145
          bii    += code_LocalVariableTable_span_O.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4146
          putu2(to_bci(bii) - bci);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4147
          putref(code_LocalVariableTable_name_RU.getRefN());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4148
          putref(code_LocalVariableTable_type_RS.getRefN());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4149
          putu2(code_LocalVariableTable_slot.getInt());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4150
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4151
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4152
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4153
      case ADH_BYTE(ATTR_CONTEXT_CODE, CODE_ATTR_LocalVariableTypeTable):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4154
        aname = cp.sym[cpool::s_LocalVariableTypeTable];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4155
        putu2(count = code_LocalVariableTypeTable_N.getInt());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4156
        for (j = 0; j < count; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4157
          int bii = code_LocalVariableTypeTable_bci_P.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4158
          int bci = to_bci(bii);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4159
          putu2(bci);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4160
          bii    += code_LocalVariableTypeTable_span_O.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4161
          putu2(to_bci(bii) - bci);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4162
          putref(code_LocalVariableTypeTable_name_RU.getRefN());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4163
          putref(code_LocalVariableTypeTable_type_RS.getRefN());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4164
          putu2(code_LocalVariableTypeTable_slot.getInt());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4165
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4166
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4167
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4168
      case ADH_BYTE(ATTR_CONTEXT_CLASS, X_ATTR_Signature):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4169
        aname = cp.sym[cpool::s_Signature];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4170
        putref(class_Signature_RS.getRefN());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4171
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4172
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4173
      case ADH_BYTE(ATTR_CONTEXT_FIELD, X_ATTR_Signature):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4174
        aname = cp.sym[cpool::s_Signature];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4175
        putref(field_Signature_RS.getRefN());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4176
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4177
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4178
      case ADH_BYTE(ATTR_CONTEXT_METHOD, X_ATTR_Signature):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4179
        aname = cp.sym[cpool::s_Signature];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4180
        putref(method_Signature_RS.getRefN());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4181
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4182
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4183
      case ADH_BYTE(ATTR_CONTEXT_CLASS,  X_ATTR_Deprecated):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4184
      case ADH_BYTE(ATTR_CONTEXT_FIELD,  X_ATTR_Deprecated):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4185
      case ADH_BYTE(ATTR_CONTEXT_METHOD, X_ATTR_Deprecated):
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4186
        aname = cp.sym[cpool::s_Deprecated];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4187
        // no data
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4188
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4189
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4191
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4192
    if (aname == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4193
      // Unparse a compressor-defined attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4194
      layout_definition* lo = ad.getLayout(idx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4195
      if (lo == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4196
        abort("bad layout index");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4197
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4198
      }
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  4199
      assert((int)lo->idx == idx);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4200
      aname = lo->nameEntry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4201
      if (aname == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4202
        bytes nameb; nameb.set(lo->name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4203
        aname = cp.ensureUtf8(nameb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4204
        // Cache the name entry for next time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4205
        lo->nameEntry = aname;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4206
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4207
      // Execute all the layout elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4208
      band** bands = lo->bands();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4209
      if (lo->hasCallables()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4210
        band& cble = *bands[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4211
        assert(cble.le_kind == EK_CBLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4212
        bands = cble.le_body;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4213
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4214
      putlayout(bands);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4216
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4217
    if (aname == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4218
      abort("bad attribute index");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4219
    CHECK_0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4220
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4221
    byte* wp1 = wp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4222
    wp = wp_at(abase);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4223
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4224
    // DTRT if this attr is on the strip-list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4225
    // (Note that we emptied the data out of the band first.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4226
    if (ad.strip_names.contains(aname)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4227
      continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4229
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4230
    // patch the name and length
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4231
    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
  4232
    putu4((int)(wp1 - (wp+4)));  // put the attr size
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4233
    wp = wp1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4234
    na++;  // count the attrs actually written
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4235
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4236
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4237
  if (na != na0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4238
    // Refresh changed count.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4239
    putu2_at(wp_at(naOffset), na);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4240
  return na;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4241
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4242
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4243
void unpacker::write_members(int num, int attrc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4244
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4245
  attr_definitions& ad = attr_defs[attrc];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4246
  band& member_flags_hi = ad.xxx_flags_hi();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4247
  band& member_flags_lo = ad.xxx_flags_lo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4248
  band& member_descr = (&member_flags_hi)[e_field_descr-e_field_flags_hi];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4249
  assert(endsWith(member_descr.name, "_descr"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4250
  assert(endsWith(member_flags_lo.name, "_flags_lo"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4251
  assert(endsWith(member_flags_lo.name, "_flags_lo"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4252
  bool haveLongFlags = ad.haveLongFlags();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4253
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4254
  putu2(num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4255
  julong indexMask = attr_defs[attrc].flagIndexMask();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4256
  for (int i = 0; i < num; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4257
    julong mflags = member_flags_hi.getLong(member_flags_lo, haveLongFlags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4258
    entry* mdescr = member_descr.getRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4259
    cur_descr = mdescr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4260
    putu2(cur_descr_flags = (ushort)(mflags & ~indexMask));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4261
    CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4262
    putref(mdescr->descrName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4263
    putref(mdescr->descrType());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4264
    write_attrs(attrc, (mflags & indexMask));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4265
    CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4266
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4267
  cur_descr = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4268
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4269
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4270
extern "C"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4271
int raw_address_cmp(const void* p1p, const void* p2p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4272
  void* p1 = *(void**) p1p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4273
  void* p2 = *(void**) p2p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4274
  return (p1 > p2)? 1: (p1 < p2)? -1: 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4275
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4276
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4277
void unpacker::write_classfile_tail() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4278
  cur_classfile_tail.empty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4279
  set_output(&cur_classfile_tail);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4280
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4281
  int i, num;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4282
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4283
  attr_definitions& ad = attr_defs[ATTR_CONTEXT_CLASS];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4284
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4285
  bool haveLongFlags = ad.haveLongFlags();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4286
  julong kflags = class_flags_hi.getLong(class_flags_lo, haveLongFlags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4287
  julong indexMask = ad.flagIndexMask();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4288
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4289
  cur_class = class_this.getRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4290
  cur_super = class_super.getRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4291
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4292
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4293
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4294
  if (cur_super == cur_class)  cur_super = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4295
  // special representation for java/lang/Object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4296
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4297
  putu2((ushort)(kflags & ~indexMask));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4298
  putref(cur_class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4299
  putref(cur_super);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4300
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4301
  putu2(num = class_interface_count.getInt());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4302
  for (i = 0; i < num; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4303
    putref(class_interface.getRef());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4304
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4305
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4306
  write_members(class_field_count.getInt(),  ATTR_CONTEXT_FIELD);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4307
  write_members(class_method_count.getInt(), ATTR_CONTEXT_METHOD);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4308
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4309
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4310
  cur_class_has_local_ics = false;  // may be set true by write_attrs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4311
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4312
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
  4313
  int naOffset = (int)wpoffset();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4314
  int na = write_attrs(ATTR_CONTEXT_CLASS, (kflags & indexMask));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4315
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4316
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4317
  // at the very last, choose which inner classes (if any) pertain to k:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4318
#ifdef ASSERT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4319
  for (i = 0; i < ic_count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4320
    assert(!ics[i].requested);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4321
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4322
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4323
  // First, consult the global table and the local constant pool,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4324
  // and decide on the globally implied inner classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4325
  // (Note that we read the cpool's outputIndex fields, but we
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4326
  // do not yet write them, since the local IC attribute might
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4327
  // reverse a global decision to declare an IC.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4328
  assert(requested_ics.length() == 0);  // must start out empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4329
  // Always include all members of the current class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4330
  for (inner_class* child = cp.getFirstChildIC(cur_class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4331
       child != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4332
       child = cp.getNextChildIC(child)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4333
    child->requested = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4334
    requested_ics.add(child);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4335
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4336
  // And, for each inner class mentioned in the constant pool,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4337
  // include it and all its outers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4338
  int    noes =           cp.outputEntries.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4339
  entry** oes = (entry**) cp.outputEntries.base();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4340
  for (i = 0; i < noes; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4341
    entry& e = *oes[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4342
    if (e.tag != CONSTANT_Class)  continue;  // wrong sort
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4343
    for (inner_class* ic = cp.getIC(&e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4344
         ic != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4345
         ic = cp.getIC(ic->outer)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4346
      if (ic->requested)  break;  // already processed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4347
      ic->requested = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4348
      requested_ics.add(ic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4349
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4350
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4351
  int local_ics = requested_ics.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4352
  // Second, consult a local attribute (if any) and adjust the global set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4353
  inner_class* extra_ics = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4354
  int      num_extra_ics = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4355
  if (cur_class_has_local_ics) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4356
    // adjust the set of ICs by symmetric set difference w/ the locals
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4357
    num_extra_ics = class_InnerClasses_N.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4358
    if (num_extra_ics == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4359
      // Explicit zero count has an irregular meaning:  It deletes the attr.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4360
      local_ics = 0;  // (short-circuit all tests of requested bits)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4361
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4362
      extra_ics = T_NEW(inner_class, num_extra_ics);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4363
      // Note:  extra_ics will be freed up by next call to get_next_file().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4364
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4365
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4366
  for (i = 0; i < num_extra_ics; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4367
    inner_class& extra_ic = extra_ics[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4368
    extra_ic.inner = class_InnerClasses_RC.getRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4369
    CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4370
    // Find the corresponding equivalent global IC:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4371
    inner_class* global_ic = cp.getIC(extra_ic.inner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4372
    int flags = class_InnerClasses_F.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4373
    if (flags == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4374
      // The extra IC is simply a copy of a global IC.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4375
      if (global_ic == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4376
        abort("bad reference to inner class");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4377
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4378
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4379
      extra_ic = (*global_ic);  // fill in rest of fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4380
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4381
      flags &= ~ACC_IC_LONG_FORM;  // clear high bit if set to get clean zero
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4382
      extra_ic.flags = flags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4383
      extra_ic.outer = class_InnerClasses_outer_RCN.getRefN();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4384
      extra_ic.name  = class_InnerClasses_name_RUN.getRefN();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4385
      // Detect if this is an exact copy of the global tuple.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4386
      if (global_ic != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4387
        if (global_ic->flags != extra_ic.flags ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4388
            global_ic->outer != extra_ic.outer ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4389
            global_ic->name  != extra_ic.name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4390
          global_ic = null;  // not really the same, so break the link
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4391
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4392
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4393
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4394
    if (global_ic != null && global_ic->requested) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4395
      // This local repetition reverses the globally implied request.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4396
      global_ic->requested = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4397
      extra_ic.requested = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4398
      local_ics -= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4399
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4400
      // The global either does not exist, or is not yet requested.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4401
      extra_ic.requested = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4402
      local_ics += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4403
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4404
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4405
  // Finally, if there are any that survived, put them into an attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4406
  // (Note that a zero-count attribute is always deleted.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4407
  // The putref calls below will tell the constant pool to add any
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4408
  // necessary local CP references to support the InnerClasses attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4409
  // This step must be the last round of additions to the local CP.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4410
  if (local_ics > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4411
    // append the new attribute:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4412
    putref(cp.sym[cpool::s_InnerClasses]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4413
    putu4(2 + 2*4*local_ics);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4414
    putu2(local_ics);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4415
    PTRLIST_QSORT(requested_ics, raw_address_cmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4416
    int num_global_ics = requested_ics.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4417
    for (i = -num_global_ics; i < num_extra_ics; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4418
      inner_class* ic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4419
      if (i < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4420
        ic = (inner_class*) requested_ics.get(num_global_ics+i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4421
      else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4422
        ic = &extra_ics[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4423
      if (ic->requested) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4424
        putref(ic->inner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4425
        putref(ic->outer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4426
        putref(ic->name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4427
        putu2(ic->flags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4428
        NOT_PRODUCT(local_ics--);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4429
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4430
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4431
    assert(local_ics == 0);           // must balance
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4432
    putu2_at(wp_at(naOffset), ++na);  // increment class attr count
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4433
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4434
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4435
  // Tidy up global 'requested' bits:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4436
  for (i = requested_ics.length(); --i >= 0; ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4437
    inner_class* ic = (inner_class*) requested_ics.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4438
    ic->requested = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4439
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4440
  requested_ics.empty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4441
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4442
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4443
  close_output();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4444
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4445
  // rewrite CP references in the tail
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4446
  cp.computeOutputIndexes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4447
  int nextref = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4448
  for (i = 0; i < (int)class_fixup_type.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4449
    int    type = class_fixup_type.getByte(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4450
    byte*  fixp = wp_at(class_fixup_offset.get(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4451
    entry* e    = (entry*)class_fixup_ref.get(nextref++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4452
    int    idx  = e->getOutputIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4453
    switch (type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4454
    case 1:  putu1_at(fixp, idx);  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4455
    case 2:  putu2_at(fixp, idx);  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4456
    default: assert(false);  // should not reach here
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4457
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4458
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4459
  CHECK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4460
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4461
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4462
void unpacker::write_classfile_head() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4463
  cur_classfile_head.empty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4464
  set_output(&cur_classfile_head);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4465
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4466
  putu4(JAVA_MAGIC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4467
  putu2(cur_class_minver);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4468
  putu2(cur_class_majver);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4469
  putu2(cp.outputIndexLimit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4470
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4471
  int checkIndex = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4472
  int    noes =           cp.outputEntries.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4473
  entry** oes = (entry**) cp.outputEntries.base();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4474
  for (int i = 0; i < noes; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4475
    entry& e = *oes[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4476
    assert(e.getOutputIndex() == checkIndex++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4477
    byte tag = e.tag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4478
    assert(tag != CONSTANT_Signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4479
    putu1(tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4480
    switch (tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4481
    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
  4482
      putu2((int)e.value.b.len);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4483
      put_bytes(e.value.b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4484
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4485
    case CONSTANT_Integer:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4486
    case CONSTANT_Float:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4487
      putu4(e.value.i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4488
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4489
    case CONSTANT_Long:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4490
    case CONSTANT_Double:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4491
      putu8(e.value.l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4492
      assert(checkIndex++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4493
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4494
    case CONSTANT_Class:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4495
    case CONSTANT_String:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4496
      // just write the ref
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4497
      putu2(e.refs[0]->getOutputIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4498
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4499
    case CONSTANT_Fieldref:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4500
    case CONSTANT_Methodref:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4501
    case CONSTANT_InterfaceMethodref:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4502
    case CONSTANT_NameandType:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4503
      putu2(e.refs[0]->getOutputIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4504
      putu2(e.refs[1]->getOutputIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4505
      break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4506
    default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4507
      abort(ERROR_INTERNAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4508
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4509
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4510
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4511
#ifndef PRODUCT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4512
  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
  4513
  total_cp_size[1] += (int)cur_classfile_head.size();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4514
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4515
  close_output();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4516
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4517
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4518
unpacker::file* unpacker::get_next_file() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4519
  CHECK_0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4520
  free_temps();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4521
  if (files_remaining == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4522
    // Leave a clue that we're exhausted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4523
    cur_file.name = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4524
    cur_file.size = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4525
    if (archive_size != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4526
      julong predicted_size = unsized_bytes_read + archive_size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4527
      if (predicted_size != bytes_read)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4528
        abort("archive header had incorrect size");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4529
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4530
    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4531
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4532
  files_remaining -= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4533
  assert(files_written < file_count || classes_written < class_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4534
  cur_file.name = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4535
  cur_file.size = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4536
  cur_file.modtime = default_file_modtime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4537
  cur_file.options = default_file_options;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4538
  cur_file.data[0].set(null, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4539
  cur_file.data[1].set(null, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4540
  if (files_written < file_count) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4541
    entry* e = file_name.getRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4542
    CHECK_0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4543
    cur_file.name = e->utf8String();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4544
    bool haveLongSize = ((archive_options & AO_HAVE_FILE_SIZE_HI) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4545
    cur_file.size = file_size_hi.getLong(file_size_lo, haveLongSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4546
    if ((archive_options & AO_HAVE_FILE_MODTIME) != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4547
      cur_file.modtime += file_modtime.getInt();  //relative to archive modtime
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4548
    if ((archive_options & AO_HAVE_FILE_OPTIONS) != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4549
      cur_file.options |= file_options.getInt() & ~suppress_file_options;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4550
  } else if (classes_written < class_count) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4551
    // there is a class for a missing file record
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4552
    cur_file.options |= FO_IS_CLASS_STUB;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4553
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4554
  if ((cur_file.options & FO_IS_CLASS_STUB) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4555
    assert(classes_written < class_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4556
    classes_written += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4557
    if (cur_file.size != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4558
      abort("class file size transmitted");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4559
      return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4560
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4561
    reset_cur_classfile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4562
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4563
    // write the meat of the classfile:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4564
    write_classfile_tail();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4565
    cur_file.data[1] = cur_classfile_tail.b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4566
    CHECK_0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4567
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4568
    // write the CP of the classfile, second:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4569
    write_classfile_head();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4570
    cur_file.data[0] = cur_classfile_head.b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4571
    CHECK_0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4572
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4573
    cur_file.size += cur_file.data[0].len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4574
    cur_file.size += cur_file.data[1].len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4575
    if (cur_file.name[0] == '\0') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4576
      bytes& prefix = cur_class->ref(0)->value.b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4577
      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
  4578
      int len = (int)(prefix.len + strlen(suffix));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4579
      bytes name; name.set(T_NEW(byte, len + 1), len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4580
      cur_file.name = name.strcat(prefix).strcat(suffix).strval();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4581
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4582
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4583
    // If there is buffered file data, produce a pointer to it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4584
    if (cur_file.size != (size_t) cur_file.size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4585
      // Silly size specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4586
      abort("resource file too large");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4587
      return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4588
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4589
    size_t rpleft = input_remaining();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4590
    if (rpleft > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4591
      if (rpleft > cur_file.size)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4592
        rpleft = (size_t) cur_file.size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4593
      cur_file.data[0].set(rp, rpleft);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4594
      rp += rpleft;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4595
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4596
    if (rpleft < cur_file.size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4597
      // 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
  4598
      size_t fleft = (size_t)cur_file.size - rpleft;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4599
      bytes_read += fleft;  // Credit it to the overall archive size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4600
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4601
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4602
  CHECK_0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4603
  bytes_written += cur_file.size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4604
  files_written += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4605
  return &cur_file;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4606
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4607
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4608
// Write a file to jarout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4609
void unpacker::write_file_to_jar(unpacker::file* f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4610
  size_t htsize = f->data[0].len + f->data[1].len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4611
  julong fsize = f->size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4612
#ifndef PRODUCT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4613
  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
  4614
    PRINTCR((2,"would write %d bytes to %s", (int) fsize, f->name));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4615
    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4616
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4617
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4618
  if (htsize == fsize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4619
    jarout->addJarEntry(f->name, f->deflate_hint(), f->modtime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4620
                        f->data[0], f->data[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4621
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4622
    assert(input_remaining() == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4623
    bytes part1, part2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4624
    part1.len = f->data[0].len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4625
    part1.set(T_NEW(byte, part1.len), part1.len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4626
    part1.copyFrom(f->data[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4627
    assert(f->data[1].len == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4628
    part2.set(null, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4629
    size_t fleft = (size_t) fsize - part1.len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4630
    assert(bytes_read > fleft);  // part2 already credited by get_next_file
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4631
    bytes_read -= fleft;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4632
    if (fleft > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4633
      // Must read some more.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4634
      if (live_input) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4635
        // Stop using the input buffer.  Make a new one:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4636
        if (free_input)  input.free();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4637
        input.init(fleft > (1<<12) ? fleft : (1<<12));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4638
        free_input = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4639
        live_input = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4640
      } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4641
        // Make it large enough.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4642
        assert(free_input);  // must be reallocable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4643
        input.ensureSize(fleft);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4644
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4645
      rplimit = rp = input.base();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4646
      input.setLimit(rp + fleft);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4647
      if (!ensure_input(fleft))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4648
        abort("EOF reading resource file");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4649
      part2.ptr = input_scan();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4650
      part2.len = input_remaining();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4651
      rplimit = rp = input.base();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4652
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4653
    jarout->addJarEntry(f->name, f->deflate_hint(), f->modtime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4654
                        part1, part2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4655
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4656
  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
  4657
    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
  4658
                     LONG_LONG_FORMAT " bytes to: %s\n", fsize, f->name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4659
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4660
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4661
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4662
// Redirect the stdio to the specified file in the unpack.log.file option
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4663
void unpacker::redirect_stdio() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4664
  if (log_file == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4665
    log_file = LOGFILE_STDOUT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4666
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4667
  if (log_file == errstrm_name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4668
    // Nothing more to be done.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4669
    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4670
  errstrm_name = log_file;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4671
  if (strcmp(log_file, LOGFILE_STDERR) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4672
    errstrm = stderr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4673
    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4674
  } else if (strcmp(log_file, LOGFILE_STDOUT) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4675
    errstrm = stdout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4676
    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4677
  } else if (log_file[0] != '\0' && (errstrm = fopen(log_file,"a+")) != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4678
    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4679
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4680
    char log_file_name[PATH_MAX+100];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4681
    char tmpdir[PATH_MAX];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4682
#ifdef WIN32
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4683
    int n = GetTempPath(PATH_MAX,tmpdir); //API returns with trailing '\'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4684
    if (n < 1 || n > PATH_MAX) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4685
      sprintf(tmpdir,"C:\\");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4686
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4687
    sprintf(log_file_name, "%sunpack.log", tmpdir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4688
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4689
    sprintf(tmpdir,"/tmp");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4690
    sprintf(log_file_name, "/tmp/unpack.log");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4691
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4692
    if ((errstrm = fopen(log_file_name, "a+")) != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4693
      log_file = errstrm_name = saveStr(log_file_name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4694
      return ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4695
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4696
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4697
    char *tname = tempnam(tmpdir,"#upkg");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4698
    sprintf(log_file_name, "%s", tname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4699
    if ((errstrm = fopen(log_file_name, "a+")) != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4700
      log_file = errstrm_name = saveStr(log_file_name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4701
      return ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4702
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4703
#ifndef WIN32
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4704
    sprintf(log_file_name, "/dev/null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4705
    // On windows most likely it will fail.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4706
    if ( (errstrm = fopen(log_file_name, "a+")) != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4707
      log_file = errstrm_name = saveStr(log_file_name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4708
      return ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4709
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4710
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4711
    // Last resort
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4712
    // (Do not use stdout, since it might be jarout->jarfp.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4713
    errstrm = stderr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4714
    log_file = errstrm_name = LOGFILE_STDERR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4715
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4716
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4717
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4718
#ifndef PRODUCT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4719
int unpacker::printcr_if_verbose(int level, const char* fmt ...) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4720
  if (verbose < level+10)  return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4721
  va_list vl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4722
  va_start(vl, fmt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4723
  char fmtbuf[300];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4724
  strcpy(fmtbuf+100, fmt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4725
  strcat(fmtbuf+100, "\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4726
  char* fmt2 = fmtbuf+100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4727
  while (level-- > 0)  *--fmt2 = ' ';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4728
  vfprintf(errstrm, fmt2, vl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4729
  return 1;  // for ?: usage
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4730
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4731
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4732
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4733
void unpacker::abort(const char* message) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4734
  if (message == null)  message = "error unpacking archive";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4735
#ifdef UNPACK_JNI
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4736
  if (message[0] == '@') {  // secret convention for sprintf
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4737
     bytes saved;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4738
     saved.saveFrom(message+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4739
     mallocs.add(message = saved.strval());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4740
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4741
  abort_message = message;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4742
  return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4743
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4744
  if (message[0] == '@')  ++message;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4745
  fprintf(errstrm, "%s\n", message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4746
#ifndef PRODUCT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4747
  fflush(errstrm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4748
  ::abort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4749
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4750
  exit(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4751
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4752
#endif // JNI
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4753
}