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
This commit is contained in:
Michael Stack 2011-06-22 21:45:31 +00:00
parent 7b6f6d6e19
commit bf9654474c
3 changed files with 43 additions and 43 deletions

View File

@ -3592,9 +3592,11 @@ public class HRegion implements HeapSize { // , Writable{
} }
public static final long FIXED_OVERHEAD = ClassSize.align( public static final long FIXED_OVERHEAD = ClassSize.align(
(4 * Bytes.SIZEOF_LONG) + ClassSize.ARRAY + ClassSize.OBJECT +
ClassSize.align(27 * ClassSize.REFERENCE) + ClassSize.OBJECT + ClassSize.ARRAY +
ClassSize.align(Bytes.SIZEOF_INT)); ClassSize.align(27 * ClassSize.REFERENCE) +
(4 * Bytes.SIZEOF_LONG) +
Bytes.SIZEOF_BOOLEAN);
public static final long DEEP_OVERHEAD = FIXED_OVERHEAD + public static final long DEEP_OVERHEAD = FIXED_OVERHEAD +
ClassSize.OBJECT + // closeLock ClassSize.OBJECT + // closeLock

View File

@ -185,45 +185,46 @@ public class ClassSize {
int arrays = 0; int arrays = 0;
//The number of references that a new object takes //The number of references that a new object takes
int references = nrOfRefsPerObj; int references = nrOfRefsPerObj;
int index = 0;
for ( ; null != cl; cl = cl.getSuperclass()) { for ( ; null != cl; cl = cl.getSuperclass()) {
Field[] field = cl.getDeclaredFields(); Field[] field = cl.getDeclaredFields();
if (null != field) { if (null != field) {
for (Field aField : field) { for (Field aField : field) {
if (!Modifier.isStatic(aField.getModifiers())) { if (Modifier.isStatic(aField.getModifiers())) continue;
Class fieldClass = aField.getType(); Class fieldClass = aField.getType();
if (fieldClass.isArray()) { if (fieldClass.isArray()) {
arrays++; arrays++;
references++; references++;
} else if (!fieldClass.isPrimitive()) { } else if (!fieldClass.isPrimitive()) {
references++; references++;
} else {// Is simple primitive } else {// Is simple primitive
String name = fieldClass.getName(); String name = fieldClass.getName();
if (name.equals("int") || name.equals("I")) if (name.equals("int") || name.equals("I"))
primitives += Bytes.SIZEOF_INT; primitives += Bytes.SIZEOF_INT;
else if (name.equals("long") || name.equals("J")) else if (name.equals("long") || name.equals("J"))
primitives += Bytes.SIZEOF_LONG; primitives += Bytes.SIZEOF_LONG;
else if (name.equals("boolean") || name.equals("Z")) else if (name.equals("boolean") || name.equals("Z"))
primitives += Bytes.SIZEOF_BOOLEAN; primitives += Bytes.SIZEOF_BOOLEAN;
else if (name.equals("short") || name.equals("S")) else if (name.equals("short") || name.equals("S"))
primitives += Bytes.SIZEOF_SHORT; primitives += Bytes.SIZEOF_SHORT;
else if (name.equals("byte") || name.equals("B")) else if (name.equals("byte") || name.equals("B"))
primitives += Bytes.SIZEOF_BYTE; primitives += Bytes.SIZEOF_BYTE;
else if (name.equals("char") || name.equals("C")) else if (name.equals("char") || name.equals("C"))
primitives += Bytes.SIZEOF_CHAR; primitives += Bytes.SIZEOF_CHAR;
else if (name.equals("float") || name.equals("F")) else if (name.equals("float") || name.equals("F"))
primitives += Bytes.SIZEOF_FLOAT; primitives += Bytes.SIZEOF_FLOAT;
else if (name.equals("double") || name.equals("D")) else if (name.equals("double") || name.equals("D"))
primitives += Bytes.SIZEOF_DOUBLE; primitives += Bytes.SIZEOF_DOUBLE;
} }
if (debug) { if (debug) {
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
// Write out region name as string and its encoded name. // Write out region name as string and its encoded name.
LOG.debug(aField.getName() + "\n\t" + aField.getType()); LOG.debug("" + index + " " + aField.getName() + " " + aField.getType());
}
} }
} }
index++;
} }
} }
} }
@ -240,17 +241,17 @@ public class ClassSize {
* @return the size estimate, in bytes * @return the size estimate, in bytes
*/ */
private static long estimateBaseFromCoefficients(int [] coeff, boolean debug) { 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 // Round up to a multiple of 8
size = align(size); long size = align(prealign_size);
if(debug) { if(debug) {
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
// Write out region name as string and its encoded name. // 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 + ", references(includes " + nrOfRefsPerObj +
" for object overhead) " + coeff[2] + ", refSize " + REFERENCE + " for object overhead)=" + coeff[2] + ", refSize " + REFERENCE +
", size " + size); ", size=" + size + ", prealign_size=" + prealign_size);
} }
} }
return size; return size;
@ -291,6 +292,5 @@ public class ClassSize {
//stored and sent together //stored and sent together
return ((num + 7) >> 3) << 3; return ((num + 7) >> 3) << 3;
} }
} }

View File

@ -304,7 +304,7 @@ public class TestHeapSize extends TestCase {
cl = HRegion.class; cl = HRegion.class;
actual = HRegion.FIXED_OVERHEAD; actual = HRegion.FIXED_OVERHEAD;
expected = ClassSize.estimateBase(cl, false); expected = ClassSize.estimateBase(cl, false);
if(expected != actual) { if (expected != actual) {
ClassSize.estimateBase(cl, true); ClassSize.estimateBase(cl, true);
assertEquals(expected, actual); assertEquals(expected, actual);
} }
@ -315,7 +315,5 @@ public class TestHeapSize extends TestCase {
// accounted for. But we have satisfied our two core requirements. // accounted for. But we have satisfied our two core requirements.
// Sizing is quite accurate now, and our tests will throw errors if // Sizing is quite accurate now, and our tests will throw errors if
// any of these classes are modified without updating overhead sizes. // any of these classes are modified without updating overhead sizes.
} }
} }