|
1 | 1 | /* |
2 | | - * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | 4 | * |
5 | 5 | * This code is free software; you can redistribute it and/or modify it |
|
22 | 22 | */ |
23 | 23 |
|
24 | 24 | #include "precompiled.hpp" |
25 | | -#include "gc/z/zForwarding.hpp" |
| 25 | +#include "gc/z/zForwarding.inline.hpp" |
| 26 | +#include "gc/z/zForwardingAllocator.inline.hpp" |
26 | 27 | #include "gc/z/zRelocationSet.hpp" |
| 28 | +#include "gc/z/zStat.hpp" |
27 | 29 | #include "memory/allocation.hpp" |
| 30 | +#include "utilities/debug.hpp" |
28 | 31 |
|
29 | 32 | ZRelocationSet::ZRelocationSet() : |
| 33 | + _allocator(), |
30 | 34 | _forwardings(NULL), |
31 | 35 | _nforwardings(0) {} |
32 | 36 |
|
33 | | -void ZRelocationSet::populate(ZPage* const* group0, size_t ngroup0, |
34 | | - ZPage* const* group1, size_t ngroup1) { |
35 | | - _nforwardings = ngroup0 + ngroup1; |
36 | | - _forwardings = REALLOC_C_HEAP_ARRAY(ZForwarding*, _forwardings, _nforwardings, mtGC); |
| 37 | +void ZRelocationSet::populate(ZPage* const* small, size_t nsmall, |
| 38 | + ZPage* const* medium, size_t nmedium, |
| 39 | + size_t forwarding_entries) { |
| 40 | + // Set relocation set length |
| 41 | + _nforwardings = nsmall + nmedium; |
37 | 42 |
|
| 43 | + // Initialize forwarding allocator to have room for the |
| 44 | + // relocation set, all forwardings, and all forwarding entries. |
| 45 | + const size_t relocation_set_size = _nforwardings * sizeof(ZForwarding*); |
| 46 | + const size_t forwardings_size = _nforwardings * sizeof(ZForwarding); |
| 47 | + const size_t forwarding_entries_size = forwarding_entries * sizeof(ZForwardingEntry); |
| 48 | + _allocator.reset(relocation_set_size + forwardings_size + forwarding_entries_size); |
| 49 | + |
| 50 | + // Allocate relocation set |
| 51 | + _forwardings = new (_allocator.alloc(relocation_set_size)) ZForwarding*[_nforwardings]; |
| 52 | + |
| 53 | + // Populate relocation set array |
38 | 54 | size_t j = 0; |
39 | 55 |
|
40 | | - // Populate group 0 |
41 | | - for (size_t i = 0; i < ngroup0; i++) { |
42 | | - _forwardings[j++] = ZForwarding::create(group0[i]); |
| 56 | + // Populate medium pages |
| 57 | + for (size_t i = 0; i < nmedium; i++) { |
| 58 | + _forwardings[j++] = ZForwarding::alloc(&_allocator, medium[i]); |
43 | 59 | } |
44 | 60 |
|
45 | | - // Populate group 1 |
46 | | - for (size_t i = 0; i < ngroup1; i++) { |
47 | | - _forwardings[j++] = ZForwarding::create(group1[i]); |
| 61 | + // Populate small pages |
| 62 | + for (size_t i = 0; i < nsmall; i++) { |
| 63 | + _forwardings[j++] = ZForwarding::alloc(&_allocator, small[i]); |
48 | 64 | } |
| 65 | + |
| 66 | + assert(_allocator.is_full(), "Should be full"); |
| 67 | + |
| 68 | + // Update statistics |
| 69 | + ZStatRelocation::set_at_populate_relocation_set(_allocator.size()); |
49 | 70 | } |
50 | 71 |
|
51 | 72 | void ZRelocationSet::reset() { |
52 | | - for (size_t i = 0; i < _nforwardings; i++) { |
53 | | - ZForwarding::destroy(_forwardings[i]); |
54 | | - _forwardings[i] = NULL; |
55 | | - } |
| 73 | + _nforwardings = 0; |
56 | 74 | } |
0 commit comments