Mercurial > hg > graal-jvmci-8
comparison graal/com.oracle.nfi/src/com/oracle/nfi/NativeFunctionInterfaceRuntime.java @ 21614:2f92172fa320
Truffle and NFI implementations are now accessed via JVMCI services instead of being hard coded in the VM (JBS:GRAAL-51)
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Sun, 31 May 2015 13:42:47 +0200 |
parents | 13f8c249edb8 |
children | 91b861398ad6 |
comparison
equal
deleted
inserted
replaced
21613:60154926b513 | 21614:2f92172fa320 |
---|---|
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.nfi; | 23 package com.oracle.nfi; |
24 | 24 |
25 import com.oracle.jvmci.service.*; | |
25 import com.oracle.nfi.api.*; | 26 import com.oracle.nfi.api.*; |
26 | 27 |
27 /** | 28 /** |
28 * Class for obtaining the {@link NativeFunctionInterface} (if any) provided by the VM. | 29 * Class for obtaining the {@link NativeFunctionInterface} (if any) provided by the VM. |
29 */ | 30 */ |
30 public final class NativeFunctionInterfaceRuntime { | 31 public final class NativeFunctionInterfaceRuntime { |
31 private static final NativeFunctionInterface INSTANCE; | 32 private static final NativeFunctionInterface INSTANCE; |
32 | |
33 /** | |
34 * Creates a new {@link NativeFunctionInterface}. | |
35 * | |
36 * @throws UnsatisfiedLinkError if not running on a VM that provides a | |
37 * {@link NativeFunctionInterface} | |
38 */ | |
39 private static native NativeFunctionInterface createInterface(); | |
40 | 33 |
41 /** | 34 /** |
42 * Gets the {@link NativeFunctionInterface} (if any) provided by the VM. | 35 * Gets the {@link NativeFunctionInterface} (if any) provided by the VM. |
43 * | 36 * |
44 * @return null if the VM does not provide a {@link NativeFunctionInterface} | 37 * @return null if the VM does not provide a {@link NativeFunctionInterface} |
46 public static NativeFunctionInterface getNativeFunctionInterface() { | 39 public static NativeFunctionInterface getNativeFunctionInterface() { |
47 return INSTANCE; | 40 return INSTANCE; |
48 } | 41 } |
49 | 42 |
50 static { | 43 static { |
51 NativeFunctionInterface instance; | 44 |
52 try { | 45 NativeFunctionInterface instance = null; |
53 instance = createInterface(); | 46 NativeFunctionInterfaceAccess access = Services.loadSingle(NativeFunctionInterfaceAccess.class, false); |
54 } catch (UnsatisfiedLinkError e) { | 47 if (access != null) { |
55 instance = null; | 48 instance = access.getNativeFunctionInterface(); |
56 } | 49 } |
57 INSTANCE = instance; | 50 INSTANCE = instance; |
58 } | 51 } |
59 } | 52 } |