diff --git a/dora-runtime/src/boots/deserializer.rs b/dora-runtime/src/boots/deserializer.rs index 5b760ed22..ef2daea9a 100644 --- a/dora-runtime/src/boots/deserializer.rs +++ b/dora-runtime/src/boots/deserializer.rs @@ -22,6 +22,7 @@ pub fn decode_code_descriptor(reader: &mut ByteReader) -> CodeDescriptor { code, comments, constpool, + new_constpool: None, lazy_compilation, gcpoints, positions, diff --git a/dora-runtime/src/masm.rs b/dora-runtime/src/masm.rs index 37c17e47b..cebae1f5f 100644 --- a/dora-runtime/src/masm.rs +++ b/dora-runtime/src/masm.rs @@ -1,4 +1,4 @@ -use byteorder::{LittleEndian, WriteBytesExt}; +use byteorder::{BigEndian, WriteBytesExt}; use std::cell::Cell; use std::ops::Deref; @@ -56,26 +56,26 @@ impl NewConstPool { fn add_addr(&mut self, value: Address) -> usize { self.align(std::mem::size_of::()); self.data - .write_u64::(value.to_usize() as u64) + .write_u64::(value.to_usize() as u64) .unwrap(); self.data.len() } fn add_f32(&mut self, value: f32) -> usize { self.align(std::mem::size_of::()); - self.data.write_f32::(value).unwrap(); + self.data.write_f32::(value).unwrap(); self.data.len() } fn add_f64(&mut self, value: f64) -> usize { self.align(std::mem::size_of::()); - self.data.write_f64::(value).unwrap(); + self.data.write_f64::(value).unwrap(); self.data.len() } fn add_i128(&mut self, value: i128) -> usize { self.align(std::mem::size_of::()); - self.data.write_i128::(value).unwrap(); + self.data.write_i128::(value).unwrap(); self.data.len() } @@ -146,8 +146,11 @@ impl MacroAssembler { }) .collect::>(); + 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, diff --git a/dora-runtime/src/vm/code.rs b/dora-runtime/src/vm/code.rs index 35ba8d8a9..3b899fb65 100644 --- a/dora-runtime/src/vm/code.rs +++ b/dora-runtime/src/vm/code.rs @@ -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 { @@ -268,6 +279,7 @@ impl fmt::Debug for Code { pub struct CodeDescriptor { pub constpool: ConstPool, + pub new_constpool: Option>, pub code: Vec, pub lazy_compilation: LazyCompilationData, pub gcpoints: GcPointTable,