jdk/src/java.base/share/classes/com/sun/java/util/jar/pack/ConstantPool.java
author martin
Tue, 15 Sep 2015 21:56:04 -0700
changeset 32649 2ee9017c7597
parent 25859 3317bb8137f4
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
/*
15526
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents: 12544
diff changeset
     2
 * Copyright (c) 2001, 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: 6313
diff changeset
    28
import java.util.AbstractList;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 6313
diff changeset
    29
import java.util.ArrayList;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 6313
diff changeset
    30
import java.util.Arrays;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 6313
diff changeset
    31
import java.util.Collection;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 6313
diff changeset
    32
import java.util.List;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 6313
diff changeset
    33
import java.util.ListIterator;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 6313
diff changeset
    34
import java.util.Map;
445c518364c4 7003227: (pack200) intermittent failures compiling pack200
ksrini
parents: 6313
diff changeset
    35
import java.util.Set;
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
    36
import static com.sun.java.util.jar.pack.Constants.*;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * Representation of constant pool entries and indexes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * @author John Rose
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
abstract
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
    43
class ConstantPool {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    private ConstantPool() {}  // do not instantiate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    static int verbose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        return Utils.currentPropMap().getInteger(Utils.DEBUG_VERBOSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    /** Factory for Utf8 string constants.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     *  Used for well-known strings like "SourceFile", "<init>", etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     *  Also used to back up more complex constant pool entries, like Class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    public static synchronized Utf8Entry getUtf8Entry(String value) {
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
    55
        Map<String, Utf8Entry> utf8Entries  = Utils.getTLGlobals().getUtf8Entries();
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
    56
        Utf8Entry e = utf8Entries.get(value);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        if (e == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
            e = new Utf8Entry(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
            utf8Entries.put(e.stringValue(), e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        return e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    /** Factory for Class constants. */
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
    64
    public static ClassEntry getClassEntry(String name) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
    65
        Map<String, ClassEntry> classEntries = Utils.getTLGlobals().getClassEntries();
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
    66
        ClassEntry e = classEntries.get(name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        if (e == null) {
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
    68
            e = new ClassEntry(getUtf8Entry(name));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            assert(name.equals(e.stringValue()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            classEntries.put(e.stringValue(), e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        return e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    /** Factory for literal constants (String, Integer, etc.). */
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
    75
    public static LiteralEntry getLiteralEntry(Comparable<?> value) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
    76
        Map<Object, LiteralEntry> literalEntries = Utils.getTLGlobals().getLiteralEntries();
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
    77
        LiteralEntry e = literalEntries.get(value);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        if (e == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            if (value instanceof String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                e = new StringEntry(getUtf8Entry((String)value));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                e = new NumberEntry((Number)value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            literalEntries.put(value, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        return e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    /** Factory for literal constants (String, Integer, etc.). */
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
    88
    public static StringEntry getStringEntry(String value) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        return (StringEntry) getLiteralEntry(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    /** Factory for signature (type) constants. */
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
    93
    public static SignatureEntry getSignatureEntry(String type) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
    94
        Map<String, SignatureEntry> signatureEntries = Utils.getTLGlobals().getSignatureEntries();
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
    95
        SignatureEntry e = signatureEntries.get(type);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        if (e == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            e = new SignatureEntry(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            assert(e.stringValue().equals(type));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            signatureEntries.put(type, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        return e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    // Convenience overloading.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    public static SignatureEntry getSignatureEntry(Utf8Entry formRef, ClassEntry[] classRefs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        return getSignatureEntry(SignatureEntry.stringValueOf(formRef, classRefs));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    /** Factory for descriptor (name-and-type) constants. */
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   109
    public static DescriptorEntry getDescriptorEntry(Utf8Entry nameRef, SignatureEntry typeRef) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   110
        Map<String, DescriptorEntry> descriptorEntries = Utils.getTLGlobals().getDescriptorEntries();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        String key = DescriptorEntry.stringValueOf(nameRef, typeRef);
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   112
        DescriptorEntry e = descriptorEntries.get(key);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        if (e == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            e = new DescriptorEntry(nameRef, typeRef);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            assert(e.stringValue().equals(key))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                : (e.stringValue()+" != "+(key));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            descriptorEntries.put(key, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        return e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    // Convenience overloading.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    public static DescriptorEntry getDescriptorEntry(Utf8Entry nameRef, Utf8Entry typeRef) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        return getDescriptorEntry(nameRef, getSignatureEntry(typeRef.stringValue()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    /** Factory for member reference constants. */
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   127
    public static MemberEntry getMemberEntry(byte tag, ClassEntry classRef, DescriptorEntry descRef) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   128
        Map<String, MemberEntry> memberEntries = Utils.getTLGlobals().getMemberEntries();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        String key = MemberEntry.stringValueOf(tag, classRef, descRef);
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   130
        MemberEntry e = memberEntries.get(key);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        if (e == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            e = new MemberEntry(tag, classRef, descRef);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            assert(e.stringValue().equals(key))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                : (e.stringValue()+" != "+(key));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            memberEntries.put(key, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        return e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   140
    /** Factory for MethodHandle constants. */
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   141
    public static MethodHandleEntry getMethodHandleEntry(byte refKind, MemberEntry memRef) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   142
        Map<String, MethodHandleEntry> methodHandleEntries = Utils.getTLGlobals().getMethodHandleEntries();
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   143
        String key = MethodHandleEntry.stringValueOf(refKind, memRef);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   144
        MethodHandleEntry e = methodHandleEntries.get(key);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   145
        if (e == null) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   146
            e = new MethodHandleEntry(refKind, memRef);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   147
            assert(e.stringValue().equals(key));
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   148
            methodHandleEntries.put(key, e);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   149
        }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   150
        return e;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   151
    }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   152
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   153
    /** Factory for MethodType constants. */
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   154
    public static MethodTypeEntry getMethodTypeEntry(SignatureEntry sigRef) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   155
        Map<String, MethodTypeEntry> methodTypeEntries = Utils.getTLGlobals().getMethodTypeEntries();
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   156
        String key = sigRef.stringValue();
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   157
        MethodTypeEntry e = methodTypeEntries.get(key);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   158
        if (e == null) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   159
            e = new MethodTypeEntry(sigRef);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   160
            assert(e.stringValue().equals(key));
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   161
            methodTypeEntries.put(key, e);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   162
        }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   163
        return e;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   164
    }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   165
    public static MethodTypeEntry getMethodTypeEntry(Utf8Entry typeRef) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   166
        return getMethodTypeEntry(getSignatureEntry(typeRef.stringValue()));
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   167
    }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   168
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   169
    /** Factory for InvokeDynamic constants. */
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   170
    public static InvokeDynamicEntry getInvokeDynamicEntry(BootstrapMethodEntry bssRef, DescriptorEntry descRef) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   171
        Map<String, InvokeDynamicEntry> invokeDynamicEntries = Utils.getTLGlobals().getInvokeDynamicEntries();
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   172
        String key = InvokeDynamicEntry.stringValueOf(bssRef, descRef);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   173
        InvokeDynamicEntry e = invokeDynamicEntries.get(key);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   174
        if (e == null) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   175
            e = new InvokeDynamicEntry(bssRef, descRef);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   176
            assert(e.stringValue().equals(key));
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   177
            invokeDynamicEntries.put(key, e);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   178
        }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   179
        return e;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   180
    }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   181
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   182
    /** Factory for BootstrapMethod pseudo-constants. */
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   183
    public static BootstrapMethodEntry getBootstrapMethodEntry(MethodHandleEntry bsmRef, Entry[] argRefs) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   184
        Map<String, BootstrapMethodEntry> bootstrapMethodEntries = Utils.getTLGlobals().getBootstrapMethodEntries();
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   185
        String key = BootstrapMethodEntry.stringValueOf(bsmRef, argRefs);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   186
        BootstrapMethodEntry e = bootstrapMethodEntries.get(key);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   187
        if (e == null) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   188
            e = new BootstrapMethodEntry(bsmRef, argRefs);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   189
            assert(e.stringValue().equals(key));
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   190
            bootstrapMethodEntries.put(key, e);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   191
        }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   192
        return e;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   193
    }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   194
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    /** Entries in the constant pool. */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   197
    public abstract static
10115
eb08d08c7ef7 7060849: Eliminate pack200 build warnings
ksrini
parents: 7803
diff changeset
   198
    class Entry implements Comparable<Object> {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        protected final byte tag;       // a CONSTANT_foo code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        protected int valueHash;        // cached hashCode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        protected Entry(byte tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            this.tag = tag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        public final byte getTag() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            return tag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
16050
1eee624cddb3 8007297: [pack200] allow opcodes with InterfaceMethodRefs
ksrini
parents: 15526
diff changeset
   210
        public final boolean tagEquals(int tag) {
1eee624cddb3 8007297: [pack200] allow opcodes with InterfaceMethodRefs
ksrini
parents: 15526
diff changeset
   211
            return getTag() == tag;
1eee624cddb3 8007297: [pack200] allow opcodes with InterfaceMethodRefs
ksrini
parents: 15526
diff changeset
   212
        }
1eee624cddb3 8007297: [pack200] allow opcodes with InterfaceMethodRefs
ksrini
parents: 15526
diff changeset
   213
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        public Entry getRef(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        public boolean eq(Entry that) {  // same reference
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            assert(that != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            return this == that || this.equals(that);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        // Equality of Entries is value-based.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        public abstract boolean equals(Object o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        public final int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            if (valueHash == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                valueHash = computeValueHash();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                if (valueHash == 0)  valueHash = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            return valueHash;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        protected abstract int computeValueHash();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        public abstract int compareTo(Object o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        protected int superCompareTo(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            Entry that = (Entry) o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            if (this.tag != that.tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                return TAG_ORDER[this.tag] - TAG_ORDER[that.tag];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            return 0;  // subclasses must refine this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        public final boolean isDoubleWord() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            return tag == CONSTANT_Double || tag == CONSTANT_Long;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
15526
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents: 12544
diff changeset
   250
        public final boolean tagMatches(int matchTag) {
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents: 12544
diff changeset
   251
            if (tag == matchTag)
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents: 12544
diff changeset
   252
                return true;
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents: 12544
diff changeset
   253
            byte[] allowedTags;
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents: 12544
diff changeset
   254
            switch (matchTag) {
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents: 12544
diff changeset
   255
                case CONSTANT_All:
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents: 12544
diff changeset
   256
                    return true;
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents: 12544
diff changeset
   257
                case CONSTANT_Signature:
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents: 12544
diff changeset
   258
                    return tag == CONSTANT_Utf8;  // format check also?
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents: 12544
diff changeset
   259
                case CONSTANT_LoadableValue:
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents: 12544
diff changeset
   260
                    allowedTags = LOADABLE_VALUE_TAGS;
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents: 12544
diff changeset
   261
                    break;
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents: 12544
diff changeset
   262
                case CONSTANT_AnyMember:
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents: 12544
diff changeset
   263
                    allowedTags = ANY_MEMBER_TAGS;
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents: 12544
diff changeset
   264
                    break;
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents: 12544
diff changeset
   265
                case CONSTANT_FieldSpecific:
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents: 12544
diff changeset
   266
                    allowedTags = FIELD_SPECIFIC_TAGS;
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents: 12544
diff changeset
   267
                    break;
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents: 12544
diff changeset
   268
                default:
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents: 12544
diff changeset
   269
                    return false;
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents: 12544
diff changeset
   270
            }
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents: 12544
diff changeset
   271
            for (byte b : allowedTags) {
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents: 12544
diff changeset
   272
                if (b == tag)
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents: 12544
diff changeset
   273
                    return true;
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents: 12544
diff changeset
   274
            }
84de8685a2d0 8003549: (pack200) assertion errors when processing lambda class files with IMethods
ksrini
parents: 12544
diff changeset
   275
            return false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            String valuePrint = stringValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            if (verbose() > 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                if (valueHash != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                    valuePrint += " hash="+valueHash;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                valuePrint += " id="+System.identityHashCode(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            return tagName(tag)+"="+valuePrint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        public abstract String stringValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    public static
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    class Utf8Entry extends Entry {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        final String value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        Utf8Entry(String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            super(CONSTANT_Utf8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            this.value = value.intern();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            hashCode();  // force computation of valueHash
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        protected int computeValueHash() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            return value.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        public boolean equals(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            // Use reference equality of interned strings:
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   304
            return (o != null && o.getClass() == Utf8Entry.class
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   305
                    && ((Utf8Entry) o).value.equals(value));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        public int compareTo(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            int x = superCompareTo(o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            if (x == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                x = value.compareTo(((Utf8Entry)o).value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            return x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        public String stringValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    static boolean isMemberTag(byte tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        switch (tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        case CONSTANT_Fieldref:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        case CONSTANT_Methodref:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        case CONSTANT_InterfaceMethodref:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    static byte numberTagOf(Number value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        if (value instanceof Integer)  return CONSTANT_Integer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        if (value instanceof Float)    return CONSTANT_Float;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        if (value instanceof Long)     return CONSTANT_Long;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        if (value instanceof Double)   return CONSTANT_Double;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        throw new RuntimeException("bad literal value "+value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   337
    static boolean isRefKind(byte refKind) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   338
        return (REF_getField <= refKind && refKind <= REF_invokeInterface);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   339
    }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   340
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   341
    public abstract static
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    class LiteralEntry extends Entry {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        protected LiteralEntry(byte tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            super(tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
10115
eb08d08c7ef7 7060849: Eliminate pack200 build warnings
ksrini
parents: 7803
diff changeset
   347
        public abstract Comparable<?> literalValue();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    public static
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    class NumberEntry extends LiteralEntry {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        final Number value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        NumberEntry(Number value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            super(numberTagOf(value));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            this.value = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            hashCode();  // force computation of valueHash
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        protected int computeValueHash() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            return value.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        public boolean equals(Object o) {
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   363
            return (o != null && o.getClass() == NumberEntry.class
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   364
                    && ((NumberEntry) o).value.equals(value));
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   365
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        public int compareTo(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            int x = superCompareTo(o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            if (x == 0) {
10115
eb08d08c7ef7 7060849: Eliminate pack200 build warnings
ksrini
parents: 7803
diff changeset
   370
                @SuppressWarnings("unchecked")
eb08d08c7ef7 7060849: Eliminate pack200 build warnings
ksrini
parents: 7803
diff changeset
   371
                Comparable<Number> compValue = (Comparable<Number>)value;
eb08d08c7ef7 7060849: Eliminate pack200 build warnings
ksrini
parents: 7803
diff changeset
   372
                x = compValue.compareTo(((NumberEntry)o).value);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            return x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        public Number numberValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        }
10115
eb08d08c7ef7 7060849: Eliminate pack200 build warnings
ksrini
parents: 7803
diff changeset
   379
        public Comparable<?> literalValue() {
eb08d08c7ef7 7060849: Eliminate pack200 build warnings
ksrini
parents: 7803
diff changeset
   380
            return (Comparable<?>) value;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        public String stringValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            return value.toString();
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
    public static
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    class StringEntry extends LiteralEntry {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        final Utf8Entry ref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        public Entry getRef(int i) { return i == 0 ? ref : null; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        StringEntry(Entry ref) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            super(CONSTANT_String);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            this.ref = (Utf8Entry) ref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            hashCode();  // force computation of valueHash
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        protected int computeValueHash() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            return ref.hashCode() + tag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        public boolean equals(Object o) {
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   401
            return (o != null && o.getClass() == StringEntry.class &&
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   402
                    ((StringEntry)o).ref.eq(ref));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        public int compareTo(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            int x = superCompareTo(o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            if (x == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                x = ref.compareTo(((StringEntry)o).ref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            return x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        }
10115
eb08d08c7ef7 7060849: Eliminate pack200 build warnings
ksrini
parents: 7803
diff changeset
   411
        public Comparable<?> literalValue() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            return ref.stringValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        public String stringValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            return ref.stringValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    public static
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    class ClassEntry extends Entry {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        final Utf8Entry ref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        public Entry getRef(int i) { return i == 0 ? ref : null; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        protected int computeValueHash() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            return ref.hashCode() + tag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        ClassEntry(Entry ref) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            super(CONSTANT_Class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            this.ref = (Utf8Entry) ref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            hashCode();  // force computation of valueHash
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        public boolean equals(Object o) {
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   433
            return (o != null && o.getClass() == ClassEntry.class
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   434
                    && ((ClassEntry) o).ref.eq(ref));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        public int compareTo(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            int x = superCompareTo(o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            if (x == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                x = ref.compareTo(((ClassEntry)o).ref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            return x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        public String stringValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            return ref.stringValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    public static
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    class DescriptorEntry extends Entry {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        final Utf8Entry      nameRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        final SignatureEntry typeRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        public Entry getRef(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            if (i == 0)  return nameRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            if (i == 1)  return typeRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        DescriptorEntry(Entry nameRef, Entry typeRef) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            super(CONSTANT_NameandType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            if (typeRef instanceof Utf8Entry) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                typeRef = getSignatureEntry(typeRef.stringValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            this.nameRef = (Utf8Entry) nameRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            this.typeRef = (SignatureEntry) typeRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            hashCode();  // force computation of valueHash
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        protected int computeValueHash() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            int hc2 = typeRef.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            return (nameRef.hashCode() + (hc2 << 8)) ^ hc2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        public boolean equals(Object o) {
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   471
            if (o == null || o.getClass() != DescriptorEntry.class) {
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   472
                return false;
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   473
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            DescriptorEntry that = (DescriptorEntry)o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            return this.nameRef.eq(that.nameRef)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                && this.typeRef.eq(that.typeRef);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        public int compareTo(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            int x = superCompareTo(o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            if (x == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                DescriptorEntry that = (DescriptorEntry)o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                // Primary key is typeRef, not nameRef.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                x = this.typeRef.compareTo(that.typeRef);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                if (x == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                    x = this.nameRef.compareTo(that.nameRef);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
            return x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        public String stringValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            return stringValueOf(nameRef, typeRef);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        static
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        String stringValueOf(Entry nameRef, Entry typeRef) {
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   494
            return qualifiedStringValue(typeRef, nameRef);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        public String prettyString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            return nameRef.stringValue()+typeRef.prettyString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        public boolean isMethod() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            return typeRef.isMethod();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        public byte getLiteralTag() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            return typeRef.getLiteralTag();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   510
    static String qualifiedStringValue(Entry e1, Entry e2) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   511
        return qualifiedStringValue(e1.stringValue(), e2.stringValue());
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   512
    }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   513
    static String qualifiedStringValue(String s1, String s234) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   514
        // Qualification by dot must decompose uniquely.  Second string might already be qualified.
24685
215fa91e1b4c 8044461: Cleanup new Boolean and single character strings
rriggs
parents: 17422
diff changeset
   515
        assert(s1.indexOf('.') < 0);
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   516
        return s1+"."+s234;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   517
    }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   518
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    public static
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
    class MemberEntry extends Entry {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        final ClassEntry classRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        final DescriptorEntry descRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        public Entry getRef(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            if (i == 0)  return classRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            if (i == 1)  return descRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        protected int computeValueHash() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            int hc2 = descRef.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            return (classRef.hashCode() + (hc2 << 8)) ^ hc2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        MemberEntry(byte tag, ClassEntry classRef, DescriptorEntry descRef) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            super(tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
            assert(isMemberTag(tag));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            this.classRef = classRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
            this.descRef  = descRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
            hashCode();  // force computation of valueHash
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        public boolean equals(Object o) {
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   541
            if (o == null || o.getClass() != MemberEntry.class) {
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   542
                return false;
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   543
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            MemberEntry that = (MemberEntry)o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            return this.classRef.eq(that.classRef)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                && this.descRef.eq(that.descRef);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        public int compareTo(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
            int x = superCompareTo(o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            if (x == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                MemberEntry that = (MemberEntry)o;
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   552
                if (Utils.SORT_MEMBERS_DESCR_MAJOR)
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   553
                    // descRef is transmitted as UDELTA5; sort it first?
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   554
                    x = this.descRef.compareTo(that.descRef);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                // Primary key is classRef.
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   556
                if (x == 0)
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   557
                    x = this.classRef.compareTo(that.classRef);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                if (x == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                    x = this.descRef.compareTo(that.descRef);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            return x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        public String stringValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
            return stringValueOf(tag, classRef, descRef);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        static
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        String stringValueOf(byte tag, ClassEntry classRef, DescriptorEntry descRef) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
            assert(isMemberTag(tag));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
            String pfx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
            switch (tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
            case CONSTANT_Fieldref:            pfx = "Field:";   break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
            case CONSTANT_Methodref:           pfx = "Method:";  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
            case CONSTANT_InterfaceMethodref:  pfx = "IMethod:"; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            default:                           pfx = tag+"???";  break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            }
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   576
            return pfx+qualifiedStringValue(classRef, descRef);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        public boolean isMethod() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            return descRef.isMethod();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
    public static
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    class SignatureEntry extends Entry {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        final Utf8Entry    formRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        final ClassEntry[] classRefs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        String             value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        Utf8Entry          asUtf8Entry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        public Entry getRef(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            if (i == 0)  return formRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
            return i-1 < classRefs.length ? classRefs[i-1] : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        SignatureEntry(String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
            super(CONSTANT_Signature);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
            value = value.intern();  // always do this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
            this.value = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
            String[] parts = structureSignature(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            formRef = getUtf8Entry(parts[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            classRefs = new ClassEntry[parts.length-1];
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   601
            for (int i = 1; i < parts.length; i++) {
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   602
                classRefs[i - 1] = getClassEntry(parts[i]);
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   603
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            hashCode();  // force computation of valueHash
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        protected int computeValueHash() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            stringValue();  // force computation of value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
            return value.hashCode() + tag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        public Utf8Entry asUtf8Entry() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
            if (asUtf8Entry == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                asUtf8Entry = getUtf8Entry(stringValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            return asUtf8Entry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        public boolean equals(Object o) {
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   619
            return (o != null && o.getClass() == SignatureEntry.class &&
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
   620
                    ((SignatureEntry)o).value.equals(value));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        public int compareTo(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
            int x = superCompareTo(o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
            if (x == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                SignatureEntry that = (SignatureEntry)o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                x = compareSignatures(this.value, that.value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
            return x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        public String stringValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
            if (value == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                value = stringValueOf(formRef, classRefs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
            return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        static
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        String stringValueOf(Utf8Entry formRef, ClassEntry[] classRefs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
            String[] parts = new String[1+classRefs.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
            parts[0] = formRef.stringValue();
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   640
            for (int i = 1; i < parts.length; i++) {
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   641
                parts[i] = classRefs[i - 1].stringValue();
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   642
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
            return flattenSignature(parts).intern();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        public int computeSize(boolean countDoublesTwice) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
            String form = formRef.stringValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
            int min = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
            int max = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
            if (isMethod()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                min = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
                max = form.indexOf(')');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
            int size = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
            for (int i = min; i < max; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
                switch (form.charAt(i)) {
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   657
                    case 'D':
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   658
                    case 'J':
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   659
                        if (countDoublesTwice) {
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   660
                            size++;
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   661
                        }
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   662
                        break;
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   663
                    case '[':
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   664
                        // Skip rest of array info.
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   665
                        while (form.charAt(i) == '[') {
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   666
                            ++i;
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   667
                        }
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   668
                        break;
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   669
                    case ';':
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   670
                        continue;
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   671
                    default:
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   672
                        assert (0 <= JAVA_SIGNATURE_CHARS.indexOf(form.charAt(i)));
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   673
                        break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                size++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
            return size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        public boolean isMethod() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
            return formRef.stringValue().charAt(0) == '(';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        public byte getLiteralTag() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
            switch (formRef.stringValue().charAt(0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
            case 'I': return CONSTANT_Integer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
            case 'J': return CONSTANT_Long;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
            case 'F': return CONSTANT_Float;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
            case 'D': return CONSTANT_Double;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
            case 'B': case 'S': case 'C': case 'Z':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                return CONSTANT_Integer;
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   690
            case 'L':
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   691
                /*
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   692
                switch (classRefs[0].stringValue()) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   693
                case "java/lang/String":
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   694
                    return CONSTANT_String;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   695
                case "java/lang/invoke/MethodHandle":
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   696
                    return CONSTANT_MethodHandle;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   697
                case "java/lang/invoke/MethodType":
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   698
                    return CONSTANT_MethodType;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   699
                default:  // java/lang/Object, etc.
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   700
                    return CONSTANT_LoadableValue;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   701
                }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   702
                */
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   703
                return CONSTANT_String;  // JDK 7 ConstantValue limited to String
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
            assert(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
            return CONSTANT_None;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
        public String prettyString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
            String s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
            if (isMethod()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
                s = formRef.stringValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
                s = s.substring(0, 1+s.indexOf(')'));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
                s = "/" + formRef.stringValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
            int i;
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   717
            while ((i = s.indexOf(';')) >= 0) {
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   718
                s = s.substring(0, i) + s.substring(i + 1);
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
   719
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
            return s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
    static int compareSignatures(String s1, String s2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        return compareSignatures(s1, s2, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
    static int compareSignatures(String s1, String s2, String[] p1, String[] p2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
        final int S1_COMES_FIRST = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
        final int S2_COMES_FIRST = +1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
        char c1 = s1.charAt(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        char c2 = s2.charAt(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        // fields before methods (because there are fewer of them)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        if (c1 != '(' && c2 == '(')  return S1_COMES_FIRST;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        if (c2 != '(' && c1 == '(')  return S2_COMES_FIRST;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        if (p1 == null)  p1 = structureSignature(s1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        if (p2 == null)  p2 = structureSignature(s2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
         // non-classes before classes (because there are fewer of them)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
         if (p1.length == 1 && p2.length > 1)  return S1_COMES_FIRST;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
         if (p2.length == 1 && p1.length > 1)  return S2_COMES_FIRST;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
         // all else being equal, use the same comparison as for Utf8 strings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
         return s1.compareTo(s2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        if (p1.length != p2.length)  return p1.length - p2.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
        int length = p1.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        for (int i = length; --i >= 0; ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
            int res = p1[i].compareTo(p2[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
            if (res != 0)  return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        assert(s1.equals(s2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
    static int countClassParts(Utf8Entry formRef) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
        int num = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        String s = formRef.stringValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
        for (int i = 0; i < s.length(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
            if (s.charAt(i) == 'L')  ++num;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        return num;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
    static String flattenSignature(String[] parts) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        String form = parts[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        if (parts.length == 1)  return form;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        int len = form.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        for (int i = 1; i < parts.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
            len += parts[i].length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
        char[] sig = new char[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
        int j = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
        int k = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
        for (int i = 0; i < form.length(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
            char ch = form.charAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
            sig[j++] = ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
            if (ch == 'L') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                String cls = parts[k++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                cls.getChars(0, cls.length(), sig, j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                j += cls.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
                //sig[j++] = ';';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
        assert(j == len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
        assert(k == parts.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        return new String(sig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   788
    private static int skipTo(char semi, String sig, int i) {
17422
c04d73570793 8013155: [pack200] improve performance of pack200
kizune
parents: 16126
diff changeset
   789
        i = sig.indexOf(semi, i);
c04d73570793 8013155: [pack200] improve performance of pack200
kizune
parents: 16126
diff changeset
   790
        return (i >= 0) ? i : sig.length();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
    static String[] structureSignature(String sig) {
17422
c04d73570793 8013155: [pack200] improve performance of pack200
kizune
parents: 16126
diff changeset
   794
        int firstl = sig.indexOf('L');
c04d73570793 8013155: [pack200] improve performance of pack200
kizune
parents: 16126
diff changeset
   795
        if (firstl < 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
            String[] parts = { sig };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
            return parts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
        }
17422
c04d73570793 8013155: [pack200] improve performance of pack200
kizune
parents: 16126
diff changeset
   799
        // Segment the string like sig.split("L\\([^;<]*\\)").
c04d73570793 8013155: [pack200] improve performance of pack200
kizune
parents: 16126
diff changeset
   800
        // N.B.: Previous version of this code did a more complex match,
c04d73570793 8013155: [pack200] improve performance of pack200
kizune
parents: 16126
diff changeset
   801
        // to next ch < ' ' or ch in [';'..'@'].  The only important
c04d73570793 8013155: [pack200] improve performance of pack200
kizune
parents: 16126
diff changeset
   802
        // characters are ';' and '<', since they are part of the
c04d73570793 8013155: [pack200] improve performance of pack200
kizune
parents: 16126
diff changeset
   803
        // signature syntax.
c04d73570793 8013155: [pack200] improve performance of pack200
kizune
parents: 16126
diff changeset
   804
        // Examples:
c04d73570793 8013155: [pack200] improve performance of pack200
kizune
parents: 16126
diff changeset
   805
        //   "(Ljava/lang/Object;IJLLoo;)V" => {"(L;IJL;)V", "java/lang/Object", "Loo"}
c04d73570793 8013155: [pack200] improve performance of pack200
kizune
parents: 16126
diff changeset
   806
        //   "Ljava/util/List<Ljava/lang/String;>;" => {"L<L;>;", "java/util/List", "java/lang/String"}
c04d73570793 8013155: [pack200] improve performance of pack200
kizune
parents: 16126
diff changeset
   807
        char[] form = null;
c04d73570793 8013155: [pack200] improve performance of pack200
kizune
parents: 16126
diff changeset
   808
        String[] parts = null;
c04d73570793 8013155: [pack200] improve performance of pack200
kizune
parents: 16126
diff changeset
   809
        for (int pass = 0; pass <= 1; pass++) {
c04d73570793 8013155: [pack200] improve performance of pack200
kizune
parents: 16126
diff changeset
   810
            // pass 0 is a sizing pass, pass 1 packs the arrays
c04d73570793 8013155: [pack200] improve performance of pack200
kizune
parents: 16126
diff changeset
   811
            int formPtr = 0;
c04d73570793 8013155: [pack200] improve performance of pack200
kizune
parents: 16126
diff changeset
   812
            int partPtr = 1;
c04d73570793 8013155: [pack200] improve performance of pack200
kizune
parents: 16126
diff changeset
   813
            int nextsemi = 0, nextangl = 0;  // next ';' or '<', or zero, or sigLen
c04d73570793 8013155: [pack200] improve performance of pack200
kizune
parents: 16126
diff changeset
   814
            int lastj = 0;
c04d73570793 8013155: [pack200] improve performance of pack200
kizune
parents: 16126
diff changeset
   815
            for (int i = firstl + 1, j; i > 0; i = sig.indexOf('L', j) + 1) {
c04d73570793 8013155: [pack200] improve performance of pack200
kizune
parents: 16126
diff changeset
   816
                // sig[i-1] is 'L', while sig[j] will be the first ';' or '<' after it
c04d73570793 8013155: [pack200] improve performance of pack200
kizune
parents: 16126
diff changeset
   817
                // each part is in sig[i .. j-1]
c04d73570793 8013155: [pack200] improve performance of pack200
kizune
parents: 16126
diff changeset
   818
                if (nextsemi < i)  nextsemi = skipTo(';', sig, i);
c04d73570793 8013155: [pack200] improve performance of pack200
kizune
parents: 16126
diff changeset
   819
                if (nextangl < i)  nextangl = skipTo('<', sig, i);
c04d73570793 8013155: [pack200] improve performance of pack200
kizune
parents: 16126
diff changeset
   820
                j = (nextsemi < nextangl ? nextsemi : nextangl);
c04d73570793 8013155: [pack200] improve performance of pack200
kizune
parents: 16126
diff changeset
   821
                if (pass != 0) {
c04d73570793 8013155: [pack200] improve performance of pack200
kizune
parents: 16126
diff changeset
   822
                    sig.getChars(lastj, i, form, formPtr);
c04d73570793 8013155: [pack200] improve performance of pack200
kizune
parents: 16126
diff changeset
   823
                    parts[partPtr] = sig.substring(i, j);
c04d73570793 8013155: [pack200] improve performance of pack200
kizune
parents: 16126
diff changeset
   824
                }
c04d73570793 8013155: [pack200] improve performance of pack200
kizune
parents: 16126
diff changeset
   825
                formPtr += (i - lastj);
c04d73570793 8013155: [pack200] improve performance of pack200
kizune
parents: 16126
diff changeset
   826
                partPtr += 1;
c04d73570793 8013155: [pack200] improve performance of pack200
kizune
parents: 16126
diff changeset
   827
                lastj = j;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
            }
17422
c04d73570793 8013155: [pack200] improve performance of pack200
kizune
parents: 16126
diff changeset
   829
            if (pass != 0) {
c04d73570793 8013155: [pack200] improve performance of pack200
kizune
parents: 16126
diff changeset
   830
                sig.getChars(lastj, sig.length(), form, formPtr);
c04d73570793 8013155: [pack200] improve performance of pack200
kizune
parents: 16126
diff changeset
   831
                break;
c04d73570793 8013155: [pack200] improve performance of pack200
kizune
parents: 16126
diff changeset
   832
            }
c04d73570793 8013155: [pack200] improve performance of pack200
kizune
parents: 16126
diff changeset
   833
            formPtr += (sig.length() - lastj);
c04d73570793 8013155: [pack200] improve performance of pack200
kizune
parents: 16126
diff changeset
   834
            form = new char[formPtr];
c04d73570793 8013155: [pack200] improve performance of pack200
kizune
parents: 16126
diff changeset
   835
            parts = new String[partPtr];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
        parts[0] = new String(form);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        //assert(flattenSignature(parts).equals(sig));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        return parts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24685
diff changeset
   842
    /** @since 1.7, JSR 292 */
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   843
    public static
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   844
    class MethodHandleEntry extends Entry {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   845
        final int refKind;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   846
        final MemberEntry memRef;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   847
        public Entry getRef(int i) { return i == 0 ? memRef : null; }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   848
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   849
        protected int computeValueHash() {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   850
            int hc2 = refKind;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   851
            return (memRef.hashCode() + (hc2 << 8)) ^ hc2;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   852
        }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   853
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   854
        MethodHandleEntry(byte refKind, MemberEntry memRef) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   855
            super(CONSTANT_MethodHandle);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   856
            assert(isRefKind(refKind));
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   857
            this.refKind = refKind;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   858
            this.memRef  = memRef;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   859
            hashCode();  // force computation of valueHash
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   860
        }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   861
        public boolean equals(Object o) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   862
            if (o == null || o.getClass() != MethodHandleEntry.class) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   863
                return false;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   864
            }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   865
            MethodHandleEntry that = (MethodHandleEntry)o;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   866
            return this.refKind == that.refKind
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   867
                && this.memRef.eq(that.memRef);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   868
        }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   869
        public int compareTo(Object o) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   870
            int x = superCompareTo(o);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   871
            if (x == 0) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   872
                MethodHandleEntry that = (MethodHandleEntry)o;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   873
                if (Utils.SORT_HANDLES_KIND_MAJOR)
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   874
                    // Primary key could be refKind.
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   875
                    x = this.refKind - that.refKind;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   876
                // Primary key is memRef, which is transmitted as UDELTA5.
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   877
                if (x == 0)
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   878
                    x = this.memRef.compareTo(that.memRef);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   879
                if (x == 0)
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   880
                    x = this.refKind - that.refKind;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   881
            }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   882
            return x;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   883
        }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   884
        public static String stringValueOf(int refKind, MemberEntry memRef) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   885
            return refKindName(refKind)+":"+memRef.stringValue();
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   886
        }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   887
        public String stringValue() {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   888
            return stringValueOf(refKind, memRef);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   889
        }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   890
    }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   891
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24685
diff changeset
   892
    /** @since 1.7, JSR 292 */
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   893
    public static
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   894
    class MethodTypeEntry extends Entry {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   895
        final SignatureEntry typeRef;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   896
        public Entry getRef(int i) { return i == 0 ? typeRef : null; }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   897
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   898
        protected int computeValueHash() {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   899
            return typeRef.hashCode() + tag;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   900
        }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   901
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   902
        MethodTypeEntry(SignatureEntry typeRef) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   903
            super(CONSTANT_MethodType);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   904
            this.typeRef  = typeRef;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   905
            hashCode();  // force computation of valueHash
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   906
        }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   907
        public boolean equals(Object o) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   908
            if (o == null || o.getClass() != MethodTypeEntry.class) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   909
                return false;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   910
            }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   911
            MethodTypeEntry that = (MethodTypeEntry)o;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   912
            return this.typeRef.eq(that.typeRef);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   913
        }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   914
        public int compareTo(Object o) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   915
            int x = superCompareTo(o);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   916
            if (x == 0) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   917
                MethodTypeEntry that = (MethodTypeEntry)o;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   918
                x = this.typeRef.compareTo(that.typeRef);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   919
            }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   920
            return x;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   921
        }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   922
        public String stringValue() {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   923
            return typeRef.stringValue();
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   924
        }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   925
    }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   926
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24685
diff changeset
   927
    /** @since 1.7, JSR 292 */
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   928
    public static
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   929
    class InvokeDynamicEntry extends Entry {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   930
        final BootstrapMethodEntry bssRef;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   931
        final DescriptorEntry descRef;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   932
        public Entry getRef(int i) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   933
            if (i == 0)  return bssRef;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   934
            if (i == 1)  return descRef;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   935
            return null;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   936
        }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   937
        protected int computeValueHash() {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   938
            int hc2 = descRef.hashCode();
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   939
            return (bssRef.hashCode() + (hc2 << 8)) ^ hc2;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   940
        }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   941
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   942
        InvokeDynamicEntry(BootstrapMethodEntry bssRef, DescriptorEntry descRef) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   943
            super(CONSTANT_InvokeDynamic);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   944
            this.bssRef  = bssRef;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   945
            this.descRef = descRef;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   946
            hashCode();  // force computation of valueHash
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   947
        }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   948
        public boolean equals(Object o) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   949
            if (o == null || o.getClass() != InvokeDynamicEntry.class) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   950
                return false;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   951
            }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   952
            InvokeDynamicEntry that = (InvokeDynamicEntry)o;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   953
            return this.bssRef.eq(that.bssRef)
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   954
                && this.descRef.eq(that.descRef);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   955
        }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   956
        public int compareTo(Object o) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   957
            int x = superCompareTo(o);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   958
            if (x == 0) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   959
                InvokeDynamicEntry that = (InvokeDynamicEntry)o;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   960
                if (Utils.SORT_INDY_BSS_MAJOR)
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   961
                    // Primary key could be bsmRef.
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   962
                    x = this.bssRef.compareTo(that.bssRef);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   963
                // Primary key is descriptor, which is transmitted as UDELTA5.
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   964
                if (x == 0)
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   965
                    x = this.descRef.compareTo(that.descRef);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   966
                if (x == 0)
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   967
                    x = this.bssRef.compareTo(that.bssRef);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   968
            }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   969
            return x;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   970
        }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   971
        public String stringValue() {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   972
            return stringValueOf(bssRef, descRef);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   973
        }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   974
        static
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   975
        String stringValueOf(BootstrapMethodEntry bssRef, DescriptorEntry descRef) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   976
            return "Indy:"+bssRef.stringValue()+"."+descRef.stringValue();
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   977
        }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   978
    }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   979
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24685
diff changeset
   980
    /** @since 1.7, JSR 292 */
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   981
    public static
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   982
    class BootstrapMethodEntry extends Entry {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   983
        final MethodHandleEntry bsmRef;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   984
        final Entry[] argRefs;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   985
        public Entry getRef(int i) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   986
            if (i == 0)  return bsmRef;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   987
            if (i-1 < argRefs.length)  return argRefs[i-1];
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   988
            return null;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   989
        }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   990
        protected int computeValueHash() {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   991
            int hc2 = bsmRef.hashCode();
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   992
            return (Arrays.hashCode(argRefs) + (hc2 << 8)) ^ hc2;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   993
        }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   994
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   995
        BootstrapMethodEntry(MethodHandleEntry bsmRef, Entry[] argRefs) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   996
            super(CONSTANT_BootstrapMethod);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   997
            this.bsmRef  = bsmRef;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   998
            this.argRefs = argRefs.clone();
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
   999
            hashCode();  // force computation of valueHash
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1000
        }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1001
        public boolean equals(Object o) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1002
            if (o == null || o.getClass() != BootstrapMethodEntry.class) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1003
                return false;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1004
            }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1005
            BootstrapMethodEntry that = (BootstrapMethodEntry)o;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1006
            return this.bsmRef.eq(that.bsmRef)
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1007
                && Arrays.equals(this.argRefs, that.argRefs);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1008
        }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1009
        public int compareTo(Object o) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1010
            int x = superCompareTo(o);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1011
            if (x == 0) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1012
                BootstrapMethodEntry that = (BootstrapMethodEntry)o;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1013
                if (Utils.SORT_BSS_BSM_MAJOR)
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1014
                    // Primary key is bsmRef.
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1015
                    x = this.bsmRef.compareTo(that.bsmRef);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1016
                // Primary key is args array length, which is transmitted as UDELTA5.
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1017
                if (x == 0)
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1018
                    x = compareArgArrays(this.argRefs, that.argRefs);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1019
                if (x == 0)
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1020
                    x = this.bsmRef.compareTo(that.bsmRef);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1021
            }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1022
            return x;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1023
        }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1024
        public String stringValue() {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1025
            return stringValueOf(bsmRef, argRefs);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1026
        }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1027
        static
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1028
        String stringValueOf(MethodHandleEntry bsmRef, Entry[] argRefs) {
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 24865
diff changeset
  1029
            StringBuilder sb = new StringBuilder(bsmRef.stringValue());
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1030
            // Arguments are formatted as "<foo;bar;baz>" instead of "[foo,bar,baz]".
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1031
            // This ensures there will be no confusion if "[,]" appear inside of names.
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1032
            char nextSep = '<';
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1033
            boolean didOne = false;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1034
            for (Entry argRef : argRefs) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1035
                sb.append(nextSep).append(argRef.stringValue());
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1036
                nextSep = ';';
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1037
            }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1038
            if (nextSep == '<')  sb.append(nextSep);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1039
            sb.append('>');
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1040
            return sb.toString();
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1041
        }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1042
        static
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1043
        int compareArgArrays(Entry[] a1, Entry[] a2) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1044
            int x = a1.length - a2.length;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1045
            if (x != 0)  return x;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1046
            for (int i = 0; i < a1.length; i++) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1047
                x = a1[i].compareTo(a2[i]);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1048
                if (x != 0)  break;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1049
            }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1050
            return x;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1051
        }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1052
    }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1053
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
    // Handy constants:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
    protected static final Entry[] noRefs = {};
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
    protected static final ClassEntry[] noClassRefs = {};
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
    /** An Index is a mapping between CP entries and small integers. */
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
  1059
    public static final
10115
eb08d08c7ef7 7060849: Eliminate pack200 build warnings
ksrini
parents: 7803
diff changeset
  1060
    class Index extends AbstractList<Entry> {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
        protected String debugName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
        protected Entry[] cpMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
        protected boolean flattenSigs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
        protected Entry[] getMap() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
            return cpMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
        protected Index(String debugName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
            this.debugName = debugName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
        protected Index(String debugName, Entry[] cpMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
            this(debugName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
            setMap(cpMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
        protected void setMap(Entry[] cpMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
            clearIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
            this.cpMap = cpMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
        }
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
  1078
        protected Index(String debugName, Collection<Entry> cpMapList) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
            this(debugName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
            setMap(cpMapList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
        }
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
  1082
        protected void setMap(Collection<Entry> cpMapList) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
            cpMap = new Entry[cpMapList.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
            cpMapList.toArray(cpMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
            setMap(cpMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
        public int size() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
            return cpMap.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
        }
10115
eb08d08c7ef7 7060849: Eliminate pack200 build warnings
ksrini
parents: 7803
diff changeset
  1090
        public Entry get(int i) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
            return cpMap[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
        public Entry getEntry(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
            // same as get(), with covariant return type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
            return cpMap[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
        // Find index of e in cpMap, or return -1 if none.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
        // As a special hack, if flattenSigs, signatures are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
        // treated as equivalent entries of cpMap.  This is wrong
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
  1102
        // from a Collection point of view, because contains()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
        // reports true for signatures, but the iterator()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
        // never produces them!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
        private int findIndexOf(Entry e) {
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
  1106
            if (indexKey == null) {
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
  1107
                initializeIndex();
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
  1108
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
            int probe = findIndexLocation(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
            if (indexKey[probe] != e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
                if (flattenSigs && e.tag == CONSTANT_Signature) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
                    SignatureEntry se = (SignatureEntry) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
                    return findIndexOf(se.asUtf8Entry());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
                return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
            int index = indexValue[probe];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
            assert(e.equals(cpMap[index]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
            return index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
        public boolean contains(Entry e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
            return findIndexOf(e) >= 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
        // Find index of e in cpMap.  Should not return -1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
        public int indexOf(Entry e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
            int index = findIndexOf(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
            if (index < 0 && verbose() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
                System.out.println("not found: "+e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
                System.out.println("       in: "+this.dumpString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
                Thread.dumpStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
            assert(index >= 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
            return index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
        }
10115
eb08d08c7ef7 7060849: Eliminate pack200 build warnings
ksrini
parents: 7803
diff changeset
  1135
        public int lastIndexOf(Entry e) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
            return indexOf(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
        public boolean assertIsSorted() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
            for (int i = 1; i < cpMap.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
                if (cpMap[i-1].compareTo(cpMap[i]) > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
                    System.out.println("Not sorted at "+(i-1)+"/"+i+": "+this.dumpString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
        // internal hash table
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
        protected Entry[] indexKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
        protected int[]   indexValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
        protected void clearIndex() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
            indexKey   = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
            indexValue = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
        private int findIndexLocation(Entry e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
            int size   = indexKey.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
            int hash   = e.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
            int probe  = hash & (size - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
            int stride = ((hash >>> 8) | 1) & (size - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
            for (;;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
                Entry e1 = indexKey[probe];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
                if (e1 == e || e1 == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
                    return probe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
                probe += stride;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
                if (probe >= size)  probe -= size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
        private void initializeIndex() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
            if (verbose() > 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
                System.out.println("initialize Index "+debugName+" ["+size()+"]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
            int hsize0 = (int)((cpMap.length + 10) * 1.5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
            int hsize = 1;
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
  1174
            while (hsize < hsize0) {
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
  1175
                hsize <<= 1;
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
  1176
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
            indexKey   = new Entry[hsize];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
            indexValue = new int[hsize];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
            for (int i = 0; i < cpMap.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
                Entry e = cpMap[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
                if (e == null)  continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
                int probe = findIndexLocation(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
                assert(indexKey[probe] == null);  // e has unique index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
                indexKey[probe] = e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
                indexValue[probe] = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
        }
10115
eb08d08c7ef7 7060849: Eliminate pack200 build warnings
ksrini
parents: 7803
diff changeset
  1188
        public Entry[] toArray(Entry[] a) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
            int sz = size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
            if (a.length < sz)  return super.toArray(a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
            System.arraycopy(cpMap, 0, a, 0, sz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
            if (a.length > sz)  a[sz] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
            return a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
        }
10115
eb08d08c7ef7 7060849: Eliminate pack200 build warnings
ksrini
parents: 7803
diff changeset
  1195
        public Entry[] toArray() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
            return toArray(new Entry[size()]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
        public Object clone() {
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
  1199
            return new Index(debugName, cpMap.clone());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
            return "Index "+debugName+" ["+size()+"]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
        public String dumpString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
            String s = toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
            s += " {\n";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
            for (int i = 0; i < cpMap.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
                s += "    "+i+": "+cpMap[i]+"\n";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
            s += "}";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
            return s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
    // Index methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
    public static
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
    Index makeIndex(String debugName, Entry[] cpMap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
        return new Index(debugName, cpMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
    public static
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
  1223
    Index makeIndex(String debugName, Collection<Entry> cpMapList) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
        return new Index(debugName, cpMapList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
    /** Sort this index (destructively) into canonical order. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
    public static
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
    void sort(Index ix) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
        // %%% Should move this into class Index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
        ix.clearIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
        Arrays.sort(ix.cpMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
        if (verbose() > 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
            System.out.println("sorted "+ix.dumpString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
    /** Return a set of indexes partitioning these entries.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
     *  The keys array must of length this.size(), and marks entries.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
     *  The result array is as long as one plus the largest key value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
     *  Entries with a negative key are dropped from the partition.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
    public static
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
    Index[] partition(Index ix, int[] keys) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
        // %%% Should move this into class Index.
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
  1245
        List<List<Entry>> parts = new ArrayList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
        Entry[] cpMap = ix.cpMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
        assert(keys.length == cpMap.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
        for (int i = 0; i < keys.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
            int key = keys[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
            if (key < 0)  continue;
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
  1251
            while (key >= parts.size()) {
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
  1252
                parts.add(null);
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
  1253
            }
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
  1254
            List<Entry> part = parts.get(key);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
            if (part == null) {
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
  1256
                parts.set(key, part = new ArrayList<>());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
            part.add(cpMap[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
        Index[] indexes = new Index[parts.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
        for (int key = 0; key < indexes.length; key++) {
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
  1262
            List<Entry> part = parts.get(key);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
            if (part == null)  continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
            indexes[key] = new Index(ix.debugName+"/part#"+key, part);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
            assert(indexes[key].indexOf(part.get(0)) == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
        return indexes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
    public static
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
    Index[] partitionByTag(Index ix) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
        // Partition by tag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
        Entry[] cpMap = ix.cpMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
        int[] keys = new int[cpMap.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
        for (int i = 0; i < keys.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
            Entry e = cpMap[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
            keys[i] = (e == null)? -1: e.tag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
        Index[] byTag = partition(ix, keys);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
        for (int tag = 0; tag < byTag.length; tag++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
            if (byTag[tag] == null)  continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
            byTag[tag].debugName = tagName(tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
        if (byTag.length < CONSTANT_Limit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
            Index[] longer = new Index[CONSTANT_Limit];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
            System.arraycopy(byTag, 0, longer, 0, byTag.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
            byTag = longer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
        return byTag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
    /** Coherent group of constant pool indexes. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
    public static
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
    class IndexGroup {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
        private Index[] indexByTag = new Index[CONSTANT_Limit];
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1295
        private Index[] indexByTagGroup;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
        private int[]   untypedFirstIndexByTag;
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1297
        private int     totalSizeQQ;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
        private Index[][] indexByTagAndClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
        /** Index of all CP entries of all types, in definition order. */
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1301
        private Index makeTagGroupIndex(byte tagGroupTag, byte[] tagsInGroup) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1302
            if (indexByTagGroup == null)
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1303
                indexByTagGroup = new Index[CONSTANT_GroupLimit - CONSTANT_GroupFirst];
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1304
            int which = tagGroupTag - CONSTANT_GroupFirst;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1305
            assert(indexByTagGroup[which] == null);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1306
            int fillp = 0;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1307
            Entry[] cpMap = null;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1308
            for (int pass = 1; pass <= 2; pass++) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
                untypedIndexOf(null);  // warm up untypedFirstIndexByTag
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1310
                for (byte tag : tagsInGroup) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
                    Index ix = indexByTag[tag];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
                    if (ix == null)  continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
                    int ixLen = ix.cpMap.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
                    if (ixLen == 0)  continue;
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1315
                    assert(tagGroupTag == CONSTANT_All
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1316
                            ? fillp == untypedFirstIndexByTag[tag]
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1317
                            : fillp  < untypedFirstIndexByTag[tag]);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1318
                    if (cpMap != null) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1319
                        assert(cpMap[fillp] == null);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1320
                        assert(cpMap[fillp+ixLen-1] == null);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1321
                        System.arraycopy(ix.cpMap, 0, cpMap, fillp, ixLen);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1322
                    }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1323
                    fillp += ixLen;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
                }
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1325
                if (cpMap == null) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1326
                    assert(pass == 1);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1327
                    // get ready for pass 2
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1328
                    cpMap = new Entry[fillp];
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1329
                    fillp = 0;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1330
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
            }
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1332
            indexByTagGroup[which] = new Index(tagName(tagGroupTag), cpMap);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1333
            return indexByTagGroup[which];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
        public int untypedIndexOf(Entry e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
            if (untypedFirstIndexByTag == null) {
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1338
                untypedFirstIndexByTag = new int[CONSTANT_Limit+1];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
                int fillp = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
                for (int i = 0; i < TAGS_IN_ORDER.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
                    byte tag = TAGS_IN_ORDER[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
                    Index ix = indexByTag[tag];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
                    if (ix == null)  continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
                    int ixLen = ix.cpMap.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
                    untypedFirstIndexByTag[tag] = fillp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
                    fillp += ixLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
                }
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1348
                untypedFirstIndexByTag[CONSTANT_Limit] = fillp;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
            if (e == null)  return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
            int tag = e.tag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
            Index ix = indexByTag[tag];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
            if (ix == null)  return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
            int idx = ix.findIndexOf(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
            if (idx >= 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
                idx += untypedFirstIndexByTag[tag];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
            return idx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
        public void initIndexByTag(byte tag, Index ix) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
            assert(indexByTag[tag] == null);  // do not init twice
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
            Entry[] cpMap = ix.cpMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
            for (int i = 0; i < cpMap.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
                // It must be a homogeneous Entry set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
                assert(cpMap[i].tag == tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
            if (tag == CONSTANT_Utf8) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
                // Special case:  First Utf8 must always be empty string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
                assert(cpMap.length == 0 || cpMap[0].stringValue().equals(""));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
            indexByTag[tag] = ix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
            // decache indexes derived from this one:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
            untypedFirstIndexByTag = null;
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1374
            indexByTagGroup = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
            if (indexByTagAndClass != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
                indexByTagAndClass[tag] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
        /** Index of all CP entries of a given tag. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
        public Index getIndexByTag(byte tag) {
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1381
            if (tag >= CONSTANT_GroupFirst)
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1382
                return getIndexByTagGroup(tag);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
            Index ix = indexByTag[tag];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
            if (ix == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
                // Make an empty one by default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
                ix = new Index(tagName(tag), new Entry[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
                indexByTag[tag] = ix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
            return ix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1392
        private Index getIndexByTagGroup(byte tag) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1393
            // pool groups:
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1394
            if (indexByTagGroup != null) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1395
                Index ix = indexByTagGroup[tag - CONSTANT_GroupFirst];
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1396
                if (ix != null)  return ix;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1397
            }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1398
            switch (tag) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1399
            case CONSTANT_All:
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1400
                return makeTagGroupIndex(CONSTANT_All, TAGS_IN_ORDER);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1401
            case CONSTANT_LoadableValue:
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1402
                    return makeTagGroupIndex(CONSTANT_LoadableValue, LOADABLE_VALUE_TAGS);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1403
            case CONSTANT_AnyMember:
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1404
                return makeTagGroupIndex(CONSTANT_AnyMember, ANY_MEMBER_TAGS);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1405
            case CONSTANT_FieldSpecific:
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1406
                // This one does not have any fixed index, since it is context-specific.
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1407
                return null;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1408
            }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1409
            throw new AssertionError("bad tag group "+tag);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1410
        }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1411
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
        /** Index of all CP entries of a given tag and class. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
        public Index getMemberIndex(byte tag, ClassEntry classRef) {
16075
32c3bc19bba7 7186957: Improve Pack200 data validation
ksrini
parents: 12544
diff changeset
  1414
            if (classRef == null)
32c3bc19bba7 7186957: Improve Pack200 data validation
ksrini
parents: 12544
diff changeset
  1415
                throw new RuntimeException("missing class reference for " + tagName(tag));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
            if (indexByTagAndClass == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
                indexByTagAndClass = new Index[CONSTANT_Limit][];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
            Index allClasses =  getIndexByTag(CONSTANT_Class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
            Index[] perClassIndexes = indexByTagAndClass[tag];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
            if (perClassIndexes == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
                // Create the partition now.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
                // Divide up all entries of the given tag according to their class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
                Index allMembers = getIndexByTag(tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
                int[] whichClasses = new int[allMembers.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
                for (int i = 0; i < whichClasses.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
                    MemberEntry e = (MemberEntry) allMembers.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
                    int whichClass = allClasses.indexOf(e.classRef);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
                    whichClasses[i] = whichClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
                perClassIndexes = partition(allMembers, whichClasses);
6313
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
  1431
                for (int i = 0; i < perClassIndexes.length; i++) {
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
  1432
                    assert (perClassIndexes[i] == null ||
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
  1433
                            perClassIndexes[i].assertIsSorted());
470912c9e214 6888127: java.util.jar.Pack200.Packer Memory Leak
ksrini
parents: 5506
diff changeset
  1434
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
                indexByTagAndClass[tag] = perClassIndexes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
            int whichClass = allClasses.indexOf(classRef);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
            return perClassIndexes[whichClass];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
        // Given the sequence of all methods of the given name and class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
        // produce the ordinal of this particular given overloading.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
        public int getOverloadingIndex(MemberEntry methodRef) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
            Index ix = getMemberIndex(methodRef.tag, methodRef.classRef);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
            Utf8Entry nameRef = methodRef.descRef.nameRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
            int ord = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
            for (int i = 0; i < ix.cpMap.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
                MemberEntry e = (MemberEntry) ix.cpMap[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
                if (e.equals(methodRef))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
                    return ord;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
                if (e.descRef.nameRef.equals(nameRef))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
                    // Found a different overloading.  Increment the ordinal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
                    ord++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
            throw new RuntimeException("should not reach here");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
        // Inverse of getOverloadingIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
        public MemberEntry getOverloadingForIndex(byte tag, ClassEntry classRef, String name, int which) {
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
  1460
            assert(name.equals(name.intern()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
            Index ix = getMemberIndex(tag, classRef);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
            int ord = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
            for (int i = 0; i < ix.cpMap.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
                MemberEntry e = (MemberEntry) ix.cpMap[i];
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
  1465
                if (e.descRef.nameRef.stringValue().equals(name)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
                    if (ord == which)  return e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
                    ord++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
            throw new RuntimeException("should not reach here");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
        public boolean haveNumbers() {
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1474
            for (byte tag : NUMBER_TAGS) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1475
                if (getIndexByTag(tag).size() > 0)  return true;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1476
            }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1477
            return false;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1478
        }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1479
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1480
        public boolean haveExtraTags() {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1481
            for (byte tag : EXTRA_TAGS) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
                if (getIndexByTag(tag).size() > 0)  return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
    /** Close the set cpRefs under the getRef(*) relation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
     *  Also, if flattenSigs, replace all signatures in cpRefs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
     *  by their equivalent Utf8s.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
     *  Also, discard null from cpRefs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
     */
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1494
    public static void completeReferencesIn(Set<Entry> cpRefs, boolean flattenSigs) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1495
         completeReferencesIn(cpRefs, flattenSigs, null);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1496
    }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1497
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
    public static
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1499
    void completeReferencesIn(Set<Entry> cpRefs, boolean flattenSigs,
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1500
                              List<BootstrapMethodEntry>bsms) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
        cpRefs.remove(null);
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
  1502
        for (ListIterator<Entry> work =
7803
56bc97d69d93 6880112: Project Coin: Port JDK core library code to use diamond operator
smarks
parents: 7795
diff changeset
  1503
                 new ArrayList<>(cpRefs).listIterator(cpRefs.size());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
             work.hasPrevious(); ) {
7795
98021fc612af 6990106: FindBugs scan - Malicious code vulnerability Warnings in com.sun.java.util.jar.pack.*
ksrini
parents: 7192
diff changeset
  1505
            Entry e = work.previous();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
            work.remove();          // pop stack
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
            assert(e != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
            if (flattenSigs && e.tag == CONSTANT_Signature) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
                SignatureEntry se = (SignatureEntry) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
                Utf8Entry      ue = se.asUtf8Entry();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
                // Totally replace e by se.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
                cpRefs.remove(se);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
                cpRefs.add(ue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
                e = ue;   // do not descend into the sig
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
            }
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1516
            if (bsms != null && e.tag == CONSTANT_BootstrapMethod) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1517
                BootstrapMethodEntry bsm = (BootstrapMethodEntry)e;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1518
                cpRefs.remove(bsm);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1519
                // move it away to the side table where it belongs
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1520
                if (!bsms.contains(bsm))
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1521
                    bsms.add(bsm);
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1522
                // fall through to recursively add refs for this entry
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1523
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
            // Recursively add the refs of e to cpRefs:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
            for (int i = 0; ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
                Entry re = e.getRef(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
                if (re == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
                    break;          // no more refs in e
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
                if (cpRefs.add(re)) // output the ref
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
                    work.add(re);   // push stack, if a new ref
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
    static double percent(int num, int den) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
        return (int)((10000.0*num)/den + 0.5) / 100.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
    public static String tagName(int tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
        switch (tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
            case CONSTANT_Utf8:                 return "Utf8";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
            case CONSTANT_Integer:              return "Integer";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
            case CONSTANT_Float:                return "Float";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
            case CONSTANT_Long:                 return "Long";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
            case CONSTANT_Double:               return "Double";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
            case CONSTANT_Class:                return "Class";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
            case CONSTANT_String:               return "String";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
            case CONSTANT_Fieldref:             return "Fieldref";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
            case CONSTANT_Methodref:            return "Methodref";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
            case CONSTANT_InterfaceMethodref:   return "InterfaceMethodref";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
            case CONSTANT_NameandType:          return "NameandType";
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1552
            case CONSTANT_MethodHandle:         return "MethodHandle";
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1553
            case CONSTANT_MethodType:           return "MethodType";
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1554
            case CONSTANT_InvokeDynamic:        return "InvokeDynamic";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
                // pseudo-tags:
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1557
            case CONSTANT_All:                  return "**All";
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1558
            case CONSTANT_None:                 return "**None";
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1559
            case CONSTANT_LoadableValue:        return "**LoadableValue";
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1560
            case CONSTANT_AnyMember:            return "**AnyMember";
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1561
            case CONSTANT_FieldSpecific:        return "*FieldSpecific";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
            case CONSTANT_Signature:            return "*Signature";
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1563
            case CONSTANT_BootstrapMethod:      return "*BootstrapMethod";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
        return "tag#"+tag;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1568
    public static String refKindName(int refKind) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1569
        switch (refKind) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1570
            case REF_getField:                  return "getField";
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1571
            case REF_getStatic:                 return "getStatic";
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1572
            case REF_putField:                  return "putField";
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1573
            case REF_putStatic:                 return "putStatic";
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1574
            case REF_invokeVirtual:             return "invokeVirtual";
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1575
            case REF_invokeStatic:              return "invokeStatic";
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1576
            case REF_invokeSpecial:             return "invokeSpecial";
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1577
            case REF_newInvokeSpecial:          return "newInvokeSpecial";
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1578
            case REF_invokeInterface:           return "invokeInterface";
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1579
        }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1580
        return "refKind#"+refKind;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1581
    }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1582
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
    // archive constant pool definition order
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
    static final byte TAGS_IN_ORDER[] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
        CONSTANT_Utf8,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
        CONSTANT_Integer,           // cp_Int
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
        CONSTANT_Float,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
        CONSTANT_Long,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
        CONSTANT_Double,
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1590
        CONSTANT_String,            // note that String=8 precedes Class=7
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
        CONSTANT_Class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
        CONSTANT_Signature,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
        CONSTANT_NameandType,       // cp_Descr
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
        CONSTANT_Fieldref,          // cp_Field
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
        CONSTANT_Methodref,         // cp_Method
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1596
        CONSTANT_InterfaceMethodref, // cp_Imethod
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1597
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1598
        // Constants defined in JDK 7 and later:
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1599
        CONSTANT_MethodHandle,
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1600
        CONSTANT_MethodType,
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1601
        CONSTANT_BootstrapMethod,  // pseudo-tag, really stored in a class attribute
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1602
        CONSTANT_InvokeDynamic
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
    static final byte TAG_ORDER[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
        TAG_ORDER = new byte[CONSTANT_Limit];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
        for (int i = 0; i < TAGS_IN_ORDER.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
            TAG_ORDER[TAGS_IN_ORDER[i]] = (byte)(i+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
        System.out.println("TAG_ORDER[] = {");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
        for (int i = 0; i < TAG_ORDER.length; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
            System.out.println("  "+TAG_ORDER[i]+",");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
        System.out.println("};");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
    }
12544
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1617
    static final byte[] NUMBER_TAGS = {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1618
        CONSTANT_Integer, CONSTANT_Float, CONSTANT_Long, CONSTANT_Double
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1619
    };
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1620
    static final byte[] EXTRA_TAGS = {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1621
        CONSTANT_MethodHandle, CONSTANT_MethodType,
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1622
        CONSTANT_BootstrapMethod, // pseudo-tag
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1623
        CONSTANT_InvokeDynamic
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1624
    };
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1625
    static final byte[] LOADABLE_VALUE_TAGS = { // for CONSTANT_LoadableValue
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1626
        CONSTANT_Integer, CONSTANT_Float, CONSTANT_Long, CONSTANT_Double,
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1627
        CONSTANT_String, CONSTANT_Class,
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1628
        CONSTANT_MethodHandle, CONSTANT_MethodType
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1629
    };
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1630
    static final byte[] ANY_MEMBER_TAGS = { // for CONSTANT_AnyMember
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1631
        CONSTANT_Fieldref, CONSTANT_Methodref, CONSTANT_InterfaceMethodref
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1632
    };
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1633
    static final byte[] FIELD_SPECIFIC_TAGS = { // for CONSTANT_FieldSpecific
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1634
        CONSTANT_Integer, CONSTANT_Float, CONSTANT_Long, CONSTANT_Double,
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1635
        CONSTANT_String
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1636
    };
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1637
    static {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1638
        assert(
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1639
            verifyTagOrder(TAGS_IN_ORDER) &&
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1640
            verifyTagOrder(NUMBER_TAGS) &&
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1641
            verifyTagOrder(EXTRA_TAGS) &&
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1642
            verifyTagOrder(LOADABLE_VALUE_TAGS) &&
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1643
            verifyTagOrder(ANY_MEMBER_TAGS) &&
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1644
            verifyTagOrder(FIELD_SPECIFIC_TAGS)
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1645
        );
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1646
    }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1647
    private static boolean verifyTagOrder(byte[] tags) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1648
        int prev = -1;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1649
        for (byte tag : tags) {
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1650
            int next = TAG_ORDER[tag];
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1651
            assert(next > 0) : "tag not found: "+tag;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1652
            assert(TAGS_IN_ORDER[next-1] == tag) : "tag repeated: "+tag+" => "+next+" => "+TAGS_IN_ORDER[next-1];
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1653
            assert(prev < next) : "tags not in order: "+Arrays.toString(tags)+" at "+tag;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1654
            prev = next;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1655
        }
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1656
        return true;
5768f2e096de 6981776: Pack200 must support -target 7 bytecodes
ksrini
parents: 10115
diff changeset
  1657
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
}