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的更多相关文章

  1. 使用“Cocos引擎”创建的cpp工程如何在VS中调试Cocos2d-x源码

    前段时间Cocos2d-x更新了一个Cocos引擎,这是一个集合源码,IDE,Studio这一家老小的整合包,我们可以使用这个Cocos引擎来创建我们的项目. 在Cocos2d-x被整合到Cocos引 ...

  2. Json CPP 中文支持与入门示例

    在每一个Json Cpp自带*.cpp文件头加上: #include "stdafx.h" 将Json Cpp对自带的头文件的引用修改为单引号方式,例如json_reader.cp ...

  3. cpp 调用python

    在用cpp调用python时, 出现致命错误: no module named site  ,  原因解释器在搜索路径下没有找到python库.可以在调用Py_Initialize前,调用 Py_Se ...

  4. nginx+fastcgi+c/cpp

    参考:http://github.tiankonguse.com/blog/2015/01/19/cgi-nginx-three/ 跟着做了一遍,然后根据记忆写的,不清楚有没错漏步骤,希望多多评论多多 ...

  5. APM程序分析-ArduCopter.cpp

    该文件是APM的主文件. #define SCHED_TASK(func, rate_hz, max_time_micros) SCHED_TASK_CLASS(Copter, &copter ...

  6. APM程序分析-AC_WPNav.cpp

    APM程序分析 主程序在ArduCopter.cpp的loop()函数. /// advance_wp_target_along_track - move target location along ...

  7. Dev Cpp 输出中文字符问题

    最近 c++ 上机作业,vc++6.0 挂了没法用,只好用 Dev Cpp 先顶替一下,然而在遇到输出中文字符的时候出现了乱码的情况,但这种情况又非常诡异.于是简单了解了一下写成此博客. [写在前面] ...

  8. 【安卓】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 ...

  9. Identify Memory Leaks in Visual CPP Applications —— VLD内存泄漏检测工具

    原文地址:http://www.codeproject.com/Articles/1045847/Identify-Memory-Leaks-in-Visual-CPP-Applications 基于 ...

随机推荐

  1. 转:Android Log

    在调试代码的时候我们需要查看调试信息,那我们就需要用Android Log类. android.util.Log常用的方法有以下5个:Log.v() Log.d() Log.i() Log.w() 以 ...

  2. ngrepeat 时注意的地方和一些little tricks

    angularjs的一些使用经验总结,此篇文章单谈ng指令之一ngrepeat 1. ngrepeat 时报错 Duplicates in a repeater are not allowed, 正常 ...

  3. SHTSC2017酱油记~~~

    一转眼,SHTSC2017就结束了呢... [前记] noip2016的时候,day2由于各种奇奇怪怪的原因,于是策略上犯错误,然后直接滚粗... 作为一个SHTSC2016年就莫名其妙当上B队队长的 ...

  4. Quartus 调试中的Nios 程序

    FPGA的程序通常包含硬件和软件两部分.正常情况下调试需要分别进行下载,过程繁琐. 为了将Nios II的软件程序包含到.sof文件中方便调试,可以在SOPC Builder中的RAM初始化为Nios ...

  5. Gradle for Android(一)

    Gradle是一种基于Groovy的动态DSL,而Groovy语言是一种基于jvm的动态语言.这里只分享实际开发中会用到的场景,您不需要去学习Groovy语言,知道Java的您是很容易阅读Groovy ...

  6. How to Use Instruments in Xcode

    http://blog.csdn.net/woaifen3344/article/details/40748075 This is a blog post by iOS Tutorial Team m ...

  7. 《Linux命令、编辑器与shell编程》第三版 学习笔记---003 使用multibootusb

    1.下载文件https://codeload.github.com/mbusb/multibootusb-8.9.0.tar.gz,使用命令: tar xvf multibootusb-8.9.0.t ...

  8. 几种常见的YUV格式--yuv422:yuv420【转】

    转自:http://blog.csdn.net/u012288815/article/details/51799477 关于yuv 格式 YUV 格式通常有两大类:打包(packed)格式和平面(pl ...

  9. 10.OpenStack块存储服务

    添加块存储服务 安装和配置控制器节点 创建数据库 mysql -uroot -ptoyo123 CREATE DATABASE cinder; GRANT ALL PRIVILEGES ON cind ...

  10. sql多对多探讨

    --用sql语句探讨一对多 多对多关系 /**** 你有3个表  学生表(学生id 学生姓名) 课程表(课程id 课程名) 成绩表 (学生id 课程id 分数) 班级表(班级id 学生id) 这里的班 ...