10
10
#include " builtin/io.hpp"
11
11
12
12
#include " call_frame.hpp"
13
+ #include " configuration.hpp"
13
14
14
15
#include " gc/gc.hpp"
15
16
@@ -31,27 +32,16 @@ namespace rubinius {
31
32
* - Heap A and Heap B, which get one quarter of the heap each. Heaps A and B
32
33
* alternate between being the Current and Next space on each collection.
33
34
*/
34
- BakerGC::BakerGC (ObjectMemory *om, size_t bytes )
35
+ BakerGC::BakerGC (ObjectMemory *om, Configuration& config )
35
36
: GarbageCollector(om)
36
- , full(new Heap(bytes))
37
- , eden(new Heap(full->allocate (bytes / 2 ), bytes / 2))
38
- , heap_a(new Heap(full->allocate (bytes / 4 ), bytes / 4))
39
- , heap_b(new Heap(full->allocate (bytes / 4 ), bytes / 4))
40
- , full_new(NULL )
41
- , eden_new(NULL )
42
- , heap_a_new(NULL )
43
- , heap_b_new(NULL )
37
+ , bytes_(config.gc_young_bytes * 2 )
38
+ , full(new Heap(bytes_))
39
+ , eden(new Heap(full->allocate (bytes_ / 2 ), bytes_ / 2))
40
+ , heap_a(new Heap(full->allocate (bytes_ / 4 ), bytes_ / 4))
41
+ , heap_b(new Heap(full->allocate (bytes_ / 4 ), bytes_ / 4))
44
42
, current(heap_a)
45
43
, next(heap_b)
46
- , total_objects(0 )
47
- , current_byte_size_(bytes)
48
- , requested_byte_size_(bytes)
49
- , original_lifetime_(1 )
50
- , lifetime_(1 )
51
- , copy_spills_(0 )
52
- , promoted_objects_(0 )
53
- , tune_threshold_(0 )
54
- , autotune_lifetime_(false )
44
+ , lifetime_(config.gc_young_lifetime)
55
45
{
56
46
reset ();
57
47
}
@@ -98,9 +88,7 @@ namespace rubinius {
98
88
} else if (likely (next->enough_space_p (
99
89
obj->size_in_bytes (object_memory_->state ())))) {
100
90
copy = next->move_object (object_memory_->state (), obj);
101
- total_objects++;
102
91
} else {
103
- copy_spills_++;
104
92
copy = object_memory_->promote_object (obj);
105
93
promoted_push (copy);
106
94
}
@@ -137,18 +125,10 @@ namespace rubinius {
137
125
return next->fully_scanned_p ();
138
126
}
139
127
140
- const static double cOverFullThreshold = 95.0 ;
141
- const static int cOverFullTimes = 3 ;
142
- const static size_t cMinimumLifetime = 1 ;
143
-
144
- const static double cUnderFullThreshold = 20.0 ;
145
- const static int cUnderFullTimes = -3 ;
146
- const static size_t cMaximumLifetime = 6 ;
147
-
148
128
/* *
149
129
* Perform garbage collection on the young objects.
150
130
*/
151
- void BakerGC::collect (GCData* data, YoungCollectStats* stats ) {
131
+ void BakerGC::collect (GCData* data) {
152
132
153
133
#ifdef HAVE_VALGRIND_H
154
134
(void )VALGRIND_MAKE_MEM_DEFINED (next->start ().as_int (), next->size ());
@@ -157,15 +137,8 @@ namespace rubinius {
157
137
mprotect (next->start (), next->size (), PROT_READ | PROT_WRITE);
158
138
mprotect (current->start (), current->size (), PROT_READ | PROT_WRITE);
159
139
160
- check_growth_start ();
161
-
162
140
ObjectArray *current_rs = object_memory_->swap_remember_set ();
163
141
164
- total_objects = 0 ;
165
-
166
- copy_spills_ = 0 ;
167
- reset_promoted ();
168
-
169
142
// Start by copying objects in the remember set
170
143
for (ObjectArray::iterator oi = current_rs->begin ();
171
144
oi != current_rs->end ();
@@ -199,7 +172,10 @@ namespace rubinius {
199
172
}
200
173
}
201
174
202
- for (Allocator<capi::Handle >::Iterator i (data->handles ()->allocator ()); i.more (); i.advance ()) {
175
+ for (Allocator<capi::Handle >::Iterator i (data->handles ()->allocator ());
176
+ i.more ();
177
+ i.advance ())
178
+ {
203
179
if (!i->in_use_p ()) continue ;
204
180
205
181
if (!i->weak_p () && i->object ()->young_object_p ()) {
@@ -293,47 +269,9 @@ namespace rubinius {
293
269
Heap* x = next;
294
270
next = current;
295
271
current = x;
296
-
297
- if (stats) {
298
- stats->lifetime = lifetime_;
299
- stats->percentage_used = current->percentage_used ();
300
- stats->promoted_objects = promoted_objects_;
301
- stats->excess_objects = copy_spills_;
302
- }
303
-
304
- // Tune the age at which promotion occurs
305
- if (autotune_lifetime_) {
306
- double used = current->percentage_used ();
307
- if (used > cOverFullThreshold) {
308
- if (tune_threshold_ >= cOverFullTimes) {
309
- if (lifetime_ > cMinimumLifetime) lifetime_--;
310
- } else {
311
- tune_threshold_++;
312
- }
313
- } else if (used < cUnderFullThreshold) {
314
- if (tune_threshold_ <= cUnderFullTimes) {
315
- if (lifetime_ < cMaximumLifetime) lifetime_++;
316
- } else {
317
- tune_threshold_--;
318
- }
319
- } else if (tune_threshold_ > 0 ) {
320
- tune_threshold_--;
321
- } else if (tune_threshold_ < 0 ) {
322
- tune_threshold_++;
323
- } else if (tune_threshold_ == 0 ) {
324
- if (lifetime_ < original_lifetime_) {
325
- lifetime_++;
326
- } else if (lifetime_ > original_lifetime_) {
327
- lifetime_--;
328
- }
329
- }
330
- }
331
-
332
272
}
333
273
334
274
void BakerGC::reset () {
335
- check_growth_finish ();
336
-
337
275
next->reset ();
338
276
eden->reset ();
339
277
@@ -362,41 +300,6 @@ namespace rubinius {
362
300
return true ;
363
301
}
364
302
365
- void BakerGC::check_growth_start () {
366
- if (unlikely (current_byte_size_ != requested_byte_size_)) {
367
-
368
- full_new = new Heap (requested_byte_size_);
369
- eden_new = new Heap (full_new->allocate (requested_byte_size_ / 2 ), requested_byte_size_ / 2 );
370
- heap_a_new = new Heap (full_new->allocate (requested_byte_size_ / 4 ), requested_byte_size_ / 4 );
371
- heap_b_new = new Heap (full_new->allocate (requested_byte_size_ / 4 ), requested_byte_size_ / 4 );
372
-
373
- // Install the next pointer so we move objects to the new memory space.
374
- next = heap_a_new;
375
- }
376
- }
377
-
378
- void BakerGC::check_growth_finish () {
379
- if (unlikely (full_new)) {
380
- delete heap_a;
381
- delete heap_b;
382
- delete eden;
383
- delete full;
384
- heap_a = heap_a_new;
385
- heap_b = heap_b_new;
386
- eden = eden_new;
387
- full = full_new;
388
- current = heap_a_new;
389
- next = heap_b_new;
390
-
391
- heap_a_new = NULL ;
392
- heap_b_new = NULL ;
393
- eden_new = NULL ;
394
- full_new = NULL ;
395
-
396
- current_byte_size_ = requested_byte_size_;
397
- }
398
- }
399
-
400
303
void BakerGC::scan_mark_set () {
401
304
// Scan any mature objects in the mark set
402
305
// since they might refer to young objects.
0 commit comments