Mercurial > hg > graal-compiler
annotate graal/com.oracle.nfi/src/com/oracle/nfi/NativeFunctionInterfaceRuntime.java @ 23247:d455abbf413d
Do not peel loops with loop exits that unwind.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Sat, 02 Jan 2016 13:26:48 +0100 |
parents | 56359eb3abfa |
children |
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 { |
23222
56359eb3abfa
moved @ServiceProvider mechanism from JVMCI to Graal (GRAAL-1380)
Doug Simon <doug.simon@oracle.com>
parents:
22790
diff
changeset
|
52 servicesClass = Class.forName("jdk.vm.ci.services.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 { |
23222
56359eb3abfa
moved @ServiceProvider mechanism from JVMCI to Graal (GRAAL-1380)
Doug Simon <doug.simon@oracle.com>
parents:
22790
diff
changeset
|
55 servicesClass = Class.forName("jdk.vm.ci.service.Services"); |
22039
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) { |
23222
56359eb3abfa
moved @ServiceProvider mechanism from JVMCI to Graal (GRAAL-1380)
Doug Simon <doug.simon@oracle.com>
parents:
22790
diff
changeset
|
57 try { |
56359eb3abfa
moved @ServiceProvider mechanism from JVMCI to Graal (GRAAL-1380)
Doug Simon <doug.simon@oracle.com>
parents:
22790
diff
changeset
|
58 // Legacy support |
56359eb3abfa
moved @ServiceProvider mechanism from JVMCI to Graal (GRAAL-1380)
Doug Simon <doug.simon@oracle.com>
parents:
22790
diff
changeset
|
59 servicesClass = Class.forName("com.oracle.jvmci.service.Services"); |
56359eb3abfa
moved @ServiceProvider mechanism from JVMCI to Graal (GRAAL-1380)
Doug Simon <doug.simon@oracle.com>
parents:
22790
diff
changeset
|
60 } catch (ClassNotFoundException e3) { |
56359eb3abfa
moved @ServiceProvider mechanism from JVMCI to Graal (GRAAL-1380)
Doug Simon <doug.simon@oracle.com>
parents:
22790
diff
changeset
|
61 // JVMCI is unavailable |
56359eb3abfa
moved @ServiceProvider mechanism from JVMCI to Graal (GRAAL-1380)
Doug Simon <doug.simon@oracle.com>
parents:
22790
diff
changeset
|
62 } |
22039
3e7ab72bac96
fix for renaming packages com.oracle.jvmci to jdk.internal.jvmci
Doug Simon <doug.simon@oracle.com>
parents:
21894
diff
changeset
|
63 } |
21894
91b861398ad6
removed dependency from NFI to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
21614
diff
changeset
|
64 } |
91b861398ad6
removed dependency from NFI to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
21614
diff
changeset
|
65 if (servicesClass != null) { |
91b861398ad6
removed dependency from NFI to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
21614
diff
changeset
|
66 try { |
91b861398ad6
removed dependency from NFI to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
21614
diff
changeset
|
67 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
|
68 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
|
69 } catch (Throwable e) { |
91b861398ad6
removed dependency from NFI to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
21614
diff
changeset
|
70 // Fail fast for other errors |
91b861398ad6
removed dependency from NFI to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
21614
diff
changeset
|
71 throw (InternalError) new InternalError().initCause(e); |
91b861398ad6
removed dependency from NFI to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
21614
diff
changeset
|
72 } |
91b861398ad6
removed dependency from NFI to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
21614
diff
changeset
|
73 } |
91b861398ad6
removed dependency from NFI to JVMCI
Doug Simon <doug.simon@oracle.com>
parents:
21614
diff
changeset
|
74 // 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
|
75 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
|
76 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
|
77 } |
16705 | 78 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
|
79 } |
dd8449afc086
GNFI: move GNFI interfaces to oracle.nfi - interface does not depend on graal
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
80 } |