Skip to content

Remove usage of ObjectCleaner - #8064

Merged
normanmaurer merged 1 commit into
4.1from
no_cleaner
Jun 28, 2018
Merged

normanmaurer merged 1 commit into
4.1from
no_cleaner

Conversation

@normanmaurer

@normanmaurer normanmaurer commented Jun 27, 2018 •

Copy link
Copy Markdown
Member

Motivation:

ObjectCleaner does start a Thread to handle the cleaning of resources which leaks into the users application. We should not use it in netty itself to make things more predictable.

Modifications:

  • Remove usage of ObjectCleaner and use finalize as a replacement when possible.
  • Clarify javadocs for FastThreadLocal.onRemoval(...) to ensure its clear that remove() is not guaranteed to be called when the Thread completees and so this method is not enough to guarantee cleanup for this case.

Result:

Fixes #8017.

@normanmaurer

Copy link
Copy Markdown
Member Author

@jasontedor @johnou FYI as well... When working on this I also noticed that the docs not really said that onRemoval(...) is guaranteed to be called when a Thread completes.

@normanmaurer

normanmaurer commented Jun 27, 2018 •

Copy link
Copy Markdown
Member Author

So with this and #8062 there is no more need to use ObjectCleaner.

The behaviour of FastThreadLocal changes basically back to before this commit:
e329ca1#diff-e0eb4e9a6ea15564e4ddd076c55978de

This was introduced in 4.1.20.Final

@normanmaurer

Copy link
Copy Markdown
Member Author

I have also another idea to still somehow guarantee the call of onRemoval without the extra thread. I will do some experiments here and open a PR to show the idea later today.

Link head = link;
while (head != null) {
reclaimSpace(LINK_CAPACITY);
head = head.next;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@nitsanw should be free from GC nepotism here right?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@johnou actually I think you have a good point here. We should ensure we null out next. Let me fix this

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@johnou PTAL again

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@normanmaurer

Copy link
Copy Markdown
Member Author

So my other idea was basically to have a ReferenceQueue and store some references in it that can handle the onRemoval when needed on a "sampling" kind of basis. While this works ( I have a working PR here) I am not sure this really is any better then just this PR alone.

@johnou

johnou commented Jun 27, 2018

Copy link
Copy Markdown
Contributor

@normanmaurer I would stick with finalize until Java 9 to avoid adding unnecessary complexity unless there is a clear performance gain.

@bryce-anderson bryce-anderson left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, but note that I'm light on context.

@carl-mastrangelo carl-mastrangelo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

try {
super.finalize();
} finally {
Link head = link;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

optional: destroy link after this

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done

Motivation:

ObjectCleaner does start a Thread to handle the cleaning of resources which leaks into the users application. We should not use it in netty itself to make things more predictable.

Modifications:

- Remove usage of ObjectCleaner and use finalize as a replacement when possible.
- Clarify javadocs for FastThreadLocal.onRemoval(...) to ensure its clear that remove() is not guaranteed to be called when the Thread completees and so this method is not enough to guarantee cleanup for this case.

Result:

Fixes #8017.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants