Android-x86
Fork
Donation

  • R/O
  • HTTP
  • SSH
  • HTTPS

frameworks-base: Commit

frameworks/base


Commit MetaInfo

Revisión9b437508581c412a7c1fc18650dbcdef456741cb (tree)
Tiempo2019-11-14 13:55:27
Autorxiajiang <xia1.jiang@inte...>
CommiterChih-Wei Huang

Log Message

Reduce the overhead of the PRC compatibility package feature during system bootup

The PRC compatibility package introduced too heavy overhead
in system bootup. This commit aims to reduce the overhead
in system bootup and improve the performance of PRC
compatibility package.

NOTE: The format of ThirdPartySO has been changed to improve
the performance. From now on, the lib name should be trimmed
as below if want to add into the list. For "libabc_v1_2_3.so",
add "abc_v" into the list, that is, the version information
at the tail of lib name should be removed.

Change-Id: Ic374e363d3d31f9bd69be839b33b1bd65950ef61
Tracked-On:https://jira01.devtools.intel.com/browse/OAM-25819
Signed-off-by: xiajiang <xia1.jiang@intel.com>
Reviewed-on: https://android.intel.com:443/484542

Cambiar Resumen

Diferencia incremental

--- a/core/java/com/android/internal/content/NativeLibraryHelper.java
+++ b/core/java/com/android/internal/content/NativeLibraryHelper.java
@@ -79,6 +79,7 @@ public class NativeLibraryHelper {
7979 final boolean extractNativeLibs;
8080 final boolean debuggable;
8181 final String pkgName;
82+ final String apkDir;
8283
8384 public static Handle create(File packageFile) throws IOException {
8485 try {
@@ -90,19 +91,35 @@ public class NativeLibraryHelper {
9091 }
9192
9293 public static Handle create(Package pkg) throws IOException {
94+ String apkdir;
95+ if ((pkg.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
96+ apkdir = null;
97+ } else {
98+ apkdir = pkg.codePath;
99+ }
93100 return create(pkg.getAllCodePaths(),
94101 (pkg.applicationInfo.flags & ApplicationInfo.FLAG_MULTIARCH) != 0,
95102 (pkg.applicationInfo.flags & ApplicationInfo.FLAG_EXTRACT_NATIVE_LIBS) != 0,
96- (pkg.applicationInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0, pkg.packageName);
103+ (pkg.applicationInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0, pkg.packageName, apkdir);
104+ }
105+
106+ private static String getApkDir(PackageLite lite) {
107+ if (lite.codePath == null ||
108+ lite.codePath.startsWith("/system/") ||
109+ lite.codePath.startsWith("/vendor/") ||
110+ lite.codePath.startsWith("/oem/")) {
111+ return null;
112+ }
113+ return lite.codePath;
97114 }
98115
99116 public static Handle create(PackageLite lite) throws IOException {
100117 return create(lite.getAllCodePaths(), lite.multiArch, lite.extractNativeLibs,
101- lite.debuggable, lite.packageName);
118+ lite.debuggable, lite.packageName, getApkDir(lite));
102119 }
103120
104121 private static Handle create(List<String> codePaths, boolean multiArch,
105- boolean extractNativeLibs, boolean debuggable, String pkgName) throws IOException {
122+ boolean extractNativeLibs, boolean debuggable, String pkgName, String apkdir) throws IOException {
106123 final int size = codePaths.size();
107124 final long[] apkHandles = new long[size];
108125 for (int i = 0; i < size; i++) {
@@ -117,7 +134,7 @@ public class NativeLibraryHelper {
117134 }
118135 }
119136
120- return new Handle(apkHandles, multiArch, extractNativeLibs, debuggable, pkgName);
137+ return new Handle(apkHandles, multiArch, extractNativeLibs, debuggable, pkgName, apkdir);
121138 }
122139
123140 public static Handle createFd(PackageLite lite, FileDescriptor fd) throws IOException {
@@ -128,16 +145,17 @@ public class NativeLibraryHelper {
128145 throw new IOException("Unable to open APK " + path + " from fd " + fd);
129146 }
130147
131- return new Handle(apkHandles, lite.multiArch, lite.extractNativeLibs, lite.debuggable, lite.packageName);
148+ return new Handle(apkHandles, lite.multiArch, lite.extractNativeLibs, lite.debuggable, lite.packageName, getApkDir(lite));
132149 }
133150
134151 Handle(long[] apkHandles, boolean multiArch, boolean extractNativeLibs,
135- boolean debuggable, String pkgName) {
152+ boolean debuggable, String pkgName, String apkdir) {
136153 this.apkHandles = apkHandles;
137154 this.multiArch = multiArch;
138155 this.extractNativeLibs = extractNativeLibs;
139156 this.debuggable = debuggable;
140157 this.pkgName = pkgName;
158+ this.apkDir = apkdir;
141159 mGuard.open("close");
142160 }
143161
@@ -213,12 +231,8 @@ public class NativeLibraryHelper {
213231 public static int findSupportedAbi(Handle handle, String[] supportedAbis) {
214232 int finalRes = NO_NATIVE_LIBRARIES;
215233 for (long apkHandle : handle.apkHandles) {
216- int res;
217- if (true) {
218- res = nativeFindSupportedAbiReplace(apkHandle, supportedAbis, handle.debuggable, handle.pkgName);
219- } else {
220- res = nativeFindSupportedAbi(apkHandle, supportedAbis, handle.debuggable);
221- }
234+ final int res = nativeFindSupportedAbiReplace(apkHandle, supportedAbis,
235+ handle.debuggable, handle.pkgName, handle.apkDir);
222236
223237 if (res == NO_NATIVE_LIBRARIES) {
224238 // No native code, keep looking through all APKs.
@@ -241,11 +255,8 @@ public class NativeLibraryHelper {
241255 return finalRes;
242256 }
243257
244- private native static int nativeFindSupportedAbi(long handle, String[] supportedAbis,
245- boolean debuggable);
246-
247258 private native static int nativeFindSupportedAbiReplace(long handle, String[] supportedAbis,
248- boolean debuggable, String pkgName);
259+ boolean debuggable, String pkgName, String apkdir);
249260
250261 // Convenience method to call removeNativeBinariesFromDirLI(File)
251262 public static void removeNativeBinariesLI(String nativeLibraryPath) {
--- a/core/jni/abipicker/ABIPicker.cpp
+++ b/core/jni/abipicker/ABIPicker.cpp
@@ -40,11 +40,12 @@ static bool thirdload = false;
4040 static bool whiteload = false;
4141 static bool blackload = false;
4242
43-static const char* iaRelated[] = {"intel", "atom", "x86", "x64"};
43+static const char* iaRelated[] = {"intel", "intl", "atom", "x86", "x64"};
4444
4545 //////////////////////////////////////////////////////////////////////
4646 void getConfig(const char* cfgFile , Vector<char*>& cfgVec) {
4747 FILE* fp = fopen(cfgFile, "r");
48+ assert(fp != NULL);
4849 int read = -1;
4950 char *line = NULL;
5051 size_t len = 0;
@@ -132,8 +133,14 @@ bool isReliableLib(Vector<char*>& libList) {
132133 int len = ARR_SIZE(iaRelated);
133134 for (unsigned i = 0; i < sz; i++) {
134135 for (int j=0; j < len; j++) {
135- if (NULL != strstr(libList[i], iaRelated[j])) {
136- return true;
136+ char* p = NULL;
137+ if (NULL != (p = strcasestr(libList[i], iaRelated[j]))) {
138+ int lenIA = strlen(iaRelated[j]);
139+ if (!isalpha(*(p+lenIA))) {
140+ if (!isalpha(*(p-1)) || (p == (libList[i] + 3))) {
141+ return true;
142+ }
143+ }
137144 }
138145 }
139146 }
@@ -168,21 +175,47 @@ static bool isMixedLib(char* libCur, char* buffer) {
168175 return mixed;
169176 }
170177
178+// compare the given string with the length, igonre upper and lower
179+// len must be less than the length of two string
180+static bool ignoreCmp(const char* str1, const char* str2, int len){
181+ assert (str1 != NULL && str2 != NULL);
182+ assert ((len <= strlen(str1)) && (len <= strlen(str2)));
183+ for (int i = 0 ; i < len; i++) {
184+ if (str1[i] != str2[i]) {
185+ if(isalpha(str1[i]) && isalpha(str2[i])
186+ && (abs((str1[i]-str2[i])) == 32)) {
187+ continue;
188+ }
189+ return false;
190+ }
191+ }
192+ return true;
193+}
194+
171195 static bool isInThirdPartySOList(char* libName) {
172- if (!libName) return false;
196+ assert (libName != NULL);
173197 size_t libLen = strlen(libName);
174- bool ret = false;
175198 size_t sz = thirdPartySO.size();
176199 for (size_t i = 0; i < sz; i++) {
200+ // thirdPartySO[i] won't be NULL
177201 size_t n = strlen(thirdPartySO[i]);
178- // three for prefix "lib", and 3 for suffix ".so"
179- if ((libLen == (n+6))&&(0 == strncmp(libName + 3, thirdPartySO[i], n))) {
180- ret = true;
181- break;
202+ // three char for ".so"
203+ int j = libLen - 4;
204+ // now only '-' '-' and '.'found
205+ while((j >= 0) && (isdigit(libName[j]) || (libName[j] == '-')
206+ || (libName[j] == '_') || (libName[j] == '.'))) {
207+ j--;
182208 }
209+ // three char for "lib" and include the name with no letters
210+ if ((j == 2) || ((size_t)j == (n+2))) {
211+ if (ignoreCmp(libName+3, thirdPartySO[i], n)) {
212+ P_LOG("ABIpicker libName %s,In Third", libName);
213+ return true;
214+ }
215+ }
216+
183217 }
184- P_LOG("ABIpicker libName %s,In Third %d", libName, ret);
185- return ret;
218+ return false;
186219 }
187220
188221 static void insertionSort(Vector<char*>& list) {
@@ -205,9 +238,9 @@ static void insertionSort(Vector<char*>& list) {
205238
206239 //////////////////////////////////////////////////////////////////////
207240 // Use armRef as a reference, compare all libraries of iaRef with all
208-// libraries of armRef. If both are match, iaRef will be returned with
209-// *result and true is return value. Or else, *result is rawResult and
210-// false is return value
241+// libraries of armRef.If the two are match or iaRef is more, iaRef
242+// will be returned with *result and true is return value. Or else,
243+// *result is rawResult and false is return value
211244 bool ABIPicker::compare(char* armRef, char* iaRef,
212245 char* rawResult, char** result) {
213246 bool ret = true;
@@ -231,6 +264,8 @@ bool ABIPicker::compare(char* armRef, char* iaRef,
231264 Vector<char*>* armRefList = getLibList(armRef);
232265
233266 // if contains the key words in iaRelated, just return true
267+ assert(iaRefList != NULL);
268+ assert(armRefList != NULL);
234269 if (isReliableLib(*iaRefList)) {
235270 *result = iaRef;
236271 break;
@@ -257,7 +292,7 @@ bool ABIPicker::compare(char* armRef, char* iaRef,
257292
258293 *result = armRef;
259294 ret = false;
260- } while (false);
295+ } while (0);
261296
262297 ALOGV("%s Vs. %s, return %s\n",
263298 iaRef ? iaRef : "NULL",
@@ -267,28 +302,48 @@ bool ABIPicker::compare(char* armRef, char* iaRef,
267302
268303 bool ABIPicker::compareLibList(Vector<char*>& iaRefList,
269304 Vector<char*>& armRefList) {
270- if (iaRefList.size() != armRefList.size()) {
305+
306+ unsigned iaSize = iaRefList.size();
307+ unsigned armSize = armRefList.size();
308+ if (iaSize < armSize) {
271309 return false;
310+ } else if (iaSize == 0 && armSize == 0) {
311+ return true;
272312 }
273313
314+ int iaNum = 0;
315+ int armNum = 0;
274316 Vector<char*>::iterator itIa = iaRefList.begin();
275317 Vector<char*>::iterator itArm = armRefList.begin();
318+ bool isEqual = false;
276319 while (itIa != iaRefList.end() && itArm != armRefList.end()) {
277- char* iaLibName = *itIa;
278- char* armLibName = *itArm;
279-
280- // NOTE:
281- // WIN treats file names in-case-sensitive,
282- // but LINUX treats them case-sensitive.
283- if (0 != strcmp(iaLibName, armLibName)) {
320+ if ((iaSize-iaNum) < (armSize-armNum)) {
284321 return false;
285322 }
286-
287- itIa++;
323+ isEqual = false ;
324+ char* armLibName = *itArm;
325+ int armLen = strlen (armLibName);
326+ armNum++;
327+
328+ while (itIa != iaRefList.end() && !isEqual) {
329+ char* iaLibName = *itIa;
330+ iaNum++;
331+ int iaLen = strlen (iaLibName);
332+ if (iaLen == armLen) {
333+ if (ignoreCmp(iaLibName, armLibName, iaLen)) {
334+ isEqual = true;
335+ }
336+ }
337+ itIa++;
338+ }
288339 itArm++;
289340 }
290-
291- return true;
341+ // till the end, and the last result is equal
342+ if (itArm == armRefList.end() && isEqual){
343+ return true;
344+ } else {
345+ return false;
346+ }
292347 }
293348
294349 bool ABIPicker::compare3rdPartyLibList(
@@ -296,6 +351,8 @@ bool ABIPicker::compare3rdPartyLibList(
296351 size_t* iaIsvLibCount, size_t* armIsvLibCount) {
297352 Vector<char*>* iaRefList = getLibList(iaRef);
298353 Vector<char*>* armRefList = getLibList(armRef);
354+ assert(iaRefList != NULL);
355+ assert(armRefList != NULL);
299356
300357 Vector<char*>* armRef3rdPartyLibList = new Vector<char*>();
301358 Vector<char*>::iterator itArm = armRefList->begin();
@@ -328,7 +385,12 @@ bool ABIPicker::compare3rdPartyLibList(
328385
329386 itIa++;
330387 }
331- return compareLibList(*iaRef3rdPartyLibList, *armRef3rdPartyLibList);
388+ bool result = compareLibList(*iaRef3rdPartyLibList, *armRef3rdPartyLibList);
389+
390+ //release the memory
391+ free(armRef3rdPartyLibList);
392+ free(iaRef3rdPartyLibList);
393+ return result;
332394 }
333395
334396 char* ABIPicker::getAbiName(int abi) {
@@ -414,7 +476,7 @@ ABIPicker::ABIPicker(const char* pkgName, Vector<ScopedUtfChars*> abiList) {
414476 if (!mpkgName) {
415477 P_LOG("ABIPicker Construct Allocated space fails");
416478 } else {
417- strcpy(mpkgName, pkgName);
479+ snprintf(mpkgName, strlen(pkgName)+1, "%s", pkgName);
418480 }
419481 Vector<ScopedUtfChars*>::iterator it = abiList.begin();
420482 while (it != abiList.end()) {
@@ -453,6 +515,7 @@ ABIPicker::~ABIPicker(void) {
453515 it++;
454516 }
455517 mLibList->clear();
518+ delete(mLibList);
456519 }
457520
458521 bool ABIPicker::buildNativeLibList(void* apkHandle) {
@@ -510,7 +573,7 @@ bool ABIPicker::buildNativeLibList(void* apkHandle) {
510573 ret = false;
511574 break;
512575 }
513-
576+ memset(unCompBuff, 0, unCompLen);
514577 // THE MOST TIME COST OPERATION
515578 if (!zipFile->uncompressEntry(next, unCompBuff, unCompLen)) {
516579 ALOGE("%s: uncompress failed\n", fileName);
@@ -572,7 +635,7 @@ bool ABIPicker::buildNativeLibList(void* apkHandle) {
572635 ret = false;
573636 break;
574637 }
575- strcpy(mixedLib, (char*)IMPOSSIBLE_LIB_NAME);
638+ snprintf(mixedLib, (IMPOSSIBLE_LIB_LEN+1), "%s", IMPOSSIBLE_LIB_NAME);
576639 mixedLib[IMPOSSIBLE_LIB_LEN] ='\0';
577640 libListOfCurAbi->push_back(mixedLib);
578641 continue;
@@ -588,7 +651,7 @@ bool ABIPicker::buildNativeLibList(void* apkHandle) {
588651 ret = false;
589652 break;
590653 }
591- strcpy(curLibName, lastSlash);
654+ snprintf(curLibName,libNameSize+1, "%s", lastSlash);
592655 curLibName[libNameSize] = '\0';
593656
594657 libListOfCurAbi->push_back(curLibName);
@@ -679,13 +742,13 @@ int ABIPicker::pickupRightABI(int sysPrefer) {
679742 if (is64BitPrefer) {
680743 if (!compare(arm64Ref, ia64Ref, sysPreferAbiName, &retAbiName)) {
681744 char rawRes[ABI_NAME_MAX_LENGTH];
682- strcpy(rawRes, retAbiName);
745+ snprintf(rawRes, ABI_NAME_MAX_LENGTH, "%s", retAbiName);
683746 compare(arm32Ref, ia32Ref, rawRes, &retAbiName);
684747 }
685748 } else {
686749 compare(arm32Ref, ia32Ref, sysPreferAbiName, &retAbiName);
687750 }
688- } while (false);
751+ } while (0);
689752 int ret = getAbiIndex(retAbiName);
690753 ALOGI("selected abi %s(%d) for %s", retAbiName, ret, mpkgName);
691754 return ret;
--- a/core/jni/com_android_internal_content_NativeLibraryHelper.cpp
+++ b/core/jni/com_android_internal_content_NativeLibraryHelper.cpp
@@ -516,53 +516,82 @@ com_android_internal_content_NativeLibraryHelper_sumNativeBinaries(JNIEnv *env,
516516 }
517517
518518 static jint
519-com_android_internal_content_NativeLibraryHelper_findSupportedAbi(JNIEnv *env, jclass clazz,
520- jlong apkHandle, jobjectArray javaCpuAbisToSearch, jboolean debuggable)
521-{
522- return (jint) findSupportedAbi(env, apkHandle, javaCpuAbisToSearch, debuggable);
523-}
524-
525-static jint
526519 com_android_internal_content_NativeLibraryHelper_findSupportedAbi_replace(
527520 JNIEnv *env,
528521 jclass clazz,
529522 jlong apkHandle,
530523 jobjectArray javaCpuAbisToSearch,
531524 jboolean debuggable,
532- jstring apkPkgName)
525+ jstring apkPkgName,
526+ jstring apkDir)
533527 {
534528 #ifdef _PRC_COMPATIBILITY_PACKAGE_
529+
530+ int abiType = findSupportedAbi(env, apkHandle, javaCpuAbisToSearch, debuggable);
531+ if (apkDir == NULL) {
532+ return (jint)abiType;
533+ }
534+
535+ char abiFlag[256] = {'\0'};
536+ ScopedUtfChars apkdir(env, apkDir);
537+ size_t apkdir_size = apkdir.size();
535538 const int numAbis = env->GetArrayLength(javaCpuAbisToSearch);
536539 Vector<ScopedUtfChars*> supportedAbis;
540+
541+ assert(apkdir_size < 256 - 15);
542+ strcpy(abiFlag, apkdir.c_str());
543+ abiFlag[apkdir_size] = '/';
544+ abiFlag[apkdir_size + 1] = '.';
537545 for (int i = 0; i < numAbis; i++) {
538546 ScopedUtfChars* abiName = new ScopedUtfChars(env,
539- (jstring)env->GetObjectArrayElement(
540- javaCpuAbisToSearch, i));
547+ (jstring)env->GetObjectArrayElement(javaCpuAbisToSearch, i));
548+ if (strlcpy(abiFlag + apkdir_size + 2, abiName->c_str(), 256 - apkdir_size - 2)
549+ == abiName->size()) {
550+ if (access(abiFlag, F_OK) == 0) {
551+ abiType = i;
552+ for (int j = 0; j < i; ++j) {
553+ delete supportedAbis[j];
554+ }
555+ delete abiName;
556+ return (jint)abiType;
557+ }
558+ }
559+
541560 supportedAbis.push_back(abiName);
542561 }
543562
544- int abiType = findSupportedAbi(env, apkHandle, javaCpuAbisToSearch, debuggable);
545563 do {
564+ if (abiType < 0 || abiType >= numAbis ) {
565+ break;
566+ }
567+
568+ if (0 != strcmp(supportedAbis[abiType]->c_str(), X86ABI) &&
569+ 0 != strcmp(supportedAbis[abiType]->c_str(), X8664ABI)) {
570+ break;
571+ }
546572
547- if (abiType < 0 || abiType >= numAbis ) break ;
548- // if one package's name is on OEM's specific white list, then the
549- // package should be installed as default
550573 ScopedUtfChars name(env, apkPkgName);
551- if (isInOEMWhiteList(name.c_str())) {
574+ if (NULL == name.c_str()) {
552575 break;
553576 }
554577
555- if (0 != strcmp(supportedAbis[abiType]->c_str(), X86ABI) &&
556- 0 != strcmp(supportedAbis[abiType]->c_str(), X8664ABI)){
578+ if (isInOEMWhiteList(name.c_str())) {
557579 break;
558580 }
581+
559582 ABIPicker picker(name.c_str(),supportedAbis);
560583 if (!picker.buildNativeLibList((void*)apkHandle)) {
561584 break;
562585 }
563586
564587 abiType = picker.pickupRightABI(abiType);
565- } while (false);
588+ if (abiType >= 0 && abiType < numAbis &&
589+ (strlcpy(abiFlag + apkdir_size + 2, supportedAbis[abiType]->c_str(),
590+ 256 - apkdir_size - 2) == supportedAbis[abiType]->size())) {
591+ creat(abiFlag, 0644);
592+ }
593+
594+ } while(0);
566595
567596 for (int i = 0; i < numAbis; ++i) {
568597 delete supportedAbis[i];
@@ -654,11 +683,8 @@ static const JNINativeMethod gMethods[] = {
654683 {"nativeSumNativeBinaries",
655684 "(JLjava/lang/String;Z)J",
656685 (void *)com_android_internal_content_NativeLibraryHelper_sumNativeBinaries},
657- {"nativeFindSupportedAbi",
658- "(J[Ljava/lang/String;Z)I",
659- (void *)com_android_internal_content_NativeLibraryHelper_findSupportedAbi},
660686 {"nativeFindSupportedAbiReplace",
661- "(J[Ljava/lang/String;ZLjava/lang/String;)I",
687+ "(J[Ljava/lang/String;ZLjava/lang/String;Ljava/lang/String;)I",
662688 (void *)com_android_internal_content_NativeLibraryHelper_findSupportedAbi_replace},
663689 {"hasRenderscriptBitcode", "(J)I",
664690 (void *)com_android_internal_content_NativeLibraryHelper_hasRenderscriptBitcode},
Show on old repository browser