Skip to content
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

8261154: Memory leak in Java_java_lang_ClassLoader_defineClass0 with long class names #2407

Closed
wants to merge 4 commits into from

Conversation

cl4es
Copy link
Member

@cl4es cl4es commented Feb 4, 2021

This patch resolves a potential memory leak in Java_java_lang_ClassLoader_defineClass0

I've not figured a good way to write a regression test. A crude way to manually verify the leak and the fix is provided by the added microbenchmark that triggers the malloc in ClassLoader.c and the associated leak.

E.g., running this with /usr/bin/time -v $BUILD_DIR/images/jdk/bin/java -Xmx256m -jar $BUILD_DIR/images/test/micro/benchmarks.jar LookupDef.*WeakClass.loadLong -f 0 -i N | grep "Maximum resident set" yields:

Baseline:
N = 20     Maximum resident set size (kbytes): 544860
N = 50     Maximum resident set size (kbytes): 818532
N = 100    Maximum resident set size (kbytes): 1388560
N = 200    Maximum resident set size (kbytes): 2124296
Patch:
N = 20     Maximum resident set size (kbytes): 480476
N = 50     Maximum resident set size (kbytes): 764040
N = 100    Maximum resident set size (kbytes): 782920
N = 200    Maximum resident set size (kbytes): 921272

Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8261154: Memory leak in Java_java_lang_ClassLoader_defineClass0 with long class names

Reviewers

Download

$ git fetch https://git.openjdk.java.net/jdk pull/2407/head:pull/2407
$ git checkout pull/2407

@cl4es cl4es changed the title 8261154: Potential memory leak in Java_java_lang_ClassLoader_defineClass0 8261154: Memory leak in Java_java_lang_ClassLoader_defineClass0 Feb 4, 2021
@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented Feb 4, 2021

👋 Welcome back redestad! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@cl4es cl4es changed the title 8261154: Memory leak in Java_java_lang_ClassLoader_defineClass0 8261154: Memory leak in Java_java_lang_ClassLoader_defineClass0 with long class names Feb 4, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Feb 4, 2021

@cl4es The following label will be automatically applied to this pull request:

  • core-libs

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the core-libs label Feb 4, 2021
@cl4es cl4es marked this pull request as ready for review Feb 4, 2021
@openjdk openjdk bot added the rfr label Feb 4, 2021
@mlbridge
Copy link

@mlbridge mlbridge bot commented Feb 4, 2021

Webrevs

Copy link
Member

@tstuefe tstuefe left a comment

Hi Cleas,

looks good but why changing the the NULL comparisons?

If you wanted to simplify you could completely omit the NULL checks since free(NULL) is a noop. And potentially merge the labels - where there are two - into one.

Cheers, Thomas

@cl4es
Copy link
Member Author

@cl4es cl4es commented Feb 4, 2021

I'm not sure every platform have always agreed free(NULL) is a noop. I suspect all the currently supported ones do, though?

@tstuefe
Copy link
Member

@tstuefe tstuefe commented Feb 4, 2021

I'm not sure every platform have always agreed free(NULL) is a noop. I suspect all the currently supported ones do, though?

Its standard behavior.

Posix: https://pubs.opengroup.org/onlinepubs/009695399/functions/free.html "If ptr is a null pointer, no action shall occur. "
Windows: https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/free?view=msvc-160 " If memblock is NULL, the pointer is ignored and free immediately returns. "

So it should be okay.

@cl4es
Copy link
Member Author

@cl4es cl4es commented Feb 4, 2021

Right. I dialed back the changes here since this is a bug fix that should be kept minimal. I have another change in the pipeline that will touch code here that can double down on cleaning up.

Copy link
Member

@ChrisHegarty ChrisHegarty left a comment

LGTM.

tstuefe
tstuefe approved these changes Feb 4, 2021
Copy link
Member

@tstuefe tstuefe left a comment

Looks good!

@openjdk
Copy link

@openjdk openjdk bot commented Feb 4, 2021

@cl4es This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8261154: Memory leak in Java_java_lang_ClassLoader_defineClass0 with long class names

Reviewed-by: stuefe, chegar, mchung

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 55 new commits pushed to the master branch:

  • e93e1e1: 8261157: Incorrect GPL header after JDK-8259956
  • c1dea39: 8260335: [macos] Running app using relative path causes problems
  • f7a6cff: 8261149: Initial nroff manpage update for JDK 17
  • be772ff: 8261023: Document why memory pretouch must be a store
  • 83357b1: 8261030: Avoid loading GenerateJLIClassesHelper at runtime
  • 992b500: 8261036: Reduce classes loaded by CleanerFactory initialization
  • e8ad8b3: 8259956: jdk.jfr.internal.ChunkInputStream#available should return the sum of remaining available bytes
  • 06b33a0: 8261107: ArrayIndexOutOfBoundsException in the ICC_Profile.getInstance(InputStream)
  • 60f440d: 6436374: Graphics.setColor(null) is not documented
  • 82028e7: 8260012: Reduce inclusion of collectedHeap.hpp and heapInspection.hpp
  • ... and 45 more: https://git.openjdk.java.net/jdk/compare/ddd2951ba91fe3860b92d2f9bad4e0d900f1d650...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready label Feb 4, 2021
mlchung
mlchung approved these changes Feb 4, 2021
Copy link
Member

@mlchung mlchung left a comment

Looks good. Thanks for fixing this.

@cl4es
Copy link
Member Author

@cl4es cl4es commented Feb 5, 2021

@tstuefe, @ChrisHegarty, @mlchung - thanks for reviewing!

/integrate

@openjdk openjdk bot closed this Feb 5, 2021
@openjdk openjdk bot added integrated and removed ready rfr labels Feb 5, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Feb 5, 2021

@cl4es Since your change was applied there have been 65 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

Pushed as commit 0791899.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@cl4es cl4es deleted the utf_leak branch Feb 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs integrated
4 participants