diff options
author | Jeffrey Wilcke <jeffrey@ethereum.org> | 2017-01-05 18:52:10 +0800 |
---|---|---|
committer | Felix Lange <fjl@users.noreply.github.com> | 2017-01-05 18:52:10 +0800 |
commit | bbc4ea4ae8e8a962deae3d5693d9d4a9376eab88 (patch) | |
tree | d4743eaa073d1bc7788f5d4fc3771da37f3cb0b5 /core/vm/jit_optimiser.go | |
parent | 2126d8148806b6d8597d6a1c761080e9dc98d745 (diff) | |
download | dexon-bbc4ea4ae8e8a962deae3d5693d9d4a9376eab88.tar dexon-bbc4ea4ae8e8a962deae3d5693d9d4a9376eab88.tar.gz dexon-bbc4ea4ae8e8a962deae3d5693d9d4a9376eab88.tar.bz2 dexon-bbc4ea4ae8e8a962deae3d5693d9d4a9376eab88.tar.lz dexon-bbc4ea4ae8e8a962deae3d5693d9d4a9376eab88.tar.xz dexon-bbc4ea4ae8e8a962deae3d5693d9d4a9376eab88.tar.zst dexon-bbc4ea4ae8e8a962deae3d5693d9d4a9376eab88.zip |
core/vm: improved EVM run loop & instruction calling (#3378)
The run loop, which previously contained custom opcode executes have been
removed and has been simplified to a few checks.
Each operation consists of 4 elements: execution function, gas cost function,
stack validation function and memory size function. The execution function
implements the operation's runtime behaviour, the gas cost function implements
the operation gas costs function and greatly depends on the memory and stack,
the stack validation function validates the stack and makes sure that enough
items can be popped off and pushed on and the memory size function calculates
the memory required for the operation and returns it.
This commit also allows the EVM to go unmetered. This is helpful for offline
operations such as contract calls.
Diffstat (limited to 'core/vm/jit_optimiser.go')
-rw-r--r-- | core/vm/jit_optimiser.go | 123 |
1 files changed, 0 insertions, 123 deletions
diff --git a/core/vm/jit_optimiser.go b/core/vm/jit_optimiser.go deleted file mode 100644 index 31ad0c2e2..000000000 --- a/core/vm/jit_optimiser.go +++ /dev/null @@ -1,123 +0,0 @@ -// Copyright 2015 The go-ethereum Authors -// This file is part of the go-ethereum library. -// -// The go-ethereum library is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// The go-ethereum library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. - -package vm - -import ( - "math/big" - "time" - - "github.com/ethereum/go-ethereum/logger" - "github.com/ethereum/go-ethereum/logger/glog" -) - -// optimeProgram optimises a JIT program creating segments out of program -// instructions. Currently covered are multi-pushes and static jumps -func optimiseProgram(program *Program) { - var load []instruction - - var ( - statsJump = 0 - statsPush = 0 - ) - - if glog.V(logger.Debug) { - glog.Infof("optimising %x\n", program.Id[:4]) - tstart := time.Now() - defer func() { - glog.Infof("optimised %x done in %v with JMP: %d PSH: %d\n", program.Id[:4], time.Since(tstart), statsJump, statsPush) - }() - } - - /* - code := Parse(program.code) - for _, test := range [][]OpCode{ - []OpCode{PUSH, PUSH, ADD}, - []OpCode{PUSH, PUSH, SUB}, - []OpCode{PUSH, PUSH, MUL}, - []OpCode{PUSH, PUSH, DIV}, - } { - matchCount := 0 - MatchFn(code, test, func(i int) bool { - matchCount++ - return true - }) - fmt.Printf("found %d match count on: %v\n", matchCount, test) - } - */ - - for i := 0; i < len(program.instructions); i++ { - instr := program.instructions[i].(instruction) - - switch { - case instr.op.IsPush(): - load = append(load, instr) - case instr.op.IsStaticJump(): - if len(load) == 0 { - continue - } - // if the push load is greater than 1, finalise that - // segment first - if len(load) > 2 { - seg, size := makePushSeg(load[:len(load)-1]) - program.instructions[i-size-1] = seg - statsPush++ - } - // create a segment consisting of a pre determined - // jump, destination and validity. - seg := makeStaticJumpSeg(load[len(load)-1].data, program) - program.instructions[i-1] = seg - statsJump++ - - load = nil - default: - // create a new N pushes segment - if len(load) > 1 { - seg, size := makePushSeg(load) - program.instructions[i-size] = seg - statsPush++ - } - load = nil - } - } -} - -// makePushSeg creates a new push segment from N amount of push instructions -func makePushSeg(instrs []instruction) (pushSeg, int) { - var ( - data []*big.Int - gas = new(big.Int) - ) - - for _, instr := range instrs { - data = append(data, instr.data) - gas.Add(gas, instr.gas) - } - - return pushSeg{data, gas}, len(instrs) -} - -// makeStaticJumpSeg creates a new static jump segment from a predefined -// destination (PUSH, JUMP). -func makeStaticJumpSeg(to *big.Int, program *Program) jumpSeg { - gas := new(big.Int) - gas.Add(gas, _baseCheck[PUSH1].gas) - gas.Add(gas, _baseCheck[JUMP].gas) - - contract := &Contract{Code: program.code} - pos, err := jump(program.mapping, program.destinations, contract, to) - return jumpSeg{pos, err, gas} -} |