1
+ use std:: ptr:: copy_nonoverlapping;
2
+
3
+ use crate :: abi:: { RubyObjectAccess , MIN_OBJ_ALIGN , OBJREF_OFFSET } ;
1
4
use crate :: { abi, Ruby } ;
2
5
use mmtk:: util:: copy:: { CopySemantics , GCWorkerCopyContext } ;
3
6
use mmtk:: util:: { Address , ObjectReference } ;
@@ -32,32 +35,37 @@ impl ObjectModel<Ruby> for VMObjectModel {
32
35
const OBJECT_REF_OFFSET_LOWER_BOUND : isize = Self :: OBJREF_OFFSET as isize ;
33
36
34
37
fn copy (
35
- _from : ObjectReference ,
36
- _semantics : CopySemantics ,
37
- _copy_context : & mut GCWorkerCopyContext < Ruby > ,
38
+ from : ObjectReference ,
39
+ semantics : CopySemantics ,
40
+ copy_context : & mut GCWorkerCopyContext < Ruby > ,
38
41
) -> ObjectReference {
39
- todo ! ( )
42
+ let from_acc = RubyObjectAccess :: from_objref ( from) ;
43
+ let from_start = from_acc. obj_start ( ) ;
44
+ let object_size = from_acc. object_size ( ) ;
45
+ let to_start = copy_context. alloc_copy ( from, object_size, MIN_OBJ_ALIGN , 0 , semantics) ;
46
+ let to_payload = to_start. add ( OBJREF_OFFSET ) ;
47
+ unsafe {
48
+ copy_nonoverlapping :: < u8 > ( from_start. to_ptr ( ) , to_start. to_mut_ptr ( ) , object_size) ;
49
+ }
50
+ let to_obj = ObjectReference :: from_raw_address ( to_payload) ;
51
+ copy_context. post_copy ( to_obj, object_size, semantics) ;
52
+ to_obj
40
53
}
41
54
42
55
fn copy_to ( _from : ObjectReference , _to : ObjectReference , _region : Address ) -> Address {
43
- todo ! ( )
56
+ unimplemented ! (
57
+ "This function cannot be called because we do not support MarkCompact for Ruby."
58
+ )
44
59
}
45
60
46
61
fn get_reference_when_copied_to ( _from : ObjectReference , _to : Address ) -> ObjectReference {
47
- todo ! ( )
62
+ unimplemented ! (
63
+ "This function cannot be called because we do not support MarkCompact for Ruby."
64
+ )
48
65
}
49
66
50
67
fn get_current_size ( object : ObjectReference ) -> usize {
51
- // Currently, a hidden size field of word size is placed before each object.
52
- let prefix_size = abi:: OBJREF_OFFSET ;
53
-
54
- // That hidden field holds the payload size.
55
- let start = Self :: ref_to_object_start ( object) ;
56
- let payload_size = unsafe { start. load :: < usize > ( ) } ;
57
-
58
- // In RACTOR_CHECK_MODE, Ruby hides a field after each object to hold the Ractor ID.
59
- let suffix_size = unsafe { crate :: BINDING_FAST . suffix_size } ;
60
- prefix_size + payload_size + suffix_size
68
+ RubyObjectAccess :: from_objref ( object) . object_size ( )
61
69
}
62
70
63
71
fn get_type_descriptor ( _reference : ObjectReference ) -> & ' static [ i8 ] {
@@ -69,11 +77,11 @@ impl ObjectModel<Ruby> for VMObjectModel {
69
77
}
70
78
71
79
fn ref_to_object_start ( object : ObjectReference ) -> Address {
72
- object. to_raw_address ( ) - Self :: OBJREF_OFFSET
80
+ RubyObjectAccess :: from_objref ( object) . obj_start ( )
73
81
}
74
82
75
83
fn ref_to_header ( object : ObjectReference ) -> Address {
76
- object. to_raw_address ( )
84
+ RubyObjectAccess :: from_objref ( object) . payload_addr ( )
77
85
}
78
86
79
87
fn address_to_ref ( addr : Address ) -> ObjectReference {
0 commit comments