mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-19 18:58:19 +00:00
Reducing chances for the object with finalizer to be reffed by register
As suggested in b/143155020#comment27 Bug: 143155020 Change-Id: I4ed87a003fcd7afde213014fc1ba8b004500e71a
This commit is contained in:
@@ -24,9 +24,10 @@ import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.os.Debug;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.Keep;
|
||||
|
||||
import com.android.launcher3.DeviceProfile;
|
||||
import com.android.launcher3.InvariantDeviceProfile;
|
||||
import com.android.launcher3.Launcher;
|
||||
@@ -186,6 +187,22 @@ public class TestInformationHandler implements ResourceBasedOverride {
|
||||
Runtime.getRuntime().runFinalization();
|
||||
|
||||
final CountDownLatch fence = new CountDownLatch(1);
|
||||
createFinalizationObserver(fence);
|
||||
try {
|
||||
do {
|
||||
Runtime.getRuntime().gc();
|
||||
Runtime.getRuntime().runFinalization();
|
||||
} while (!fence.await(100, TimeUnit.MILLISECONDS));
|
||||
} catch (InterruptedException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
// Create the observer in the scope of a method to minimize the chance that
|
||||
// it remains live in a DEX/machine register at the point of the fence guard.
|
||||
// This must be kept to avoid R8 inlining it.
|
||||
@Keep
|
||||
private static void createFinalizationObserver(CountDownLatch fence) {
|
||||
new Object() {
|
||||
@Override
|
||||
protected void finalize() throws Throwable {
|
||||
@@ -196,13 +213,5 @@ public class TestInformationHandler implements ResourceBasedOverride {
|
||||
}
|
||||
}
|
||||
};
|
||||
try {
|
||||
do {
|
||||
Runtime.getRuntime().gc();
|
||||
Runtime.getRuntime().runFinalization();
|
||||
} while (!fence.await(100, TimeUnit.MILLISECONDS));
|
||||
} catch (InterruptedException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user