--- old/src/hotspot/share/oops/symbol.cpp 2020-04-26 22:07:12.544264009 -0700 +++ new/src/hotspot/share/oops/symbol.cpp 2020-04-26 22:07:12.412259040 -0700 @@ -56,6 +56,17 @@ } void* Symbol::operator new(size_t sz, int len) throw() { + if (DumpSharedSpaces) { + // To get deterministic output from -Xshare:dump, we ensure that Symbols are allocated in + // increasing adresses. When the symbols are copied into the archive, we preserve their + // relative address order (see SortedSymbolClosure in metaspaceShared.cpp) + // + // We cannot use arena because arena chunks are allocated by the OS. As a result, for example, + // the archived symbol of "java/lang/Object" may sometimes be lower than "java/lang/String", and + // sometimes be higher. This would cause non-deterministic contents in the archive. + return Metaspace::allocate(ClassLoaderData::the_null_class_loader_data(), + size(len), MetaspaceObj::ClassType, Thread::current()); + } int alloc_size = size(len)*wordSize; address res = (address) AllocateHeap(alloc_size, mtSymbol); return res;