langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Profile.java
author chegar
Sun, 17 Aug 2014 15:52:32 +0100
changeset 25874 83c19f00452c
parent 22163 langtools/src/share/classes/com/sun/tools/javac/jvm/Profile.java@3651128c74eb
child 34752 9c262a013456
permissions -rw-r--r--
8054834: Modular Source Code Reviewed-by: alanb, chegar, ihse, mduigou Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, magnus.ihse.bursie@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, paul.sandoz@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15724
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
     1
/*
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
     2
 * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
     4
 *
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    10
 *
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    15
 * accompanied this code).
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    16
 *
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    20
 *
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    23
 * questions.
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    24
 */
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    25
package com.sun.tools.javac.jvm;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    26
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    27
import com.sun.tools.javac.util.Context;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    28
import com.sun.tools.javac.util.Options;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    29
import java.util.EnumSet;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    30
import java.util.Set;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    31
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    32
import static com.sun.tools.javac.main.Option.PROFILE;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    33
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    34
/** The target profile.
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    35
 *
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    36
 *  <p><b>This is NOT part of any supported API.
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    37
 *  If you write code that depends on this, you do so at your own risk.
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    38
 *  This code and its internal interfaces are subject to change or
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    39
 *  deletion without notice.</b>
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    40
 */
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    41
public enum Profile {
22151
cb8daa93eeb1 8028545: Add -source 9 and -target 9 to javac
darcy
parents: 15724
diff changeset
    42
    COMPACT1("compact1", 1, Target.JDK1_8, Target.JDK1_9),
cb8daa93eeb1 8028545: Add -source 9 and -target 9 to javac
darcy
parents: 15724
diff changeset
    43
    COMPACT2("compact2", 2, Target.JDK1_8, Target.JDK1_9),
cb8daa93eeb1 8028545: Add -source 9 and -target 9 to javac
darcy
parents: 15724
diff changeset
    44
    COMPACT3("compact3", 3, Target.JDK1_8, Target.JDK1_9),
15724
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    45
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    46
    DEFAULT {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    47
        @Override
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    48
        public boolean isValid(Target t) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    49
            return true;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    50
        }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    51
    };
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    52
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22151
diff changeset
    53
    private static final Context.Key<Profile> profileKey = new Context.Key<>();
15724
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    54
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    55
    public static Profile instance(Context context) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    56
        Profile instance = context.get(profileKey);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    57
        if (instance == null) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    58
            Options options = Options.instance(context);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    59
            String profileString = options.get(PROFILE);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    60
            if (profileString != null) instance = lookup(profileString);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    61
            if (instance == null) instance = DEFAULT;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    62
            context.put(profileKey, instance);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    63
        }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    64
        return instance;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    65
    }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    66
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    67
    public final String name;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    68
    public final int value;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    69
    final Set<Target> targets;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    70
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    71
    Profile() {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    72
        name = null;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    73
        value = Integer.MAX_VALUE;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    74
        targets = null;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    75
    }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    76
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    77
    Profile(String name, int value, Target t, Target... targets) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    78
        this.name = name;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    79
        this.value = value;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    80
        this.targets = EnumSet.of(t, targets);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    81
    }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    82
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    83
    public static Profile lookup(String name) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    84
        // the set of values is small enough to do linear search
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    85
        for (Profile p: values()) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    86
            if (name.equals(p.name))
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    87
                return p;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    88
        }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    89
        return null;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    90
    }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    91
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    92
    public static Profile lookup(int value) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    93
        // the set of values is small enough to do linear search
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    94
        for (Profile p: values()) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    95
            if (value == p.value)
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    96
                return p;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    97
        }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    98
        return null;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
    99
    }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   100
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   101
    public boolean isValid(Target t) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   102
        return targets.contains(t);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   103
    }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents:
diff changeset
   104
}