Github user srowen commented on a diff in the pull request:
https://github.com/apache/spark/pull/16403#discussion_r94215787
--- Diff:
common/unsafe/src/test/java/org/apache/spark/unsafe/PlatformUtilSuite.java ---
@@ -74,4 +76,74 @@ public void memoryDebugFillEnabledInTest() {
Platform.getByte(offheap.getBaseObject(), offheap.getBaseOffset()),
MemoryAllocator.MEMORY_DEBUG_FILL_CLEAN_VALUE);
}
+
+ /**
+ * This test ensures that double access is handled correctly for the
host platform.
+ * On platforms that require double access to be aligned to 8-byte
boundaries, this
+ * test should pass and not cause the JVM to segfault.
+ */
+ @Test
+ public void unalignedDoublePutAndGet() {
+ MemoryBlock testBuffer = MemoryBlock.fromLongArray(new long[20]);
+
+ // write a double to an unaligned location
+ long unalignedOffset = testBuffer.getBaseOffset() + 3;
+ // double check unalignment just to be sure:
+ if (unalignedOffset % 8 == 0) {
+ unalignedOffset++;
+ }
+
+ Platform.putDouble(testBuffer.getBaseObject(), unalignedOffset,
3.14159);
+
+ double foundDouble = Platform.getDouble(testBuffer.getBaseObject(),
unalignedOffset);
+
+ Assert.assertEquals(3.14159, foundDouble, 0.000001);
+ }
+
+ /**
+ * The goal of this test is to ensure that doubles written to a memory
location
+ * using the long-buffered functor can be read back using the direct
functor,
+ * and vice-versa. This is to ensure binary output such as parquet files
written
+ * from one platform will be readable on another.
+ */
+ @Test
+ public void mixedDoubleFunctors() {
+ sun.misc.Unsafe unsafe;
+ try {
+ Field unsafeField = Unsafe.class.getDeclaredField("theUnsafe");
+ unsafeField.setAccessible(true);
+ unsafe = (sun.misc.Unsafe) unsafeField.get(null);
+ } catch (Throwable cause) {
+ unsafe = null;
--- End diff --
Could just return here to skip the test?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]