You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2014/06/13 23:29:11 UTC
svn commit: r1602526 - in /lucene/dev/branches/branch_4x: ./ lucene/
lucene/analysis/
lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/
lucene/core/ lucene/core/src/java/org/apache/lucene/index/
lucene/core/src/java/org/apache/lucene...
Author: rmuir
Date: Fri Jun 13 21:29:10 2014
New Revision: 1602526
URL: http://svn.apache.org/r1602526
Log:
LUCENE-5757: move RamUsageEstimator reflector to test-framework
Added:
lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/util/RamUsageTester.java
- copied unchanged from r1602515, lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/util/RamUsageTester.java
Removed:
lucene/dev/branches/branch_4x/lucene/tools/forbiddenApis/rue.txt
Modified:
lucene/dev/branches/branch_4x/ (props changed)
lucene/dev/branches/branch_4x/lucene/ (props changed)
lucene/dev/branches/branch_4x/lucene/CHANGES.txt (contents, props changed)
lucene/dev/branches/branch_4x/lucene/analysis/ (props changed)
lucene/dev/branches/branch_4x/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestAllDictionaries.java
lucene/dev/branches/branch_4x/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestAllDictionaries2.java
lucene/dev/branches/branch_4x/lucene/common-build.xml (contents, props changed)
lucene/dev/branches/branch_4x/lucene/core/ (props changed)
lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/index/DocTermOrds.java
lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/FieldCache.java
lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/FieldCacheImpl.java
lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/util/FieldCacheSanityChecker.java
lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/util/RamUsageEstimator.java
lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/StressRamUsageEstimator.java
lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/TestIdentityHashSet.java
lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/TestRamUsageEstimator.java
lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/TestRamUsageEstimatorOnWildAnimals.java
lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/packed/TestPackedInts.java
lucene/dev/branches/branch_4x/lucene/memory/ (props changed)
lucene/dev/branches/branch_4x/lucene/memory/build.xml
lucene/dev/branches/branch_4x/lucene/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java
lucene/dev/branches/branch_4x/lucene/memory/src/test/org/apache/lucene/index/memory/MemoryIndexTest.java
lucene/dev/branches/branch_4x/lucene/misc/ (props changed)
lucene/dev/branches/branch_4x/lucene/test-framework/ (props changed)
lucene/dev/branches/branch_4x/lucene/tools/ (props changed)
lucene/dev/branches/branch_4x/solr/ (props changed)
lucene/dev/branches/branch_4x/solr/core/ (props changed)
lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/request/UnInvertedField.java
Modified: lucene/dev/branches/branch_4x/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/CHANGES.txt?rev=1602526&r1=1602525&r2=1602526&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/CHANGES.txt (original)
+++ lucene/dev/branches/branch_4x/lucene/CHANGES.txt Fri Jun 13 21:29:10 2014
@@ -132,6 +132,9 @@ API Changes
* LUCENE-5695: DocIdSet implements Accountable. (Adrien Grand)
+* LUCENE-5757: Moved RamUsageEstimator's reflection-based processing to RamUsageTester
+ in the test-framework module. (Robert Muir)
+
Optimizations
* LUCENE-5603: hunspell stemmer more efficiently strips prefixes
Modified: lucene/dev/branches/branch_4x/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestAllDictionaries.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestAllDictionaries.java?rev=1602526&r1=1602525&r2=1602526&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestAllDictionaries.java (original)
+++ lucene/dev/branches/branch_4x/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestAllDictionaries.java Fri Jun 13 21:29:10 2014
@@ -24,9 +24,8 @@ import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import org.apache.lucene.analysis.hunspell.Dictionary;
-import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.LuceneTestCase;
-import org.apache.lucene.util.RamUsageEstimator;
+import org.apache.lucene.util.RamUsageTester;
import org.junit.Ignore;
/**
@@ -167,14 +166,14 @@ public class TestAllDictionaries extends
try (InputStream dictionary = zip.getInputStream(dicEntry);
InputStream affix = zip.getInputStream(affEntry)) {
Dictionary dic = new Dictionary(affix, dictionary);
- System.out.println(tests[i] + "\t" + RamUsageEstimator.humanSizeOf(dic) + "\t(" +
- "words=" + RamUsageEstimator.humanSizeOf(dic.words) + ", " +
- "flags=" + RamUsageEstimator.humanSizeOf(dic.flagLookup) + ", " +
- "strips=" + RamUsageEstimator.humanSizeOf(dic.stripData) + ", " +
- "conditions=" + RamUsageEstimator.humanSizeOf(dic.patterns) + ", " +
- "affixData=" + RamUsageEstimator.humanSizeOf(dic.affixData) + ", " +
- "prefixes=" + RamUsageEstimator.humanSizeOf(dic.prefixes) + ", " +
- "suffixes=" + RamUsageEstimator.humanSizeOf(dic.suffixes) + ")");
+ System.out.println(tests[i] + "\t" + RamUsageTester.humanSizeOf(dic) + "\t(" +
+ "words=" + RamUsageTester.humanSizeOf(dic.words) + ", " +
+ "flags=" + RamUsageTester.humanSizeOf(dic.flagLookup) + ", " +
+ "strips=" + RamUsageTester.humanSizeOf(dic.stripData) + ", " +
+ "conditions=" + RamUsageTester.humanSizeOf(dic.patterns) + ", " +
+ "affixData=" + RamUsageTester.humanSizeOf(dic.affixData) + ", " +
+ "prefixes=" + RamUsageTester.humanSizeOf(dic.prefixes) + ", " +
+ "suffixes=" + RamUsageTester.humanSizeOf(dic.suffixes) + ")");
}
}
}
Modified: lucene/dev/branches/branch_4x/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestAllDictionaries2.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestAllDictionaries2.java?rev=1602526&r1=1602525&r2=1602526&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestAllDictionaries2.java (original)
+++ lucene/dev/branches/branch_4x/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestAllDictionaries2.java Fri Jun 13 21:29:10 2014
@@ -24,9 +24,8 @@ import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import org.apache.lucene.analysis.hunspell.Dictionary;
-import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.LuceneTestCase;
-import org.apache.lucene.util.RamUsageEstimator;
+import org.apache.lucene.util.RamUsageTester;
import org.junit.Ignore;
/**
@@ -183,14 +182,14 @@ public class TestAllDictionaries2 extend
try (InputStream dictionary = zip.getInputStream(dicEntry);
InputStream affix = zip.getInputStream(affEntry)) {
Dictionary dic = new Dictionary(affix, dictionary);
- System.out.println(tests[i] + "\t" + RamUsageEstimator.humanSizeOf(dic) + "\t(" +
- "words=" + RamUsageEstimator.humanSizeOf(dic.words) + ", " +
- "flags=" + RamUsageEstimator.humanSizeOf(dic.flagLookup) + ", " +
- "strips=" + RamUsageEstimator.humanSizeOf(dic.stripData) + ", " +
- "conditions=" + RamUsageEstimator.humanSizeOf(dic.patterns) + ", " +
- "affixData=" + RamUsageEstimator.humanSizeOf(dic.affixData) + ", " +
- "prefixes=" + RamUsageEstimator.humanSizeOf(dic.prefixes) + ", " +
- "suffixes=" + RamUsageEstimator.humanSizeOf(dic.suffixes) + ")");
+ System.out.println(tests[i] + "\t" + RamUsageTester.humanSizeOf(dic) + "\t(" +
+ "words=" + RamUsageTester.humanSizeOf(dic.words) + ", " +
+ "flags=" + RamUsageTester.humanSizeOf(dic.flagLookup) + ", " +
+ "strips=" + RamUsageTester.humanSizeOf(dic.stripData) + ", " +
+ "conditions=" + RamUsageTester.humanSizeOf(dic.patterns) + ", " +
+ "affixData=" + RamUsageTester.humanSizeOf(dic.affixData) + ", " +
+ "prefixes=" + RamUsageTester.humanSizeOf(dic.prefixes) + ", " +
+ "suffixes=" + RamUsageTester.humanSizeOf(dic.suffixes) + ")");
}
}
}
Modified: lucene/dev/branches/branch_4x/lucene/common-build.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/common-build.xml?rev=1602526&r1=1602525&r2=1602526&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/common-build.xml (original)
+++ lucene/dev/branches/branch_4x/lucene/common-build.xml Fri Jun 13 21:29:10 2014
@@ -2214,7 +2214,6 @@ ${ant.project.name}.test.dependencies=${
<property name="forbidden-base-excludes" value=""/>
<property name="forbidden-tests-excludes" value=""/>
<property name="forbidden-sysout-excludes" value=""/>
- <property name="forbidden-rue-excludes" value=""/>
<target name="-install-forbidden-apis" unless="forbidden-apis.loaded" depends="ivy-availability-check,ivy-configure">
<ivy:cachepath organisation="de.thetaphi" module="forbiddenapis" revision="1.5.1"
@@ -2255,13 +2254,7 @@ ${ant.project.name}.test.dependencies=${
</target>
<!-- applies to only source code -->
- <target name="-check-forbidden-core" depends="-init-forbidden-apis,compile-core,-check-forbidden-sysout,-check-forbidden-rue" />
-
- <target name="-check-forbidden-rue" depends="-init-forbidden-apis,compile-core">
- <forbidden-apis signaturesFile="${common.dir}/tools/forbiddenApis/rue.txt" classpathref="forbidden-apis.allclasses.classpath">
- <fileset dir="${build.dir}/classes/java" excludes="${forbidden-rue-excludes}"/>
- </forbidden-apis>
- </target>
+ <target name="-check-forbidden-core" depends="-init-forbidden-apis,compile-core,-check-forbidden-sysout" />
<target name="-check-forbidden-sysout" depends="-init-forbidden-apis,compile-core">
<forbidden-apis bundledSignatures="jdk-system-out" classpathref="forbidden-apis.allclasses.classpath">
Modified: lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/index/DocTermOrds.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/index/DocTermOrds.java?rev=1602526&r1=1602525&r2=1602526&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/index/DocTermOrds.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/index/DocTermOrds.java Fri Jun 13 21:29:10 2014
@@ -26,6 +26,7 @@ import java.util.List;
import org.apache.lucene.codecs.PostingsFormat; // javadocs
import org.apache.lucene.index.TermsEnum.SeekStatus;
import org.apache.lucene.search.DocIdSetIterator;
+import org.apache.lucene.util.Accountable;
import org.apache.lucene.util.Bits;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.PagedBytes;
@@ -103,7 +104,7 @@ import org.apache.lucene.util.StringHelp
*
*/
-public class DocTermOrds {
+public class DocTermOrds implements Accountable {
// Term ords are shifted by this, internally, to reserve
// values 0 (end term) and 1 (index is a pointer into byte array)
@@ -160,7 +161,7 @@ public class DocTermOrds {
protected DocsEnum docsEnum;
/** Returns total bytes used. */
- public long ramUsedInBytes() {
+ public long ramBytesUsed() {
// can cache the mem size since it shouldn't change
if (memsz!=0) return memsz;
long sz = 8*8 + 32; // local fields
Modified: lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/FieldCache.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/FieldCache.java?rev=1602526&r1=1602525&r2=1602526&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/FieldCache.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/FieldCache.java Fri Jun 13 21:29:10 2014
@@ -34,6 +34,7 @@ import org.apache.lucene.index.SortedDoc
import org.apache.lucene.index.SortedSetDocValues;
import org.apache.lucene.index.Terms;
import org.apache.lucene.index.TermsEnum;
+import org.apache.lucene.util.Accountable;
import org.apache.lucene.util.Bits;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.NumericUtils;
@@ -138,8 +139,14 @@ public interface FieldCache {
/**
* Placeholder indicating creation of this cache is currently in-progress.
*/
- public static final class CreationPlaceholder {
- Object value;
+ public static final class CreationPlaceholder implements Accountable {
+ Accountable value;
+
+ @Override
+ public long ramBytesUsed() {
+ // don't call on the in-progress value, might make things angry.
+ return RamUsageEstimator.NUM_BYTES_OBJECT_REF;
+ }
}
/**
@@ -697,13 +704,13 @@ public interface FieldCache {
private final String fieldName;
private final Class<?> cacheType;
private final Object custom;
- private final Object value;
+ private final Accountable value;
private String size;
public CacheEntry(Object readerKey, String fieldName,
Class<?> cacheType,
Object custom,
- Object value) {
+ Accountable value) {
this.readerKey = readerKey;
this.fieldName = fieldName;
this.cacheType = cacheType;
@@ -731,21 +738,13 @@ public interface FieldCache {
return value;
}
- /**
- * Computes (and stores) the estimated size of the cache Value
- * @see #getEstimatedSize
- */
- public void estimateSize() {
- long bytesUsed = RamUsageEstimator.sizeOf(getValue());
- size = RamUsageEstimator.humanReadableUnits(bytesUsed);
- }
-
/**
* The most recently estimated size of the value, null unless
* estimateSize has been called.
*/
public String getEstimatedSize() {
- return size;
+ long bytesUsed = value == null ? 0 : value.ramBytesUsed();
+ return RamUsageEstimator.humanReadableUnits(bytesUsed);
}
@Override
Modified: lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/FieldCacheImpl.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/FieldCacheImpl.java?rev=1602526&r1=1602525&r2=1602526&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/FieldCacheImpl.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/FieldCacheImpl.java Fri Jun 13 21:29:10 2014
@@ -38,11 +38,13 @@ import org.apache.lucene.index.SortedDoc
import org.apache.lucene.index.SortedSetDocValues;
import org.apache.lucene.index.Terms;
import org.apache.lucene.index.TermsEnum;
+import org.apache.lucene.util.Accountable;
import org.apache.lucene.util.Bits;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.FieldCacheSanityChecker;
import org.apache.lucene.util.FixedBitSet;
import org.apache.lucene.util.PagedBytes;
+import org.apache.lucene.util.RamUsageEstimator;
import org.apache.lucene.util.packed.GrowableWriter;
import org.apache.lucene.util.packed.MonotonicAppendingLongBuffer;
import org.apache.lucene.util.packed.PackedInts;
@@ -93,11 +95,11 @@ class FieldCacheImpl implements FieldCac
final Cache cache = cacheEntry.getValue();
final Class<?> cacheType = cacheEntry.getKey();
synchronized(cache.readerCache) {
- for (final Map.Entry<Object,Map<CacheKey, Object>> readerCacheEntry : cache.readerCache.entrySet()) {
+ for (final Map.Entry<Object,Map<CacheKey, Accountable>> readerCacheEntry : cache.readerCache.entrySet()) {
final Object readerKey = readerCacheEntry.getKey();
if (readerKey == null) continue;
- final Map<CacheKey, Object> innerCache = readerCacheEntry.getValue();
- for (final Map.Entry<CacheKey, Object> mapEntry : innerCache.entrySet()) {
+ final Map<CacheKey, Accountable> innerCache = readerCacheEntry.getValue();
+ for (final Map.Entry<CacheKey, Accountable> mapEntry : innerCache.entrySet()) {
CacheKey entry = mapEntry.getKey();
result.add(new CacheEntry(readerKey, entry.field,
cacheType, entry.custom,
@@ -151,9 +153,9 @@ class FieldCacheImpl implements FieldCac
final FieldCacheImpl wrapper;
- final Map<Object,Map<CacheKey,Object>> readerCache = new WeakHashMap<>();
+ final Map<Object,Map<CacheKey,Accountable>> readerCache = new WeakHashMap<>();
- protected abstract Object createValue(AtomicReader reader, CacheKey key, boolean setDocsWithField)
+ protected abstract Accountable createValue(AtomicReader reader, CacheKey key, boolean setDocsWithField)
throws IOException;
/** Remove this reader from the cache, if present. */
@@ -165,10 +167,10 @@ class FieldCacheImpl implements FieldCac
/** Sets the key to the value for the provided reader;
* if the key is already set then this doesn't change it. */
- public void put(AtomicReader reader, CacheKey key, Object value) {
+ public void put(AtomicReader reader, CacheKey key, Accountable value) {
final Object readerKey = reader.getCoreCacheKey();
synchronized (readerCache) {
- Map<CacheKey,Object> innerCache = readerCache.get(readerKey);
+ Map<CacheKey,Accountable> innerCache = readerCache.get(readerKey);
if (innerCache == null) {
// First time this reader is using FieldCache
innerCache = new HashMap<>();
@@ -184,9 +186,9 @@ class FieldCacheImpl implements FieldCac
}
}
- public Object get(AtomicReader reader, CacheKey key, boolean setDocsWithField) throws IOException {
- Map<CacheKey,Object> innerCache;
- Object value;
+ public Accountable get(AtomicReader reader, CacheKey key, boolean setDocsWithField) throws IOException {
+ Map<CacheKey,Accountable> innerCache;
+ Accountable value;
final Object readerKey = reader.getCoreCacheKey();
synchronized (readerCache) {
innerCache = readerCache.get(readerKey);
@@ -351,7 +353,25 @@ class FieldCacheImpl implements FieldCac
} else {
bits = docsWithField;
}
- caches.get(DocsWithFieldCache.class).put(reader, new CacheKey(field, null), bits);
+ caches.get(DocsWithFieldCache.class).put(reader, new CacheKey(field, null), new BitsEntry(bits));
+ }
+
+ static class BitsEntry implements Accountable {
+ final Bits bits;
+
+ BitsEntry(Bits bits) {
+ this.bits = bits;
+ }
+
+ @Override
+ public long ramBytesUsed() {
+ long base = RamUsageEstimator.NUM_BYTES_OBJECT_REF;
+ if (bits instanceof Bits.MatchAllBits || bits instanceof Bits.MatchNoBits) {
+ return base;
+ } else {
+ return base + (bits.length() >>> 3);
+ }
+ }
}
// inherit javadocs
@@ -385,7 +405,7 @@ class FieldCacheImpl implements FieldCac
}
}
- static class BytesFromArray extends Bytes {
+ static class BytesFromArray extends Bytes implements Accountable {
private final byte[] values;
public BytesFromArray(byte[] values) {
@@ -396,6 +416,11 @@ class FieldCacheImpl implements FieldCac
public byte get(int docID) {
return values[docID];
}
+
+ @Override
+ public long ramBytesUsed() {
+ return RamUsageEstimator.NUM_BYTES_OBJECT_REF + RamUsageEstimator.sizeOf(values);
+ }
}
static final class ByteCache extends Cache {
@@ -404,7 +429,7 @@ class FieldCacheImpl implements FieldCac
}
@Override
- protected Object createValue(AtomicReader reader, CacheKey key, boolean setDocsWithField)
+ protected Accountable createValue(AtomicReader reader, CacheKey key, boolean setDocsWithField)
throws IOException {
int maxDoc = reader.maxDoc();
@@ -414,7 +439,7 @@ class FieldCacheImpl implements FieldCac
// Confusing: must delegate to wrapper (vs simply
// setting parser = DEFAULT_SHORT_PARSER) so cache
// key includes DEFAULT_SHORT_PARSER:
- return wrapper.getBytes(reader, key.field, DEFAULT_BYTE_PARSER, setDocsWithField);
+ return (Accountable) wrapper.getBytes(reader, key.field, DEFAULT_BYTE_PARSER, setDocsWithField);
}
values = new byte[maxDoc];
@@ -479,7 +504,7 @@ class FieldCacheImpl implements FieldCac
}
}
- static class ShortsFromArray extends Shorts {
+ static class ShortsFromArray extends Shorts implements Accountable {
private final short[] values;
public ShortsFromArray(short[] values) {
@@ -490,6 +515,11 @@ class FieldCacheImpl implements FieldCac
public short get(int docID) {
return values[docID];
}
+
+ @Override
+ public long ramBytesUsed() {
+ return RamUsageEstimator.NUM_BYTES_OBJECT_REF + RamUsageEstimator.sizeOf(values);
+ }
}
static final class ShortCache extends Cache {
@@ -498,7 +528,7 @@ class FieldCacheImpl implements FieldCac
}
@Override
- protected Object createValue(AtomicReader reader, CacheKey key, boolean setDocsWithField)
+ protected Accountable createValue(AtomicReader reader, CacheKey key, boolean setDocsWithField)
throws IOException {
int maxDoc = reader.maxDoc();
@@ -508,7 +538,7 @@ class FieldCacheImpl implements FieldCac
// Confusing: must delegate to wrapper (vs simply
// setting parser = DEFAULT_SHORT_PARSER) so cache
// key includes DEFAULT_SHORT_PARSER:
- return wrapper.getShorts(reader, key.field, DEFAULT_SHORT_PARSER, setDocsWithField);
+ return (Accountable) wrapper.getShorts(reader, key.field, DEFAULT_SHORT_PARSER, setDocsWithField);
}
values = new short[maxDoc];
@@ -571,7 +601,7 @@ class FieldCacheImpl implements FieldCac
}
}
- static class IntsFromArray extends Ints {
+ static class IntsFromArray extends Ints implements Accountable {
private final PackedInts.Reader values;
private final int minValue;
@@ -585,6 +615,11 @@ class FieldCacheImpl implements FieldCac
final long delta = values.get(docID);
return minValue + (int) delta;
}
+
+ @Override
+ public long ramBytesUsed() {
+ return RamUsageEstimator.NUM_BYTES_OBJECT_REF + RamUsageEstimator.NUM_BYTES_INT + values.ramBytesUsed();
+ }
}
private static class HoldsOneThing<T> {
@@ -614,7 +649,7 @@ class FieldCacheImpl implements FieldCac
}
@Override
- protected Object createValue(final AtomicReader reader, CacheKey key, boolean setDocsWithField)
+ protected Accountable createValue(final AtomicReader reader, CacheKey key, boolean setDocsWithField)
throws IOException {
final IntParser parser = (IntParser) key.custom;
@@ -625,9 +660,9 @@ class FieldCacheImpl implements FieldCac
// cache key includes
// DEFAULT_INT_PARSER/NUMERIC_UTILS_INT_PARSER:
try {
- return wrapper.getInts(reader, key.field, DEFAULT_INT_PARSER, setDocsWithField);
+ return (Accountable) wrapper.getInts(reader, key.field, DEFAULT_INT_PARSER, setDocsWithField);
} catch (NumberFormatException ne) {
- return wrapper.getInts(reader, key.field, NUMERIC_UTILS_INT_PARSER, setDocsWithField);
+ return (Accountable) wrapper.getInts(reader, key.field, NUMERIC_UTILS_INT_PARSER, setDocsWithField);
}
}
@@ -698,7 +733,8 @@ class FieldCacheImpl implements FieldCac
} else if (!fieldInfo.isIndexed()) {
return new Bits.MatchNoBits(reader.maxDoc());
}
- return (Bits) caches.get(DocsWithFieldCache.class).get(reader, new CacheKey(field, null), false);
+ BitsEntry entry = (BitsEntry) caches.get(DocsWithFieldCache.class).get(reader, new CacheKey(field, null), false);
+ return entry.bits;
}
static final class DocsWithFieldCache extends Cache {
@@ -707,7 +743,7 @@ class FieldCacheImpl implements FieldCac
}
@Override
- protected Object createValue(AtomicReader reader, CacheKey key, boolean setDocsWithField /* ignored */)
+ protected Accountable createValue(AtomicReader reader, CacheKey key, boolean setDocsWithField /* ignored */)
throws IOException {
final String field = key.field;
final int maxDoc = reader.maxDoc();
@@ -720,7 +756,7 @@ class FieldCacheImpl implements FieldCac
assert termsDocCount <= maxDoc;
if (termsDocCount == maxDoc) {
// Fast case: all docs have this field:
- return new Bits.MatchAllBits(maxDoc);
+ return new BitsEntry(new Bits.MatchAllBits(maxDoc));
}
final TermsEnum termsEnum = terms.iterator(null);
DocsEnum docs = null;
@@ -746,15 +782,15 @@ class FieldCacheImpl implements FieldCac
}
}
if (res == null) {
- return new Bits.MatchNoBits(maxDoc);
+ return new BitsEntry(new Bits.MatchNoBits(maxDoc));
}
final int numSet = res.cardinality();
if (numSet >= maxDoc) {
// The cardinality of the BitSet is maxDoc if all documents have a value.
assert numSet == maxDoc;
- return new Bits.MatchAllBits(maxDoc);
+ return new BitsEntry(new Bits.MatchAllBits(maxDoc));
}
- return res;
+ return new BitsEntry(res);
}
}
@@ -790,7 +826,7 @@ class FieldCacheImpl implements FieldCac
}
}
- static class FloatsFromArray extends Floats {
+ static class FloatsFromArray extends Floats implements Accountable {
private final float[] values;
public FloatsFromArray(float[] values) {
@@ -801,6 +837,11 @@ class FieldCacheImpl implements FieldCac
public float get(int docID) {
return values[docID];
}
+
+ @Override
+ public long ramBytesUsed() {
+ return RamUsageEstimator.NUM_BYTES_OBJECT_REF + RamUsageEstimator.sizeOf(values);
+ }
}
static final class FloatCache extends Cache {
@@ -809,7 +850,7 @@ class FieldCacheImpl implements FieldCac
}
@Override
- protected Object createValue(final AtomicReader reader, CacheKey key, boolean setDocsWithField)
+ protected Accountable createValue(final AtomicReader reader, CacheKey key, boolean setDocsWithField)
throws IOException {
final FloatParser parser = (FloatParser) key.custom;
@@ -820,9 +861,9 @@ class FieldCacheImpl implements FieldCac
// cache key includes
// DEFAULT_FLOAT_PARSER/NUMERIC_UTILS_FLOAT_PARSER:
try {
- return wrapper.getFloats(reader, key.field, DEFAULT_FLOAT_PARSER, setDocsWithField);
+ return (Accountable) wrapper.getFloats(reader, key.field, DEFAULT_FLOAT_PARSER, setDocsWithField);
} catch (NumberFormatException ne) {
- return wrapper.getFloats(reader, key.field, NUMERIC_UTILS_FLOAT_PARSER, setDocsWithField);
+ return (Accountable) wrapper.getFloats(reader, key.field, NUMERIC_UTILS_FLOAT_PARSER, setDocsWithField);
}
}
@@ -901,7 +942,7 @@ class FieldCacheImpl implements FieldCac
}
}
- static class LongsFromArray extends Longs {
+ static class LongsFromArray extends Longs implements Accountable {
private final PackedInts.Reader values;
private final long minValue;
@@ -914,6 +955,11 @@ class FieldCacheImpl implements FieldCac
public long get(int docID) {
return minValue + values.get(docID);
}
+
+ @Override
+ public long ramBytesUsed() {
+ return RamUsageEstimator.NUM_BYTES_OBJECT_REF + RamUsageEstimator.NUM_BYTES_LONG + values.ramBytesUsed();
+ }
}
static final class LongCache extends Cache {
@@ -922,7 +968,7 @@ class FieldCacheImpl implements FieldCac
}
@Override
- protected Object createValue(final AtomicReader reader, CacheKey key, boolean setDocsWithField)
+ protected Accountable createValue(final AtomicReader reader, CacheKey key, boolean setDocsWithField)
throws IOException {
final LongParser parser = (LongParser) key.custom;
@@ -933,9 +979,9 @@ class FieldCacheImpl implements FieldCac
// cache key includes
// DEFAULT_LONG_PARSER/NUMERIC_UTILS_LONG_PARSER:
try {
- return wrapper.getLongs(reader, key.field, DEFAULT_LONG_PARSER, setDocsWithField);
+ return (Accountable) wrapper.getLongs(reader, key.field, DEFAULT_LONG_PARSER, setDocsWithField);
} catch (NumberFormatException ne) {
- return wrapper.getLongs(reader, key.field, NUMERIC_UTILS_LONG_PARSER, setDocsWithField);
+ return (Accountable) wrapper.getLongs(reader, key.field, NUMERIC_UTILS_LONG_PARSER, setDocsWithField);
}
}
@@ -1027,7 +1073,7 @@ class FieldCacheImpl implements FieldCac
}
}
- static class DoublesFromArray extends Doubles {
+ static class DoublesFromArray extends Doubles implements Accountable {
private final double[] values;
public DoublesFromArray(double[] values) {
@@ -1038,6 +1084,11 @@ class FieldCacheImpl implements FieldCac
public double get(int docID) {
return values[docID];
}
+
+ @Override
+ public long ramBytesUsed() {
+ return RamUsageEstimator.NUM_BYTES_OBJECT_REF + RamUsageEstimator.sizeOf(values);
+ }
}
static final class DoubleCache extends Cache {
@@ -1046,7 +1097,7 @@ class FieldCacheImpl implements FieldCac
}
@Override
- protected Object createValue(final AtomicReader reader, CacheKey key, boolean setDocsWithField)
+ protected Accountable createValue(final AtomicReader reader, CacheKey key, boolean setDocsWithField)
throws IOException {
final DoubleParser parser = (DoubleParser) key.custom;
@@ -1057,9 +1108,9 @@ class FieldCacheImpl implements FieldCac
// cache key includes
// DEFAULT_DOUBLE_PARSER/NUMERIC_UTILS_DOUBLE_PARSER:
try {
- return wrapper.getDoubles(reader, key.field, DEFAULT_DOUBLE_PARSER, setDocsWithField);
+ return (Accountable) wrapper.getDoubles(reader, key.field, DEFAULT_DOUBLE_PARSER, setDocsWithField);
} catch (NumberFormatException ne) {
- return wrapper.getDoubles(reader, key.field, NUMERIC_UTILS_DOUBLE_PARSER, setDocsWithField);
+ return (Accountable) wrapper.getDoubles(reader, key.field, NUMERIC_UTILS_DOUBLE_PARSER, setDocsWithField);
}
}
@@ -1106,7 +1157,7 @@ class FieldCacheImpl implements FieldCac
}
}
- public static class SortedDocValuesImpl {
+ public static class SortedDocValuesImpl implements Accountable {
private final PagedBytes.Reader bytes;
private final MonotonicAppendingLongBuffer termOrdToBytesOffset;
private final PackedInts.Reader docToTermOrd;
@@ -1146,6 +1197,15 @@ class FieldCacheImpl implements FieldCac
}
};
}
+
+ @Override
+ public long ramBytesUsed() {
+ return 3*RamUsageEstimator.NUM_BYTES_OBJECT_REF +
+ RamUsageEstimator.NUM_BYTES_INT +
+ bytes.ramBytesUsed() +
+ termOrdToBytesOffset.ramBytesUsed() +
+ docToTermOrd.ramBytesUsed();
+ }
}
public SortedDocValues getTermsIndex(AtomicReader reader, String field) throws IOException {
@@ -1180,7 +1240,7 @@ class FieldCacheImpl implements FieldCac
}
@Override
- protected Object createValue(AtomicReader reader, CacheKey key, boolean setDocsWithField /* ignored */)
+ protected Accountable createValue(AtomicReader reader, CacheKey key, boolean setDocsWithField /* ignored */)
throws IOException {
final int maxDoc = reader.maxDoc();
@@ -1262,7 +1322,7 @@ class FieldCacheImpl implements FieldCac
}
}
- private static class BinaryDocValuesImpl {
+ private static class BinaryDocValuesImpl implements Accountable {
private final PagedBytes.Reader bytes;
private final PackedInts.Reader docToOffset;
@@ -1286,6 +1346,11 @@ class FieldCacheImpl implements FieldCac
}
};
}
+
+ @Override
+ public long ramBytesUsed() {
+ return 2*RamUsageEstimator.NUM_BYTES_OBJECT_REF + bytes.ramBytesUsed() + docToOffset.ramBytesUsed();
+ }
}
// TODO: this if DocTermsIndex was already created, we
@@ -1325,7 +1390,7 @@ class FieldCacheImpl implements FieldCac
}
@Override
- protected Object createValue(AtomicReader reader, CacheKey key, boolean setDocsWithField)
+ protected Accountable createValue(AtomicReader reader, CacheKey key, boolean setDocsWithField)
throws IOException {
// TODO: would be nice to first check if DocTermsIndex
@@ -1445,7 +1510,7 @@ class FieldCacheImpl implements FieldCac
}
@Override
- protected Object createValue(AtomicReader reader, CacheKey key, boolean setDocsWithField /* ignored */)
+ protected Accountable createValue(AtomicReader reader, CacheKey key, boolean setDocsWithField /* ignored */)
throws IOException {
return new DocTermOrds(reader, null, key.field);
}
Modified: lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/util/FieldCacheSanityChecker.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/util/FieldCacheSanityChecker.java?rev=1602526&r1=1602525&r2=1602526&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/util/FieldCacheSanityChecker.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/util/FieldCacheSanityChecker.java Fri Jun 13 21:29:10 2014
@@ -23,7 +23,6 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
-import org.apache.lucene.index.CompositeReader;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexReaderContext;
import org.apache.lucene.search.FieldCache;
@@ -54,19 +53,10 @@ import org.apache.lucene.store.AlreadyCl
*/
public final class FieldCacheSanityChecker {
- private boolean estimateRam;
-
public FieldCacheSanityChecker() {
/* NOOP */
}
- /**
- * If set, estimate size for all CacheEntry objects will be calculateed.
- */
- public void setRamUsageEstimator(boolean flag) {
- estimateRam = flag;
- }
-
/**
* Quick and dirty convenience method
@@ -83,7 +73,6 @@ public final class FieldCacheSanityCheck
*/
public static Insanity[] checkSanity(CacheEntry... cacheEntries) {
FieldCacheSanityChecker sanityChecker = new FieldCacheSanityChecker();
- sanityChecker.setRamUsageEstimator(true);
return sanityChecker.check(cacheEntries);
}
@@ -99,12 +88,6 @@ public final class FieldCacheSanityCheck
if (null == cacheEntries || 0 == cacheEntries.length)
return new Insanity[0];
- if (estimateRam) {
- for (int i = 0; i < cacheEntries.length; i++) {
- cacheEntries[i].estimateSize();
- }
- }
-
// the indirect mapping lets MapOfSet dedup identical valIds for us
//
// maps the (valId) identityhashCode of cache values to
@@ -125,7 +108,7 @@ public final class FieldCacheSanityCheck
// It's OK to have dup entries, where one is eg
// float[] and the other is the Bits (from
// getDocWithField())
- if (val instanceof Bits) {
+ if (val != null && "BitsEntry".equals(val.getClass().getSimpleName())) {
continue;
}
Modified: lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/util/RamUsageEstimator.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/util/RamUsageEstimator.java?rev=1602526&r1=1602525&r2=1602526&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/util/RamUsageEstimator.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/util/RamUsageEstimator.java Fri Jun 13 21:29:10 2014
@@ -27,7 +27,6 @@ import java.util.*;
/**
* Estimates the size (memory representation) of Java objects.
*
- * @see #sizeOf(Object)
* @see #shallowSizeOf(Object)
* @see #shallowSizeOfInstance(Class)
*
@@ -235,18 +234,6 @@ public final class RamUsageEstimator {
Constants.JAVA_VENDOR + ", " + Constants.JAVA_VERSION + "]";
}
- /**
- * Cached information about a given class.
- */
- private static final class ClassCache {
- public final long alignedShallowInstanceSize;
- public final Field[] referenceFields;
-
- public ClassCache(long alignedShallowInstanceSize, Field[] referenceFields) {
- this.alignedShallowInstanceSize = alignedShallowInstanceSize;
- this.referenceFields = referenceFields;
- }
- }
// Object with just one field to determine the object header size by getting the offset of the dummy field:
@SuppressWarnings("unused")
@@ -321,19 +308,6 @@ public final class RamUsageEstimator {
}
/**
- * Estimates the RAM usage by the given object. It will
- * walk the object tree and sum up all referenced objects.
- *
- * <p><b>Resource Usage:</b> This method internally uses a set of
- * every object seen during traversals so it does allocate memory
- * (it isn't side-effect free). After the method exits, this memory
- * should be GCed.</p>
- */
- public static long sizeOf(Object obj) {
- return measureObjectSize(obj);
- }
-
- /**
* Estimates a "shallow" memory usage of the given object. For arrays, this will be the
* memory taken by array storage (no subreferences will be followed). For objects, this
* will be the memory taken by the fields.
@@ -395,119 +369,6 @@ public final class RamUsageEstimator {
return alignObjectSize(size);
}
- /*
- * Non-recursive version of object descend. This consumes more memory than recursive in-depth
- * traversal but prevents stack overflows on long chains of objects
- * or complex graphs (a max. recursion depth on my machine was ~5000 objects linked in a chain
- * so not too much).
- */
- private static long measureObjectSize(Object root) {
- // Objects seen so far.
- final IdentityHashSet<Object> seen = new IdentityHashSet<>();
- // Class cache with reference Field and precalculated shallow size.
- final IdentityHashMap<Class<?>, ClassCache> classCache = new IdentityHashMap<>();
- // Stack of objects pending traversal. Recursion caused stack overflows.
- final ArrayList<Object> stack = new ArrayList<>();
- stack.add(root);
-
- long totalSize = 0;
- while (!stack.isEmpty()) {
- final Object ob = stack.remove(stack.size() - 1);
-
- if (ob == null || seen.contains(ob)) {
- continue;
- }
- seen.add(ob);
-
- final Class<?> obClazz = ob.getClass();
- assert obClazz != null : "jvm bug detected (Object.getClass() == null). please report this to your vendor";
- if (obClazz.isArray()) {
- /*
- * Consider an array, possibly of primitive types. Push any of its references to
- * the processing stack and accumulate this array's shallow size.
- */
- long size = NUM_BYTES_ARRAY_HEADER;
- final int len = Array.getLength(ob);
- if (len > 0) {
- Class<?> componentClazz = obClazz.getComponentType();
- if (componentClazz.isPrimitive()) {
- size += (long) len * primitiveSizes.get(componentClazz);
- } else {
- size += (long) NUM_BYTES_OBJECT_REF * len;
-
- // Push refs for traversal later.
- for (int i = len; --i >= 0 ;) {
- final Object o = Array.get(ob, i);
- if (o != null && !seen.contains(o)) {
- stack.add(o);
- }
- }
- }
- }
- totalSize += alignObjectSize(size);
- } else {
- /*
- * Consider an object. Push any references it has to the processing stack
- * and accumulate this object's shallow size.
- */
- try {
- ClassCache cachedInfo = classCache.get(obClazz);
- if (cachedInfo == null) {
- classCache.put(obClazz, cachedInfo = createCacheEntry(obClazz));
- }
-
- for (Field f : cachedInfo.referenceFields) {
- // Fast path to eliminate redundancies.
- final Object o = f.get(ob);
- if (o != null && !seen.contains(o)) {
- stack.add(o);
- }
- }
-
- totalSize += cachedInfo.alignedShallowInstanceSize;
- } catch (IllegalAccessException e) {
- // this should never happen as we enabled setAccessible().
- throw new RuntimeException("Reflective field access failed?", e);
- }
- }
- }
-
- // Help the GC (?).
- seen.clear();
- stack.clear();
- classCache.clear();
-
- return totalSize;
- }
-
- /**
- * Create a cached information about shallow size and reference fields for
- * a given class.
- */
- private static ClassCache createCacheEntry(final Class<?> clazz) {
- ClassCache cachedInfo;
- long shallowInstanceSize = NUM_BYTES_OBJECT_HEADER;
- final ArrayList<Field> referenceFields = new ArrayList<>(32);
- for (Class<?> c = clazz; c != null; c = c.getSuperclass()) {
- final Field[] fields = c.getDeclaredFields();
- for (final Field f : fields) {
- if (!Modifier.isStatic(f.getModifiers())) {
- shallowInstanceSize = adjustForField(shallowInstanceSize, f);
-
- if (!f.getType().isPrimitive()) {
- f.setAccessible(true);
- referenceFields.add(f);
- }
- }
- }
- }
-
- cachedInfo = new ClassCache(
- alignObjectSize(shallowInstanceSize),
- referenceFields.toArray(new Field[referenceFields.size()]));
- return cachedInfo;
- }
-
/**
* This method returns the maximum representation size of an object. <code>sizeSoFar</code>
* is the object's size measured so far. <code>f</code> is the field being probed.
@@ -515,7 +376,7 @@ public final class RamUsageEstimator {
* <p>The returned offset will be the maximum of whatever was measured so far and
* <code>f</code> field's offset and representation size (unaligned).
*/
- private static long adjustForField(long sizeSoFar, final Field f) {
+ static long adjustForField(long sizeSoFar, final Field f) {
final Class<?> type = f.getType();
final int fsize = type.isPrimitive() ? primitiveSizes.get(type) : NUM_BYTES_OBJECT_REF;
if (objectFieldOffsetMethod != null) {
@@ -577,252 +438,4 @@ public final class RamUsageEstimator {
return bytes + " bytes";
}
}
-
- /**
- * Return a human-readable size of a given object.
- * @see #sizeOf(Object)
- * @see #humanReadableUnits(long)
- */
- public static String humanSizeOf(Object object) {
- return humanReadableUnits(sizeOf(object));
- }
-
- /**
- * An identity hash set implemented using open addressing. No null keys are allowed.
- *
- * TODO: If this is useful outside this class, make it public - needs some work
- */
- static final class IdentityHashSet<KType> implements Iterable<KType> {
- /**
- * Default load factor.
- */
- public final static float DEFAULT_LOAD_FACTOR = 0.75f;
-
- /**
- * Minimum capacity for the set.
- */
- public final static int MIN_CAPACITY = 4;
-
- /**
- * All of set entries. Always of power of two length.
- */
- public Object[] keys;
-
- /**
- * Cached number of assigned slots.
- */
- public int assigned;
-
- /**
- * The load factor for this set (fraction of allocated or deleted slots before
- * the buffers must be rehashed or reallocated).
- */
- public final float loadFactor;
-
- /**
- * Cached capacity threshold at which we must resize the buffers.
- */
- private int resizeThreshold;
-
- /**
- * Creates a hash set with the default capacity of 16.
- * load factor of {@value #DEFAULT_LOAD_FACTOR}. `
- */
- public IdentityHashSet() {
- this(16, DEFAULT_LOAD_FACTOR);
- }
-
- /**
- * Creates a hash set with the given capacity, load factor of
- * {@value #DEFAULT_LOAD_FACTOR}.
- */
- public IdentityHashSet(int initialCapacity) {
- this(initialCapacity, DEFAULT_LOAD_FACTOR);
- }
-
- /**
- * Creates a hash set with the given capacity and load factor.
- */
- public IdentityHashSet(int initialCapacity, float loadFactor) {
- initialCapacity = Math.max(MIN_CAPACITY, initialCapacity);
-
- assert initialCapacity > 0 : "Initial capacity must be between (0, "
- + Integer.MAX_VALUE + "].";
- assert loadFactor > 0 && loadFactor < 1 : "Load factor must be between (0, 1).";
- this.loadFactor = loadFactor;
- allocateBuffers(roundCapacity(initialCapacity));
- }
-
- /**
- * Adds a reference to the set. Null keys are not allowed.
- */
- public boolean add(KType e) {
- assert e != null : "Null keys not allowed.";
-
- if (assigned >= resizeThreshold) expandAndRehash();
-
- final int mask = keys.length - 1;
- int slot = rehash(e) & mask;
- Object existing;
- while ((existing = keys[slot]) != null) {
- if (e == existing) {
- return false; // already found.
- }
- slot = (slot + 1) & mask;
- }
- assigned++;
- keys[slot] = e;
- return true;
- }
-
- /**
- * Checks if the set contains a given ref.
- */
- public boolean contains(KType e) {
- final int mask = keys.length - 1;
- int slot = rehash(e) & mask;
- Object existing;
- while ((existing = keys[slot]) != null) {
- if (e == existing) {
- return true;
- }
- slot = (slot + 1) & mask;
- }
- return false;
- }
-
- /** Rehash via MurmurHash.
- *
- * <p>The implementation is based on the
- * finalization step from Austin Appleby's
- * <code>MurmurHash3</code>.
- *
- * @see "http://sites.google.com/site/murmurhash/"
- */
- private static int rehash(Object o) {
- int k = System.identityHashCode(o);
- k ^= k >>> 16;
- k *= 0x85ebca6b;
- k ^= k >>> 13;
- k *= 0xc2b2ae35;
- k ^= k >>> 16;
- return k;
- }
-
- /**
- * Expand the internal storage buffers (capacity) or rehash current keys and
- * values if there are a lot of deleted slots.
- */
- private void expandAndRehash() {
- final Object[] oldKeys = this.keys;
-
- assert assigned >= resizeThreshold;
- allocateBuffers(nextCapacity(keys.length));
-
- /*
- * Rehash all assigned slots from the old hash table.
- */
- final int mask = keys.length - 1;
- for (int i = 0; i < oldKeys.length; i++) {
- final Object key = oldKeys[i];
- if (key != null) {
- int slot = rehash(key) & mask;
- while (keys[slot] != null) {
- slot = (slot + 1) & mask;
- }
- keys[slot] = key;
- }
- }
- Arrays.fill(oldKeys, null);
- }
-
- /**
- * Allocate internal buffers for a given capacity.
- *
- * @param capacity
- * New capacity (must be a power of two).
- */
- private void allocateBuffers(int capacity) {
- this.keys = new Object[capacity];
- this.resizeThreshold = (int) (capacity * DEFAULT_LOAD_FACTOR);
- }
-
- /**
- * Return the next possible capacity, counting from the current buffers' size.
- */
- protected int nextCapacity(int current) {
- assert current > 0 && Long.bitCount(current) == 1 : "Capacity must be a power of two.";
- assert ((current << 1) > 0) : "Maximum capacity exceeded ("
- + (0x80000000 >>> 1) + ").";
-
- if (current < MIN_CAPACITY / 2) current = MIN_CAPACITY / 2;
- return current << 1;
- }
-
- /**
- * Round the capacity to the next allowed value.
- */
- protected int roundCapacity(int requestedCapacity) {
- // Maximum positive integer that is a power of two.
- if (requestedCapacity > (0x80000000 >>> 1)) return (0x80000000 >>> 1);
-
- int capacity = MIN_CAPACITY;
- while (capacity < requestedCapacity) {
- capacity <<= 1;
- }
-
- return capacity;
- }
-
- public void clear() {
- assigned = 0;
- Arrays.fill(keys, null);
- }
-
- public int size() {
- return assigned;
- }
-
- public boolean isEmpty() {
- return size() == 0;
- }
-
- @Override
- public Iterator<KType> iterator() {
- return new Iterator<KType>() {
- int pos = -1;
- Object nextElement = fetchNext();
-
- @Override
- public boolean hasNext() {
- return nextElement != null;
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public KType next() {
- Object r = this.nextElement;
- if (r == null) {
- throw new NoSuchElementException();
- }
- this.nextElement = fetchNext();
- return (KType) r;
- }
-
- private Object fetchNext() {
- pos++;
- while (pos < keys.length && keys[pos] == null) {
- pos++;
- }
-
- return (pos >= keys.length ? null : keys[pos]);
- }
-
- @Override
- public void remove() {
- throw new UnsupportedOperationException();
- }
- };
- }
- }
}
Modified: lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/StressRamUsageEstimator.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/StressRamUsageEstimator.java?rev=1602526&r1=1602525&r2=1602526&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/StressRamUsageEstimator.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/StressRamUsageEstimator.java Fri Jun 13 21:29:10 2014
@@ -58,7 +58,7 @@ public class StressRamUsageEstimator ext
while (true) {
// Check the current memory consumption and provide the estimate.
long jvmUsed = memoryMXBean.getHeapMemoryUsage().getUsed();
- long estimated = RamUsageEstimator.sizeOf(first);
+ long estimated = RamUsageTester.sizeOf(first);
System.out.println(String.format(Locale.ROOT, "%10d, %10d",
jvmUsed, estimated));
Modified: lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/TestIdentityHashSet.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/TestIdentityHashSet.java?rev=1602526&r1=1602525&r2=1602526&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/TestIdentityHashSet.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/TestIdentityHashSet.java Fri Jun 13 21:29:10 2014
@@ -28,7 +28,7 @@ public class TestIdentityHashSet extends
Random rnd = random();
Set<Object> jdk = Collections.newSetFromMap(
new IdentityHashMap<Object,Boolean>());
- RamUsageEstimator.IdentityHashSet<Object> us = new RamUsageEstimator.IdentityHashSet<>();
+ RamUsageTester.IdentityHashSet<Object> us = new RamUsageTester.IdentityHashSet<>();
int max = 100000;
int threshold = 256;
Modified: lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/TestRamUsageEstimator.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/TestRamUsageEstimator.java?rev=1602526&r1=1602525&r2=1602526&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/TestRamUsageEstimator.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/TestRamUsageEstimator.java Fri Jun 13 21:29:10 2014
@@ -18,11 +18,10 @@ package org.apache.lucene.util;
*/
import static org.apache.lucene.util.RamUsageEstimator.*;
+import static org.apache.lucene.util.RamUsageTester.sizeOf;
import java.util.Random;
-import com.carrotsearch.randomizedtesting.generators.RandomStrings;
-
public class TestRamUsageEstimator extends LuceneTestCase {
public void testSanity() {
assertTrue(sizeOf(new String("test string")) > shallowSizeOfInstance(String.class));
Modified: lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/TestRamUsageEstimatorOnWildAnimals.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/TestRamUsageEstimatorOnWildAnimals.java?rev=1602526&r1=1602525&r2=1602526&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/TestRamUsageEstimatorOnWildAnimals.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/TestRamUsageEstimatorOnWildAnimals.java Fri Jun 13 21:29:10 2014
@@ -40,7 +40,7 @@ public class TestRamUsageEstimatorOnWild
for (int i = 0; i < mid; i++) {
last = (last.next = new ListElement());
}
- RamUsageEstimator.sizeOf(first); // cause SOE or pass.
+ RamUsageTester.sizeOf(first); // cause SOE or pass.
lower = mid;
} catch (StackOverflowError e) {
upper = mid;
Modified: lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/packed/TestPackedInts.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/packed/TestPackedInts.java?rev=1602526&r1=1602525&r2=1602526&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/packed/TestPackedInts.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/util/packed/TestPackedInts.java Fri Jun 13 21:29:10 2014
@@ -38,6 +38,7 @@ import org.apache.lucene.util.LongsRef;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.LuceneTestCase.Slow;
import org.apache.lucene.util.RamUsageEstimator;
+import org.apache.lucene.util.RamUsageTester;
import org.apache.lucene.util.TestUtil;
import org.apache.lucene.util.packed.PackedInts.Reader;
import org.junit.Ignore;
@@ -146,7 +147,7 @@ public class TestPackedInts extends Luce
}
in.close();
- final long expectedBytesUsed = RamUsageEstimator.sizeOf(r);
+ final long expectedBytesUsed = RamUsageTester.sizeOf(r);
final long computedBytesUsed = r.ramBytesUsed();
assertEquals(r.getClass() + "expected " + expectedBytesUsed + ", got: " + computedBytesUsed,
expectedBytesUsed, computedBytesUsed);
@@ -687,7 +688,7 @@ public class TestPackedInts extends Luce
assertEquals(10, wrt.get(7));
assertEquals(99, wrt.get(valueCount - 10));
assertEquals(1 << 10, wrt.get(valueCount - 1));
- assertEquals(RamUsageEstimator.sizeOf(wrt), wrt.ramBytesUsed());
+ assertEquals(RamUsageTester.sizeOf(wrt), wrt.ramBytesUsed());
}
public void testPagedGrowableWriter() {
@@ -716,7 +717,7 @@ public class TestPackedInts extends Luce
}
// test ramBytesUsed
- assertEquals(RamUsageEstimator.sizeOf(writer), writer.ramBytesUsed(), 8);
+ assertEquals(RamUsageTester.sizeOf(writer), writer.ramBytesUsed(), 8);
// test copy
PagedGrowableWriter copy = writer.resize(TestUtil.nextLong(random(), writer.size() / 2, writer.size() * 3 / 2));
@@ -764,7 +765,7 @@ public class TestPackedInts extends Luce
}
// test ramBytesUsed
- assertEquals(RamUsageEstimator.sizeOf(writer) - RamUsageEstimator.sizeOf(writer.format), writer.ramBytesUsed());
+ assertEquals(RamUsageTester.sizeOf(writer) - RamUsageTester.sizeOf(writer.format), writer.ramBytesUsed());
// test copy
PagedMutable copy = writer.resize(TestUtil.nextLong(random(), writer.size() / 2, writer.size() * 3 / 2));
@@ -1048,7 +1049,7 @@ public class TestPackedInts extends Luce
}
}
- final long expectedBytesUsed = RamUsageEstimator.sizeOf(buf);
+ final long expectedBytesUsed = RamUsageTester.sizeOf(buf);
final long computedBytesUsed = buf.ramBytesUsed();
assertEquals(expectedBytesUsed, computedBytesUsed);
}
Modified: lucene/dev/branches/branch_4x/lucene/memory/build.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/memory/build.xml?rev=1602526&r1=1602525&r2=1602526&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/memory/build.xml (original)
+++ lucene/dev/branches/branch_4x/lucene/memory/build.xml Fri Jun 13 21:29:10 2014
@@ -19,10 +19,6 @@
<project name="memory" default="default">
- <property name="forbidden-rue-excludes" value="
- org/apache/lucene/index/memory/MemoryIndex.class
- "/>
-
<description>
Single-document in-memory index implementation
</description>
Modified: lucene/dev/branches/branch_4x/lucene/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java?rev=1602526&r1=1602525&r2=1602526&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java (original)
+++ lucene/dev/branches/branch_4x/lucene/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java Fri Jun 13 21:29:10 2014
@@ -575,15 +575,6 @@ public class MemoryIndex {
*/
}
}
-
- /**
- * Returns a reasonable approximation of the main memory [bytes] consumed by
- * this instance. Useful for smart memory sensititive caches/pools.
- * @return the main memory consumption
- */
- public long getMemorySize() {
- return RamUsageEstimator.sizeOf(this);
- }
/** sorts into ascending order (on demand), reusing memory along the way */
private void sortFields() {
@@ -656,7 +647,6 @@ public class MemoryIndex {
result.append("\tterms=" + info.terms.size());
result.append(", positions=" + numPositions);
- result.append(", memory=" + RamUsageEstimator.humanReadableUnits(RamUsageEstimator.sizeOf(info)));
result.append("\n");
sumPositions += numPositions;
sumTerms += info.terms.size();
@@ -665,7 +655,6 @@ public class MemoryIndex {
result.append("\nfields=" + sortedFields.length);
result.append(", terms=" + sumTerms);
result.append(", positions=" + sumPositions);
- result.append(", memory=" + RamUsageEstimator.humanReadableUnits(getMemorySize()));
return result.toString();
}
Modified: lucene/dev/branches/branch_4x/lucene/memory/src/test/org/apache/lucene/index/memory/MemoryIndexTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/memory/src/test/org/apache/lucene/index/memory/MemoryIndexTest.java?rev=1602526&r1=1602525&r2=1602526&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/memory/src/test/org/apache/lucene/index/memory/MemoryIndexTest.java (original)
+++ lucene/dev/branches/branch_4x/lucene/memory/src/test/org/apache/lucene/index/memory/MemoryIndexTest.java Fri Jun 13 21:29:10 2014
@@ -162,14 +162,6 @@ public class MemoryIndexTest extends Bas
memory.addField("foo", fooField.toString(), analyzer);
memory.addField("term", termField.toString(), analyzer);
- if (VERBOSE) {
- System.out.println("Random MemoryIndex:\n" + memory.toString());
- System.out.println("Same index as RAMDirectory: " +
- RamUsageEstimator.humanReadableUnits(RamUsageEstimator.sizeOf(ramdir)));
- System.out.println();
- } else {
- assertTrue(memory.getMemorySize() > 0L);
- }
AtomicReader reader = (AtomicReader) memory.createSearcher().getIndexReader();
DirectoryReader competitor = DirectoryReader.open(ramdir);
duellReaders(competitor, reader);
Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/request/UnInvertedField.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/request/UnInvertedField.java?rev=1602526&r1=1602525&r2=1602526&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/request/UnInvertedField.java (original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/request/UnInvertedField.java Fri Jun 13 21:29:10 2014
@@ -156,7 +156,7 @@ public class UnInvertedField extends Doc
public long memSize() {
// can cache the mem size since it shouldn't change
if (memsz!=0) return memsz;
- long sz = super.ramUsedInBytes();
+ long sz = super.ramBytesUsed();
sz += 8*8 + 32; // local fields
sz += bigTerms.size() * 64;
for (TopTerm tt : bigTerms.values()) {