8323900: Avoid calling os::init_random() in CDS static dump
Reviewed-by: stuefe, ccheung
This commit is contained in:
parent
cd4c3aac63
commit
2fe2f3aff8
src/hotspot/share
@ -39,6 +39,7 @@
|
||||
#include "classfile/systemDictionaryShared.hpp"
|
||||
#include "classfile/vmClasses.hpp"
|
||||
#include "interpreter/abstractInterpreter.hpp"
|
||||
#include "jvm.h"
|
||||
#include "logging/log.hpp"
|
||||
#include "logging/logStream.hpp"
|
||||
#include "memory/allStatic.hpp"
|
||||
@ -170,7 +171,7 @@ ArchiveBuilder::ArchiveBuilder() :
|
||||
{
|
||||
_klasses = new (mtClassShared) GrowableArray<Klass*>(4 * K, mtClassShared);
|
||||
_symbols = new (mtClassShared) GrowableArray<Symbol*>(256 * K, mtClassShared);
|
||||
|
||||
_entropy_seed = 0x12345678;
|
||||
assert(_current == nullptr, "must be");
|
||||
_current = this;
|
||||
}
|
||||
@ -190,6 +191,16 @@ ArchiveBuilder::~ArchiveBuilder() {
|
||||
}
|
||||
}
|
||||
|
||||
// Returns a deterministic sequence of pseudo random numbers. The main purpose is NOT
|
||||
// for randomness but to get good entropy for the identity_hash() of archived Symbols,
|
||||
// while keeping the contents of static CDS archives deterministic to ensure
|
||||
// reproducibility of JDK builds.
|
||||
int ArchiveBuilder::entropy() {
|
||||
assert(SafepointSynchronize::is_at_safepoint(), "needed to ensure deterministic sequence");
|
||||
_entropy_seed = os::next_random(_entropy_seed);
|
||||
return static_cast<int>(_entropy_seed);
|
||||
}
|
||||
|
||||
class GatherKlassesAndSymbols : public UniqueMetaspaceClosure {
|
||||
ArchiveBuilder* _builder;
|
||||
|
||||
|
@ -219,6 +219,7 @@ private:
|
||||
ResizeableResourceHashtable<address, address, AnyObj::C_HEAP, mtClassShared> _buffered_to_src_table;
|
||||
GrowableArray<Klass*>* _klasses;
|
||||
GrowableArray<Symbol*>* _symbols;
|
||||
unsigned int _entropy_seed;
|
||||
|
||||
// statistics
|
||||
DumpAllocStats _alloc_stats;
|
||||
@ -341,6 +342,7 @@ public:
|
||||
ArchiveBuilder();
|
||||
~ArchiveBuilder();
|
||||
|
||||
int entropy();
|
||||
void gather_klasses_and_symbols();
|
||||
void gather_source_objs();
|
||||
bool gather_klass_and_symbol(MetaspaceClosure::Ref* ref, bool read_only);
|
||||
|
@ -513,9 +513,6 @@ void VM_PopulateDumpSharedSpace::doit() {
|
||||
|
||||
char* cloned_vtables = CppVtables::dumptime_init(&builder);
|
||||
|
||||
// Initialize random for updating the hash of symbols
|
||||
os::init_random(0x12345678);
|
||||
|
||||
builder.dump_rw_metadata();
|
||||
builder.dump_ro_metadata();
|
||||
builder.relocate_metaspaceobj_embedded_pointers();
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -23,6 +23,7 @@
|
||||
*/
|
||||
|
||||
#include "precompiled.hpp"
|
||||
#include "cds/archiveBuilder.hpp"
|
||||
#include "cds/metaspaceShared.hpp"
|
||||
#include "classfile/altHashing.hpp"
|
||||
#include "classfile/classLoaderData.hpp"
|
||||
@ -73,11 +74,8 @@ Symbol::Symbol(const Symbol& s1) {
|
||||
|
||||
#if INCLUDE_CDS
|
||||
void Symbol::update_identity_hash() {
|
||||
// This is called at a safepoint during dumping of a static CDS archive. The caller should have
|
||||
// called os::init_random() with a deterministic seed and then iterate all archived Symbols in
|
||||
// a deterministic order.
|
||||
assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint");
|
||||
_hash_and_refcount = pack_hash_and_refcount((short)os::random(), PERM_REFCOUNT);
|
||||
_hash_and_refcount = pack_hash_and_refcount((short)ArchiveBuilder::current()->entropy(), PERM_REFCOUNT);
|
||||
}
|
||||
|
||||
void Symbol::set_permanent() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user