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