Repository navigation
Faster VarHandle, Unaligned and AES paths for NoSync #21
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
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
bd3db8d
Run Unsafe's unaligned accessors as intrinsics and keep one DataView …
Project516 39e2269
Cache a VarHandle call site's handle and call its implementation dire…
Project516 7f78e4f
Cache exact VarHandles at a call site once their type check has passed.
Project516 9669d1c
Run Unsafe's byte-order unaligned accessors as intrinsics and size ea…
Project516 aad435e
Run AES block encryption as an intrinsic, as HotSpot does.
Project516 12ec01e
Run NoSync with the passing OpenJDK tests again.
Project516 4beba08
Explain the VarHandle, AES and scratch view assumptions and test a cl…
Project516 809e42d
Test unaligned reads across the elements of int, char and short arrays.
Project516 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import java.lang.invoke.MethodHandles; | ||
| import java.lang.invoke.VarHandle; | ||
| import java.nio.ByteBuffer; | ||
| import java.nio.ByteOrder; | ||
| import java.util.HexFormat; | ||
|
|
||
| // Multi-byte reads and writes at every alignment, in both byte orders, through | ||
| // byte array views, heap and direct buffers, and views of other element types, | ||
| // and native-order reads across the elements of other primitive arrays. | ||
| public class Unaligned { | ||
| public static void main(String[] args) { | ||
| HexFormat hex = HexFormat.of(); | ||
| for (ByteOrder order : new ByteOrder[] {ByteOrder.BIG_ENDIAN, ByteOrder.LITTLE_ENDIAN}) { | ||
| VarHandle ints = MethodHandles.byteArrayViewVarHandle(int[].class, order); | ||
| VarHandle longs = MethodHandles.byteArrayViewVarHandle(long[].class, order); | ||
| VarHandle shorts = MethodHandles.byteArrayViewVarHandle(short[].class, order); | ||
| VarHandle chars = MethodHandles.byteArrayViewVarHandle(char[].class, order); | ||
| for (int at = 0; at < 8; at++) { | ||
| byte[] b = new byte[24]; | ||
| ints.set(b, at, 0x81828384); | ||
| longs.set(b, at + 4, 0x0102030405060708L); | ||
| shorts.set(b, at + 12, (short) -2); | ||
| chars.set(b, at + 14, 'ꯍ'); | ||
| System.out.println(order + " " + at + " " + hex.formatHex(b) + " " + Integer.toHexString((int) ints.get(b, at)) | ||
| + " " + Long.toHexString((long) longs.get(b, at + 4)) + " " + (short) shorts.get(b, at + 12) | ||
| + " " + Integer.toHexString((char) chars.get(b, at + 14)) + " " + Long.toHexString((long) longs.get(b, at + 1))); | ||
| } | ||
| for (ByteBuffer buf : new ByteBuffer[] {ByteBuffer.allocate(32), ByteBuffer.allocateDirect(32)}) { | ||
| buf.order(order); | ||
| for (int at = 0; at < 5; at++) { | ||
| buf.putLong(at, -0x123456789abcdefL).putInt(at + 9, 0x7f00ff01).putShort(at + 14, (short) 0x8001).putChar(at + 17, 'Z') | ||
| .putDouble(at + 20, Math.PI).putFloat(at + 28 - at, 1.5f); | ||
| System.out.println((buf.isDirect() ? "direct " : "heap ") + order + " " + at + " " + Long.toHexString(buf.getLong(at)) | ||
| + " " + buf.getInt(at + 9) + " " + buf.getShort(at + 14) + " " + buf.getChar(at + 17) + " " + buf.getDouble(at + 20) | ||
| + " " + buf.getFloat(28) + " " + buf.getInt(at + 1)); | ||
| } | ||
| } | ||
| // a clone written through a view after the original was | ||
| byte[] orig = new byte[8]; | ||
| ints.set(orig, 1, 0x11223344); | ||
| byte[] copy = orig.clone(); | ||
| ints.set(copy, 1, 0x55667788); | ||
| System.out.println(order + " clone " + hex.formatHex(orig) + " " + hex.formatHex(copy)); | ||
| // an int buffer over a byte buffer, read through a long view | ||
| ByteBuffer bb = ByteBuffer.allocate(40).order(order); | ||
| bb.asIntBuffer().put(new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}); | ||
| System.out.println(order + " view " + Long.toHexString(bb.asLongBuffer().get(2)) + " " + bb.position(3).slice().order(order).getInt(0)); | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| } | ||
| // Arrays.mismatch reads longs across the elements of int, char and short | ||
| // arrays, from any starting element | ||
| int[] ia = new int[40], ib = new int[40]; | ||
| char[] ca = new char[70], cb = new char[70]; | ||
| short[] sa = new short[70], sb = new short[70]; | ||
| StringBuilder out = new StringBuilder("mismatch"); | ||
| for (int diff = 0; diff < 40; diff += 3) { | ||
| ib[diff] = ia[diff] + 1; | ||
| cb[diff + 25] = 'x'; | ||
| sb[diff + 25] = -1; | ||
| for (int from = 0; from < 5; from++) { | ||
| out.append(' ').append(java.util.Arrays.mismatch(ia, from, 40, ib, from, 40)) | ||
| .append(',').append(java.util.Arrays.mismatch(ca, from, 70, cb, from + 1, 70)) | ||
| .append(',').append(java.util.Arrays.mismatch(sa, from, 70, sb, from, 70)); | ||
| } | ||
| ib[diff] = ia[diff]; | ||
| cb[diff + 25] = 0; | ||
| sb[diff + 25] = 0; | ||
| } | ||
| System.out.println(out); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.