Skip to content

Fix permgen leak by storing Class instances as String #50

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

Merged
merged 3 commits into from
Feb 4, 2016

Conversation

vlsi
Copy link
Contributor

@vlsi vlsi commented Nov 13, 2015

Previously KeyFactory generated java.lang.Class fields even with CLASS_BY_NAME customization.
That might lead to unexpected class and classloader leak.
The fix ensures KeyFactory uses java.lang.String to store class names.
It should make no harm as CGLIB uses per-classloader cache, thus class name should be sufficiently unique.

@vlsi vlsi mentioned this pull request Nov 13, 2015
@@ -84,14 +84,30 @@
938313161, 1288102441, 1768288259 };


public static final Customizer CLASS_BY_NAME = new Customizer() {
public static final Customizer CLASS_BY_NAME = new Customizer2() {
public void customize(CodeEmitter e, Type type) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a no-op and be defined in the interface

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically speaking, if someone uses CLASS_BY_NAME as Customizer, he/she would expect Customizer.customize(CodeEmitter e, Type type) do some meaningful stuff.

So, the implementation is there for backward compatibility

@elrodro83 elrodro83 mentioned this pull request Nov 14, 2015
@@ -425,7 +425,7 @@ private static void hash_object(CodeEmitter e, Type type, Customizer customizer)
Label end = e.make_label();
e.dup();
e.ifnull(skip);
if (customizer != null) {
if (customizer != null && !(customizer instanceof FieldTypeCustomizer)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can these logic be handled by the concrete Customizer rather than here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can do that, however it would require adding additional field for fieldCustomizer.

The thing is logic behind old and new customizers is quite different: old customizer augmented hashCode/equals code while new one augments field types and constructor.

@vlsi vlsi force-pushed the fix_class_leak branch 2 times, most recently from 83289d1 to 6a9873a Compare November 16, 2015 15:00
@vlsi
Copy link
Contributor Author

vlsi commented Nov 16, 2015

Please check updated PR.
I've used different interfaces for Customizer, FieldTypeCustomizer, etc, so no more instanceof checks in the business code.

Previously KeyFactory generated java.lang.Class fields even with CLASS_BY_NAME customization.
That might lead to unexpected class and classloader leak.
The fix ensures KeyFactory uses java.lang.String to store class names.
It should make no harm as CGLIB uses per-classloader cache, thus class name should be sufficiently unique
@elrodro83
Copy link
Contributor

@sameb Any chance this can be merged? How long would it take to have a release in the maven repos that includes this fix?

@elrodro83
Copy link
Contributor

Is there anybody else apart from @sameb that can merge PRs?

@vlsi
Copy link
Contributor Author

vlsi commented Dec 22, 2015

@JBodkin, @lukesandberg, can you have a look?

@lukesandberg
Copy link
Contributor

Sorry I don't have commiter privileges.

On Tue, Dec 22, 2015, 7:41 AM Vladimir Sitnikov [email protected]
wrote:

@JBodkin https://github.com/JBodkin, @lukesandberg
https://github.com/lukesandberg, can you have a look?


Reply to this email directly or view it on GitHub
#50 (comment).

@ghost
Copy link

ghost commented Dec 30, 2015

I'm afraid I don't have committer privileges, hopefully sameb will be back after the holidays.

@sameb
Copy link
Contributor

sameb commented Jan 4, 2016

Hi everyone, I'm going to talk with Chris N (one of the original owners of cglib) about adding more committers here, since I don't have the time to keep up with all the pull requests. I'll try to review the outstanding ones over the course of this week.

raphw pushed a commit that referenced this pull request Feb 4, 2016
To the best of my knowledge, this looks like a good solution given the bounds of the current implementation. I favour this solution over #54, it seems like the cleaner solution and it is benchmarked.
@raphw raphw merged commit 196da25 into cglib:master Feb 4, 2016
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

Successfully merging this pull request may close these issues.

5 participants