75 // return NULL.
76 HeapWord* allocate(size_t word_sz) {
77 HeapWord* res = _top;
78 if (pointer_delta(_end, _top) >= word_sz) {
79 _top = _top + word_sz;
80 return res;
81 } else {
82 return NULL;
83 }
84 }
85
86 // Undo the last allocation in the buffer, which is required to be of the
87 // "obj" of the given "word_sz".
88 void undo_allocation(HeapWord* obj, size_t word_sz) {
89 assert(pointer_delta(_top, _bottom) >= word_sz, "Bad undo");
90 assert(pointer_delta(_top, obj) == word_sz, "Bad undo");
91 _top = obj;
92 }
93
94 // The total (word) size of the buffer, including both allocated and
95 // unallocted space.
96 size_t word_sz() { return _word_sz; }
97
98 // Should only be done if we are about to reset with a new buffer of the
99 // given size.
100 void set_word_size(size_t new_word_sz) {
101 assert(new_word_sz > AlignmentReserve, "Too small");
102 _word_sz = new_word_sz;
103 }
104
105 // The number of words of unallocated space remaining in the buffer.
106 size_t words_remaining() {
107 assert(_end >= _top, "Negative buffer");
108 return pointer_delta(_end, _top, HeapWordSize);
109 }
110
111 bool contains(void* addr) {
112 return (void*)_bottom <= addr && addr < (void*)_hard_end;
113 }
114
115 // Sets the space of the buffer to be [buf, space+word_sz()).
|
75 // return NULL.
76 HeapWord* allocate(size_t word_sz) {
77 HeapWord* res = _top;
78 if (pointer_delta(_end, _top) >= word_sz) {
79 _top = _top + word_sz;
80 return res;
81 } else {
82 return NULL;
83 }
84 }
85
86 // Undo the last allocation in the buffer, which is required to be of the
87 // "obj" of the given "word_sz".
88 void undo_allocation(HeapWord* obj, size_t word_sz) {
89 assert(pointer_delta(_top, _bottom) >= word_sz, "Bad undo");
90 assert(pointer_delta(_top, obj) == word_sz, "Bad undo");
91 _top = obj;
92 }
93
94 // The total (word) size of the buffer, including both allocated and
95 // unallocated space.
96 size_t word_sz() { return _word_sz; }
97
98 // Should only be done if we are about to reset with a new buffer of the
99 // given size.
100 void set_word_size(size_t new_word_sz) {
101 assert(new_word_sz > AlignmentReserve, "Too small");
102 _word_sz = new_word_sz;
103 }
104
105 // The number of words of unallocated space remaining in the buffer.
106 size_t words_remaining() {
107 assert(_end >= _top, "Negative buffer");
108 return pointer_delta(_end, _top, HeapWordSize);
109 }
110
111 bool contains(void* addr) {
112 return (void*)_bottom <= addr && addr < (void*)_hard_end;
113 }
114
115 // Sets the space of the buffer to be [buf, space+word_sz()).
|