comparison 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
comparison
equal deleted inserted replaced
21526:1da7aef31a08 21527:07b088d61d5d
1 /* 1 /*
2 * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
20 * or visit www.oracle.com if you need additional information or have any 20 * or visit www.oracle.com if you need additional information or have any
21 * questions. 21 * questions.
22 */ 22 */
23 package com.oracle.graal.api.runtime; 23 package com.oracle.graal.api.runtime;
24 24
25 import java.util.*;
26
25 import sun.reflect.*; 27 import sun.reflect.*;
26 28
29 /**
30 * Access point for {@linkplain #getRuntime() retrieving} the single {@link GraalRuntime} instance.
31 */
27 public class Graal { 32 public class Graal {
28 33
29 private static final GraalRuntime runtime; 34 private static final GraalRuntime runtime = initializeRuntime();
30 35
31 private static native GraalRuntime initializeRuntime(); 36 private static GraalRuntime initializeRuntime() {
37 for (GraalRuntimeFactory factory : Services.load(GraalRuntimeFactory.class)) {
38 return factory.getRuntime();
39 }
40 return new InvalidGraalRuntime();
41 }
32 42
43 /**
44 * Gets the singleton {@link GraalRuntime} instance available to the application.
45 */
33 public static GraalRuntime getRuntime() { 46 public static GraalRuntime getRuntime() {
34 return runtime; 47 return runtime;
35 } 48 }
36 49
37 static { 50 /**
38 GraalRuntime rt; 51 * Gets a capability provided by the {@link GraalRuntime} instance available to the application.
39 try { 52 *
40 rt = initializeRuntime(); 53 * @throws UnsupportedOperationException if the capability is not available
41 } catch (UnsatisfiedLinkError e) { 54 */
42 rt = new InvalidGraalRuntime();
43 }
44 runtime = rt;
45 }
46
47 @CallerSensitive 55 @CallerSensitive
48 public static <T> T getRequiredCapability(Class<T> clazz) { 56 public static <T> T getRequiredCapability(Class<T> clazz) {
49 T t = getRuntime().getCapability(clazz); 57 T t = getRuntime().getCapability(clazz);
50 if (t == null) { 58 if (t == null) {
51 String javaHome = System.getProperty("java.home"); 59 String javaHome = System.getProperty("java.home");
52 String vmName = System.getProperty("java.vm.name"); 60 String vmName = System.getProperty("java.vm.name");
53 StringBuilder errorMessage = new StringBuilder(); 61 Formatter errorMessage = new Formatter();
54 if (runtime.getClass() == InvalidGraalRuntime.class) { 62 if (runtime.getClass() == InvalidGraalRuntime.class) {
55 errorMessage.append(String.format("The VM does not support the Graal API.\n")); 63 errorMessage.format("The VM does not support the Graal API.%n");
56 } else { 64 } else {
57 errorMessage.append(String.format("The VM does not expose required Graal capability %s.\n", clazz.getName())); 65 errorMessage.format("The VM does not expose required Graal capability %s.%n", clazz.getName());
58 } 66 }
59 errorMessage.append(String.format("Currently used Java home directory is %s.\n", javaHome)); 67 errorMessage.format("Currently used Java home directory is %s.%n", javaHome);
60 errorMessage.append(String.format("Currently used VM configuration is: %s", vmName)); 68 errorMessage.format("Currently used VM configuration is: %s", vmName);
61 throw new UnsupportedOperationException(errorMessage.toString()); 69 throw new UnsupportedOperationException(errorMessage.toString());
62 } 70 }
63 return t; 71 return t;
64 } 72 }
65 73