InternalNativePriv.h revision 375fb116bcb817b37509ab579dbd55cdbb765cbf
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/*
18 * Declarations and definitions common to internal native code.
19 */
20#ifndef DALVIK_NATIVE_INTERNALNATIVEPRIV_H_
21#define DALVIK_NATIVE_INTERNALNATIVEPRIV_H_
22
23/*
24 * Return macros.  Note we use "->i" instead of "->z" for boolean; this
25 * is because the interpreter expects everything to be a 32-bit value.
26 */
27#ifdef NDEBUG
28# define RETURN_VOID()           do { (void)(pResult); return; } while(0)
29#else
30# define RETURN_VOID()           do { pResult->i = 0xfefeabab; return; }while(0)
31#endif
32#define RETURN_BOOLEAN(_val)    do { pResult->i = (_val); return; } while(0)
33#define RETURN_INT(_val)        do { pResult->i = (_val); return; } while(0)
34#define RETURN_LONG(_val)       do { pResult->j = (_val); return; } while(0)
35#define RETURN_FLOAT(_val)      do { pResult->f = (_val); return; } while(0)
36#define RETURN_DOUBLE(_val)     do { pResult->d = (_val); return; } while(0)
37#define RETURN_PTR(_val)        do { pResult->l = (Object*)(_val); return; } while(0)
38
39/*
40 * Normally a method that has an "inline native" will be invoked using
41 * execute-inline. If the method is invoked via reflection, JNI, or by
42 * virtual dispatch (in the case of String.equals, which we may arrive
43 * at via Object.equals), we need a non-"inline native" implementation.
44 *
45 * This macro is used to implement the native methods that bridge this gap.
46 */
47#define MAKE_INTRINSIC_TRAMPOLINE(INTRINSIC_FN) \
48    extern bool INTRINSIC_FN(u4 arg0, u4 arg1, u4 arg2, u4 arg3, \
49            JValue* pResult); \
50    INTRINSIC_FN(args[0], args[1], args[2], args[3], pResult);
51
52/*
53 * Verify that "obj" is non-null and is an instance of "clazz".
54 *
55 * Returns "false" and throws an exception if not.
56 */
57bool dvmVerifyObjectInClass(Object* obj, ClassObject* clazz);
58
59/*
60 * Find a class by name, initializing it if requested.
61 */
62ClassObject* dvmFindClassByName(StringObject* nameObj, Object* loader,
63    bool doInit);
64
65/*
66 * We insert native method stubs for abstract methods so we don't have to
67 * check the access flags at the time of the method call.  This results in
68 * "native abstract" methods, which can't exist.  If we see the "abstract"
69 * flag set, clear the "native" flag.
70 *
71 * We also move the DECLARED_SYNCHRONIZED flag into the SYNCHRONIZED
72 * position, because the callers of this function are trying to convey
73 * the "traditional" meaning of the flags to their callers.
74 */
75u4 dvmFixMethodFlags(u4 flags);
76
77/*
78 * dvmHashTableFree callback for some DexFile operations.
79 */
80void dvmFreeDexOrJar(void* vptr);
81
82/*
83 * Tables of methods.
84 */
85extern const DalvikNativeMethod dvm_java_lang_Object[];
86extern const DalvikNativeMethod dvm_java_lang_Class[];
87extern const DalvikNativeMethod dvm_java_lang_Double[];
88extern const DalvikNativeMethod dvm_java_lang_Float[];
89extern const DalvikNativeMethod dvm_java_lang_Math[];
90extern const DalvikNativeMethod dvm_java_lang_Runtime[];
91extern const DalvikNativeMethod dvm_java_lang_String[];
92extern const DalvikNativeMethod dvm_java_lang_System[];
93extern const DalvikNativeMethod dvm_java_lang_Throwable[];
94extern const DalvikNativeMethod dvm_java_lang_VMClassLoader[];
95extern const DalvikNativeMethod dvm_java_lang_VMThread[];
96extern const DalvikNativeMethod dvm_java_lang_reflect_AccessibleObject[];
97extern const DalvikNativeMethod dvm_java_lang_reflect_Array[];
98extern const DalvikNativeMethod dvm_java_lang_reflect_Constructor[];
99extern const DalvikNativeMethod dvm_java_lang_reflect_Field[];
100extern const DalvikNativeMethod dvm_java_lang_reflect_Method[];
101extern const DalvikNativeMethod dvm_java_lang_reflect_Proxy[];
102extern const DalvikNativeMethod dvm_java_util_concurrent_atomic_AtomicLong[];
103extern const DalvikNativeMethod dvm_dalvik_bytecode_OpcodeInfo[];
104extern const DalvikNativeMethod dvm_dalvik_system_SamplingProfiler[];
105extern const DalvikNativeMethod dvm_dalvik_system_VMDebug[];
106extern const DalvikNativeMethod dvm_dalvik_system_DexFile[];
107extern const DalvikNativeMethod dvm_dalvik_system_VMRuntime[];
108extern const DalvikNativeMethod dvm_dalvik_system_Zygote[];
109extern const DalvikNativeMethod dvm_dalvik_system_VMStack[];
110extern const DalvikNativeMethod dvm_org_apache_harmony_dalvik_ddmc_DdmServer[];
111extern const DalvikNativeMethod dvm_org_apache_harmony_dalvik_ddmc_DdmVmInternal[];
112extern const DalvikNativeMethod dvm_org_apache_harmony_dalvik_NativeTestTarget[];
113extern const DalvikNativeMethod dvm_sun_misc_Unsafe[];
114
115#endif  // DALVIK_NATIVE_INTERNALNATIVEPRIV_H_
116