Skip to content

Commit

Permalink
rt: Start using new constpool for cannon
Browse files Browse the repository at this point in the history
  • Loading branch information
dinfuehr committed Jan 1, 2025
1 parent b6ec367 commit 5819b19
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
1 change: 1 addition & 0 deletions dora-runtime/src/boots/deserializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub fn decode_code_descriptor(reader: &mut ByteReader) -> CodeDescriptor {
code,
comments,
constpool,
new_constpool: None,
lazy_compilation,
gcpoints,
positions,
Expand Down
13 changes: 8 additions & 5 deletions dora-runtime/src/masm.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use byteorder::{LittleEndian, WriteBytesExt};
use byteorder::{BigEndian, WriteBytesExt};

use std::cell::Cell;
use std::ops::Deref;
Expand Down Expand Up @@ -56,26 +56,26 @@ impl NewConstPool {
fn add_addr(&mut self, value: Address) -> usize {
self.align(std::mem::size_of::<usize>());
self.data
.write_u64::<LittleEndian>(value.to_usize() as u64)
.write_u64::<BigEndian>(value.to_usize() as u64)
.unwrap();
self.data.len()
}

fn add_f32(&mut self, value: f32) -> usize {
self.align(std::mem::size_of::<f32>());
self.data.write_f32::<LittleEndian>(value).unwrap();
self.data.write_f32::<BigEndian>(value).unwrap();
self.data.len()
}

fn add_f64(&mut self, value: f64) -> usize {
self.align(std::mem::size_of::<f64>());
self.data.write_f64::<LittleEndian>(value).unwrap();
self.data.write_f64::<BigEndian>(value).unwrap();
self.data.len()
}

fn add_i128(&mut self, value: i128) -> usize {
self.align(std::mem::size_of::<i128>());
self.data.write_i128::<LittleEndian>(value).unwrap();
self.data.write_i128::<BigEndian>(value).unwrap();
self.data.len()
}

Expand Down Expand Up @@ -146,8 +146,11 @@ impl MacroAssembler {
})
.collect::<Vec<_>>();

let new_constpool = self.new_constpool.data.into_iter().rev().collect();

CodeDescriptor {
constpool: self.constpool,
new_constpool: Some(new_constpool),
code: asm.code(),
lazy_compilation: self.lazy_compilation,
gcpoints: self.gcpoints,
Expand Down
20 changes: 16 additions & 4 deletions dora-runtime/src/vm/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,21 @@ pub fn install_code(vm: &VM, code_descriptor: CodeDescriptor, kind: CodeKind) ->
code_header.native_code_object = Address::null();
code_header.padding = 0;

// Fill constant pool.
code_descriptor
.constpool
.install(object_payload_start.to_ptr());
if let Some(new_constpool) = code_descriptor.new_constpool {
// Copy embedded constants into object.
unsafe {
ptr::copy_nonoverlapping(
new_constpool.as_ptr(),
object_payload_start.to_mut_ptr(),
new_constpool.len(),
);
}
} else {
// Fill constant pool.
code_descriptor
.constpool
.install(object_payload_start.to_ptr());
}

// Copy machine code into object.
unsafe {
Expand Down Expand Up @@ -268,6 +279,7 @@ impl fmt::Debug for Code {

pub struct CodeDescriptor {
pub constpool: ConstPool,
pub new_constpool: Option<Vec<u8>>,
pub code: Vec<u8>,
pub lazy_compilation: LazyCompilationData,
pub gcpoints: GcPointTable,
Expand Down

0 comments on commit 5819b19

Please sign in to comment.