@@ -4,23 +4,19 @@ use crate::util::linear_scan::Region;
44use crate :: vm:: VMBinding ;
55use std:: sync:: atomic:: AtomicBool ;
66use std:: sync:: atomic:: Ordering ;
7- #[ cfg( feature = "ms_block_list_sanity" ) ]
8- use std:: sync:: Mutex ;
97
108/// List of blocks owned by the allocator
119#[ repr( C ) ]
1210pub struct BlockList {
13- first : Option < Block > ,
14- last : Option < Block > ,
15- size : usize ,
16- lock : AtomicBool ,
17- #[ cfg( feature = "ms_block_list_sanity" ) ]
18- sanity_list : Mutex < Vec < Block > > ,
11+ pub first : Option < Block > ,
12+ pub last : Option < Block > ,
13+ pub size : usize ,
14+ pub lock : AtomicBool ,
1915}
2016
2117impl std:: fmt:: Debug for BlockList {
2218 fn fmt ( & self , f : & mut std:: fmt:: Formatter ) -> std:: fmt:: Result {
23- write ! ( f, "{:?}" , self . iter( ) . collect:: <Vec <Block >>( ) )
19+ write ! ( f, "BlockList {:?}" , self . iter( ) . collect:: <Vec <Block >>( ) )
2420 }
2521}
2622
@@ -31,57 +27,12 @@ impl BlockList {
3127 last : None ,
3228 size,
3329 lock : AtomicBool :: new ( false ) ,
34- #[ cfg( feature = "ms_block_list_sanity" ) ]
35- sanity_list : Mutex :: new ( vec ! [ ] ) ,
36- }
37- }
38-
39- // fn access_block_list<R: Copy, F: FnOnce() -> R>(&self, access_func: F) -> R {
40- // #[cfg(feature = "ms_block_list_sanity")]
41- // let mut sanity_list = self.sanity_list.lock().unwrap();
42-
43- // let ret = access_func();
44-
45- // // Verify the block list is the same as the sanity list
46- // #[cfg(feature = "ms_block_list_sanity")]
47- // {
48- // if !sanity_list.iter().map(|b| *b).eq(BlockListIterator { cursor: self.first }) {
49- // eprintln!("Sanity block list: {:?}", &mut sanity_list as &mut Vec<Block>);
50- // eprintln!("Actual block list: {:?}", self);
51- // panic!("Incorrect block list");
52- // }
53- // }
54-
55- // ret
56- // }
57- #[ cfg( feature = "ms_block_list_sanity" ) ]
58- fn verify_block_list ( & self , sanity_list : & mut Vec < Block > ) {
59- if !sanity_list
60- . iter ( )
61- . map ( |b| * b)
62- . eq ( BlockListIterator { cursor : self . first } )
63- {
64- eprintln ! ( "Sanity block list: {:?}" , sanity_list) ;
65- eprintln ! ( "First {:?}" , sanity_list. get( 0 ) ) ;
66- eprintln ! ( "Actual block list: {:?}" , self ) ;
67- eprintln ! ( "First {:?}" , self . first) ;
68- eprintln ! ( "Block list {:?}" , self as * const _) ;
69- panic ! ( "Incorrect block list" ) ;
7030 }
7131 }
7232
7333 /// List has no blocks
7434 pub fn is_empty ( & self ) -> bool {
75- let ret = self . first . is_none ( ) ;
76-
77- #[ cfg( feature = "ms_block_list_sanity" ) ]
78- {
79- let mut sanity_list = self . sanity_list . lock ( ) . unwrap ( ) ;
80- self . verify_block_list ( & mut sanity_list) ;
81- assert_eq ! ( sanity_list. is_empty( ) , ret) ;
82- }
83-
84- ret
35+ self . first . is_none ( )
8536 }
8637
8738 /// Remove a block from the list
@@ -109,26 +60,11 @@ impl BlockList {
10960 next. store_prev_block ( prev) ;
11061 }
11162 }
112-
113- #[ cfg( feature = "ms_block_list_sanity" ) ]
114- {
115- let mut sanity_list = self . sanity_list . lock ( ) . unwrap ( ) ;
116- if let Some ( ( index, _) ) = sanity_list
117- . iter ( )
118- . enumerate ( )
119- . find ( |& ( _, & val) | val == block)
120- {
121- sanity_list. remove ( index) ;
122- } else {
123- panic ! ( "Cannot find {:?} in the block list" , block) ;
124- }
125- self . verify_block_list ( & mut sanity_list) ;
126- }
12763 }
12864
12965 /// Pop the first block in the list
13066 pub fn pop ( & mut self ) -> Option < Block > {
131- let ret = if let Some ( head) = self . first {
67+ if let Some ( head) = self . first {
13268 if let Some ( next) = head. load_next_block ( ) {
13369 self . first = Some ( next) ;
13470 next. clear_prev_block ( ) ;
@@ -142,22 +78,7 @@ impl BlockList {
14278 Some ( head)
14379 } else {
14480 None
145- } ;
146-
147- #[ cfg( feature = "ms_block_list_sanity" ) ]
148- {
149- let mut sanity_list = self . sanity_list . lock ( ) . unwrap ( ) ;
150- let sanity_ret = if sanity_list. is_empty ( ) {
151- None
152- } else {
153- Some ( sanity_list. remove ( 0 ) ) // pop first
154- } ;
155- self . verify_block_list ( & mut sanity_list) ;
156- assert_eq ! ( sanity_ret, ret) ;
15781 }
158-
159- trace ! ( "Blocklist {:?}: Pop = {:?}" , self as * const _, ret) ;
160- ret
16182 }
16283
16384 /// Push block to the front of the list
@@ -176,33 +97,10 @@ impl BlockList {
17697 self . first = Some ( block) ;
17798 }
17899 block. store_block_list ( self ) ;
179-
180- #[ cfg( feature = "ms_block_list_sanity" ) ]
181- {
182- let mut sanity_list = self . sanity_list . lock ( ) . unwrap ( ) ;
183- sanity_list. insert ( 0 , block) ; // push front
184- self . verify_block_list ( & mut sanity_list) ;
185- }
186100 }
187101
188102 /// Moves all the blocks of `other` into `self`, leaving `other` empty.
189103 pub fn append ( & mut self , other : & mut BlockList ) {
190- trace ! (
191- "Blocklist {:?}: Append Blocklist {:?}" ,
192- self as * const _,
193- other as * const _
194- ) ;
195- #[ cfg( feature = "ms_block_list_sanity" ) ]
196- {
197- // Check before merging
198- let mut sanity_list = self . sanity_list . lock ( ) . unwrap ( ) ;
199- self . verify_block_list ( & mut sanity_list) ;
200- let mut sanity_list_other = other. sanity_list . lock ( ) . unwrap ( ) ;
201- other. verify_block_list ( & mut sanity_list_other) ;
202- }
203- #[ cfg( feature = "ms_block_list_sanity" ) ]
204- let mut sanity_list_in_other = other. sanity_list . lock ( ) . unwrap ( ) . clone ( ) ;
205-
206104 debug_assert_eq ! ( self . size, other. size) ;
207105 if !other. is_empty ( ) {
208106 debug_assert ! (
@@ -234,26 +132,13 @@ impl BlockList {
234132 }
235133 other. reset ( ) ;
236134 }
237-
238- #[ cfg( feature = "ms_block_list_sanity" ) ]
239- {
240- let mut sanity_list = self . sanity_list . lock ( ) . unwrap ( ) ;
241- sanity_list. append ( & mut sanity_list_in_other) ;
242- self . verify_block_list ( & mut sanity_list) ;
243- }
244135 }
245136
246137 /// Remove all blocks
247138 fn reset ( & mut self ) {
248139 trace ! ( "Blocklist {:?}: Reset" , self as * const _) ;
249140 self . first = None ;
250141 self . last = None ;
251-
252- #[ cfg( feature = "ms_block_list_sanity" ) ]
253- {
254- let mut sanity_list = self . sanity_list . lock ( ) . unwrap ( ) ;
255- sanity_list. clear ( ) ;
256- }
257142 }
258143
259144 /// Lock the list. The MiMalloc allocator mostly uses thread-local block lists, and those operations on the list
@@ -294,24 +179,6 @@ impl BlockList {
294179 }
295180 }
296181 }
297-
298- /// Get the size of this block list.
299- pub fn size ( & self ) -> usize {
300- let ret = self . size ;
301-
302- #[ cfg( feature = "ms_block_list_sanity" ) ]
303- {
304- let mut sanity_list = self . sanity_list . lock ( ) . unwrap ( ) ;
305- self . verify_block_list ( & mut sanity_list) ;
306- }
307-
308- ret
309- }
310-
311- /// Get the first block in the list.
312- pub fn first ( & self ) -> Option < Block > {
313- self . first
314- }
315182}
316183
317184pub struct BlockListIterator {
0 commit comments