jdk/make/modules/tools/src/com/sun/classanalyzer/ClassFileParser.java
author jcoomes
Thu, 20 May 2010 08:32:11 -0700
changeset 5545 c531522ec99a
parent 4524 697144bd8b04
child 5506 202f599c92aa
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4524
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
     1
/*
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
     2
 * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
     4
 *
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
     7
 * published by the Free Software Foundation.
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
     8
 *
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    13
 * accompanied this code).
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    14
 *
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    18
 *
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    21
 * have any questions.
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    22
 *
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    23
 */
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    24
package com.sun.classanalyzer;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    25
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    26
import com.sun.tools.classfile.*;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    27
import com.sun.tools.classfile.Type.*;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    28
import com.sun.tools.classfile.Descriptor.InvalidDescriptor;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    29
import static com.sun.tools.classfile.AccessFlags.*;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    30
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    31
import java.io.BufferedInputStream;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    32
import java.io.File;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    33
import java.io.FileInputStream;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    34
import java.io.IOException;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    35
import java.io.InputStream;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    36
import java.util.List;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    37
import java.util.Set;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    38
import java.util.TreeSet;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    39
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    40
/**
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    41
 *
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    42
 * @author Mandy Chung
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    43
 */
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    44
public class ClassFileParser {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    45
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    46
    final Klass this_klass;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    47
    final ClassFile classfile;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    48
    final ConstantPoolParser constantPoolParser;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    49
    final AnnotationParser annotationParser;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    50
    final CodeAttributeParser codeAttributeParser;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    51
    private final boolean buildDeps;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    52
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    53
    protected ClassFileParser(InputStream in, long size, boolean buildDeps) throws IOException {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    54
        try {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    55
            this.classfile = ClassFile.read(in);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    56
            this.this_klass = getKlass(this.classfile);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    57
            this.buildDeps = buildDeps;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    58
            this.constantPoolParser = new ConstantPoolParser(this);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    59
            this.annotationParser = new AnnotationParser(this);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    60
            this.codeAttributeParser = new CodeAttributeParser(this);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    61
        } catch (ConstantPoolException ex) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    62
            throw new RuntimeException(ex);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    63
        }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    64
    }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    65
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    66
    private Klass getKlass(ClassFile cf) throws ConstantPoolException {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    67
        Klass k = Klass.getKlass(cf.getName());
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    68
        k.setAccessFlags(cf.access_flags.flags);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    69
        k.setFileSize(cf.byteLength());
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    70
        return k;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    71
    }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    72
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    73
    public static ClassFileParser newParser(InputStream in, long size, boolean buildDeps) throws IOException {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    74
        return new ClassFileParser(in, size, buildDeps);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    75
    }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    76
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    77
    public static ClassFileParser newParser(String classPathname, boolean buildDeps) throws IOException {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    78
        return newParser(new File(classPathname), buildDeps);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    79
    }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    80
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    81
    public static ClassFileParser newParser(File f, boolean buildDeps) throws IOException {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    82
        BufferedInputStream in = new BufferedInputStream(new FileInputStream(f));
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    83
        try {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    84
            return newParser(in, f.length(), buildDeps);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    85
        } finally {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    86
            in.close();
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    87
        }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    88
    }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    89
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    90
    public void parseDependency(boolean publicAPIs) throws IOException {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    91
        if (publicAPIs && !classfile.access_flags.is(ACC_PUBLIC)) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    92
            // process public APIs only
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    93
            return;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    94
        }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    95
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    96
        parseClassInfo();
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    97
        if (!publicAPIs) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    98
            // parse all references in the classfile
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
    99
            constantPoolParser.parseDependency();
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   100
        }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   101
        parseMethods(publicAPIs);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   102
        parseFields(publicAPIs);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   103
    }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   104
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   105
    void parseClassInfo() throws IOException {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   106
        ConstantPool cpool = classfile.constant_pool;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   107
        try {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   108
            Signature_attribute sigAttr = (Signature_attribute) classfile.attributes.get(Attribute.Signature);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   109
            if (sigAttr == null) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   110
                // use info from class file header
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   111
                if (classfile.isClass() && classfile.super_class != 0) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   112
                    String sn = classfile.getSuperclassName();
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   113
                    addExtends(sn);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   114
                }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   115
                for (int i = 0; i < classfile.interfaces.length; i++) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   116
                    String interf = classfile.getInterfaceName(i);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   117
                    if (classfile.isClass()) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   118
                        addImplements(interf);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   119
                    } else {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   120
                        addExtends(interf);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   121
                    }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   122
                }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   123
            } else {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   124
                Type t = sigAttr.getParsedSignature().getType(cpool);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   125
                // The signature parser cannot disambiguate between a
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   126
                // FieldType and a ClassSignatureType that only contains a superclass type.
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   127
                if (t instanceof Type.ClassSigType) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   128
                    Type.ClassSigType cst = Type.ClassSigType.class.cast(t);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   129
                    if (cst.superclassType != null) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   130
                        for (Klass k : getKlass(cst.superclassType)) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   131
                            addExtends(k);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   132
                        }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   133
                    }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   134
                    if (cst.superinterfaceTypes != null) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   135
                        for (Type t1 : cst.superinterfaceTypes) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   136
                            for (Klass k : getKlass(t1)) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   137
                                addImplements(k);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   138
                            }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   139
                        }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   140
                    }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   141
                } else {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   142
                    for (Klass k : getKlass(t)) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   143
                        addExtends(k);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   144
                    }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   145
                }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   146
            }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   147
            // parse attributes
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   148
            annotationParser.parseAttributes(classfile.attributes);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   149
        } catch (ConstantPoolException ex) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   150
            throw new RuntimeException(ex);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   151
        }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   152
    }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   153
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   154
    private void parseFields(boolean publicAPIs) throws IOException {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   155
        ConstantPool cpool = classfile.constant_pool;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   156
        for (Field f : classfile.fields) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   157
            try {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   158
                AccessFlags flags = f.access_flags;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   159
                if (publicAPIs && !flags.is(ACC_PUBLIC) && !flags.is(ACC_PROTECTED)) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   160
                    continue;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   161
                }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   162
                String fieldname = f.getName(cpool);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   163
                Signature_attribute sigAttr = (Signature_attribute) f.attributes.get(Attribute.Signature);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   164
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   165
                if (sigAttr == null) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   166
                    Set<Klass> types = parseDescriptor(f.descriptor);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   167
                    String info = getFlag(flags) + " " + f.descriptor.getFieldType(cpool) + " " + fieldname;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   168
                    addFieldTypes(types, info, flags);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   169
                } else {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   170
                    Type t = sigAttr.getParsedSignature().getType(cpool);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   171
                    String info = getFlag(flags) + " " + t + " " + fieldname;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   172
                    addFieldTypes(getKlass(t), info, flags);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   173
                }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   174
                // parse attributes
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   175
                annotationParser.parseAttributes(f.attributes);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   176
            } catch (ConstantPoolException ex) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   177
                throw new RuntimeException(ex);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   178
            } catch (InvalidDescriptor ex) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   179
                throw new RuntimeException(ex);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   180
            }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   181
        }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   182
    }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   183
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   184
    private void parseMethods(boolean publicAPIs) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   185
        for (Method m : classfile.methods) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   186
            if (publicAPIs && !m.access_flags.is(ACC_PUBLIC) && !m.access_flags.is(ACC_PROTECTED)) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   187
                // only interest in the API level
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   188
                return;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   189
            }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   190
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   191
            parseMethod(m);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   192
        }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   193
    }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   194
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   195
    String checkClassName(String classname) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   196
        int i = 0;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   197
        while (i < classname.length()) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   198
            switch (classname.charAt(i)) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   199
                case 'Z':
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   200
                case 'B':
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   201
                case 'C':
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   202
                case 'S':
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   203
                case 'I':
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   204
                case 'J':
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   205
                case 'F':
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   206
                case 'D':
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   207
                    return "";
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   208
                case 'L':
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   209
                    if (!classname.endsWith(";")) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   210
                        throw new RuntimeException("Invalid classname " + classname);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   211
                    }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   212
                    return classname.substring(i + 1, classname.length() - 1);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   213
                case '[':
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   214
                    i++;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   215
                    break;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   216
                default:
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   217
                    if (classname.endsWith(";")) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   218
                        throw new RuntimeException("Invalid classname " + classname);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   219
                    }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   220
                    return classname;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   221
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   222
            }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   223
        }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   224
        throw new RuntimeException("Invalid classname " + classname);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   225
    }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   226
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   227
    private void addExtends(String classname) throws IOException {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   228
        if (!buildDeps) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   229
            return;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   230
        }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   231
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   232
        addExtends(Klass.getKlass(classname));
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   233
    }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   234
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   235
    private void addExtends(Klass k) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   236
        if (!buildDeps) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   237
            return;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   238
        }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   239
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   240
        ResolutionInfo resInfo = ResolutionInfo.resolvedExtends(this_klass, k);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   241
        resInfo.setPublicAccess(classfile.access_flags.is(ACC_PUBLIC));
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   242
        this_klass.addDep(k, resInfo);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   243
        k.addReferrer(this_klass, resInfo);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   244
    }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   245
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   246
    private void addImplements(String classname) throws IOException {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   247
        if (!buildDeps) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   248
            return;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   249
        }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   250
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   251
        addImplements(Klass.getKlass(classname));
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   252
    }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   253
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   254
    private void addImplements(Klass k) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   255
        if (!buildDeps) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   256
            return;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   257
        }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   258
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   259
        ResolutionInfo resInfo = ResolutionInfo.resolvedImplements(this_klass, k);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   260
        resInfo.setPublicAccess(classfile.access_flags.is(ACC_PUBLIC));
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   261
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   262
        this_klass.addDep(k, resInfo);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   263
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   264
        k.addReferrer(this_klass, resInfo);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   265
    }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   266
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   267
    private Set<Klass> getKlass(Type type) throws IOException {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   268
        Set<Klass> refTypes = new TreeSet<Klass>();
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   269
        if (!buildDeps) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   270
            return refTypes;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   271
        }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   272
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   273
        type.accept(typevisitor, refTypes);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   274
        return refTypes;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   275
    }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   276
    private Type.Visitor<Void, Set<Klass>> typevisitor = new Type.Visitor<Void, Set<Klass>>() {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   277
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   278
        public Void visitSimpleType(SimpleType type, Set<Klass> klasses) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   279
            // nop
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   280
            return null;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   281
        }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   282
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   283
        public Void visitArrayType(ArrayType type, Set<Klass> klasses) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   284
            try {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   285
                klasses.addAll(getKlass(type.elemType));
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   286
            } catch (IOException ex) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   287
                throw new RuntimeException(ex);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   288
            }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   289
            return null;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   290
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   291
        }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   292
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   293
        public Void visitMethodType(MethodType type, Set<Klass> klasses) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   294
            throw new InternalError("Unexpected type " + type);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   295
        }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   296
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   297
        public Void visitClassSigType(ClassSigType type, Set<Klass> klasses) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   298
            try {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   299
                if (type.superclassType != null) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   300
                    klasses.addAll(getKlass(type.superclassType));
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   301
                }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   302
                if (type.superinterfaceTypes != null) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   303
                    for (Type t : type.superinterfaceTypes) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   304
                        klasses.addAll(getKlass(t));
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   305
                    }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   306
                }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   307
                if (type.typeParamTypes != null) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   308
                    for (Type t : type.typeParamTypes) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   309
                        klasses.addAll(getKlass(t));
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   310
                    }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   311
                }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   312
            } catch (IOException ex) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   313
                throw new RuntimeException(ex);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   314
            }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   315
            return null;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   316
        }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   317
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   318
        public Void visitClassType(ClassType type, Set<Klass> klasses) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   319
            klasses.add(Klass.getKlass(type.getBinaryName()));
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   320
            if (type.typeArgs != null) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   321
                for (Type t : type.typeArgs) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   322
                    try {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   323
                        klasses.addAll(getKlass(t));
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   324
                    } catch (IOException ex) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   325
                        throw new RuntimeException(ex);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   326
                    }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   327
                }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   328
            }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   329
            return null;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   330
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   331
        }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   332
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   333
        public Void visitTypeParamType(TypeParamType type, Set<Klass> klasses) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   334
            try {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   335
                if (type.classBound != null) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   336
                    klasses.addAll(getKlass(type.classBound));
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   337
                }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   338
                if (type.interfaceBounds != null) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   339
                    for (Type t : type.interfaceBounds) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   340
                        klasses.addAll(getKlass(t));
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   341
                    }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   342
                }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   343
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   344
            } catch (IOException ex) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   345
                throw new RuntimeException(ex);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   346
            }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   347
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   348
            return null;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   349
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   350
        }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   351
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   352
        public Void visitWildcardType(WildcardType type, Set<Klass> klasses) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   353
            if (type.boundType != null) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   354
                try {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   355
                    klasses.addAll(getKlass(type.boundType));
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   356
                } catch (IOException ex) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   357
                    throw new RuntimeException(ex);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   358
                }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   359
            }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   360
            return null;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   361
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   362
        }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   363
    };
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   364
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   365
    private void printMethod(Method m) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   366
        try {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   367
            System.out.println("parsing " + m.getName(classfile.constant_pool) + "(" +
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   368
                    m.descriptor.getParameterTypes(classfile.constant_pool) + ") return type " +
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   369
                    m.descriptor.getReturnType(classfile.constant_pool));
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   370
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   371
        } catch (ConstantPoolException ex) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   372
        } catch (InvalidDescriptor ex) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   373
        }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   374
    }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   375
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   376
    private static StringBuilder appendWord(StringBuilder sb, String word) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   377
        if (sb.length() > 0) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   378
            sb.append(" ");
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   379
        }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   380
        sb.append(word);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   381
        return sb;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   382
    }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   383
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   384
    private static String getFlag(AccessFlags flags) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   385
        StringBuilder modifier = new StringBuilder();
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   386
        if (flags.is(ACC_PUBLIC)) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   387
            modifier.append("public");
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   388
        }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   389
        if (flags.is(ACC_PRIVATE)) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   390
            modifier.append("private");
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   391
        }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   392
        if (flags.is(ACC_PROTECTED)) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   393
            modifier.append("protected");
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   394
        }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   395
        if (flags.is(ACC_STATIC)) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   396
            appendWord(modifier, "static");
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   397
        }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   398
        if (flags.is(ACC_FINAL)) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   399
            appendWord(modifier, "final");
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   400
        }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   401
        if (flags.is(ACC_SYNCHRONIZED)) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   402
            // return "synchronized";
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   403
        }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   404
        if (flags.is(0x80)) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   405
            // return (t == Type.Field ? "transient" : null);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   406
            // return "transient";
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   407
        }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   408
        if (flags.is(ACC_VOLATILE)) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   409
            // return "volatile";
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   410
        }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   411
        if (flags.is(ACC_NATIVE)) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   412
            // return "native";
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   413
        }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   414
        if (flags.is(ACC_ABSTRACT)) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   415
            appendWord(modifier, "abstract");
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   416
        }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   417
        if (flags.is(ACC_STRICT)) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   418
            // return "strictfp";
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   419
        }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   420
        if (flags.is(ACC_MODULE)) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   421
            appendWord(modifier, "module");
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   422
        }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   423
        return modifier.toString();
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   424
    }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   425
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   426
    private Klass.Method toKlassMethod(Method m, Descriptor d) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   427
        try {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   428
            ConstantPool cpool = classfile.constant_pool;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   429
            String methodname = m.getName(cpool);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   430
            StringBuilder sb = new StringBuilder();
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   431
            sb.append(getFlag(m.access_flags));
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   432
            if (methodname.equals("<init>")) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   433
                String s = this_klass.getBasename() + d.getParameterTypes(cpool);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   434
                appendWord(sb, s);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   435
            } else if (methodname.equals("<clinit>")) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   436
                // <clinit>
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   437
                appendWord(sb, methodname);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   438
            } else {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   439
                String s = d.getReturnType(cpool) + " " + methodname + d.getParameterTypes(cpool);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   440
                appendWord(sb, s);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   441
            }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   442
            String signature = sb.toString().replace('/', '.');
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   443
            return this_klass.getMethod(methodname, signature);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   444
        } catch (ConstantPoolException ex) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   445
            throw new RuntimeException(ex);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   446
        } catch (InvalidDescriptor ex) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   447
            throw new RuntimeException(ex);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   448
        }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   449
    }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   450
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   451
    Klass.Method parseMethod(Method m) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   452
        AccessFlags flags = m.access_flags;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   453
        Descriptor d;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   454
        List<? extends Type> methodExceptions = null;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   455
        try {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   456
            ConstantPool cpool = classfile.constant_pool;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   457
            Klass.Method kmethod;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   458
            Signature_attribute sigAttr = (Signature_attribute) m.attributes.get(Attribute.Signature);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   459
            if (sigAttr == null) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   460
                d = m.descriptor;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   461
                Set<Klass> types = parseDescriptor(d);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   462
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   463
                kmethod = toKlassMethod(m, d);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   464
                addMethodTypes(types, kmethod, flags);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   465
            } else {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   466
                Type.MethodType methodType;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   467
                Signature methodSig = sigAttr.getParsedSignature();
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   468
                d = methodSig;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   469
                try {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   470
                    kmethod = toKlassMethod(m, d);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   471
                    methodType = (Type.MethodType) methodSig.getType(cpool);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   472
                    addMethodTypes(getKlass(methodType.returnType), kmethod, flags);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   473
                    if (methodType.paramTypes != null) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   474
                        for (Type t : methodType.paramTypes) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   475
                            addMethodTypes(getKlass(t), kmethod, flags);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   476
                        }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   477
                    }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   478
                    if (methodType.typeParamTypes != null) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   479
                        for (Type t : methodType.typeParamTypes) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   480
                            addMethodTypes(getKlass(t), kmethod, flags);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   481
                        }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   482
                    }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   483
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   484
                    methodExceptions = methodType.throwsTypes;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   485
                    if (methodExceptions != null) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   486
                        if (methodExceptions.size() == 0) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   487
                            methodExceptions = null;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   488
                        } else {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   489
                            for (Type t : methodExceptions) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   490
                                addCheckedExceptionTypes(getKlass(t), kmethod, flags);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   491
                            }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   492
                        }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   493
                    }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   494
                } catch (ConstantPoolException e) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   495
                    throw new RuntimeException(e);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   496
                }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   497
            }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   498
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   499
            Attribute e_attr = m.attributes.get(Attribute.Exceptions);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   500
            if (e_attr != null && methodExceptions == null) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   501
                // if there are generic exceptions, there must be erased exceptions
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   502
                if (e_attr instanceof Exceptions_attribute) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   503
                    Exceptions_attribute exceptions = (Exceptions_attribute) e_attr;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   504
                    for (int i = 0; i < exceptions.number_of_exceptions; i++) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   505
                        String classname = checkClassName(exceptions.getException(i, classfile.constant_pool));
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   506
                        if (classname.length() > 0 && buildDeps) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   507
                            Klass to = Klass.getKlass(classname);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   508
                            ResolutionInfo resInfo = ResolutionInfo.resolvedCheckedException(this_klass, to, kmethod);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   509
                            resInfo.setPublicAccess(flags.is(ACC_PUBLIC));
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   510
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   511
                            this_klass.addDep(to, resInfo);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   512
                            to.addReferrer(this_klass, resInfo);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   513
                        }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   514
                    }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   515
                } else {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   516
                    throw new RuntimeException("Invalid attribute: " + e_attr);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   517
                }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   518
            }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   519
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   520
            Code_attribute c_attr = (Code_attribute) m.attributes.get(Attribute.Code);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   521
            if (c_attr != null) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   522
                codeAttributeParser.parse(c_attr, kmethod);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   523
            }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   524
            kmethod.isAbstract = classfile.access_flags.is(ACC_ABSTRACT);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   525
            kmethod.setCodeLength(m.byteLength());
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   526
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   527
            // parse annotation attributes
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   528
            annotationParser.parseAttributes(m.attributes, kmethod);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   529
            return kmethod;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   530
        } catch (ConstantPoolException ex) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   531
            throw new RuntimeException(ex);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   532
        } catch (IOException ex) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   533
            throw new RuntimeException(ex);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   534
        }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   535
    }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   536
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   537
    private void addFieldTypes(Set<Klass> types, String info, AccessFlags flags) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   538
        if (types.isEmpty() || !buildDeps) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   539
            return;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   540
        }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   541
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   542
        for (Klass to : types) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   543
            ResolutionInfo resInfo = ResolutionInfo.resolvedField(this_klass, to, info);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   544
            resInfo.setPublicAccess(flags.is(ACC_PUBLIC));
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   545
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   546
            this_klass.addDep(to, resInfo);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   547
            to.addReferrer(this_klass, resInfo);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   548
        }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   549
    }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   550
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   551
    private void addReferencedTypes(Method m, Descriptor d, AccessFlags flags) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   552
        Set<Klass> types = parseDescriptor(d);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   553
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   554
        Klass.Method method = toKlassMethod(m, d);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   555
        addMethodTypes(types, method, flags);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   556
    }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   557
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   558
    private void addMethodTypes(Set<Klass> types, Klass.Method method, AccessFlags flags) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   559
        if (types.isEmpty() || !buildDeps) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   560
            return;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   561
        }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   562
        for (Klass to : types) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   563
            ResolutionInfo resInfo = ResolutionInfo.resolvedMethodSignature(this_klass, to, method);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   564
            resInfo.setPublicAccess(flags.is(ACC_PUBLIC));
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   565
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   566
            this_klass.addDep(to, resInfo);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   567
            to.addReferrer(this_klass, resInfo);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   568
        }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   569
    }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   570
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   571
    private void addCheckedExceptionTypes(Set<Klass> types, Klass.Method method, AccessFlags flags) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   572
        if (types.isEmpty() || !buildDeps) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   573
            return;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   574
        }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   575
        for (Klass to : types) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   576
            ResolutionInfo resInfo = ResolutionInfo.resolvedCheckedException(this_klass, to, method);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   577
            resInfo.setPublicAccess(flags.is(ACC_PUBLIC));
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   578
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   579
            this_klass.addDep(to, resInfo);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   580
            to.addReferrer(this_klass, resInfo);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   581
        }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   582
    }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   583
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   584
    private Set<Klass> parseDescriptor(Descriptor d) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   585
        Set<Klass> types = new TreeSet<Klass>();
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   586
        try {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   587
            String desc = d.getValue(classfile.constant_pool);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   588
            int p = 0;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   589
            while (p < desc.length()) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   590
                String type;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   591
                char ch;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   592
                switch (ch = desc.charAt(p++)) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   593
                    case '(':
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   594
                    case ')':
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   595
                    case '[':
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   596
                    case 'B':
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   597
                    case 'C':
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   598
                    case 'D':
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   599
                    case 'F':
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   600
                    case 'I':
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   601
                    case 'J':
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   602
                    case 'S':
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   603
                    case 'Z':
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   604
                    case 'V':
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   605
                        continue;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   606
                    case 'L':
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   607
                        int sep = desc.indexOf(';', p);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   608
                        if (sep == -1) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   609
                            throw new RuntimeException("Invalid descriptor: " + (p - 1) + " " + desc);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   610
                        }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   611
                        type = checkClassName(desc.substring(p, sep));
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   612
                        p = sep + 1;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   613
                        break;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   614
                    default:
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   615
                        throw new RuntimeException("Invalid descriptor: " + (p - 1) + " " + desc);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   616
                }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   617
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   618
                if (!type.isEmpty() && buildDeps) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   619
                    Klass to = Klass.getKlass(type);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   620
                    types.add(to);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   621
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   622
                }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   623
            }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   624
        } catch (ConstantPoolException ex) {
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   625
            throw new RuntimeException(ex);
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   626
        }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   627
        return types;
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   628
    }
697144bd8b04 6909572: Add a new target for building modules
mchung
parents:
diff changeset
   629
}