mirror of
https://github.com/google/guava.git
synced 2026-10-28 16:47:30 +08:00
I want to call attention up front to the fact that _`Finalizer`_ still uses reflection (to invoke `finalizeReferent`). We might imagine an alternative class similar to `Finalizer` that we'd use in the same-class-loader case. That class could call `finalizeReferent` directly. Hopefully it wouldn't need to [worry about class unloading](https://github.com/google/guava/blob/de2b19178d2748fe09402c531ef75350af634667/guava/src/com/google/common/base/internal/Finalizer.java#L70-L71), since we might be running under an environment in which that's not a thing? But this would deserve more thought. Anyway: The motivation here is that GraalVM needs help to see through reflection, just as Proguard, R8, etc. do. We haven't made much [effort to support Graal](https://github.com/google/guava/issues/3894), but this CL is an easy enough win. (Again, given that we _also_ use reflection in `Finalizer`, I wouldn't assume that `FinalizableReference`+GraalVM now "works." But it does now get through an initial step that I was testing against.) This CL might also allow us to simplify our Proguard configuration. However, it's not necessarily that simple: - Since we still _attempt_ reflection, we might want the class we reflect upon to still have its expected shape, even if we ultimately don't use it for one reason or another. - We could consider configuring Proguard with `-assumevalues` so that it _doesn't_ attempt reflection. (Compare https://github.com/google/guava/commit/14050c34d13b64846875d1a7b3ca4a1003a1e5cf, which I later undid in https://github.com/google/guava/commit/75da92419a7d414bd3de23c89f2ddfd83754767d.) - _Technically_, we should keep in mind that it's possible to use Proguard for a _server_ app, so "Proguard" does not imply "Android," and we ideally would write rules with that in mind. (This also came up in https://github.com/google/guava/commit/75da92419a7d414bd3de23c89f2ddfd83754767d.) In practice, I'm not sure how much that would matter. RELNOTES=n/a PiperOrigin-RevId: 884581412
38 lines
1.4 KiB
Prolog
38 lines
1.4 KiB
Prolog
# Note: We intentionally don't add the flags we'd need to make Flags and Enums
|
|
# work. That's because the Proguard configuration required to make them work on
|
|
# optimized code would preclude lots of optimization, like converting enums
|
|
# into ints.
|
|
|
|
# Throwables uses internal APIs for lazy stack trace resolution
|
|
-dontnote sun.misc.SharedSecrets
|
|
-keep class sun.misc.SharedSecrets {
|
|
*** getJavaLangAccess(...);
|
|
}
|
|
-dontnote sun.misc.JavaLangAccess
|
|
-keep class sun.misc.JavaLangAccess {
|
|
*** getStackTraceElement(...);
|
|
*** getStackTraceDepth(...);
|
|
}
|
|
|
|
# FinalizableReferenceQueue calls this reflectively
|
|
# Proguard is intelligent enough to spot the use of reflection onto this, so we
|
|
# only need to keep the names, and allow it to be stripped out if
|
|
# FinalizableReferenceQueue is unused.
|
|
#
|
|
# (Under Android, we end up using Finalzier non-reflectively, so we could
|
|
# likely rework all this configuration.)
|
|
-keepclassmembernames class com.google.common.base.internal.Finalizer {
|
|
*** startFinalizer(...);
|
|
}
|
|
# However, it cannot "spot" that this method needs to be kept IF the class is.
|
|
-keepclassmembers class com.google.common.base.internal.Finalizer {
|
|
*** startFinalizer(...);
|
|
}
|
|
|
|
-keepclassmembernames class com.google.common.base.FinalizableReference {
|
|
void finalizeReferent();
|
|
}
|
|
-keepclassmembers class com.google.common.base.FinalizableReference {
|
|
void finalizeReferent();
|
|
}
|