Small issues with Dict (dict.cpp, dict2.cpp)
Thomas Stüfe
thomas.stuefe at gmail.com
Tue Apr 1 13:11:07 UTC 2014
Hello,
I see some smallish issues in the "Dict" class which can be found
share/vm/libadt/dict.cpp and in slightly different form in
share/vm/adlc/dict2.cpp.
Nothing major, and of course I may be wrong...
1) Dict &Dict::operator =( const Dict &d ):
...
if( _size < d._size ) { // If must have more buckets
_arena = d._arena;
_bin = (bucket*)_arena->Arealloc( _bin, sizeof(bucket)*_size,
sizeof(bucket)*d._size );
memset( &_bin[_size], 0, (d._size-_size)*sizeof(bucket) );
_size = d._size;
}
Both Arealloc and memset seem pointless to me, as the buckets are cleared
anyway below.
Also, we leak the old content if the arena is different - we could at least
attempt to Afree() the old bucket list in the old arena.
2) void *Dict::Delete(void *key) :
...
b->_cnt--; // Remove key/value from lo bucket
b->_keyvals[j+j ] = b->_keyvals[b->_cnt+b->_cnt ];
b->_keyvals[j+j+1] = b->_keyvals[b->_cnt+b->_cnt+1];
if bucket only had one entry (hopefully the rule, if hash works well),
the copying is unnecessary.
3) int32 Dict::operator ==(const Dict &d2) const
This uses memcmp to compare buckets, so it depends on the order of bucket
list entries; I am not sure this was intended.
I also did not find any use for these methods, are they actually used
somewhere?
Kind Regards,
Thomas Stüfe
More information about the hotspot-dev
mailing list