On Mon, 17 Jul 2023 17:14:01 GMT, Ioi Lam <ik...@openjdk.org> wrote: >> Currently we exit the VM after static dumping with >> `MetaspaceShared::exit_after_static_dump()`. >> >> >> // We have finished dumping the static archive. At this point, there may be >> pending VM >> // operations. We have changed some global states (such as >> vmClasses::_klasses) that >> // may cause these VM operations to fail. For safety, forget these >> operations and >> // exit the VM directly. >> void MetaspaceShared::exit_after_static_dump() { >> os::_exit(0); >> } >> >> >> As the comment suggests, the VM state is altered when preparing and >> performing the static dump, so this change aims to prevent these state >> changes so the VM can exit normally after the static dump completes. There >> are three major aspects to this change: >> 1. Since the resolved references array in the Constant Pool is altered when >> preparing for a static dump, a "scratch copy" is created and archived >> instead >> 2. Symbols are sorted by address and have their hash recalculated. Similarly >> to point 1, the copies of the symbols that are to be archived have their >> hashes updated as opposed to the originals. >> 3. The handling of -Xshare:dump during argument parsing such that the VM can >> continue and exit normally with an exit code of 0. > > src/hotspot/share/cds/heapShared.hpp line 288: > >> 286: 36137, // prime number >> 287: AnyObj::C_HEAP, >> 288: mtClassShared> ResolvedReferenceScratchTable; > > You are using `oop->identity_hash()` as the key for this table. However, it's > possible for two `resolved_references` arrays to have the exact same > identity. It's better to to use `ResourceHashtable<OopHandle, OopHandle, ...` > for this table. Then, you need to define two custom functions for these two > parameters for `ResourceHashtable` > > > unsigned (*HASH) (K const&), > bool (*EQUALS)(K const&, K const&) > > where the `K` type is `OopHandle`. > > The `HASH` function can return `OopHandle::resolve()->identity_hash()` and > the `EQUALS` function can compare the values of `OopHandle::resolve()`. > > For the coding style, you can search for tables that use > `HeapShared::oop_hash` for examples.
Actually, using `Oophandle` is too complicated. You can just use the `ConstantPool*` as the key, since each original `resolved_references` array is associated with a unique `ConstantPool*`. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/14879#discussion_r1265941938