From bf9654474ce84db978fb427c0166aa1b5581a6aa Mon Sep 17 00:00:00 2001 From: Michael Stack Date: Wed, 22 Jun 2011 21:45:31 +0000 Subject: [PATCH] Attempted fix for broken TestHeapSize up on jenkins git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1138647 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop/hbase/regionserver/HRegion.java | 8 +- .../apache/hadoop/hbase/util/ClassSize.java | 74 +++++++++---------- .../apache/hadoop/hbase/io/TestHeapSize.java | 4 +- 3 files changed, 43 insertions(+), 43 deletions(-) diff --git a/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java b/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java index 83acd934692..f6586f317d5 100644 --- a/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java +++ b/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java @@ -3592,9 +3592,11 @@ public class HRegion implements HeapSize { // , Writable{ } public static final long FIXED_OVERHEAD = ClassSize.align( - (4 * Bytes.SIZEOF_LONG) + ClassSize.ARRAY + - ClassSize.align(27 * ClassSize.REFERENCE) + ClassSize.OBJECT + - ClassSize.align(Bytes.SIZEOF_INT)); + ClassSize.OBJECT + + ClassSize.ARRAY + + ClassSize.align(27 * ClassSize.REFERENCE) + + (4 * Bytes.SIZEOF_LONG) + + Bytes.SIZEOF_BOOLEAN); public static final long DEEP_OVERHEAD = FIXED_OVERHEAD + ClassSize.OBJECT + // closeLock diff --git a/src/main/java/org/apache/hadoop/hbase/util/ClassSize.java b/src/main/java/org/apache/hadoop/hbase/util/ClassSize.java index 9ada18c8280..d836fa82a74 100755 --- a/src/main/java/org/apache/hadoop/hbase/util/ClassSize.java +++ b/src/main/java/org/apache/hadoop/hbase/util/ClassSize.java @@ -185,45 +185,46 @@ public class ClassSize { int arrays = 0; //The number of references that a new object takes int references = nrOfRefsPerObj; + int index = 0; for ( ; null != cl; cl = cl.getSuperclass()) { Field[] field = cl.getDeclaredFields(); if (null != field) { for (Field aField : field) { - if (!Modifier.isStatic(aField.getModifiers())) { - Class fieldClass = aField.getType(); - if (fieldClass.isArray()) { - arrays++; - references++; - } else if (!fieldClass.isPrimitive()) { - references++; - } else {// Is simple primitive - String name = fieldClass.getName(); + if (Modifier.isStatic(aField.getModifiers())) continue; + Class fieldClass = aField.getType(); + if (fieldClass.isArray()) { + arrays++; + references++; + } else if (!fieldClass.isPrimitive()) { + references++; + } else {// Is simple primitive + String name = fieldClass.getName(); - if (name.equals("int") || name.equals("I")) - primitives += Bytes.SIZEOF_INT; - else if (name.equals("long") || name.equals("J")) - primitives += Bytes.SIZEOF_LONG; - else if (name.equals("boolean") || name.equals("Z")) - primitives += Bytes.SIZEOF_BOOLEAN; - else if (name.equals("short") || name.equals("S")) - primitives += Bytes.SIZEOF_SHORT; - else if (name.equals("byte") || name.equals("B")) - primitives += Bytes.SIZEOF_BYTE; - else if (name.equals("char") || name.equals("C")) - primitives += Bytes.SIZEOF_CHAR; - else if (name.equals("float") || name.equals("F")) - primitives += Bytes.SIZEOF_FLOAT; - else if (name.equals("double") || name.equals("D")) - primitives += Bytes.SIZEOF_DOUBLE; - } - if (debug) { - if (LOG.isDebugEnabled()) { - // Write out region name as string and its encoded name. - LOG.debug(aField.getName() + "\n\t" + aField.getType()); - } + if (name.equals("int") || name.equals("I")) + primitives += Bytes.SIZEOF_INT; + else if (name.equals("long") || name.equals("J")) + primitives += Bytes.SIZEOF_LONG; + else if (name.equals("boolean") || name.equals("Z")) + primitives += Bytes.SIZEOF_BOOLEAN; + else if (name.equals("short") || name.equals("S")) + primitives += Bytes.SIZEOF_SHORT; + else if (name.equals("byte") || name.equals("B")) + primitives += Bytes.SIZEOF_BYTE; + else if (name.equals("char") || name.equals("C")) + primitives += Bytes.SIZEOF_CHAR; + else if (name.equals("float") || name.equals("F")) + primitives += Bytes.SIZEOF_FLOAT; + else if (name.equals("double") || name.equals("D")) + primitives += Bytes.SIZEOF_DOUBLE; + } + if (debug) { + if (LOG.isDebugEnabled()) { + // Write out region name as string and its encoded name. + LOG.debug("" + index + " " + aField.getName() + " " + aField.getType()); } } + index++; } } } @@ -240,17 +241,17 @@ public class ClassSize { * @return the size estimate, in bytes */ private static long estimateBaseFromCoefficients(int [] coeff, boolean debug) { - long size = coeff[0] + align(coeff[1]*ARRAY) + coeff[2]*REFERENCE; + long prealign_size = coeff[0] + align(coeff[1] * ARRAY) + coeff[2] * REFERENCE; // Round up to a multiple of 8 - size = align(size); + long size = align(prealign_size); if(debug) { if (LOG.isDebugEnabled()) { // Write out region name as string and its encoded name. - LOG.debug("Primitives " + coeff[0] + ", arrays " + coeff[1] + + LOG.debug("Primitives=" + coeff[0] + ", arrays=" + coeff[1] + ", references(includes " + nrOfRefsPerObj + - " for object overhead) " + coeff[2] + ", refSize " + REFERENCE + - ", size " + size); + " for object overhead)=" + coeff[2] + ", refSize " + REFERENCE + + ", size=" + size + ", prealign_size=" + prealign_size); } } return size; @@ -291,6 +292,5 @@ public class ClassSize { //stored and sent together return ((num + 7) >> 3) << 3; } - } diff --git a/src/test/java/org/apache/hadoop/hbase/io/TestHeapSize.java b/src/test/java/org/apache/hadoop/hbase/io/TestHeapSize.java index 820ea16cc3a..96e21930aeb 100644 --- a/src/test/java/org/apache/hadoop/hbase/io/TestHeapSize.java +++ b/src/test/java/org/apache/hadoop/hbase/io/TestHeapSize.java @@ -304,7 +304,7 @@ public class TestHeapSize extends TestCase { cl = HRegion.class; actual = HRegion.FIXED_OVERHEAD; expected = ClassSize.estimateBase(cl, false); - if(expected != actual) { + if (expected != actual) { ClassSize.estimateBase(cl, true); assertEquals(expected, actual); } @@ -315,7 +315,5 @@ public class TestHeapSize extends TestCase { // accounted for. But we have satisfied our two core requirements. // Sizing is quite accurate now, and our tests will throw errors if // any of these classes are modified without updating overhead sizes. - } - }