1 //////////////////////////////////////////////////////////////////////////////
4 // ADLib, Prop and their related set of tools and documentation are in the
5 // public domain. The author(s) of this software reserve no copyrights on
6 // the source code and any code generated using the tools. You are encouraged
7 // to use ADLib and Prop to develop software, in both academic and commercial
8 // settings, and are welcomed to incorporate any part of ADLib and Prop into
11 // Although you are under no obligation to do so, we strongly recommend that
12 // you give away all software developed using our tools.
14 // We also ask that credit be given to us when ADLib and/or Prop are used in
15 // your programs, and that this notice be preserved intact in all the source
18 // This software is still under development and we welcome(read crave for)
19 // any suggestions and help from the users.
21 // Allen Leung (leunga@cs.nyu.edu)
23 //////////////////////////////////////////////////////////////////////////////
28 #include <AD/gc/gcbitmap.h>
29 #include <AD/gc/gcheaps.h>
30 #include <AD/gc/gcmacros.h>
34 //////////////////////////////////////////////////////////////////////////////
36 //////////////////////////////////////////////////////////////////////////////
38 : lowest_addr(0), highest_addr(0),
39 bitmap(0), bitmap_bot(0), bitmap_top(0), bitmap_core(0),
42 //////////////////////////////////////////////////////////////////////////////
44 //////////////////////////////////////////////////////////////////////////////
45 GCBitMap::~GCBitMap() { release(); }
47 //////////////////////////////////////////////////////////////////////////////
48 // Method to clear the entire bitmap
49 //////////////////////////////////////////////////////////////////////////////
50 void GCBitMap::clear()
51 { memset(bitmap_bot
, 0, bitmap_size
);
54 //////////////////////////////////////////////////////////////////////////////
55 // Method to release all the memory of a bitmap
56 //////////////////////////////////////////////////////////////////////////////
57 void GCBitMap::release()
60 HM::deallocate_pages_on_boundaries(bitmap_core
, bitmap_size
);
71 //////////////////////////////////////////////////////////////////////////////
72 // Method to grow the bitmap.
73 //////////////////////////////////////////////////////////////////////////////
74 void GCBitMap::grow (void * low
, void * high
)
76 // roundup to page size
77 void * real_low
= GC_TRUNC_PAGE_ADDR(low
);
78 void * real_high
= GC_ROUNDUP_PAGE_ADDR((Byte
*)high
+ 1);
80 // compute new address boundaries
81 void * new_low
= (real_low
< lowest_addr
|| lowest_addr
== 0)
82 ? real_low
: lowest_addr
;
83 void * new_high
= real_high
> highest_addr
? real_high
: highest_addr
;
85 // Check whether the boundaries have changed.
86 // If so, expand the bitmap
87 if (new_low
!= lowest_addr
|| new_high
!= highest_addr
) {
88 size_t new_size
= ((Byte
*)new_high
- (Byte
*)new_low
) /
90 new_size
= GC_ROUNDUP_PAGE_SIZE(new_size
);
91 void * new_bitmap_core
;
92 Glob
* new_bitmap_bot
=
93 (Glob
*)HM::allocate_pages_on_boundaries(new_size
, new_bitmap_core
);
95 lowest_addr
== 0 ? 0 :
96 (((Byte
*)lowest_addr
- (Byte
*)new_low
) /
97 (8 * GC_ALIGNMENT
* sizeof(Glob
)));
99 // copy old bitmap to new
100 memcpy(new_bitmap_bot
+ shift
, bitmap_bot
, bitmap_size
);
102 // clean up old bitmap and delete it
103 HM::deallocate_pages_on_boundaries(bitmap_core
, bitmap_size
);
105 // readjust bitmap pointers and offsets
106 lowest_addr
= new_low
;
107 highest_addr
= new_high
;
108 bitmap_size
= new_size
;
109 bitmap_core
= new_bitmap_core
;
110 bitmap_bot
= new_bitmap_bot
;
111 bitmap
= new_bitmap_bot
-
112 ((size_t)new_low
/ (sizeof(Glob
) * 8 * GC_ALIGNMENT
));
113 bitmap_top
= bitmap_bot
+ new_size
/ sizeof(Glob
);
116 cerr
<< "[ New bitmap at " << (void*)bitmap_bot
117 << " ... " << (void*)bitmap_top
<< " ]\n";