2 * Copyright (C) 2008 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * Dalvik's native call interface.
19 * You should follow the JNI function naming conventions, but prefix with
20 * "Dalvik_" instead of "Java_".
22 #ifndef _DALVIK_NATIVE
23 #define _DALVIK_NATIVE
26 * Method description; equivalent to a JNI struct.
28 typedef struct DalvikNativeMethod {
30 const char* signature;
31 DalvikNativeFunc fnPtr;
35 * All methods for one class. The last "methodInfo" has a NULL "name".
37 typedef struct DalvikNativeClass {
38 const char* classDescriptor;
39 const DalvikNativeMethod* methodInfo;
40 u4 classDescriptorHash; /* initialized at runtime */
45 bool dvmNativeStartup(void);
46 void dvmNativeShutdown(void);
50 * Convert argc/argv into a function call. This is platform-specific.
52 void dvmPlatformInvoke(void* pEnv, ClassObject* clazz, int argInfo, int argc,
53 const u4* argv, const char* signature, void* func, JValue* pResult);
56 * Generate hints to speed native calls. This is platform specific.
58 u4 dvmPlatformInvokeHints(const DexProto* proto);
61 * Convert a short library name ("jpeg") to a system-dependent name
62 * ("libjpeg.so"). Returns a newly-allocated string.
64 char* dvmCreateSystemLibraryName(char* libName);
65 //void dvmLoadNativeLibrary(StringObject* libNameObj, Object* classLoader);
66 bool dvmLoadNativeCode(const char* fileName, Object* classLoader,
71 * Resolve a native method. This uses the same prototype as a
72 * DalvikBridgeFunc, because it takes the place of the actual function
73 * until the first time that it's invoked.
75 * Causes the method's class to be initialized.
77 * Throws an exception and returns NULL on failure.
79 void dvmResolveNativeMethod(const u4* args, JValue* pResult,
80 const Method* method, struct Thread* self);
83 * Unregister all JNI native methods associated with a class.
85 void dvmUnregisterJNINativeMethods(ClassObject* clazz);
87 //#define GET_ARG_LONG(_args, _elem) (*(s8*)(&(_args)[_elem]))
88 #define GET_ARG_LONG(_args, _elem) dvmGetArgLong(_args, _elem)
91 * Helpful function for accessing long integers in "u4* args".
93 * We can't just return *(s8*)(&args[elem]), because that breaks if our
94 * architecture requires 64-bit alignment of 64-bit values.
96 * Big/little endian shouldn't matter here -- ordering of words within a
97 * long seems consistent across our supported platforms.
99 INLINE s8 dvmGetArgLong(const u4* args, int elem)
102 union { u4 parts[2]; s8 whole; } conv;
103 conv.parts[0] = args[elem];
104 conv.parts[1] = args[elem+1];
107 /* with gcc's optimizer, memcpy() turns into simpler assignments */
109 memcpy(&val, &args[elem], 8);
115 * Used to implement -Xjnitrace.
118 void dvmLogNativeMethodEntry(const Method* method, const u4* newFp);
119 void dvmLogNativeMethodExit(const Method* method, struct Thread* self,
120 const JValue retval);
122 #endif /*_DALVIK_NATIVE*/