pub struct VmBinaryModule {
pub code: Vec<u8>,
pub hash: H256,
}Expand description
A vm binary module ready to be put on chain.
Fields§
§code: Vec<u8>§hash: H256Implementations§
Source§impl VmBinaryModule
impl VmBinaryModule
Sourcepub const BRANCH_BLOCKS: u32 = 16_000
pub const BRANCH_BLOCKS: u32 = 16_000
The number of branches in Self::with_branch_blocks.
All blocks the contract enters must fit into the interpreter cache at the same time, or
the interpreter would reset the cache and compile blocks again. The cache holds
INTERPRETER_CACHE_BYTES / 24 entries and keeps room for one block of
BASIC_BLOCK_SIZE instructions. A block of one instruction takes two entries: its gas
charge and the instruction. 16000 such blocks and the final block of two instructions
take 32003 entries, below the 42689 usable.
The cache entries are kept in vectors that double their capacity as they grow, up to
the cache limit. 32003 entries stay below a capacity of 32768. Above it the vectors would
be reallocated once more, which adds a copy of the whole cache to the largest values of
b and skews the linear fit.
Sourcepub const LOAD_CHAIN_SLOTS: u32 = 1024
pub const LOAD_CHAIN_SLOTS: u32 = 1024
The number of slots in the chain of addresses of Self::with_load_chain.
With slots Self::LOAD_CHAIN_SLOT_BYTES apart, the chain stays in the L2 but not in the
L1 data cache of the reference hardware: Intel Ice Lake (48 KiB L1D of 12 ways, 1.25 MiB
L2 of 20 ways) and AMD Zen 3 (32 KiB L1D of 8 ways, 512 KiB L2 of 8 ways), all with 64
byte lines, 64 L1D sets and 1024 L2 sets. A load touches one line, or two in the
benchmark variant where every load spans two lines. With slots two lines apart, the 1024
lines (64 KiB) of the other variants map to every other set and the 2048 lines (128 KiB)
of the spanning variant to every set. Either way each L1D set in use receives 32 lines
against at most 12 ways, and each L2 set 2 lines, a quarter of the Zen 3 ways. The L2 is
physically indexed, so 2 lines per set is an average that depends on where the 32 4 KiB
pages of the chain land. Every load also takes a DTLB lookup; the 32 pages fit the 64 entry
L1 DTLB of both.
Sourcepub const LOAD_CHAIN_SLOT_BYTES: u32 = 128
pub const LOAD_CHAIN_SLOT_BYTES: u32 = 128
The distance between two slots of Self::with_load_chain in bytes.
Two 64 byte cache lines; see Self::LOAD_CHAIN_SLOTS.
Sourcepub const MAX_CODE_BYTES: u32
pub const MAX_CODE_BYTES: u32
The largest code section Self::with_code_bytes builds.
The interpreter keeps a map with one entry per byte of the code section. It counts
towards [limits::code::PURGABLE_MEMORY_LIMIT] next to the interpreter cache, which a
contract of this size fills. That allows at most 512 KiB of code. One page is left as a
margin for the code that Self::with_code_bytes adds.
Sourcepub fn dummy_unique(replace_with: u32) -> Self
pub fn dummy_unique(replace_with: u32) -> Self
Same as Self::dummy but uses replace_with to make the code unique.
Sourcepub fn sized(size: u32) -> Self
pub fn sized(size: u32) -> Self
Same as as with_num_instructions but based on the blob size.
This is needed when we weigh a blob without knowing how much instructions it contains.
Sourcepub fn with_num_instructions(num_instructions: u32) -> Self
pub fn with_num_instructions(num_instructions: u32) -> Self
A contract code of specified number of instructions that uses all its bytes for instructions but will return immediately.
All the basic blocks are maximum sized (only the first is important though). This is to account for the fact that the interpreter will compile one basic block at a time even when no code is executed. Hence this contract will trigger the compilation of a maximum sized basic block and then return with its first instruction.
All the code will be put into the “call” export. Hence this code can be safely used for the
instantiate_with_code benchmark where no compilation of any block should be measured.
Sourcepub fn with_branch_blocks(b: u32) -> Self
pub fn with_branch_blocks(b: u32) -> Self
A contract whose call export enters b basic blocks of one instruction and returns.
The code holds Self::BRANCH_BLOCKS branches, one ecalli SENTINEL and one ret.
Each branch ends a basic block, so each forms a block of its own, and it is always taken
to the next block. The ecalli SENTINEL comes after b of them: the call compiles and
runs b blocks of one branch each, then compiles the block of the ecalli SENTINEL and
the instruction after it, and stops at the ecalli SENTINEL. The code holds the same
instructions for every b, so its size does not depend on b.
The branch is a branch_eq of two registers. Of the instructions that end a basic block
and continue at another one, a register branch is the slowest to compile and run per
block, so the slope is an upper bound for the other terminators.
b is within 0..=BRANCH_BLOCKS.
Sourcepub fn with_entry_block(n: u32) -> Self
pub fn with_entry_block(n: u32) -> Self
A contract whose call export compiles an entry block of n instructions and returns.
The entry block starts with an ecalli SENTINEL, which ends the execution but not the
basic block, so the interpreter compiles the whole block before running it. n - 2
fillers and a fallthrough follow. The remaining BASIC_BLOCK_SIZE - n fillers and a
ret form a second block, which is never entered. The code holds the same instructions
for every n, so its size does not depend on n.
The filler is a store_imm_indirect_u64 with two 4 byte immediates. It never executes.
Of the instructions that do not end a basic block, the store_imm_indirect kinds are the
slowest to compile per instruction, with short immediates as well, so the slope is an
upper bound for the others.
n is within 2..=BASIC_BLOCK_SIZE.
Sourcepub fn with_load_chain() -> Self
pub fn with_load_chain() -> Self
A contract whose call export runs a1 iterations of LOAD_CHAIN_GAS - 3 dependent
loads.
An iteration is the branch jump @done if t0 == a1, then one basic block of loads
a0 = u64 [a0], t0 = t0 + 1 and jump @loop. Each load reads the address of the next
one, so it cannot start before the previous load has finished. The contract declares
Self::LOAD_CHAIN_SLOTS slots of Self::LOAD_CHAIN_SLOT_BYTES as read-write data.
The caller writes the chain of addresses into it and sets a0 to the first address.
Sourcepub fn with_indirect_jump_cycle() -> Self
pub fn with_indirect_jump_cycle() -> Self
A contract whose call export runs a1 laps of a random cycle of indirect jumps.
The cycle has INDIRECT_JUMP_GAS - 3 basic blocks of one instruction each. Every block
is a load_imm_and_jump_indirect that jumps to the address in a0 and loads the address
of the block after the next one into a0. A lap starts and ends at a block with the
branch jump @done if t0 == a1, followed by t0 = t0 + 1 and the jump into the cycle.
The order of the blocks in the cycle is a fixed random permutation, so consecutive
jumps go to unrelated code addresses.
Before the first lap, a warm-up loop enters every cycle block once in code order, with
a0 holding the loop’s own address so that the block jumps back to it. The interpreter
compiles a block when execution first enters it and appends its handlers to its cache,
so the cache holds the cycle blocks in code order. A lap visits them in the random order
of the cycle, so its reads of handlers and arguments are as scattered as its reads of the
jump table and the code map. The warm-up runs once per call whatever a1 is.
The number of blocks keeps the interpreter data a lap reads in the L2 but not in the L1
data cache of the reference hardware (see Self::LOAD_CHAIN_SLOTS). A jump into a
block reads the block’s 2 byte jump table entry, its 4 byte entry in the code map, and
the 8 byte handler and 16 byte arguments of its two compiled instructions: the gas charge
and the jump. The code map has one entry per code byte and a block is 5 bytes of code, so
the entries of consecutive blocks are 20 bytes apart and a lap reads every cache line of
the map: 20 bytes per block. Every block thus adds 2 + 20 + 2 * 24 = 70 bytes to the data
of a lap. The code itself is read only when a block is compiled. The
INDIRECT_JUMP_GAS - 3 = 3000 blocks take 205 KiB, 4.3 times the Ice Lake L1D: each of
the 64 L1D sets receives about 51 lines against at most 12 ways. Each of the 1024 L2 sets
receives 3.2 lines, 40% of the Zen 3 ways. The L2 is physically indexed, so 3.2 lines per
set is an average that depends on where the pages land. The data spans four arrays of
4 KiB pages, jump table 2 to 3, code map 15 to 16, handlers 12 to 13 and arguments 24 to
25, so 53 to 57 pages plus the interpreter’s own state. They fit the fully associative 64
entry L1 DTLB of Zen 3. The 64 entry L1 DTLB of Ice Lake is 4-way set associative, so some
of them may miss it and hit the second level TLB.
Sourcepub fn with_code_bytes(code_bytes: u32) -> Self
pub fn with_code_bytes(code_bytes: u32) -> Self
A contract with a code section of about code_bytes bytes whose call export returns
at once.
The call export is a basic block of ecalli SENTINEL and fallthrough, which stops
the call. Blocks of a0 = a1 + a2, 3 bytes each, fill the rest of the code section and
never run. Only the size of the code section depends on code_bytes.
Trait Implementations§
Source§impl Clone for VmBinaryModule
impl Clone for VmBinaryModule
Source§fn clone(&self) -> VmBinaryModule
fn clone(&self) -> VmBinaryModule
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for VmBinaryModule
impl RefUnwindSafe for VmBinaryModule
impl Send for VmBinaryModule
impl Sync for VmBinaryModule
impl Unpin for VmBinaryModule
impl UnwindSafe for VmBinaryModule
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CheckedConversion for T
impl<T> CheckedConversion for T
§fn checked_from<T>(t: T) -> Option<Self>where
Self: TryFrom<T>,
fn checked_from<T>(t: T) -> Option<Self>where
Self: TryFrom<T>,
§fn checked_into<T>(self) -> Option<T>where
Self: TryInto<T>,
fn checked_into<T>(self) -> Option<T>where
Self: TryInto<T>,
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Conv for T
impl<T> Conv for T
§impl<T, U> DefensiveTruncateInto<U> for Twhere
U: DefensiveTruncateFrom<T>,
impl<T, U> DefensiveTruncateInto<U> for Twhere
U: DefensiveTruncateFrom<T>,
§fn defensive_truncate_into(self) -> U
fn defensive_truncate_into(self) -> U
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<Src, Dest> IntoTuple<Dest> for Srcwhere
Dest: FromTuple<Src>,
impl<Src, Dest> IntoTuple<Dest> for Srcwhere
Dest: FromTuple<Src>,
fn into_tuple(self) -> Dest
§impl<T> IsType<T> for T
impl<T> IsType<T> for T
§impl<T, Outer> IsWrappedBy<Outer> for T
impl<T, Outer> IsWrappedBy<Outer> for T
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> SaturatedConversion for T
impl<T> SaturatedConversion for T
§fn saturated_from<T>(t: T) -> Selfwhere
Self: UniqueSaturatedFrom<T>,
fn saturated_from<T>(t: T) -> Selfwhere
Self: UniqueSaturatedFrom<T>,
§fn saturated_into<T>(self) -> Twhere
Self: UniqueSaturatedInto<T>,
fn saturated_into<T>(self) -> Twhere
Self: UniqueSaturatedInto<T>,
T. Read more§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.§impl<T> TryConv for T
impl<T> TryConv for T
§impl<T, U> TryIntoKey<U> for Twhere
U: TryFromKey<T>,
impl<T, U> TryIntoKey<U> for Twhere
U: TryFromKey<T>,
type Error = <U as TryFromKey<T>>::Error
fn try_into_key(self) -> Result<U, <U as TryFromKey<T>>::Error>
§impl<S, T> UncheckedInto<T> for Swhere
T: UncheckedFrom<S>,
impl<S, T> UncheckedInto<T> for Swhere
T: UncheckedFrom<S>,
§fn unchecked_into(self) -> T
fn unchecked_into(self) -> T
unchecked_from.§impl<T, S> UniqueSaturatedInto<T> for S
impl<T, S> UniqueSaturatedInto<T> for S
§fn unique_saturated_into(self) -> T
fn unique_saturated_into(self) -> T
T.