jdk/src/java.base/share/classes/com/sun/java/util/jar/pack/Attribute.java
author martin
Tue, 15 Sep 2015 21:56:04 -0700
changeset 32649 2ee9017c7597
parent 31471 ae27c6f1d8bf
permissions -rw-r--r--
8136583: Core libraries should use blessed modifier order Summary: Run blessed-modifier-order script (see bug) Reviewed-by: psandoz, chegar, alanb, plevart
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
15261
c5b882836677 8005252: pack200 should support MethodParameters
ksrini
parents: 12857
diff changeset
     2
 * Copyright (c) 2003, 2013, 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: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
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: 6901
diff changeset
    28
import com.sun.java.util.jar.pack.ConstantPool.Entry;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 6901
diff changeset
    29
import com.sun.java.util.jar.pack.ConstantPool.Index;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 6901
diff changeset
    30
import java.io.ByteArrayOutputStream;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 6901
diff changeset
    31
import java.io.IOException;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 6901
diff changeset
    32
import java.util.ArrayList;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 6901
diff changeset
    33
import java.util.Arrays;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 6901
diff changeset
    34
import java.util.Collection;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 6901
diff changeset
    35
import java.util.Collections;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 6901
diff changeset
    36
import java.util.HashMap;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 6901
diff changeset
    37
import java.util.List;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 6901
diff changeset
    38
import java.util.Map;
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
    39
import static com.sun.java.util.jar.pack.Constants.*;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * Represents an attribute in a class-file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * Takes care to remember where constant pool indexes occur.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * Implements the "little language" of Pack200 for describing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * attribute layouts.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * @author John Rose
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 */
10115
eb08d08c7ef7 7060849: Eliminate pack200 build warnings
ksrini
parents: 7795
diff changeset
    48
