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
25 #include "cds/archiveHeapLoader.inline.hpp"
26 #include "cds/cdsConfig.hpp"
27 #include "cds/heapShared.hpp"
28 #include "cds/metaspaceShared.hpp"
29 #include "classfile/classLoaderDataShared.hpp"
30 #include "classfile/systemDictionaryShared.hpp"
31 #include "gc/shared/collectedHeap.hpp"
32 #include "logging/log.hpp"
33 #include "memory/iterator.inline.hpp"
34 #include "memory/resourceArea.hpp"
35 #include "memory/universe.hpp"
36 #include "sanitizers/ub.hpp"
37 #include "utilities/bitMap.inline.hpp"
38 #include "utilities/copy.hpp"
39
40 #if INCLUDE_CDS_JAVA_HEAP
41
42 bool ArchiveHeapLoader::_is_mapped = false;
43 bool ArchiveHeapLoader::_is_loaded = false;
44
45 bool ArchiveHeapLoader::_narrow_oop_base_initialized = false;
46 address ArchiveHeapLoader::_narrow_oop_base;
47 int ArchiveHeapLoader::_narrow_oop_shift;
48
49 // Support for loaded heap.
50 uintptr_t ArchiveHeapLoader::_loaded_heap_bottom = 0;
422 p += o->size();
423 }
424
425 for (HeapWord* p = bottom; p < top; ) {
426 oop o = cast_to_oop(p);
427 o->oop_iterate(&verifier);
428 p += o->size();
429 }
430 }
431
432 void ArchiveHeapLoader::fill_failed_loaded_heap() {
433 assert(_loading_failed, "must be");
434 if (_loaded_heap_bottom != 0) {
435 assert(_loaded_heap_top != 0, "must be");
436 HeapWord* bottom = (HeapWord*)_loaded_heap_bottom;
437 HeapWord* top = (HeapWord*)_loaded_heap_top;
438 Universe::heap()->fill_with_objects(bottom, top - bottom);
439 }
440 }
441
442 class PatchNativePointers: public BitMapClosure {
443 Metadata** _start;
444
445 public:
446 PatchNativePointers(Metadata** start) : _start(start) {}
447
448 bool do_bit(size_t offset) {
449 Metadata** p = _start + offset;
450 *p = (Metadata*)(address(*p) + MetaspaceShared::relocation_delta());
451 return true;
452 }
453 };
454
455 void ArchiveHeapLoader::patch_native_pointers() {
456 if (MetaspaceShared::relocation_delta() == 0) {
457 return;
458 }
459
460 FileMapRegion* r = FileMapInfo::current_info()->region_at(MetaspaceShared::hp);
461 if (r->mapped_base() != nullptr && r->has_ptrmap()) {
|
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
25 #include "cds/archiveHeapLoader.inline.hpp"
26 #include "cds/cdsConfig.hpp"
27 #include "cds/heapShared.hpp"
28 #include "cds/metaspaceShared.hpp"
29 #include "classfile/classLoaderDataShared.hpp"
30 #include "classfile/systemDictionaryShared.hpp"
31 #include "classfile/vmClasses.hpp"
32 #include "gc/shared/collectedHeap.hpp"
33 #include "logging/log.hpp"
34 #include "memory/iterator.inline.hpp"
35 #include "memory/resourceArea.hpp"
36 #include "memory/universe.hpp"
37 #include "sanitizers/ub.hpp"
38 #include "utilities/bitMap.inline.hpp"
39 #include "utilities/copy.hpp"
40
41 #if INCLUDE_CDS_JAVA_HEAP
42
43 bool ArchiveHeapLoader::_is_mapped = false;
44 bool ArchiveHeapLoader::_is_loaded = false;
45
46 bool ArchiveHeapLoader::_narrow_oop_base_initialized = false;
47 address ArchiveHeapLoader::_narrow_oop_base;
48 int ArchiveHeapLoader::_narrow_oop_shift;
49
50 // Support for loaded heap.
51 uintptr_t ArchiveHeapLoader::_loaded_heap_bottom = 0;
423 p += o->size();
424 }
425
426 for (HeapWord* p = bottom; p < top; ) {
427 oop o = cast_to_oop(p);
428 o->oop_iterate(&verifier);
429 p += o->size();
430 }
431 }
432
433 void ArchiveHeapLoader::fill_failed_loaded_heap() {
434 assert(_loading_failed, "must be");
435 if (_loaded_heap_bottom != 0) {
436 assert(_loaded_heap_top != 0, "must be");
437 HeapWord* bottom = (HeapWord*)_loaded_heap_bottom;
438 HeapWord* top = (HeapWord*)_loaded_heap_top;
439 Universe::heap()->fill_with_objects(bottom, top - bottom);
440 }
441 }
442
443 oop ArchiveHeapLoader::oop_from_offset(int offset) {
444 // Once GC starts, the offsets saved in CachedCodeDirectoryInternal::_permanent_oop_offsets
445 // will become invalid. I don't know what function can check if GCs are allowed, but surely
446 // GCs can't happen before the Object class is loaded.
447 assert(CDSConfig::is_using_archive(), "sanity");
448 assert(vmClasses::Object_klass()->class_loader_data() == nullptr,
449 "can be called only very early during VM start-up");
450 if (is_loaded()) {
451 return cast_to_oop(_loaded_heap_bottom + offset);
452 } else {
453 assert(is_mapped(), "must be");
454 return cast_to_oop(_mapped_heap_bottom + offset);
455 }
456 }
457
458 class PatchNativePointers: public BitMapClosure {
459 Metadata** _start;
460
461 public:
462 PatchNativePointers(Metadata** start) : _start(start) {}
463
464 bool do_bit(size_t offset) {
465 Metadata** p = _start + offset;
466 *p = (Metadata*)(address(*p) + MetaspaceShared::relocation_delta());
467 return true;
468 }
469 };
470
471 void ArchiveHeapLoader::patch_native_pointers() {
472 if (MetaspaceShared::relocation_delta() == 0) {
473 return;
474 }
475
476 FileMapRegion* r = FileMapInfo::current_info()->region_at(MetaspaceShared::hp);
477 if (r->mapped_base() != nullptr && r->has_ptrmap()) {
|