1 /*
2 * Copyright (c) 2019, 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 *
41 _compacted = false;
42 _ptrmap = ptrmap;
43
44 // Use this as initial guesstimate. We should need less space in the
45 // archive, but if we're wrong the bitmap will be expanded automatically.
46 size_t estimated_archive_size = MetaspaceGC::capacity_until_GC();
47 // But set it smaller in debug builds so we always test the expansion code.
48 // (Default archive is about 12MB).
49 DEBUG_ONLY(estimated_archive_size = 6 * M);
50
51 // We need one bit per pointer in the archive.
52 _ptrmap->initialize(estimated_archive_size / sizeof(intptr_t));
53 }
54
55 void ArchivePtrMarker::mark_pointer(address* ptr_loc) {
56 assert(_ptrmap != NULL, "not initialized");
57 assert(!_compacted, "cannot mark anymore");
58
59 if (_ptr_base <= ptr_loc && ptr_loc < _ptr_end) {
60 address value = *ptr_loc;
61 if (value != NULL) {
62 assert(uintx(ptr_loc) % sizeof(intptr_t) == 0, "pointers must be stored in aligned addresses");
63 size_t idx = ptr_loc - _ptr_base;
64 if (_ptrmap->size() <= idx) {
65 _ptrmap->resize((idx + 1) * 2);
66 }
67 assert(idx < _ptrmap->size(), "must be");
68 _ptrmap->set_bit(idx);
69 //tty->print_cr("Marking pointer [%p] -> %p @ " SIZE_FORMAT_W(9), ptr_loc, *ptr_loc, idx);
70 }
71 }
72 }
73
74 class ArchivePtrBitmapCleaner: public BitMapClosure {
75 CHeapBitMap* _ptrmap;
76 address* _ptr_base;
77 address _relocatable_base;
78 address _relocatable_end;
79 size_t _max_non_null_offset;
80
|
1 /*
2 * Copyright (c) 2019, 2020, 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 *
41 _compacted = false;
42 _ptrmap = ptrmap;
43
44 // Use this as initial guesstimate. We should need less space in the
45 // archive, but if we're wrong the bitmap will be expanded automatically.
46 size_t estimated_archive_size = MetaspaceGC::capacity_until_GC();
47 // But set it smaller in debug builds so we always test the expansion code.
48 // (Default archive is about 12MB).
49 DEBUG_ONLY(estimated_archive_size = 6 * M);
50
51 // We need one bit per pointer in the archive.
52 _ptrmap->initialize(estimated_archive_size / sizeof(intptr_t));
53 }
54
55 void ArchivePtrMarker::mark_pointer(address* ptr_loc) {
56 assert(_ptrmap != NULL, "not initialized");
57 assert(!_compacted, "cannot mark anymore");
58
59 if (_ptr_base <= ptr_loc && ptr_loc < _ptr_end) {
60 address value = *ptr_loc;
61 // We don't want any pointer that points to very bottom of the archive, otherwise when
62 // MetaspaceShared::default_base_address()==0, we can't distinguish between a pointer
63 // to nothing (NULL) vs a pointer to an objects that happens to be at the very bottom
64 // of the archive.
65 assert(value != (address)_ptr_base, "don't point to the bottom of the archive");
66
67 if (value != NULL) {
68 assert(uintx(ptr_loc) % sizeof(intptr_t) == 0, "pointers must be stored in aligned addresses");
69 size_t idx = ptr_loc - _ptr_base;
70 if (_ptrmap->size() <= idx) {
71 _ptrmap->resize((idx + 1) * 2);
72 }
73 assert(idx < _ptrmap->size(), "must be");
74 _ptrmap->set_bit(idx);
75 //tty->print_cr("Marking pointer [%p] -> %p @ " SIZE_FORMAT_W(9), ptr_loc, *ptr_loc, idx);
76 }
77 }
78 }
79
80 class ArchivePtrBitmapCleaner: public BitMapClosure {
81 CHeapBitMap* _ptrmap;
82 address* _ptr_base;
83 address _relocatable_base;
84 address _relocatable_end;
85 size_t _max_non_null_offset;
86
|