smuching202 opened a new issue, #15018:
URL: https://github.com/apache/lucene/issues/15018

   I noticed that ByteRefIntMap's INIT_RAM_BYTES 
[assignment](https://github.com/apache/lucene/blob/branch_10_2/lucene/core/src/java/org/apache/lucene/index/BufferedUpdates.java#L295)
 uses `RamUsageEstimator.shallowSizeOf` with a class literal, which seems 
incorrect:
   
   ```
   private static final long INIT_RAM_BYTES =
       RamUsageEstimator.shallowSizeOf(BytesRefIntMap.class)
           + RamUsageEstimator.shallowSizeOf(BytesRefHash.class)
           + RamUsageEstimator.sizeOf(new int[BytesRefHash.DEFAULT_CAPACITY]);
   ```
   
   If we follow the flow for 
`RamUsageEstimator.shallowSizeOf(BytesRefIntMap.class)`, and look at the 
[implementation](https://github.com/apache/lucene/blob/branch_10_2/lucene/core/src/java/org/apache/lucene/util/RamUsageEstimator.java#L517),
 it expects an object instance as its parameter:
   
   ```
   public static long shallowSizeOf(Object obj) {
     if (obj == null) return 0;
     final Class<?> clz = obj.getClass();
     if (clz.isArray()) {
       return shallowSizeOfArray(obj);
     } else {
       return shallowSizeOfInstance(clz);
     }
   }
   ```
   
   Passing a class literal (e.g., BytesRefIntMap.class) means obj.getClass() 
will return java.lang.Class, so this code is actually measuring the size of a 
Class object, not the shallow size of a BytesRefIntMap instance.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to