Status Update
Comments
sg...@google.com <sg...@google.com> #2
Thank you for the report. Using -assumenosideeffects
can have undesired effects at runtime, however it should never lead VerifyError
. Do you have a reproduction that you can share? If possible you can share a
dm...@gmail.com <dm...@gmail.com> #3
Hello!
Unfortunately, this cannot be reproduced on a "clean" project, and I cannot share the full AS project.
I can privately share the compiler dumps of a project where the error occurs, but I don't know which one you need - with the faulty rules applied or without them, or both?
Thanks!
sg...@google.com <sg...@google.com> #4
You can share either of them, it doesn't matter which, as we can modify the rules in the dump to reproduce both cases.
dm...@gmail.com <dm...@gmail.com> #5
Sent the dump to both emails, I hope it will help.
sg...@google.com <sg...@google.com> #6
Thank you for the dump. I can reproduce the issue, getting the following when verifying the generated DEX:
08-17 05:05:29.665 11573 11576 W dex2oat : Verification error in java.lang.Object kr4.invoke(java.lang.Object)
08-17 05:05:29.665 11573 11576 W dex2oat : java.lang.Object kr4.invoke(java.lang.Object) failed to verify: java.lang.Object kr4.invoke(java.lang.Object): [0x0] 'this' argument 'Reference: java.lang.Object' not instance of 'Reference: kr4'
08-17 05:05:29.675 11573 11576 W dex2oat : Rejecting class a17 that attempts to sub-type erroneous class kr4 in /data/local/tmp/out.jar
08-17 05:05:29.676 11573 11576 W dex2oat : Rejecting class a89 that attempts to sub-type erroneous class kr4 in /data/local/tmp/out.jar
... Lots of Rejecting class xxx that attempts to sub-type erroneous class kr4 in /data/local/tmp/out.jar
Mapping file contains:
kotlin.jvm.internal.Lambda -> kr4:
The issue reproduces on our main branch.
Removing public static void checkNotNullParameter(...);
from the -assumenosideeffects class kotlin.jvm.internal.Intrinsics
removes the verification error.
sg...@google.com <sg...@google.com> #7
Building with main kotlin.jvm.internal.Lambda -> pt4:
The verification issue with pt4.invoke
is obvious:
.method public invoke(Ljava/lang/Object;)Ljava/lang/Object;
.locals 0
invoke-virtual {p1}, Lpt4;->toString()Ljava/lang/String;
move-result-object p1
return-object p1
.end method
sg...@google.com <sg...@google.com>
ap...@google.com <ap...@google.com> #8
Branch: main
commit 8b452944fdfbb850046222d33357d21eea6acef5
Author: Søren Gjesse <sgjesse@google.com>
Date: Mon Aug 21 11:53:39 2023
Reproduce invalid code produced from bridge hoisting
Bug:
Change-Id: I3b1a7932dcdc7222f0ee9e3143ea3f855e2b936f
A src/test/java/com/android/tools/r8/bridgeremoval/hoisting/BridgeAfterAssumeNoSideEffectsTest.java
ap...@google.com <ap...@google.com> #9
Branch: main
commit 6b618fb57de003c4a65487b52b405f20ec88cfd7
Author: Søren Gjesse <sgjesse@google.com>
Date: Mon Aug 21 11:55:41 2023
Handle assume instructions in bridge hoisting
Bug:
Change-Id: I17f6760d041e95618a0d048572a306c64a042457
M src/main/java/com/android/tools/r8/ir/optimize/info/bridge/BridgeAnalyzer.java
M src/test/java/com/android/tools/r8/bridgeremoval/hoisting/BridgeAfterAssumeNoSideEffectsTest.java
ap...@google.com <ap...@google.com> #10
Branch: 8.2
commit a8991323e2d54cfff809e9936f9cc27f87faf4a4
Author: Søren Gjesse <sgjesse@google.com>
Date: Tue Aug 22 11:54:11 2023
Version 8.2.26
Bug:
Change-Id: I9062b2c64cf4e9f503cee107829148846d89d152
M src/main/java/com/android/tools/r8/Version.java
ap...@google.com <ap...@google.com> #11
Branch: 8.2
commit 84e04300f9f777f052a0d705660f623512d0abca
Author: Søren Gjesse <sgjesse@google.com>
Date: Tue Aug 22 11:53:27 2023
Handle assume instructions in bridge hoisting
Bug:
Change-Id: I17f6760d041e95618a0d048572a306c64a042457
M src/main/java/com/android/tools/r8/ir/optimize/info/bridge/BridgeAnalyzer.java
M src/test/java/com/android/tools/r8/bridgeremoval/hoisting/BridgeAfterAssumeNoSideEffectsTest.java
ap...@google.com <ap...@google.com> #12
Branch: 8.2
commit 0a41d9044ecadbdfaa13203628b19d23a5e9a2e2
Author: Søren Gjesse <sgjesse@google.com>
Date: Tue Aug 22 11:53:13 2023
Reproduce invalid code produced from bridge hoisting
Bug:
Change-Id: I3b1a7932dcdc7222f0ee9e3143ea3f855e2b936f
A src/test/java/com/android/tools/r8/bridgeremoval/hoisting/BridgeAfterAssumeNoSideEffectsTest.java
ap...@google.com <ap...@google.com> #13
Branch: 8.1
commit 27225cb3591e706ed9755f9228279b91efeddf65
Author: Søren Gjesse <sgjesse@google.com>
Date: Tue Aug 22 15:38:14 2023
Version 8.1.67
Bug:
Change-Id: I0a90e53df159ca2a81ec29ed58a88c3928d51423
M src/main/java/com/android/tools/r8/Version.java
ap...@google.com <ap...@google.com> #14
Branch: 8.1
commit 2c6a9d70c479f5508bcdf7192f713f787cb64bbb
Author: Søren Gjesse <sgjesse@google.com>
Date: Tue Aug 22 15:35:27 2023
Reproduce invalid code produced from bridge hoisting
Bug:
Change-Id: I3b1a7932dcdc7222f0ee9e3143ea3f855e2b936f
A src/test/java/com/android/tools/r8/bridgeremoval/hoisting/BridgeAfterAssumeNoSideEffectsTest.java
ap...@google.com <ap...@google.com> #15
Branch: 8.1
commit c702a784e14306728755030f96e64d7808676484
Author: Søren Gjesse <sgjesse@google.com>
Date: Tue Aug 22 15:38:00 2023
Handle assume instructions in bridge hoisting
Bug:
Change-Id: I17f6760d041e95618a0d048572a306c64a042457
M src/main/java/com/android/tools/r8/ir/optimize/info/bridge/BridgeAnalyzer.java
M src/test/java/com/android/tools/r8/bridgeremoval/hoisting/BridgeAfterAssumeNoSideEffectsTest.java
ap...@google.com <ap...@google.com> #16
Branch: 8.0
commit 64b314fb5389edd02d5c588ab6ce8d8168eab00b
Author: Søren Gjesse <sgjesse@google.com>
Date: Tue Aug 22 16:07:28 2023
Reproduce invalid code produced from bridge hoisting
Bug:
Change-Id: I3b1a7932dcdc7222f0ee9e3143ea3f855e2b936f
A src/test/java/com/android/tools/r8/bridgeremoval/hoisting/BridgeAfterAssumeNoSideEffectsTest.java
ap...@google.com <ap...@google.com> #17
Branch: 8.0
commit e43d0dd4d1f1ee92efc96869621ba31d124fe503
Author: Søren Gjesse <sgjesse@google.com>
Date: Tue Aug 22 16:08:59 2023
Version 8.0.64
Bug:
Change-Id: I02c22c219030f39db053adc109367e24b8f1e6a9
M src/main/java/com/android/tools/r8/Version.java
ap...@google.com <ap...@google.com> #18
Branch: 8.0
commit c507b4132c0d989286e2fce27e6118bef2a5cb86
Author: Søren Gjesse <sgjesse@google.com>
Date: Tue Aug 22 16:08:30 2023
Handle assume instructions in bridge hoisting
Bug:
Change-Id: I17f6760d041e95618a0d048572a306c64a042457
M src/main/java/com/android/tools/r8/ir/optimize/info/bridge/BridgeAnalyzer.java
M src/test/java/com/android/tools/r8/bridgeremoval/hoisting/BridgeAfterAssumeNoSideEffectsTest.java
sg...@google.com <sg...@google.com> #19
This is now fixed, and you can use R8 8.1.67 with AGP 8.1.1 (or 8.1.0). The fix did not make it into AGP 8.1.1, which shipped with
For AGP 8.0.x use 8.0.64. For AGP 8.2.x use 8.2.26 which will go into Android Studio Hedgehog / AGP 8.2 Beta 2.
To use a specific R8 version (e.g. 8.1.67) merge the following into settings.gradle
or settings.gradle.kts
:
pluginManagement {
buildscript {
repositories {
mavenCentral()
maven {
url = uri("https://storage.googleapis.com/r8-releases/raw")
}
}
dependencies {
classpath("com.android.tools:r8:8.1.67")
}
}
}
to...@gmail.com <to...@gmail.com> #20
Thank you for the report. Using -assumenosideeffects can have undesired effects at runtime
Sorry to jump on this issue, but since this is something that came up a few times but never ended in an official statement about it maybe now is the time to ask again.
I'm also using:
-assumenosideeffects class kotlin.jvm.internal.Intrinsics {
public static void checkNotNull(...);
public static void checkExpressionValueIsNotNull(...);
public static void checkNotNullExpressionValue(...);
public static void checkParameterIsNotNull(...);
public static void checkNotNullParameter(...);
public static void checkReturnedValueIsNotNull(...);
public static void checkFieldIsNotNull(...);
public static void throwUninitializedPropertyAccessException(...);
public static void throwNpe(...);
public static void throwJavaNpe(...);
public static void throwAssert(...);
public static void throwIllegalArgument(...);
public static void throwIllegalState(...);
}
As even with R8 full mode it reduce the dex file by aprox 100 Kb.
What is the official R8 team position about those rules, there's often remarks they probably should not be used, but no definitive answer about yes or no.
Is there any possible side effect about those specific ones, that could overcome the dex size gain?
sg...@google.com <sg...@google.com> #21
In general using -assumenosideeffects
can be dangerous as it can unconditionally remove code.
In the case of the check*
methods the null
checks will be removed. In most cases that will just postpone the NPE until later when the null value is accessed. However, that might be way later in the program execution (e.g. the value is used to set a field which is then accessed in a completely different code path). So the code will have different behavior. In the case of a pure Kotlin project this should (almost) be safe, as nullability is checked at compile time.
It is also possible to have the Kotlin compiler not emitting null checks using something like this:
android {
kotlinOptions {
freeCompilerArgs = listOf(
"-Xno-param-assertions",
"-Xno-call-assertions",
"-Xno-receiver-assertions"
)
}
}
However, that only works for the code which is compiled from source and not binary dependencies.
For the throw*
I don't know when they are actually generated by the Kotlin compiler, so how removing these affects the application soundness I cannot say.
ap...@google.com <ap...@google.com> #22
Branch: 4.0
commit 5b3819134a7d7bb3fc3ca4a9b79dc25a065a39f4
Author: Søren Gjesse <sgjesse@google.com>
Date: Tue Aug 22 16:21:18 2023
Handle assume instructions in bridge hoisting
Bug:
Change-Id: I17f6760d041e95618a0d048572a306c64a042457
M src/main/java/com/android/tools/r8/ir/optimize/info/bridge/BridgeAnalyzer.java
M src/test/java/com/android/tools/r8/bridgeremoval/hoisting/BridgeAfterAssumeNoSideEffectsTest.java
ap...@google.com <ap...@google.com> #23
Branch: 4.0
commit ec460f9dde31a99170d126d6e20f6f8794f9a559
Author: Søren Gjesse <sgjesse@google.com>
Date: Tue Aug 22 16:17:19 2023
Reproduce invalid code produced from bridge hoisting
Bug:
Change-Id: I3b1a7932dcdc7222f0ee9e3143ea3f855e2b936f
A src/test/java/com/android/tools/r8/bridgeremoval/hoisting/BridgeAfterAssumeNoSideEffectsTest.java
ap...@google.com <ap...@google.com> #24
Branch: 4.0
commit f91d04a07894ffa0d9bb58e6d45bdf87547dd4b5
Author: Søren Gjesse <sgjesse@google.com>
Date: Tue Aug 22 16:21:35 2023
Version 4.0.69
Bug:
Change-Id: I761b1fa3b18d28e3a26c1056482d8eb5657c0712
M src/main/java/com/android/tools/r8/Version.java
an...@google.com <an...@google.com> #25
Thank you for your patience while our engineering team worked to resolve this issue. A fix for this issue is now available in:
- Android Studio Hedgehog | 2023.1.1 Beta 3
- Android Gradle Plugin 8.2.0-beta03
We encourage you to try the latest update.
If you notice further issues or have questions, please file a new bug report.
Thank you for taking the time to submit feedback — we really appreciate it!
an...@google.com <an...@google.com> #26
The fixes for this issue are now also available in:
- Android Studio Giraffe | 2022.3.1 Patch 2
- Android Gradle Plugin 8.1.2
We encourage you to try the latest update.
If you notice further issues or have questions, please file a new bug report.
Description
After updating Kotlin from 1.8.21 to 1.9.0 and R8 from 4.0.48 to 8.1.56 I started receiving this fatal exception:
A quick look in a JaDX decompiler has shown that ox6 is some kind of autogenerated lambda state machine, probably a work of Kotlin compiler or R8?
Also, probably, this might be an issue of the following Proguard rules regarding stripping out Kotlin nullchecks in production, because removing them makes the application launch:
(these rules worked in R8 4.x, however)
R8: 8.1.56 (build 892155436bed60c4f2f7672d4993950e7b342bd9 from go/r8bot (luci-r8-custom-ci-focal-2-5rpr))
AGP: 8.1.0
Kotlin: 1.9.0 (K2 is disabled, KSP + KAPT applied)
JVM Target: 11