Skip to content

Commit 261c9a7

Browse files
committed
hoist jumptable nil-check out of the interpreter loop
1 parent e699f5b commit 261c9a7

33 files changed

Lines changed: 1352 additions & 371 deletions

File tree

core/vm/interpreter.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,11 @@ func (in *CVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
201201
}
202202

203203
var (
204-
op OpCode // current opcode
205-
mem = NewMemory() // bound memory
206-
stack = newstack() // local stack
207-
scope = &ScopeContext{
204+
op OpCode // current opcode
205+
jumpTable *JumpTable = in.table
206+
mem = NewMemory() // bound memory
207+
stack = newstack() // local stack
208+
callContext = &ScopeContext{
208209
Memory: mem,
209210
Stack: stack,
210211
Contract: contract,
@@ -235,9 +236,9 @@ func (in *CVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
235236
defer func() {
236237
if err != nil {
237238
if !logged {
238-
in.cvm.Config().Tracer.CaptureState(pcCopy, op, gasCopy, cost, scope, in.returnData, in.cvm.depth, err)
239+
in.cvm.Config().Tracer.CaptureState(pcCopy, op, gasCopy, cost, callContext, in.returnData, in.cvm.depth, err)
239240
} else {
240-
in.cvm.Config().Tracer.CaptureFault(pcCopy, op, gasCopy, cost, scope, in.cvm.depth, err)
241+
in.cvm.Config().Tracer.CaptureFault(pcCopy, op, gasCopy, cost, callContext, in.cvm.depth, err)
241242
}
242243
}
243244
}()
@@ -252,6 +253,7 @@ func (in *CVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
252253
}
253254
cgas := uint64(0)
254255
//for atomic.LoadInt32(&in.cvm.abort) == 0 {
256+
_ = jumpTable[0] // nil-check the jumpTable out of the loop
255257
for {
256258
if debug {
257259
// Capture pre-execution values for tracing.
@@ -261,7 +263,7 @@ func (in *CVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
261263
// Get the operation from the jump table and validate the stack to ensure there are
262264
// enough stack items available to perform the operation.
263265
op = contract.GetOp(pc)
264-
operation := in.table[op]
266+
operation := jumpTable[op]
265267
//if operation == nil {
266268
// return nil, fmt.Errorf("invalid opcode 0x%x", int(op))
267269
//}
@@ -329,7 +331,7 @@ func (in *CVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
329331
}
330332

331333
if debug {
332-
in.cvm.Config().Tracer.CaptureState(pc, op, gasCopy, cost, scope, in.returnData, in.cvm.depth, err)
334+
in.cvm.Config().Tracer.CaptureState(pc, op, gasCopy, cost, callContext, in.returnData, in.cvm.depth, err)
333335
logged = true
334336
}
335337

@@ -338,7 +340,7 @@ func (in *CVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
338340
}
339341

340342
// execute the operation
341-
ret, err = operation.execute(&pc, in, scope)
343+
ret, err = operation.execute(&pc, in, callContext)
342344
if in.cvm.Config().RPC_GetInternalTransaction {
343345
if op == CALL {
344346
res = append(res, ret...)

go.mod

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.6.1
77
github.com/CortexFoundation/inference v1.0.2-0.20230307032835-9197d586a4e8
88
github.com/CortexFoundation/statik v0.0.0-20210315012922-8bb8a7b5dc66
9-
github.com/CortexFoundation/torrentfs v1.0.69-0.20250624130554-3907c8c961de
9+
github.com/CortexFoundation/torrentfs v1.0.70-0.20250705184717-83e763fd9aef
1010
github.com/VictoriaMetrics/fastcache v1.12.5
1111
github.com/arsham/figurine v1.3.0
1212
github.com/aws/aws-sdk-go-v2 v1.36.5
@@ -50,7 +50,7 @@ require (
5050
github.com/muesli/reflow v0.3.0
5151
github.com/muesli/termenv v0.16.0
5252
github.com/naoina/toml v0.1.2-0.20170918210437-9fafd6967416
53-
github.com/olekukonko/tablewriter v1.0.7
53+
github.com/olekukonko/tablewriter v1.0.8
5454
github.com/peterh/liner v1.2.2
5555
github.com/pion/stun/v2 v2.0.0
5656
github.com/rs/cors v1.11.1
@@ -149,7 +149,7 @@ require (
149149
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
150150
github.com/fatih/color v1.18.0 // indirect
151151
github.com/garslo/gogen v0.0.0-20170306192744-1d203ffc1f61 // indirect
152-
github.com/getsentry/sentry-go v0.34.0 // indirect
152+
github.com/getsentry/sentry-go v0.34.1 // indirect
153153
github.com/go-llsqlite/adapter v0.2.0 // indirect
154154
github.com/go-llsqlite/crawshaw v0.6.0 // indirect
155155
github.com/go-logr/logr v1.4.3 // indirect
@@ -224,7 +224,7 @@ require (
224224
github.com/spaolacci/murmur3 v1.1.0 // indirect
225225
github.com/steakknife/hamming v0.0.0-20180906055917-c99c65617cd3 // indirect
226226
github.com/supranational/blst v0.3.15 // indirect
227-
github.com/tidwall/btree v1.7.0 // indirect
227+
github.com/tidwall/btree v1.8.0 // indirect
228228
github.com/tidwall/hashmap v1.8.1 // indirect
229229
github.com/tklauser/go-sysconf v0.3.15 // indirect
230230
github.com/tklauser/numcpus v0.10.0 // indirect
@@ -234,7 +234,7 @@ require (
234234
github.com/ucwong/shard v1.0.1-0.20250426172507-f1db2901f62c // indirect
235235
github.com/wlynxg/anet v0.0.5 // indirect
236236
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
237-
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
237+
github.com/xrash/smetrics v0.0.0-20250705151800-55b8f293f342 // indirect
238238
github.com/xujiajun/mmap-go v1.0.1 // indirect
239239
github.com/xujiajun/utils v0.0.0-20220904132955-5f7c5b914235 // indirect
240240
github.com/yusufpapurcu/wmi v1.2.4 // indirect

go.sum

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ github.com/CortexFoundation/statik v0.0.0-20210315012922-8bb8a7b5dc66/go.mod h1:
7070
github.com/CortexFoundation/torrentfs v1.0.13-0.20200623060705-ce027f43f2f8/go.mod h1:Ma+tGhPPvz4CEZHaqEJQMOEGOfHeQBiAoNd1zyc/w3Q=
7171
github.com/CortexFoundation/torrentfs v1.0.14-0.20200703071639-3fcabcabf274/go.mod h1:qnb3YlIJmuetVBtC6Lsejr0Xru+1DNmDCdTqnwy7lhk=
7272
github.com/CortexFoundation/torrentfs v1.0.20-0.20200810031954-d36d26f82fcc/go.mod h1:N5BsicP5ynjXIi/Npl/SRzlJ630n1PJV2sRj0Z0t2HA=
73-
github.com/CortexFoundation/torrentfs v1.0.69-0.20250624130554-3907c8c961de h1:Kmr75lnqQQRsJm7eMw7yACLKiLD9QjRfabjv51Ao7Vg=
74-
github.com/CortexFoundation/torrentfs v1.0.69-0.20250624130554-3907c8c961de/go.mod h1:2kPs5QtFTkHKQz/VKUN0qzRHKSGucudGcEIEvRhmH/g=
73+
github.com/CortexFoundation/torrentfs v1.0.70-0.20250705184717-83e763fd9aef h1:Omnrs5UisVld4p7CE3x3sP3h791FWfnc7W5jP8bK2b8=
74+
github.com/CortexFoundation/torrentfs v1.0.70-0.20250705184717-83e763fd9aef/go.mod h1:2kPs5QtFTkHKQz/VKUN0qzRHKSGucudGcEIEvRhmH/g=
7575
github.com/CortexFoundation/wormhole v0.0.2-0.20241128010855-a23c88842cfa h1:46VAGWxOwpoLlPNcR9etAhK0NtT215skO9Wl4i14r4o=
7676
github.com/CortexFoundation/wormhole v0.0.2-0.20241128010855-a23c88842cfa/go.mod h1:ipzmPabDgzYKUbXkGVe2gTkBEp+MsDx6pXGiuYzmP6s=
7777
github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
@@ -492,8 +492,8 @@ github.com/garslo/gogen v0.0.0-20170306192744-1d203ffc1f61/go.mod h1:Q0X6pkwTILD
492492
github.com/garyburd/redigo v1.6.0/go.mod h1:NR3MbYisc3/PwhQ00EMzDiPmrwpPxAn5GI05/YaO1SY=
493493
github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08 h1:f6D9Hr8xV8uYKlyuj8XIruxlh9WjVjdh1gIicAS7ays=
494494
github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08/go.mod h1:x7DCsMOv1taUwEWCzT4cmDeAkigA5/QCwUodaVOe8Ww=
495-
github.com/getsentry/sentry-go v0.34.0 h1:1FCHBVp8TfSc8L10zqSwXUZNiOSF+10qw4czjarTiY4=
496-
github.com/getsentry/sentry-go v0.34.0/go.mod h1:C55omcY9ChRQIUcVcGcs+Zdy4ZpQGvNJ7JYHIoSWOtE=
495+
github.com/getsentry/sentry-go v0.34.1 h1:HSjc1C/OsnZttohEPrrqKH42Iud0HuLCXpv8cU1pWcw=
496+
github.com/getsentry/sentry-go v0.34.1/go.mod h1:C55omcY9ChRQIUcVcGcs+Zdy4ZpQGvNJ7JYHIoSWOtE=
497497
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
498498
github.com/gliderlabs/ssh v0.1.1/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
499499
github.com/glycerine/go-unsnap-stream v0.0.0-20180323001048-9f0cb55181dd/go.mod h1:/20jfyN9Y5QPEAprSgKAUr+glWDY39ZiUEAYOEv5dsE=
@@ -900,8 +900,8 @@ github.com/olekukonko/ll v0.0.9/go.mod h1:En+sEW0JNETl26+K8eZ6/W4UQ7CYSrrgg/EdIY
900900
github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo=
901901
github.com/olekukonko/tablewriter v0.0.4/go.mod h1:zq6QwlOf5SlnkVbMSr5EoBv3636FWnp+qbPhuoO21uA=
902902
github.com/olekukonko/tablewriter v0.0.5-0.20200416053754-163badb3bac6/go.mod h1:zq6QwlOf5SlnkVbMSr5EoBv3636FWnp+qbPhuoO21uA=
903-
github.com/olekukonko/tablewriter v1.0.7 h1:HCC2e3MM+2g72M81ZcJU11uciw6z/p82aEnm4/ySDGw=
904-
github.com/olekukonko/tablewriter v1.0.7/go.mod h1:H428M+HzoUXC6JU2Abj9IT9ooRmdq9CxuDmKMtrOCMs=
903+
github.com/olekukonko/tablewriter v1.0.8 h1:f6wJzHg4QUtJdvrVPKco4QTrAylgaU0+b9br/lJxEiQ=
904+
github.com/olekukonko/tablewriter v1.0.8/go.mod h1:H428M+HzoUXC6JU2Abj9IT9ooRmdq9CxuDmKMtrOCMs=
905905
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
906906
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
907907
github.com/onsi/ginkgo v1.10.1/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
@@ -1210,8 +1210,8 @@ github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d/go.mod h1:RRCYJ
12101210
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA=
12111211
github.com/templexxx/cpufeat v0.0.0-20180724012125-cef66df7f161/go.mod h1:wM7WEvslTq+iOEAMDLSzhVuOt5BRZ05WirO+b09GHQU=
12121212
github.com/templexxx/xor v0.0.0-20191217153810-f85b25db303b/go.mod h1:5XA7W9S6mni3h5uvOC75dA3m9CCCaS83lltmc0ukdi4=
1213-
github.com/tidwall/btree v1.7.0 h1:L1fkJH/AuEh5zBnnBbmTwQ5Lt+bRJ5A8EWecslvo9iI=
1214-
github.com/tidwall/btree v1.7.0/go.mod h1:twD9XRA5jj9VUQGELzDO4HPQTNJsoWWfYEL+EUQ2cKY=
1213+
github.com/tidwall/btree v1.8.0 h1:kHHy8hSBauQUe0KPHMFLOt0olAj1nDnkHPJhr8+HFkM=
1214+
github.com/tidwall/btree v1.8.0/go.mod h1:jBbTdUWhSZClZWoDg54VnvV7/54modSOzDN7VXftj1A=
12151215
github.com/tidwall/hashmap v1.8.1 h1:hXNzBfSJ2Jwvt0lbkWD59O/r3OfatSIcbuWT0VKEVns=
12161216
github.com/tidwall/hashmap v1.8.1/go.mod h1:v+0qJrJn7l+l2dB8+fAFpC62p2G0SMP2Teu8ejkebg8=
12171217
github.com/tinylib/msgp v1.0.2/go.mod h1:+d+yLhGm8mzTaHzB+wgMYrodPfmZrzkirds8fDWklFE=
@@ -1270,8 +1270,8 @@ github.com/xlab/treeprint v0.0.0-20180616005107-d6fb6747feb6/go.mod h1:ce1O1j6Ut
12701270
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
12711271
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
12721272
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
1273-
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4=
1274-
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
1273+
github.com/xrash/smetrics v0.0.0-20250705151800-55b8f293f342 h1:FnBeRrxr7OU4VvAzt5X7s6266i6cSVkkFPS0TuXWbIg=
1274+
github.com/xrash/smetrics v0.0.0-20250705151800-55b8f293f342/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
12751275
github.com/xtaci/kcp-go v5.4.20+incompatible/go.mod h1:bN6vIwHQbfHaHtFpEssmWsN45a+AZwO7eyRCmEIbtvE=
12761276
github.com/xtaci/lossyconn v0.0.0-20190602105132-8df528c0c9ae/go.mod h1:gXtu8J62kEgmN++bm9BVICuT/e8yiLI2KFobd/TRFsE=
12771277
github.com/xujiajun/mmap-go v1.0.1 h1:7Se7ss1fLPPRW+ePgqGpCkfGIZzJV6JPq9Wq9iv/WHc=

vendor/github.com/CortexFoundation/torrentfs/README.md

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/getsentry/sentry-go/CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/getsentry/sentry-go/batch_logger.go

Lines changed: 49 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/getsentry/sentry-go/client.go

Lines changed: 12 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/getsentry/sentry-go/scope.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/getsentry/sentry-go/sentry.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/getsentry/sentry-go/transport.go

Lines changed: 6 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)