Mercurial > hg > graal-compiler
comparison src/share/vm/graal/graalCompilerToGPU.cpp @ 9430:147162b27799
GRAAL-234 - PTX code loading
author | Morris Meyer <morris.meyer@oracle.com> |
---|---|
date | Tue, 30 Apr 2013 08:17:55 -0400 |
parents | |
children | ed6202820ecf |
comparison
equal
deleted
inserted
replaced
9429:aaf8798b0969 | 9430:147162b27799 |
---|---|
1 /* | |
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 */ | |
23 | |
24 #include "precompiled.hpp" | |
25 | |
26 #include "graal/graalCompiler.hpp" | |
27 #include "graal/graalEnv.hpp" | |
28 #include "runtime/gpu.hpp" | |
29 | |
30 | |
31 // Entry to native method implementation that transitions current thread to '_thread_in_vm'. | |
32 #define C2V_VMENTRY(result_type, name, signature) \ | |
33 JNIEXPORT result_type JNICALL c2v_ ## name signature { \ | |
34 TRACE_graal_3("CompilerToGPU::" #name); \ | |
35 GRAAL_VM_ENTRY_MARK; \ | |
36 | |
37 // Entry to native method implementation that calls a JNI function | |
38 // and hence cannot transition current thread to '_thread_in_vm'. | |
39 #define C2V_ENTRY(result_type, name, signature) \ | |
40 JNIEXPORT result_type JNICALL c2v_ ## name signature { \ | |
41 TRACE_graal_3("CompilerToGPU::" #name); \ | |
42 | |
43 #define C2V_END } | |
44 | |
45 | |
46 C2V_VMENTRY(jlong, generateKernel, (JNIEnv *env, jobject, jbyteArray code, jstring name)) | |
47 if (gpu::is_available() == false || gpu::has_gpu_linkage() == false && gpu::is_initialized()) { | |
48 tty->print_cr("generateKernel - not available / no linkage / not initialized"); | |
49 return 0; | |
50 } | |
51 jboolean is_copy; | |
52 jbyte *bytes = env->GetByteArrayElements(code, &is_copy); | |
53 jint len = env->GetArrayLength(code); | |
54 const char *namestr = env->GetStringUTFChars(name, &is_copy); | |
55 gpu::generate_kernel((unsigned char *)bytes, len, namestr); | |
56 env->ReleaseByteArrayElements(code, bytes, 0); | |
57 env->ReleaseStringUTFChars(name, namestr); | |
58 | |
59 return 42; | |
60 C2V_END | |
61 | |
62 C2V_VMENTRY(jboolean, deviceInit, (JNIEnv *env, jobject)) | |
63 if (gpu::is_available() == false || gpu::has_gpu_linkage() == false) { | |
64 tty->print_cr("deviceInit - not available / no linkage"); | |
65 return false; | |
66 } | |
67 if (gpu::is_initialized()) { | |
68 tty->print_cr("deviceInit - already initialized"); | |
69 return true; | |
70 } | |
71 gpu::initialize_gpu(); | |
72 return gpu::is_initialized(); | |
73 C2V_END | |
74 | |
75 C2V_VMENTRY(jboolean, deviceDetach, (JNIEnv *env, jobject)) | |
76 return true; | |
77 C2V_END | |
78 | |
79 | |
80 #define CC (char*) /*cast a literal from (const char*)*/ | |
81 #define FN_PTR(f) CAST_FROM_FN_PTR(void*, &(c2v_ ## f)) | |
82 | |
83 #define RESOLVED_TYPE "Lcom/oracle/graal/api/meta/ResolvedJavaType;" | |
84 #define TYPE "Lcom/oracle/graal/api/meta/JavaType;" | |
85 #define METHOD "Lcom/oracle/graal/api/meta/JavaMethod;" | |
86 #define FIELD "Lcom/oracle/graal/api/meta/JavaField;" | |
87 #define SIGNATURE "Lcom/oracle/graal/api/meta/Signature;" | |
88 #define CONSTANT_POOL "Lcom/oracle/graal/api/meta/ConstantPool;" | |
89 #define CONSTANT "Lcom/oracle/graal/api/meta/Constant;" | |
90 #define KIND "Lcom/oracle/graal/api/meta/Kind;" | |
91 #define LOCAL "Lcom/oracle/graal/api/meta/Local;" | |
92 #define RUNTIME_CALL "Lcom/oracle/graal/api/code/RuntimeCall;" | |
93 #define EXCEPTION_HANDLERS "[Lcom/oracle/graal/api/meta/ExceptionHandler;" | |
94 #define REFLECT_METHOD "Ljava/lang/reflect/Method;" | |
95 #define REFLECT_CONSTRUCTOR "Ljava/lang/reflect/Constructor;" | |
96 #define REFLECT_FIELD "Ljava/lang/reflect/Field;" | |
97 #define STRING "Ljava/lang/String;" | |
98 #define OBJECT "Ljava/lang/Object;" | |
99 #define CLASS "Ljava/lang/Class;" | |
100 #define STACK_TRACE_ELEMENT "Ljava/lang/StackTraceElement;" | |
101 #define HS_RESOLVED_TYPE "Lcom/oracle/graal/hotspot/meta/HotSpotResolvedObjectType;" | |
102 #define HS_RESOLVED_JAVA_TYPE "Lcom/oracle/graal/hotspot/meta/HotSpotResolvedJavaType;" | |
103 #define HS_RESOLVED_METHOD "Lcom/oracle/graal/hotspot/meta/HotSpotResolvedJavaMethod;" | |
104 #define HS_RESOLVED_FIELD "Lcom/oracle/graal/hotspot/meta/HotSpotResolvedJavaField;" | |
105 #define HS_COMP_RESULT "Lcom/oracle/graal/hotspot/HotSpotCompilationResult;" | |
106 #define HS_CONFIG "Lcom/oracle/graal/hotspot/HotSpotVMConfig;" | |
107 #define HS_METHOD "Lcom/oracle/graal/hotspot/meta/HotSpotMethod;" | |
108 #define HS_INSTALLED_CODE "Lcom/oracle/graal/hotspot/meta/HotSpotInstalledCode;" | |
109 #define METHOD_DATA "Lcom/oracle/graal/hotspot/meta/HotSpotMethodData;" | |
110 #define METASPACE_METHOD "J" | |
111 #define METASPACE_METHOD_DATA "J" | |
112 #define NMETHOD "J" | |
113 #define GPUSPACE_METHOD "J" | |
114 | |
115 JNINativeMethod CompilerToGPU_methods[] = { | |
116 {CC"generateKernel", CC"([B" STRING ")"GPUSPACE_METHOD, FN_PTR(generateKernel)}, | |
117 {CC"deviceInit", CC"()Z", FN_PTR(deviceInit)}, | |
118 {CC"deviceDetach", CC"()Z", FN_PTR(deviceDetach)}, | |
119 }; | |
120 | |
121 int CompilerToGPU_methods_count() { | |
122 return sizeof(CompilerToGPU_methods) / sizeof(JNINativeMethod); | |
123 } | |
124 |