You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nemo.apache.org by gw...@apache.org on 2019/08/19 05:03:09 UTC

[incubator-nemo] branch master updated: [NEMO-413] Fix index checking for byte access of MemoryChunk using UNSAFE #234

This is an automated email from the ASF dual-hosted git repository.

gwlee pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nemo.git


The following commit(s) were added to refs/heads/master by this push:
     new cb75680  [NEMO-413] Fix index checking for byte access of MemoryChunk using UNSAFE #234
cb75680 is described below

commit cb756801f2293c4c28116565323c91b0e2f0267d
Author: Haeyoon Cho <ch...@gmail.com>
AuthorDate: Mon Aug 19 14:03:05 2019 +0900

    [NEMO-413] Fix index checking for byte access of MemoryChunk using UNSAFE #234
    
    JIRA: [NEMO-413: Fix index checking for byte access of MemoryChunk using UNSAFE](https://issues.apache.org/jira/projects/NEMO/issues/NEMO-413)
    
    **Major changes:**
    - Index checking for byte operation using UNSAFE fixed: type size for byte changed from 0 to 1.
    
    Closes #234
---
 .../main/java/org/apache/nemo/runtime/executor/data/MemoryChunk.java | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/runtime/executor/src/main/java/org/apache/nemo/runtime/executor/data/MemoryChunk.java b/runtime/executor/src/main/java/org/apache/nemo/runtime/executor/data/MemoryChunk.java
index bbaa99a..e5d9803 100644
--- a/runtime/executor/src/main/java/org/apache/nemo/runtime/executor/data/MemoryChunk.java
+++ b/runtime/executor/src/main/java/org/apache/nemo/runtime/executor/data/MemoryChunk.java
@@ -38,6 +38,7 @@ public class MemoryChunk {
   @SuppressWarnings("restriction")
   protected static final long BYTE_ARRAY_BASE_OFFSET = UNSAFE.arrayBaseOffset(byte[].class);
   private static final boolean LITTLE_ENDIAN = (ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN);
+  private static final int BYTE_SIZE = 1;
   private static final int SHORT_SIZE = 2;
   private static final int CHAR_SIZE = 2;
   private static final int INT_SIZE = 4;
@@ -117,7 +118,7 @@ public class MemoryChunk {
   @SuppressWarnings("restriction")
   public final byte get(final int index) {
     final long pos = address + index;
-    if (checkIndex(index, pos, 0)) {
+    if (checkIndex(index, pos, BYTE_SIZE)) {
       return UNSAFE.getByte(pos);
     } else if (address > addressLimit) {
       throw new IllegalStateException("MemoryChunk has been freed");
@@ -135,7 +136,7 @@ public class MemoryChunk {
   @SuppressWarnings("restriction")
   public final void put(final int index, final byte b) {
     final long pos = address + index;
-    if (checkIndex(index, pos, 0)) {
+    if (checkIndex(index, pos, BYTE_SIZE)) {
       UNSAFE.putByte(pos, b);
     } else if (address > addressLimit) {
       throw new IllegalStateException("MemoryChunk has been freed");