Mercurial > hg > graal-compiler
annotate graal/com.oracle.nfi/src/com/oracle/nfi/NativeFunctionInterfaceRuntime.java @ 23117:8aecb496a8be
TraceRA: TraceAllocationPhase: directly pass context to phases.
author | Josef Eisl <josef.eisl@jku.at> |
---|---|
date | Mon, 30 Nov 2015 11:23:16 +0100 |
parents | 615f3bbbb174 |
children | 56359eb3abfa |
rev | line source |
---|---|
16691
dd8449afc086
GNFI: move GNFI interfaces to oracle.nfi - interface does not depend on graal
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
1 /* |
dd8449afc086
GNFI: move GNFI interfaces to oracle.nfi - interface does not depend on graal
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
dd8449afc086
GNFI: move GNFI interfaces to oracle.nfi - interface does not depend on graal
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
dd8449afc086
GNFI: move GNFI interfaces to oracle.nfi - interface does not depend on graal
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
4 * |
dd8449afc086
GNFI: move GNFI interfaces to oracle.nfi - interface does not depend on graal
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
dd8449afc086
GNFI: move GNFI interfaces to oracle.nfi - interface does not depend on graal
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
dd8449afc086
GNFI: move GNFI interfaces to oracle.nfi - interface does not depend on graal
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
dd8449afc086
GNFI: move GNFI interfaces to oracle.nfi - interface does not depend on graal
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
8 * |
dd8449afc086
GNFI: move GNFI interfaces to oracle.nfi - interface does not depend on graal
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
dd8449afc086
GNFI: move GNFI interfaces to oracle.nfi - interface does not depend on graal
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
dd8449afc086
GNFI: move GNFI interfaces to oracle.nfi - interface does not depend on graal
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
dd8449afc086
GNFI: move GNFI interfaces to oracle.nfi - interface does not depend on graal
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
dd8449afc086
GNFI: move GNFI interfaces to oracle.nfi - interface does not depend on graal
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
13 * accompanied this code). |
dd8449afc086
GNFI: move GNFI interfaces to oracle.nfi - interface does not depend on graal
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
14 * |
dd8449afc086
GNFI: move GNFI interfaces to oracle.nfi - interface does not depend on graal
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
dd8449afc086
GNFI: move GNFI interfaces to oracle.nfi - interface does not depend on graal
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
dd8449afc086
GNFI: move GNFI interfaces to oracle.nfi - interface does not depend on graal
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
dd8449afc086
GNFI: move GNFI interfaces to oracle.nfi - interface does not depend on graal
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
18 * |
dd8449afc086
GNFI: move GNFI interfaces to oracle.nfi - interface does not depend on graal
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
dd8449afc086
GNFI: move GNFI interfaces to oracle.nfi - interface does not depend on graal
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
dd8449afc086
GNFI: move GNFI interfaces to oracle.nfi - interface does not depend on graal
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
21 * questions. |
dd8449afc086
GNFI: move GNFI interfaces to oracle.nfi - interface does not depend on graal
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
22 */ |
dd8449afc086
GNFI: move GNFI interfaces to oracle.nfi - interface does not depend on graal
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
23 package com.oracle.nfi; |
dd8449afc086
GNFI: move GNFI interfaces to oracle.nfi - interface does not depend on graal
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
24 |
22646
05183a084a08
updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents:
22039
diff
changeset
|
25 import java.lang.reflect.Method; |
21894
91b861398ad6
removed dependency from NFI to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
21614
diff
changeset
|
26 |
22646
05183a084a08
updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents:
22039
diff
changeset
|
27 import com.oracle.nfi.api.NativeFunctionInterface; |
05183a084a08
updated imports to be explicit and added checkstyle rule to forbid * imports
Doug Simon <doug.simon@oracle.com>
parents:
22039
diff
changeset
|
28 import com.oracle.nfi.api.NativeFunctionInterfaceAccess; |
16691
dd8449afc086
GNFI: move GNFI interfaces to oracle.nfi - interface does not depend on graal
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
29 |
16704 | 30 /** |
16705 | 31 * Class for obtaining the {@link NativeFunctionInterface} (if any) provided by the VM. |
16704 | 32 */ |
16691
dd8449afc086
GNFI: move GNFI interfaces to oracle.nfi - interface does not depend on graal
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
33 public final class NativeFunctionInterfaceRuntime { |
16705 | 34 private static final NativeFunctionInterface INSTANCE; |
16691
dd8449afc086
GNFI: move GNFI interfaces to oracle.nfi - interface does not depend on graal
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
35 |
16704 | 36 /** |
16705 | 37 * Gets the {@link NativeFunctionInterface} (if any) provided by the VM. |
38 * | |
39 * @return null if the VM does not provide a {@link NativeFunctionInterface} | |
40 */ | |
16691
dd8449afc086
GNFI: move GNFI interfaces to oracle.nfi - interface does not depend on graal
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
41 public static NativeFunctionInterface getNativeFunctionInterface() { |
16705 | 42 return INSTANCE; |
16691
dd8449afc086
GNFI: move GNFI interfaces to oracle.nfi - interface does not depend on graal
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
43 } |
dd8449afc086
GNFI: move GNFI interfaces to oracle.nfi - interface does not depend on graal
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
44 |
dd8449afc086
GNFI: move GNFI interfaces to oracle.nfi - interface does not depend on graal
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
45 static { |
21614
2f92172fa320
Truffle and NFI implementations are now accessed via JVMCI services instead of being hard coded in the VM (JBS:GRAAL-51)
Doug Simon <doug.simon@oracle.com>
parents:
16705
diff
changeset
|
46 |
2f92172fa320
Truffle and NFI implementations are now accessed via JVMCI services instead of being hard coded in the VM (JBS:GRAAL-51)
Doug Simon <doug.simon@oracle.com>
parents:
16705
diff
changeset
|
47 NativeFunctionInterface instance = null; |
21894
91b861398ad6
removed dependency from NFI to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
21614
diff
changeset
|
48 |
91b861398ad6
removed dependency from NFI to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
21614
diff
changeset
|
49 NativeFunctionInterfaceAccess access = null; |
91b861398ad6
removed dependency from NFI to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
21614
diff
changeset
|
50 Class<?> servicesClass = null; |
91b861398ad6
removed dependency from NFI to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
21614
diff
changeset
|
51 try { |
22790
615f3bbbb174
Update jvmci and truffle import: Rename jdk.internal.jvmci to jdk.vm.ci
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22646
diff
changeset
|
52 servicesClass = Class.forName("jdk.vm.ci.service.Services"); |
21894
91b861398ad6
removed dependency from NFI to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
21614
diff
changeset
|
53 } catch (ClassNotFoundException e) { |
22039
3e7ab72bac96
fix for renaming packages com.oracle.jvmci to jdk.internal.jvmci
Doug Simon <doug.simon@oracle.com>
parents:
21894
diff
changeset
|
54 try { |
3e7ab72bac96
fix for renaming packages com.oracle.jvmci to jdk.internal.jvmci
Doug Simon <doug.simon@oracle.com>
parents:
21894
diff
changeset
|
55 // Legacy support |
3e7ab72bac96
fix for renaming packages com.oracle.jvmci to jdk.internal.jvmci
Doug Simon <doug.simon@oracle.com>
parents:
21894
diff
changeset
|
56 servicesClass = Class.forName("com.oracle.jvmci.service.Services"); |
3e7ab72bac96
fix for renaming packages com.oracle.jvmci to jdk.internal.jvmci
Doug Simon <doug.simon@oracle.com>
parents:
21894
diff
changeset
|
57 } catch (ClassNotFoundException e2) { |
3e7ab72bac96
fix for renaming packages com.oracle.jvmci to jdk.internal.jvmci
Doug Simon <doug.simon@oracle.com>
parents:
21894
diff
changeset
|
58 // JVMCI is unavailable |
3e7ab72bac96
fix for renaming packages com.oracle.jvmci to jdk.internal.jvmci
Doug Simon <doug.simon@oracle.com>
parents:
21894
diff
changeset
|
59 } |
21894
91b861398ad6
removed dependency from NFI to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
21614
diff
changeset
|
60 } |
91b861398ad6
removed dependency from NFI to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
21614
diff
changeset
|
61 if (servicesClass != null) { |
91b861398ad6
removed dependency from NFI to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
21614
diff
changeset
|
62 try { |
91b861398ad6
removed dependency from NFI to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
21614
diff
changeset
|
63 Method m = servicesClass.getDeclaredMethod("loadSingle", Class.class, boolean.class); |
91b861398ad6
removed dependency from NFI to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
21614
diff
changeset
|
64 access = (NativeFunctionInterfaceAccess) m.invoke(null, NativeFunctionInterfaceAccess.class, false); |
91b861398ad6
removed dependency from NFI to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
21614
diff
changeset
|
65 } catch (Throwable e) { |
91b861398ad6
removed dependency from NFI to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
21614
diff
changeset
|
66 // Fail fast for other errors |
91b861398ad6
removed dependency from NFI to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
21614
diff
changeset
|
67 throw (InternalError) new InternalError().initCause(e); |
91b861398ad6
removed dependency from NFI to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
21614
diff
changeset
|
68 } |
91b861398ad6
removed dependency from NFI to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
21614
diff
changeset
|
69 } |
91b861398ad6
removed dependency from NFI to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
21614
diff
changeset
|
70 // TODO: try standard ServiceLoader? |
21614
2f92172fa320
Truffle and NFI implementations are now accessed via JVMCI services instead of being hard coded in the VM (JBS:GRAAL-51)
Doug Simon <doug.simon@oracle.com>
parents:
16705
diff
changeset
|
71 if (access != null) { |
2f92172fa320
Truffle and NFI implementations are now accessed via JVMCI services instead of being hard coded in the VM (JBS:GRAAL-51)
Doug Simon <doug.simon@oracle.com>
parents:
16705
diff
changeset
|
72 instance = access.getNativeFunctionInterface(); |
16691
dd8449afc086
GNFI: move GNFI interfaces to oracle.nfi - interface does not depend on graal
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
73 } |
16705 | 74 INSTANCE = instance; |
16691
dd8449afc086
GNFI: move GNFI interfaces to oracle.nfi - interface does not depend on graal
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
75 } |
dd8449afc086
GNFI: move GNFI interfaces to oracle.nfi - interface does not depend on graal
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
76 } |