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

NativeDigest context free via Cleaner API #191

Merged
merged 1 commit into from
Aug 1, 2019

Conversation

alon-sh
Copy link
Contributor

@alon-sh alon-sh commented Jun 19, 2019

due to issues such as eclipse-openj9/openj9#5611 removed the native context de-allocation via a finalizer. Introduced the use of PhantomReferences to control when the native digest context can be de-allocated.

The cleanup stage happens when the reference array is fully used, at which point there is an attempted clean-up by examining the ReferenceQueue which will de-allocate the native contexts and also free up space in the reference array.

Signed-off-by: Alon Shalev Housfater alonsh@ca.ibm.com

@pshipton pshipton requested a review from keithc-ca June 19, 2019 18:46
@alon-sh
Copy link
Contributor Author

alon-sh commented Jun 19, 2019

@pshipton @DanHeidinga @keithc-ca still testing the changes locally. If possible, would like to get the review cycle started. See eclipse-openj9/openj9#5611 and eclipse-openj9/openj9#4530 for the actual error reports.

Also note that I can't be certain this PR will fix those issues as I'm unable to reproduce the error locally. However, looking at the code at Java_jdk_crypto_jniprovider_NativeCrypto_DigestUpdate which has extensive error checking likely the crash occurs here:
(*OSSL_DigestUpdate)(context->ctx, (messageNative + messageOffset), messageLen)

so I'm assuming context is de-allocated too early which is why the crash happens in the finalizer of sun/security/ssl/BaseSSLSocketImpl

@pshipton
Copy link
Member

This won't clean if new Digest's aren't being created. Ideally https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/ref/Cleaner.html should be used.

@keithc-ca
Copy link
Member

You may want to reuse the common cleaner accessible via jdk.internal.ref.CleanerFactory.cleaner().

@alon-sh
Copy link
Contributor Author

alon-sh commented Jun 19, 2019

@pshipton @keithc-ca is this also available for jdk8?

@keithc-ca
Copy link
Member

Yes, in Java 8 there is sun.misc.Cleaner (with differing API).

@DanHeidinga
Copy link
Contributor

@ashbm5 Are you adapting this PR in light of Keith & Peter's comments on using sun.misc.Cleaner?

@alon-sh
Copy link
Contributor Author

alon-sh commented Jul 5, 2019

@DanHeidinga I'm a bit concerned about the performance impact of using sun.misc.Cleaner since it requires a background thread so I'm also evaluating the perf. impact of this approach. Also try different ways of resolving this issue - perhaps by buffering input data before sending to OpenSSL

@DanHeidinga
Copy link
Contributor

@alon-sh alon-sh changed the title NativeDigest context free via PhantomReferences mechanism NativeDigest context free via Cleaner API Jul 23, 2019
@alon-sh
Copy link
Contributor Author

alon-sh commented Jul 23, 2019

@pshipton @keithc-ca @DanHeidinga updated the PR with using the Cleaner API code. I did the relevant performance testing and found out that there is some impact when constant digest objects are being created and released when compared to finalizer but only slightly so while hopefully fixing the reported issues. with optimized code that doesn't constantly create new digest objects, there is no performance impact.

@alon-sh alon-sh force-pushed the openj9 branch 2 times, most recently from e5c99dd to 9fc5b66 Compare July 24, 2019 18:51
@alon-sh
Copy link
Contributor Author

alon-sh commented Jul 29, 2019

@keithc-ca updated, please review

Copy link
Member

@keithc-ca keithc-ca left a comment

Choose a reason for hiding this comment

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

Please address the merge conflict. Please also rebase (on the current head of the openj9 branch) and squash.

@alon-sh alon-sh force-pushed the openj9 branch 3 times, most recently from 176dd61 to e1b0150 Compare July 30, 2019 15:17
@alon-sh
Copy link
Contributor Author

alon-sh commented Jul 30, 2019

@keithc-ca updated, please review

Signed-off-by: Alon Shalev Housfater <alonsh@ca.ibm.com>
@keithc-ca
Copy link
Member

Jenkins test all,sanity,extended zlinux jdk11

@keithc-ca
Copy link
Member

The build and both test jobs were successful, but something strange happened to the 'parallel' part of the test job: merging under the assumption that the strangeness is irrelevant.

keithc-ca pushed a commit to keithc-ca/openj9-openjdk11 that referenced this pull request Mar 24, 2021
Correct encoding of META-INF/services config files - javac tooling fix
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.

4 participants