annotate graal/com.oracle.graal.options/src/com/oracle/graal/options/OptionsLoader.java @ 23209:f35e653aa876

moved @Option mechanism from JVMCI to Graal (GRAAL-1371)
author Doug Simon <doug.simon@oracle.com>
date Mon, 21 Dec 2015 16:19:35 +0100
parents
children 86780d6ac391
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
23209
f35e653aa876 moved @Option mechanism from JVMCI to Graal (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1 /*
f35e653aa876 moved @Option mechanism from JVMCI to Graal (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
f35e653aa876 moved @Option mechanism from JVMCI to Graal (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f35e653aa876 moved @Option mechanism from JVMCI to Graal (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
4 *
f35e653aa876 moved @Option mechanism from JVMCI to Graal (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
f35e653aa876 moved @Option mechanism from JVMCI to Graal (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
f35e653aa876 moved @Option mechanism from JVMCI to Graal (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
f35e653aa876 moved @Option mechanism from JVMCI to Graal (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
8 *
f35e653aa876 moved @Option mechanism from JVMCI to Graal (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
f35e653aa876 moved @Option mechanism from JVMCI to Graal (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f35e653aa876 moved @Option mechanism from JVMCI to Graal (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
f35e653aa876 moved @Option mechanism from JVMCI to Graal (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
f35e653aa876 moved @Option mechanism from JVMCI to Graal (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
13 * accompanied this code).
f35e653aa876 moved @Option mechanism from JVMCI to Graal (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
14 *
f35e653aa876 moved @Option mechanism from JVMCI to Graal (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
f35e653aa876 moved @Option mechanism from JVMCI to Graal (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
f35e653aa876 moved @Option mechanism from JVMCI to Graal (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f35e653aa876 moved @Option mechanism from JVMCI to Graal (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
18 *
f35e653aa876 moved @Option mechanism from JVMCI to Graal (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f35e653aa876 moved @Option mechanism from JVMCI to Graal (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
f35e653aa876 moved @Option mechanism from JVMCI to Graal (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
21 * questions.
f35e653aa876 moved @Option mechanism from JVMCI to Graal (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
22 */
f35e653aa876 moved @Option mechanism from JVMCI to Graal (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
23 package com.oracle.graal.options;
f35e653aa876 moved @Option mechanism from JVMCI to Graal (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
24
f35e653aa876 moved @Option mechanism from JVMCI to Graal (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
25 import java.util.ServiceLoader;
f35e653aa876 moved @Option mechanism from JVMCI to Graal (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
26 import java.util.SortedMap;
f35e653aa876 moved @Option mechanism from JVMCI to Graal (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
27 import java.util.TreeMap;
f35e653aa876 moved @Option mechanism from JVMCI to Graal (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
28
f35e653aa876 moved @Option mechanism from JVMCI to Graal (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
29 /**
f35e653aa876 moved @Option mechanism from JVMCI to Graal (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
30 * Helper class used to load option descriptors. Only to be used in the slow-path.
f35e653aa876 moved @Option mechanism from JVMCI to Graal (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
31 */
f35e653aa876 moved @Option mechanism from JVMCI to Graal (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
32 public class OptionsLoader {
f35e653aa876 moved @Option mechanism from JVMCI to Graal (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
33 public static final SortedMap<String, OptionDescriptor> options = new TreeMap<>();
f35e653aa876 moved @Option mechanism from JVMCI to Graal (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
34
f35e653aa876 moved @Option mechanism from JVMCI to Graal (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
35 /**
f35e653aa876 moved @Option mechanism from JVMCI to Graal (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
36 * Initializes {@link #options} from {@link Options} services.
f35e653aa876 moved @Option mechanism from JVMCI to Graal (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
37 */
f35e653aa876 moved @Option mechanism from JVMCI to Graal (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
38 static {
f35e653aa876 moved @Option mechanism from JVMCI to Graal (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
39 for (OptionDescriptors opts : ServiceLoader.load(OptionDescriptors.class, OptionsLoader.class.getClassLoader())) {
f35e653aa876 moved @Option mechanism from JVMCI to Graal (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
40 for (OptionDescriptor desc : opts) {
f35e653aa876 moved @Option mechanism from JVMCI to Graal (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
41 String name = desc.getName();
f35e653aa876 moved @Option mechanism from JVMCI to Graal (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
42 OptionDescriptor existing = options.put(name, desc);
f35e653aa876 moved @Option mechanism from JVMCI to Graal (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
43 assert existing == null : "Option named \"" + name + "\" has multiple definitions: " + existing.getLocation() + " and " + desc.getLocation();
f35e653aa876 moved @Option mechanism from JVMCI to Graal (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
44 }
f35e653aa876 moved @Option mechanism from JVMCI to Graal (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
45 }
f35e653aa876 moved @Option mechanism from JVMCI to Graal (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
46 }
f35e653aa876 moved @Option mechanism from JVMCI to Graal (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
47 }