Android-x86
Fork
Donation

  • R/O
  • HTTP
  • SSH
  • HTTPS

frameworks-base: Commit

frameworks/base


Commit MetaInfo

Revisión00e73787f2ed59f57b2b09279de57c6dde642f2d (tree)
Tiempo2020-04-14 23:46:51
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
@@ -212,12 +230,8 @@ public class NativeLibraryHelper {
212230 public static int findSupportedAbi(Handle handle, String[] supportedAbis) {
213231 int finalRes = NO_NATIVE_LIBRARIES;
214232 for (long apkHandle : handle.apkHandles) {
215- int res;
216- if (true) {
217- res = nativeFindSupportedAbiReplace(apkHandle, supportedAbis, handle.debuggable, handle.pkgName);
218- } else {
219- res = nativeFindSupportedAbi(apkHandle, supportedAbis, handle.debuggable);
220- }
233+ final int res = nativeFindSupportedAbiReplace(apkHandle, supportedAbis,
234+ handle.debuggable, handle.pkgName, handle.apkDir);
221235
222236 if (res == NO_NATIVE_LIBRARIES) {
223237 // No native code, keep looking through all APKs.
@@ -240,11 +254,8 @@ public class NativeLibraryHelper {
240254 return finalRes;
241255 }
242256
243- private native static int nativeFindSupportedAbi(long handle, String[] supportedAbis,
244- boolean debuggable);
245-
246257 private native static int nativeFindSupportedAbiReplace(long handle, String[] supportedAbis,
247- boolean debuggable, String pkgName);
258+ boolean debuggable, String pkgName, String apkdir);
248259
249260 // Convenience method to call removeNativeBinariesFromDirLI(File)
250261 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
@@ -514,53 +514,82 @@ com_android_internal_content_NativeLibraryHelper_sumNativeBinaries(JNIEnv *env,
514514 }
515515
516516 static jint
517-com_android_internal_content_NativeLibraryHelper_findSupportedAbi(JNIEnv *env, jclass clazz,
518- jlong apkHandle, jobjectArray javaCpuAbisToSearch, jboolean debuggable)
519-{
520- return (jint) findSupportedAbi(env, apkHandle, javaCpuAbisToSearch, debuggable);
521-}
522-
523-static jint
524517 com_android_internal_content_NativeLibraryHelper_findSupportedAbi_replace(
525518 JNIEnv *env,
526519 jclass clazz,
527520 jlong apkHandle,
528521 jobjectArray javaCpuAbisToSearch,
529522 jboolean debuggable,
530- jstring apkPkgName)
523+ jstring apkPkgName,
524+ jstring apkDir)
531525 {
532526 #ifdef _PRC_COMPATIBILITY_PACKAGE_
527+
528+ int abiType = findSupportedAbi(env, apkHandle, javaCpuAbisToSearch, debuggable);
529+ if (apkDir == NULL) {
530+ return (jint)abiType;
531+ }
532+
533+ char abiFlag[256] = {'\0'};
534+ ScopedUtfChars apkdir(env, apkDir);
535+ size_t apkdir_size = apkdir.size();
533536 const int numAbis = env->GetArrayLength(javaCpuAbisToSearch);
534537 Vector<ScopedUtfChars*> supportedAbis;
538+
539+ assert(apkdir_size < 256 - 15);
540+ strcpy(abiFlag, apkdir.c_str());
541+ abiFlag[apkdir_size] = '/';
542+ abiFlag[apkdir_size + 1] = '.';
535543 for (int i = 0; i < numAbis; i++) {
536544 ScopedUtfChars* abiName = new ScopedUtfChars(env,
537- (jstring)env->GetObjectArrayElement(
538- javaCpuAbisToSearch, i));
545+ (jstring)env->GetObjectArrayElement(javaCpuAbisToSearch, i));
546+ if (strlcpy(abiFlag + apkdir_size + 2, abiName->c_str(), 256 - apkdir_size - 2)
547+ == abiName->size()) {
548+ if (access(abiFlag, F_OK) == 0) {
549+ abiType = i;
550+ for (int j = 0; j < i; ++j) {
551+ delete supportedAbis[j];
552+ }
553+ delete abiName;
554+ return (jint)abiType;
555+ }
556+ }
557+
539558 supportedAbis.push_back(abiName);
540559 }
541560
542- int abiType = findSupportedAbi(env, apkHandle, javaCpuAbisToSearch, debuggable);
543561 do {
562+ if (abiType < 0 || abiType >= numAbis ) {
563+ break;
564+ }
565+
566+ if (0 != strcmp(supportedAbis[abiType]->c_str(), X86ABI) &&
567+ 0 != strcmp(supportedAbis[abiType]->c_str(), X8664ABI)) {
568+ break;
569+ }
544570
545- if (abiType < 0 || abiType >= numAbis ) break ;
546- // if one package's name is on OEM's specific white list, then the
547- // package should be installed as default
548571 ScopedUtfChars name(env, apkPkgName);
549- if (isInOEMWhiteList(name.c_str())) {
572+ if (NULL == name.c_str()) {
550573 break;
551574 }
552575
553- if (0 != strcmp(supportedAbis[abiType]->c_str(), X86ABI) &&
554- 0 != strcmp(supportedAbis[abiType]->c_str(), X8664ABI)){
576+ if (isInOEMWhiteList(name.c_str())) {
555577 break;
556578 }
579+
557580 ABIPicker picker(name.c_str(),supportedAbis);
558581 if (!picker.buildNativeLibList((void*)apkHandle)) {
559582 break;
560583 }
561584
562585 abiType = picker.pickupRightABI(abiType);
563- } while (false);
586+ if (abiType >= 0 && abiType < numAbis &&
587+ (strlcpy(abiFlag + apkdir_size + 2, supportedAbis[abiType]->c_str(),
588+ 256 - apkdir_size - 2) == supportedAbis[abiType]->size())) {
589+ creat(abiFlag, 0644);
590+ }
591+
592+ } while(0);
564593
565594 for (int i = 0; i < numAbis; ++i) {
566595 delete supportedAbis[i];
@@ -659,11 +688,8 @@ static const JNINativeMethod gMethods[] = {
659688 {"nativeSumNativeBinaries",
660689 "(JLjava/lang/String;Z)J",
661690 (void *)com_android_internal_content_NativeLibraryHelper_sumNativeBinaries},
662- {"nativeFindSupportedAbi",
663- "(J[Ljava/lang/String;Z)I",
664- (void *)com_android_internal_content_NativeLibraryHelper_findSupportedAbi},
665691 {"nativeFindSupportedAbiReplace",
666- "(J[Ljava/lang/String;ZLjava/lang/String;)I",
692+ "(J[Ljava/lang/String;ZLjava/lang/String;Ljava/lang/String;)I",
667693 (void *)com_android_internal_content_NativeLibraryHelper_findSupportedAbi_replace},
668694 {"hasRenderscriptBitcode", "(J)I",
669695 (void *)com_android_internal_content_NativeLibraryHelper_hasRenderscriptBitcode},
Show on old repository browser