8249087: Always initialize _body[0..1] in Symbol constructor

Reviewed-by: dholmes, lfoltan
This commit is contained in:
Ioi Lam 2020-07-24 13:56:45 -07:00
parent 831e98327b
commit 112bbcb396

View file

@ -51,7 +51,12 @@ uint32_t Symbol::pack_hash_and_refcount(short hash, int refcount) {
Symbol::Symbol(const u1* name, int length, int refcount) {
_hash_and_refcount = pack_hash_and_refcount((short)os::random(), refcount);
_length = length;
_body[0] = 0; // in case length == 0
// _body[0..1] are allocated in the header just by coincidence in the current
// implementation of Symbol. They are read by identity_hash(), so make sure they
// are initialized.
// No other code should assume that _body[0..1] are always allocated. E.g., do
// not unconditionally read base()[0] as that will be invalid for an empty Symbol.
_body[0] = _body[1] = 0;
memcpy(_body, name, length);
}