annotate graal/com.oracle.graal.api.runtime/src/com/oracle/graal/api/runtime/Graal.java @ 21538:c1e2fdb5fea3

removed more dependencies from JVMCI classes to non-JVMCI classes (JBS:GRAAL-53)
author Doug Simon <doug.simon@oracle.com>
date Mon, 25 May 2015 17:20:39 +0200
parents e37d1fe9f332
children b1530a6cce8c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5499
8d7d009a54d8 Introduction of com.oracle.graal.api project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
1 /*
21527
07b088d61d5d added HotSpotJVMCIRuntime* classes, replaced references to HotSpotGraalRuntime in VM with HotSpotJVMCIRuntime (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 16397
diff changeset
2 * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
5499
8d7d009a54d8 Introduction of com.oracle.graal.api project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8d7d009a54d8 Introduction of com.oracle.graal.api project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
4 *
8d7d009a54d8 Introduction of com.oracle.graal.api project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
8d7d009a54d8 Introduction of com.oracle.graal.api project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
8d7d009a54d8 Introduction of com.oracle.graal.api project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
8d7d009a54d8 Introduction of com.oracle.graal.api project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
8 *
8d7d009a54d8 Introduction of com.oracle.graal.api project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
8d7d009a54d8 Introduction of com.oracle.graal.api project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8d7d009a54d8 Introduction of com.oracle.graal.api project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
8d7d009a54d8 Introduction of com.oracle.graal.api project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
8d7d009a54d8 Introduction of com.oracle.graal.api project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
13 * accompanied this code).
8d7d009a54d8 Introduction of com.oracle.graal.api project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
14 *
8d7d009a54d8 Introduction of com.oracle.graal.api project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
8d7d009a54d8 Introduction of com.oracle.graal.api project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
8d7d009a54d8 Introduction of com.oracle.graal.api project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
8d7d009a54d8 Introduction of com.oracle.graal.api project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
18 *
8d7d009a54d8 Introduction of com.oracle.graal.api project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
8d7d009a54d8 Introduction of com.oracle.graal.api project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
8d7d009a54d8 Introduction of com.oracle.graal.api project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
21 * questions.
8d7d009a54d8 Introduction of com.oracle.graal.api project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
22 */
6540
31aa76ffd3bb Rename project graal.api to graal.api.runtime
Christian Wimmer <christian.wimmer@oracle.com>
parents: 5627
diff changeset
23 package com.oracle.graal.api.runtime;
5499
8d7d009a54d8 Introduction of com.oracle.graal.api project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
24
21527
07b088d61d5d added HotSpotJVMCIRuntime* classes, replaced references to HotSpotGraalRuntime in VM with HotSpotJVMCIRuntime (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 16397
diff changeset
25 import java.util.*;
07b088d61d5d added HotSpotJVMCIRuntime* classes, replaced references to HotSpotGraalRuntime in VM with HotSpotJVMCIRuntime (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 16397
diff changeset
26
21538
c1e2fdb5fea3 removed more dependencies from JVMCI classes to non-JVMCI classes (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21530
diff changeset
27 import com.oracle.jvmci.runtime.*;
c1e2fdb5fea3 removed more dependencies from JVMCI classes to non-JVMCI classes (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 21530
diff changeset
28
14125
e09829e6680f implement initial security model for Graal (JBS:GRAAL-22)
Doug Simon <doug.simon@oracle.com>
parents: 12488
diff changeset
29 import sun.reflect.*;
e09829e6680f implement initial security model for Graal (JBS:GRAAL-22)
Doug Simon <doug.simon@oracle.com>
parents: 12488
diff changeset
30
21527
07b088d61d5d added HotSpotJVMCIRuntime* classes, replaced references to HotSpotGraalRuntime in VM with HotSpotJVMCIRuntime (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 16397
diff changeset
31 /**
07b088d61d5d added HotSpotJVMCIRuntime* classes, replaced references to HotSpotGraalRuntime in VM with HotSpotJVMCIRuntime (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 16397
diff changeset
32 * Access point for {@linkplain #getRuntime() retrieving} the single {@link GraalRuntime} instance.
07b088d61d5d added HotSpotJVMCIRuntime* classes, replaced references to HotSpotGraalRuntime in VM with HotSpotJVMCIRuntime (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 16397
diff changeset
33 */
5499
8d7d009a54d8 Introduction of com.oracle.graal.api project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
34 public class Graal {
8d7d009a54d8 Introduction of com.oracle.graal.api project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
35
21527
07b088d61d5d added HotSpotJVMCIRuntime* classes, replaced references to HotSpotGraalRuntime in VM with HotSpotJVMCIRuntime (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 16397
diff changeset
36 private static final GraalRuntime runtime = initializeRuntime();
5499
8d7d009a54d8 Introduction of com.oracle.graal.api project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
37
21527
07b088d61d5d added HotSpotJVMCIRuntime* classes, replaced references to HotSpotGraalRuntime in VM with HotSpotJVMCIRuntime (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 16397
diff changeset
38 private static GraalRuntime initializeRuntime() {
21530
e37d1fe9f332 assert that at most one GraalRuntimeFactory is available
Doug Simon <doug.simon@oracle.com>
parents: 21527
diff changeset
39 GraalRuntime rt = null;
21527
07b088d61d5d added HotSpotJVMCIRuntime* classes, replaced references to HotSpotGraalRuntime in VM with HotSpotJVMCIRuntime (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 16397
diff changeset
40 for (GraalRuntimeFactory factory : Services.load(GraalRuntimeFactory.class)) {
21530
e37d1fe9f332 assert that at most one GraalRuntimeFactory is available
Doug Simon <doug.simon@oracle.com>
parents: 21527
diff changeset
41 assert rt == null : String.format("Multiple %s implementations found: %s, %s", GraalRuntime.class.getName(), rt.getClass().getName(), factory.getRuntime().getClass().getName());
e37d1fe9f332 assert that at most one GraalRuntimeFactory is available
Doug Simon <doug.simon@oracle.com>
parents: 21527
diff changeset
42 rt = factory.getRuntime();
e37d1fe9f332 assert that at most one GraalRuntimeFactory is available
Doug Simon <doug.simon@oracle.com>
parents: 21527
diff changeset
43 }
e37d1fe9f332 assert that at most one GraalRuntimeFactory is available
Doug Simon <doug.simon@oracle.com>
parents: 21527
diff changeset
44 if (rt != null) {
e37d1fe9f332 assert that at most one GraalRuntimeFactory is available
Doug Simon <doug.simon@oracle.com>
parents: 21527
diff changeset
45 return rt;
21527
07b088d61d5d added HotSpotJVMCIRuntime* classes, replaced references to HotSpotGraalRuntime in VM with HotSpotJVMCIRuntime (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 16397
diff changeset
46 }
07b088d61d5d added HotSpotJVMCIRuntime* classes, replaced references to HotSpotGraalRuntime in VM with HotSpotJVMCIRuntime (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 16397
diff changeset
47 return new InvalidGraalRuntime();
07b088d61d5d added HotSpotJVMCIRuntime* classes, replaced references to HotSpotGraalRuntime in VM with HotSpotJVMCIRuntime (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 16397
diff changeset
48 }
5499
8d7d009a54d8 Introduction of com.oracle.graal.api project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
49
21527
07b088d61d5d added HotSpotJVMCIRuntime* classes, replaced references to HotSpotGraalRuntime in VM with HotSpotJVMCIRuntime (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 16397
diff changeset
50 /**
07b088d61d5d added HotSpotJVMCIRuntime* classes, replaced references to HotSpotGraalRuntime in VM with HotSpotJVMCIRuntime (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 16397
diff changeset
51 * Gets the singleton {@link GraalRuntime} instance available to the application.
07b088d61d5d added HotSpotJVMCIRuntime* classes, replaced references to HotSpotGraalRuntime in VM with HotSpotJVMCIRuntime (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 16397
diff changeset
52 */
5499
8d7d009a54d8 Introduction of com.oracle.graal.api project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
53 public static GraalRuntime getRuntime() {
8d7d009a54d8 Introduction of com.oracle.graal.api project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
54 return runtime;
8d7d009a54d8 Introduction of com.oracle.graal.api project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
55 }
8d7d009a54d8 Introduction of com.oracle.graal.api project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
56
21527
07b088d61d5d added HotSpotJVMCIRuntime* classes, replaced references to HotSpotGraalRuntime in VM with HotSpotJVMCIRuntime (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 16397
diff changeset
57 /**
07b088d61d5d added HotSpotJVMCIRuntime* classes, replaced references to HotSpotGraalRuntime in VM with HotSpotJVMCIRuntime (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 16397
diff changeset
58 * Gets a capability provided by the {@link GraalRuntime} instance available to the application.
07b088d61d5d added HotSpotJVMCIRuntime* classes, replaced references to HotSpotGraalRuntime in VM with HotSpotJVMCIRuntime (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 16397
diff changeset
59 *
07b088d61d5d added HotSpotJVMCIRuntime* classes, replaced references to HotSpotGraalRuntime in VM with HotSpotJVMCIRuntime (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 16397
diff changeset
60 * @throws UnsupportedOperationException if the capability is not available
07b088d61d5d added HotSpotJVMCIRuntime* classes, replaced references to HotSpotGraalRuntime in VM with HotSpotJVMCIRuntime (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 16397
diff changeset
61 */
14129
9864ae31e1fe add @CallerSensitive annotations (JBS:GRAAL-22)
Andreas Woess <andreas.woess@jku.at>
parents: 14125
diff changeset
62 @CallerSensitive
5627
e1b29c516354 Implement addEntryMethod in boot image generator. Add Graal.getRequiredCapability utility to Graal class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5523
diff changeset
63 public static <T> T getRequiredCapability(Class<T> clazz) {
e1b29c516354 Implement addEntryMethod in boot image generator. Add Graal.getRequiredCapability utility to Graal class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5523
diff changeset
64 T t = getRuntime().getCapability(clazz);
e1b29c516354 Implement addEntryMethod in boot image generator. Add Graal.getRequiredCapability utility to Graal class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5523
diff changeset
65 if (t == null) {
8574
b82ffd0c4ed2 Improved error message for Graal API capability queries.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
66 String javaHome = System.getProperty("java.home");
b82ffd0c4ed2 Improved error message for Graal API capability queries.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
67 String vmName = System.getProperty("java.vm.name");
21527
07b088d61d5d added HotSpotJVMCIRuntime* classes, replaced references to HotSpotGraalRuntime in VM with HotSpotJVMCIRuntime (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 16397
diff changeset
68 Formatter errorMessage = new Formatter();
8574
b82ffd0c4ed2 Improved error message for Graal API capability queries.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
69 if (runtime.getClass() == InvalidGraalRuntime.class) {
21527
07b088d61d5d added HotSpotJVMCIRuntime* classes, replaced references to HotSpotGraalRuntime in VM with HotSpotJVMCIRuntime (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 16397
diff changeset
70 errorMessage.format("The VM does not support the Graal API.%n");
8574
b82ffd0c4ed2 Improved error message for Graal API capability queries.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
71 } else {
21527
07b088d61d5d added HotSpotJVMCIRuntime* classes, replaced references to HotSpotGraalRuntime in VM with HotSpotJVMCIRuntime (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 16397
diff changeset
72 errorMessage.format("The VM does not expose required Graal capability %s.%n", clazz.getName());
8574
b82ffd0c4ed2 Improved error message for Graal API capability queries.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
73 }
21527
07b088d61d5d added HotSpotJVMCIRuntime* classes, replaced references to HotSpotGraalRuntime in VM with HotSpotJVMCIRuntime (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 16397
diff changeset
74 errorMessage.format("Currently used Java home directory is %s.%n", javaHome);
07b088d61d5d added HotSpotJVMCIRuntime* classes, replaced references to HotSpotGraalRuntime in VM with HotSpotJVMCIRuntime (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents: 16397
diff changeset
75 errorMessage.format("Currently used VM configuration is: %s", vmName);
8574
b82ffd0c4ed2 Improved error message for Graal API capability queries.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
76 throw new UnsupportedOperationException(errorMessage.toString());
5627
e1b29c516354 Implement addEntryMethod in boot image generator. Add Graal.getRequiredCapability utility to Graal class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5523
diff changeset
77 }
e1b29c516354 Implement addEntryMethod in boot image generator. Add Graal.getRequiredCapability utility to Graal class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5523
diff changeset
78 return t;
e1b29c516354 Implement addEntryMethod in boot image generator. Add Graal.getRequiredCapability utility to Graal class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5523
diff changeset
79 }
8574
b82ffd0c4ed2 Improved error message for Graal API capability queries.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
80
b82ffd0c4ed2 Improved error message for Graal API capability queries.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
81 private static final class InvalidGraalRuntime implements GraalRuntime {
b82ffd0c4ed2 Improved error message for Graal API capability queries.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
82
b82ffd0c4ed2 Improved error message for Graal API capability queries.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
83 @Override
b82ffd0c4ed2 Improved error message for Graal API capability queries.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
84 public String getName() {
b82ffd0c4ed2 Improved error message for Graal API capability queries.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
85 return "";
b82ffd0c4ed2 Improved error message for Graal API capability queries.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
86 }
b82ffd0c4ed2 Improved error message for Graal API capability queries.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
87
b82ffd0c4ed2 Improved error message for Graal API capability queries.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
88 @Override
b82ffd0c4ed2 Improved error message for Graal API capability queries.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
89 public <T> T getCapability(Class<T> clazz) {
b82ffd0c4ed2 Improved error message for Graal API capability queries.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
90 return null;
b82ffd0c4ed2 Improved error message for Graal API capability queries.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
91 }
b82ffd0c4ed2 Improved error message for Graal API capability queries.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
92 }
5499
8d7d009a54d8 Introduction of com.oracle.graal.api project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
93 }