-
Notifications
You must be signed in to change notification settings - Fork 56
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
Improve speed in MessageDigest and Hmac #54
Conversation
@ private exceptional_behavior | ||
@ requires buff.count <= buffSize - 1; | ||
@ assignable \nothing; | ||
@ signals_only ArrayIndexOutOfBoundsException; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little confused by this. The behavior here is not documented in the javadoc (which appears to have been copied from a different function) and doesn't really make sense to me either; in particular, this appears to be an equivalent condition (modulo overflow) to the one on 385.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are for formal proofs of correctness. It has been slightly modified to take into account the hard coded length (of 1). We do not currently have this system running, but I'm avoiding bit-rot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we know if these proofs are correct? The requires conditions seem to overlap to me, unless I'm missing something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They were and we need to figure out how to reenable running of them. They have have drifted even separate from this PR. I'm trying to keep them as close to correct as possible.
@ ensures canTakeData(bufferState); | ||
@ also | ||
@ public exceptional_behavior | ||
@ requires buff.count <= buffSize - 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we throwing exceptions when the buffer count is within the buffer size?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not Java exceptions but for the formal verification. The listed line requires that the buffer count be valid.
Heap error. Restarted |
Close and re-open to rerun status checks. |
As |
We ran our benchmark suite for MessageDigest and HMac on an i3.metal instance with 16 simultaneous threads.
|
Issue #: #52
Description of changes:
Improves handling of single-byte updates to both MessageDigest and Hmac by not using array copies and by removing unneeded synchronization. Both of these objects are not thread-safe to begin with and we only need to ensure we are synchronized when crossing the JNI boundary. We achieve this synchronization by taking a lock on the
ctx
(which is unique to each instance of the MessageDigest or Hmac SPI). We do this rather than use a standardsynchronized
method as passing a non-static method as a functional interface creates new lambda instances in memory and can reduce efficiency (due to object allocation/deallocation). This does not guarantee that there are no other threads updating the data arrays at the same time. Doing so may (correctly) create a corrupted result (as the behavior in this case is undefined). We are not worried about reading past the ends of these arrays (and creating memory errors) as the C++ code performs correct bounds checking on these arrays prior to use (withinjava_buffer
).Detailed benchmarks are being run, but initial results look promising:
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.