langtools/src/jdk.dev/share/classes/com/sun/tools/jdeps/Profile.java
author attila
Wed, 01 Oct 2014 10:26:25 +0200
changeset 26888 2722a9c501a5
parent 25874 83c19f00452c
child 27579 d1a63c99cdd5
permissions -rw-r--r--
8059370: Unnecessary work in deoptimizing recompilation Reviewed-by: jlaskey, lagergren
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16550
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
     1
/*
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 21503
diff changeset
     2
 * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
16550
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
     4
 *
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    10
 *
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    15
 * accompanied this code).
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    16
 *
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    20
 *
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    23
 * questions.
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    24
 */
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    25
package com.sun.tools.jdeps;
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    26
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    27
import java.io.IOException;
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    28
import java.util.*;
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    29
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    30
/**
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    31
 * Build the profile information from ct.sym if exists.
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    32
 */
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    33
enum Profile {
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    34
    COMPACT1("compact1", 1, "java.compact1"),
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    35
    COMPACT2("compact2", 2, "java.compact2"),
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    36
    COMPACT3("compact3", 3, "java.compact3"),
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    37
    FULL_JRE("Full JRE", 4, "java.se");
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    38
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    39
    final String name;
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    40
    final int profile;
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    41
    final String moduleName;
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    42
    final Set<Module> modules = new HashSet<>();
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    43
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    44
    Profile(String name, int profile, String moduleName) {
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    45
        this.name = name;
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    46
        this.profile = profile;
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    47
        this.moduleName = moduleName;
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    48
    }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    49
25442
755ff386d1ac 8029548: (jdeps) use @jdk.Exported to determine supported vs JDK internal API
mchung
parents: 21503
diff changeset
    50
    public String profileName() {
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    51
        return name;
16550
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    52
    }
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    53
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    54
    @Override
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    55
    public String toString() {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    56
        return moduleName;
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    57
    }
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    58
16550
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    59
    public static int getProfileCount() {
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    60
        return JDK.isEmpty() ? 0 : Profile.values().length;
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    61
    }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    62
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    63
    /**
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    64
     * Returns the Profile for the given package name; null if not found.
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    65
     */
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    66
    public static Profile getProfile(String pn) {
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    67
        for (Profile p : Profile.values()) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    68
            for (Module m : p.modules) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    69
                if (m.packages().contains(pn)) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    70
                    return p;
21046
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    71
                }
ebf16a1a6328 8015912: jdeps support to output in dot file format
mchung
parents: 16550
diff changeset
    72
            }
16550
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    73
        }
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    74
        return null;
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    75
    }
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    76
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    77
    /*
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    78
     * Returns the Profile for a given Module; null if not found.
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    79
     */
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    80
    public static Profile getProfile(Module m) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    81
        for (Profile p : Profile.values()) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    82
            if (p.modules.contains(m)) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    83
                return p;
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    84
            }
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    85
        }
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    86
        return null;
16550
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    87
    }
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
    88
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    89
    final static Set<Module> JDK = new HashSet<>();
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    90
    static void initProfiles() {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    91
        for (Profile p : Profile.values()) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    92
            Module m = PlatformClassPath.findModule(p.moduleName);
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    93
            if (m == null)
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    94
                throw new Error(p.moduleName + " doesn't exist");
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    95
            p.modules.add(m);
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    96
            JDK.add(m);
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    97
            for (String n : m.requires().keySet()) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    98
                Module d = PlatformClassPath.findModule(n);
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
    99
                if (d == null)
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   100
                    throw new Error(n + " doesn't exist");
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   101
                p.modules.add(d);
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   102
                JDK.add(d);
16550
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
   103
            }
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   104
        }
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   105
    }
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   106
    // for debugging
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   107
    public static void main(String[] args) throws IOException {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   108
        // find platform modules
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   109
        PlatformClassPath.getArchives(null);
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   110
        if (Profile.getProfileCount() == 0) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   111
            System.err.println("No profile is present in this JDK");
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   112
        }
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   113
        for (Profile p : Profile.values()) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   114
            String profileName = p.name;
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   115
            System.out.format("%2d: %-10s  %s%n", p.profile, profileName, p.modules);
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   116
            for (Module m: p.modules) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   117
                System.out.format("module %s%n", m.name());
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   118
                System.out.format("   requires %s%n", m.requires());
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   119
                for (Map.Entry<String,Set<String>> e: m.exports().entrySet()) {
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   120
                    System.out.format("   exports %s %s%n", e.getKey(),
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   121
                        e.getValue().isEmpty() ? "" : "to " + e.getValue());
16550
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
   122
                }
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
   123
            }
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
   124
        }
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   125
        System.out.println("All JDK modules:-");
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   126
        JDK.stream().sorted(Comparator.comparing(Module::name))
83c19f00452c 8054834: Modular Source Code
chegar
parents: 25442
diff changeset
   127
           .forEach(m -> System.out.println(m));
16550
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
   128
    }
f20e2521f3df 8005428: Update jdeps to read the same profile information as by javac
mchung
parents:
diff changeset
   129
}