Skip to content

Commit 846f34f

Browse files
committed
core/vm, tests: implemented semi-jit vm
* changed stack and removed stack ptr. Let go decide on slice reuse.
1 parent 698e98d commit 846f34f

19 files changed

Lines changed: 1572 additions & 79 deletions

‎Makefile‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@
22
# with Go source code. If you know what GOPATH is then you probably
33
# don't need to bother with make.
44

5-
.PHONY: geth mist all test travis-test-with-coverage clean
5+
.PHONY: geth evm mist all test travis-test-with-coverage clean
66
GOBIN = build/bin
77

88
geth:
99
build/env.sh go install -v $(shell build/ldflags.sh) ./cmd/geth
1010
@echo "Done building."
1111
@echo "Run \"$(GOBIN)/geth\" to launch geth."
1212

13+
evm:
14+
build/env.sh $(GOROOT)/bin/go install -v $(shell build/ldflags.sh) ./cmd/evm
15+
@echo "Done building."
16+
@echo "Run \"$(GOBIN)/evm to start the evm."
1317
mist:
1418
build/env.sh go install -v $(shell build/ldflags.sh) ./cmd/mist
1519
@echo "Done building."

‎cmd/evm/main.go‎

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"github.com/ethereum/go-ethereum/core/types"
3333
"github.com/ethereum/go-ethereum/core/vm"
3434
"github.com/ethereum/go-ethereum/ethdb"
35+
"github.com/ethereum/go-ethereum/logger/glog"
3536
)
3637

