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