class Attribute implements Comparable<Attribute> {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    // Attribute instance fields.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    Layout def;     // the name and format of this attr
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    byte[] bytes;   // the actual bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    Object fixups;  // reference relocations, if any are required
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    public String name() { return def.name(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    public Layout layout() { return def; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    public byte[] bytes() { return bytes; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    public int size() { return bytes.length; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    public Entry getNameRef() { return def.getNameRef(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private Attribute(Attribute old) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        this.def = old.def;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        this.bytes = old.bytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        this.fixups = old.fixups;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    public Attribute(Layout def, byte[] bytes, Object fixups) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        this.def = def;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        this.bytes = bytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        this.fixups = fixups;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        Fixups.setBytes(fixups, bytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    public Attribute(Layout def, byte[] bytes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        this(def, bytes, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    public Attribute addContent(byte[] bytes, Object fixups) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        assert(isCanonical());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        if (bytes.length == 0 && fixups == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        Attribute res = new Attribute(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        res.bytes = bytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        res.fixups = fixups;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        Fixups.setBytes(fixups, bytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    public Attribute addContent(byte[] bytes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        return addContent(bytes, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    public void finishRefs(Index ix) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        if (fixups != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            Fixups.finishRefs(fixups, bytes, ix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            fixups = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    public boolean isCanonical() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        return this == def.canon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
17490
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   102
    @Override
10115
eb08d08c7ef7 7060849: Eliminate pack200 build warnings
ksrini
parents: 7795
diff changeset
   103
    public int compareTo(Attribute that) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        return this.def.compareTo(that.def);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   107
    private static final Map<List<Attribute>, List<Attribute>> canonLists = new HashMap<>();
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   108
    private static final Map<Layout, Attribute> attributes = new HashMap<>();
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   109
    private static final Map<Layout, Attribute> standardDefs = new HashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    // Canonicalized lists of trivial attrs (Deprecated, etc.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    // are used by trimToSize, in order to reduce footprint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    // of some common cases.  (Note that Code attributes are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    // always zero size.)
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   115
    public static List<Attribute> getCanonList(List<Attribute> al) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        synchronized (canonLists) {
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   117
            List<Attribute> cl = canonLists.get(al);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            if (cl == null) {
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   119
                cl = new ArrayList<>(al.size());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                cl.addAll(al);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                cl = Collections.unmodifiableList(cl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                canonLists.put(al, cl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            return cl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    // Find the canonical empty attribute with the given ctype, name, layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    public static Attribute find(int ctype, String name, String layout) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        Layout key = Layout.makeKey(ctype, name, layout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        synchronized (attributes) {
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   132
            Attribute a = attributes.get(key);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            if (a == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                a = new Layout(ctype, name, layout).canonicalInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                attributes.put(key, a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            return a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   141
    public static Layout keyForLookup(int ctype, String name) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        return Layout.makeKey(ctype, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    // Find canonical empty attribute with given ctype and name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    // and with the standard layout.
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   147
    public static Attribute lookup(Map<Layout, Attribute> defs, int ctype,
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   148
            String name) {
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   149
        if (defs == null) {
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   150
            defs = standardDefs;
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   151
        }
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   152
        return defs.get(Layout.makeKey(ctype, name));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    }
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   154
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   155
    public static Attribute define(Map<Layout, Attribute> defs, int ctype,
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   156
            String name, String layout) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        Attribute a = find(ctype, name, layout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        defs.put(Layout.makeKey(ctype, name), a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        return a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    static {
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   163
        Map<Layout, Attribute> sd = standardDefs;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        define(sd, ATTR_CONTEXT_CLASS, "Signature", "RSH");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        define(sd, ATTR_CONTEXT_CLASS, "Synthetic", "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        define(sd, ATTR_CONTEXT_CLASS, "Deprecated", "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        define(sd, ATTR_CONTEXT_CLASS, "SourceFile", "RUH");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        define(sd, ATTR_CONTEXT_CLASS, "EnclosingMethod", "RCHRDNH");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        define(sd, ATTR_CONTEXT_CLASS, "InnerClasses", "NH[RCHRCNHRUNHFH]");
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   170
        define(sd, ATTR_CONTEXT_CLASS, "BootstrapMethods", "NH[RMHNH[KLH]]");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        define(sd, ATTR_CONTEXT_FIELD, "Signature", "RSH");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        define(sd, ATTR_CONTEXT_FIELD, "Synthetic", "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        define(sd, ATTR_CONTEXT_FIELD, "Deprecated", "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        define(sd, ATTR_CONTEXT_FIELD, "ConstantValue", "KQH");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        define(sd, ATTR_CONTEXT_METHOD, "Signature", "RSH");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        define(sd, ATTR_CONTEXT_METHOD, "Synthetic", "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        define(sd, ATTR_CONTEXT_METHOD, "Deprecated", "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        define(sd, ATTR_CONTEXT_METHOD, "Exceptions", "NH[RCH]");
16013
3569e84e7429 8008262: pack200 should support MethodParameters - part 2
ksrini
parents: 15526
diff changeset
   181
        define(sd, ATTR_CONTEXT_METHOD, "MethodParameters", "NB[RUNHFH]");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        //define(sd, ATTR_CONTEXT_METHOD, "Code", "HHNI[B]NH[PHPOHPOHRCNH]NH[RUHNI[B]]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        define(sd, ATTR_CONTEXT_CODE, "StackMapTable",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
               ("[NH[(1)]]" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                "[TB" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                "(64-127)[(2)]" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                "(247)[(1)(2)]" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                "(248-251)[(1)]" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                "(252)[(1)(2)]" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                "(253)[(1)(2)(2)]" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                "(254)[(1)(2)(2)(2)]" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                "(255)[(1)NH[(2)]NH[(2)]]" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                "()[]" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                "]" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                "[H]" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                "[TB(7)[RCH](8)[PH]()[]]"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        define(sd, ATTR_CONTEXT_CODE, "LineNumberTable", "NH[PHH]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        define(sd, ATTR_CONTEXT_CODE, "LocalVariableTable", "NH[PHOHRUHRSHH]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        define(sd, ATTR_CONTEXT_CODE, "LocalVariableTypeTable", "NH[PHOHRUHRSHH]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        //define(sd, ATTR_CONTEXT_CODE, "CharacterRangeTable", "NH[PHPOHIIH]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        //define(sd, ATTR_CONTEXT_CODE, "CoverageTable", "NH[PHHII]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        // Note:  Code and InnerClasses are special-cased elsewhere.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        // Their layout specs. are given here for completeness.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        // The Code spec is incomplete, in that it does not distinguish
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        // bytecode bytes or locate CP references.
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   209
        // The BootstrapMethods attribute is also special-cased
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   210
        // elsewhere as an appendix to the local constant pool.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    // Metadata.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    // We define metadata using similar layouts
17490
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   216
    // for all five kinds of metadata attributes and 2 type metadata attributes
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    // Regular annotations are a counted list of [RSHNH[RUH(1)]][...]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    //   pack.method.attribute.RuntimeVisibleAnnotations=[NH[(1)]][RSHNH[RUH(1)]][TB...]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    // Parameter annotations are a counted list of regular annotations.
17490
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   222
    //   pack.method.attribute.RuntimeVisibleParameterAnnotations=[NB[(1)]][NH[(1)]][RSHNH[RUH(1)]][TB...]
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    // RuntimeInvisible annotations are defined similarly...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    // Non-method annotations are defined similarly...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    // Annotation are a simple tagged value [TB...]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    //   pack.attribute.method.AnnotationDefault=[TB...]
17490
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   229
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        String mdLayouts[] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            Attribute.normalizeLayoutString
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            (""
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
             +"\n  # parameter_annotations :="
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
             +"\n  [ NB[(1)] ]     # forward call to annotations"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
             ),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            Attribute.normalizeLayoutString
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            (""
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
             +"\n  # annotations :="
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
             +"\n  [ NH[(1)] ]     # forward call to annotation"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
             +"\n  "
17490
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   242
            ),
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   243
            Attribute.normalizeLayoutString
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   244
             (""
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
             +"\n  # annotation :="
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
             +"\n  [RSH"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
             +"\n    NH[RUH (1)]   # forward call to value"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
             +"\n    ]"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
             ),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            Attribute.normalizeLayoutString
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            (""
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
             +"\n  # value :="
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
             +"\n  [TB # Callable 2 encodes one tagged value."
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
             +"\n    (\\B,\\C,\\I,\\S,\\Z)[KIH]"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
             +"\n    (\\D)[KDH]"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
             +"\n    (\\F)[KFH]"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
             +"\n    (\\J)[KJH]"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
             +"\n    (\\c)[RSH]"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
             +"\n    (\\e)[RSH RUH]"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
             +"\n    (\\s)[RUH]"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
             +"\n    (\\[)[NH[(0)]] # backward self-call to value"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
             +"\n    (\\@)[RSH NH[RUH (0)]] # backward self-call to value"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
             +"\n    ()[] ]"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
             )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        };
17490
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   266
        /*
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   267
         * RuntimeVisibleTypeAnnotation and RuntimeInvisibleTypeAnnotatation are
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   268
         * similar to RuntimeVisibleAnnotation and RuntimeInvisibleAnnotation,
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   269
         * a type-annotation union  and a type-path structure precedes the
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   270
         * annotation structure
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   271
         */
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   272
        String typeLayouts[] = {
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   273
            Attribute.normalizeLayoutString
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   274
            (""
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   275
             +"\n # type-annotations :="
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   276
             +"\n  [ NH[(1)(2)(3)] ]     # forward call to type-annotations"
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   277
            ),
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   278
            Attribute.normalizeLayoutString
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   279
            ( ""
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   280
             +"\n  # type-annotation :="
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   281
             +"\n  [TB"
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   282
             +"\n    (0-1) [B] # {CLASS, METHOD}_TYPE_PARAMETER"
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   283
             +"\n    (16) [FH] # CLASS_EXTENDS"
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   284
             +"\n    (17-18) [BB] # {CLASS, METHOD}_TYPE_PARAMETER_BOUND"
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   285
             +"\n    (19-21) [] # FIELD, METHOD_RETURN, METHOD_RECEIVER"
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   286
             +"\n    (22) [B] # METHOD_FORMAL_PARAMETER"
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   287
             +"\n    (23) [H] # THROWS"
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   288
             +"\n    (64-65) [NH[PHOHH]] # LOCAL_VARIABLE, RESOURCE_VARIABLE"
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   289
             +"\n    (66) [H] # EXCEPTION_PARAMETER"
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   290
             +"\n    (67-70) [PH] # INSTANCEOF, NEW, {CONSTRUCTOR, METHOD}_REFERENCE_RECEIVER"
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   291
             +"\n    (71-75) [PHB] # CAST, {CONSTRUCTOR,METHOD}_INVOCATION_TYPE_ARGUMENT, {CONSTRUCTOR, METHOD}_REFERENCE_TYPE_ARGUMENT"
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   292
             +"\n    ()[] ]"
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   293
            ),
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   294
            Attribute.normalizeLayoutString
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   295
            (""
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   296
             +"\n # type-path"
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   297
             +"\n [ NB[BB] ]"
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   298
            )
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   299
        };
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   300
        Map<Layout, Attribute> sd = standardDefs;
17490
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   301
        String defaultLayout     = mdLayouts[3];
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   302
        String annotationsLayout = mdLayouts[1] + mdLayouts[2] + mdLayouts[3];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        String paramsLayout      = mdLayouts[0] + annotationsLayout;
17490
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   304
        String typesLayout       = typeLayouts[0] + typeLayouts[1] +
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   305
                                   typeLayouts[2] + mdLayouts[2] + mdLayouts[3];
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   306
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        for (int ctype = 0; ctype < ATTR_CONTEXT_LIMIT; ctype++) {
17490
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   308
            if (ctype != ATTR_CONTEXT_CODE) {
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   309
                define(sd, ctype,
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   310
                       "RuntimeVisibleAnnotations",   annotationsLayout);
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   311
                define(sd, ctype,
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   312
                       "RuntimeInvisibleAnnotations",  annotationsLayout);
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   313
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   314
                if (ctype == ATTR_CONTEXT_METHOD) {
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   315
                    define(sd, ctype,
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   316
                           "RuntimeVisibleParameterAnnotations",   paramsLayout);
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   317
                    define(sd, ctype,
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   318
                           "RuntimeInvisibleParameterAnnotations", paramsLayout);
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   319
                    define(sd, ctype,
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   320
                           "AnnotationDefault", defaultLayout);
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   321
                }
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   322
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            define(sd, ctype,
17490
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   324
                   "RuntimeVisibleTypeAnnotations", typesLayout);
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   325
            define(sd, ctype,
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   326
                   "RuntimeInvisibleTypeAnnotations", typesLayout);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    public static String contextName(int ctype) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        switch (ctype) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        case ATTR_CONTEXT_CLASS: return "class";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        case ATTR_CONTEXT_FIELD: return "field";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        case ATTR_CONTEXT_METHOD: return "method";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        case ATTR_CONTEXT_CODE: return "code";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    /** Base class for any attributed object (Class, Field, Method, Code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     *  Flags are included because they are used to help transmit the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     *  presence of attributes.  That is, flags are a mix of modifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     *  bits and attribute indicators.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 31471
diff changeset
   345
    public abstract static
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    class Holder {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        // We need this abstract method to interpret embedded CP refs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        protected abstract Entry[] getCPMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        protected int flags;             // defined here for convenience
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   352
        protected List<Attribute> attributes;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        public int attributeSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            return (attributes == null) ? 0 : attributes.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        public void trimToSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            if (attributes == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            }
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   362
            if (attributes.isEmpty()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                attributes = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            if (attributes instanceof ArrayList) {
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   367
                ArrayList<Attribute> al = (ArrayList<Attribute>)attributes;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                al.trimToSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                boolean allCanon = true;
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   370
                for (Attribute a : al) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                    if (!a.isCanonical()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                        allCanon = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                    if (a.fixups != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                        assert(!a.isCanonical());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                        a.fixups = Fixups.trimToSize(a.fixups);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                if (allCanon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                    // Replace private writable attribute list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                    // with only trivial entries by public unique
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                    // immutable attribute list with the same entries.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                    attributes = getCanonList(al);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        public void addAttribute(Attribute a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            if (attributes == null)
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   390
                attributes = new ArrayList<>(3);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            else if (!(attributes instanceof ArrayList))
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   392
                attributes = new ArrayList<>(attributes);  // unfreeze it
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            attributes.add(a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        public Attribute removeAttribute(Attribute a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            if (attributes == null)       return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            if (!attributes.contains(a))  return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            if (!(attributes instanceof ArrayList))
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   400
                attributes = new ArrayList<>(attributes);  // unfreeze it
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            attributes.remove(a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            return a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        public Attribute getAttribute(int n) {
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   406
            return attributes.get(n);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   409
        protected void visitRefs(int mode, Collection<Entry> refs) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            if (attributes == null)  return;
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   411
            for (Attribute a : attributes) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                a.visitRefs(this, mode, refs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   416
        static final List<Attribute> noAttributes = Arrays.asList(new Attribute[0]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   418
        public List<Attribute> getAttributes() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            if (attributes == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                return noAttributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            return attributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   424
        public void setAttributes(List<Attribute> attrList) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            if (attrList.isEmpty())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                attributes = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                attributes = attrList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        public Attribute getAttribute(String attrName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            if (attributes == null)  return null;
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   433
            for (Attribute a : attributes) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                if (a.name().equals(attrName))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                    return a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        public Attribute getAttribute(Layout attrDef) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            if (attributes == null)  return null;
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   442
            for (Attribute a : attributes) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                if (a.layout() == attrDef)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                    return a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        public Attribute removeAttribute(String attrName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            return removeAttribute(getAttribute(attrName));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        public Attribute removeAttribute(Layout attrDef) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            return removeAttribute(getAttribute(attrDef));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        public void strip(String attrName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            removeAttribute(getAttribute(attrName));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    // Lightweight interface to hide details of band structure.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    // Also used for testing.
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 31471
diff changeset
   464
    public abstract static
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    class ValueStream {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        public int getInt(int bandIndex) { throw undef(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        public void putInt(int bandIndex, int value) { throw undef(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        public Entry getRef(int bandIndex) { throw undef(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        public void putRef(int bandIndex, Entry ref) { throw undef(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        // Note:  decodeBCI goes w/ getInt/Ref; encodeBCI goes w/ putInt/Ref
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        public int decodeBCI(int bciCode) { throw undef(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        public int encodeBCI(int bci) { throw undef(); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        public void noteBackCall(int whichCallable) { /* ignore by default */ }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        private RuntimeException undef() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            return new UnsupportedOperationException("ValueStream method");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    // Element kinds:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    static final byte EK_INT  = 1;     // B H I SH etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    static final byte EK_BCI  = 2;     // PH POH etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    static final byte EK_BCO  = 3;     // OH etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    static final byte EK_FLAG = 4;     // FH etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    static final byte EK_REPL = 5;     // NH[...] etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    static final byte EK_REF  = 6;     // RUH, RUNH, KQH, etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    static final byte EK_UN   = 7;     // TB(...)[...] etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    static final byte EK_CASE = 8;     // (...)[...] etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    static final byte EK_CALL = 9;     // (0), (1), etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    static final byte EK_CBLE = 10;    // [...][...] etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    static final byte EF_SIGN  = 1<<0;   // INT is signed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    static final byte EF_DELTA = 1<<1;   // BCI/BCI value is diff'ed w/ previous
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    static final byte EF_NULL  = 1<<2;   // null REF is expected/allowed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    static final byte EF_BACK  = 1<<3;   // call, callable, case is backward
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    static final int NO_BAND_INDEX = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    /** A "class" of attributes, characterized by a context-type, name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     *  and format.  The formats are specified in a "little language".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    public static
10115
eb08d08c7ef7 7060849: Eliminate pack200 build warnings
ksrini
parents: 7795
diff changeset
   500
    class Layout implements Comparable<Layout> {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        int ctype;       // attribute context type, e.g., ATTR_CONTEXT_CODE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        String name;     // name of attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        boolean hasRefs; // this kind of attr contains CP refs?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        String layout;   // layout specification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        int bandCount;   // total number of elems
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        Element[] elems; // tokenization of layout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        Attribute canon; // canonical instance of this layout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        public int ctype() { return ctype; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        public String name() { return name; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        public String layout() { return layout; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        public Attribute canonicalInstance() { return canon; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        public Entry getNameRef() {
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   515
            return ConstantPool.getUtf8Entry(name());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   518
        public boolean isEmpty() {
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   519
            return layout.isEmpty();
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   520
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        public Layout(int ctype, String name, String layout) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            this.ctype = ctype;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            this.name = name.intern();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            this.layout = layout.intern();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            assert(ctype < ATTR_CONTEXT_LIMIT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            boolean hasCallables = layout.startsWith("[");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                if (!hasCallables) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                    this.elems = tokenizeLayout(this, -1, layout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                    String[] bodies = splitBodies(layout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                    // Make the callables now, so they can be linked immediately.
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   534
                    Element[] lelems = new Element[bodies.length];
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   535
                    this.elems = lelems;
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   536
                    for (int i = 0; i < lelems.length; i++) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                        Element ce = this.new Element();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                        ce.kind = EK_CBLE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                        ce.removeBand();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                        ce.bandIndex = NO_BAND_INDEX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                        ce.layout = bodies[i];
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   542
                        lelems[i] = ce;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                    // Next fill them in.
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   545
                    for (int i = 0; i < lelems.length; i++) {
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   546
                        Element ce = lelems[i];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                        ce.body = tokenizeLayout(this, i, bodies[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                    //System.out.println(Arrays.asList(elems));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            } catch (StringIndexOutOfBoundsException ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                // simplest way to catch syntax errors...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                throw new RuntimeException("Bad attribute layout: "+layout, ee);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
            // Some uses do not make a fresh one for each occurrence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
            // For example, if layout == "", we only need one attr to share.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            canon = new Attribute(this, noBytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        private Layout() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        static Layout makeKey(int ctype, String name, String layout) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            Layout def = new Layout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
            def.ctype = ctype;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            def.name = name.intern();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
            def.layout = layout.intern();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
            assert(ctype < ATTR_CONTEXT_LIMIT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
            return def;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        static Layout makeKey(int ctype, String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
            return makeKey(ctype, name, "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        public Attribute addContent(byte[] bytes, Object fixups) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
            return canon.addContent(bytes, fixups);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        public Attribute addContent(byte[] bytes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
            return canon.addContent(bytes, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
17490
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   579
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        public boolean equals(Object x) {
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   581
            return ( x != null) && ( x.getClass() == Layout.class ) &&
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   582
                    equals((Layout)x);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        public boolean equals(Layout that) {
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   585
            return this.name.equals(that.name)
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   586
                && this.layout.equals(that.layout)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                && this.ctype == that.ctype;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        }
17490
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   589
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            return (((17 + name.hashCode())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                    * 37 + layout.hashCode())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                    * 37 + ctype);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        }
17490
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   595
        @Override
10115
eb08d08c7ef7 7060849: Eliminate pack200 build warnings
ksrini
parents: 7795
diff changeset
   596
        public int compareTo(Layout that) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
            int r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
            r = this.name.compareTo(that.name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            if (r != 0)  return r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            r = this.layout.compareTo(that.layout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            if (r != 0)  return r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
            return this.ctype - that.ctype;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        }
17490
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   604
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
            String str = contextName(ctype)+"."+name+"["+layout+"]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            // If -ea, print out more informative strings!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
            assert((str = stringForDebug()) != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
            return str;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        private String stringForDebug() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
            return contextName(ctype)+"."+name+Arrays.asList(elems);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        public
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        class Element {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            String layout;   // spelling in the little language
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            byte flags;      // EF_SIGN, etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
            byte kind;       // EK_UINT, etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
            byte len;        // scalar length of element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
            byte refKind;    // CONSTANT_String, etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            int bandIndex;   // which band does this element govern?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
            int value;       // extra parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
            Element[] body;  // extra data (for replications, unions, calls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
            boolean flagTest(byte mask) { return (flags & mask) != 0; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
            Element() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
                bandIndex = bandCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
            void removeBand() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                --bandCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
                assert(bandIndex == bandCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
                bandIndex = NO_BAND_INDEX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
            public boolean hasBand() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
                return bandIndex >= 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
                String str = layout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
                // If -ea, print out more informative strings!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
                assert((str = stringForDebug()) != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
                return str;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
            private String stringForDebug() {
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   648
                Element[] lbody = this.body;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
                switch (kind) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
                case EK_CALL:
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   651
                    lbody = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
                case EK_CASE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
                    if (flagTest(EF_BACK))
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   655
                        lbody = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                return layout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
                    + (!hasBand()?"":"#"+bandIndex)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
                    + "<"+ (flags==0?"":""+flags)+kind+len
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
                    + (refKind==0?"":""+refKind) + ">"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
                    + (value==0?"":"("+value+")")
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   663
                    + (lbody==null?"": ""+Arrays.asList(lbody));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        public boolean hasCallables() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
            return (elems.length > 0 && elems[0].kind == EK_CBLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        }
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 31471
diff changeset
   670
        private static final Element[] noElems = {};
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        public Element[] getCallables() {
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   672
            if (hasCallables()) {
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   673
                Element[] nelems = Arrays.copyOf(elems, elems.length);
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   674
                return nelems;
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   675
            } else
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                return noElems;  // no callables at all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        public Element[] getEntryPoint() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
            if (hasCallables())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                return elems[0].body;  // body of first callable
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   681
            else {
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   682
                Element[] nelems = Arrays.copyOf(elems, elems.length);
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   683
                return nelems;  // no callables; whole body
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   684
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        /** Return a sequence of tokens from the given attribute bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
         *  Sequence elements will be 1-1 correspondent with my layout tokens.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        public void parse(Holder holder,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                          byte[] bytes, int pos, int len, ValueStream out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
            int end = parseUsing(getEntryPoint(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                                 holder, bytes, pos, len, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
            if (end != pos + len)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                throw new InternalError("layout parsed "+(end-pos)+" out of "+len+" bytes");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        /** Given a sequence of tokens, return the attribute bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
         *  Sequence elements must be 1-1 correspondent with my layout tokens.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
         *  The returned object is a cookie for Fixups.finishRefs, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
         *  must be used to harden any references into integer indexes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        public Object unparse(ValueStream in, ByteArrayOutputStream out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
            Object[] fixups = { null };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
            unparseUsing(getEntryPoint(), fixups, in, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
            return fixups[0]; // return ref-bearing cookie, if any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
12857
0a5f341c2a28 7168401: pack200 does not produce a compatible pack file for JDK7 classes if indy is not present
ksrini
parents: 12544
diff changeset
   708
        public String layoutForClassVersion(Package.Version vers) {
0a5f341c2a28 7168401: pack200 does not produce a compatible pack file for JDK7 classes if indy is not present
ksrini
parents: 12544
diff changeset
   709
            if (vers.lessThan(JAVA6_MAX_CLASS_VERSION)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
                // Disallow layout syntax in the oldest protocol version.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
                return expandCaseDashNotation(layout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
            return layout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
    public static
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
    class FormatException extends IOException {
10115
eb08d08c7ef7 7060849: Eliminate pack200 build warnings
ksrini
parents: 7795
diff changeset
   719
        private static final long serialVersionUID = -2542243830788066513L;
eb08d08c7ef7 7060849: Eliminate pack200 build warnings
ksrini
parents: 7795
diff changeset
   720
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        private int ctype;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        private String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
        String layout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        public FormatException(String message,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
                               int ctype, String name, String layout) {
6901
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6313
diff changeset
   726
            super(ATTR_CONTEXT_NAME[ctype]+ " attribute \"" + name + "\"" +
68f3d74dbda1 6746111: Improve pack200 error message
ksrini
parents: 6313
diff changeset
   727
                  (message == null? "" : (": " + message)));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
            this.ctype = ctype;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
            this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
            this.layout = layout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        public FormatException(String message,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
                               int ctype, String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
            this(message, ctype, name, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   738
    void visitRefs(Holder holder, int mode, final Collection<Entry> refs) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        if (mode == VRM_CLASSIC) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
            refs.add(getNameRef());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        // else the name is owned by the layout, and is processed elsewhere
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
        if (bytes.length == 0)  return;  // quick exit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        if (!def.hasRefs)       return;  // quick exit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
        if (fixups != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
            Fixups.visitRefs(fixups, refs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        // References (to a local cpMap) are embedded in the bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        def.parse(holder, bytes, 0, bytes.length,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
            new ValueStream() {
17490
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   752
                @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
                public void putInt(int bandIndex, int value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
                }
17490
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   755
                @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
                public void putRef(int bandIndex, Entry ref) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
                    refs.add(ref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
                }
17490
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   759
                @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
                public int encodeBCI(int bci) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
                    return bci;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
    public void parse(Holder holder, byte[] bytes, int pos, int len, ValueStream out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        def.parse(holder, bytes, pos, len, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
    public Object unparse(ValueStream in, ByteArrayOutputStream out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
        return def.unparse(in, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
17490
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
   773
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
        return def
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
            +"{"+(bytes == null ? -1 : size())+"}"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
            +(fixups == null? "": fixups.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
    /** Remove any informal "pretty printing" from the layout string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     *  Removes blanks and control chars.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     *  Removes '#' comments (to end of line).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     *  Replaces '\c' by the decimal code of the character c.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
     *  Replaces '0xNNN' by the decimal code of the hex number NNN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 31471
diff changeset
   786
    public static
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
    String normalizeLayoutString(String layout) {
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   788
        StringBuilder buf = new StringBuilder();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
        for (int i = 0, len = layout.length(); i < len; ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
            char ch = layout.charAt(i++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
            if (ch <= ' ') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
                // Skip whitespace and control chars
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
            } else if (ch == '#') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
                // Skip to end of line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
                int end1 = layout.indexOf('\n', i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
                int end2 = layout.indexOf('\r', i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
                if (end1 < 0)  end1 = len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
                if (end2 < 0)  end2 = len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
                i = Math.min(end1, end2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
            } else if (ch == '\\') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
                // Map a character reference to its decimal code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
                buf.append((int) layout.charAt(i++));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
            } else if (ch == '0' && layout.startsWith("0x", i-1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
                // Map a hex numeral to its decimal code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
                int start = i-1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
                int end = start+2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
                while (end < len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
                    int dig = layout.charAt(end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
                    if ((dig >= '0' && dig <= '9') ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
                        (dig >= 'a' && dig <= 'f'))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
                        ++end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
                    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
                if (end > start) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
                    String num = layout.substring(start, end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
                    buf.append(Integer.decode(num));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
                    i = end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
                    buf.append(ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
                buf.append(ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
        String result = buf.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
        if (false && !result.equals(layout)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
            Utils.log.info("Normalizing layout string");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
            Utils.log.info("    From: "+layout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
            Utils.log.info("    To:   "+result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
    /// Subroutines for parsing and unparsing:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
    /** Parse the attribute layout language.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
  attribute_layout:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
        ( layout_element )* | ( callable )+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
  layout_element:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
        ( integral | replication | union | call | reference )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
  callable:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
        '[' body ']'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
  body:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
        ( layout_element )+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
  integral:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
        ( unsigned_int | signed_int | bc_index | bc_offset | flag )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
  unsigned_int:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
        uint_type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
  signed_int:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        'S' uint_type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
  any_int:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
        ( unsigned_int | signed_int )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
  bc_index:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
        ( 'P' uint_type | 'PO' uint_type )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
  bc_offset:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        'O' any_int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
  flag:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        'F' uint_type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
  uint_type:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        ( 'B' | 'H' | 'I' | 'V' )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
  replication:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        'N' uint_type '[' body ']'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
  union:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        'T' any_int (union_case)* '(' ')' '[' (body)? ']'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
  union_case:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
        '(' union_case_tag (',' union_case_tag)* ')' '[' (body)? ']'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
  union_case_tag:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
        ( numeral | numeral '-' numeral )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
  call:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
        '(' numeral ')'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
  reference:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
        reference_type ( 'N' )? uint_type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
  reference_type:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
        ( constant_ref | schema_ref | utf8_ref | untyped_ref )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
  constant_ref:
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   884
        ( 'KI' | 'KJ' | 'KF' | 'KD' | 'KS' | 'KQ' | 'KM' | 'KT' | 'KL' )
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
  schema_ref:
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   886
        ( 'RC' | 'RS' | 'RD' | 'RF' | 'RM' | 'RI' | 'RY' | 'RB' | 'RN' )
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
  utf8_ref:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
        'RU'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
  untyped_ref:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
        'RQ'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
  numeral:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        '(' ('-')? (digit)+ ')'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
  digit:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        ( '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
 </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
    static //private
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
    Layout.Element[] tokenizeLayout(Layout self, int curCble, String layout) {
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   900
        List<Layout.Element> col = new ArrayList<>(layout.length());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
        tokenizeLayout(self, curCble, layout, col);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        Layout.Element[] res = new Layout.Element[col.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
        col.toArray(res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
    static //private
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   907
    void tokenizeLayout(Layout self, int curCble, String layout, List<Layout.Element> col) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
        boolean prevBCI = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        for (int len = layout.length(), i = 0; i < len; ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
            int start = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
            int body;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
            Layout.Element e = self.new Element();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
            byte kind;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
            //System.out.println("at "+i+": ..."+layout.substring(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
            // strip a prefix
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
            switch (layout.charAt(i++)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
            /// layout_element: integral
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
            case 'B': case 'H': case 'I': case 'V': // unsigned_int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
                kind = EK_INT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
                --i; // reparse
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
                i = tokenizeUInt(e, layout, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
            case 'S': // signed_int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
                kind = EK_INT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
                --i; // reparse
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
                i = tokenizeSInt(e, layout, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
            case 'P': // bc_index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
                kind = EK_BCI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
                if (layout.charAt(i++) == 'O') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
                    // bc_index: 'PO' tokenizeUInt
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
                    e.flags |= EF_DELTA;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
                    // must follow P or PO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
                    if (!prevBCI)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
                        { i = -i; continue; } // fail
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
                    i++; // move forward
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
                --i; // reparse
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
                i = tokenizeUInt(e, layout, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
            case 'O': // bc_offset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
                kind = EK_BCO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
                e.flags |= EF_DELTA;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
                // must follow P or PO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
                if (!prevBCI)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
                    { i = -i; continue; } // fail
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
                i = tokenizeSInt(e, layout, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
            case 'F': // flag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
                kind = EK_FLAG;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
                i = tokenizeUInt(e, layout, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
            case 'N': // replication: 'N' uint '[' elem ... ']'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
                kind = EK_REPL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
                i = tokenizeUInt(e, layout, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
                if (layout.charAt(i++) != '[')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
                    { i = -i; continue; } // fail
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
                i = skipBody(layout, body = i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
                e.body = tokenizeLayout(self, curCble,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
                                        layout.substring(body, i++));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
            case 'T': // union: 'T' any_int union_case* '(' ')' '[' body ']'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
                kind = EK_UN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
                i = tokenizeSInt(e, layout, i);
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   965
                List<Layout.Element> cases = new ArrayList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
                for (;;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
                    // Keep parsing cases until we hit the default case.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
                    if (layout.charAt(i++) != '(')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
                        { i = -i; break; } // fail
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
                    int beg = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
                    i = layout.indexOf(')', i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
                    String cstr = layout.substring(beg, i++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
                    int cstrlen = cstr.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
                    if (layout.charAt(i++) != '[')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
                        { i = -i; break; } // fail
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
                    // Check for duplication.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
                    if (layout.charAt(i) == ']')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
                        body = i;  // missing body, which is legal here
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
                    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
                        i = skipBody(layout, body = i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
                    Layout.Element[] cbody
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
                        = tokenizeLayout(self, curCble,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
                                         layout.substring(body, i++));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
                    if (cstrlen == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
                        Layout.Element ce = self.new Element();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
                        ce.body = cbody;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
                        ce.kind = EK_CASE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
                        ce.removeBand();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
                        cases.add(ce);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
                        break;  // done with the whole union
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
                        // Parse a case string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
                        boolean firstCaseNum = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
                        for (int cp = 0, endp;; cp = endp+1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
                            // Look for multiple case tags:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
                            endp = cstr.indexOf(',', cp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
                            if (endp < 0)  endp = cstrlen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
                            String cstr1 = cstr.substring(cp, endp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
                            if (cstr1.length() == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
                                cstr1 = "empty";  // will fail parse
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
                            int value0, value1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
                            // Check for a case range (new in 1.6).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
                            int dash = findCaseDash(cstr1, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
                            if (dash >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
                                value0 = parseIntBefore(cstr1, dash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
                                value1 = parseIntAfter(cstr1, dash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
                                if (value0 >= value1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
                                    { i = -i; break; } // fail
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
                            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
                                value0 = value1 = Integer.parseInt(cstr1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
                            // Add a case for each value in value0..value1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
                            for (;; value0++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
                                Layout.Element ce = self.new Element();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
                                ce.body = cbody;  // all cases share one body
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
                                ce.kind = EK_CASE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
                                ce.removeBand();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
                                if (!firstCaseNum)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
                                    // "backward case" repeats a body
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
                                    ce.flags |= EF_BACK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
                                firstCaseNum = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
                                ce.value = value0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
                                cases.add(ce);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
                                if (value0 == value1)  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
                            if (endp == cstrlen) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
                                break;  // done with this case
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
                e.body = new Layout.Element[cases.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
                cases.toArray(e.body);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
                e.kind = kind;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
                for (int j = 0; j < e.body.length-1; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
                    Layout.Element ce = e.body[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
                    if (matchCase(e, ce.value) != ce) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
                        // Duplicate tag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
                        { i = -i; break; } // fail
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
            case '(': // call: '(' '-'? digit+ ')'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
                kind = EK_CALL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
                e.removeBand();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
                i = layout.indexOf(')', i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
                String cstr = layout.substring(start+1, i++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
                int offset = Integer.parseInt(cstr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
                int target = curCble + offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
                if (!(offset+"").equals(cstr) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
                    self.elems == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
                    target < 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
                    target >= self.elems.length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
                    { i = -i; continue; } // fail
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
                Layout.Element ce = self.elems[target];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
                assert(ce.kind == EK_CBLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
                e.value = target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
                e.body = new Layout.Element[]{ ce };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
                // Is it a (recursive) backward call?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
                if (offset <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
                    // Yes.  Mark both caller and callee backward.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
                    e.flags  |= EF_BACK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
                    ce.flags |= EF_BACK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
            case 'K':  // reference_type: constant_ref
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
                kind = EK_REF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
                switch (layout.charAt(i++)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
                case 'I': e.refKind = CONSTANT_Integer; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
                case 'J': e.refKind = CONSTANT_Long; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
                case 'F': e.refKind = CONSTANT_Float; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
                case 'D': e.refKind = CONSTANT_Double; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
                case 'S': e.refKind = CONSTANT_String; break;
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1074
                case 'Q': e.refKind = CONSTANT_FieldSpecific; break;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1075
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1076
                // new in 1.7:
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1077
                case 'M': e.refKind = CONSTANT_MethodHandle; break;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1078
                case 'T': e.refKind = CONSTANT_MethodType; break;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1079
                case 'L': e.refKind = CONSTANT_LoadableValue; break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
                default: { i = -i; continue; } // fail
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
            case 'R': // schema_ref
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
                kind = EK_REF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
                switch (layout.charAt(i++)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
                case 'C': e.refKind = CONSTANT_Class; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
                case 'S': e.refKind = CONSTANT_Signature; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
                case 'D': e.refKind = CONSTANT_NameandType; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
                case 'F': e.refKind = CONSTANT_Fieldref; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
                case 'M': e.refKind = CONSTANT_Methodref; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
                case 'I': e.refKind = CONSTANT_InterfaceMethodref; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
                case 'U': e.refKind = CONSTANT_Utf8; break; //utf8_ref
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
                case 'Q': e.refKind = CONSTANT_All; break; //untyped_ref
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1096
                // new in 1.7:
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1097
                case 'Y': e.refKind = CONSTANT_InvokeDynamic; break;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1098
                case 'B': e.refKind = CONSTANT_BootstrapMethod; break;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1099
                case 'N': e.refKind = CONSTANT_AnyMember; break;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1100
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
                default: { i = -i; continue; } // fail
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
            default: { i = -i; continue; } // fail
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
            // further parsing of refs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
            if (kind == EK_REF) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
                // reference: reference_type -><- ( 'N' )? tokenizeUInt
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
                if (layout.charAt(i++) == 'N') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
                    e.flags |= EF_NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
                    i++; // move forward
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
                --i; // reparse
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
                i = tokenizeUInt(e, layout, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
                self.hasRefs = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
            prevBCI = (kind == EK_BCI);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
            // store the new element
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
            e.kind = kind;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
            e.layout = layout.substring(start, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
            col.add(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
    static //private
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
    String[] splitBodies(String layout) {
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
  1129
        List<String> bodies = new ArrayList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
        // Parse several independent layout bodies:  "[foo][bar]...[baz]"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
        for (int i = 0; i < layout.length(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
            if (layout.charAt(i++) != '[')
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
                layout.charAt(-i);  // throw error
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
            int body;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
            i = skipBody(layout, body = i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
            bodies.add(layout.substring(body, i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
        String[] res = new String[bodies.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
        bodies.toArray(res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
    }
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 31471
diff changeset
  1142
    private static
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
    int skipBody(String layout, int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
        assert(layout.charAt(i-1) == '[');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
        if (layout.charAt(i) == ']')
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
            // No empty bodies, please.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
            return -i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
        // skip balanced [...[...]...]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
        for (int depth = 1; depth > 0; ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
            switch (layout.charAt(i++)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
            case '[': depth++; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
            case ']': depth--; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
        --i;  // get before bracket
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
        assert(layout.charAt(i) == ']');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
        return i;  // return closing bracket
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
    }
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 31471
diff changeset
  1159
    private static
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
    int tokenizeUInt(Layout.Element e, String layout, int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
        switch (layout.charAt(i++)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
        case 'V': e.len = 0; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
        case 'B': e.len = 1; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
        case 'H': e.len = 2; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
        case 'I': e.len = 4; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
        default: return -i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
        return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
    }
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 31471
diff changeset
  1170
    private static
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
    int tokenizeSInt(Layout.Element e, String layout, int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
        if (layout.charAt(i) == 'S') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
            e.flags |= EF_SIGN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
            ++i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
        return tokenizeUInt(e, layout, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 31471
diff changeset
  1179
    private static
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
    boolean isDigit(char c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
        return c >= '0' && c <= '9';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
    /** Find an occurrence of hyphen '-' between two numerals. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
    static //private
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
    int findCaseDash(String layout, int fromIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
        if (fromIndex <= 0)  fromIndex = 1;  // minimum dash pos
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
        int lastDash = layout.length() - 2;  // maximum dash pos
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
        for (;;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
            int dash = layout.indexOf('-', fromIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
            if (dash < 0 || dash > lastDash)  return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
            if (isDigit(layout.charAt(dash-1))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
                char afterDash = layout.charAt(dash+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
                if (afterDash == '-' && dash+2 < layout.length())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
                    afterDash = layout.charAt(dash+2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
                if (isDigit(afterDash)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
                    // matched /[0-9]--?[0-9]/; return position of dash
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
                    return dash;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
            fromIndex = dash+1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
    static
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
    int parseIntBefore(String layout, int dash) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
        int end = dash;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
        int beg = end;
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
  1208
        while (beg > 0 && isDigit(layout.charAt(beg-1))) {
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
  1209
            --beg;
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
  1210
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
        if (beg == end)  return Integer.parseInt("empty");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
        // skip backward over a sign
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
        if (beg >= 1 && layout.charAt(beg-1) == '-')  --beg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
        assert(beg == 0 || !isDigit(layout.charAt(beg-1)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
        return Integer.parseInt(layout.substring(beg, end));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
    static
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
    int parseIntAfter(String layout, int dash) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
        int beg = dash+1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
        int end = beg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
        int limit = layout.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
        if (end < limit && layout.charAt(end) == '-')  ++end;
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
  1223
        while (end < limit && isDigit(layout.charAt(end))) {
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
  1224
            ++end;
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
  1225
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
        if (beg == end)  return Integer.parseInt("empty");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
        return Integer.parseInt(layout.substring(beg, end));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
    /** For compatibility with 1.5 pack, expand 1-5 into 1,2,3,4,5. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
    static
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
    String expandCaseDashNotation(String layout) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
        int dash = findCaseDash(layout, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
        if (dash < 0)  return layout;  // no dashes (the common case)
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
  1234
        StringBuilder result = new StringBuilder(layout.length() * 3);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
        int sofar = 0;  // how far have we processed the layout?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
        for (;;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
            // for each dash, collect everything up to the dash
31471
ae27c6f1d8bf 8077242: (str) Optimize AbstractStringBuilder.append(CharSequence, int, int) for String argument
igerasim
parents: 25859
diff changeset
  1238
            result.append(layout, sofar, dash);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
            sofar = dash+1;  // skip the dash
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
            // then collect intermediate values
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
            int value0 = parseIntBefore(layout, dash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
            int value1 = parseIntAfter(layout, dash);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
            assert(value0 < value1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
            result.append(",");  // close off value0 numeral
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
            for (int i = value0+1; i < value1; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
                result.append(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
                result.append(",");  // close off i numeral
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
            dash = findCaseDash(layout, sofar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
            if (dash < 0)  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
        }
31471
ae27c6f1d8bf 8077242: (str) Optimize AbstractStringBuilder.append(CharSequence, int, int) for String argument
igerasim
parents: 25859
diff changeset
  1252
        result.append(layout, sofar, layout.length());  // collect the rest
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
        return result.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
        assert(expandCaseDashNotation("1-5").equals("1,2,3,4,5"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
        assert(expandCaseDashNotation("-2--1").equals("-2,-1"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
        assert(expandCaseDashNotation("-2-1").equals("-2,-1,0,1"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
        assert(expandCaseDashNotation("-1-0").equals("-1,0"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
    // Parse attribute bytes, putting values into bands.  Returns new pos.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
    // Used when reading a class file (local refs resolved with local cpMap).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
    // Also used for ad hoc scanning.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
    static
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
    int parseUsing(Layout.Element[] elems, Holder holder,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
                   byte[] bytes, int pos, int len, ValueStream out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
        int prevBCI = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
        int prevRBCI = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
        int end = pos + len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
        int[] buf = { 0 };  // for calls to parseInt, holds 2nd result
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
        for (int i = 0; i < elems.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
            Layout.Element e = elems[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
            int bandIndex = e.bandIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
            int value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
            int BCI, RBCI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
            switch (e.kind) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
            case EK_INT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
                pos = parseInt(e, bytes, pos, buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
                value = buf[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
                out.putInt(bandIndex, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
            case EK_BCI:  // PH, POH
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
                pos = parseInt(e, bytes, pos, buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
                BCI = buf[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
                RBCI = out.encodeBCI(BCI);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
                if (!e.flagTest(EF_DELTA)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
                    // PH:  transmit R(bci), store bci
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
                    value = RBCI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
                    // POH:  transmit D(R(bci)), store bci
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
                    value = RBCI - prevRBCI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
                prevBCI = BCI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
                prevRBCI = RBCI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
                out.putInt(bandIndex, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
            case EK_BCO:  // OH
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
                assert(e.flagTest(EF_DELTA));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
                // OH:  transmit D(R(bci)), store D(bci)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
                pos = parseInt(e, bytes, pos, buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
                BCI = prevBCI + buf[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
                RBCI = out.encodeBCI(BCI);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
                value = RBCI - prevRBCI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
                prevBCI = BCI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
                prevRBCI = RBCI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
                out.putInt(bandIndex, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
            case EK_FLAG:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
                pos = parseInt(e, bytes, pos, buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
                value = buf[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
                out.putInt(bandIndex, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
            case EK_REPL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
                pos = parseInt(e, bytes, pos, buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
                value = buf[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
                out.putInt(bandIndex, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
                for (int j = 0; j < value; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
                    pos = parseUsing(e.body, holder, bytes, pos, end-pos, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
                break;  // already transmitted the scalar value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
            case EK_UN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
                pos = parseInt(e, bytes, pos, buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
                value = buf[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
                out.putInt(bandIndex, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
                Layout.Element ce = matchCase(e, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
                pos = parseUsing(ce.body, holder, bytes, pos, end-pos, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
                break;  // already transmitted the scalar value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
            case EK_CALL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
                // Adjust band offset if it is a backward call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
                assert(e.body.length == 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
                assert(e.body[0].kind == EK_CBLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
                if (e.flagTest(EF_BACK))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
                    out.noteBackCall(e.value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
                pos = parseUsing(e.body[0].body, holder, bytes, pos, end-pos, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
                break;  // no additional scalar value to transmit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
            case EK_REF:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
                pos = parseInt(e, bytes, pos, buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
                int localRef = buf[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
                Entry globalRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
                if (localRef == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
                    globalRef = null;  // N.B. global null reference is -1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
                } else {
15526
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents: 15261
diff changeset
  1345
                    Entry[] cpMap = holder.getCPMap();
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents: 15261
diff changeset
  1346
                    globalRef = (localRef >= 0 && localRef < cpMap.length
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents: 15261
diff changeset
  1347
                                    ? cpMap[localRef]
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents: 15261
diff changeset
  1348
                                    : null);
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents: 15261
diff changeset
  1349
                    byte tag = e.refKind;
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents: 15261
diff changeset
  1350
                    if (globalRef != null && tag == CONSTANT_Signature
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
                        && globalRef.getTag() == CONSTANT_Utf8) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
                        // Cf. ClassReader.readSignatureRef.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
                        String typeName = globalRef.stringValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
                        globalRef = ConstantPool.getSignatureEntry(typeName);
15526
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents: 15261
diff changeset
  1355
                    }
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents: 15261
diff changeset
  1356
                    String got = (globalRef == null
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents: 15261
diff changeset
  1357
                        ? "invalid CP index"
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents: 15261
diff changeset
  1358
                        : "type=" + ConstantPool.tagName(globalRef.tag));
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents: 15261
diff changeset
  1359
                    if (globalRef == null || !globalRef.tagMatches(tag)) {
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents: 15261
diff changeset
  1360
                        throw new IllegalArgumentException(
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents: 15261
diff changeset
  1361
                                "Bad constant, expected type=" +
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents: 15261
diff changeset
  1362
                                ConstantPool.tagName(tag) + " got " + got);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
                out.putRef(bandIndex, globalRef);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
                break;
17490
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
  1367
            default: assert(false);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
        return pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
    static
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
    Layout.Element matchCase(Layout.Element e, int value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
        assert(e.kind == EK_UN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
        int lastj = e.body.length-1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
        for (int j = 0; j < lastj; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
            Layout.Element ce = e.body[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
            assert(ce.kind == EK_CASE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
            if (value == ce.value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
                return ce;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
        return e.body[lastj];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 31471
diff changeset
  1386
    private static
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
    int parseInt(Layout.Element e, byte[] bytes, int pos, int[] buf) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
        int value = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
        int loBits = e.len * 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
        // Read in big-endian order:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
        for (int bitPos = loBits; (bitPos -= 8) >= 0; ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
            value += (bytes[pos++] & 0xFF) << bitPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
        if (loBits < 32 && e.flagTest(EF_SIGN)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
            // sign-extend subword value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
            int hiBits = 32 - loBits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
            value = (value << hiBits) >> hiBits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
        buf[0] = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
        return pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
    // Format attribute bytes, drawing values from bands.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
    // Used when emptying attribute bands into a package model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
    // (At that point CP refs. are not yet assigned indexes.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
    static
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
    void unparseUsing(Layout.Element[] elems, Object[] fixups,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
                      ValueStream in, ByteArrayOutputStream out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
        int prevBCI = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
        int prevRBCI = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
        for (int i = 0; i < elems.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
            Layout.Element e = elems[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
            int bandIndex = e.bandIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
            int value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
            int BCI, RBCI;  // "RBCI" is R(BCI), BCI's coded representation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
            switch (e.kind) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
            case EK_INT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
                value = in.getInt(bandIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
                unparseInt(e, value, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
            case EK_BCI:  // PH, POH
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
                value = in.getInt(bandIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
                if (!e.flagTest(EF_DELTA)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
                    // PH:  transmit R(bci), store bci
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
                    RBCI = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
                    // POH:  transmit D(R(bci)), store bci
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
                    RBCI = prevRBCI + value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
                assert(prevBCI == in.decodeBCI(prevRBCI));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
                BCI = in.decodeBCI(RBCI);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
                unparseInt(e, BCI, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
                prevBCI = BCI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
                prevRBCI = RBCI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
            case EK_BCO:  // OH
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
                value = in.getInt(bandIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
                assert(e.flagTest(EF_DELTA));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
                // OH:  transmit D(R(bci)), store D(bci)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
                assert(prevBCI == in.decodeBCI(prevRBCI));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
                RBCI = prevRBCI + value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
                BCI = in.decodeBCI(RBCI);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
                unparseInt(e, BCI - prevBCI, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
                prevBCI = BCI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
                prevRBCI = RBCI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
            case EK_FLAG:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
                value = in.getInt(bandIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
                unparseInt(e, value, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
            case EK_REPL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
                value = in.getInt(bandIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
                unparseInt(e, value, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
                for (int j = 0; j < value; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
                    unparseUsing(e.body, fixups, in, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
            case EK_UN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
                value = in.getInt(bandIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
                unparseInt(e, value, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
                Layout.Element ce = matchCase(e, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
                unparseUsing(ce.body, fixups, in, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
            case EK_CALL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
                assert(e.body.length == 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
                assert(e.body[0].kind == EK_CBLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
                unparseUsing(e.body[0].body, fixups, in, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
            case EK_REF:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
                Entry globalRef = in.getRef(bandIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
                int localRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
                if (globalRef != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
                    // It's a one-element array, really an lvalue.
17490
46864558d068 8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents: 16013
diff changeset
  1474
                    fixups[0] = Fixups.addRefWithLoc(fixups[0], out.size(), globalRef);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
                    localRef = 0; // placeholder for fixups
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
                    localRef = 0; // fixed null value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
                unparseInt(e, localRef, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
            default: assert(false); continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 31471
diff changeset
  1486
    private static
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
    void unparseInt(Layout.Element e, int value, ByteArrayOutputStream out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
        int loBits = e.len * 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
        if (loBits == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
            // It is not stored at all ('V' layout).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
        if (loBits < 32) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
            int hiBits = 32 - loBits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
            int codedValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
            if (e.flagTest(EF_SIGN))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
                codedValue = (value << hiBits) >> hiBits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
                codedValue = (value << hiBits) >>> hiBits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
            if (codedValue != value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
                throw new InternalError("cannot code in "+e.len+" bytes: "+value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
        // Write in big-endian order:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
        for (int bitPos = loBits; (bitPos -= 8) >= 0; ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
            out.write((byte)(value >>> bitPos));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
    /// Testing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
    public static void main(String av[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
        int maxVal = 12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
        int iters = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
        boolean verbose;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
        int ap = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
        while (ap < av.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
            if (!av[ap].startsWith("-"))  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
            if (av[ap].startsWith("-m"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
                maxVal = Integer.parseInt(av[ap].substring(2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
            else if (av[ap].startsWith("-i"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
                iters = Integer.parseInt(av[ap].substring(2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
                throw new RuntimeException("Bad option: "+av[ap]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
            ap++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
        verbose = (iters == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
        if (iters <= 0)  iters = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
        if (ap == av.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
            av = new String[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
                "HH",         // ClassFile.version
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
                "RUH",        // SourceFile
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
                "RCHRDNH",    // EnclosingMethod
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
                "KQH",        // ConstantValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
                "NH[RCH]",    // Exceptions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
                "NH[PHH]",    // LineNumberTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
                "NH[PHOHRUHRSHH]",      // LocalVariableTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
                "NH[PHPOHIIH]",         // CharacterRangeTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
                "NH[PHHII]",            // CoverageTable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
                "NH[RCHRCNHRUNHFH]",    // InnerClasses
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1540
                "NH[RMHNH[KLH]]",       // BootstrapMethods
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
                "HHNI[B]NH[PHPOHPOHRCNH]NH[RUHNI[B]]", // Code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
                "=AnnotationDefault",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
                // Like metadata, but with a compact tag set:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
                "[NH[(1)]]"
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1545
                +"[NH[(1)]]"
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1546
                +"[RSHNH[RUH(1)]]"
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1547
                +"[TB(0,1,3)[KIH](2)[KDH](5)[KFH](4)[KJH](7)[RSH](8)[RSHRUH](9)[RUH](10)[(-1)](6)[NH[(0)]]()[]]",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
                ""
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
            ap = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
        }
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1552
        Utils.currentInstance.set(new PackerImpl());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
        final int[][] counts = new int[2][3];  // int bci ref
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
        final Entry[] cpMap = new Entry[maxVal+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
        for (int i = 0; i < cpMap.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
            if (i == 0)  continue;  // 0 => null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
            cpMap[i] = ConstantPool.getLiteralEntry(new Integer(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
        }
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1559
        Package.Class cls = new Package().new Class("");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
        cls.cpMap = cpMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
        class TestValueStream extends ValueStream {
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1562
            java.util.Random rand = new java.util.Random(0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
            ArrayList history = new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
            int ckidx = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
            int maxVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
            boolean verbose;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
            void reset() { history.clear(); ckidx = 0; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
            public int getInt(int bandIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
                counts[0][0]++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
                int value = rand.nextInt(maxVal+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
                history.add(new Integer(bandIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
                history.add(new Integer(value));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
                return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
            public void putInt(int bandIndex, int token) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
                counts[1][0]++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
                if (verbose)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
                    System.out.print(" "+bandIndex+":"+token);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
                // Make sure this put parallels a previous get:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
                int check0 = ((Integer)history.get(ckidx+0)).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
                int check1 = ((Integer)history.get(ckidx+1)).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
                if (check0 != bandIndex || check1 != token) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
                    if (!verbose)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
                        System.out.println(history.subList(0, ckidx));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
                    System.out.println(" *** Should be "+check0+":"+check1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
                    throw new RuntimeException("Failed test!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
                ckidx += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
            public Entry getRef(int bandIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
                counts[0][2]++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
                int value = getInt(bandIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
                if (value < 0 || value > maxVal) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
                    System.out.println(" *** Unexpected ref code "+value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
                    return ConstantPool.getLiteralEntry(new Integer(value));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
                return cpMap[value];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
            public void putRef(int bandIndex, Entry ref) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
                counts[1][2]++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
                if (ref == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
                    putInt(bandIndex, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
                Number refValue = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
                if (ref instanceof ConstantPool.NumberEntry)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
                    refValue = ((ConstantPool.NumberEntry)ref).numberValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
                int value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
                if (!(refValue instanceof Integer)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
                    System.out.println(" *** Unexpected ref "+ref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
                    value = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
                    value = ((Integer)refValue).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
                putInt(bandIndex, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
            public int encodeBCI(int bci) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
                counts[1][1]++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
                // move LSB to MSB of low byte
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
                int code = (bci >> 8) << 8;  // keep high bits
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
                code += (bci & 0xFE) >> 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
                code += (bci & 0x01) << 7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
                return code ^ (8<<8);  // mark it clearly as coded
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
            public int decodeBCI(int bciCode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
                counts[0][1]++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
                bciCode ^= (8<<8);  // remove extra mark
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
                int bci = (bciCode >> 8) << 8;  // keep high bits
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
                bci += (bciCode & 0x7F) << 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
                bci += (bciCode & 0x80) >> 7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
                return bci;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
        TestValueStream tts = new TestValueStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
        tts.maxVal = maxVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
        tts.verbose = verbose;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
        ByteArrayOutputStream buf = new ByteArrayOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
        for (int i = 0; i < (1 << 30); i = (i + 1) * 5) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
            int ei = tts.encodeBCI(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
            int di = tts.decodeBCI(ei);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
            if (di != i)  System.out.println("i="+Integer.toHexString(i)+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
                                             " ei="+Integer.toHexString(ei)+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
                                             " di="+Integer.toHexString(di));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
        while (iters-- > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
            for (int i = ap; i < av.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
                String layout = av[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
                if (layout.startsWith("=")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
                    String name = layout.substring(1);
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1650
                    for (Attribute a : standardDefs.values()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
                        if (a.name().equals(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
                            layout = a.layout().layout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
                    if (layout.startsWith("=")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
                        System.out.println("Could not find "+name+" in "+standardDefs.values());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
                Layout self = new Layout(0, "Foo", layout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
                if (verbose) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
                    System.out.print("/"+layout+"/ => ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
                    System.out.println(Arrays.asList(self.elems));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
                buf.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
                tts.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
                Object fixups = self.unparse(tts, buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
                byte[] bytes = buf.toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
                // Attach the references to the byte array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
                Fixups.setBytes(fixups, bytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
                // Patch the references to their frozen values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
                Fixups.finishRefs(fixups, bytes, new Index("test", cpMap));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
                if (verbose) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
                    System.out.print("  bytes: {");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
                    for (int j = 0; j < bytes.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
                        System.out.print(" "+bytes[j]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
                    System.out.println("}");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
                if (verbose) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
                    System.out.print("  parse: {");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
                }
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1683
                self.parse(cls, bytes, 0, bytes.length, tts);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
                if (verbose) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
                    System.out.println("}");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
        for (int j = 0; j <= 1; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
            System.out.print("values "+(j==0?"read":"written")+": {");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
            for (int k = 0; k < counts[j].length; k++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
                System.out.print(" "+counts[j][k]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
            System.out.println(" }");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
//*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
}