Skip to content

Commit

Permalink
no load
Browse files Browse the repository at this point in the history
  • Loading branch information
sunny2022da committed Feb 21, 2024
1 parent d28b0db commit a26bfb2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
19 changes: 7 additions & 12 deletions core/vm/compiler/OpCodeCache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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
}
3 changes: 3 additions & 0 deletions core/vm/opcodeProcessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit a26bfb2

Please sign in to comment.