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;
411 p += o->size();
412 }
413
414 for (HeapWord* p = bottom; p < top; ) {
415 oop o = cast_to_oop(p);
416 o->oop_iterate(&verifier);
417 p += o->size();
418 }
419 }
420
421 void ArchiveHeapLoader::fill_failed_loaded_heap() {
422 assert(_loading_failed, "must be");
423 if (_loaded_heap_bottom != 0) {
424 assert(_loaded_heap_top != 0, "must be");
425 HeapWord* bottom = (HeapWord*)_loaded_heap_bottom;
426 HeapWord* top = (HeapWord*)_loaded_heap_top;
427 Universe::heap()->fill_with_objects(bottom, top - bottom);
428 }
429 }
430
431 class PatchNativePointers: public BitMapClosure {
432 Metadata** _start;
433
434 public:
435 PatchNativePointers(Metadata** start) : _start(start) {}
436
437 bool do_bit(size_t offset) {
438 Metadata** p = _start + offset;
439 *p = (Metadata*)(address(*p) + MetaspaceShared::relocation_delta());
440 // Currently we have only Klass pointers in heap objects.
441 // This needs to be relaxed when we support other types of native
442 // pointers such as Method.
443 assert(((Klass*)(*p))->is_klass(), "must be");
444 return true;
445 }
446 };
447
448 void ArchiveHeapLoader::patch_native_pointers() {
449 if (MetaspaceShared::relocation_delta() == 0) {
450 return;
451 }
452
453 FileMapRegion* r = FileMapInfo::current_info()->region_at(MetaspaceShared::hp);
454 if (r->mapped_base() != nullptr && r->has_ptrmap()) {
455 log_info(cds, heap)("Patching native pointers in heap region");
456 BitMapView bm = FileMapInfo::current_info()->ptrmap_view(MetaspaceShared::hp);
457 PatchNativePointers patcher((Metadata**)r->mapped_base() + FileMapInfo::current_info()->heap_ptrmap_start_pos());
458 bm.iterate(&patcher);
459 }
460 }
461 #endif // INCLUDE_CDS_JAVA_HEAP
|
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;
412 p += o->size();
413 }
414
415 for (HeapWord* p = bottom; p < top; ) {
416 oop o = cast_to_oop(p);
417 o->oop_iterate(&verifier);
418 p += o->size();
419 }
420 }
421
422 void ArchiveHeapLoader::fill_failed_loaded_heap() {
423 assert(_loading_failed, "must be");
424 if (_loaded_heap_bottom != 0) {
425 assert(_loaded_heap_top != 0, "must be");
426 HeapWord* bottom = (HeapWord*)_loaded_heap_bottom;
427 HeapWord* top = (HeapWord*)_loaded_heap_top;
428 Universe::heap()->fill_with_objects(bottom, top - bottom);
429 }
430 }
431
432 oop ArchiveHeapLoader::oop_from_offset(int offset) {
433 // Once GC starts, the offsets saved in CachedCodeDirectoryInternal::_permanent_oop_offsets
434 // will become invalid. I don't know what function can check if GCs are allowed, but surely
435 // GCs can't happen before the Object class is loaded.
436 assert(CDSConfig::is_using_archive(), "sanity");
437 assert(vmClasses::Object_klass()->class_loader_data() == nullptr,
438 "can be called only very early during VM start-up");
439 if (is_loaded()) {
440 return cast_to_oop(_loaded_heap_bottom + offset);
441 } else {
442 assert(is_mapped(), "must be");
443 return cast_to_oop(_mapped_heap_bottom + offset);
444 }
445 }
446
447 class PatchNativePointers: public BitMapClosure {
448 Metadata** _start;
449
450 public:
451 PatchNativePointers(Metadata** start) : _start(start) {}
452
453 bool do_bit(size_t offset) {
454 Metadata** p = _start + offset;
455 *p = (Metadata*)(address(*p) + MetaspaceShared::relocation_delta());
456 return true;
457 }
458 };
459
460 void ArchiveHeapLoader::patch_native_pointers() {
461 if (MetaspaceShared::relocation_delta() == 0) {
462 return;
463 }
464
465 FileMapRegion* r = FileMapInfo::current_info()->region_at(MetaspaceShared::hp);
466 if (r->mapped_base() != nullptr && r->has_ptrmap()) {
467 log_info(cds, heap)("Patching native pointers in heap region");
468 BitMapView bm = FileMapInfo::current_info()->ptrmap_view(MetaspaceShared::hp);
469 PatchNativePointers patcher((Metadata**)r->mapped_base() + FileMapInfo::current_info()->heap_ptrmap_start_pos());
470 bm.iterate(&patcher);
471 }
472 }
473 #endif // INCLUDE_CDS_JAVA_HEAP
|