annotate graal/com.oracle.graal.api.runtime/src/com/oracle/graal/api/runtime/Graal.java @ 21527:07b088d61d5d

added HotSpotJVMCIRuntime* classes, replaced references to HotSpotGraalRuntime in VM with HotSpotJVMCIRuntime (JBS:GRAAL-53)
author Doug Simon <doug.simon@oracle.com>
date Fri, 22 May 2015 23:26:20 +0200
parents 9ca36e4e3137
children e37d1fe9f332
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
14125
e09829e6680f implement initial security model for Graal (JBS:GRAAL-22)
Doug Simon <doug.simon@oracle.com>
parents: 12488
diff changeset
27 import sun.reflect.*;
e09829e6680f implement initial security model for Graal (JBS:GRAAL-22)
Doug Simon <doug.simon@oracle.com>
parents: 12488
diff changeset
28
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
29 /**
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
30 * 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
31 */
5499
8d7d009a54d8 Introduction of com.oracle.graal.api project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
32 public class Graal {
8d7d009a54d8 Introduction of com.oracle.graal.api project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
33
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
34 private static final GraalRuntime runtime = initializeRuntime();
5499
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 GraalRuntime initializeRuntime() {
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
37 for (GraalRuntimeFactory factory : Services.load(GraalRuntimeFactory.class)) {
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 return factory.getRuntime();
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
39 }
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 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
41 }
5499
8d7d009a54d8 Introduction of com.oracle.graal.api project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
42
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
43 /**
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
44 * 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
45 */
5499
8d7d009a54d8 Introduction of com.oracle.graal.api project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
46 public static GraalRuntime getRuntime() {
8d7d009a54d8 Introduction of com.oracle.graal.api project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
47 return runtime;
8d7d009a54d8 Introduction of com.oracle.graal.api project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
48 }
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 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
52 *
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
53 * @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
54 */
14129
9864ae31e1fe add @CallerSensitive annotations (JBS:GRAAL-22)
Andreas Woess <andreas.woess@jku.at>
parents: 14125
diff changeset
55 @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
56 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
57 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
58 if (t == null) {
8574
b82ffd0c4ed2 Improved error message for Graal API capability queries.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
59 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
60 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
61 Formatter errorMessage = new Formatter();
8574
b82ffd0c4ed2 Improved error message for Graal API capability queries.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
62 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
63 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
64 } 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
65 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
66 }
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
67 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
68 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
69 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
70 }
e1b29c516354 Implement addEntryMethod in boot image generator. Add Graal.getRequiredCapability utility to Graal class.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5523
diff changeset
71 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
72 }
8574
b82ffd0c4ed2 Improved error message for Graal API capability queries.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
73
b82ffd0c4ed2 Improved error message for Graal API capability queries.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
74 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
75
b82ffd0c4ed2 Improved error message for Graal API capability queries.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
76 @Override
b82ffd0c4ed2 Improved error message for Graal API capability queries.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
77 public String getName() {
b82ffd0c4ed2 Improved error message for Graal API capability queries.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
78 return "";
b82ffd0c4ed2 Improved error message for Graal API capability queries.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
79 }
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 @Override
b82ffd0c4ed2 Improved error message for Graal API capability queries.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
82 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
83 return null;
b82ffd0c4ed2 Improved error message for Graal API capability queries.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
84 }
b82ffd0c4ed2 Improved error message for Graal API capability queries.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 7530
diff changeset
85 }
5499
8d7d009a54d8 Introduction of com.oracle.graal.api project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
86 }