/** * Rehashes the content of the table into a bigger table. * This method is called automatically when the hashtable's * size exceeds the threshold. */ private void rehash() { CharArrayCache newHashtable = new CharArrayCache(this.keyTable.length * 2); for (int i = this.keyTable.length; --i >= 0;) if (this.keyTable[i] != null) newHashtable.put(this.keyTable[i], this.valueTable[i]); this.keyTable = newHashtable.keyTable; this.valueTable = newHashtable.valueTable; this.threshold = newHashtable.threshold; } /** Remove the object associated with the specified key in the
/** * INTERNAL USE-ONLY * This methods returns a char[] representing the file name of the receiver * * @return char[] */ public char[] fileName() { return this.constantPool.UTF8Cache.returnKeyFor(2); }
/** * Puts the specified element into the hashtable if it wasn't there already, * using the specified key. The element may be retrieved by doing a get() with the same key. * The key and the element cannot be null. * * @param key the given key in the hashtable * @param value the given value * @return int the old value of the key, or -value if it did not have one. */ public int putIfAbsent(char[] key, int value) { int length = this.keyTable.length, index = CharOperation.hashCode(key) % length; while (this.keyTable[index] != null) { if (CharOperation.equals(this.keyTable[index], key)) return this.valueTable[index]; if (++index == length) { // faster than modulo index = 0; } } this.keyTable[index] = key; this.valueTable[index] = value; // assumes the threshold is never equal to the size of the table if (++this.elementSize > this.threshold) rehash(); return -value; // negative when added (value is assumed to be > 0) }
public int literalIndexForType(final char[] constantPoolName) { int index; if ((index = this.classCache.putIfAbsent(constantPoolName, this.currentIndex)) < 0) { // The entry doesn't exit yet this.currentIndex++; if ((index = -index) > 0xFFFF){ this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType()); } int length = this.offsets.length; if (length <= index) { // resize System.arraycopy(this.offsets, 0, (this.offsets = new int[index * 2]), 0, length); } this.offsets[index] = this.currentOffset; writeU1(ClassTag); // Then the name index int nameIndexOffset = this.currentOffset; if (this.currentOffset + 2 >= this.poolContent.length) { resizePoolContents(2); } this.currentOffset+=2; final int nameIndex = literalIndex(constantPoolName); this.poolContent[nameIndexOffset++] = (byte) (nameIndex >> 8); this.poolContent[nameIndexOffset] = (byte) nameIndex; } return index; } /*
public void reset() { if (this.doubleCache != null) this.doubleCache.clear(); if (this.floatCache != null) this.floatCache.clear(); if (this.intCache != null) this.intCache.clear(); if (this.longCache != null) this.longCache.clear(); this.UTF8Cache.clear(); this.stringCache.clear(); this.methodsAndFieldsCache.clear(); this.classCache.clear(); this.packageCache.clear(); this.moduleCache.clear(); this.nameAndTypeCacheForFieldsAndMethods.clear(); this.currentIndex = 1; this.currentOffset = 0; } }
/** * Converts to a rather lengthy String. * * return String the ascii representation of the receiver */ public String toString() { int max = size(); StringBuffer buf = new StringBuffer(); buf.append("{"); //$NON-NLS-1$ for (int i = 0; i < max; ++i) { if (this.keyTable[i] != null) { buf.append(this.keyTable[i]).append("->").append(this.valueTable[i]); //$NON-NLS-1$ } if (i < max) { buf.append(", "); //$NON-NLS-1$ } } buf.append("}"); //$NON-NLS-1$ return buf.toString(); } }
/** * ConstantPool constructor comment. */ public ConstantPool(ClassFile classFile) { this.UTF8Cache = new CharArrayCache(UTF8_INITIAL_SIZE); this.stringCache = new CharArrayCache(STRING_INITIAL_SIZE); this.methodsAndFieldsCache = new HashtableOfObject(METHODS_AND_FIELDS_INITIAL_SIZE); this.classCache = new CharArrayCache(CLASS_INITIAL_SIZE); this.nameAndTypeCacheForFieldsAndMethods = new HashtableOfObject(NAMEANDTYPE_INITIAL_SIZE); this.offsets = new int[5]; initialize(classFile); } public void initialize(ClassFile givenClassFile) {
index = entry.index; } else { CharArrayCache charArrayCache = new CharArrayCache(); charArrayCache.putIfAbsent(entry.signature, entry.index); index = charArrayCache.putIfAbsent(key2, value); this.nameAndTypeCacheForFieldsAndMethods.put(key1, charArrayCache); index = charArrayCache.putIfAbsent(key2, value);
/** * Puts the specified element into the hashtable, using the specified * key. The element may be retrieved by doing a get() with the same key. * The key and the element cannot be null. * * @param key <CODE>Object</CODE> the specified key in the hashtable * @param value <CODE>int</CODE> the specified element * @return int the old value of the key, or -1 if it did not have one. */ private int put(char[] key, int value) { int length = this.keyTable.length, index = CharOperation.hashCode(key) % length; while (this.keyTable[index] != null) { if (CharOperation.equals(this.keyTable[index], key)) return this.valueTable[index] = value; if (++index == length) { // faster than modulo index = 0; } } this.keyTable[index] = key; this.valueTable[index] = value; // assumes the threshold is never equal to the size of the table if (++this.elementSize > this.threshold) rehash(); return value; } /**
public int literalIndexForType(final char[] constantPoolName) { int index; if ((index = this.classCache.putIfAbsent(constantPoolName, this.currentIndex)) < 0) { // The entry doesn't exit yet this.currentIndex++; if ((index = -index) > 0xFFFF){ this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType()); } int length = this.offsets.length; if (length <= index) { // resize System.arraycopy(this.offsets, 0, (this.offsets = new int[index * 2]), 0, length); } this.offsets[index] = this.currentOffset; writeU1(ClassTag); // Then the name index int nameIndexOffset = this.currentOffset; if (this.currentOffset + 2 >= this.poolContent.length) { resizePoolContents(2); } this.currentOffset+=2; final int nameIndex = literalIndex(constantPoolName); this.poolContent[nameIndexOffset++] = (byte) (nameIndex >> 8); this.poolContent[nameIndexOffset] = (byte) nameIndex; } return index; } /*
public void reset() { if (this.doubleCache != null) this.doubleCache.clear(); if (this.floatCache != null) this.floatCache.clear(); if (this.intCache != null) this.intCache.clear(); if (this.longCache != null) this.longCache.clear(); this.UTF8Cache.clear(); this.stringCache.clear(); this.methodsAndFieldsCache.clear(); this.classCache.clear(); this.packageCache.clear(); this.moduleCache.clear(); this.nameAndTypeCacheForFieldsAndMethods.clear(); this.dynamicCache.clear(); this.currentIndex = 1; this.currentOffset = 0; } }
/** * Converts to a rather lengthy String. * * return String the ascii representation of the receiver */ public String toString() { int max = size(); StringBuffer buf = new StringBuffer(); buf.append("{"); //$NON-NLS-1$ for (int i = 0; i < max; ++i) { if (this.keyTable[i] != null) { buf.append(this.keyTable[i]).append("->").append(this.valueTable[i]); //$NON-NLS-1$ } if (i < max) { buf.append(", "); //$NON-NLS-1$ } } buf.append("}"); //$NON-NLS-1$ return buf.toString(); } }
/** * ConstantPool constructor comment. */ public ConstantPool(ClassFile classFile) { this.UTF8Cache = new CharArrayCache(UTF8_INITIAL_SIZE); this.stringCache = new CharArrayCache(STRING_INITIAL_SIZE); this.methodsAndFieldsCache = new HashtableOfObject(METHODS_AND_FIELDS_INITIAL_SIZE); this.classCache = new CharArrayCache(CLASS_INITIAL_SIZE); this.nameAndTypeCacheForFieldsAndMethods = new HashtableOfObject(NAMEANDTYPE_INITIAL_SIZE); this.offsets = new int[5]; initialize(classFile); } public void initialize(ClassFile givenClassFile) {
/** * Rehashes the content of the table into a bigger table. * This method is called automatically when the hashtable's * size exceeds the threshold. */ private void rehash() { CharArrayCache newHashtable = new CharArrayCache(this.keyTable.length * 2); for (int i = this.keyTable.length; --i >= 0;) if (this.keyTable[i] != null) newHashtable.put(this.keyTable[i], this.valueTable[i]); this.keyTable = newHashtable.keyTable; this.valueTable = newHashtable.valueTable; this.threshold = newHashtable.threshold; } /** Remove the object associated with the specified key in the
/** * Puts the specified element into the hashtable if it wasn't there already, * using the specified key. The element may be retrieved by doing a get() with the same key. * The key and the element cannot be null. * * @param key the given key in the hashtable * @param value the given value * @return int the old value of the key, or -value if it did not have one. */ public int putIfAbsent(char[] key, int value) { int length = this.keyTable.length, index = CharOperation.hashCode(key) % length; while (this.keyTable[index] != null) { if (CharOperation.equals(this.keyTable[index], key)) return this.valueTable[index]; if (++index == length) { // faster than modulo index = 0; } } this.keyTable[index] = key; this.valueTable[index] = value; // assumes the threshold is never equal to the size of the table if (++this.elementSize > this.threshold) rehash(); return -value; // negative when added (value is assumed to be > 0) }
public int literalIndexForType(final char[] constantPoolName) { int index; if ((index = this.classCache.putIfAbsent(constantPoolName, this.currentIndex)) < 0) { // The entry doesn't exit yet this.currentIndex++; if ((index = -index) > 0xFFFF){ this.classFile.referenceBinding.scope.problemReporter().noMoreAvailableSpaceInConstantPool(this.classFile.referenceBinding.scope.referenceType()); } int length = this.offsets.length; if (length <= index) { // resize System.arraycopy(this.offsets, 0, (this.offsets = new int[index * 2]), 0, length); } this.offsets[index] = this.currentOffset; writeU1(ClassTag); // Then the name index int nameIndexOffset = this.currentOffset; if (this.currentOffset + 2 >= this.poolContent.length) { resizePoolContents(2); } this.currentOffset+=2; final int nameIndex = literalIndex(constantPoolName); this.poolContent[nameIndexOffset++] = (byte) (nameIndex >> 8); this.poolContent[nameIndexOffset] = (byte) nameIndex; } return index; } /*
/** * INTERNAL USE-ONLY * This methods returns a char[] representing the file name of the receiver * * @return char[] */ public char[] fileName() { return this.constantPool.UTF8Cache.returnKeyFor(2); }
public void reset() { if (this.doubleCache != null) this.doubleCache.clear(); if (this.floatCache != null) this.floatCache.clear(); if (this.intCache != null) this.intCache.clear(); if (this.longCache != null) this.longCache.clear(); this.UTF8Cache.clear(); this.stringCache.clear(); this.methodsAndFieldsCache.clear(); this.classCache.clear(); this.nameAndTypeCacheForFieldsAndMethods.clear(); this.currentIndex = 1; this.currentOffset = 0; } public void resetForAttributeName(char[] attributeName, int constantPoolIndex, int constantPoolOffset) {