Skip to content

JarFileWrapper may cause many FinalReferences causing GC pressure #28042

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
HzjNeverStop opened this issue Sep 17, 2021 · 12 comments
Closed

JarFileWrapper may cause many FinalReferences causing GC pressure #28042

HzjNeverStop opened this issue Sep 17, 2021 · 12 comments
Assignees
Labels
type: regression A regression from a previous release
Milestone

Comments

@HzjNeverStop
Copy link

HzjNeverStop commented Sep 17, 2021

Environment:spring boot 2.5.4 + jdk8
Create a bean to continue load class which could not be found,than use java -jar start springboot fatjar

@Component
public class TestClass implements InitializingBean {
    @Override
    public void afterPropertiesSet() throws Exception {
        new Thread(() -> {
            while (true) {
                try {
                    Class.forName("com.test.error.NotClassFound");
                } catch (ClassNotFoundException e) {
                    //ignore
                }
            }
        }).start();
    }
}

many org.springframework.boot.loader.jar.JarFileWrapper will be create which increase FinalReference time in gc:
20210917132511

when update spring boot version to 2.1.13,it's ok:
20210917132520

In normal it will not happen because LaunchedURLClassLoader has package cache,but it will happen when so bug trigger many nonexistent class load.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Sep 17, 2021
@wilkinsona wilkinsona changed the title org.springframework.boot.loader.jar.JarFileWrapper may cause may FinalReference org.springframework.boot.loader.jar.JarFileWrapper may cause many FinalReference Oct 1, 2021
@wilkinsona
Copy link
Member

Thanks for the report. I have reproduced the behaviour that you have described. I suspect that the changes for #22991 are the cause. It was intended to fix a problem that's specific to Java 11 but it looks as if it may have regressed things on Java 8. Running on Java 8, the peak memory footprint of JarFileWrapper is around 10x the peak that I see on Java 11.

@wilkinsona wilkinsona changed the title org.springframework.boot.loader.jar.JarFileWrapper may cause many FinalReference org.springframework.boot.loader.jar.JarFileWrapper may cause many FinalReference when running on Java 8 Oct 1, 2021
@wilkinsona wilkinsona added type: regression A regression from a previous release and removed status: waiting-for-triage An issue we've not yet triaged labels Oct 1, 2021
@wilkinsona wilkinsona added this to the 2.4.x milestone Oct 1, 2021
@wilkinsona
Copy link
Member

This may have been reported previously in #23505 but there wasn't enough information to diagnose the problem.

@wilkinsona
Copy link
Member

wilkinsona commented Oct 4, 2021

@philwebb What's your take on this one? Short of having different code for Java 8 and Java 11 (which is tricky as we're sub-classing), I'm not sure what the best approach is here.

@wilkinsona wilkinsona added the for: team-attention An issue we'd like other members of the team to review label Oct 4, 2021
@philwebb philwebb self-assigned this Oct 4, 2021
@philwebb philwebb removed the for: team-attention An issue we'd like other members of the team to review label Oct 4, 2021
@philwebb
Copy link
Member

philwebb commented Oct 7, 2021

I'm really not sure how to fix this one. We do have #26745 open as well.

@philwebb philwebb changed the title org.springframework.boot.loader.jar.JarFileWrapper may cause many FinalReference when running on Java 8 JarFileWrapper may cause many FinalReferences causing GC pressure Oct 15, 2021
@philwebb philwebb modified the milestones: 2.4.x, 2.4.12 Oct 15, 2021
@philwebb
Copy link
Member

@wilkinsona would you mind checking this fix to see if it works with your sample. I think it's working when I try it both on Java 11 and 8.

@philwebb philwebb reopened this Oct 15, 2021
@wilkinsona
Copy link
Member

👍 LGTM.

@fankaifeng
Copy link

fankaifeng commented Aug 1, 2023

hello,I had the same problem, What should I do

@wilkinsona
Copy link
Member

@fankaifeng As far as we know, this problem was fixed in Spring Boot 2.4.12. If you're using a newer version of Spring Boot and the problem is still occurring, please open a new issue and provide a complete yet minimal sample that reproduces it.

@fankaifeng
Copy link

Why is the problem version 2.5.4 raised by HzjNeverStop not compatible after 2.4.12, our version is 2.3.12.RELEASE, do not want to upgrade, how to solve it

@bclozel
Copy link
Member

bclozel commented Aug 1, 2023

@fankaifeng it's been fixed in 2.5.6 as well, see #28356.
Spring Boot 2.3.x has been out of open source support for 2+ years and of commercial support for a year now. We won't release new 2.3.x versions; please upgrade to a supported Spring Boot version.

@helloworldtang
Copy link

2.5.2 also have the problem:
org.springframework.boot.loader.jar.JarFileWrapper may cause many FinalReference when running on Java 8

jdk version: 1.8.0_144
spring boot:2.5.2

from dump :
image

image

@wilkinsona
Copy link
Member

@helloworldtang That is to be expected as this issue was not fixed until 2.5.6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: regression A regression from a previous release
Projects
None yet
Development

No branches or pull requests

7 participants