On Thu, 21 Sep 2023 06:21:13 GMT, Axel Boldt-Christmas <abold...@openjdk.org> wrote:
>> `inUseList` will end up with the same value as `inUseListHead`. The reason >> the old code worked is because `getAddressField` does not type check and >> `reinterpret_cast<addres>(&ObjectSynchronizer::_in_use_list) == >> reinterpret_cast<addres>(&ObjectSynchronizer::_in_use_list._head)` >> >> Effectively I changed this to load it correctly (regardless of what >> `offset_of(MonitorList, _head)` ends up being) and name the variables more >> appropriately. >> >> C++ interpretation of what the java change does: >> ```C++ >> // Old code >> // Type type = db.lookupType("ObjectSynchronizer"); >> // inUseList = type.getAddressField("_in_use_list").getValue(); >> address inUseList = >> *(reinterpret_cast<address*>(&ObjectSynchronizer::_in_use_list)); >> >> // New code >> // Type objectSynchronizerType = db.lookupType("ObjectSynchronizer"); >> // Type monitorListType = db.lookupType("MonitorList"); >> // Address monitorListAddr = >> objectSynchronizerType.getField("_in_use_list").getStaticFieldAddress(); >> // inUseListHead = >> monitorListType.getAddressField("_head").getAddress(monitorListAddr); >> address monitorListAddr = >> reinterpret_cast<address>(&ObjectSynchronizer::_in_use_list); >> address inUseList = *(reinterpret_cast<address*>(monitorListAddr + >> offset_of(MonitorList, _head))); > > Just to clarify what might cause confusion (at least it is what confused me > at first when I read this code) is that `getAddress()`/ > `getAddressField(...).getValue()` does not return the address of the field. > It returns the value of the field (loaded and) interpreted as an address. I see now. _in_use_list is a MonitorList (not a pointer to one) and the first field of a MonitorList is the _head field. So that means the address of the _in_use_list field is also the address of the _head field. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/15782#discussion_r1333390292