InternalNative.cpp
1 /*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ /*
* Internal-native initialization and some common utility functions.
*/
#include "Dalvik.h"
#include "native/InternalNativePriv.h" /*
* Set of classes for which we provide methods.
*
* The last field, classNameHash, is filled in at startup.
*/
static DalvikNativeClass gDvmNativeMethodSet[] = {
{ "Ljava/lang/Object;", dvm_java_lang_Object, },
{ "Ljava/lang/Class;", dvm_java_lang_Class, },
{ "Ljava/lang/Double;", dvm_java_lang_Double, },
{ "Ljava/lang/Float;", dvm_java_lang_Float, },
{ "Ljava/lang/Math;", dvm_java_lang_Math, },
{ "Ljava/lang/Runtime;", dvm_java_lang_Runtime, },
{ "Ljava/lang/String;", dvm_java_lang_String, },
{ "Ljava/lang/System;", dvm_java_lang_System, },
{ "Ljava/lang/Throwable;", dvm_java_lang_Throwable, },
{ "Ljava/lang/VMClassLoader;", dvm_java_lang_VMClassLoader, },
{ "Ljava/lang/VMThread;", dvm_java_lang_VMThread, },
{ "Ljava/lang/reflect/AccessibleObject;",
dvm_java_lang_reflect_AccessibleObject, },
{ "Ljava/lang/reflect/Array;", dvm_java_lang_reflect_Array, },
{ "Ljava/lang/reflect/Constructor;",
dvm_java_lang_reflect_Constructor, },
{ "Ljava/lang/reflect/Field;", dvm_java_lang_reflect_Field, },
{ "Ljava/lang/reflect/Method;", dvm_java_lang_reflect_Method, },
{ "Ljava/lang/reflect/Proxy;", dvm_java_lang_reflect_Proxy, },
{ "Ljava/util/concurrent/atomic/AtomicLong;",
dvm_java_util_concurrent_atomic_AtomicLong, },
{ "Ldalvik/bytecode/OpcodeInfo;", dvm_dalvik_bytecode_OpcodeInfo, },
{ "Ldalvik/system/VMDebug;", dvm_dalvik_system_VMDebug, },
{ "Ldalvik/system/DexFile;", dvm_dalvik_system_DexFile, },
{ "Ldalvik/system/VMRuntime;", dvm_dalvik_system_VMRuntime, },
{ "Ldalvik/system/Zygote;", dvm_dalvik_system_Zygote, },
{ "Ldalvik/system/VMStack;", dvm_dalvik_system_VMStack, },
{ "Lorg/apache/harmony/dalvik/ddmc/DdmServer;",
dvm_org_apache_harmony_dalvik_ddmc_DdmServer, },
{ "Lorg/apache/harmony/dalvik/ddmc/DdmVmInternal;",
dvm_org_apache_harmony_dalvik_ddmc_DdmVmInternal, },
{ "Lorg/apache/harmony/dalvik/NativeTestTarget;",
dvm_org_apache_harmony_dalvik_NativeTestTarget, },
{ "Lsun/misc/Unsafe;", dvm_sun_misc_Unsafe, },
{ NULL, NULL, },
}; /*
* Set up hash values on the class names.
*/
bool dvmInternalNativeStartup()
{
DalvikNativeClass* classPtr = gDvmNativeMethodSet; while (classPtr->classDescriptor != NULL) {
classPtr->classDescriptorHash =
dvmComputeUtf8Hash(classPtr->classDescriptor);
classPtr++;
} gDvm.userDexFiles = dvmHashTableCreate(, dvmFreeDexOrJar);
if (gDvm.userDexFiles == NULL)
return false; return true;
} /*
* Clean up.
*/
void dvmInternalNativeShutdown()
{
dvmHashTableFree(gDvm.userDexFiles);
} /*
* Search the internal native set for a match.
*/
DalvikNativeFunc dvmLookupInternalNativeMethod(const Method* method)
{
const char* classDescriptor = method->clazz->descriptor;
const DalvikNativeClass* pClass;
u4 hash; hash = dvmComputeUtf8Hash(classDescriptor);
pClass = gDvmNativeMethodSet;
while (true) {
if (pClass->classDescriptor == NULL)
break;
if (pClass->classDescriptorHash == hash &&
strcmp(pClass->classDescriptor, classDescriptor) == )
{
const DalvikNativeMethod* pMeth = pClass->methodInfo;
while (true) {
if (pMeth->name == NULL)
break; if (dvmCompareNameDescriptorAndMethod(pMeth->name,
pMeth->signature, method) == )
{
/* match */
//ALOGV("+++ match on %s.%s %s at %p",
// className, methodName, methodSignature, pMeth->fnPtr);
return pMeth->fnPtr;
} pMeth++;
}
} pClass++;
} return NULL;
} /*
* Magic "internal native" code stub, inserted into abstract method
* definitions when a class is first loaded. This throws the expected
* exception so we don't have to explicitly check for it in the interpreter.
*/
void dvmAbstractMethodStub(const u4* args, JValue* pResult)
{
ALOGD("--- called into dvmAbstractMethodStub");
dvmThrowAbstractMethodError("abstract method not implemented");
} /*
* Verify that "obj" is non-null and is an instance of "clazz".
* Used to implement reflection on fields and methods.
*
* Returns "false" and throws an exception if not.
*/
bool dvmVerifyObjectInClass(Object* obj, ClassObject* clazz) {
ClassObject* exceptionClass = NULL;
if (obj == NULL) {
exceptionClass = gDvm.exNullPointerException;
} else if (!dvmInstanceof(obj->clazz, clazz)) {
exceptionClass = gDvm.exIllegalArgumentException;
} if (exceptionClass == NULL) {
return true;
} std::string expectedClassName(dvmHumanReadableDescriptor(clazz->descriptor));
std::string actualClassName(dvmHumanReadableType(obj));
dvmThrowExceptionFmt(exceptionClass, "expected receiver of type %s, but got %s",
expectedClassName.c_str(), actualClassName.c_str());
return false;
} /*
* Find a class by name, initializing it if requested.
*/
ClassObject* dvmFindClassByName(StringObject* nameObj, Object* loader,
bool doInit)
{
ClassObject* clazz = NULL;
char* name = NULL;
char* descriptor = NULL; if (nameObj == NULL) {
dvmThrowNullPointerException("name == null");
goto bail;
}
name = dvmCreateCstrFromString(nameObj); /*
* We need to validate and convert the name (from x.y.z to x/y/z). This
* is especially handy for array types, since we want to avoid
* auto-generating bogus array classes.
*/
if (!dexIsValidClassName(name, true)) {
ALOGW("dvmFindClassByName rejecting '%s'", name);
dvmThrowClassNotFoundException(name);
goto bail;
} descriptor = dvmDotToDescriptor(name);
if (descriptor == NULL) {
goto bail;
} if (doInit)
clazz = dvmFindClass(descriptor, loader);
else
clazz = dvmFindClassNoInit(descriptor, loader); if (clazz == NULL) {
LOGVV("FAIL: load %s (%d)", descriptor, doInit);
Thread* self = dvmThreadSelf();
Object* oldExcep = dvmGetException(self);
dvmAddTrackedAlloc(oldExcep, self); /* don't let this be GCed */
dvmClearException(self);
dvmThrowChainedClassNotFoundException(name, oldExcep);
dvmReleaseTrackedAlloc(oldExcep, self);
} else {
LOGVV("GOOD: load %s (%d) --> %p ldr=%p",
descriptor, doInit, clazz, clazz->classLoader);
} bail:
free(name);
free(descriptor);
return clazz;
} /*
* We insert native method stubs for abstract methods so we don't have to
* check the access flags at the time of the method call. This results in
* "native abstract" methods, which can't exist. If we see the "abstract"
* flag set, clear the "native" flag.
*
* We also move the DECLARED_SYNCHRONIZED flag into the SYNCHRONIZED
* position, because the callers of this function are trying to convey
* the "traditional" meaning of the flags to their callers.
*/
u4 dvmFixMethodFlags(u4 flags)
{
if ((flags & ACC_ABSTRACT) != ) {
flags &= ~ACC_NATIVE;
} flags &= ~ACC_SYNCHRONIZED; if ((flags & ACC_DECLARED_SYNCHRONIZED) != ) {
flags |= ACC_SYNCHRONIZED;
} return flags & JAVA_FLAGS_MASK;
}
InternalNative.cpp的更多相关文章
- 使用“Cocos引擎”创建的cpp工程如何在VS中调试Cocos2d-x源码
前段时间Cocos2d-x更新了一个Cocos引擎,这是一个集合源码,IDE,Studio这一家老小的整合包,我们可以使用这个Cocos引擎来创建我们的项目. 在Cocos2d-x被整合到Cocos引 ...
- Json CPP 中文支持与入门示例
在每一个Json Cpp自带*.cpp文件头加上: #include "stdafx.h" 将Json Cpp对自带的头文件的引用修改为单引号方式,例如json_reader.cp ...
- cpp 调用python
在用cpp调用python时, 出现致命错误: no module named site , 原因解释器在搜索路径下没有找到python库.可以在调用Py_Initialize前,调用 Py_Se ...
- nginx+fastcgi+c/cpp
参考:http://github.tiankonguse.com/blog/2015/01/19/cgi-nginx-three/ 跟着做了一遍,然后根据记忆写的,不清楚有没错漏步骤,希望多多评论多多 ...
- APM程序分析-ArduCopter.cpp
该文件是APM的主文件. #define SCHED_TASK(func, rate_hz, max_time_micros) SCHED_TASK_CLASS(Copter, &copter ...
- APM程序分析-AC_WPNav.cpp
APM程序分析 主程序在ArduCopter.cpp的loop()函数. /// advance_wp_target_along_track - move target location along ...
- Dev Cpp 输出中文字符问题
最近 c++ 上机作业,vc++6.0 挂了没法用,只好用 Dev Cpp 先顶替一下,然而在遇到输出中文字符的时候出现了乱码的情况,但这种情况又非常诡异.于是简单了解了一下写成此博客. [写在前面] ...
- 【安卓】aidl.exe E 10744 10584 io_delegate.cpp:102] Error while creating directories: Invalid argument
这几天在使用.aidl文件的时候eclipse的控制台总是爆出如下提示: aidl.exe E 10744 10584 io_delegate.cpp:102] Error while creatin ...
- Identify Memory Leaks in Visual CPP Applications —— VLD内存泄漏检测工具
原文地址:http://www.codeproject.com/Articles/1045847/Identify-Memory-Leaks-in-Visual-CPP-Applications 基于 ...
随机推荐
- Fiddler抓取HTTP请求
参考链接:http://blog.csdn.net/ohmygirl/article/details/17849983/ http://www.cnblogs.com/kingwolf_JavaScr ...
- [bzoj1051][HAOI2006]受欢迎的牛——强连通分量
题目大意: 给定一个有向图,求能够被其他所有点访问到的点的个数. 题解: 首先,这个题我在洛谷上AC了,但是bzoj上WA,不知道为什么. 说一下解法. 首先,我们进行scc分解,可以知道, 如果一个 ...
- (未解决)WIN8下使用POWERSHELL安装python easy_install无法成功
按照https://pypi.python.org/pypi/setuptools#windows-8-powershell介绍的方法, 安装未成功.安装似乎没有启动, 也未安装成功. Windows ...
- How do I list all fields of an object in Objective-C?
http://stackoverflow.com/questions/1213901/how-do-i-list-all-fields-of-an-object-in-objective-c As m ...
- (七)ubuntu下编译openwrt内核的环境配置
首先安装基本开发环境: sudo apt-get install ssh vim samba tftp nfs 安装编译openwrt须要的包: 解压openwrt包编译出错: Build depen ...
- Servlet4.0 注解不生效解决
当我们创建好一个4.0的servlet 生成的注解大概是这样 name=xxxxx 默认的是不具有效果的 你可以有两种方式 1.去掉属性name,3.0就是这样子的 2.非要有name属性 请加上u ...
- hdu 5108(数论-整数分解)
Alexandra and Prime Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (J ...
- MVC中AuthorizeAttribute用法并实现授权管理
1.创建一个类(用来检查用户是否登录和用户权限)代码如下 public class MemberCheckAttribute : AuthorizeAttribute { //AuthorizeAtt ...
- HDU 5923 Prediction(2016 CCPC东北地区大学生程序设计竞赛 Problem B,并查集)
题目链接 2016 CCPC东北地区大学生程序设计竞赛 B题 题意 给定一个无向图和一棵树,树上的每个结点对应无向图中的一条边,现在给出$q$个询问, 每次选定树中的一个点集,然后真正被选上的是这 ...
- Redis单机部署、添加开机自启、配置参数
1.Redis简介 redis是使用C语言编写的开源的,支持网络,基于内存,可持久性的键值对存储数据库,2013年5月之前,Redis是最流行的键值对存储数据库,Redis采用内存数据集,支持多种数据 ...