diff --git a/core/vm/evm.go b/core/vm/evm.go index 59e301c0a7..579c81ed0a 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -140,7 +140,7 @@ func NewEVM(blockCtx BlockContext, statedb StateDB, chainConfig *params.ChainCon Config: config, chainConfig: chainConfig, chainRules: chainConfig.Rules(blockCtx.BlockNumber, blockCtx.Random != nil, blockCtx.Time), - jumpDests: newMapJumpDests(), + jumpDests: newGlobalJumpDests(), } evm.precompiles = activePrecompiledContracts(evm.chainRules) diff --git a/core/vm/jumpdests.go b/core/vm/jumpdests.go index 1a30c1943f..3c962fba77 100644 --- a/core/vm/jumpdests.go +++ b/core/vm/jumpdests.go @@ -16,7 +16,11 @@ package vm -import "github.com/ethereum/go-ethereum/common" +import ( + "sync" + + "github.com/ethereum/go-ethereum/common" +) // JumpDestCache represents the cache of jumpdest analysis results. type JumpDestCache interface { @@ -45,3 +49,26 @@ func (j mapJumpDests) Load(codeHash common.Hash) (BitVec, bool) { func (j mapJumpDests) Store(codeHash common.Hash, vec BitVec) { j[codeHash] = vec } + +// globalJumpDestCache is a global cache of JUMPDEST bitmaps. +var globalJumpDestCache sync.Map + +type globalJumpDests struct{} + +// newGlobalJumpDests returns a JumpDestCache backed by the process-global +// sync.Map. All callers share the same backing map. +func newGlobalJumpDests() JumpDestCache { + return globalJumpDests{} +} + +func (globalJumpDests) Load(codeHash common.Hash) (BitVec, bool) { + v, ok := globalJumpDestCache.Load(codeHash) + if !ok { + return nil, false + } + return v.(BitVec), true +} + +func (globalJumpDests) Store(codeHash common.Hash, vec BitVec) { + globalJumpDestCache.Store(codeHash, vec) +}