Skip to content

Cache miss with AGP 7.4 #416

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
GianfrancoMS opened this issue Jan 14, 2023 · 7 comments
Closed

Cache miss with AGP 7.4 #416

GianfrancoMS opened this issue Jan 14, 2023 · 7 comments

Comments

@GianfrancoMS
Copy link

GianfrancoMS commented Jan 14, 2023

At my company, we're trying to update to AGP 7.4 and to the Android Cache Fix Gradle Plugin 2.6.2, but we have encountered a cache miss with the task compile${variant}JavaWithJavac. This cache miss did not happen in previous versions.

Versions:

  • Gradle 7.5.1
  • Kotlin 1.7.21
  • AGP 7.4 (previous was 7.3.1)
  • Android Cache Fix Gradle Plugin 2.6.2 (previous was 2.6.1)
  • JDK 17

Screenshot 2023-01-14 at 11 55 20

Let me know if you need a scan dump since my GE instance is behind a VPN.

@cdsap
Copy link
Member

cdsap commented Jan 14, 2023

hi @GianfrancoMS, thanks for reporting this issue.
I notice the issue is coming from the jdkImage. We provided a JdkImageWorkaround for AGP < 7.4 but the workaround is not applied for AGP 7.4 since the fix was provided in AGP 7.4.0-alpha07 (https://issuetracker.google.com/u/1/issues/234820480#comment6)

If you test 2.6.2 with AGP 7.3.1 works right?

We will test again the AGP 7.4 reproducing the JdkImage issue. If is not fixed, we will apply again the workaround in the latest AGP.

@GianfrancoMS
Copy link
Author

2.6.2 with AGP 7.3.1 works perfectly. It only happens with AGP 7.4.

@cdsap
Copy link
Member

cdsap commented Jan 18, 2023

Hi @GianfrancoMS, I finished the investigation and here is the result:

The existing issue mentioned https://issuetracker.google.com/u/1/issues/234820480 is not reproducible in AGP 7.4, so the workaround is correctly not applied in the AGP 7.4.

Now, why are we seeing this cache miss in the JavaCompile?
First, I reproduced your issue in a simple project with AGP 7.4 and Android Cache Fix Plugin 2.6.2 executing builds in different Java versions:
Screen Shot 2023-01-17 at 6 28 12 PM
I noticed that the reason is different from one project using 7.3.1:
Screen Shot 2023-01-17 at 6 29 49 PM

We observe that the file properties differences lay on jrt-fs.jar for our builds with 7.4 and for 7.3 is the entire folder.
That means, that Google has fixed correctly the original issue, but still we are seeing differences in the jar.

This is a known issue that normalization can fix. To be sure, I compared two builds with different Java versions and collected the jar for each job. Applying a diff on the two folders we have:
Screen Shot 2023-01-17 at 6 39 55 PM
We can notice small differences in the internal folders jimage and decompressor.
So applying the normalization:

allprojects {
     normalization {
        runtimeClasspath {
            ignore '**/jdk/internal/jimage/decompressor/**'
            ignore '**/jdk/internal/jrtfs/**'
        }
    }
}

Fixes the issue:
Screen Shot 2023-01-17 at 6 43 35 PM

Please let me know if the normalisation configuration works for you, I would recommend verifying the jar differences to better understand what to normalize.

@GianfrancoMS
Copy link
Author

GianfrancoMS commented Jan 18, 2023

It's a really weird difference.

Screenshot 2023-01-18 at 17 53 47

CI

  • OS: Linux 4.14.77-80.57.amzn2.x86_64 (amd64)
  • Java runtime: Private Build OpenJDK Runtime Environment 17.0.5+8-Ubuntu-2ubuntu122.04
  • Java VM: Private Build OpenJDK 64-Bit Server VM 17.0.5+8-Ubuntu-2ubuntu122.04 (mixed mode, sharing)

LOCAL

  • OS: macOS 13.1 (aarch64)
  • Java runtime: Oracle OpenJDK Runtime Environment 17.0.2+8-86
  • Java VM: Oracle OpenJDK 64-Bit Server VM 17.0.2+8-86 (mixed mode, sharing)

@GianfrancoMS
Copy link
Author

GianfrancoMS commented Jan 18, 2023

Applying normalization with these values worked:

normalization {
    runtimeClasspath {
        ignore '**/jdk/internal/jimage/**'
        ignore '**/jdk/internal/jrtfs/**'
        ignore '**/module-descriptor.txt'
        ignore '**/java/lang/invoke/**'
    }
}

I added the extra ones just to make sure we do not have problems with other JDK distributions. Do you think it is a reasonable decision?

@cdsap
Copy link
Member

cdsap commented Jan 21, 2023

@GianfrancoMS, we have one interesting finding:
the cache miss for Java 17 is only present in versions 17.0.2, if you bump your Java version to 17.0.(3,4,5...) you will have a cache hit without normalization.

@GianfrancoMS
Copy link
Author

Fixed in #419

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants