2
2
extern crate lazy_static;
3
3
4
4
use std:: collections:: HashMap ;
5
- use std:: ops:: Range ;
6
5
use std:: ptr:: null_mut;
7
6
use std:: sync:: atomic:: AtomicUsize ;
8
7
use std:: sync:: Mutex ;
9
8
9
+ use edges:: { OpenJDKEdge , OpenJDKEdgeRange } ;
10
10
use libc:: { c_char, c_void, uintptr_t} ;
11
11
use mmtk:: util:: alloc:: AllocationError ;
12
12
use mmtk:: util:: opaque_pointer:: * ;
13
13
use mmtk:: util:: { Address , ObjectReference } ;
14
- use mmtk:: vm:: edge_shape:: { AddressRangeIterator , Edge , MemorySlice } ;
15
14
use mmtk:: vm:: VMBinding ;
16
15
use mmtk:: { MMTKBuilder , Mutator , MMTK } ;
17
16
@@ -20,6 +19,7 @@ pub mod active_plan;
20
19
pub mod api;
21
20
mod build_info;
22
21
pub mod collection;
22
+ mod edges;
23
23
mod gc_work;
24
24
pub mod object_model;
25
25
mod object_scanning;
@@ -136,103 +136,6 @@ pub static FREE_LIST_ALLOCATOR_SIZE: uintptr_t =
136
136
#[ derive( Default ) ]
137
137
pub struct OpenJDK ;
138
138
139
- /// The type of edges in OpenJDK.
140
- /// Currently it has the same layout as `Address`, but we override its load and store methods.
141
- #[ derive( Clone , Copy , PartialEq , Eq , Hash , Debug ) ]
142
- #[ repr( transparent) ]
143
- pub struct OpenJDKEdge {
144
- pub addr : Address ,
145
- }
146
-
147
- impl From < Address > for OpenJDKEdge {
148
- fn from ( value : Address ) -> Self {
149
- Self { addr : value }
150
- }
151
- }
152
-
153
- impl Edge for OpenJDKEdge {
154
- fn load ( & self ) -> ObjectReference {
155
- if cfg ! ( any( target_arch = "x86" , target_arch = "x86_64" ) ) {
156
- // Workaround: On x86 (including x86_64), machine instructions may contain pointers as
157
- // immediates, and they may be unaligned. It is an undefined behavior in Rust to
158
- // dereference unaligned pointers. We have to explicitly use unaligned memory access
159
- // methods. On x86, ordinary MOV instructions can load and store memory at unaligned
160
- // addresses, so we expect `ptr.read_unaligned()` to have no performance penalty over
161
- // `ptr.read()` if `ptr` is actually aligned.
162
- unsafe {
163
- let ptr = self . addr . to_ptr :: < ObjectReference > ( ) ;
164
- ptr. read_unaligned ( )
165
- }
166
- } else {
167
- unsafe { self . addr . load ( ) }
168
- }
169
- }
170
-
171
- fn store ( & self , object : ObjectReference ) {
172
- if cfg ! ( any( target_arch = "x86" , target_arch = "x86_64" ) ) {
173
- unsafe {
174
- let ptr = self . addr . to_mut_ptr :: < ObjectReference > ( ) ;
175
- ptr. write_unaligned ( object)
176
- }
177
- } else {
178
- unsafe { self . addr . store ( object) }
179
- }
180
- }
181
- }
182
-
183
- /// A range of OpenJDKEdge, usually used for arrays.
184
- #[ derive( Clone , PartialEq , Eq , Hash , Debug ) ]
185
- pub struct OpenJDKEdgeRange {
186
- range : Range < Address > ,
187
- }
188
-
189
- impl From < Range < Address > > for OpenJDKEdgeRange {
190
- fn from ( value : Range < Address > ) -> Self {
191
- Self { range : value }
192
- }
193
- }
194
-
195
- pub struct OpenJDKEdgeRangeIterator {
196
- inner : AddressRangeIterator ,
197
- }
198
-
199
- impl Iterator for OpenJDKEdgeRangeIterator {
200
- type Item = OpenJDKEdge ;
201
-
202
- fn next ( & mut self ) -> Option < Self :: Item > {
203
- self . inner . next ( ) . map ( |a| a. into ( ) )
204
- }
205
- }
206
-
207
- // Note that we cannot implement MemorySlice for `Range<OpenJDKEdgeRange>` because neither
208
- // `MemorySlice` nor `Range<T>` are defined in the `mmtk-openjdk` crate. ("orphan rule")
209
- impl MemorySlice for OpenJDKEdgeRange {
210
- type Edge = OpenJDKEdge ;
211
- type EdgeIterator = OpenJDKEdgeRangeIterator ;
212
-
213
- fn iter_edges ( & self ) -> Self :: EdgeIterator {
214
- OpenJDKEdgeRangeIterator {
215
- inner : self . range . iter_edges ( ) ,
216
- }
217
- }
218
-
219
- fn object ( & self ) -> Option < ObjectReference > {
220
- self . range . object ( )
221
- }
222
-
223
- fn start ( & self ) -> Address {
224
- self . range . start ( )
225
- }
226
-
227
- fn bytes ( & self ) -> usize {
228
- self . range . bytes ( )
229
- }
230
-
231
- fn copy ( src : & Self , tgt : & Self ) {
232
- MemorySlice :: copy ( & src. range , & tgt. range )
233
- }
234
- }
235
-
236
139
impl VMBinding for OpenJDK {
237
140
type VMObjectModel = object_model:: VMObjectModel ;
238
141
type VMScanning = scanning:: VMScanning ;
0 commit comments