Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
73c4e600
Commit
73c4e600
authored
Aug 13, 2015
by
Jeffrey Wilcke
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1638 from obscuren/jit-fixes
core/vm: fixed jit error & added inline docs
parents
a89cfe92
9cacec70
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
34 additions
and
41 deletions
+34
-41
main.go
cmd/evm/main.go
+1
-1
flags.go
cmd/utils/flags.go
+1
-1
block_processor.go
core/block_processor.go
+1
-11
instructions.go
core/vm/instructions.go
+8
-11
jit.go
core/vm/jit.go
+6
-0
jit_test.go
core/vm/jit_test.go
+1
-1
settings.go
core/vm/settings.go
+3
-3
vm.go
core/vm/vm.go
+1
-1
state_test.go
tests/state_test.go
+2
-3
state_test_util.go
tests/state_test_util.go
+3
-3
vm_test.go
tests/vm_test.go
+3
-2
vm_test_util.go
tests/vm_test_util.go
+4
-4
No files found.
cmd/evm/main.go
View file @
73c4e600
...
@@ -102,7 +102,7 @@ func init() {
...
@@ -102,7 +102,7 @@ func init() {
func
run
(
ctx
*
cli
.
Context
)
{
func
run
(
ctx
*
cli
.
Context
)
{
vm
.
Debug
=
ctx
.
GlobalBool
(
DebugFlag
.
Name
)
vm
.
Debug
=
ctx
.
GlobalBool
(
DebugFlag
.
Name
)
vm
.
ForceJit
=
ctx
.
GlobalBool
(
ForceJitFlag
.
Name
)
vm
.
ForceJit
=
ctx
.
GlobalBool
(
ForceJitFlag
.
Name
)
vm
.
DisableJit
=
ctx
.
GlobalBool
(
DisableJitFlag
.
Name
)
vm
.
EnableJit
=
!
ctx
.
GlobalBool
(
DisableJitFlag
.
Name
)
glog
.
SetToStderr
(
true
)
glog
.
SetToStderr
(
true
)
...
...
cmd/utils/flags.go
View file @
73c4e600
...
@@ -452,7 +452,7 @@ func SetupLogger(ctx *cli.Context) {
...
@@ -452,7 +452,7 @@ func SetupLogger(ctx *cli.Context) {
// SetupVM configured the VM package's global settings
// SetupVM configured the VM package's global settings
func
SetupVM
(
ctx
*
cli
.
Context
)
{
func
SetupVM
(
ctx
*
cli
.
Context
)
{
vm
.
DisableJit
=
!
ctx
.
GlobalBool
(
VMEnableJitFlag
.
Name
)
vm
.
EnableJit
=
ctx
.
GlobalBool
(
VMEnableJitFlag
.
Name
)
vm
.
ForceJit
=
ctx
.
GlobalBool
(
VMForceJitFlag
.
Name
)
vm
.
ForceJit
=
ctx
.
GlobalBool
(
VMForceJitFlag
.
Name
)
vm
.
SetJITCacheSize
(
ctx
.
GlobalInt
(
VMJitCacheFlag
.
Name
))
vm
.
SetJITCacheSize
(
ctx
.
GlobalInt
(
VMJitCacheFlag
.
Name
))
}
}
...
...
core/block_processor.go
View file @
73c4e600
...
@@ -354,18 +354,8 @@ func (sm *BlockProcessor) GetLogs(block *types.Block) (logs state.Logs, err erro
...
@@ -354,18 +354,8 @@ func (sm *BlockProcessor) GetLogs(block *types.Block) (logs state.Logs, err erro
for
_
,
receipt
:=
range
receipts
{
for
_
,
receipt
:=
range
receipts
{
logs
=
append
(
logs
,
receipt
.
Logs
()
...
)
logs
=
append
(
logs
,
receipt
.
Logs
()
...
)
}
}
return
}
}
return
logs
,
nil
// TODO: remove backward compatibility
var
(
parent
=
sm
.
bc
.
GetBlock
(
block
.
ParentHash
())
state
=
state
.
New
(
parent
.
Root
(),
sm
.
chainDb
)
)
sm
.
TransitionState
(
state
,
parent
,
block
,
true
)
return
state
.
Logs
(),
nil
}
}
// See YP section 4.3.4. "Block Header Validity"
// See YP section 4.3.4. "Block Header Validity"
...
...
core/vm/instructions.go
View file @
73c4e600
...
@@ -341,19 +341,19 @@ func opCoinbase(instr instruction, env Environment, context *Context, memory *Me
...
@@ -341,19 +341,19 @@ func opCoinbase(instr instruction, env Environment, context *Context, memory *Me
}
}
func
opTimestamp
(
instr
instruction
,
env
Environment
,
context
*
Context
,
memory
*
Memory
,
stack
*
stack
)
{
func
opTimestamp
(
instr
instruction
,
env
Environment
,
context
*
Context
,
memory
*
Memory
,
stack
*
stack
)
{
stack
.
push
(
new
(
big
.
Int
)
.
SetUint64
(
env
.
Time
(
)))
stack
.
push
(
U256
(
new
(
big
.
Int
)
.
SetUint64
(
env
.
Time
()
)))
}
}
func
opNumber
(
instr
instruction
,
env
Environment
,
context
*
Context
,
memory
*
Memory
,
stack
*
stack
)
{
func
opNumber
(
instr
instruction
,
env
Environment
,
context
*
Context
,
memory
*
Memory
,
stack
*
stack
)
{
stack
.
push
(
U256
(
env
.
BlockNumber
(
)))
stack
.
push
(
U256
(
new
(
big
.
Int
)
.
Set
(
env
.
BlockNumber
()
)))
}
}
func
opDifficulty
(
instr
instruction
,
env
Environment
,
context
*
Context
,
memory
*
Memory
,
stack
*
stack
)
{
func
opDifficulty
(
instr
instruction
,
env
Environment
,
context
*
Context
,
memory
*
Memory
,
stack
*
stack
)
{
stack
.
push
(
new
(
big
.
Int
)
.
Set
(
env
.
Difficulty
(
)))
stack
.
push
(
U256
(
new
(
big
.
Int
)
.
Set
(
env
.
Difficulty
()
)))
}
}
func
opGasLimit
(
instr
instruction
,
env
Environment
,
context
*
Context
,
memory
*
Memory
,
stack
*
stack
)
{
func
opGasLimit
(
instr
instruction
,
env
Environment
,
context
*
Context
,
memory
*
Memory
,
stack
*
stack
)
{
stack
.
push
(
new
(
big
.
Int
)
.
Set
(
env
.
GasLimit
(
)))
stack
.
push
(
U256
(
new
(
big
.
Int
)
.
Set
(
env
.
GasLimit
()
)))
}
}
func
opPop
(
instr
instruction
,
env
Environment
,
context
*
Context
,
memory
*
Memory
,
stack
*
stack
)
{
func
opPop
(
instr
instruction
,
env
Environment
,
context
*
Context
,
memory
*
Memory
,
stack
*
stack
)
{
...
@@ -415,15 +415,12 @@ func opSstore(instr instruction, env Environment, context *Context, memory *Memo
...
@@ -415,15 +415,12 @@ func opSstore(instr instruction, env Environment, context *Context, memory *Memo
env
.
State
()
.
SetState
(
context
.
Address
(),
loc
,
common
.
BigToHash
(
val
))
env
.
State
()
.
SetState
(
context
.
Address
(),
loc
,
common
.
BigToHash
(
val
))
}
}
func
opJump
(
instr
instruction
,
env
Environment
,
context
*
Context
,
memory
*
Memory
,
stack
*
stack
)
{
func
opJump
(
instr
instruction
,
env
Environment
,
context
*
Context
,
memory
*
Memory
,
stack
*
stack
)
{}
}
func
opJumpi
(
instr
instruction
,
env
Environment
,
context
*
Context
,
memory
*
Memory
,
stack
*
stack
)
{}
func
opJumpi
(
instr
instruction
,
env
Environment
,
context
*
Context
,
memory
*
Memory
,
stack
*
stack
)
{
func
opJumpdest
(
instr
instruction
,
env
Environment
,
context
*
Context
,
memory
*
Memory
,
stack
*
stack
)
{}
}
func
opJumpdest
(
instr
instruction
,
env
Environment
,
context
*
Context
,
memory
*
Memory
,
stack
*
stack
)
{
}
func
opPc
(
instr
instruction
,
env
Environment
,
context
*
Context
,
memory
*
Memory
,
stack
*
stack
)
{
func
opPc
(
instr
instruction
,
env
Environment
,
context
*
Context
,
memory
*
Memory
,
stack
*
stack
)
{
stack
.
push
(
instr
.
data
)
stack
.
push
(
new
(
big
.
Int
)
.
Set
(
instr
.
data
)
)
}
}
func
opMsize
(
instr
instruction
,
env
Environment
,
context
*
Context
,
memory
*
Memory
,
stack
*
stack
)
{
func
opMsize
(
instr
instruction
,
env
Environment
,
context
*
Context
,
memory
*
Memory
,
stack
*
stack
)
{
...
...
core/vm/jit.go
View file @
73c4e600
...
@@ -83,6 +83,7 @@ type Program struct {
...
@@ -83,6 +83,7 @@ type Program struct {
code
[]
byte
code
[]
byte
}
}
// NewProgram returns a new JIT program
func
NewProgram
(
code
[]
byte
)
*
Program
{
func
NewProgram
(
code
[]
byte
)
*
Program
{
program
:=
&
Program
{
program
:=
&
Program
{
Id
:
crypto
.
Sha3Hash
(
code
),
Id
:
crypto
.
Sha3Hash
(
code
),
...
@@ -113,6 +114,7 @@ func (p *Program) addInstr(op OpCode, pc uint64, fn instrFn, data *big.Int) {
...
@@ -113,6 +114,7 @@ func (p *Program) addInstr(op OpCode, pc uint64, fn instrFn, data *big.Int) {
p
.
mapping
[
pc
]
=
len
(
p
.
instructions
)
-
1
p
.
mapping
[
pc
]
=
len
(
p
.
instructions
)
-
1
}
}
// CompileProgram compiles the given program and return an error when it fails
func
CompileProgram
(
program
*
Program
)
(
err
error
)
{
func
CompileProgram
(
program
*
Program
)
(
err
error
)
{
if
progStatus
(
atomic
.
LoadInt32
(
&
program
.
status
))
==
progCompile
{
if
progStatus
(
atomic
.
LoadInt32
(
&
program
.
status
))
==
progCompile
{
return
nil
return
nil
...
@@ -272,6 +274,8 @@ func CompileProgram(program *Program) (err error) {
...
@@ -272,6 +274,8 @@ func CompileProgram(program *Program) (err error) {
return
nil
return
nil
}
}
// RunProgram runs the program given the enviroment and context and returns an
// error if the execution failed (non-consensus)
func
RunProgram
(
program
*
Program
,
env
Environment
,
context
*
Context
,
input
[]
byte
)
([]
byte
,
error
)
{
func
RunProgram
(
program
*
Program
,
env
Environment
,
context
*
Context
,
input
[]
byte
)
([]
byte
,
error
)
{
return
runProgram
(
program
,
0
,
NewMemory
(),
newstack
(),
env
,
context
,
input
)
return
runProgram
(
program
,
0
,
NewMemory
(),
newstack
(),
env
,
context
,
input
)
}
}
...
@@ -352,6 +356,8 @@ func runProgram(program *Program, pcstart uint64, mem *Memory, stack *stack, env
...
@@ -352,6 +356,8 @@ func runProgram(program *Program, pcstart uint64, mem *Memory, stack *stack, env
pc
++
pc
++
}
}
context
.
Input
=
nil
return
context
.
Return
(
nil
),
nil
return
context
.
Return
(
nil
),
nil
}
}
...
...
core/vm/jit_test.go
View file @
73c4e600
...
@@ -46,7 +46,7 @@ func runVmBench(test vmBench, b *testing.B) {
...
@@ -46,7 +46,7 @@ func runVmBench(test vmBench, b *testing.B) {
}
}
env
:=
NewEnv
()
env
:=
NewEnv
()
DisableJit
=
test
.
nojit
EnableJit
=
!
test
.
nojit
ForceJit
=
test
.
forcejit
ForceJit
=
test
.
forcejit
b
.
ResetTimer
()
b
.
ResetTimer
()
...
...
core/vm/settings.go
View file @
73c4e600
...
@@ -17,9 +17,9 @@
...
@@ -17,9 +17,9 @@
package
vm
package
vm
var
(
var
(
DisableJit
bool
=
true
// Disable
the JIT VM
EnableJit
bool
// Enables
the JIT VM
ForceJit
bool
// Force the JIT, skip byte VM
ForceJit
bool
// Force the JIT, skip byte VM
MaxProgSize
int
// Max cache size for JIT Programs
MaxProgSize
int
// Max cache size for JIT Programs
)
)
const
defaultJitMaxCache
int
=
64
const
defaultJitMaxCache
int
=
64
core/vm/vm.go
View file @
73c4e600
...
@@ -64,7 +64,7 @@ func (self *Vm) Run(context *Context, input []byte) (ret []byte, err error) {
...
@@ -64,7 +64,7 @@ func (self *Vm) Run(context *Context, input []byte) (ret []byte, err error) {
codehash
=
crypto
.
Sha3Hash
(
context
.
Code
)
// codehash is used when doing jump dest caching
codehash
=
crypto
.
Sha3Hash
(
context
.
Code
)
// codehash is used when doing jump dest caching
program
*
Program
program
*
Program
)
)
if
!
Dis
ableJit
{
if
En
ableJit
{
// Fetch program status.
// Fetch program status.
// * If ready run using JIT
// * If ready run using JIT
// * If unknown, compile in a seperate goroutine
// * If unknown, compile in a seperate goroutine
...
...
tests/state_test.go
View file @
73c4e600
...
@@ -27,14 +27,13 @@ import (
...
@@ -27,14 +27,13 @@ import (
func
init
()
{
func
init
()
{
if
os
.
Getenv
(
"JITVM"
)
==
"true"
{
if
os
.
Getenv
(
"JITVM"
)
==
"true"
{
vm
.
ForceJit
=
true
vm
.
ForceJit
=
true
}
else
{
vm
.
EnableJit
=
true
vm
.
DisableJit
=
true
}
}
}
}
func
BenchmarkStateCall1024
(
b
*
testing
.
B
)
{
func
BenchmarkStateCall1024
(
b
*
testing
.
B
)
{
fn
:=
filepath
.
Join
(
stateTestDir
,
"stCallCreateCallCodeTest.json"
)
fn
:=
filepath
.
Join
(
stateTestDir
,
"stCallCreateCallCodeTest.json"
)
if
err
:=
BenchVmTest
(
fn
,
bconf
{
"Call1024BalanceTooLow"
,
true
,
false
},
b
);
err
!=
nil
{
if
err
:=
BenchVmTest
(
fn
,
bconf
{
"Call1024BalanceTooLow"
,
true
,
os
.
Getenv
(
"JITVM"
)
==
"true"
},
b
);
err
!=
nil
{
b
.
Error
(
err
)
b
.
Error
(
err
)
}
}
}
}
...
...
tests/state_test_util.go
View file @
73c4e600
...
@@ -71,8 +71,8 @@ func BenchStateTest(p string, conf bconf, b *testing.B) error {
...
@@ -71,8 +71,8 @@ func BenchStateTest(p string, conf bconf, b *testing.B) error {
return
fmt
.
Errorf
(
"test not found: %s"
,
conf
.
name
)
return
fmt
.
Errorf
(
"test not found: %s"
,
conf
.
name
)
}
}
p
NoJit
:=
vm
.
Dis
ableJit
p
Jit
:=
vm
.
En
ableJit
vm
.
DisableJit
=
conf
.
no
jit
vm
.
EnableJit
=
conf
.
jit
pForceJit
:=
vm
.
ForceJit
pForceJit
:=
vm
.
ForceJit
vm
.
ForceJit
=
conf
.
precomp
vm
.
ForceJit
=
conf
.
precomp
...
@@ -94,7 +94,7 @@ func BenchStateTest(p string, conf bconf, b *testing.B) error {
...
@@ -94,7 +94,7 @@ func BenchStateTest(p string, conf bconf, b *testing.B) error {
benchStateTest
(
test
,
env
,
b
)
benchStateTest
(
test
,
env
,
b
)
}
}
vm
.
DisableJit
=
pNo
Jit
vm
.
EnableJit
=
p
Jit
vm
.
ForceJit
=
pForceJit
vm
.
ForceJit
=
pForceJit
return
nil
return
nil
...
...
tests/vm_test.go
View file @
73c4e600
...
@@ -17,20 +17,21 @@
...
@@ -17,20 +17,21 @@
package
tests
package
tests
import
(
import
(
"os"
"path/filepath"
"path/filepath"
"testing"
"testing"
)
)
func
BenchmarkVmAckermann32Tests
(
b
*
testing
.
B
)
{
func
BenchmarkVmAckermann32Tests
(
b
*
testing
.
B
)
{
fn
:=
filepath
.
Join
(
vmTestDir
,
"vmPerformanceTest.json"
)
fn
:=
filepath
.
Join
(
vmTestDir
,
"vmPerformanceTest.json"
)
if
err
:=
BenchVmTest
(
fn
,
bconf
{
"ackermann32"
,
true
,
false
},
b
);
err
!=
nil
{
if
err
:=
BenchVmTest
(
fn
,
bconf
{
"ackermann32"
,
true
,
os
.
Getenv
(
"JITVM"
)
==
"true"
},
b
);
err
!=
nil
{
b
.
Error
(
err
)
b
.
Error
(
err
)
}
}
}
}
func
BenchmarkVmFibonacci16Tests
(
b
*
testing
.
B
)
{
func
BenchmarkVmFibonacci16Tests
(
b
*
testing
.
B
)
{
fn
:=
filepath
.
Join
(
vmTestDir
,
"vmPerformanceTest.json"
)
fn
:=
filepath
.
Join
(
vmTestDir
,
"vmPerformanceTest.json"
)
if
err
:=
BenchVmTest
(
fn
,
bconf
{
"fibonacci16"
,
true
,
false
},
b
);
err
!=
nil
{
if
err
:=
BenchVmTest
(
fn
,
bconf
{
"fibonacci16"
,
true
,
os
.
Getenv
(
"JITVM"
)
==
"true"
},
b
);
err
!=
nil
{
b
.
Error
(
err
)
b
.
Error
(
err
)
}
}
}
}
...
...
tests/vm_test_util.go
View file @
73c4e600
...
@@ -52,7 +52,7 @@ func RunVmTestWithReader(r io.Reader, skipTests []string) error {
...
@@ -52,7 +52,7 @@ func RunVmTestWithReader(r io.Reader, skipTests []string) error {
type
bconf
struct
{
type
bconf
struct
{
name
string
name
string
precomp
bool
precomp
bool
nojit
bool
jit
bool
}
}
func
BenchVmTest
(
p
string
,
conf
bconf
,
b
*
testing
.
B
)
error
{
func
BenchVmTest
(
p
string
,
conf
bconf
,
b
*
testing
.
B
)
error
{
...
@@ -67,8 +67,8 @@ func BenchVmTest(p string, conf bconf, b *testing.B) error {
...
@@ -67,8 +67,8 @@ func BenchVmTest(p string, conf bconf, b *testing.B) error {
return
fmt
.
Errorf
(
"test not found: %s"
,
conf
.
name
)
return
fmt
.
Errorf
(
"test not found: %s"
,
conf
.
name
)
}
}
p
NoJit
:=
vm
.
Dis
ableJit
p
Jit
:=
vm
.
En
ableJit
vm
.
DisableJit
=
conf
.
no
jit
vm
.
EnableJit
=
conf
.
jit
pForceJit
:=
vm
.
ForceJit
pForceJit
:=
vm
.
ForceJit
vm
.
ForceJit
=
conf
.
precomp
vm
.
ForceJit
=
conf
.
precomp
...
@@ -99,7 +99,7 @@ func BenchVmTest(p string, conf bconf, b *testing.B) error {
...
@@ -99,7 +99,7 @@ func BenchVmTest(p string, conf bconf, b *testing.B) error {
benchVmTest
(
test
,
env
,
b
)
benchVmTest
(
test
,
env
,
b
)
}
}
vm
.
DisableJit
=
pNo
Jit
vm
.
EnableJit
=
p
Jit
vm
.
ForceJit
=
pForceJit
vm
.
ForceJit
=
pForceJit
return
nil
return
nil
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment