jdk/src/share/classes/com/sun/java/util/jar/pack/PackageReader.java
author ohair
Tue, 28 Dec 2010 15:53:50 -0800
changeset 7668 d4a77089c587
parent 7192 445c518364c4
child 7816 55a18147b4bf
permissions -rw-r--r--
6962318: Update copyright year Reviewed-by: xdono
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
7668
d4a77089c587 6962318: Update copyright year
ohair
parents: 7192
diff changeset
     2
 * Copyright (c) 2001, 2010, 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: 4919
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: 4919
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: 4919
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4919
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4919
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package com.sun.java.util.jar.pack;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
7192
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 5506
diff changeset
    28
import com.sun.java.util.jar.pack.ConstantPool.ClassEntry;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 5506
diff changeset
    29
import com.sun.java.util.jar.pack.ConstantPool.DescriptorEntry;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 5506
diff changeset
    30
import com.sun.java.util.jar.pack.ConstantPool.Entry;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 5506
diff changeset
    31
import com.sun.java.util.jar.pack.ConstantPool.Index;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 5506
diff changeset
    32
import com.sun.java.util.jar.pack.ConstantPool.MemberEntry;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 5506
diff changeset
    33
import com.sun.java.util.jar.pack.ConstantPool.SignatureEntry;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 5506
diff changeset
    34
import com.sun.java.util.jar.pack.ConstantPool.Utf8Entry;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import com.sun.java.util.jar.pack.Package.Class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import com.sun.java.util.jar.pack.Package.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import com.sun.java.util.jar.pack.Package.InnerClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * Reader for a package file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * @see PackageWriter
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * @author John Rose
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
class PackageReader extends BandStructure {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    Package pkg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    byte[] bytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    LimitedBuffer in;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    PackageReader(Package pkg, InputStream in) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        this.pkg = pkg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        this.in = new LimitedBuffer(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    /** A buffered input stream which is careful not to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     *  read its underlying stream ahead of a given mark,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     *  called the 'readLimit'.  This property declares
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     *  the maximum number of characters that future reads
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     *  can consume from the underlying stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    static
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    class LimitedBuffer extends BufferedInputStream {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        long served;     // total number of charburgers served
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        int  servedPos;  // ...as of this value of super.pos
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        long limit;      // current declared limit
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        long buffered;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        public boolean atLimit() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            boolean z = (getBytesServed() == limit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            assert(!z || limit == buffered);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            return z;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        public long getBytesServed() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            return served + (pos - servedPos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        public void setReadLimit(long newLimit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            if (newLimit == -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                limit = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                limit = getBytesServed() + newLimit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        public long getReadLimit() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            if (limit == -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                return limit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                return limit - getBytesServed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        public int read() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            if (pos < count) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                // fast path
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                return buf[pos++] & 0xFF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            served += (pos - servedPos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            int ch = super.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            servedPos = pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            if (ch >= 0)  served += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            assert(served <= limit || limit == -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            return ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        public int read(byte b[], int off, int len) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            served += (pos - servedPos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            int nr = super.read(b, off, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            servedPos = pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            if (nr >= 0)  served += nr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            assert(served <= limit || limit == -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            return nr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        public long skip(long n) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            throw new RuntimeException("no skipping");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        LimitedBuffer(InputStream originalIn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            super(null, 1<<14);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            servedPos = pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            super.in = new FilterInputStream(originalIn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                public int read() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                    if (buffered == limit)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                    ++buffered;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                    return super.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                public int read(byte b[], int off, int len) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                    if (buffered == limit)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                    if (limit != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                        long remaining = limit - buffered;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                        if (len > remaining)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                            len = (int)remaining;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                    int nr = super.read(b, off, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                    if (nr >= 0)  buffered += nr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                    return nr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    void read() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        boolean ok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            //  pack200_archive:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            //        file_header
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            //        *band_headers :BYTE1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            //        cp_bands
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            //        attr_definition_bands
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            //        ic_bands
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            //        class_bands
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            //        bc_bands
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            //        file_bands
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            readFileHeader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            readBandHeaders();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            readConstantPool();  // cp_bands
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            readAttrDefs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            readInnerClasses();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            Class[] classes = readClasses();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            readByteCodes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            readFiles();     // file_bands
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            assert(archiveSize1 == 0 || in.atLimit());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            assert(archiveSize1 == 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                   in.getBytesServed() == archiveSize0+archiveSize1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            all_bands.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            // As a post-pass, build constant pools and inner classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            for (int i = 0; i < classes.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                reconstructClass(classes[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            ok = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        } catch (Exception ee) {
4919
b00f729ee70a 6925868: Eliminate pack200's dependency on logging
mchung
parents: 2
diff changeset
   170
            Utils.log.warning("Error on input: "+ee, ee);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            if (verbose > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                Utils.log.info("Stream offsets:"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                                 " served="+in.getBytesServed()+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                                 " buffered="+in.buffered+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                                 " limit="+in.limit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            //if (verbose > 0)  ee.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            if (ee instanceof IOException)  throw (IOException)ee;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            if (ee instanceof RuntimeException)  throw (RuntimeException)ee;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            throw new Error("error unpacking", ee);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    // Temporary count values, until band decoding gets rolling.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    int[] tagCount = new int[CONSTANT_Limit];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    int numFiles;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    int numAttrDefs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    int numInnerClasses;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    int numClasses;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    void readFileHeader() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        //  file_header:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        //        archive_magic archive_header
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        readArchiveMagic();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        readArchiveHeader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    // Local routine used to parse fixed-format scalars
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    // in the file_header:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    private int getMagicInt32() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        int res = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        for (int i = 0; i < 4; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            res <<= 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            res |= (archive_magic.getByte() & 0xFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    final static int MAGIC_BYTES = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    void readArchiveMagic() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        // Read a minimum of bytes in the first gulp.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        in.setReadLimit(MAGIC_BYTES + AH_LENGTH_MIN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        //  archive_magic:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        //        #archive_magic_word :BYTE1[4]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        archive_magic.expectLength(MAGIC_BYTES);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        archive_magic.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        // read and check magic numbers:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        pkg.magic = getMagicInt32();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        archive_magic.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    void readArchiveHeader() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        //  archive_header:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        //        #archive_minver :UNSIGNED5[1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        //        #archive_majver :UNSIGNED5[1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        //        #archive_options :UNSIGNED5[1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        //        (archive_file_counts) ** (#have_file_headers)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        //        (archive_special_counts) ** (#have_special_formats)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        //        cp_counts
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        //        class_counts
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        //  archive_file_counts:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        //        #archive_size_hi :UNSIGNED5[1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        //        #archive_size_lo :UNSIGNED5[1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        //        #archive_next_count :UNSIGNED5[1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        //        #archive_modtime :UNSIGNED5[1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        //        #file_count :UNSIGNED5[1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        //  class_counts:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        //        #ic_count :UNSIGNED5[1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        //        #default_class_minver :UNSIGNED5[1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        //        #default_class_majver :UNSIGNED5[1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        //        #class_count :UNSIGNED5[1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        //  archive_special_counts:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        //        #band_headers_size :UNSIGNED5[1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        //        #attr_definition_count :UNSIGNED5[1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        assert(AH_LENGTH == 8+(ConstantPool.TAGS_IN_ORDER.length)+6);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        archive_header_0.expectLength(AH_LENGTH_0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        archive_header_0.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        pkg.package_minver = archive_header_0.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        pkg.package_majver = archive_header_0.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        pkg.checkVersion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        this.initPackageMajver(pkg.package_majver);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        archiveOptions = archive_header_0.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        archive_header_0.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        // detect archive optional fields in archive header
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        boolean haveSpecial = testBit(archiveOptions, AO_HAVE_SPECIAL_FORMATS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        boolean haveFiles   = testBit(archiveOptions, AO_HAVE_FILE_HEADERS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        boolean haveNumbers = testBit(archiveOptions, AO_HAVE_CP_NUMBERS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        initAttrIndexLimit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        // now we are ready to use the data:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        archive_header_S.expectLength(haveFiles? AH_LENGTH_S: 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        archive_header_S.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        if (haveFiles) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            long sizeHi = archive_header_S.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            long sizeLo = archive_header_S.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            archiveSize1 = (sizeHi << 32) + ((sizeLo << 32) >>> 32);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            // Set the limit, now, up to the file_bits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            in.setReadLimit(archiveSize1);  // for debug only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            archiveSize1 = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            in.setReadLimit(-1);  // remove limitation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        archive_header_S.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        archiveSize0 = in.getBytesServed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        int remainingHeaders = AH_LENGTH - AH_LENGTH_0 - AH_LENGTH_S;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        if (!haveFiles)    remainingHeaders -= AH_FILE_HEADER_LEN-AH_LENGTH_S;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        if (!haveSpecial)  remainingHeaders -= AH_SPECIAL_FORMAT_LEN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        if (!haveNumbers)  remainingHeaders -= AH_CP_NUMBER_LEN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        assert(remainingHeaders >= AH_LENGTH_MIN - AH_LENGTH_0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        archive_header_1.expectLength(remainingHeaders);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        archive_header_1.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        if (haveFiles) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            archiveNextCount = archive_header_1.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            pkg.default_modtime = archive_header_1.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            numFiles = archive_header_1.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            archiveNextCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            numFiles = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        if (haveSpecial) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            band_headers.expectLength(archive_header_1.getInt());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            numAttrDefs = archive_header_1.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            band_headers.expectLength(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            numAttrDefs = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        readConstantPoolCounts(haveNumbers);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        numInnerClasses = archive_header_1.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        pkg.default_class_minver = (short) archive_header_1.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        pkg.default_class_majver = (short) archive_header_1.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        numClasses = archive_header_1.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        archive_header_1.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        // set some derived archive bits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        if (testBit(archiveOptions, AO_DEFLATE_HINT)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            pkg.default_options |= FO_DEFLATE_HINT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    void readBandHeaders() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        band_headers.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        bandHeaderBytePos = 1;  // Leave room to pushback the initial XB byte.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        bandHeaderBytes = new byte[bandHeaderBytePos + band_headers.length()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        for (int i = bandHeaderBytePos; i < bandHeaderBytes.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            bandHeaderBytes[i] = (byte) band_headers.getByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        band_headers.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    void readConstantPoolCounts(boolean haveNumbers) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        // size the constant pools:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        for (int k = 0; k < ConstantPool.TAGS_IN_ORDER.length; k++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            //  cp_counts:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            //        #cp_Utf8_count :UNSIGNED5[1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            //        (cp_number_counts) ** (#have_cp_numbers)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            //        #cp_String_count :UNSIGNED5[1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            //        #cp_Class_count :UNSIGNED5[1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            //        #cp_Signature_count :UNSIGNED5[1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            //        #cp_Descr_count :UNSIGNED5[1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            //        #cp_Field_count :UNSIGNED5[1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            //        #cp_Method_count :UNSIGNED5[1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            //        #cp_Imethod_count :UNSIGNED5[1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            //  cp_number_counts:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            //        #cp_Int_count :UNSIGNED5[1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            //        #cp_Float_count :UNSIGNED5[1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            //        #cp_Long_count :UNSIGNED5[1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            //        #cp_Double_count :UNSIGNED5[1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            byte tag = ConstantPool.TAGS_IN_ORDER[k];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            if (!haveNumbers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                // These four counts are optional.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                switch (tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                case CONSTANT_Integer:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                case CONSTANT_Float:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                case CONSTANT_Long:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                case CONSTANT_Double:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            tagCount[tag] = archive_header_1.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    protected Index getCPIndex(byte tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        return pkg.cp.getIndexByTag(tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    Index initCPIndex(byte tag, Entry[] cpMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        if (verbose > 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            for (int i = 0; i < cpMap.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                Utils.log.fine("cp.add "+cpMap[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        Index index = ConstantPool.makeIndex(ConstantPool.tagName(tag), cpMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        if (verbose > 1)  Utils.log.fine("Read "+index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        pkg.cp.initIndexByTag(tag, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        return index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    void readConstantPool() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        //  cp_bands:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        //        cp_Utf8
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        //        *cp_Int :UDELTA5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        //        *cp_Float :UDELTA5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        //        cp_Long
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        //        cp_Double
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        //        *cp_String :UDELTA5  (cp_Utf8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        //        *cp_Class :UDELTA5  (cp_Utf8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        //        cp_Signature
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        //        cp_Descr
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        //        cp_Field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        //        cp_Method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        //        cp_Imethod
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        if (verbose > 0)  Utils.log.info("Reading CP");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        for (int k = 0; k < ConstantPool.TAGS_IN_ORDER.length; k++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            byte tag = ConstantPool.TAGS_IN_ORDER[k];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            int  len = tagCount[tag];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            Entry[] cpMap = new Entry[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            if (verbose > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                Utils.log.info("Reading "+cpMap.length+" "+ConstantPool.tagName(tag)+" entries...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            switch (tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            case CONSTANT_Utf8:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                readUtf8Bands(cpMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            case CONSTANT_Integer:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                cp_Int.expectLength(cpMap.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                cp_Int.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                for (int i = 0; i < cpMap.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                    int x = cp_Int.getInt();  // coding handles signs OK
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                    cpMap[i] = ConstantPool.getLiteralEntry(new Integer(x));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                cp_Int.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            case CONSTANT_Float:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                cp_Float.expectLength(cpMap.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                cp_Float.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                for (int i = 0; i < cpMap.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                    int x = cp_Float.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                    float fx = Float.intBitsToFloat(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                    cpMap[i] = ConstantPool.getLiteralEntry(new Float(fx));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                cp_Float.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            case CONSTANT_Long:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                //  cp_Long:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                //        *cp_Long_hi :UDELTA5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                //        *cp_Long_lo :DELTA5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                cp_Long_hi.expectLength(cpMap.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                cp_Long_hi.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                cp_Long_lo.expectLength(cpMap.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                cp_Long_lo.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                for (int i = 0; i < cpMap.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                    long hi = cp_Long_hi.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                    long lo = cp_Long_lo.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                    long x = (hi << 32) + ((lo << 32) >>> 32);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                    cpMap[i] = ConstantPool.getLiteralEntry(new Long(x));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                cp_Long_hi.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                cp_Long_lo.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            case CONSTANT_Double:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                //  cp_Double:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                //        *cp_Double_hi :UDELTA5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                //        *cp_Double_lo :DELTA5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                cp_Double_hi.expectLength(cpMap.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                cp_Double_hi.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                cp_Double_lo.expectLength(cpMap.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                cp_Double_lo.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                for (int i = 0; i < cpMap.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                    long hi = cp_Double_hi.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                    long lo = cp_Double_lo.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                    long x = (hi << 32) + ((lo << 32) >>> 32);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                    double dx = Double.longBitsToDouble(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                    cpMap[i] = ConstantPool.getLiteralEntry(new Double(dx));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                cp_Double_hi.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                cp_Double_lo.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            case CONSTANT_String:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                cp_String.expectLength(cpMap.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                cp_String.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                cp_String.setIndex(getCPIndex(CONSTANT_Utf8));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                for (int i = 0; i < cpMap.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                    cpMap[i] = ConstantPool.getLiteralEntry(cp_String.getRef().stringValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                cp_String.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            case CONSTANT_Class:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                cp_Class.expectLength(cpMap.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                cp_Class.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                cp_Class.setIndex(getCPIndex(CONSTANT_Utf8));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                for (int i = 0; i < cpMap.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                    cpMap[i] = ConstantPool.getClassEntry(cp_Class.getRef().stringValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                cp_Class.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            case CONSTANT_Signature:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                readSignatureBands(cpMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            case CONSTANT_NameandType:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                //  cp_Descr:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                //        *cp_Descr_type :DELTA5  (cp_Signature)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                //        *cp_Descr_name :UDELTA5  (cp_Utf8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                cp_Descr_name.expectLength(cpMap.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                cp_Descr_name.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                cp_Descr_name.setIndex(getCPIndex(CONSTANT_Utf8));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                cp_Descr_type.expectLength(cpMap.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                cp_Descr_type.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                cp_Descr_type.setIndex(getCPIndex(CONSTANT_Signature));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                for (int i = 0; i < cpMap.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                    Entry ref  = cp_Descr_name.getRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                    Entry ref2 = cp_Descr_type.getRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                    cpMap[i] = ConstantPool.getDescriptorEntry((Utf8Entry)ref,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                                                        (SignatureEntry)ref2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                cp_Descr_name.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                cp_Descr_type.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            case CONSTANT_Fieldref:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                readMemberRefs(tag, cpMap, cp_Field_class, cp_Field_desc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            case CONSTANT_Methodref:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                readMemberRefs(tag, cpMap, cp_Method_class, cp_Method_desc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            case CONSTANT_InterfaceMethodref:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                readMemberRefs(tag, cpMap, cp_Imethod_class, cp_Imethod_desc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                assert(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            Index index = initCPIndex(tag, cpMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            if (optDumpBands) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                PrintStream ps = new PrintStream(getDumpStream(index, ".idx"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                printArrayTo(ps, index.cpMap, 0, index.cpMap.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                ps.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        cp_bands.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        setBandIndexes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    void readUtf8Bands(Entry[] cpMap) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        //  cp_Utf8:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        //        *cp_Utf8_prefix :DELTA5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        //        *cp_Utf8_suffix :UNSIGNED5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        //        *cp_Utf8_chars :CHAR3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        //        *cp_Utf8_big_suffix :DELTA5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        //        (*cp_Utf8_big_chars :DELTA5)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        //          ** length(cp_Utf8_big_suffix)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        int len = cpMap.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        if (len == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
            return;  // nothing to read
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        // Bands have implicit leading zeroes, for the empty string:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        final int SUFFIX_SKIP_1 = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        final int PREFIX_SKIP_2 = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        // First band:  Read lengths of shared prefixes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        cp_Utf8_prefix.expectLength(Math.max(0, len - PREFIX_SKIP_2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        cp_Utf8_prefix.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        // Second band:  Read lengths of unshared suffixes:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        cp_Utf8_suffix.expectLength(Math.max(0, len - SUFFIX_SKIP_1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        cp_Utf8_suffix.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        char[][] suffixChars = new char[len][];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        int bigSuffixCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        // Third band:  Read the char values in the unshared suffixes:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        cp_Utf8_chars.expectLength(cp_Utf8_suffix.getIntTotal());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        cp_Utf8_chars.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        for (int i = 0; i < len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
            int suffix = (i < SUFFIX_SKIP_1)? 0: cp_Utf8_suffix.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
            if (suffix == 0 && i >= SUFFIX_SKIP_1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                // chars are packed in cp_Utf8_big_chars
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                bigSuffixCount += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            suffixChars[i] = new char[suffix];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            for (int j = 0; j < suffix; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                int ch = cp_Utf8_chars.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                assert(ch == (char)ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                suffixChars[i][j] = (char)ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        cp_Utf8_chars.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        // Fourth band:  Go back and size the specially packed strings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        int maxChars = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        cp_Utf8_big_suffix.expectLength(bigSuffixCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        cp_Utf8_big_suffix.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        cp_Utf8_suffix.resetForSecondPass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        for (int i = 0; i < len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
            int suffix = (i < SUFFIX_SKIP_1)? 0: cp_Utf8_suffix.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
            int prefix = (i < PREFIX_SKIP_2)? 0: cp_Utf8_prefix.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            if (suffix == 0 && i >= SUFFIX_SKIP_1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                assert(suffixChars[i] == null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                suffix = cp_Utf8_big_suffix.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                assert(suffixChars[i] != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
            if (maxChars < prefix + suffix)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                maxChars = prefix + suffix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        char[] buf = new char[maxChars];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        // Fifth band(s):  Get the specially packed characters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        cp_Utf8_suffix.resetForSecondPass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        cp_Utf8_big_suffix.resetForSecondPass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        for (int i = 0; i < len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
            if (i < SUFFIX_SKIP_1)  continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            int suffix = cp_Utf8_suffix.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
            if (suffix != 0)  continue;  // already input
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
            suffix = cp_Utf8_big_suffix.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            suffixChars[i] = new char[suffix];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            if (suffix == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                // Do not bother to add an empty "(Utf8_big_0)" band.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            IntBand packed = cp_Utf8_big_chars.newIntBand("(Utf8_big_"+i+")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
            packed.expectLength(suffix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            packed.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            for (int j = 0; j < suffix; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                int ch = packed.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                assert(ch == (char)ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                suffixChars[i][j] = (char)ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
            packed.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        cp_Utf8_big_chars.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        // Finally, sew together all the prefixes and suffixes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        cp_Utf8_prefix.resetForSecondPass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        cp_Utf8_suffix.resetForSecondPass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        cp_Utf8_big_suffix.resetForSecondPass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        for (int i = 0; i < len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
            int prefix = (i < PREFIX_SKIP_2)? 0: cp_Utf8_prefix.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
            int suffix = (i < SUFFIX_SKIP_1)? 0: cp_Utf8_suffix.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
            if (suffix == 0 && i >= SUFFIX_SKIP_1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
                suffix = cp_Utf8_big_suffix.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
            // by induction, the buffer is already filled with the prefix
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
            System.arraycopy(suffixChars[i], 0, buf, prefix, suffix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
            cpMap[i] = ConstantPool.getUtf8Entry(new String(buf, 0, prefix+suffix));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        cp_Utf8_prefix.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        cp_Utf8_suffix.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        cp_Utf8_big_suffix.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
    HashMap utf8Signatures;  // Utf8Entry->SignatureEntry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    void readSignatureBands(Entry[] cpMap) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        //  cp_Signature:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        //        *cp_Signature_form :DELTA5  (cp_Utf8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        //        *cp_Signature_classes :UDELTA5  (cp_Class)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        cp_Signature_form.expectLength(cpMap.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        cp_Signature_form.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        cp_Signature_form.setIndex(getCPIndex(CONSTANT_Utf8));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        int[] numSigClasses = new int[cpMap.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        for (int i = 0; i < cpMap.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
            Utf8Entry formRef = (Utf8Entry) cp_Signature_form.getRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
            numSigClasses[i] = ConstantPool.countClassParts(formRef);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        cp_Signature_form.resetForSecondPass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        cp_Signature_classes.expectLength(getIntTotal(numSigClasses));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        cp_Signature_classes.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        cp_Signature_classes.setIndex(getCPIndex(CONSTANT_Class));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        utf8Signatures = new HashMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        for (int i = 0; i < cpMap.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
            Utf8Entry formRef = (Utf8Entry) cp_Signature_form.getRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
            ClassEntry[] classRefs = new ClassEntry[numSigClasses[i]];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
            for (int j = 0; j < classRefs.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
                classRefs[j] = (ClassEntry) cp_Signature_classes.getRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
            SignatureEntry se = ConstantPool.getSignatureEntry(formRef, classRefs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
            cpMap[i] = se;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
            utf8Signatures.put(se.asUtf8Entry(), se);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        cp_Signature_form.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        cp_Signature_classes.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
    void readMemberRefs(byte tag, Entry[] cpMap, CPRefBand cp_class, CPRefBand cp_desc) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        //  cp_Field:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
        //        *cp_Field_class :DELTA5  (cp_Class)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        //        *cp_Field_desc :UDELTA5  (cp_Descr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        //  cp_Method:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        //        *cp_Method_class :DELTA5  (cp_Class)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        //        *cp_Method_desc :UDELTA5  (cp_Descr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        //  cp_Imethod:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        //        *cp_Imethod_class :DELTA5  (cp_Class)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        //        *cp_Imethod_desc :UDELTA5  (cp_Descr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        cp_class.expectLength(cpMap.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        cp_class.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        cp_class.setIndex(getCPIndex(CONSTANT_Class));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        cp_desc.expectLength(cpMap.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        cp_desc.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        cp_desc.setIndex(getCPIndex(CONSTANT_NameandType));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        for (int i = 0; i < cpMap.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
            ClassEntry      mclass = (ClassEntry     ) cp_class.getRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
            DescriptorEntry mdescr = (DescriptorEntry) cp_desc.getRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            cpMap[i] = ConstantPool.getMemberEntry(tag, mclass, mdescr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        cp_class.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        cp_desc.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    void readFiles() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        //  file_bands:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
        //        *file_name :UNSIGNED5  (cp_Utf8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        //        *file_size_hi :UNSIGNED5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        //        *file_size_lo :UNSIGNED5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        //        *file_modtime :DELTA5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        //        *file_options :UNSIGNED5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        //        *file_bits :BYTE1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        if (verbose > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
            Utils.log.info("  ...building "+numFiles+" files...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        file_name.expectLength(numFiles);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        file_size_lo.expectLength(numFiles);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        int options = archiveOptions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        boolean haveSizeHi  = testBit(options, AO_HAVE_FILE_SIZE_HI);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        boolean haveModtime = testBit(options, AO_HAVE_FILE_MODTIME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        boolean haveOptions = testBit(options, AO_HAVE_FILE_OPTIONS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        if (haveSizeHi)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
            file_size_hi.expectLength(numFiles);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        if (haveModtime)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
            file_modtime.expectLength(numFiles);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        if (haveOptions)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
            file_options.expectLength(numFiles);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
        file_name.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
        file_size_hi.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        file_size_lo.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        file_modtime.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        file_options.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        file_bits.setInputStreamFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        Iterator nextClass = pkg.getClasses().iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
        // Compute file lengths before reading any file bits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        long totalFileLength = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        long[] fileLengths = new long[numFiles];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        for (int i = 0; i < numFiles; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
            long size = ((long)file_size_lo.getInt() << 32) >>> 32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
            if (haveSizeHi)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
                size += (long)file_size_hi.getInt() << 32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
            fileLengths[i] = size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
            totalFileLength += size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        assert(in.getReadLimit() == -1 || in.getReadLimit() == totalFileLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        byte[] buf = new byte[1<<16];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        for (int i = 0; i < numFiles; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
            // %%% Use a big temp file for file bits?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
            Utf8Entry name = (Utf8Entry) file_name.getRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
            long size = fileLengths[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
            File file = pkg.new File(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
            file.modtime = pkg.default_modtime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
            file.options = pkg.default_options;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
            if (haveModtime)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
                file.modtime += file_modtime.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
            if (haveOptions)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
                file.options |= file_options.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
            if (verbose > 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
                Utils.log.fine("Reading "+size+" bytes of "+name.stringValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
            long toRead = size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
            while (toRead > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                int nr = buf.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
                if (nr > toRead)  nr = (int) toRead;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
                nr = file_bits.getInputStream().read(buf, 0, nr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                if (nr < 0)  throw new EOFException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                file.addBytes(buf, 0, nr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                toRead -= nr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
            pkg.addFile(file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
            if (file.isClassStub()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
                assert(file.getFileLength() == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                Class cls = (Class) nextClass.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                cls.initFile(file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
        // Do the rest of the classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        while (nextClass.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
            Class cls = (Class) nextClass.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
            cls.initFile(null);  // implicitly initialize to a trivial one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
            cls.file.modtime = pkg.default_modtime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
        file_name.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
        file_size_hi.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
        file_size_lo.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
        file_modtime.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
        file_options.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        file_bits.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
        file_bands.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        if (archiveSize1 != 0 && !in.atLimit()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
            throw new RuntimeException("Predicted archive_size "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
                                       archiveSize1+" != "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
                                       (in.getBytesServed()-archiveSize0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
    void readAttrDefs() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
        //  attr_definition_bands:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        //        *attr_definition_headers :BYTE1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
        //        *attr_definition_name :UNSIGNED5  (cp_Utf8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        //        *attr_definition_layout :UNSIGNED5  (cp_Utf8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        attr_definition_headers.expectLength(numAttrDefs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
        attr_definition_name.expectLength(numAttrDefs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
        attr_definition_layout.expectLength(numAttrDefs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
        attr_definition_headers.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
        attr_definition_name.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
        attr_definition_layout.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
        PrintStream dump = !optDumpBands ? null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
            : new PrintStream(getDumpStream(attr_definition_headers, ".def"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
        for (int i = 0; i < numAttrDefs; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
            int       header = attr_definition_headers.getByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
            Utf8Entry name   = (Utf8Entry) attr_definition_name.getRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
            Utf8Entry layout = (Utf8Entry) attr_definition_layout.getRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
            int       ctype  = (header &  ADH_CONTEXT_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
            int       index  = (header >> ADH_BIT_SHIFT) - ADH_BIT_IS_LSB;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
            Attribute.Layout def = new Attribute.Layout(ctype,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
                                                        name.stringValue(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
                                                        layout.stringValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
            // Check layout string for Java 6 extensions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
            String pvLayout = def.layoutForPackageMajver(getPackageMajver());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
            if (!pvLayout.equals(def.layout())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
                throw new IOException("Bad attribute layout in version 150 archive: "+def.layout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
            this.setAttributeLayoutIndex(def, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
            if (dump != null)  dump.println(index+" "+def);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        if (dump != null)  dump.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
        attr_definition_headers.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        attr_definition_name.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
        attr_definition_layout.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
        // Attribute layouts define bands, one per layout element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        // Create them now, all at once.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        makeNewAttributeBands();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
        attr_definition_bands.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
    void readInnerClasses() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
        //  ic_bands:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
        //        *ic_this_class :UDELTA5  (cp_Class)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
        //        *ic_flags :UNSIGNED5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
        //        *ic_outer_class :DELTA5  (null or cp_Class)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
        //        *ic_name :DELTA5  (null or cp_Utf8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
        ic_this_class.expectLength(numInnerClasses);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
        ic_this_class.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
        ic_flags.expectLength(numInnerClasses);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
        ic_flags.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
        int longICCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        for (int i = 0; i < numInnerClasses; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
            int flags = ic_flags.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
            boolean longForm = (flags & ACC_IC_LONG_FORM) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
            if (longForm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
                longICCount += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        ic_outer_class.expectLength(longICCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
        ic_outer_class.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        ic_name.expectLength(longICCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        ic_name.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        ic_flags.resetForSecondPass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
        ArrayList icList = new ArrayList(numInnerClasses);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
        for (int i = 0; i < numInnerClasses; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
            int flags = ic_flags.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
            boolean longForm = (flags & ACC_IC_LONG_FORM) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
            flags &= ~ACC_IC_LONG_FORM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
            ClassEntry thisClass = (ClassEntry) ic_this_class.getRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
            ClassEntry outerClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
            Utf8Entry  thisName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
            if (longForm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
                outerClass = (ClassEntry) ic_outer_class.getRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
                thisName   = (Utf8Entry)  ic_name.getRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
                String n = thisClass.stringValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
                String[] parse = pkg.parseInnerClassName(n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
                assert(parse != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
                String pkgOuter = parse[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
                //String number = parse[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
                String name     = parse[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
                if (pkgOuter == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
                    outerClass = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
                    outerClass = ConstantPool.getClassEntry(pkgOuter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
                if (name == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
                    thisName   = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
                    thisName   = ConstantPool.getUtf8Entry(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
            InnerClass ic =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
                new InnerClass(thisClass, outerClass, thisName, flags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
            assert(longForm || ic.predictable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
            icList.add(ic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
        ic_flags.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        ic_this_class.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
        ic_outer_class.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
        ic_name.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        pkg.setAllInnerClasses(icList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
        ic_bands.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
    void readLocalInnerClasses(Class cls) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
        int nc = class_InnerClasses_N.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
        ArrayList localICs = new ArrayList(nc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        for (int i = 0; i < nc; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
            ClassEntry thisClass = (ClassEntry) class_InnerClasses_RC.getRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
            int        flags     =              class_InnerClasses_F.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
            if (flags == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
                // A zero flag means copy a global IC here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
                InnerClass ic = pkg.getGlobalInnerClass(thisClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
                assert(ic != null);  // must be a valid global IC reference
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
                localICs.add(ic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
                if (flags == ACC_IC_LONG_FORM)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
                    flags = 0;  // clear the marker bit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
                ClassEntry outer = (ClassEntry) class_InnerClasses_outer_RCN.getRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
                Utf8Entry name   = (Utf8Entry)  class_InnerClasses_name_RUN.getRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
                localICs.add(new InnerClass(thisClass, outer, name, flags));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
        cls.setInnerClasses(localICs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
        // cls.expandLocalICs may add more tuples to ics also,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
        // or may even delete tuples.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
        // We cannot do that now, because we do not know the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
        // full contents of the local constant pool yet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
    static final int NO_FLAGS_YET = 0;  // placeholder for later flag read-in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
    Class[] readClasses() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
        //  class_bands:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
        //        *class_this :DELTA5  (cp_Class)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
        //        *class_super :DELTA5  (cp_Class)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
        //        *class_interface_count :DELTA5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
        //        *class_interface :DELTA5  (cp_Class)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
        //        ...(member bands)...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
        //        class_attr_bands
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
        //        code_bands
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
        Class[] classes = new Class[numClasses];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
        if (verbose > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
            Utils.log.info("  ...building "+classes.length+" classes...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
        class_this.expectLength(numClasses);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
        class_super.expectLength(numClasses);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
        class_interface_count.expectLength(numClasses);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
        class_this.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
        class_super.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
        class_interface_count.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
        class_interface.expectLength(class_interface_count.getIntTotal());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
        class_interface.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
        for (int i = 0; i < classes.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
            ClassEntry   thisClass  = (ClassEntry) class_this.getRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
            ClassEntry   superClass = (ClassEntry) class_super.getRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
            ClassEntry[] interfaces = new ClassEntry[class_interface_count.getInt()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
            for (int j = 0; j < interfaces.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
                interfaces[j] = (ClassEntry) class_interface.getRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
            // Packer encoded rare case of null superClass as thisClass:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
            if (superClass == thisClass)  superClass = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
            Class cls = pkg.new Class(NO_FLAGS_YET,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
                                      thisClass, superClass, interfaces);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
            classes[i] = cls;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
        class_this.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
        class_super.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
        class_interface_count.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
        class_interface.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
        readMembers(classes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
        countAndReadAttrs(ATTR_CONTEXT_CLASS, Arrays.asList(classes));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
        pkg.trimToSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
        readCodeHeaders();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        //code_bands.doneDisbursing(); // still need to read code attrs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
        //class_bands.doneDisbursing(); // still need to read code attrs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
        return classes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
    private int getOutputIndex(Entry e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
        // Output CPs do not contain signatures.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
        assert(e.tag != CONSTANT_Signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
        int k = pkg.cp.untypedIndexOf(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
        // In the output ordering, input signatures can serve
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
        // in place of Utf8s.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
        if (k >= 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
            return k;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
        if (e.tag == CONSTANT_Utf8) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
            Entry se = (Entry) utf8Signatures.get(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
            return pkg.cp.untypedIndexOf(se);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
    Comparator entryOutputOrder = new Comparator() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
        public int compare(Object o0, Object o1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
            Entry e0 = (Entry) o0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
            Entry e1 = (Entry) o1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
            int k0 = getOutputIndex(e0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
            int k1 = getOutputIndex(e1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
            if (k0 >= 0 && k1 >= 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
                // If both have keys, use the keys.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
                return k0 - k1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
            if (k0 == k1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
                // If neither have keys, use their native tags & spellings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
                return e0.compareTo(e1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
            // Otherwise, the guy with the key comes first.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
            return (k0 >= 0)? 0-1: 1-0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
    void reconstructClass(Class cls) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
        if (verbose > 1)  Utils.log.fine("reconstruct "+cls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
        // check for local .ClassFile.version
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
        Attribute retroVersion = cls.getAttribute(attrClassFileVersion);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
        if (retroVersion != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
            cls.removeAttribute(retroVersion);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
            short[] minmajver = parseClassFileVersionAttr(retroVersion);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
            cls.minver = minmajver[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
            cls.majver = minmajver[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
            cls.minver = pkg.default_class_minver;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
            cls.majver = pkg.default_class_majver;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
        // Replace null SourceFile by "obvious" string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
        cls.expandSourceFile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
        // record the local cp:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
        cls.setCPMap(reconstructLocalCPMap(cls));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
    Entry[] reconstructLocalCPMap(Class cls) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
        HashSet ldcRefs = (HashSet) ldcRefMap.get(cls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
        HashSet cpRefs = new HashSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
        HashSet sigSet = new HashSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
        // look for constant pool entries:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
        cls.visitRefs(VRM_CLASSIC, cpRefs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
        // flesh out the local constant pool
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
        ConstantPool.completeReferencesIn(cpRefs, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
        // Now that we know all our local class references,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
        // compute the InnerClasses attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
        int changed = cls.expandLocalICs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
        if (changed != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
            if (changed > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
                // Just visit the expanded InnerClasses attr.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
                cls.visitInnerClassRefs(VRM_CLASSIC, cpRefs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
                // Have to recompute from scratch, because of deletions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
                cpRefs.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
                cls.visitRefs(VRM_CLASSIC, cpRefs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
            // flesh out the local constant pool, again
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
            ConstantPool.completeReferencesIn(cpRefs, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
        // construct a local constant pool
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
        int numDoubles = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
        for (Iterator i = cpRefs.iterator(); i.hasNext(); ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
            Entry e = (Entry) i.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
            if (e.isDoubleWord())  numDoubles++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
            assert(e.tag != CONSTANT_Signature) : (e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
        Entry[] cpMap = new Entry[1+numDoubles+cpRefs.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
        int fillp = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
        // Add all ldc operands first.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
        if (ldcRefs != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
            assert(cpRefs.containsAll(ldcRefs));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
            for (Iterator i = ldcRefs.iterator(); i.hasNext(); ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
                Entry e = (Entry) i.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
                cpMap[fillp++] = e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
            assert(fillp == 1+ldcRefs.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
            cpRefs.removeAll(ldcRefs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
            ldcRefs = null;  // done with it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
        // Next add all the two-byte references.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
        HashSet wideRefs = cpRefs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
        cpRefs = null;  // do not use!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
        int narrowLimit = fillp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
        for (Iterator i = wideRefs.iterator(); i.hasNext(); ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
            Entry e = (Entry) i.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
            cpMap[fillp++] = e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
        assert(fillp == narrowLimit+wideRefs.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
        Arrays.sort(cpMap, 1, narrowLimit, entryOutputOrder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
        Arrays.sort(cpMap, narrowLimit, fillp, entryOutputOrder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
        if (verbose > 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
            Utils.log.fine("CP of "+this+" {");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
            for (int i = 0; i < fillp; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
                Entry e = cpMap[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
                Utils.log.fine("  "+((e==null)?-1:getOutputIndex(e))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
                                   +" : "+e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
            Utils.log.fine("}");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
        // Now repack backwards, introducing null elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
        int revp = cpMap.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
        for (int i = fillp; --i >= 1; ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
            Entry e = cpMap[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
            if (e.isDoubleWord())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
                cpMap[--revp] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
            cpMap[--revp] = e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
        assert(revp == 1);  // do not process the initial null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
        return cpMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
    void readMembers(Class[] classes) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
        //  class_bands:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
        //        ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
        //        *class_field_count :DELTA5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
        //        *class_method_count :DELTA5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
        //        *field_descr :DELTA5  (cp_Descr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
        //        field_attr_bands
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
        //        *method_descr :MDELTA5  (cp_Descr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
        //        method_attr_bands
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
        //        ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
        assert(classes.length == numClasses);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
        class_field_count.expectLength(numClasses);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
        class_method_count.expectLength(numClasses);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
        class_field_count.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
        class_method_count.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
        // Make a pre-pass over field and method counts to size the descrs:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
        int totalNF = class_field_count.getIntTotal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
        int totalNM = class_method_count.getIntTotal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
        field_descr.expectLength(totalNF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
        method_descr.expectLength(totalNM);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
        if (verbose > 1)  Utils.log.fine("expecting #fields="+totalNF+" and #methods="+totalNM+" in #classes="+numClasses);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
        ArrayList fields = new ArrayList(totalNF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
        field_descr.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
        for (int i = 0; i < classes.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
            Class c = classes[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
            int nf = class_field_count.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
            for (int j = 0; j < nf; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
                Class.Field f = c.new Field(NO_FLAGS_YET, (DescriptorEntry)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
                                            field_descr.getRef());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
                fields.add(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
        class_field_count.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
        field_descr.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
        countAndReadAttrs(ATTR_CONTEXT_FIELD, fields);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
        fields = null;  // release to GC
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
        ArrayList methods = new ArrayList(totalNM);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
        method_descr.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
        for (int i = 0; i < classes.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
            Class c = classes[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
            int nm = class_method_count.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
            for (int j = 0; j < nm; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
                Class.Method m = c.new Method(NO_FLAGS_YET, (DescriptorEntry)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
                                              method_descr.getRef());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
                methods.add(m);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
        class_method_count.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
        method_descr.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
        countAndReadAttrs(ATTR_CONTEXT_METHOD, methods);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
        // Up to this point, Code attributes look like empty attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
        // Now we start to special-case them.  The empty canonical Code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
        // attributes stay in the method attribute lists, however.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
        allCodes = buildCodeAttrs(methods);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
    Code[] allCodes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
    List codesWithFlags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
    HashMap ldcRefMap = new HashMap();  // HashMap<Class, HashSet<Entry>>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
    Code[] buildCodeAttrs(List methods) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
        ArrayList codes = new ArrayList(methods.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
        for (Iterator i = methods.iterator(); i.hasNext(); ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
            Class.Method m = (Class.Method) i.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
            if (m.getAttribute(attrCodeEmpty) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
                m.code = new Code(m);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
                codes.add(m.code);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
        Code[] a = new Code[codes.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
        codes.toArray(a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
        return a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
    void readCodeHeaders() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
        //  code_bands:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
        //        *code_headers :BYTE1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
        //        *code_max_stack :UNSIGNED5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
        //        *code_max_na_locals :UNSIGNED5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
        //        *code_handler_count :UNSIGNED5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
        //        ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
        //        code_attr_bands
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
        boolean attrsOK = testBit(archiveOptions, AO_HAVE_ALL_CODE_FLAGS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
        code_headers.expectLength(allCodes.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
        code_headers.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
        ArrayList longCodes = new ArrayList(allCodes.length / 10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
        for (int i = 0; i < allCodes.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
            Code c = allCodes[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
            int sc = code_headers.getByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
            assert(sc == (sc & 0xFF));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
            if (verbose > 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
                Utils.log.fine("codeHeader "+c+" = "+sc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
            if (sc == LONG_CODE_HEADER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
                // We will read ms/ml/nh/flags from bands shortly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
                longCodes.add(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
            // Short code header is the usual case:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
            c.setMaxStack(     shortCodeHeader_max_stack(sc) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
            c.setMaxNALocals(  shortCodeHeader_max_na_locals(sc) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
            c.setHandlerCount( shortCodeHeader_handler_count(sc) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
            assert(shortCodeHeader(c) == sc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
        code_headers.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
        code_max_stack.expectLength(longCodes.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
        code_max_na_locals.expectLength(longCodes.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
        code_handler_count.expectLength(longCodes.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
        // Do the long headers now.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
        code_max_stack.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
        code_max_na_locals.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
        code_handler_count.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
        for (Iterator i = longCodes.iterator(); i.hasNext(); ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
            Code c = (Code) i.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
            c.setMaxStack(     code_max_stack.getInt() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
            c.setMaxNALocals(  code_max_na_locals.getInt() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
            c.setHandlerCount( code_handler_count.getInt() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
        code_max_stack.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
        code_max_na_locals.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
        code_handler_count.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
        readCodeHandlers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
        if (attrsOK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
            // Code attributes are common (debug info not stripped).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
            codesWithFlags = Arrays.asList(allCodes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
            // Code attributes are very sparse (debug info is stripped).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
            codesWithFlags = longCodes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
        countAttrs(ATTR_CONTEXT_CODE, codesWithFlags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
        // do readAttrs later, after BCs are scanned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
    void readCodeHandlers() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
        //  code_bands:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
        //        ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
        //        *code_handler_start_P :BCI5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
        //        *code_handler_end_PO :BRANCH5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
        //        *code_handler_catch_PO :BRANCH5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
        //        *code_handler_class_RCN :UNSIGNED5  (null or cp_Class)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
        //        ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
        int nh = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
        for (int i = 0; i < allCodes.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
            Code c = allCodes[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
            nh += c.getHandlerCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
        ValueBand[] code_handler_bands = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
            code_handler_start_P,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
            code_handler_end_PO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
            code_handler_catch_PO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
            code_handler_class_RCN
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
        for (int i = 0; i < code_handler_bands.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
            code_handler_bands[i].expectLength(nh);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
            code_handler_bands[i].readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
        for (int i = 0; i < allCodes.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
            Code c = allCodes[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
            for (int j = 0, jmax = c.getHandlerCount(); j < jmax; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
                c.handler_class[j] = code_handler_class_RCN.getRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
                // For now, just record the raw BCI codes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
                // We must wait until we have instruction boundaries.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
                c.handler_start[j] = code_handler_start_P.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
                c.handler_end[j]   = code_handler_end_PO.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
                c.handler_catch[j] = code_handler_catch_PO.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
        for (int i = 0; i < code_handler_bands.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
            code_handler_bands[i].doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
    void fixupCodeHandlers() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
        // Actually decode (renumber) the BCIs now.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
        for (int i = 0; i < allCodes.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
            Code c = allCodes[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
            for (int j = 0, jmax = c.getHandlerCount(); j < jmax; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
                int sum = c.handler_start[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
                c.handler_start[j] = c.decodeBCI(sum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
                sum += c.handler_end[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
                c.handler_end[j]   = c.decodeBCI(sum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
                sum += c.handler_catch[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
                c.handler_catch[j] = c.decodeBCI(sum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
    // Generic routines for reading attributes of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
    // classes, fields, methods, and codes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
    // The holders is a global list, already collected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
    // of attribute "customers".
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
    void countAndReadAttrs(int ctype, Collection holders) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
        //  class_attr_bands:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
        //        *class_flags :UNSIGNED5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
        //        *class_attr_count :UNSIGNED5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
        //        *class_attr_indexes :UNSIGNED5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
        //        *class_attr_calls :UNSIGNED5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
        //        *class_Signature_RS :UNSIGNED5 (cp_Signature)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
        //        class_metadata_bands
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
        //        *class_SourceFile_RU :UNSIGNED5 (cp_Utf8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
        //        *class_EnclosingMethod_RM :UNSIGNED5 (cp_Method)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
        //        ic_local_bands
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
        //        *class_ClassFile_version_minor_H :UNSIGNED5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
        //        *class_ClassFile_version_major_H :UNSIGNED5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
        //  field_attr_bands:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
        //        *field_flags :UNSIGNED5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
        //        *field_attr_count :UNSIGNED5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
        //        *field_attr_indexes :UNSIGNED5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
        //        *field_attr_calls :UNSIGNED5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
        //        *field_Signature_RS :UNSIGNED5 (cp_Signature)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
        //        field_metadata_bands
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
        //        *field_ConstantValue_KQ :UNSIGNED5 (cp_Int, etc.; see note)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
        //  method_attr_bands:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
        //        *method_flags :UNSIGNED5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
        //        *method_attr_count :UNSIGNED5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
        //        *method_attr_indexes :UNSIGNED5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
        //        *method_attr_calls :UNSIGNED5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
        //        *method_Signature_RS :UNSIGNED5 (cp_Signature)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
        //        method_metadata_bands
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
        //        *method_Exceptions_N :UNSIGNED5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
        //        *method_Exceptions_RC :UNSIGNED5  (cp_Class)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
        //  code_attr_bands:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
        //        *code_flags :UNSIGNED5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
        //        *code_attr_count :UNSIGNED5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
        //        *code_attr_indexes :UNSIGNED5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
        //        *code_attr_calls :UNSIGNED5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
        //        *code_LineNumberTable_N :UNSIGNED5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
        //        *code_LineNumberTable_bci_P :BCI5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
        //        *code_LineNumberTable_line :UNSIGNED5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
        //        *code_LocalVariableTable_N :UNSIGNED5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
        //        *code_LocalVariableTable_bci_P :BCI5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
        //        *code_LocalVariableTable_span_O :BRANCH5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
        //        *code_LocalVariableTable_name_RU :UNSIGNED5 (cp_Utf8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
        //        *code_LocalVariableTable_type_RS :UNSIGNED5 (cp_Signature)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
        //        *code_LocalVariableTable_slot :UNSIGNED5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
        countAttrs(ctype, holders);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
        readAttrs(ctype, holders);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
    // Read flags and count the attributes that are to be placed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
    // on the given holders.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
    void countAttrs(int ctype, Collection holders) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
        // Here, xxx stands for one of class, field, method, code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
        MultiBand xxx_attr_bands = attrBands[ctype];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
        long flagMask = attrFlagMask[ctype];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
        if (verbose > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
            Utils.log.fine("scanning flags and attrs for "+Attribute.contextName(ctype)+"["+holders.size()+"]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
        // Fetch the attribute layout definitions which govern the bands
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
        // we are about to read.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
        Attribute.Layout[] defs = new Attribute.Layout[attrDefs[ctype].size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
        attrDefs[ctype].toArray(defs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
        IntBand xxx_flags_hi = getAttrBand(xxx_attr_bands, AB_FLAGS_HI);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
        IntBand xxx_flags_lo = getAttrBand(xxx_attr_bands, AB_FLAGS_LO);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
        IntBand xxx_attr_count = getAttrBand(xxx_attr_bands, AB_ATTR_COUNT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
        IntBand xxx_attr_indexes = getAttrBand(xxx_attr_bands, AB_ATTR_INDEXES);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
        IntBand xxx_attr_calls = getAttrBand(xxx_attr_bands, AB_ATTR_CALLS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
        // Count up the number of holders which have overflow attrs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
        int overflowMask = attrOverflowMask[ctype];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
        int overflowHolderCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
        boolean haveLongFlags = haveFlagsHi(ctype);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
        xxx_flags_hi.expectLength(haveLongFlags? holders.size(): 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
        xxx_flags_hi.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
        xxx_flags_lo.expectLength(holders.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
        xxx_flags_lo.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
        assert((flagMask & overflowMask) == overflowMask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
        for (Iterator i = holders.iterator(); i.hasNext(); ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
            Attribute.Holder h = (Attribute.Holder) i.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
            int flags = xxx_flags_lo.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
            h.flags = flags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
            if ((flags & overflowMask) != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
                overflowHolderCount += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
        // For each holder with overflow attrs, read a count.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
        xxx_attr_count.expectLength(overflowHolderCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
        xxx_attr_count.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
        xxx_attr_indexes.expectLength(xxx_attr_count.getIntTotal());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
        xxx_attr_indexes.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
        // Now it's time to check flag bits that indicate attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
        // We accumulate (a) a list of attribute types for each holder
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
        // (class/field/method/code), and also we accumulate (b) a total
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
        // count for each attribute type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
        int[] totalCounts = new int[defs.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
        for (Iterator i = holders.iterator(); i.hasNext(); ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
            Attribute.Holder h = (Attribute.Holder) i.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
            assert(h.attributes == null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
            // System.out.println("flags="+h.flags+" using fm="+flagMask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
            long attrBits = ((h.flags & flagMask) << 32) >>> 32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
            // Clean up the flags now.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
            h.flags -= (int)attrBits;   // strip attr bits
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
            assert(h.flags == (char)h.flags);  // 16 bits only now
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
            assert((ctype != ATTR_CONTEXT_CODE) || h.flags == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
            if (haveLongFlags)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
                attrBits += (long)xxx_flags_hi.getInt() << 32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
            if (attrBits == 0)  continue;  // no attrs on this guy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
            int noa = 0;  // number of overflow attrs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
            long overflowBit = (attrBits & overflowMask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
            assert(overflowBit >= 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
            attrBits -= overflowBit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
            if (overflowBit != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
                noa = xxx_attr_count.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
            int nfa = 0;  // number of flag attrs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
            long bits = attrBits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
            for (int ai = 0; bits != 0; ai++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
                if ((bits & (1L<<ai)) == 0)  continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
                bits -= (1L<<ai);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
                nfa += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
            ArrayList ha = new ArrayList(nfa + noa);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
            h.attributes = ha;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
            bits = attrBits;  // iterate again
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
            for (int ai = 0; bits != 0; ai++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
                if ((bits & (1L<<ai)) == 0)  continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
                bits -= (1L<<ai);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
                totalCounts[ai] += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
                // This definition index is live in this holder.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
                if (defs[ai] == null)  badAttrIndex(ai, ctype);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
                Attribute canonical = defs[ai].canonicalInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
                ha.add(canonical);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
                nfa -= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
            assert(nfa == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
            for (; noa > 0; noa--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
                int ai = xxx_attr_indexes.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
                totalCounts[ai] += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
                // This definition index is live in this holder.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
                if (defs[ai] == null)  badAttrIndex(ai, ctype);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
                Attribute canonical = defs[ai].canonicalInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
                ha.add(canonical);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
        xxx_flags_hi.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
        xxx_flags_lo.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
        xxx_attr_count.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
        xxx_attr_indexes.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
        // Now each holder has a list of canonical attribute instances.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
        // For layouts with no elements, we are done.  However, for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
        // layouts with bands, we must replace each canonical (empty)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
        // instance with a value-bearing one, initialized from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
        // appropriate bands.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
        // Make a small pass to detect and read backward call counts.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
        int callCounts = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
        for (boolean predef = true; ; predef = false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
            for (int ai = 0; ai < defs.length; ai++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
                Attribute.Layout def = defs[ai];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
                if (def == null)  continue;  // unused index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
                if (predef != isPredefinedAttr(ctype, ai))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
                    continue;  // wrong pass
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
                int totalCount = totalCounts[ai];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
                if (totalCount == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
                    continue;  // irrelevant
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
                Attribute.Layout.Element[] cbles = def.getCallables();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
                for (int j = 0; j < cbles.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
                    assert(cbles[j].kind == Attribute.EK_CBLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
                    if (cbles[j].flagTest(Attribute.EF_BACK))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
                        callCounts += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
            if (!predef)  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
        xxx_attr_calls.expectLength(callCounts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
        xxx_attr_calls.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
        // Finally, size all the attribute bands.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
        for (boolean predef = true; ; predef = false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
            for (int ai = 0; ai < defs.length; ai++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
                Attribute.Layout def = defs[ai];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
                if (def == null)  continue;  // unused index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
                if (predef != isPredefinedAttr(ctype, ai))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
                    continue;  // wrong pass
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
                int totalCount = totalCounts[ai];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
                Band[] ab = (Band[]) attrBandTable.get(def);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
                if (def == attrInnerClassesEmpty) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
                    // Special case.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
                    // Size the bands as if using the following layout:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
                    //    [RCH TI[ (0)[] ()[RCNH RUNH] ]].
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
                    class_InnerClasses_N.expectLength(totalCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
                    class_InnerClasses_N.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
                    int tupleCount = class_InnerClasses_N.getIntTotal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
                    class_InnerClasses_RC.expectLength(tupleCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
                    class_InnerClasses_RC.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
                    class_InnerClasses_F.expectLength(tupleCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
                    class_InnerClasses_F.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
                    // Drop remaining columns wherever flags are zero:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
                    tupleCount -= class_InnerClasses_F.getIntCount(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
                    class_InnerClasses_outer_RCN.expectLength(tupleCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
                    class_InnerClasses_outer_RCN.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
                    class_InnerClasses_name_RUN.expectLength(tupleCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
                    class_InnerClasses_name_RUN.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
                } else if (totalCount == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
                    // Expect no elements at all.  Skip quickly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
                    for (int j = 0; j < ab.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
                        ab[j].doneWithUnusedBand();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
                    // Read these bands in sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
                    boolean hasCallables = def.hasCallables();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
                    if (!hasCallables) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
                        readAttrBands(def.elems, totalCount, new int[0], ab);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
                        Attribute.Layout.Element[] cbles = def.getCallables();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
                        // At first, record initial calls.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
                        // Later, forward calls may also accumulate here:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
                        int[] forwardCounts = new int[cbles.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
                        forwardCounts[0] = totalCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
                        for (int j = 0; j < cbles.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
                            assert(cbles[j].kind == Attribute.EK_CBLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
                            int entryCount = forwardCounts[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
                            forwardCounts[j] = -1;  // No more, please!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
                            if (cbles[j].flagTest(Attribute.EF_BACK))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
                                entryCount += xxx_attr_calls.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
                            readAttrBands(cbles[j].body, entryCount, forwardCounts, ab);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
            if (!predef)  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
        xxx_attr_calls.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
    void badAttrIndex(int ai, int ctype) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
        throw new IOException("Unknown attribute index "+ai+" for "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
                                   ATTR_CONTEXT_NAME[ctype]+" attribute");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
    void readAttrs(int ctype, Collection holders) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
        // Decode band values into attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
        HashSet sawDefs = new HashSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
        ByteArrayOutputStream buf = new ByteArrayOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
        for (Iterator i = holders.iterator(); i.hasNext(); ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
            final Attribute.Holder h = (Attribute.Holder) i.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
            if (h.attributes == null)  continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
            for (ListIterator j = h.attributes.listIterator(); j.hasNext(); ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
                Attribute a = (Attribute) j.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
                Attribute.Layout def = a.layout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
                if (def.bandCount == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
                    if (def == attrInnerClassesEmpty) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
                        // Special logic to read this attr.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
                        readLocalInnerClasses((Class) h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
                    // Canonical empty attr works fine (e.g., Synthetic).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
                sawDefs.add(def);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
                boolean isCV = (ctype == ATTR_CONTEXT_FIELD && def == attrConstantValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
                if (isCV)  setConstantValueIndex((Class.Field)h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
                if (verbose > 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
                    Utils.log.fine("read "+a+" in "+h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
                final Band[] ab = (Band[]) attrBandTable.get(def);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
                // Read one attribute of type def from ab into a byte array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
                buf.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
                Object fixups = a.unparse(new Attribute.ValueStream() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
                    public int getInt(int bandIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
                        return ((IntBand) ab[bandIndex]).getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
                    public Entry getRef(int bandIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
                        return ((CPRefBand) ab[bandIndex]).getRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
                    public int decodeBCI(int bciCode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
                        Code code = (Code) h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
                        return code.decodeBCI(bciCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
                }, buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
                // Replace the canonical attr with the one just read.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
                j.set(a.addContent(buf.toByteArray(), fixups));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
                if (isCV)  setConstantValueIndex(null);  // clean up
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
        // Mark the bands we just used as done disbursing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
        for (Iterator i = sawDefs.iterator(); i.hasNext(); ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
            Attribute.Layout def = (Attribute.Layout) i.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
            if (def == null)  continue;  // unused index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
            Band[] ab = (Band[]) attrBandTable.get(def);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
            for (int j = 0; j < ab.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
                ab[j].doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
        if (ctype == ATTR_CONTEXT_CLASS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
            class_InnerClasses_N.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
            class_InnerClasses_RC.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
            class_InnerClasses_F.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
            class_InnerClasses_outer_RCN.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
            class_InnerClasses_name_RUN.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
        MultiBand xxx_attr_bands = attrBands[ctype];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
        for (int i = 0; i < xxx_attr_bands.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
            Band b = xxx_attr_bands.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
            if (b instanceof MultiBand)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
                b.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
        xxx_attr_bands.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
    private
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
    void readAttrBands(Attribute.Layout.Element[] elems,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
                       int count, int[] forwardCounts,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
                       Band[] ab)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
            throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
        for (int i = 0; i < elems.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
            Attribute.Layout.Element e = elems[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
            Band eBand = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
            if (e.hasBand()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
                eBand = ab[e.bandIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
                eBand.expectLength(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
                eBand.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
            switch (e.kind) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
            case Attribute.EK_REPL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
                // Recursive call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
                int repCount = ((IntBand)eBand).getIntTotal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
                // Note:  getIntTotal makes an extra pass over this band.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
                readAttrBands(e.body, repCount, forwardCounts, ab);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
            case Attribute.EK_UN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
                int remainingCount = count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
                for (int j = 0; j < e.body.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
                    int caseCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
                    if (j == e.body.length-1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
                        caseCount = remainingCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
                        caseCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
                        for (int j0 = j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
                             (j == j0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
                             || (j < e.body.length
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
                                 && e.body[j].flagTest(Attribute.EF_BACK));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
                             j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
                            caseCount += ((IntBand)eBand).getIntCount(e.body[j].value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
                        --j;  // back up to last occurrence of this body
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
                    remainingCount -= caseCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
                    readAttrBands(e.body[j].body, caseCount, forwardCounts, ab);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
                assert(remainingCount == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
            case Attribute.EK_CALL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
                assert(e.body.length == 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
                assert(e.body[0].kind == Attribute.EK_CBLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
                if (!e.flagTest(Attribute.EF_BACK)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
                    // Backward calls are pre-counted, but forwards are not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
                    // Push the present count forward.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
                    assert(forwardCounts[e.value] >= 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
                    forwardCounts[e.value] += count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
            case Attribute.EK_CBLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
                assert(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
    void readByteCodes() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
        //  bc_bands:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
        //        *bc_codes :BYTE1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
        //        *bc_case_count :UNSIGNED5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
        //        *bc_case_value :DELTA5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
        //        *bc_byte :BYTE1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
        //        *bc_short :DELTA5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
        //        *bc_local :UNSIGNED5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
        //        *bc_label :BRANCH5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
        //        *bc_intref :DELTA5  (cp_Int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
        //        *bc_floatref :DELTA5  (cp_Float)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
        //        *bc_longref :DELTA5  (cp_Long)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
        //        *bc_doubleref :DELTA5  (cp_Double)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
        //        *bc_stringref :DELTA5  (cp_String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
        //        *bc_classref :UNSIGNED5  (current class or cp_Class)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
        //        *bc_fieldref :DELTA5  (cp_Field)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
        //        *bc_methodref :UNSIGNED5  (cp_Method)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
        //        *bc_imethodref :DELTA5  (cp_Imethod)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
        //        *bc_thisfield :UNSIGNED5 (cp_Field, only for current class)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
        //        *bc_superfield :UNSIGNED5 (cp_Field, only for current super)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
        //        *bc_thismethod :UNSIGNED5 (cp_Method, only for current class)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
        //        *bc_supermethod :UNSIGNED5 (cp_Method, only for current super)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
        //        *bc_initref :UNSIGNED5 (cp_Field, only for most recent new)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
        //        *bc_escref :UNSIGNED5 (cp_All)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
        //        *bc_escrefsize :UNSIGNED5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
        //        *bc_escsize :UNSIGNED5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
        //        *bc_escbyte :BYTE1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
        bc_codes.elementCountForDebug = allCodes.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
        bc_codes.setInputStreamFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
        readByteCodeOps();  // reads from bc_codes and bc_case_count
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
        bc_codes.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
        // All the operand bands have now been sized.  Read them all in turn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
        Band[] operand_bands = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
            bc_case_value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
            bc_byte, bc_short,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
            bc_local, bc_label,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
            bc_intref, bc_floatref,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
            bc_longref, bc_doubleref, bc_stringref,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
            bc_classref, bc_fieldref,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
            bc_methodref, bc_imethodref,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
            bc_thisfield, bc_superfield,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
            bc_thismethod, bc_supermethod,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
            bc_initref,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
            bc_escref, bc_escrefsize, bc_escsize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
        for (int i = 0; i < operand_bands.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
            operand_bands[i].readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
        bc_escbyte.expectLength(bc_escsize.getIntTotal());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
        bc_escbyte.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
        expandByteCodeOps();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
        // Done fetching values from operand bands:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
        bc_case_count.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
        for (int i = 0; i < operand_bands.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
            operand_bands[i].doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
        bc_escbyte.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
        bc_bands.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
        // We must delay the parsing of Code attributes until we
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
        // have a complete model of bytecodes, for BCI encodings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
        readAttrs(ATTR_CONTEXT_CODE, codesWithFlags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
        // Ditto for exception handlers in codes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
        fixupCodeHandlers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
        // Now we can finish with class_bands; cf. readClasses().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
        code_bands.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
        class_bands.doneDisbursing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
    private void readByteCodeOps() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
        // scratch buffer for collecting code::
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
        byte[] buf = new byte[1<<12];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
        // record of all switch opcodes (these are variable-length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
        ArrayList allSwitchOps = new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
        for (int k = 0; k < allCodes.length; k++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
            Code c = allCodes[k];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
        scanOneMethod:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
            for (int i = 0; ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
                int bc = bc_codes.getByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
                if (i + 10 > buf.length)  buf = realloc(buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
                buf[i] = (byte)bc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
                boolean isWide = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
                if (bc == _wide) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
                    bc = bc_codes.getByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
                    buf[++i] = (byte)bc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
                    isWide = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
                assert(bc == (0xFF & bc));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
                // Adjust expectations of various band sizes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
                switch (bc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
                case _tableswitch:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
                case _lookupswitch:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
                    bc_case_count.expectMoreLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
                    allSwitchOps.add(new Integer(bc));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
                case _iinc:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
                    bc_local.expectMoreLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
                    if (isWide)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
                        bc_short.expectMoreLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
                    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
                        bc_byte.expectMoreLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
                case _sipush:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
                    bc_short.expectMoreLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
                case _bipush:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
                    bc_byte.expectMoreLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
                case _newarray:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
                    bc_byte.expectMoreLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
                case _multianewarray:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
                    assert(getCPRefOpBand(bc) == bc_classref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
                    bc_classref.expectMoreLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
                    bc_byte.expectMoreLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
                case _ref_escape:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
                    bc_escrefsize.expectMoreLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
                    bc_escref.expectMoreLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
                case _byte_escape:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
                    bc_escsize.expectMoreLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
                    // bc_escbyte will have to be counted too
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
                    if (Instruction.isInvokeInitOp(bc)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
                        bc_initref.expectMoreLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
                    if (Instruction.isSelfLinkerOp(bc)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
                        CPRefBand bc_which = selfOpRefBand(bc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
                        bc_which.expectMoreLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
                    if (Instruction.isBranchOp(bc)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
                        bc_label.expectMoreLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
                    if (Instruction.isCPRefOp(bc)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
                        CPRefBand bc_which = getCPRefOpBand(bc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
                        bc_which.expectMoreLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
                        assert(bc != _multianewarray);  // handled elsewhere
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
                    if (Instruction.isLocalSlotOp(bc)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
                        bc_local.expectMoreLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
                case _end_marker:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
                    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
                        // Transfer from buf to a more permanent place:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
                        c.bytes = realloc(buf, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
                        break scanOneMethod;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
        // To size instruction bands correctly, we need info on switches:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
        bc_case_count.readFrom(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
        for (Iterator i = allSwitchOps.iterator(); i.hasNext(); ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
            int bc = ((Integer)i.next()).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
            int caseCount = bc_case_count.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
            bc_label.expectMoreLength(1+caseCount); // default label + cases
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
            bc_case_value.expectMoreLength(bc == _tableswitch ? 1 : caseCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
        bc_case_count.resetForSecondPass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
    private void expandByteCodeOps() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
        // scratch buffer for collecting code:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
        byte[] buf = new byte[1<<12];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
        // scratch buffer for collecting instruction boundaries:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
        int[] insnMap = new int[1<<12];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
        // list of label carriers, for label decoding post-pass:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
        int[] labels = new int[1<<10];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
        // scratch buffer for registering CP refs:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
        Fixups fixupBuf = new Fixups();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
        for (int k = 0; k < allCodes.length; k++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
            Code code = allCodes[k];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
            byte[] codeOps = code.bytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
            code.bytes = null;  // just for now, while we accumulate bits
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
            Class curClass = code.thisClass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
            HashSet ldcRefSet = (HashSet) ldcRefMap.get(curClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
            if (ldcRefSet == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
                ldcRefMap.put(curClass, ldcRefSet = new HashSet());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
            ClassEntry thisClass  = curClass.thisClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
            ClassEntry superClass = curClass.superClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
            ClassEntry newClass   = null;  // class of last _new opcode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
            int pc = 0;  // fill pointer in buf; actual bytecode PC
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
            int numInsns = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
            int numLabels = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
            boolean hasEscs = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
            fixupBuf.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
            for (int i = 0; i < codeOps.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
                int bc = Instruction.getByte(codeOps, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
                int curPC = pc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
                insnMap[numInsns++] = curPC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
                if (pc + 10 > buf.length)  buf = realloc(buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
                if (numInsns+10 > insnMap.length)  insnMap = realloc(insnMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
                if (numLabels+10 > labels.length)  labels = realloc(labels);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
                boolean isWide = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
                if (bc == _wide) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
                    buf[pc++] = (byte) bc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
                    bc = Instruction.getByte(codeOps, ++i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
                    isWide = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
                switch (bc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
                case _tableswitch: // apc:  (df, lo, hi, (hi-lo+1)*(label))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
                case _lookupswitch: // apc:  (df, nc, nc*(case, label))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
                    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
                        int caseCount = bc_case_count.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
                        while ((pc + 30 + caseCount*8) > buf.length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
                            buf = realloc(buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
                        buf[pc++] = (byte) bc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
                        //initialize apc, df, lo, hi bytes to reasonable bits:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
                        Arrays.fill(buf, pc, pc+30, (byte)0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
                        Instruction.Switch isw = (Instruction.Switch)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
                            Instruction.at(buf, curPC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
                        //isw.setDefaultLabel(getLabel(bc_label, code, curPC));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
                        isw.setCaseCount(caseCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
                        if (bc == _tableswitch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
                            isw.setCaseValue(0, bc_case_value.getInt());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
                            for (int j = 0; j < caseCount; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
                                isw.setCaseValue(j, bc_case_value.getInt());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
                        // Make our getLabel calls later.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
                        labels[numLabels++] = curPC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
                        pc = isw.getNextPC();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
                case _iinc:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
                    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
                        buf[pc++] = (byte) bc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
                        int local = bc_local.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
                        int delta;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
                        if (isWide) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
                            delta = bc_short.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
                            Instruction.setShort(buf, pc, local); pc += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
                            Instruction.setShort(buf, pc, delta); pc += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
                            delta = (byte) bc_byte.getByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
                            buf[pc++] = (byte)local;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
                            buf[pc++] = (byte)delta;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
                case _sipush:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
                    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
                        int val = bc_short.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
                        buf[pc++] = (byte) bc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
                        Instruction.setShort(buf, pc, val); pc += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
                case _bipush:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
                case _newarray:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
                    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
                        int val = bc_byte.getByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
                        buf[pc++] = (byte) bc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
                        buf[pc++] = (byte) val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
                case _ref_escape:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
                    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
                        // Note that insnMap has one entry for this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
                        hasEscs = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
                        int size = bc_escrefsize.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
                        Entry ref = bc_escref.getRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
                        if (size == 1)  ldcRefSet.add(ref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
                        int fmt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
                        switch (size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
                        case 1: fmt = Fixups.U1_FORMAT; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
                        case 2: fmt = Fixups.U2_FORMAT; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
                        default: assert(false); fmt = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
                        fixupBuf.add(pc, fmt, ref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
                        buf[pc+0] = buf[pc+1] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
                        pc += size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
                case _byte_escape:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
                    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
                        // Note that insnMap has one entry for all these bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
                        hasEscs = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
                        int size = bc_escsize.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
                        while ((pc + size) > buf.length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
                            buf = realloc(buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
                        while (size-- > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
                            buf[pc++] = (byte) bc_escbyte.getByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
                    if (Instruction.isInvokeInitOp(bc)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
                        int idx = (bc - _invokeinit_op);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
                        int origBC = _invokespecial;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2012
                        ClassEntry classRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
                        switch (idx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
                        case _invokeinit_self_option:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
                            classRef = thisClass; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
                        case _invokeinit_super_option:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
                            classRef = superClass; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2018
                        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
                            assert(idx == _invokeinit_new_option);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
                            classRef = newClass; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
                        buf[pc++] = (byte) origBC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
                        int coding = bc_initref.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
                        // Find the nth overloading of <init> in classRef.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
                        MemberEntry ref = pkg.cp.getOverloadingForIndex(CONSTANT_Methodref, classRef, "<init>", coding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2026
                        fixupBuf.add(pc, Fixups.U2_FORMAT, ref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
                        buf[pc+0] = buf[pc+1] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2028
                        pc += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
                        assert(Instruction.opLength(origBC) == (pc - curPC));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
                    if (Instruction.isSelfLinkerOp(bc)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
                        int idx = (bc - _self_linker_op);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
                        boolean isSuper = (idx >= _self_linker_super_flag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
                        if (isSuper)  idx -= _self_linker_super_flag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2036
                        boolean isAload = (idx >= _self_linker_aload_flag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2037
                        if (isAload)  idx -= _self_linker_aload_flag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2038
                        int origBC = _first_linker_op + idx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
                        boolean isField = Instruction.isFieldOp(origBC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
                        CPRefBand bc_which;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
                        ClassEntry which_cls  = isSuper ? superClass : thisClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
                        Index which_ix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2043
                        if (isField) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
                            bc_which = isSuper ? bc_superfield  : bc_thisfield;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2045
                            which_ix = pkg.cp.getMemberIndex(CONSTANT_Fieldref, which_cls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2046
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2047
                            bc_which = isSuper ? bc_supermethod : bc_thismethod;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
                            which_ix = pkg.cp.getMemberIndex(CONSTANT_Methodref, which_cls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
                        assert(bc_which == selfOpRefBand(bc));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2051
                        MemberEntry ref = (MemberEntry) bc_which.getRef(which_ix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2052
                        if (isAload) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2053
                            buf[pc++] = (byte) _aload_0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2054
                            curPC = pc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
                            // Note: insnMap keeps the _aload_0 separate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2056
                            insnMap[numInsns++] = curPC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2057
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2058
                        buf[pc++] = (byte) origBC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2059
                        fixupBuf.add(pc, Fixups.U2_FORMAT, ref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2060
                        buf[pc+0] = buf[pc+1] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2061
                        pc += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2062
                        assert(Instruction.opLength(origBC) == (pc - curPC));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2063
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2064
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
                    if (Instruction.isBranchOp(bc)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2066
                        buf[pc++] = (byte) bc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2067
                        assert(!isWide);  // no wide prefix for branches
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2068
                        int nextPC = curPC + Instruction.opLength(bc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2069
                        // Make our getLabel calls later.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2070
                        labels[numLabels++] = curPC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
                        //Instruction.at(buf, curPC).setBranchLabel(getLabel(bc_label, code, curPC));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
                        while (pc < nextPC)  buf[pc++] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2074
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2075
                    if (Instruction.isCPRefOp(bc)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2076
                        CPRefBand bc_which = getCPRefOpBand(bc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2077
                        Entry ref = bc_which.getRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
                        if (ref == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2079
                            if (bc_which == bc_classref) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2080
                                // Shorthand for class self-references.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2081
                                ref = thisClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
                            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
                                assert(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2084
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2085
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2086
                        int origBC = bc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
                        int size = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
                        switch (bc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
                        case _ildc:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
                        case _cldc:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2091
                        case _fldc:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2092
                        case _aldc:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2093
                            origBC = _ldc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
                            size = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
                            ldcRefSet.add(ref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
                        case _ildc_w:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
                        case _cldc_w:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2099
                        case _fldc_w:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2100
                        case _aldc_w:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2101
                            origBC = _ldc_w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2102
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2103
                        case _lldc2_w:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2104
                        case _dldc2_w:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2105
                            origBC = _ldc2_w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2106
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2107
                        case _new:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2108
                            newClass = (ClassEntry) ref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2109
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2111
                        buf[pc++] = (byte) origBC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2112
                        int fmt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2113
                        switch (size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2114
                        case 1: fmt = Fixups.U1_FORMAT; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2115
                        case 2: fmt = Fixups.U2_FORMAT; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2116
                        default: assert(false); fmt = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2117
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2118
                        fixupBuf.add(pc, fmt, ref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2119
                        buf[pc+0] = buf[pc+1] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2120
                        pc += size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2121
                        if (origBC == _multianewarray) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2122
                            // Copy the trailing byte also.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2123
                            int val = bc_byte.getByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
                            buf[pc++] = (byte) val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2125
                        } else if (origBC == _invokeinterface) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2126
                            int argSize = ((MemberEntry)ref).descRef.typeRef.computeSize(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2127
                            buf[pc++] = (byte)( 1 + argSize );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2128
                            buf[pc++] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2129
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2130
                        assert(Instruction.opLength(origBC) == (pc - curPC));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2131
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2132
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2133
                    if (Instruction.isLocalSlotOp(bc)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2134
                        buf[pc++] = (byte) bc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2135
                        int local = bc_local.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2136
                        if (isWide) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2137
                            Instruction.setShort(buf, pc, local);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2138
                            pc += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2139
                            if (bc == _iinc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2140
                                int iVal = bc_short.getInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2141
                                Instruction.setShort(buf, pc, iVal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2142
                                pc += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2143
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2144
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2145
                            Instruction.setByte(buf, pc, local);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2146
                            pc += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2147
                            if (bc == _iinc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2148
                                int iVal = bc_byte.getByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2149
                                Instruction.setByte(buf, pc, iVal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2150
                                pc += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2151
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2153
                        assert(Instruction.opLength(bc) == (pc - curPC));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2154
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2155
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2156
                    // Random bytecode.  Just copy it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2157
                    if (bc >= _bytecode_limit)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2158
                        Utils.log.warning("unrecognized bytescode "+bc
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2159
                                            +" "+Instruction.byteName(bc));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2160
                    assert(bc < _bytecode_limit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2161
                    buf[pc++] = (byte) bc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2162
                    assert(Instruction.opLength(bc) == (pc - curPC));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2163
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2164
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2165
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2166
            // now make a permanent copy of the bytecodes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2167
            code.setBytes(realloc(buf, pc));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2168
            code.setInstructionMap(insnMap, numInsns);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2169
            // fix up labels, now that code has its insnMap
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2170
            Instruction ibr = null;  // temporary branch instruction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2171
            for (int i = 0; i < numLabels; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2172
                int curPC = labels[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2173
                // (Note:  Passing ibr in allows reuse, a speed hack.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2174
                ibr = Instruction.at(code.bytes, curPC, ibr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2175
                if (ibr instanceof Instruction.Switch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2176
                    Instruction.Switch isw = (Instruction.Switch) ibr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2177
                    isw.setDefaultLabel(getLabel(bc_label, code, curPC));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2178
                    int caseCount = isw.getCaseCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2179
                    for (int j = 0; j < caseCount; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2180
                        isw.setCaseLabel(j, getLabel(bc_label, code, curPC));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2181
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2182
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2183
                    ibr.setBranchLabel(getLabel(bc_label, code, curPC));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2184
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2185
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2186
            if (fixupBuf.size() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2187
                if (verbose > 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2188
                    Utils.log.fine("Fixups in code: "+fixupBuf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
                code.addFixups(fixupBuf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2190
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2191
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2193
}