Mercurial > hg > graal-compiler
annotate graal/com.oracle.nfi/src/com/oracle/nfi/NativeFunctionInterfaceRuntime.java @ 22567:6de3a450bc17
[SPARC] Fix issues with new ConstantValue and JavaConstant handling
author | Stefan Anzinger <stefan.anzinger@oracle.com> |
---|---|
date | Tue, 01 Sep 2015 14:30:54 +0200 |
parents | 3e7ab72bac96 |
children | 05183a084a08 |
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 |
21894
91b861398ad6
removed dependency from NFI to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
21614
diff
changeset
|
25 import java.lang.reflect.*; |
91b861398ad6
removed dependency from NFI to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
21614
diff
changeset
|
26 |
16691
dd8449afc086
GNFI: move GNFI interfaces to oracle.nfi - interface does not depend on graal
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
27 import com.oracle.nfi.api.*; |
dd8449afc086
GNFI: move GNFI interfaces to oracle.nfi - interface does not depend on graal
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
28 |
16704 | 29 /** |
16705 | 30 * Class for obtaining the {@link NativeFunctionInterface} (if any) provided by the VM. |
16704 | 31 */ |
16691
dd8449afc086
GNFI: move GNFI interfaces to oracle.nfi - interface does not depend on graal
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
32 public final class NativeFunctionInterfaceRuntime { |
16705 | 33 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
|
34 |
16704 | 35 /** |
16705 | 36 * Gets the {@link NativeFunctionInterface} (if any) provided by the VM. |
37 * | |
38 * @return null if the VM does not provide a {@link NativeFunctionInterface} | |
39 */ | |
16691
dd8449afc086
GNFI: move GNFI interfaces to oracle.nfi - interface does not depend on graal
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
40 public static NativeFunctionInterface getNativeFunctionInterface() { |
16705 | 41 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
|
42 } |
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 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
|
45 |
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 NativeFunctionInterface instance = null; |
21894
91b861398ad6
removed dependency from NFI to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
21614
diff
changeset
|
47 |
91b861398ad6
removed dependency from NFI to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
21614
diff
changeset
|
48 NativeFunctionInterfaceAccess access = null; |
91b861398ad6
removed dependency from NFI to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
21614
diff
changeset
|
49 Class<?> servicesClass = null; |
91b861398ad6
removed dependency from NFI to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
21614
diff
changeset
|
50 try { |
22039
3e7ab72bac96
fix for renaming packages com.oracle.jvmci to jdk.internal.jvmci
Doug Simon <doug.simon@oracle.com>
parents:
21894
diff
changeset
|
51 servicesClass = Class.forName("jdk.internal.jvmci.service.Services"); |
21894
91b861398ad6
removed dependency from NFI to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
21614
diff
changeset
|
52 } 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
|
53 try { |
3e7ab72bac96
fix for renaming packages com.oracle.jvmci to jdk.internal.jvmci
Doug Simon <doug.simon@oracle.com>
parents:
21894
diff
changeset
|
54 // Legacy support |
3e7ab72bac96
fix for renaming packages com.oracle.jvmci to jdk.internal.jvmci
Doug Simon <doug.simon@oracle.com>
parents:
21894
diff
changeset
|
55 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
|
56 } 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
|
57 // 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
|
58 } |
21894
91b861398ad6
removed dependency from NFI to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
21614
diff
changeset
|
59 } |
91b861398ad6
removed dependency from NFI to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
21614
diff
changeset
|
60 if (servicesClass != null) { |
91b861398ad6
removed dependency from NFI to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
21614
diff
changeset
|
61 try { |
91b861398ad6
removed dependency from NFI to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
21614
diff
changeset
|
62 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
|
63 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
|
64 } catch (Throwable e) { |
91b861398ad6
removed dependency from NFI to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
21614
diff
changeset
|
65 // Fail fast for other errors |
91b861398ad6
removed dependency from NFI to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
21614
diff
changeset
|
66 throw (InternalError) new InternalError().initCause(e); |
91b861398ad6
removed dependency from NFI to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
21614
diff
changeset
|
67 } |
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 // 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
|
70 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
|
71 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
|
72 } |
16705 | 73 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
|
74 } |
dd8449afc086
GNFI: move GNFI interfaces to oracle.nfi - interface does not depend on graal
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
75 } |