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. hadoop学习之HDFS

    1.什么是大数据?什么是云计算?什么是hadoop? 大数据现在很火,到底什么是大数据,多大的数据才算大,一般而言对于TB级以上的数据我们成为大数据,对于这些数据它的价值在哪?大数据的价值就是我们大量 ...

  2. linux--lsof

    lsof(list open files)是一个列出当前系统打开文件的工具.在linux环境下,任何事物都以文件的形式存在,通过文件不仅仅可以访问常规数据,还可以访问网络连接和硬件.所以如传输控制协议 ...

  3. lca板子

    #include<cstdio> #include<cstring> #include<algorithm> #define LL long long using ...

  4. 洛谷T8115 毁灭

    题目描述 YJC决定对入侵C国的W国军队发动毁灭性打击.将C国看成一个平面直角坐标系,W国一共有n^2个人进入了C国境内,在每一个(x,y)(1≤x,y≤n)上都有恰好一个W国人.YJC决定使用m颗核 ...

  5. [bzoj2111][ZJOI2010]Perm 排列计数 ——问题转换,建立数学模型

    题目大意 称一个1,2,...,N的排列P1,P2...,Pn是Magic的,当且仅当2<=i<=N时,Pi>Pi/2. 计算1,2,...N的排列中有多少是Magic的,答案可能很 ...

  6. flexigrid 学习总结

    最近看到了一款flexigrid表格组件,简单美观,在下载使用的过程中,发现缺少很多功能.<基于jQuery的GridView-Flexigrid(2)-扩展和修复>给我带来了很大的帮助, ...

  7. oracle 的数组(转)

    declare type t_indexby is table of number index by binary_integer; type t_nested is table of number; ...

  8. LVDS 数据通道详解 单8 单6

    1.1.1           LVDS接口分类 1.1.1.1              单路6bit LVDS 这种接口电路中,采用单路方式传输,每个基色信号采用6位数据,共18位RGB数据,因此 ...

  9. 【linux高级程序设计】(第十二章)Linux多线程编程 4

    读写锁 书上有读者写者的代码,我实在是懒得实现一遍了.跟之前的代码差不多. 多线程异步信号处理 int pthread_kill (pthread_t __threadid, int __signo) ...

  10. poj 1151(离散化+矩形面积并)

    题目链接:http://poj.org/problem?id=1151 关于离散化,这篇博客讲的很好:http://www.cppblog.com/MiYu/archive/2010/10/15/12 ...