better estimation of memory consumption

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@480339 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Wolfgang Hoschek 2006-11-29 02:29:19 +00:00
parent 989b1cb981
commit 06a9b2e22a
1 changed files with 11 additions and 3 deletions

View File

@ -1112,12 +1112,14 @@ public class MemoryIndex {
public static final int FLOAT = 4; public static final int FLOAT = 4;
public static final int DOUBLE = 8; public static final int DOUBLE = 8;
private static final int LOG_PTR = (int) Math.round(log2(PTR));
/** /**
* Object header of any heap allocated Java object. * Object header of any heap allocated Java object.
* ptr to class, info for monitor, gc, hash, etc. * ptr to class, info for monitor, gc, hash, etc.
*/ */
private static final int OBJECT_HEADER = 2*4; // typically even on 64 bit VMs // private static final int OBJECT_HEADER = 2*4; // even on 64 bit VMs?
// private static final int OBJECT_HEADER = 2*PTR; private static final int OBJECT_HEADER = 2*PTR;
/** /**
* Modern VMs tend to trade space for time, allocating memory on word * Modern VMs tend to trade space for time, allocating memory on word
@ -1139,7 +1141,8 @@ public class MemoryIndex {
// 9..16 --> 2*PTR // 9..16 --> 2*PTR
private static int sizeOf(int n) { private static int sizeOf(int n) {
return IS_WORD_ALIGNED_VM ? return IS_WORD_ALIGNED_VM ?
((n-1)/PTR + 1) * PTR : // ((n-1)/PTR + 1) * PTR : // slow version
(((n-1) >> LOG_PTR) + 1) << LOG_PTR : // fast version
n; n;
} }
@ -1189,6 +1192,11 @@ public class MemoryIndex {
} }
} }
/** logarithm to the base 2. Example: log2(4) == 2, log2(8) == 3 */
private static double log2(double value) {
return Math.log(value) / Math.log(2);
}
} }
} }