author | iklam |
Wed, 13 Nov 2019 16:36:54 -0800 | |
changeset 59070 | 22ee476cc664 |
permissions | -rw-r--r-- |
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
1 |
/* |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
2 |
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
4 |
* |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
8 |
* |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
13 |
* accompanied this code). |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
14 |
* |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
18 |
* |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
21 |
* questions. |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
22 |
* |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
23 |
*/ |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
24 |
|
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
25 |
#include "precompiled.hpp" |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
26 |
#include "memory/archiveUtils.hpp" |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
27 |
#include "memory/metaspace.hpp" |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
28 |
#include "utilities/bitMap.inline.hpp" |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
29 |
|
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
30 |
#if INCLUDE_CDS |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
31 |
|
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
32 |
CHeapBitMap* ArchivePtrMarker::_ptrmap = NULL; |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
33 |
address* ArchivePtrMarker::_ptr_base; |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
34 |
address* ArchivePtrMarker::_ptr_end; |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
35 |
bool ArchivePtrMarker::_compacted; |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
36 |
|
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
37 |
void ArchivePtrMarker::initialize(CHeapBitMap* ptrmap, address* ptr_base, address* ptr_end) { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
38 |
assert(_ptrmap == NULL, "initialize only once"); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
39 |
_ptr_base = ptr_base; |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
40 |
_ptr_end = ptr_end; |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
41 |
_compacted = false; |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
42 |
_ptrmap = ptrmap; |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
43 |
|
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
44 |
// Use this as initial guesstimate. We should need less space in the |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
45 |
// archive, but if we're wrong the bitmap will be expanded automatically. |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
46 |
size_t estimated_archive_size = MetaspaceGC::capacity_until_GC(); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
47 |
// But set it smaller in debug builds so we always test the expansion code. |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
48 |
// (Default archive is about 12MB). |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
49 |
DEBUG_ONLY(estimated_archive_size = 6 * M); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
50 |
|
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
51 |
// We need one bit per pointer in the archive. |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
52 |
_ptrmap->initialize(estimated_archive_size / sizeof(intptr_t)); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
53 |
} |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
54 |
|
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
55 |
void ArchivePtrMarker::mark_pointer(address* ptr_loc) { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
56 |
assert(_ptrmap != NULL, "not initialized"); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
57 |
assert(!_compacted, "cannot mark anymore"); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
58 |
|
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
59 |
if (_ptr_base <= ptr_loc && ptr_loc < _ptr_end) { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
60 |
address value = *ptr_loc; |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
61 |
if (value != NULL) { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
62 |
assert(uintx(ptr_loc) % sizeof(intptr_t) == 0, "pointers must be stored in aligned addresses"); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
63 |
size_t idx = ptr_loc - _ptr_base; |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
64 |
if (_ptrmap->size() <= idx) { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
65 |
_ptrmap->resize((idx + 1) * 2); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
66 |
} |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
67 |
assert(idx < _ptrmap->size(), "must be"); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
68 |
_ptrmap->set_bit(idx); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
69 |
//tty->print_cr("Marking pointer [%p] -> %p @ " SIZE_FORMAT_W(9), ptr_loc, *ptr_loc, idx); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
70 |
} |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
71 |
} |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
72 |
} |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
73 |
|
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
74 |
class ArchivePtrBitmapCleaner: public BitMapClosure { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
75 |
CHeapBitMap* _ptrmap; |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
76 |
address* _ptr_base; |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
77 |
address _relocatable_base; |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
78 |
address _relocatable_end; |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
79 |
size_t _max_non_null_offset; |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
80 |
|
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
81 |
public: |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
82 |
ArchivePtrBitmapCleaner(CHeapBitMap* ptrmap, address* ptr_base, address relocatable_base, address relocatable_end) : |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
83 |
_ptrmap(ptrmap), _ptr_base(ptr_base), |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
84 |
_relocatable_base(relocatable_base), _relocatable_end(relocatable_end), _max_non_null_offset(0) {} |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
85 |
|
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
86 |
bool do_bit(size_t offset) { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
87 |
address* ptr_loc = _ptr_base + offset; |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
88 |
address ptr_value = *ptr_loc; |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
89 |
if (ptr_value != NULL) { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
90 |
assert(_relocatable_base <= ptr_value && ptr_value < _relocatable_end, "do not point to arbitrary locations!"); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
91 |
if (_max_non_null_offset < offset) { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
92 |
_max_non_null_offset = offset; |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
93 |
} |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
94 |
} else { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
95 |
_ptrmap->clear_bit(offset); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
96 |
DEBUG_ONLY(log_trace(cds, reloc)("Clearing pointer [" PTR_FORMAT "] -> NULL @ " SIZE_FORMAT_W(9), p2i(ptr_loc), offset)); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
97 |
} |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
98 |
|
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
99 |
return true; |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
100 |
} |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
101 |
|
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
102 |
size_t max_non_null_offset() const { return _max_non_null_offset; } |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
103 |
}; |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
104 |
|
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
105 |
void ArchivePtrMarker::compact(address relocatable_base, address relocatable_end) { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
106 |
assert(!_compacted, "cannot compact again"); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
107 |
ArchivePtrBitmapCleaner cleaner(_ptrmap, _ptr_base, relocatable_base, relocatable_end); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
108 |
_ptrmap->iterate(&cleaner); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
109 |
compact(cleaner.max_non_null_offset()); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
110 |
} |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
111 |
|
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
112 |
void ArchivePtrMarker::compact(size_t max_non_null_offset) { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
113 |
assert(!_compacted, "cannot compact again"); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
114 |
_ptrmap->resize(max_non_null_offset + 1); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
115 |
_compacted = true; |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
116 |
} |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
117 |
|
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
diff
changeset
|
118 |
#endif // INCLUDE_CDS |