jdk/src/jdk.pack200/share/native/common-unpack/unpack.h
author ksrini
Thu, 07 Apr 2016 12:54:23 -0700
changeset 36960 d7731fdfe7c3
parent 29591 51244d1ddffc
permissions -rw-r--r--
8150469: unpack200 fails to compare crc correctly. Reviewed-by: jrose
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
36960
d7731fdfe7c3 8150469: unpack200 fails to compare crc correctly.
ksrini
parents: 29591
diff changeset
     2
 * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2624
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2624
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2624
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2624
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2624
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
// Global Structures
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
struct jar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
struct gunzip;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
struct band;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
struct cpool;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
struct entry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
struct cpindex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
struct inner_class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
struct value_stream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
struct cpindex {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
  uint    len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
  entry*  base1;   // base of primary index
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
  entry** base2;   // base of secondary index
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
  byte    ixTag;   // type of entries (!= CONSTANT_None), plus 64 if sub-index
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
  enum { SUB_TAG = 64 };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
  entry* get(uint i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
  void init(int len_, entry* base1_, int ixTag_) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    len = len_;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    base1 = base1_;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    base2 = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    ixTag = ixTag_;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
  void init(int len_, entry** base2_, int ixTag_) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    len = len_;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    base1 = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    base2 = base2_;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    ixTag = ixTag_;
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
struct cpool {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
  uint  nentries;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
  entry* entries;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
  entry* first_extra_entry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
  uint maxentries;      // total allocated size of entries
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
  // Position and size of each homogeneous subrange:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
  int     tag_count[CONSTANT_Limit];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
  int     tag_base[CONSTANT_Limit];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
  cpindex tag_index[CONSTANT_Limit];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
  ptrlist tag_extras[CONSTANT_Limit];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 5506
diff changeset
    70
  int     tag_group_count[CONSTANT_GroupLimit - CONSTANT_GroupFirst];
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 5506
diff changeset
    71
  cpindex tag_group_index[CONSTANT_GroupLimit - CONSTANT_GroupFirst];
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 5506
diff changeset
    72
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
  cpindex* member_indexes;   // indexed by 2*CONSTANT_Class.inord
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
  cpindex* getFieldIndex(entry* classRef);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
  cpindex* getMethodIndex(entry* classRef);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
  inner_class** ic_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
  inner_class** ic_child_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
  inner_class* getIC(entry* inner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
  inner_class* getFirstChildIC(entry* outer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
  inner_class* getNextChildIC(inner_class* child);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
  int outputIndexLimit;  // index limit after renumbering
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
  ptrlist outputEntries; // list of entry* needing output idx assigned
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 5506
diff changeset
    85
  ptrlist requested_bsms; // which bsms need output?
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
  entry** hashTab;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
  uint    hashTabLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
  entry*& hashTabRef(byte tag, bytes& b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
  entry*  ensureUtf8(bytes& b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
  entry*  ensureClass(bytes& b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
  // Well-known Utf8 symbols.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
  enum {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    #define SNAME(n,s) s_##s,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    ALL_ATTR_DO(SNAME)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    #undef SNAME
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    s_lt_init_gt,  // <init>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    s_LIMIT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
  };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
  entry* sym[s_LIMIT];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
  // read counts from hdr, allocate main arrays
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 5506
diff changeset
   104
  void init(unpacker* u, int counts[CONSTANT_Limit]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
  // pointer to outer unpacker, for error checks etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
  unpacker* u;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
  int getCount(byte tag) {
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 5506
diff changeset
   110
    if ((uint)tag >= CONSTANT_GroupFirst) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 5506
diff changeset
   111
      assert((uint)tag < CONSTANT_GroupLimit);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 5506
diff changeset
   112
      return tag_group_count[(uint)tag - CONSTANT_GroupFirst];
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 5506
diff changeset
   113
    } else {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 5506
diff changeset
   114
      assert((uint)tag < CONSTANT_Limit);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 5506
diff changeset
   115
      return tag_count[(uint)tag];
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 5506
diff changeset
   116
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
  cpindex* getIndex(byte tag) {
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 5506
diff changeset
   119
    if ((uint)tag >= CONSTANT_GroupFirst) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 5506
diff changeset
   120
      assert((uint)tag < CONSTANT_GroupLimit);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 5506
diff changeset
   121
      return &tag_group_index[(uint)tag - CONSTANT_GroupFirst];
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 5506
diff changeset
   122
    } else {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 5506
diff changeset
   123
      assert((uint)tag < CONSTANT_Limit);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 5506
diff changeset
   124
      return &tag_index[(uint)tag];
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 5506
diff changeset
   125
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
  }
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 5506
diff changeset
   127
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
  cpindex* getKQIndex();  // uses cur_descr
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
  void expandSignatures();
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 5506
diff changeset
   131
  void initGroupIndexes();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
  void initMemberIndexes();
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 5506
diff changeset
   133
  int  initLoadableValues(entry** loadable_entries);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
  void computeOutputOrder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
  void computeOutputIndexes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
  void resetOutputIndexes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
  // error handling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
  inline void abort(const char* msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
  inline bool aborting();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 * The unpacker provides the entry points to the unpack engine,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 * as well as maintains the state of the engine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
struct unpacker {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
  // One element of the resulting JAR.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
  struct file {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    const char* name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    julong      size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    int         modtime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    int         options;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    bytes       data[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    // Note:  If Sum(data[*].len) < size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    // remaining bytes must be read directly from the input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    bool deflate_hint() { return ((options & FO_DEFLATE_HINT) != 0); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
  };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
  // back pointer to NativeUnpacker obj and Java environment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
  void* jniobj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
  void* jnienv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
  // global pointer to self, if not running under JNI (not multi-thread safe)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
  static unpacker* non_mt_current;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
  // if running Unix-style, here are the inputs and outputs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
  FILE* infileptr;  // buffered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
  int   infileno;   // unbuffered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
  bytes inbytes;    // direct
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
  gunzip* gzin;     // gunzip filter, if any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
  jar*  jarout;     // output JAR file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
#ifndef PRODUCT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
  int   nowrite;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
  int   skipfiles;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
  int   verbose_bands;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
  // pointer to self, for U_NEW macro
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
  unpacker* u;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
  // private abort message string, allocated to PATH_MAX*2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
  const char* abort_message;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
  ptrlist mallocs;      // list of guys to free when we are all done
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
  ptrlist tmallocs;     // list of guys to free on next client request
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
  fillbytes smallbuf;   // supplies small alloc requests
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
  fillbytes tsmallbuf;  // supplies temporary small alloc requests
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
  // option management members
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
  int   verbose;  // verbose level, 0 means no output
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
  bool  strip_compile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
  bool  strip_debug;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
  bool  strip_jcov;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
  bool  remove_packfile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
  int   deflate_hint_or_zero;  // ==0 means not set, otherwise -1 or 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
  int   modification_time_or_zero;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
  FILE*       errstrm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
  const char* errstrm_name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
  const char* log_file;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
  // input stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
  fillbytes input;       // the whole block (size is predicted, has slop too)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
  bool      live_input;  // is the data in this block live?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
  bool      free_input;  // must the input buffer be freed?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
  byte*     rp;          // read pointer (< rplimit <= input.limit())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
  byte*     rplimit;     // how much of the input block has been read?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
  julong    bytes_read;
29591
51244d1ddffc 8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents: 29368
diff changeset
   212
  size_t    unsized_bytes_read;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
  // callback to read at least one byte, up to available input
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
  typedef jlong (*read_input_fn_t)(unpacker* self, void* buf, jlong minlen, jlong maxlen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
  read_input_fn_t read_input_fn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
  // archive header fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
  int      magic, minver, majver;
2602
5b394a4b6ce1 6755943: Java JAR Pack200 Decompression should enforce stricter header checks
ksrini
parents: 2
diff changeset
   220
  size_t   archive_size;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
  int      archive_next_count, archive_options, archive_modtime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
  int      band_headers_size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
  int      file_count, attr_definition_count, ic_count, class_count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
  int      default_class_minver, default_class_majver;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
  int      default_file_options, suppress_file_options;  // not header fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
  int      default_archive_modtime, default_file_modtime;  // not header fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
  int      code_count;  // not a header field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
  int      files_remaining;  // not a header field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
  // engine state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
  band*        all_bands;   // indexed by band_number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
  byte*        meta_rp;     // read-pointer into (copy of) band_headers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
  cpool        cp;          // all constant pool information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
  inner_class* ics;         // InnerClasses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
  // output stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
  bytes    output;      // output block (either classfile head or tail)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
  byte*    wp;          // write pointer (< wplimit == output.limit())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
  byte*    wpbase;      // write pointer starting address (<= wp)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
  byte*    wplimit;     // how much of the output block has been written?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
  // output state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
  file      cur_file;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
  entry*    cur_class;  // CONSTANT_Class entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
  entry*    cur_super;  // CONSTANT_Class entry or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
  entry*    cur_descr;  // CONSTANT_NameandType entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
  int       cur_descr_flags;  // flags corresponding to cur_descr
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
  int       cur_class_minver, cur_class_majver;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
  bool      cur_class_has_local_ics;
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 5506
diff changeset
   250
  int       cur_class_local_bsm_count;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
  fillbytes cur_classfile_head;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
  fillbytes cur_classfile_tail;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
  int       files_written;   // also tells which file we're working on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
  int       classes_written; // also tells which class we're working on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
  julong    bytes_written;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
  intlist   bcimap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
  fillbytes class_fixup_type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
  intlist   class_fixup_offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
  ptrlist   class_fixup_ref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
  fillbytes code_fixup_type;    // which format of branch operand?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
  intlist   code_fixup_offset;  // location of operand needing fixup
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
  intlist   code_fixup_source;  // encoded ID of branch insn
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
  ptrlist   requested_ics;      // which ics need output?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
  // stats pertaining to multiple segments (updated on reset)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
  julong    bytes_read_before_reset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
  julong    bytes_written_before_reset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
  int       files_written_before_reset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
  int       classes_written_before_reset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
  int       segments_read_before_reset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
  // attribute state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
  struct layout_definition {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    uint          idx;        // index (0..31...) which identifies this layout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    const char*   name;       // name of layout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    entry*        nameEntry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    const char*   layout;     // string of layout (not yet parsed)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    band**        elems;      // array of top-level layout elems (or callables)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    bool hasCallables()   { return layout[0] == '['; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    band** bands()        { assert(elems != null); return elems; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
  };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
  struct attr_definitions {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    unpacker* u;  // pointer to self, for U_NEW macro
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    int     xxx_flags_hi_bn;// locator for flags, count, indexes, calls bands
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    int     attrc;          // ATTR_CONTEXT_CLASS, etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    uint    flag_limit;     // 32 or 63, depending on archive_options bit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    julong  predef;         // mask of built-in definitions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    julong  redef;          // mask of local flag definitions or redefinitions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    ptrlist layouts;        // local (compressor-defined) defs, in index order
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    int     flag_count[X_ATTR_LIMIT_FLAGS_HI];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    intlist overflow_count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    ptrlist strip_names;    // what attribute names are being stripped?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    ptrlist band_stack;     // Temp., used during layout parsing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    ptrlist calls_to_link;  //  (ditto)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    int     bands_made;     //  (ditto)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    void free() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
      layouts.free();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
      overflow_count.free();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
      strip_names.free();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
      band_stack.free();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
      calls_to_link.free();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    // Locate the five fixed bands.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    band& xxx_flags_hi();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    band& xxx_flags_lo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    band& xxx_attr_count();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    band& xxx_attr_indexes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    band& xxx_attr_calls();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    band& fixed_band(int e_class_xxx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    // Register a new layout, and make bands for it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    layout_definition* defineLayout(int idx, const char* name, const char* layout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    layout_definition* defineLayout(int idx, entry* nameEntry, const char* layout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    band** buildBands(layout_definition* lo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    // Parse a layout string or part of one, recursively if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    const char* parseLayout(const char* lp,    band** &res, int curCble);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    const char* parseNumeral(const char* lp,   int    &res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    const char* parseIntLayout(const char* lp, band*  &res, byte le_kind,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                               bool can_be_signed = false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    band** popBody(int band_stack_base);  // pops a body off band_stack
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    // Read data into the bands of the idx-th layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    void readBandData(int idx);  // parse layout, make bands, read data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    void readBandData(band** body, uint count);  // recursive helper
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    layout_definition* getLayout(uint idx) {
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   331
      if (idx >= (uint)layouts.length())  return null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
      return (layout_definition*) layouts.get(idx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    void setHaveLongFlags(bool z) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
      assert(flag_limit == 0);  // not set up yet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
      flag_limit = (z? X_ATTR_LIMIT_FLAGS_HI: X_ATTR_LIMIT_NO_FLAGS_HI);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    bool haveLongFlags() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     assert(flag_limit == X_ATTR_LIMIT_NO_FLAGS_HI ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            flag_limit == X_ATTR_LIMIT_FLAGS_HI);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
      return flag_limit == X_ATTR_LIMIT_FLAGS_HI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    // Return flag_count if idx is predef and not redef, else zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    int predefCount(uint idx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    bool isRedefined(uint idx) {
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   349
      if (idx >= flag_limit) return false;
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   350
      return (bool)((redef >> idx) & 1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    bool isPredefined(uint idx) {
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   353
      if (idx >= flag_limit) return false;
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   354
      return (bool)(((predef & ~redef) >> idx) & 1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    julong flagIndexMask() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
      return (predef | redef);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    bool isIndex(uint idx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
      assert(flag_limit != 0);  // must be set up already
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
      if (idx < flag_limit)
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   362
        return (bool)(((predef | redef) >> idx) & 1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
      else
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
   364
        return (idx - flag_limit < (uint)overflow_count.length());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    int& getCount(uint idx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
      assert(isIndex(idx));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
      if (idx < flag_limit)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        return flag_count[idx];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
      else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        return overflow_count.get(idx - flag_limit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    bool aborting()             { return u->aborting(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    void abort(const char* msg) { u->abort(msg); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
  };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
  attr_definitions attr_defs[ATTR_CONTEXT_LIMIT];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
  // Initialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
  void         init(read_input_fn_t input_fn = null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
  // Resets to a known sane state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
  void         reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
  // Deallocates all storage.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
  void         free();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
  // Deallocates temporary storage (volatile after next client call).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
  void         free_temps() { tsmallbuf.init(); tmallocs.freeAll(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
  // Option management methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
  bool         set_option(const char* option, const char* value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
  const char*  get_option(const char* option);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
  void         dump_options();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
  // Fetching input.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
  bool   ensure_input(jlong more);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
  byte*  input_scan()               { return rp; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
  size_t input_remaining()          { return rplimit - rp; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
  size_t input_consumed()           { return rp - input.base(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
  // Entry points to the unpack engine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
  static int   run(int argc, char **argv);   // Unix-style entry point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
  void         check_options();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
  void         start(void* packptr = null, size_t len = 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
  void         redirect_stdio();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
  void         write_file_to_jar(file* f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
  void         finish();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
  // Public post unpack methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
  int          get_files_remaining()    { return files_remaining; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
  int          get_segments_remaining() { return archive_next_count; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
  file*        get_next_file();  // returns null on last file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
  // General purpose methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
  void*        alloc(size_t size) { return alloc_heap(size, true); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
  void*        temp_alloc(size_t size) { return alloc_heap(size, true, true); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
  void*        alloc_heap(size_t size, bool smallOK = false, bool temp = false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
  void         saveTo(bytes& b, const char* str) { saveTo(b, (byte*)str, strlen(str)); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
  void         saveTo(bytes& b, bytes& data) { saveTo(b, data.ptr, data.len); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
  void         saveTo(bytes& b, byte* ptr, size_t len); //{ b.ptr = U_NEW...}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
  const char*  saveStr(const char* str) { bytes buf; saveTo(buf, str); return buf.strval(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
  const char*  saveIntStr(int num) { char buf[30]; sprintf(buf, "%d", num); return saveStr(buf); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
#ifndef PRODUCT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
  int printcr_if_verbose(int level, const char* fmt,...);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
  const char*  get_abort_message();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
  void         abort(const char* s = null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
  bool         aborting() { return abort_message != null; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
  static unpacker* current();  // find current instance
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 5506
diff changeset
   429
  void checkLegacy(const char* name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
  // Output management
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
  void set_output(fillbytes* which) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    assert(wp == null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    which->ensureSize(1 << 12);  // covers the average classfile
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    wpbase  = which->base();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    wp      = which->limit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    wplimit = which->end();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
  fillbytes* close_output(fillbytes* which = null);  // inverse of set_output
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
  // These take an implicit parameter of wp/wplimit, and resize as necessary:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
  byte*  put_space(size_t len);  // allocates space at wp, returns pointer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
  size_t put_empty(size_t s)    { byte* p = put_space(s); return p - wpbase; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
  void   ensure_put_space(size_t len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
  void   put_bytes(bytes& b)    { b.writeTo(put_space(b.len)); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
  void   putu1(int n)           { putu1_at(put_space(1), n); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
  void   putu1_fast(int n)      { putu1_at(wp++,         n); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
  void   putu2(int n);       // { putu2_at(put_space(2), n); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
  void   putu4(int n);       // { putu4_at(put_space(4), n); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
  void   putu8(jlong n);     // { putu8_at(put_space(8), n); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
  void   putref(entry* e);   // { putu2_at(put_space(2), putref_index(e, 2)); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
  void   putu1ref(entry* e); // { putu1_at(put_space(1), putref_index(e, 1)); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
  int    putref_index(entry* e, int size);  // size in [1..2]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
  void   put_label(int curIP, int size);    // size in {2,4}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
  void   putlayout(band** body);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
  void   put_stackmap_type();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
  size_t wpoffset() { return (size_t)(wp - wpbase); }  // (unvariant across overflow)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
  byte*  wp_at(size_t offset) { return wpbase + offset; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
  uint to_bci(uint bii);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
  void get_code_header(int& max_stack,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                       int& max_na_locals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                       int& handler_count,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                       int& cflags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
  band* ref_band_for_self_op(int bc, bool& isAloadVar, int& origBCVar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
  band* ref_band_for_op(int bc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
  // Definitions of standard classfile int formats:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
  static void putu1_at(byte* wp, int n) { assert(n == (n & 0xFF)); wp[0] = n; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
  static void putu2_at(byte* wp, int n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
  static void putu4_at(byte* wp, int n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
  static void putu8_at(byte* wp, jlong n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
  // Private stuff
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
  void reset_cur_classfile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
  void write_classfile_tail();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
  void write_classfile_head();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
  void write_code();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
  void write_bc_ops();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
  void write_members(int num, int attrc);  // attrc=ATTR_CONTEXT_FIELD/METHOD
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
  int  write_attrs(int attrc, julong indexBits);
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 5506
diff changeset
   481
  int  write_ics(int naOffset, int na);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 5506
diff changeset
   482
  int  write_bsms(int naOffset, int na);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
  // The readers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
  void read_bands();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
  void read_file_header();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
  void read_cp();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
  void read_cp_counts(value_stream& hdr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
  void read_attr_defs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
  void read_ics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
  void read_attrs(int attrc, int obj_count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
  void read_classes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
  void read_code_headers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
  void read_bcs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
  void read_bc_ops();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
  void read_files();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
  void read_Utf8_values(entry* cpMap, int len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
  void read_single_words(band& cp_band, entry* cpMap, int len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
  void read_double_words(band& cp_bands, entry* cpMap, int len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
  void read_single_refs(band& cp_band, byte refTag, entry* cpMap, int len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
  void read_double_refs(band& cp_band, byte ref1Tag, byte ref2Tag, entry* cpMap, int len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
  void read_signature_values(entry* cpMap, int len);
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 5506
diff changeset
   503
  void read_method_handle(entry* cpMap, int len);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 5506
diff changeset
   504
  void read_method_type(entry* cpMap, int len);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 5506
diff changeset
   505
  void read_bootstrap_methods(entry* cpMap, int len);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
inline void cpool::abort(const char* msg) { u->abort(msg); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
inline bool cpool::aborting()             { return u->aborting(); }