mirror of
https://github.com/revanced/multidexlib2.git
synced 2025-05-03 08:04:32 +02:00
Refactor DexIO.writeCommon
This commit is contained in:
parent
7b27d0ca5a
commit
9ee3cce268
@ -128,26 +128,11 @@ public class DexIO {
|
|||||||
int fileClassCount = 0;
|
int fileClassCount = 0;
|
||||||
while (currentClass != null) {
|
while (currentClass != null) {
|
||||||
if (minimalMainDex && fileClassCount >= minMainDexClassCount) break;
|
if (minimalMainDex && fileClassCount >= minMainDexClassCount) break;
|
||||||
dexPool.mark();
|
if (!internClass(dexPool, currentClass, maxDexPoolSize)) {
|
||||||
dexPool.internClass(currentClass);
|
checkDexPoolOverflow(currentClass, fileClassCount, minMainDexClassCount);
|
||||||
fileClassCount++;
|
|
||||||
boolean overflow =
|
|
||||||
dexPool.typeSection.getItemCount() > maxDexPoolSize ||
|
|
||||||
//dexPool.protoSection.getItemCount() > maxDexPoolSize ||
|
|
||||||
dexPool.fieldSection.getItemCount() > maxDexPoolSize ||
|
|
||||||
dexPool.methodSection.getItemCount() > maxDexPoolSize ||
|
|
||||||
//dexPool.classSection.getItemCount() > maxDexPoolSize ||
|
|
||||||
false;
|
|
||||||
if (overflow) {
|
|
||||||
if (fileClassCount <= minMainDexClassCount) throw new DexPoolOverflowException(
|
|
||||||
"Dex pool overflowed while writing type " + fileClassCount +
|
|
||||||
" of " + minMainDexClassCount);
|
|
||||||
if (fileClassCount == 1) throw new DexPoolOverflowException(
|
|
||||||
"Type too big for dex pool: " + currentClass.getType());
|
|
||||||
dexPool.reset();
|
|
||||||
fileClassCount--;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
fileClassCount++;
|
||||||
currentClass = getQueueItem(queue, classIterator, lock);
|
currentClass = getQueueItem(queue, classIterator, lock);
|
||||||
}
|
}
|
||||||
synchronized (lock) {
|
synchronized (lock) {
|
||||||
@ -165,6 +150,30 @@ public class DexIO {
|
|||||||
} while (currentClass != null);
|
} while (currentClass != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean internClass(DexPool dexPool, ClassDef classDef, int maxDexPoolSize) {
|
||||||
|
dexPool.mark();
|
||||||
|
dexPool.internClass(classDef);
|
||||||
|
if (
|
||||||
|
dexPool.typeSection.getItemCount() > maxDexPoolSize ||
|
||||||
|
//dexPool.protoSection.getItemCount() > maxDexPoolSize ||
|
||||||
|
dexPool.fieldSection.getItemCount() > maxDexPoolSize ||
|
||||||
|
dexPool.methodSection.getItemCount() > maxDexPoolSize ||
|
||||||
|
//dexPool.classSection.getItemCount() > maxDexPoolSize ||
|
||||||
|
false
|
||||||
|
) {
|
||||||
|
dexPool.reset(); // roll back interning on pool overflow
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void checkDexPoolOverflow(ClassDef classDef, int classCount, int minClassCount) {
|
||||||
|
if (classCount < minClassCount) throw new DexPoolOverflowException(
|
||||||
|
"Dex pool overflowed while writing type " + (classCount + 1) + " of " + minClassCount);
|
||||||
|
if (classCount == 0) throw new DexPoolOverflowException(
|
||||||
|
"Type too big for dex pool: " + classDef.getType());
|
||||||
|
}
|
||||||
|
|
||||||
private static <T> T getQueueItem(Queue<T> queue, Iterator<? extends T> iterator, Object lock) {
|
private static <T> T getQueueItem(Queue<T> queue, Iterator<? extends T> iterator, Object lock) {
|
||||||
T item = queue.poll();
|
T item = queue.poll();
|
||||||
if (item == null) {
|
if (item == null) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user