3738
var (
@@ -40,6 +41,14 @@ var (
4041
Name: "debug",
4142
Usage: "output full trace logs",
4243
}
44+
ForceJitFlag = cli.BoolFlag{
45+
Name: "forcejit",
46+
Usage: "forces jit compilation",
47+
}
48+
DisableJitFlag = cli.BoolFlag{
49+
Name: "nojit",
50+
Usage: "disabled jit compilation",
51+
}
4352
CodeFlag = cli.StringFlag{
4453
Name: "code",
4554
Usage: "EVM code",
@@ -77,6 +86,8 @@ func init() {
7786
app = utils.NewApp("0.2", "the evm command line interface")
7887
app.Flags = []cli.Flag{
7988
DebugFlag,
89+
ForceJitFlag,
90+
DisableJitFlag,
8091
SysStatFlag,
8192
CodeFlag,
8293
GasFlag,
@@ -90,6 +101,10 @@ func init() {
90101

91102
func run(ctx *cli.Context) {
92103
vm.Debug = ctx.GlobalBool(DebugFlag.Name)
104+
vm.ForceJit = ctx.GlobalBool(ForceJitFlag.Name)
105+
vm.DisableJit = ctx.GlobalBool(DisableJitFlag.Name)
106+
107+
glog.SetToStderr(true)
93108

94109
db, _ := ethdb.NewMemDatabase()
95110
statedb := state.New(common.Hash{}, db)
@@ -110,11 +125,6 @@ func run(ctx *cli.Context) {
110125
)
111126
vmdone := time.Since(tstart)
112127

113-
if e != nil {
114-
fmt.Println(e)
115-
os.Exit(1)
116-
}
117-
118128
if ctx.GlobalBool(DumpFlag.Name) {
119129
fmt.Println(string(statedb.Dump()))
120130
}
@@ -133,7 +143,11 @@ num gc: %d
133143
`, mem.Alloc, mem.TotalAlloc, mem.Mallocs, mem.HeapAlloc, mem.HeapObjects, mem.NumGC)
134144
}
135145

136-
fmt.Printf("OUT: 0x%x\n", ret)
146+
fmt.Printf("OUT: 0x%x", ret)
147+
if e != nil {
148+
fmt.Printf(" error: %v", e)
149+
}
150+
fmt.Println()
137151
}
138152

139153
func main() {

‎cmd/geth/main.go‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,9 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso
307307
utils.ExecFlag,
308308
utils.WhisperEnabledFlag,
309309
utils.VMDebugFlag,
310+
utils.VMForceJitFlag,
311+
utils.VMJitCacheFlag,
312+
utils.VMEnableJitFlag,
310313
utils.NetworkIdFlag,
311314
utils.RPCCORSDomainFlag,
312315
utils.VerbosityFlag,

‎cmd/utils/flags.go‎

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"runtime"
2828
"strconv"
2929

30+
"github.com/ethereum/go-ethereum/core/vm"
3031
"github.com/ethereum/go-ethereum/metrics"
3132

3233
"github.com/codegangsta/cli"
@@ -172,6 +173,25 @@ var (
172173
Value: "",
173174
}
174175

176+
// vm flags
177+
VMDebugFlag = cli.BoolFlag{
178+
Name: "vmdebug",
179+
Usage: "Virtual Machine debug output",
180+
}
181+
VMForceJitFlag = cli.BoolFlag{
182+
Name: "forcejit",
183+
Usage: "Force the JIT VM to take precedence",
184+
}
185+
VMJitCacheFlag = cli.IntFlag{
186+
Name: "jitcache",
187+
Usage: "Amount of cached JIT VM programs",
188+
Value: 64,
189+
}
190+
VMEnableJitFlag = cli.BoolFlag{
191+
Name: "jitvm",
192+
Usage: "Enable the JIT VM",
193+
}
194+
175195
// logging and debug settings
176196
LogFileFlag = cli.StringFlag{
177197
Name: "logfile",
@@ -196,10 +216,6 @@ var (
196216
Usage: "The syntax of the argument is a comma-separated list of pattern=N, where pattern is a literal file name (minus the \".go\" suffix) or \"glob\" pattern and N is a log verbosity level.",
197217
Value: glog.GetVModule(),
198218
}
199-
VMDebugFlag = cli.BoolFlag{
200-
Name: "vmdebug",
201-
Usage: "Virtual Machine debug output",
202-
}
203219
BacktraceAtFlag = cli.GenericFlag{
204220
Name: "backtrace_at",
205221
Usage: "If set to a file and line number (e.g., \"block.go:271\") holding a logging statement, a stack trace will be logged",
@@ -434,6 +450,13 @@ func SetupLogger(ctx *cli.Context) {
434450
glog.SetLogDir(ctx.GlobalString(LogFileFlag.Name))
435451
}
436452

453+
// SetupVM configured the VM package's global settings
454+
func SetupVM(ctx *cli.Context) {
455+
vm.DisableJit = !ctx.GlobalBool(VMEnableJitFlag.Name)
456+
vm.ForceJit = ctx.GlobalBool(VMForceJitFlag.Name)
457+
vm.SetJITCacheSize(ctx.GlobalInt(VMJitCacheFlag.Name))
458+
}
459+
437460
// MakeChain creates a chain manager from set command line flags.
438461
func MakeChain(ctx *cli.Context) (chain *core.ChainManager, blockDB, stateDB, extraDB common.Database) {
439462
datadir := ctx.GlobalString(DataDirFlag.Name)

‎core/block_processor.go‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ func (sm *BlockProcessor) TransitionState(statedb *state.StateDB, parent, block
8484
}
8585

8686
func (self *BlockProcessor) ApplyTransaction(coinbase *state.StateObject, statedb *state.StateDB, header *types.Header, tx *types.Transaction, usedGas *big.Int, transientProcess bool) (*types.Receipt, *big.Int, error) {
87-
// If we are mining this block and validating we want to set the logs back to 0
88-
8987
cb := statedb.GetStateObject(coinbase.Address())
9088
_, gas, err := ApplyMessage(NewEnv(statedb, self.bc, tx, header), tx, cb)
9189
if err != nil {

‎core/chain_manager.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ func (self *ChainManager) InsertChain(chain types.Blocks) (int, error) {
632632
switch status {
633633
case CanonStatTy:
634634
if glog.V(logger.Debug) {
635-
glog.Infof("[%v] inserted block #%d (%d TXs %d UNCs) (%x...). Took %v\n", time.Now().UnixNano(), block.Number(), len(block.Transactions()), len(block.Uncles()), block.Hash().Bytes()[0:4], time.Since(bstart))
635+
glog.Infof("[%v] inserted block #%d (%d TXs %v G %d UNCs) (%x...). Took %v\n", time.Now().UnixNano(), block.Number(), len(block.Transactions()), block.GasUsed(), len(block.Uncles()), block.Hash().Bytes()[0:4], time.Since(bstart))
636636
}
637637
queue[i] = ChainEvent{block, block.Hash(), logs}
638638
queueEvent.canonicalCount++

‎core/vm/context.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type Context struct {
3535
jumpdests destinations // result of JUMPDEST analysis.
3636

3737
Code []byte
38+
Input []byte
3839
CodeAddr *common.Address
3940

4041
value, Gas, UsedGas, Price *big.Int

‎core/vm/contracts.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func ecrecoverFunc(in []byte) []byte {
9494
v := byte(vbig.Uint64())
9595

9696
if !crypto.ValidateSignatureValues(v, r, s) {
97-
glog.V(logger.Error).Infof("EC RECOVER FAIL: v, r or s value invalid")
97+
glog.V(logger.Debug).Infof("EC RECOVER FAIL: v, r or s value invalid")
9898
return nil
9999
}
100100

‎core/vm/gas.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ func baseCheck(op OpCode, stack *stack, gas *big.Int) error {
5454
return err
5555
}
5656

57-
if r.stackPush > 0 && len(stack.data)-r.stackPop+r.stackPush > int(params.StackLimit.Int64())+1 {
58-
return fmt.Errorf("stack limit reached %d (%d)", len(stack.data), params.StackLimit.Int64())
57+
if r.stackPush > 0 && stack.len()-r.stackPop+r.stackPush > int(params.StackLimit.Int64()) {
58+
return fmt.Errorf("stack limit reached %d (%d)", stack.len(), params.StackLimit.Int64())
5959
}
6060

6161
gas.Add(gas, r.gas)

0 commit comments

Comments
 (0)