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. DP———1.最大子连续子序列和

    最大连续子序列 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Sub ...

  2. centos 搭建web平台

    centos 查询是否安装apacherpm -qa httpd 出现类似 httpd--.el6.centos..x86_64 ,说明已安装 yum -y install httpd    // 安 ...

  3. 信息竞赛程序卡时_C++

    一.卡时简介 卡时是一个竞赛时常用的技巧 有些题目我们想不到完美算法就只能用暴力解决,但是此类方法一般时间复杂度较高,此时我们需要进行卡时 通俗来讲就是进行一个时间限制,让程序在达到这个时间后立马退出 ...

  4. [9018_1963][IOI_1998]Picture

    题目描述 N(N<5000) 张矩形的海报,照片和其他同样形状的图片贴在墙上.它们的边都是垂直的或水平的.每个矩形可以部分或者全部覆盖其他矩形.所有的矩形组成的集合的轮廓称为周长.写一个程序计算 ...

  5. mysql 连接失败问题汇集

    FHost '192.168.5.128' is not allowed to connect to this MySQL serverConnection closed by foreign hos ...

  6. matlab 分析wav波形

    [x,fs,bits]=wavread('d.wav', [1 5000]); % sound(x, fs, bits); N = length(x); n = 0 : N-1; t = n/fs; ...

  7. VMWare虚拟机如何与主机共享文件夹(最容易看懂的讲解)附图~

    http://wenku.baidu.com/view/54ab9e19227916888486d776.html 新建好虚拟机并安装好系统后,在编辑虚拟机设置--选项进行以下设置: 点添加 选择你要 ...

  8. 《Linux命令行与shell脚本编程大全 第3版》Shell脚本编程基础---57

    以下为阅读<Linux命令行与shell脚本编程大全 第3版>的读书笔记,为了方便记录,特地与书的内容保持同步,特意做成一节一次随笔,特记录如下:

  9. 使用vim进行java编程

    首先:编写源代码Test.java 1class Test{                                                                       ...

  10. malloc()之后,内核发生了什么?【转】

    转自:http://blog.csdn.net/qianlong4526888/article/details/9042835 [-] 1brk系统调用服务例程 2扩大堆 3缺页异常的处理过程 31d ...