Android-x86
Fork
Donation

  • R/O
  • HTTP
  • SSH
  • HTTPS

dalvik: Commit

dalvik


Commit MetaInfo

Revision474df315744d857345758fc2ee5765e46091443a (tree)
Time2014-02-14 04:58:37
Authorllin4 <ling.lin@inte...>
CommiterChih-Wei Huang

Log Message

Dalvik houdini hook rebase on KK

Including positive hash code patch port from OTC https://otc-android.intel.com/gerrit/#/c/13089/:
Make x86 version of Dalvik to always return positive hash code
when Houdini is enabled in the platform, to match
the ARM app's assumption on its native platform.
MiTalk fails without this fix.

Category: feature differentiation
Domain: AOSP.Houdini-Integration

Change-Id: I3d5df892360cfccb1acd7a4f13315795384375eb
Signed-off-by: llin4 <ling.lin@intel.com>

Change Summary

Incremental Difference

--- a/vm/Jni.cpp
+++ b/vm/Jni.cpp
@@ -703,6 +703,14 @@ static void throwNoSuchMethodError(ClassObject* c, const char* name, const char*
703703 dvmThrowNoSuchMethodError(msg.c_str());
704704 }
705705
706+#ifdef WITH_HOUDINI
707+namespace houdini {
708+bool hookCheckMethod(void *fnPtr);
709+void dvmHookPlatformInvoke(void* pEnv, void* clazz, int argInfo, int argc,
710+ const int* argv, const char* shorty, void* func, void* pReturn);
711+}
712+#endif
713+
706714 /*
707715 * Register a method that uses JNI calling conventions.
708716 */
@@ -762,6 +770,10 @@ static bool dvmRegisterJNIMethod(ClassObject* clazz, const char* methodName,
762770 ALOGV("Note: %s.%s:%s was already registered", clazz->descriptor, methodName, signature);
763771 }
764772
773+#ifdef WITH_HOUDINI
774+ method->needHoudini = houdini::hookCheckMethod(fnPtr);
775+#endif
776+
765777 method->fastJni = fastJni;
766778 dvmUseJNIBridge(method, fnPtr);
767779
@@ -1153,6 +1165,13 @@ void dvmCallJNIMethod(const u4* args, JValue* pResult, const Method* method, Thr
11531165
11541166 JNIEnv* env = self->jniEnv;
11551167 COMPUTE_STACK_SUM(self);
1168+#ifdef WITH_HOUDINI
1169+ if (dvmNeedHoudiniMethod(method))
1170+ houdini::dvmHookPlatformInvoke(env, (ClassObject*)staticMethodClass,
1171+ method->jniArgInfo, method->insSize, (const int*)modArgs, method->shorty,
1172+ (void*)method->insns, pResult);
1173+ else
1174+#endif
11561175 dvmPlatformInvoke(env,
11571176 (ClassObject*) staticMethodClass,
11581177 method->jniArgInfo, method->insSize, modArgs, method->shorty,
--- a/vm/Native.cpp
+++ b/vm/Native.cpp
@@ -29,6 +29,26 @@
2929 static void freeSharedLibEntry(void* ptr);
3030 static void* lookupSharedLibMethod(const Method* method);
3131
32+#ifdef WITH_HOUDINI
33+/*
34+ * Pointer to hold Houdini Hook structure defined in libhoudini_hook.a
35+ */
36+void *gHoudiniHook = NULL;
37+
38+namespace houdini {
39+void* hookDlopen(const char* filename, int flag, bool* useHoudini);
40+void* hookDlsym(bool useHoudini, void* handle, const char* symbol);
41+int hookJniOnload(bool useHoudini, void* func, void* jniVm, void* arg);
42+}
43+/*
44+ * Get the shorty string for a method.
45+ */
46+const char* dvmGetMethodShorty(void* method)
47+{
48+ const Method* meth = (const Method*)method;
49+ return meth->shorty;
50+}
51+#endif
3252
3353 /*
3454 * Initialize the native code loader.
@@ -156,6 +176,9 @@ struct SharedLib {
156176 pthread_cond_t onLoadCond; /* wait for JNI_OnLoad in other thread */
157177 u4 onLoadThreadId; /* recursive invocation guard */
158178 OnLoadState onLoadResult; /* result of earlier JNI_OnLoad */
179+#ifdef WITH_HOUDINI
180+ bool useHoudini;
181+#endif
159182 };
160183
161184 /*
@@ -380,7 +403,12 @@ bool dvmLoadNativeCode(const char* pathName, Object* classLoader,
380403 */
381404 Thread* self = dvmThreadSelf();
382405 ThreadStatus oldStatus = dvmChangeStatus(self, THREAD_VMWAIT);
406+#ifdef WITH_HOUDINI
407+ bool useHoudini = false;
408+ handle = houdini::hookDlopen(pathName, RTLD_LAZY, &useHoudini);
409+#else
383410 handle = dlopen(pathName, RTLD_LAZY);
411+#endif
384412 dvmChangeStatus(self, oldStatus);
385413
386414 if (handle == NULL) {
@@ -394,6 +422,9 @@ bool dvmLoadNativeCode(const char* pathName, Object* classLoader,
394422 pNewEntry = (SharedLib*) calloc(1, sizeof(SharedLib));
395423 pNewEntry->pathName = strdup(pathName);
396424 pNewEntry->handle = handle;
425+#ifdef WITH_HOUDINI
426+ pNewEntry->useHoudini = useHoudini;
427+#endif
397428 pNewEntry->classLoader = classLoader;
398429 dvmInitMutex(&pNewEntry->onLoadLock);
399430 pthread_cond_init(&pNewEntry->onLoadCond, NULL);
@@ -415,7 +446,11 @@ bool dvmLoadNativeCode(const char* pathName, Object* classLoader,
415446 void* vonLoad;
416447 int version;
417448
449+#ifdef WITH_HOUDINI
450+ vonLoad = houdini::hookDlsym(useHoudini, handle, "JNI_OnLoad");
451+#else
418452 vonLoad = dlsym(handle, "JNI_OnLoad");
453+#endif
419454 if (vonLoad == NULL) {
420455 ALOGD("No JNI_OnLoad found in %s %p, skipping init", pathName, classLoader);
421456 result = true;
@@ -434,7 +469,11 @@ bool dvmLoadNativeCode(const char* pathName, Object* classLoader,
434469 if (gDvm.verboseJni) {
435470 ALOGI("[Calling JNI_OnLoad for \"%s\"]", pathName);
436471 }
472+#ifdef WITH_HOUDINI
473+ version = houdini::hookJniOnload(useHoudini, (void*)func, (void*)gDvmJni.jniVm, NULL);
474+#else
437475 version = (*func)(gDvmJni.jniVm, NULL);
476+#endif
438477 dvmChangeStatus(self, oldStatus);
439478 self->classLoaderOverride = prevOverride;
440479
@@ -705,6 +744,10 @@ static int findMethodInLib(void* vlib, void* vmethod)
705744 } else
706745 ALOGV("+++ scanning '%s' for '%s'", pLib->pathName, meth->name);
707746
747+#ifdef WITH_HOUDINI
748+ dvmSetHoudiniMethod((Method*)vmethod, pLib->useHoudini);
749+#endif
750+
708751 /*
709752 * First, we try it without the signature.
710753 */
@@ -718,7 +761,11 @@ static int findMethodInLib(void* vlib, void* vmethod)
718761 goto bail;
719762
720763 ALOGV("+++ calling dlsym(%s)", mangleCM);
764+#ifdef WITH_HOUDINI
765+ func = houdini::hookDlsym(pLib->useHoudini, pLib->handle, mangleCM);
766+#else
721767 func = dlsym(pLib->handle, mangleCM);
768+#endif
722769 if (func == NULL) {
723770 mangleSig =
724771 createMangledSignature(&meth->prototype);
@@ -732,7 +779,11 @@ static int findMethodInLib(void* vlib, void* vmethod)
732779 sprintf(mangleCMSig, "%s__%s", mangleCM, mangleSig);
733780
734781 ALOGV("+++ calling dlsym(%s)", mangleCMSig);
782+#ifdef WITH_HOUDINI
783+ func = houdini::hookDlsym(pLib->useHoudini, pLib->handle, mangleCMSig);
784+#else
735785 func = dlsym(pLib->handle, mangleCMSig);
786+#endif
736787 if (func != NULL) {
737788 ALOGV("Found '%s' with dlsym", mangleCMSig);
738789 }
--- a/vm/ReconfigureDvm.mk
+++ b/vm/ReconfigureDvm.mk
@@ -30,8 +30,15 @@ LOCAL_SHARED_LIBRARIES += \
3030 libselinux \
3131 libz
3232
33+ifeq ($(INTEL_HOUDINI),true)
34+ LOCAL_CFLAGS += -DWITH_HOUDINI
35+endif
3336 LOCAL_STATIC_LIBRARIES += libdex
3437
38+ifeq ($(INTEL_HOUDINI),true)
39+ LOCAL_STATIC_LIBRARIES += libhoudini_hook
40+endif
41+
3542 LOCAL_C_INCLUDES += external/stlport/stlport bionic/ bionic/libstdc++/include
3643 LOCAL_SHARED_LIBRARIES += libstlport
3744
--- a/vm/Sync.cpp
+++ b/vm/Sync.cpp
@@ -1218,7 +1218,12 @@ void dvmThreadInterrupt(Thread* thread)
12181218 #ifndef WITH_COPYING_GC
12191219 u4 dvmIdentityHashCode(Object *obj)
12201220 {
1221- return (u4)obj;
1221+ /*
1222+ * The following assumes that objects are allocated at even boundaries, so
1223+ * the shift preserves uniqueness of hashCode() while guaranteeing a
1224+ * non-negative result (for the convenience of some applications,like MiTalk).
1225+ */
1226+ return (u4)(((u4)obj)>>1);
12221227 }
12231228 #else
12241229 /*
--- a/vm/oo/Object.h
+++ b/vm/oo/Object.h
@@ -578,6 +578,9 @@ struct Method {
578578
579579 /* set if method was called during method profiling */
580580 bool inProfile;
581+#ifdef WITH_HOUDINI
582+ bool needHoudini;
583+#endif
581584 };
582585
583586 u4 dvmGetMethodIdx(const Method* method);
@@ -691,6 +694,14 @@ INLINE bool dvmIsFinalMethod(const Method* method) {
691694 INLINE bool dvmIsNativeMethod(const Method* method) {
692695 return (method->accessFlags & ACC_NATIVE) != 0;
693696 }
697+#ifdef WITH_HOUDINI
698+INLINE void dvmSetHoudiniMethod(Method* method, bool needHoudini) {
699+ method->needHoudini = needHoudini;
700+}
701+INLINE bool dvmNeedHoudiniMethod(const Method* method) {
702+ return (method->needHoudini);
703+}
704+#endif
694705 INLINE bool dvmIsAbstractMethod(const Method* method) {
695706 return (method->accessFlags & ACC_ABSTRACT) != 0;
696707 }
Show on old repository browser