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 #include "precompiled.hpp"
25 #include "gc/z/zLock.inline.hpp"
26 #include "gc/z/zMarkStack.inline.hpp"
27 #include "gc/z/zMarkStackAllocator.hpp"
28 #include "logging/log.hpp"
29 #include "runtime/atomic.hpp"
30 #include "runtime/os.hpp"
31 #include "utilities/debug.hpp"
32
33 uintptr_t ZMarkStackSpaceStart;
34
35 ZMarkStackSpace::ZMarkStackSpace() :
36 _expand_lock(),
37 _start(0),
38 _top(0),
39 _end(0) {
40 assert(ZMarkStackSpaceLimit >= ZMarkStackSpaceExpandSize, "ZMarkStackSpaceLimit too small");
41
42 // Reserve address space
43 const size_t size = ZMarkStackSpaceLimit;
44 const size_t alignment = (size_t)os::vm_allocation_granularity();
45 const uintptr_t addr = (uintptr_t)os::reserve_memory(size, NULL, alignment, mtGC);
46 if (addr == 0) {
47 log_error(gc, marking)("Failed to reserve address space for mark stacks");
48 return;
49 }
50
51 // Successfully initialized
52 _start = _top = _end = addr;
53
54 // Register mark stack space start
55 ZMarkStackSpaceStart = _start;
56 }
57
58 bool ZMarkStackSpace::is_initialized() const {
59 return _start != 0;
60 }
61
62 uintptr_t ZMarkStackSpace::alloc_space(size_t size) {
63 uintptr_t top = Atomic::load(&_top);
64
65 for (;;) {
66 const uintptr_t end = Atomic::load(&_end);
67 const uintptr_t new_top = top + size;
|
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 #include "precompiled.hpp"
25 #include "gc/shared/gcLogPrecious.hpp"
26 #include "gc/z/zLock.inline.hpp"
27 #include "gc/z/zMarkStack.inline.hpp"
28 #include "gc/z/zMarkStackAllocator.hpp"
29 #include "logging/log.hpp"
30 #include "runtime/atomic.hpp"
31 #include "runtime/os.hpp"
32 #include "utilities/debug.hpp"
33
34 uintptr_t ZMarkStackSpaceStart;
35
36 ZMarkStackSpace::ZMarkStackSpace() :
37 _expand_lock(),
38 _start(0),
39 _top(0),
40 _end(0) {
41 assert(ZMarkStackSpaceLimit >= ZMarkStackSpaceExpandSize, "ZMarkStackSpaceLimit too small");
42
43 // Reserve address space
44 const size_t size = ZMarkStackSpaceLimit;
45 const size_t alignment = (size_t)os::vm_allocation_granularity();
46 const uintptr_t addr = (uintptr_t)os::reserve_memory(size, NULL, alignment, mtGC);
47 if (addr == 0) {
48 log_error_p(gc, marking)("Failed to reserve address space for mark stacks");
49 return;
50 }
51
52 // Successfully initialized
53 _start = _top = _end = addr;
54
55 // Register mark stack space start
56 ZMarkStackSpaceStart = _start;
57 }
58
59 bool ZMarkStackSpace::is_initialized() const {
60 return _start != 0;
61 }
62
63 uintptr_t ZMarkStackSpace::alloc_space(size_t size) {
64 uintptr_t top = Atomic::load(&_top);
65
66 for (;;) {
67 const uintptr_t end = Atomic::load(&_end);
68 const uintptr_t new_top = top + size;
|