Singlular syscall context (#24204)
This commit is contained in:
@ -115,7 +115,8 @@ fn bench_program_alu(bencher: &mut Bencher) {
|
||||
Executable::<BpfError, ThisInstructionMeter>::jit_compile(&mut executable).unwrap();
|
||||
let compute_meter = invoke_context.get_compute_meter();
|
||||
let mut instruction_meter = ThisInstructionMeter { compute_meter };
|
||||
let mut vm = create_vm(&executable, &mut inner_iter, invoke_context, &[]).unwrap();
|
||||
invoke_context.set_orig_account_lengths(vec![]).unwrap();
|
||||
let mut vm = create_vm(&executable, &mut inner_iter, invoke_context).unwrap();
|
||||
|
||||
println!("Interpreted:");
|
||||
assert_eq!(
|
||||
@ -219,6 +220,9 @@ fn bench_create_vm(bencher: &mut Bencher) {
|
||||
.unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
invoke_context
|
||||
.set_orig_account_lengths(account_lengths)
|
||||
.unwrap();
|
||||
|
||||
let executable = Executable::<BpfError, ThisInstructionMeter>::from_elf(
|
||||
&elf,
|
||||
@ -229,13 +233,7 @@ fn bench_create_vm(bencher: &mut Bencher) {
|
||||
.unwrap();
|
||||
|
||||
bencher.iter(|| {
|
||||
let _ = create_vm(
|
||||
&executable,
|
||||
serialized.as_slice_mut(),
|
||||
invoke_context,
|
||||
&account_lengths,
|
||||
)
|
||||
.unwrap();
|
||||
let _ = create_vm(&executable, serialized.as_slice_mut(), invoke_context).unwrap();
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -270,13 +268,10 @@ fn bench_instruction_count_tuner(_bencher: &mut Bencher) {
|
||||
.unwrap();
|
||||
let compute_meter = invoke_context.get_compute_meter();
|
||||
let mut instruction_meter = ThisInstructionMeter { compute_meter };
|
||||
let mut vm = create_vm(
|
||||
&executable,
|
||||
serialized.as_slice_mut(),
|
||||
invoke_context,
|
||||
&account_lengths,
|
||||
)
|
||||
.unwrap();
|
||||
invoke_context
|
||||
.set_orig_account_lengths(account_lengths)
|
||||
.unwrap();
|
||||
let mut vm = create_vm(&executable, serialized.as_slice_mut(), invoke_context).unwrap();
|
||||
|
||||
let mut measure = Measure::start("tune");
|
||||
let _ = vm.execute_program_interpreted(&mut instruction_meter);
|
||||
|
@ -245,13 +245,11 @@ fn run_program(name: &str) -> u64 {
|
||||
.unwrap();
|
||||
let mut parameter_bytes = parameter_bytes.clone();
|
||||
{
|
||||
let mut vm = create_vm(
|
||||
&executable,
|
||||
parameter_bytes.as_slice_mut(),
|
||||
invoke_context,
|
||||
&account_lengths,
|
||||
)
|
||||
.unwrap();
|
||||
invoke_context
|
||||
.set_orig_account_lengths(account_lengths.clone())
|
||||
.unwrap();
|
||||
let mut vm =
|
||||
create_vm(&executable, parameter_bytes.as_slice_mut(), invoke_context).unwrap();
|
||||
let result = if i == 0 {
|
||||
vm.execute_program_interpreted(&mut instruction_meter)
|
||||
} else {
|
||||
@ -1418,7 +1416,7 @@ fn assert_instruction_count() {
|
||||
#[cfg(feature = "bpf_c")]
|
||||
{
|
||||
programs.extend_from_slice(&[
|
||||
("alloc", 1237),
|
||||
("alloc", 11502),
|
||||
("bpf_to_bpf", 313),
|
||||
("multiple_static", 208),
|
||||
("noop", 5),
|
||||
|
@ -1,16 +0,0 @@
|
||||
use std::{alloc::Layout, fmt};
|
||||
|
||||
/// Based loosely on the unstable std::alloc::Alloc trait
|
||||
pub trait Alloc {
|
||||
fn alloc(&mut self, layout: Layout) -> Result<u64, AllocErr>;
|
||||
fn dealloc(&mut self, addr: u64, layout: Layout);
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||
pub struct AllocErr;
|
||||
|
||||
impl fmt::Display for AllocErr {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
f.write_str("Error: Memory allocation failed")
|
||||
}
|
||||
}
|
@ -1,8 +1,7 @@
|
||||
#![allow(clippy::integer_arithmetic)]
|
||||
|
||||
use {
|
||||
crate::alloc,
|
||||
alloc::{Alloc, AllocErr},
|
||||
solana_program_runtime::invoke_context::{Alloc, AllocErr},
|
||||
solana_rbpf::aligned_memory::AlignedMemory,
|
||||
std::alloc::Layout,
|
||||
};
|
||||
|
@ -1,7 +1,6 @@
|
||||
#![deny(clippy::integer_arithmetic)]
|
||||
#![deny(clippy::indexing_slicing)]
|
||||
|
||||
pub mod alloc;
|
||||
pub mod allocator_bump;
|
||||
pub mod deprecated;
|
||||
pub mod serialization;
|
||||
@ -234,7 +233,6 @@ pub fn create_vm<'a, 'b>(
|
||||
program: &'a Pin<Box<Executable<BpfError, ThisInstructionMeter>>>,
|
||||
parameter_bytes: &mut [u8],
|
||||
invoke_context: &'a mut InvokeContext<'b>,
|
||||
orig_data_lens: &'a [usize],
|
||||
) -> Result<EbpfVm<'a, BpfError, ThisInstructionMeter>, EbpfError<BpfError>> {
|
||||
let compute_budget = invoke_context.get_compute_budget();
|
||||
let heap_size = compute_budget.heap_size.unwrap_or(HEAP_LENGTH);
|
||||
@ -251,7 +249,7 @@ pub fn create_vm<'a, 'b>(
|
||||
let mut heap =
|
||||
AlignedMemory::new_with_size(compute_budget.heap_size.unwrap_or(HEAP_LENGTH), HOST_ALIGN);
|
||||
let mut vm = EbpfVm::new(program, heap.as_slice_mut(), parameter_bytes)?;
|
||||
syscalls::bind_syscall_context_objects(&mut vm, invoke_context, heap, orig_data_lens)?;
|
||||
syscalls::bind_syscall_context_objects(&mut vm, invoke_context, heap)?;
|
||||
Ok(vm)
|
||||
}
|
||||
|
||||
@ -1145,6 +1143,7 @@ impl Executor for BpfExecutor {
|
||||
let (mut parameter_bytes, account_lengths) =
|
||||
serialize_parameters(invoke_context.transaction_context, instruction_context)?;
|
||||
serialize_time.stop();
|
||||
invoke_context.set_orig_account_lengths(account_lengths)?;
|
||||
let mut create_vm_time = Measure::start("create_vm");
|
||||
let mut execute_time;
|
||||
let execution_result = {
|
||||
@ -1152,7 +1151,6 @@ impl Executor for BpfExecutor {
|
||||
&self.executable,
|
||||
parameter_bytes.as_slice_mut(),
|
||||
invoke_context,
|
||||
&account_lengths,
|
||||
) {
|
||||
Ok(info) => info,
|
||||
Err(e) => {
|
||||
@ -1234,7 +1232,7 @@ impl Executor for BpfExecutor {
|
||||
.transaction_context
|
||||
.get_current_instruction_context()?,
|
||||
parameter_bytes.as_slice(),
|
||||
&account_lengths,
|
||||
invoke_context.get_orig_account_lengths()?,
|
||||
invoke_context
|
||||
.feature_set
|
||||
.is_active(&do_support_realloc::id()),
|
||||
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user