From a26bfb259835dc1115db08bc06a7ac4536c2bccc Mon Sep 17 00:00:00 2001 From: Sunny Date: Wed, 21 Feb 2024 09:57:11 +0800 Subject: [PATCH] no load --- core/vm/compiler/OpCodeCache.go | 19 +++++++------------ core/vm/opcodeProcessor.go | 3 +++ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/core/vm/compiler/OpCodeCache.go b/core/vm/compiler/OpCodeCache.go index b01e79b61a..43cf9348b7 100644 --- a/core/vm/compiler/OpCodeCache.go +++ b/core/vm/compiler/OpCodeCache.go @@ -11,7 +11,7 @@ import ( const CodeCacheGCThreshold = 1024 * 1024 * 1024 /* 1 GB */ // CodeCacheGCSoftLimit is used to trigger GC for memory control. // upper limit of bytecodes of smart contract is ~25MB. -const CodeCacheGCSoftLimit = 2 * 1024 * 1024 /* 2MB */ +const CodeCacheGCSoftLimit = 200 * 1024 * 1024 /* 200MB */ type OptCode []byte @@ -69,7 +69,7 @@ func (c *OpCodeCache) UpdateCodeCache(address common.Address, code OptCode, code c.codeCacheSize = 0 } if c.opcodesCache[address] == nil { - c.opcodesCache[address] = make(map[common.Hash]OptCode, 3) + c.opcodesCache[address] = make(map[common.Hash]OptCode) } c.opcodesCache[address][codeHash] = code c.codeCacheSize += uint64(len(code)) @@ -98,18 +98,13 @@ func (c *OpCodeCache) GetValFromShlAndSubMap(x uint8, y uint8, z uint8) *uint256 var once sync.Once var opcodeCache *OpCodeCache -func newOpCodeCache() *OpCodeCache { - codeCache := new(OpCodeCache) - codeCache.opcodesCache = make(map[common.Address]map[common.Hash]OptCode, CodeCacheGCThreshold>>10) - codeCache.shlAndSubMap = make(map[ThreeU8Operands]*uint256.Int, 4096) - codeCache.codeCacheMutex = sync.RWMutex{} - opcodeCache = codeCache - return codeCache -} - func GetOpCodeCacheInstance() *OpCodeCache { once.Do(func() { - opcodeCache = newOpCodeCache() + opcodeCache = &OpCodeCache{ + opcodesCache: make(map[common.Address]map[common.Hash]OptCode, CodeCacheGCThreshold>>10), + shlAndSubMap: make(map[ThreeU8Operands]*uint256.Int, 4096), + codeCacheMutex: sync.RWMutex{}, + } }) return opcodeCache } diff --git a/core/vm/opcodeProcessor.go b/core/vm/opcodeProcessor.go index 5bfc7b66ca..e32fe032b3 100644 --- a/core/vm/opcodeProcessor.go +++ b/core/vm/opcodeProcessor.go @@ -19,6 +19,9 @@ type OpCodeProcessorConfig struct { } func GenOrLoadOptimizedCode(address common.Address, code []byte, codeHash common.Hash) (compiler.OptCode, bool, error) { + if len(code) != 0 { + return code, false, nil + } /* Try load from cache */ codeCache := compiler.GetOpCodeCacheInstance() // TODO-dav:The lock on the whole codecache is not optimal, consider use smaller granularity.