lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From whosc...@apache.org
Subject svn commit: r475843 - /lucene/java/trunk/contrib/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java
Date Thu, 16 Nov 2006 18:13:57 GMT
Author: whoschek
Date: Thu Nov 16 10:13:56 2006
New Revision: 475843

URL: http://svn.apache.org/viewvc?view=rev&rev=475843
Log:
better memory estimate

Modified:
    lucene/java/trunk/contrib/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java

Modified: lucene/java/trunk/contrib/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java?view=diff&rev=475843&r1=475842&r2=475843
==============================================================================
--- lucene/java/trunk/contrib/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java
(original)
+++ lucene/java/trunk/contrib/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java
Thu Nov 16 10:13:56 2006
@@ -174,6 +174,9 @@
   /** Could be made configurable; See {@link Document#setBoost(float)} */
   private static final float docBoost = 1.0f;
   
+  /** number of memory bytes a VM pointer occupies */ 
+  private static final int PTR = is64BitVM() ? 8 : 4;
+
   private static final long serialVersionUID = 2782195016849084649L;
 
   private static final boolean DEBUG = false;
@@ -442,8 +445,7 @@
    */
   public int getMemorySize() {
     // for example usage in a smart cache see nux.xom.pool.Pool
-    int HEADER = 12; // object header of any java object
-    int PTR = 4; // pointer on 32 bit VMs
+    int HEADER = 2*PTR; // object header of any java object
     int ARR = HEADER + 4;
     int STR = HEADER + 3*4 + PTR + ARR; // string
     int INTARRLIST = HEADER + 4 + PTR + ARR;
@@ -475,6 +477,14 @@
     return size;
   } 
 
+  private static boolean is64BitVM() {
+    int bits = Integer.getInteger("sun.arch.data.model", 0).intValue();
+    if (bits != 0) return bits == 64;
+        
+    // fallback if sun.arch.data.model isn't available
+    return System.getProperty("java.vm.name").toLowerCase().indexOf("64") >= 0;
+  }
+    
   private int numPositions(ArrayIntList positions) {
     return positions.size() / stride;
   }



Mime
View raw message