Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id D8A16200CCC for ; Fri, 21 Jul 2017 20:13:32 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id D6DD716DA05; Fri, 21 Jul 2017 18:13:32 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 0200C16D9FA for ; Fri, 21 Jul 2017 20:13:31 +0200 (CEST) Received: (qmail 38766 invoked by uid 500); 21 Jul 2017 18:13:31 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 38755 invoked by uid 99); 21 Jul 2017 18:13:31 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 21 Jul 2017 18:13:31 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 0B23EE964C; Fri, 21 Jul 2017 18:13:31 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: chia7712@apache.org To: commits@hbase.apache.org Message-Id: <9b2e2eb6ac224c91874035a39207c0ff@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: hbase git commit: HBASE-18389 Remove byte[] from formal parameter of sizeOf() of ClassSize, ClassSize.MemoryLayout and ClassSize.UnsafeLayout Date: Fri, 21 Jul 2017 18:13:31 +0000 (UTC) archived-at: Fri, 21 Jul 2017 18:13:33 -0000 Repository: hbase Updated Branches: refs/heads/master 2a0d18928 -> 31c3edaa2 HBASE-18389 Remove byte[] from formal parameter of sizeOf() of ClassSize, ClassSize.MemoryLayout and ClassSize.UnsafeLayout Signed-off-by: Chia-Ping Tsai Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/31c3edaa Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/31c3edaa Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/31c3edaa Branch: refs/heads/master Commit: 31c3edaa29776b63cc69ecd37306ad10836992eb Parents: 2a0d189 Author: Xiang Li Authored: Mon Jul 17 17:11:16 2017 +0800 Committer: Chia-Ping Tsai Committed: Sat Jul 22 02:12:59 2017 +0800 ---------------------------------------------------------------------- .../java/org/apache/hadoop/hbase/CellUtil.java | 8 ++--- .../java/org/apache/hadoop/hbase/KeyValue.java | 4 +-- .../org/apache/hadoop/hbase/util/ClassSize.java | 34 +++++++++++++++++--- 3 files changed, 36 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/31c3edaa/hbase-common/src/main/java/org/apache/hadoop/hbase/CellUtil.java ---------------------------------------------------------------------- diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/CellUtil.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/CellUtil.java index 56de21b..1146de4 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/CellUtil.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/CellUtil.java @@ -564,7 +564,7 @@ public final class CellUtil { public long heapSize() { long sum = HEAP_SIZE_OVERHEAD + CellUtil.estimatedHeapSizeOf(cell); if (this.tags != null) { - sum += ClassSize.sizeOf(this.tags, this.tags.length); + sum += ClassSize.sizeOf(this.tags); } return sum; } @@ -763,7 +763,7 @@ public final class CellUtil { long sum = HEAP_SIZE_OVERHEAD + CellUtil.estimatedHeapSizeOf(cell); // this.tags is on heap byte[] if (this.tags != null) { - sum += ClassSize.sizeOf(this.tags, this.tags.length); + sum += ClassSize.sizeOf(this.tags); } return sum; } @@ -889,7 +889,7 @@ public final class CellUtil { public long heapSize() { long sum = ClassSize.REFERENCE + super.heapSize(); if (this.value != null) { - sum += ClassSize.sizeOf(this.value, this.value.length); + sum += ClassSize.sizeOf(this.value); } return sum; } @@ -989,7 +989,7 @@ public final class CellUtil { public long heapSize() { long sum = ClassSize.REFERENCE + super.heapSize(); if (this.value != null) { - sum += ClassSize.sizeOf(this.value, this.value.length); + sum += ClassSize.sizeOf(this.value); } return sum; } http://git-wip-us.apache.org/repos/asf/hbase/blob/31c3edaa/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java ---------------------------------------------------------------------- diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java index 9b9dc43..98cf9cb 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java @@ -2608,8 +2608,8 @@ public class KeyValue implements ExtendedCell { */ return ClassSize.align(sum) + (offset == 0 - ? ClassSize.sizeOf(bytes, length) // count both length and object overhead - : length); // only count the number of bytes + ? ClassSize.sizeOfByteArray(length) // count both length and object overhead + : length); // only count the number of bytes } /** http://git-wip-us.apache.org/repos/asf/hbase/blob/31c3edaa/hbase-common/src/main/java/org/apache/hadoop/hbase/util/ClassSize.java ---------------------------------------------------------------------- diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/ClassSize.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/ClassSize.java index 1b19c92..3ab59e7 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/ClassSize.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/ClassSize.java @@ -168,7 +168,7 @@ public class ClassSize { return ((num + 7) >> 3) << 3; } - long sizeOf(byte[] b, int len) { + long sizeOfByteArray(int len) { return align(arrayHeaderSize() + len); } } @@ -213,7 +213,7 @@ public class ClassSize { @Override @SuppressWarnings("static-access") - long sizeOf(byte[] b, int len) { + long sizeOfByteArray(int len) { return align(arrayHeaderSize() + len * UnsafeAccess.theUnsafe.ARRAY_BYTE_INDEX_SCALE); } } @@ -463,8 +463,34 @@ public class ClassSize { return model != null && model.equals("32"); } - public static long sizeOf(byte[] b, int len) { - return memoryLayout.sizeOf(b, len); + /** + * Calculate the memory consumption (in byte) of a byte array, + * including the array header and the whole backing byte array. + * + * If the whole byte array is occupied (not shared with other objects), please use this function. + * If not, please use {@link #sizeOfByteArray(int)} instead. + * + * @param b the byte array + * @return the memory consumption (in byte) of the whole byte array + */ + public static long sizeOf(byte[] b) { + return memoryLayout.sizeOfByteArray(b.length); + } + + /** + * Calculate the memory consumption (in byte) of a part of a byte array, + * including the array header and the part of the backing byte array. + * + * This function is used when the byte array backs multiple objects. + * For example, in {@link org.apache.hadoop.hbase.KeyValue}, + * multiple KeyValue objects share a same backing byte array ({@link org.apache.hadoop.hbase.KeyValue#bytes}). + * Also see {@link org.apache.hadoop.hbase.KeyValue#heapSize()}. + * + * @param len the length (in byte) used partially in the backing byte array + * @return the memory consumption (in byte) of the part of the byte array + */ + public static long sizeOfByteArray(int len) { + return memoryLayout.sizeOfByteArray(len); } }