@@ -4,23 +4,19 @@ use crate::util::linear_scan::Region;
4
4
use crate :: vm:: VMBinding ;
5
5
use std:: sync:: atomic:: AtomicBool ;
6
6
use std:: sync:: atomic:: Ordering ;
7
- #[ cfg( feature = "ms_block_list_sanity" ) ]
8
- use std:: sync:: Mutex ;
9
7
10
8
/// List of blocks owned by the allocator
11
9
#[ repr( C ) ]
12
10
pub 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 ,
19
15
}
20
16
21
17
impl std:: fmt:: Debug for BlockList {
22
18
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 >>( ) )
24
20
}
25
21
}
26
22
@@ -31,57 +27,12 @@ impl BlockList {
31
27
last : None ,
32
28
size,
33
29
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" ) ;
70
30
}
71
31
}
72
32
73
33
/// List has no blocks
74
34
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 ( )
85
36
}
86
37
87
38
/// Remove a block from the list
@@ -109,26 +60,11 @@ impl BlockList {
109
60
next. store_prev_block ( prev) ;
110
61
}
111
62
}
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
- }
127
63
}
128
64
129
65
/// Pop the first block in the list
130
66
pub fn pop ( & mut self ) -> Option < Block > {
131
- let ret = if let Some ( head) = self . first {
67
+ if let Some ( head) = self . first {
132
68
if let Some ( next) = head. load_next_block ( ) {
133
69
self . first = Some ( next) ;
134
70
next. clear_prev_block ( ) ;
@@ -142,22 +78,7 @@ impl BlockList {
142
78
Some ( head)
143
79
} else {
144
80
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) ;
157
81
}
158
-
159
- trace ! ( "Blocklist {:?}: Pop = {:?}" , self as * const _, ret) ;
160
- ret
161
82
}
162
83
163
84
/// Push block to the front of the list
@@ -176,33 +97,10 @@ impl BlockList {
176
97
self . first = Some ( block) ;
177
98
}
178
99
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
- }
186
100
}
187
101
188
102
/// Moves all the blocks of `other` into `self`, leaving `other` empty.
189
103
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
-
206
104
debug_assert_eq ! ( self . size, other. size) ;
207
105
if !other. is_empty ( ) {
208
106
debug_assert ! (
@@ -234,26 +132,13 @@ impl BlockList {
234
132
}
235
133
other. reset ( ) ;
236
134
}
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
- }
244
135
}
245
136
246
137
/// Remove all blocks
247
138
fn reset ( & mut self ) {
248
139
trace ! ( "Blocklist {:?}: Reset" , self as * const _) ;
249
140
self . first = None ;
250
141
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
- }
257
142
}
258
143
259
144
/// Lock the list. The MiMalloc allocator mostly uses thread-local block lists, and those operations on the list
@@ -294,24 +179,6 @@ impl BlockList {
294
179
}
295
180
}
296
181
}
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
- }
315
182
}
316
183
317
184
pub struct BlockListIterator {
0 commit comments