Skip to content

Commit

Permalink
rt: Remove NewConstpol again
Browse files Browse the repository at this point in the history
  • Loading branch information
dinfuehr committed Jan 5, 2025
1 parent 04d069f commit cd9fde0
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 75 deletions.
1 change: 0 additions & 1 deletion dora-runtime/src/boots/deserializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ pub fn decode_code_descriptor(reader: &mut ByteReader) -> CodeDescriptor {
code,
comments,
constpool,
new_constpool: None,
lazy_compilation,
gcpoints,
positions,
Expand Down
59 changes: 1 addition & 58 deletions dora-runtime/src/masm.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use byteorder::{BigEndian, WriteBytesExt};

use std::cell::Cell;
use std::ops::Deref;
use std::rc::Rc;
Expand Down Expand Up @@ -44,52 +42,6 @@ pub enum Mem {
Offset(Reg, i32, i32),
}

struct NewConstPool {
data: Vec<u8>,
}

impl NewConstPool {
fn new() -> NewConstPool {
NewConstPool { data: Vec::new() }
}

fn add_addr(&mut self, value: Address) -> usize {
self.align(std::mem::size_of::<usize>());
self.data
.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::<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::<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::<BigEndian>(value).unwrap();
self.data.len()
}

fn align(&mut self, alignment: usize) -> usize {
let off = self.data.len() % alignment;
if off != 0 {
assert!(alignment > off);
self.data.extend(std::iter::repeat_n(0, alignment - off));
}
assert_eq!(self.data.len() % alignment, 0);
self.data.len()
}
}

pub enum EpilogConstant {
Float32(f32),
Float64(f64),
Expand All @@ -103,7 +55,6 @@ pub struct MacroAssembler {
bailouts: Vec<(Label, Trap, Location)>,
lazy_compilation: LazyCompilationData,
constpool: ConstPool,
new_constpool: NewConstPool,
epilog_constants: Vec<(Label, EpilogConstant)>,
gcpoints: GcPointTable,
comments: CommentTable,
Expand All @@ -119,7 +70,6 @@ impl MacroAssembler {
bailouts: Vec::new(),
lazy_compilation: LazyCompilationData::new(),
constpool: ConstPool::new(),
new_constpool: NewConstPool::new(),
epilog_constants: Vec::new(),
gcpoints: GcPointTable::new(),
comments: CommentTable::new(),
Expand All @@ -141,8 +91,6 @@ impl MacroAssembler {

// Align data such that code start is properly aligned.
let cp_size = self.constpool.align(CODE_ALIGNMENT as i32);
let new_cp_size = self.new_constpool.align(CODE_ALIGNMENT);
assert_eq!(cp_size, new_cp_size as i32);

let asm = self.asm.finalize(CODE_ALIGNMENT);

Expand All @@ -158,11 +106,8 @@ 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 Expand Up @@ -223,9 +168,7 @@ impl MacroAssembler {
}

pub fn add_const_addr(&mut self, ptr: Address) -> i32 {
let result = self.constpool.add_addr(ptr);
assert_eq!(result, self.new_constpool.add_addr(ptr) as i32);
result
self.constpool.add_addr(ptr)
}

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

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());
}
// Fill constant pool.
code_descriptor
.constpool
.install(object_payload_start.to_ptr());

// Copy machine code into object.
unsafe {
Expand Down Expand Up @@ -279,7 +268,6 @@ 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 cd9fde0

Please sign in to comment.