Tue, 18 Mar 2014 19:07:22 +0100
8029075: String deduplication in G1
Summary: Implementation of JEP 192, http://openjdk.java.net/jeps/192
Reviewed-by: brutisso, tschatzl, coleenp
1 /*
2 * Copyright (c) 2011, 2012, 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 */
25 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSET_INLINE_HPP
26 #define SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSET_INLINE_HPP
28 #include "gc_implementation/g1/heapRegionSet.hpp"
30 inline void HeapRegionSetBase::add(HeapRegion* hr) {
31 check_mt_safety();
32 assert(hr->containing_set() == NULL, hrs_ext_msg(this, "should not already have a containing set %u"));
33 assert(hr->next() == NULL, hrs_ext_msg(this, "should not already be linked"));
35 _count.increment(1u, hr->capacity());
36 hr->set_containing_set(this);
37 verify_region(hr);
38 }
40 inline void HeapRegionSetBase::remove(HeapRegion* hr) {
41 check_mt_safety();
42 verify_region(hr);
43 assert(hr->next() == NULL, hrs_ext_msg(this, "should already be unlinked"));
45 hr->set_containing_set(NULL);
46 assert(_count.length() > 0, hrs_ext_msg(this, "pre-condition"));
47 _count.decrement(1u, hr->capacity());
48 }
50 inline void FreeRegionList::add_as_head(HeapRegion* hr) {
51 assert((length() == 0 && _head == NULL && _tail == NULL) ||
52 (length() > 0 && _head != NULL && _tail != NULL),
53 hrs_ext_msg(this, "invariant"));
54 // add() will verify the region and check mt safety.
55 add(hr);
57 // Now link the region.
58 if (_head != NULL) {
59 hr->set_next(_head);
60 } else {
61 _tail = hr;
62 }
63 _head = hr;
64 }
66 inline void FreeRegionList::add_as_tail(HeapRegion* hr) {
67 check_mt_safety();
68 assert((length() == 0 && _head == NULL && _tail == NULL) ||
69 (length() > 0 && _head != NULL && _tail != NULL),
70 hrs_ext_msg(this, "invariant"));
71 // add() will verify the region and check mt safety
72 add(hr);
74 // Now link the region.
75 if (_tail != NULL) {
76 _tail->set_next(hr);
77 } else {
78 _head = hr;
79 }
80 _tail = hr;
81 }
83 inline HeapRegion* FreeRegionList::remove_head() {
84 assert(!is_empty(), hrs_ext_msg(this, "the list should not be empty"));
85 assert(length() > 0 && _head != NULL && _tail != NULL,
86 hrs_ext_msg(this, "invariant"));
88 // We need to unlink it first.
89 HeapRegion* hr = _head;
90 _head = hr->next();
91 if (_head == NULL) {
92 _tail = NULL;
93 }
94 hr->set_next(NULL);
96 // remove() will verify the region and check mt safety
97 remove(hr);
98 return hr;
99 }
101 inline HeapRegion* FreeRegionList::remove_head_or_null() {
102 check_mt_safety();
103 if (!is_empty()) {
104 return remove_head();
105 } else {
106 return NULL;
107 }
108 }
110 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSET_INLINE_HPP