You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hbase.apache.org by GitBox <gi...@apache.org> on 2021/10/04 14:36:03 UTC

[GitHub] [hbase] Apache9 commented on a change in pull request #3691: HBASE-26259 Fallback support to pure Java compression

Apache9 commented on a change in pull request #3691:
URL: https://github.com/apache/hbase/pull/3691#discussion_r721428211



##########
File path: hbase-common/src/main/java/org/apache/hadoop/hbase/util/UnsafeAccess.java
##########
@@ -471,4 +485,57 @@ public static byte toByte(ByteBuffer buf, int offset) {
   public static byte toByte(Object ref, long offset) {
     return theUnsafe.getByte(ref, offset);
   }
+
+  /**
+   * Zero fill a byte buffer as efficiently as possible.
+   * @param buf the byte buffer
+   */
+  public static void clear(final ByteBuffer buf) {
+    if (buf.isDirect()) {
+      clear(((DirectBuffer)buf).address(), buf.capacity());

Review comment:
       OK, I checked the source code of openjdk, it is not a memset, it will try to use long if the address and length are both 8 bytes aligned. It is a bit strange that they do not use the typical loop unrolling way to implement this function, as what you do here.
   
   https://github.com/adoptium/jdk11u/blob/c9c728849c137e21535cc402664dd54ee421b0d3/src/hotspot/share/utilities/copy.cpp#L238
   
   And the behavior is also well documented in the javadoc of the Unsafe.setMemory method.
   ```
        * <p>The stores are in coherent (atomic) units of a size determined
        * by the address and length parameters.  If the effective address and
        * length are all even modulo 8, the stores take place in 'long' units.
        * If the effective address and length are (resp.) even modulo 4 or 2,
        * the stores take place in units of 'int' or 'short'.
   ```
   
   So let's keep your version here. And could also add some comments to say why we do not use Unsafe.setMemory.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hbase.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org