1 /*
2 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_GC_G1_G1OOPSTARCHUNKEDLIST_INLINE_HPP
26 #define SHARE_GC_G1_G1OOPSTARCHUNKEDLIST_INLINE_HPP
27
28 #include "gc/g1/g1OopStarChunkedList.hpp"
29 #include "gc/g1/g1CollectedHeap.inline.hpp"
30 #include "memory/allocation.inline.hpp"
31 #include "memory/iterator.hpp"
32
33 template <typename T>
push(ChunkedList<T *,mtGC> ** field,T * p)34 inline void G1OopStarChunkedList::push(ChunkedList<T*, mtGC>** field, T* p) {
35 ChunkedList<T*, mtGC>* list = *field;
36 if (list == NULL) {
37 *field = new ChunkedList<T*, mtGC>();
38 _used_memory += sizeof(ChunkedList<T*, mtGC>);
39 } else if (list->is_full()) {
40 ChunkedList<T*, mtGC>* next = new ChunkedList<T*, mtGC>();
41 next->set_next_used(list);
42 *field = next;
43 _used_memory += sizeof(ChunkedList<T*, mtGC>);
44 }
45
46 (*field)->push(p);
47 }
48
push_root(narrowOop * p)49 inline void G1OopStarChunkedList::push_root(narrowOop* p) {
50 push(&_croots, p);
51 }
52
push_root(oop * p)53 inline void G1OopStarChunkedList::push_root(oop* p) {
54 push(&_roots, p);
55 }
56
push_oop(narrowOop * p)57 inline void G1OopStarChunkedList::push_oop(narrowOop* p) {
58 push(&_coops, p);
59 }
60
push_oop(oop * p)61 inline void G1OopStarChunkedList::push_oop(oop* p) {
62 push(&_oops, p);
63 }
64
65 template <typename T>
delete_list(ChunkedList<T *,mtGC> * c)66 void G1OopStarChunkedList::delete_list(ChunkedList<T*, mtGC>* c) {
67 while (c != NULL) {
68 ChunkedList<T*, mtGC>* next = c->next_used();
69 delete c;
70 c = next;
71 }
72 }
73
74 template <typename T>
chunks_do(ChunkedList<T *,mtGC> * head,OopClosure * cl)75 size_t G1OopStarChunkedList::chunks_do(ChunkedList<T*, mtGC>* head, OopClosure* cl) {
76 size_t result = 0;
77 for (ChunkedList<T*, mtGC>* c = head; c != NULL; c = c->next_used()) {
78 result += c->size();
79 for (size_t i = 0; i < c->size(); i++) {
80 T* p = c->at(i);
81 cl->do_oop(p);
82 }
83 }
84 return result;
85 }
86
87 #endif // SHARE_GC_G1_G1OOPSTARCHUNKEDLIST_INLINE_HPP
88