Mercurial > hg > graal-compiler
annotate graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/nfi/HotSpotNativeFunctionInterface.java @ 23347:f868bd0c3f02
Make CallingConvention in HotSpotHostBackend instead of passing it in as a parameter to GraalCompiler.compile
author | Christian Wimmer <christian.wimmer@oracle.com> |
---|---|
date | Thu, 21 Jan 2016 10:35:29 -0800 |
parents | 52f4acf6f365 |
children |
rev | line source |
---|---|
13837
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
1 /* |
23316
52f4acf6f365
Update import: Move CompilationResult and DataSection from JVMCI to Graal.
Roland Schatz <roland.schatz@oracle.com>
parents:
23271
diff
changeset
|
2 * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved. |
13837
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
4 * |
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
8 * |
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
13 * accompanied this code). |
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
14 * |
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
18 * |
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
21 * questions. |
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
22 */ |
20872
b1700db197c7
Move com.oracle.nfi implementation to graal.truffle.hotspot since it implements an interface that does not live in the graal class-loader
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents:
20068
diff
changeset
|
23 package com.oracle.graal.truffle.hotspot.nfi; |
13837
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
24 |
22592
357e73d0091c
moved cstring utilities into UnsafeUtil and made them require the caller to have the Unsafe capability
Doug Simon <doug.simon@oracle.com>
parents:
22573
diff
changeset
|
25 import static com.oracle.graal.truffle.hotspot.nfi.NativeCallStubGraphBuilder.getGraph; |
22790
615f3bbbb174
Update jvmci and truffle import: Rename jdk.internal.jvmci to jdk.vm.ci
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22718
diff
changeset
|
26 import static jdk.vm.ci.common.UnsafeUtil.createCString; |
615f3bbbb174
Update jvmci and truffle import: Rename jdk.internal.jvmci to jdk.vm.ci
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22718
diff
changeset
|
27 import static jdk.vm.ci.common.UnsafeUtil.writeCString; |
22614
9f0e536ee385
restricted Unsafe capability access to package or class scope (GRAAL-1257)
Doug Simon <doug.simon@oracle.com>
parents:
22592
diff
changeset
|
28 |
9f0e536ee385
restricted Unsafe capability access to package or class scope (GRAAL-1257)
Doug Simon <doug.simon@oracle.com>
parents:
22592
diff
changeset
|
29 import java.lang.reflect.Field; |
9f0e536ee385
restricted Unsafe capability access to package or class scope (GRAAL-1257)
Doug Simon <doug.simon@oracle.com>
parents:
22592
diff
changeset
|
30 |
22790
615f3bbbb174
Update jvmci and truffle import: Rename jdk.internal.jvmci to jdk.vm.ci
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22718
diff
changeset
|
31 import jdk.vm.ci.code.InstalledCode; |
23316
52f4acf6f365
Update import: Move CompilationResult and DataSection from JVMCI to Graal.
Roland Schatz <roland.schatz@oracle.com>
parents:
23271
diff
changeset
|
32 import jdk.vm.ci.hotspot.HotSpotCompiledCode; |
22790
615f3bbbb174
Update jvmci and truffle import: Rename jdk.internal.jvmci to jdk.vm.ci
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22718
diff
changeset
|
33 import jdk.vm.ci.hotspot.HotSpotVMConfig; |
615f3bbbb174
Update jvmci and truffle import: Rename jdk.internal.jvmci to jdk.vm.ci
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22718
diff
changeset
|
34 import jdk.vm.ci.meta.DefaultProfilingInfo; |
615f3bbbb174
Update jvmci and truffle import: Rename jdk.internal.jvmci to jdk.vm.ci
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22718
diff
changeset
|
35 import jdk.vm.ci.meta.TriState; |
22614
9f0e536ee385
restricted Unsafe capability access to package or class scope (GRAAL-1257)
Doug Simon <doug.simon@oracle.com>
parents:
22592
diff
changeset
|
36 import sun.misc.Unsafe; |
22573
74b3e5c0209c
suppressed -Xlint:try warnings
Doug Simon <doug.simon@oracle.com>
parents:
22472
diff
changeset
|
37 |
23316
52f4acf6f365
Update import: Move CompilationResult and DataSection from JVMCI to Graal.
Roland Schatz <roland.schatz@oracle.com>
parents:
23271
diff
changeset
|
38 import com.oracle.graal.code.CompilationResult; |
22592
357e73d0091c
moved cstring utilities into UnsafeUtil and made them require the caller to have the Unsafe capability
Doug Simon <doug.simon@oracle.com>
parents:
22573
diff
changeset
|
39 import com.oracle.graal.compiler.GraalCompiler; |
357e73d0091c
moved cstring utilities into UnsafeUtil and made them require the caller to have the Unsafe capability
Doug Simon <doug.simon@oracle.com>
parents:
22573
diff
changeset
|
40 import com.oracle.graal.compiler.target.Backend; |
357e73d0091c
moved cstring utilities into UnsafeUtil and made them require the caller to have the Unsafe capability
Doug Simon <doug.simon@oracle.com>
parents:
22573
diff
changeset
|
41 import com.oracle.graal.debug.Debug; |
357e73d0091c
moved cstring utilities into UnsafeUtil and made them require the caller to have the Unsafe capability
Doug Simon <doug.simon@oracle.com>
parents:
22573
diff
changeset
|
42 import com.oracle.graal.debug.Debug.Scope; |
23316
52f4acf6f365
Update import: Move CompilationResult and DataSection from JVMCI to Graal.
Roland Schatz <roland.schatz@oracle.com>
parents:
23271
diff
changeset
|
43 import com.oracle.graal.hotspot.HotSpotCompiledCodeBuilder; |
22592
357e73d0091c
moved cstring utilities into UnsafeUtil and made them require the caller to have the Unsafe capability
Doug Simon <doug.simon@oracle.com>
parents:
22573
diff
changeset
|
44 import com.oracle.graal.hotspot.meta.HotSpotProviders; |
357e73d0091c
moved cstring utilities into UnsafeUtil and made them require the caller to have the Unsafe capability
Doug Simon <doug.simon@oracle.com>
parents:
22573
diff
changeset
|
45 import com.oracle.graal.lir.asm.CompilationResultBuilderFactory; |
357e73d0091c
moved cstring utilities into UnsafeUtil and made them require the caller to have the Unsafe capability
Doug Simon <doug.simon@oracle.com>
parents:
22573
diff
changeset
|
46 import com.oracle.graal.lir.phases.LIRSuites; |
357e73d0091c
moved cstring utilities into UnsafeUtil and made them require the caller to have the Unsafe capability
Doug Simon <doug.simon@oracle.com>
parents:
22573
diff
changeset
|
47 import com.oracle.graal.nodes.StructuredGraph; |
357e73d0091c
moved cstring utilities into UnsafeUtil and made them require the caller to have the Unsafe capability
Doug Simon <doug.simon@oracle.com>
parents:
22573
diff
changeset
|
48 import com.oracle.graal.phases.OptimisticOptimizations; |
357e73d0091c
moved cstring utilities into UnsafeUtil and made them require the caller to have the Unsafe capability
Doug Simon <doug.simon@oracle.com>
parents:
22573
diff
changeset
|
49 import com.oracle.graal.phases.PhaseSuite; |
357e73d0091c
moved cstring utilities into UnsafeUtil and made them require the caller to have the Unsafe capability
Doug Simon <doug.simon@oracle.com>
parents:
22573
diff
changeset
|
50 import com.oracle.graal.phases.tiers.HighTierContext; |
357e73d0091c
moved cstring utilities into UnsafeUtil and made them require the caller to have the Unsafe capability
Doug Simon <doug.simon@oracle.com>
parents:
22573
diff
changeset
|
51 import com.oracle.graal.phases.tiers.Suites; |
357e73d0091c
moved cstring utilities into UnsafeUtil and made them require the caller to have the Unsafe capability
Doug Simon <doug.simon@oracle.com>
parents:
22573
diff
changeset
|
52 import com.oracle.nfi.api.NativeFunctionInterface; |
357e73d0091c
moved cstring utilities into UnsafeUtil and made them require the caller to have the Unsafe capability
Doug Simon <doug.simon@oracle.com>
parents:
22573
diff
changeset
|
53 import com.oracle.nfi.api.NativeFunctionPointer; |
357e73d0091c
moved cstring utilities into UnsafeUtil and made them require the caller to have the Unsafe capability
Doug Simon <doug.simon@oracle.com>
parents:
22573
diff
changeset
|
54 import com.oracle.nfi.api.NativeLibraryHandle; |
13837
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
55 |
13895
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
56 public class HotSpotNativeFunctionInterface implements NativeFunctionInterface { |
13837
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
57 |
13895
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
58 private final HotSpotProviders providers; |
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
59 private final Backend backend; |
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
60 private final HotSpotNativeLibraryHandle rtldDefault; |
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
61 private final HotSpotNativeFunctionPointer libraryLoadFunctionPointer; |
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
62 private final HotSpotNativeFunctionPointer functionLookupFunctionPointer; |
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
63 private final RawNativeCallNodeFactory factory; |
13837
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
64 |
13895
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
65 private HotSpotNativeFunctionHandle libraryLookupFunctionHandle; |
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
66 private HotSpotNativeFunctionHandle dllLookupFunctionHandle; |
13869
e2db5c351ef3
GNFI: cache lookup handles
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
13837
diff
changeset
|
67 |
13895
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
68 public HotSpotNativeFunctionInterface(HotSpotProviders providers, RawNativeCallNodeFactory factory, Backend backend, long dlopen, long dlsym, long rtldDefault) { |
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
69 this.rtldDefault = rtldDefault == HotSpotVMConfig.INVALID_RTLD_DEFAULT_HANDLE ? null : new HotSpotNativeLibraryHandle("RTLD_DEFAULT", rtldDefault); |
13837
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
70 this.providers = providers; |
19830
97da0b90e0f3
Use host backend when generating a new instance for HotSpotNativeFunctionInterface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
19724
diff
changeset
|
71 assert backend != null; |
13837
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
72 this.backend = backend; |
13895
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
73 this.factory = factory; |
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
74 this.libraryLoadFunctionPointer = new HotSpotNativeFunctionPointer(dlopen, "os::dll_load"); |
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
75 this.functionLookupFunctionPointer = new HotSpotNativeFunctionPointer(dlsym, "os::dll_lookup"); |
13837
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
76 } |
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
77 |
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
78 @Override |
13895
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
79 public HotSpotNativeLibraryHandle getLibraryHandle(String libPath) { |
13869
e2db5c351ef3
GNFI: cache lookup handles
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
13837
diff
changeset
|
80 if (libraryLookupFunctionHandle == null) { |
13895
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
81 libraryLookupFunctionHandle = createHandle(libraryLoadFunctionPointer, long.class, long.class, long.class, int.class); |
13869
e2db5c351ef3
GNFI: cache lookup handles
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
13837
diff
changeset
|
82 } |
13837
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
83 |
13895
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
84 int ebufLen = 1024; |
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
85 // Allocating a single chunk for both the error message buffer and the |
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
86 // file name simplifies deallocation below. |
22614
9f0e536ee385
restricted Unsafe capability access to package or class scope (GRAAL-1257)
Doug Simon <doug.simon@oracle.com>
parents:
22592
diff
changeset
|
87 long buffer = UNSAFE.allocateMemory(ebufLen + libPath.length() + 1); |
13895
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
88 long ebuf = buffer; |
22614
9f0e536ee385
restricted Unsafe capability access to package or class scope (GRAAL-1257)
Doug Simon <doug.simon@oracle.com>
parents:
22592
diff
changeset
|
89 long libPathCString = writeCString(UNSAFE, libPath, buffer + ebufLen); |
13837
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
90 try { |
13895
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
91 long handle = (long) libraryLookupFunctionHandle.call(libPathCString, ebuf, ebufLen); |
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
92 if (handle == 0) { |
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
93 throw new UnsatisfiedLinkError(libPath); |
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
94 } |
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
95 return new HotSpotNativeLibraryHandle(libPath, handle); |
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
96 } finally { |
22614
9f0e536ee385
restricted Unsafe capability access to package or class scope (GRAAL-1257)
Doug Simon <doug.simon@oracle.com>
parents:
22592
diff
changeset
|
97 UNSAFE.freeMemory(buffer); |
13837
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
98 } |
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
99 } |
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
100 |
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
101 @Override |
15040
288c23143d47
Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents:
14143
diff
changeset
|
102 public HotSpotNativeFunctionHandle getFunctionHandle(NativeLibraryHandle library, String name, Class<?> returnType, Class<?>... argumentTypes) { |
16874
3044a847fe91
NFI: never throw an unsatisfiedLinkError - better return null
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
16691
diff
changeset
|
103 HotSpotNativeFunctionPointer functionPointer = lookupFunctionPointer(name, library, false); |
13905
3089e9a7cf44
fixed bug in passing primitive arrays through native function handles
Doug Simon <doug.simon@oracle.com>
parents:
13895
diff
changeset
|
104 return createHandle(functionPointer, returnType, argumentTypes); |
13837
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
105 } |
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
106 |
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
107 @Override |
15040
288c23143d47
Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents:
14143
diff
changeset
|
108 public HotSpotNativeFunctionHandle getFunctionHandle(NativeLibraryHandle[] libraries, String name, Class<?> returnType, Class<?>... argumentTypes) { |
13895
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
109 HotSpotNativeFunctionPointer functionPointer = null; |
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
110 for (NativeLibraryHandle libraryHandle : libraries) { |
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
111 functionPointer = lookupFunctionPointer(name, libraryHandle, false); |
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
112 if (functionPointer != null) { |
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
113 return createHandle(functionPointer, returnType, argumentTypes); |
13837
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
114 } |
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
115 } |
13895
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
116 // Fall back to default library path |
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
117 return getFunctionHandle(name, returnType, argumentTypes); |
13837
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
118 } |
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
119 |
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
120 @Override |
15040
288c23143d47
Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents:
14143
diff
changeset
|
121 public HotSpotNativeFunctionHandle getFunctionHandle(String name, Class<?> returnType, Class<?>... argumentTypes) { |
13895
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
122 if (rtldDefault == null) { |
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
123 throw new UnsatisfiedLinkError(name); |
13837
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
124 } |
13895
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
125 return getFunctionHandle(rtldDefault, name, returnType, argumentTypes); |
13837
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
126 } |
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
127 |
13895
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
128 private HotSpotNativeFunctionPointer lookupFunctionPointer(String name, NativeLibraryHandle library, boolean linkageErrorIfMissing) { |
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
129 if (name == null || library == null) { |
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
130 throw new NullPointerException(); |
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
131 } |
13905
3089e9a7cf44
fixed bug in passing primitive arrays through native function handles
Doug Simon <doug.simon@oracle.com>
parents:
13895
diff
changeset
|
132 |
13895
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
133 if (dllLookupFunctionHandle == null) { |
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
134 dllLookupFunctionHandle = createHandle(functionLookupFunctionPointer, long.class, long.class, long.class); |
13837
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
135 } |
22592
357e73d0091c
moved cstring utilities into UnsafeUtil and made them require the caller to have the Unsafe capability
Doug Simon <doug.simon@oracle.com>
parents:
22573
diff
changeset
|
136 |
22614
9f0e536ee385
restricted Unsafe capability access to package or class scope (GRAAL-1257)
Doug Simon <doug.simon@oracle.com>
parents:
22592
diff
changeset
|
137 long nameCString = createCString(UNSAFE, name); |
13837
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
138 try { |
13895
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
139 long functionPointer = (long) dllLookupFunctionHandle.call(((HotSpotNativeLibraryHandle) library).value, nameCString); |
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
140 if (functionPointer == 0L) { |
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
141 if (!linkageErrorIfMissing) { |
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
142 return null; |
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
143 } |
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
144 throw new UnsatisfiedLinkError(name); |
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
145 } |
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
146 return new HotSpotNativeFunctionPointer(functionPointer, name); |
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
147 } finally { |
22614
9f0e536ee385
restricted Unsafe capability access to package or class scope (GRAAL-1257)
Doug Simon <doug.simon@oracle.com>
parents:
22592
diff
changeset
|
148 UNSAFE.freeMemory(nameCString); |
13837
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
149 } |
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
150 } |
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
151 |
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
152 @Override |
15040
288c23143d47
Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents:
14143
diff
changeset
|
153 public HotSpotNativeFunctionHandle getFunctionHandle(NativeFunctionPointer functionPointer, Class<?> returnType, Class<?>... argumentTypes) { |
13895
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
154 if (!(functionPointer instanceof HotSpotNativeFunctionPointer)) { |
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
155 throw new UnsatisfiedLinkError(functionPointer.getName()); |
13837
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
156 } |
13895
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
157 return createHandle(functionPointer, returnType, argumentTypes); |
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
158 } |
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
159 |
15040
288c23143d47
Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents:
14143
diff
changeset
|
160 private HotSpotNativeFunctionHandle createHandle(NativeFunctionPointer functionPointer, Class<?> returnType, Class<?>... argumentTypes) { |
13895
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
161 HotSpotNativeFunctionPointer hs = (HotSpotNativeFunctionPointer) functionPointer; |
16964
41f66e61b39a
NFI: fix FunctionHandle resolving
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
16874
diff
changeset
|
162 if (hs != null) { |
41f66e61b39a
NFI: fix FunctionHandle resolving
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
16874
diff
changeset
|
163 InstalledCode code = installNativeFunctionStub(hs.value, returnType, argumentTypes); |
41f66e61b39a
NFI: fix FunctionHandle resolving
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
16874
diff
changeset
|
164 return new HotSpotNativeFunctionHandle(code, hs.name, argumentTypes); |
41f66e61b39a
NFI: fix FunctionHandle resolving
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
16874
diff
changeset
|
165 } else { |
41f66e61b39a
NFI: fix FunctionHandle resolving
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
16874
diff
changeset
|
166 return null; |
41f66e61b39a
NFI: fix FunctionHandle resolving
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
16874
diff
changeset
|
167 } |
13895
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
168 } |
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
169 |
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
170 /** |
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
171 * Creates and installs a stub for calling a native function. |
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
172 */ |
22573
74b3e5c0209c
suppressed -Xlint:try warnings
Doug Simon <doug.simon@oracle.com>
parents:
22472
diff
changeset
|
173 @SuppressWarnings("try") |
15040
288c23143d47
Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents:
14143
diff
changeset
|
174 private InstalledCode installNativeFunctionStub(long functionPointer, Class<?> returnType, Class<?>... argumentTypes) { |
13895
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
175 StructuredGraph g = getGraph(providers, factory, functionPointer, returnType, argumentTypes); |
23271
8b7b4f1e3274
Ensure that Suites creation properly tracks overrides
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22790
diff
changeset
|
176 Suites suites = providers.getSuites().getDefaultSuites(); |
8b7b4f1e3274
Ensure that Suites creation properly tracks overrides
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22790
diff
changeset
|
177 LIRSuites lirSuites = providers.getSuites().getDefaultLIRSuites(); |
13895
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
178 PhaseSuite<HighTierContext> phaseSuite = backend.getSuites().getDefaultGraphBuilderSuite().copy(); |
23347
f868bd0c3f02
Make CallingConvention in HotSpotHostBackend instead of passing it in as a parameter to GraalCompiler.compile
Christian Wimmer <christian.wimmer@oracle.com>
parents:
23316
diff
changeset
|
179 CompilationResult compResult = GraalCompiler.compileGraph(g, g.method(), providers, backend, phaseSuite, OptimisticOptimizations.ALL, DefaultProfilingInfo.get(TriState.UNKNOWN), suites, |
22472
37792075b555
Remove redundant TargetDescription argument, use TargetDescription from Backend instead.
Roland Schatz <roland.schatz@oracle.com>
parents:
22300
diff
changeset
|
180 lirSuites, new CompilationResult(), CompilationResultBuilderFactory.Default); |
13895
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
181 InstalledCode installedCode; |
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
182 try (Scope s = Debug.scope("CodeInstall", providers.getCodeCache(), g.method())) { |
23316
52f4acf6f365
Update import: Move CompilationResult and DataSection from JVMCI to Graal.
Roland Schatz <roland.schatz@oracle.com>
parents:
23271
diff
changeset
|
183 HotSpotCompiledCode compiledCode = HotSpotCompiledCodeBuilder.createCompiledCode(g.method(), null, compResult); |
52f4acf6f365
Update import: Move CompilationResult and DataSection from JVMCI to Graal.
Roland Schatz <roland.schatz@oracle.com>
parents:
23271
diff
changeset
|
184 installedCode = providers.getCodeCache().addCode(g.method(), compiledCode, null, null); |
17212
1ac6b4879443
Enforce catch-blocks for Debug.Scopes with context objects.
Josef Eisl <josef.eisl@jku.at>
parents:
16964
diff
changeset
|
185 } catch (Throwable e) { |
1ac6b4879443
Enforce catch-blocks for Debug.Scopes with context objects.
Josef Eisl <josef.eisl@jku.at>
parents:
16964
diff
changeset
|
186 throw Debug.handle(e); |
13895
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
187 } |
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
188 return installedCode; |
13837
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
189 } |
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
190 |
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
191 @Override |
13895
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
192 public HotSpotNativeFunctionPointer getFunctionPointer(NativeLibraryHandle[] libraries, String name) { |
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
193 for (NativeLibraryHandle libraryHandle : libraries) { |
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
194 HotSpotNativeFunctionPointer functionPointer = lookupFunctionPointer(name, libraryHandle, false); |
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
195 if (functionPointer != null) { |
13837
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
196 return functionPointer; |
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
197 } |
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
198 } |
13895
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
199 // Fall back to default library path |
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
200 if (rtldDefault == null) { |
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
201 throw new UnsatisfiedLinkError(name); |
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
202 } |
16874
3044a847fe91
NFI: never throw an unsatisfiedLinkError - better return null
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
16691
diff
changeset
|
203 return lookupFunctionPointer(name, rtldDefault, false); |
13837
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
204 } |
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
205 |
13909
fac51a64fda0
made NativeFunctionInterfaceTest pass on Windows
Doug Simon <doug.simon@oracle.com>
parents:
13905
diff
changeset
|
206 public boolean isDefaultLibrarySearchSupported() { |
fac51a64fda0
made NativeFunctionInterfaceTest pass on Windows
Doug Simon <doug.simon@oracle.com>
parents:
13905
diff
changeset
|
207 return rtldDefault != null; |
fac51a64fda0
made NativeFunctionInterfaceTest pass on Windows
Doug Simon <doug.simon@oracle.com>
parents:
13905
diff
changeset
|
208 } |
fac51a64fda0
made NativeFunctionInterfaceTest pass on Windows
Doug Simon <doug.simon@oracle.com>
parents:
13905
diff
changeset
|
209 |
13837
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
210 @Override |
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
211 public NativeFunctionPointer getNativeFunctionPointerFromRawValue(long rawValue) { |
13895
4731c1a0b1f3
consolidated GNFI code into graal.hotspot project and cleaned up the documentation and code
Doug Simon <doug.simon@oracle.com>
parents:
13872
diff
changeset
|
212 return new HotSpotNativeFunctionPointer(rawValue, null); |
13837
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
213 } |
22614
9f0e536ee385
restricted Unsafe capability access to package or class scope (GRAAL-1257)
Doug Simon <doug.simon@oracle.com>
parents:
22592
diff
changeset
|
214 |
9f0e536ee385
restricted Unsafe capability access to package or class scope (GRAAL-1257)
Doug Simon <doug.simon@oracle.com>
parents:
22592
diff
changeset
|
215 private static final Unsafe UNSAFE = initUnsafe(); |
9f0e536ee385
restricted Unsafe capability access to package or class scope (GRAAL-1257)
Doug Simon <doug.simon@oracle.com>
parents:
22592
diff
changeset
|
216 |
9f0e536ee385
restricted Unsafe capability access to package or class scope (GRAAL-1257)
Doug Simon <doug.simon@oracle.com>
parents:
22592
diff
changeset
|
217 private static Unsafe initUnsafe() { |
9f0e536ee385
restricted Unsafe capability access to package or class scope (GRAAL-1257)
Doug Simon <doug.simon@oracle.com>
parents:
22592
diff
changeset
|
218 try { |
9f0e536ee385
restricted Unsafe capability access to package or class scope (GRAAL-1257)
Doug Simon <doug.simon@oracle.com>
parents:
22592
diff
changeset
|
219 return Unsafe.getUnsafe(); |
9f0e536ee385
restricted Unsafe capability access to package or class scope (GRAAL-1257)
Doug Simon <doug.simon@oracle.com>
parents:
22592
diff
changeset
|
220 } catch (SecurityException se) { |
9f0e536ee385
restricted Unsafe capability access to package or class scope (GRAAL-1257)
Doug Simon <doug.simon@oracle.com>
parents:
22592
diff
changeset
|
221 try { |
9f0e536ee385
restricted Unsafe capability access to package or class scope (GRAAL-1257)
Doug Simon <doug.simon@oracle.com>
parents:
22592
diff
changeset
|
222 Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe"); |
9f0e536ee385
restricted Unsafe capability access to package or class scope (GRAAL-1257)
Doug Simon <doug.simon@oracle.com>
parents:
22592
diff
changeset
|
223 theUnsafe.setAccessible(true); |
9f0e536ee385
restricted Unsafe capability access to package or class scope (GRAAL-1257)
Doug Simon <doug.simon@oracle.com>
parents:
22592
diff
changeset
|
224 return (Unsafe) theUnsafe.get(Unsafe.class); |
9f0e536ee385
restricted Unsafe capability access to package or class scope (GRAAL-1257)
Doug Simon <doug.simon@oracle.com>
parents:
22592
diff
changeset
|
225 } catch (Exception e) { |
9f0e536ee385
restricted Unsafe capability access to package or class scope (GRAAL-1257)
Doug Simon <doug.simon@oracle.com>
parents:
22592
diff
changeset
|
226 throw new RuntimeException("exception while trying to get Unsafe", e); |
9f0e536ee385
restricted Unsafe capability access to package or class scope (GRAAL-1257)
Doug Simon <doug.simon@oracle.com>
parents:
22592
diff
changeset
|
227 } |
9f0e536ee385
restricted Unsafe capability access to package or class scope (GRAAL-1257)
Doug Simon <doug.simon@oracle.com>
parents:
22592
diff
changeset
|
228 } |
9f0e536ee385
restricted Unsafe capability access to package or class scope (GRAAL-1257)
Doug Simon <doug.simon@oracle.com>
parents:
22592
diff
changeset
|
229 } |
13837
ed3a1471e133
Add the Graal Native Function Interface
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
diff
changeset
|
230 } |