Home | History | Annotate | Download | only in vm
      1 /*
      2  * Copyright (C) 2008 The Android Open Source Project
      3  *
      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
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     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.
     15  */
     16 /*
     17  * Dalvik's native call interface.
     18  *
     19  * You should follow the JNI function naming conventions, but prefix with
     20  * "Dalvik_" instead of "Java_".
     21  */
     22 #ifndef _DALVIK_NATIVE
     23 #define _DALVIK_NATIVE
     24 
     25 /*
     26  * Method description; equivalent to a JNI struct.
     27  */
     28 typedef struct DalvikNativeMethod {
     29     const char* name;
     30     const char* signature;
     31     DalvikNativeFunc  fnPtr;
     32 } DalvikNativeMethod;
     33 
     34 /*
     35  * All methods for one class.  The last "methodInfo" has a NULL "name".
     36  */
     37 typedef struct DalvikNativeClass {
     38     const char* classDescriptor;
     39     const DalvikNativeMethod* methodInfo;
     40     u4          classDescriptorHash;          /* initialized at runtime */
     41 } DalvikNativeClass;
     42 
     43 
     44 /* init/shutdown */
     45 bool dvmNativeStartup(void);
     46 void dvmNativeShutdown(void);
     47 
     48 
     49 /*
     50  * Convert argc/argv into a function call.  This is platform-specific.
     51  */
     52 void dvmPlatformInvoke(void* pEnv, ClassObject* clazz, int argInfo, int argc,
     53     const u4* argv, const char* signature, void* func, JValue* pResult);
     54 
     55 /*
     56  * Generate hints to speed native calls.  This is platform specific.
     57  */
     58 u4 dvmPlatformInvokeHints(const DexProto* proto);
     59 
     60 /*
     61  * Convert a short library name ("jpeg") to a system-dependent name
     62  * ("libjpeg.so").  Returns a newly-allocated string.
     63  */
     64 char* dvmCreateSystemLibraryName(char* libName);
     65 //void dvmLoadNativeLibrary(StringObject* libNameObj, Object* classLoader);
     66 bool dvmLoadNativeCode(const char* fileName, Object* classLoader,
     67         char** detail);
     68 
     69 
     70 /*
     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.
     74  *
     75  * Causes the method's class to be initialized.
     76  *
     77  * Throws an exception and returns NULL on failure.
     78  */
     79 void dvmResolveNativeMethod(const u4* args, JValue* pResult,
     80     const Method* method, struct Thread* self);
     81 
     82 /*
     83  * Unregister all JNI native methods associated with a class.
     84  */
     85 void dvmUnregisterJNINativeMethods(ClassObject* clazz);
     86 
     87 //#define GET_ARG_LONG(_args, _elem)          (*(s8*)(&(_args)[_elem]))
     88 #define GET_ARG_LONG(_args, _elem)          dvmGetArgLong(_args, _elem)
     89 
     90 /*
     91  * Helpful function for accessing long integers in "u4* args".
     92  *
     93  * We can't just return *(s8*)(&args[elem]), because that breaks if our
     94  * architecture requires 64-bit alignment of 64-bit values.
     95  *
     96  * Big/little endian shouldn't matter here -- ordering of words within a
     97  * long seems consistent across our supported platforms.
     98  */
     99 INLINE s8 dvmGetArgLong(const u4* args, int elem)
    100 {
    101 #if 0
    102     union { u4 parts[2]; s8 whole; } conv;
    103     conv.parts[0] = args[elem];
    104     conv.parts[1] = args[elem+1];
    105     return conv.whole;
    106 #else
    107     /* with gcc's optimizer, memcpy() turns into simpler assignments */
    108     s8 val;
    109     memcpy(&val, &args[elem], 8);
    110     return val;
    111 #endif
    112 }
    113 
    114 /*
    115  * Used to implement -Xjnitrace.
    116  */
    117 struct Thread;
    118 void dvmLogNativeMethodEntry(const Method* method, const u4* newFp);
    119 void dvmLogNativeMethodExit(const Method* method, struct Thread* self,
    120         const JValue retval);
    121 
    122 #endif /*_DALVIK_NATIVE*/
    123