34 #include "classfile/symbolTable.hpp"
35 #include "classfile/stringTable.hpp"
36 #include "classfile/systemDictionary.hpp"
37 #include "classfile/systemDictionaryShared.hpp"
38 #include "code/codeCache.hpp"
39 #include "gc/shared/softRefPolicy.hpp"
40 #include "interpreter/bytecodeStream.hpp"
41 #include "interpreter/bytecodes.hpp"
42 #include "logging/log.hpp"
43 #include "logging/logMessage.hpp"
44 #include "memory/archiveUtils.inline.hpp"
45 #include "memory/dynamicArchive.hpp"
46 #include "memory/filemap.hpp"
47 #include "memory/heapShared.inline.hpp"
48 #include "memory/metaspace.hpp"
49 #include "memory/metaspaceClosure.hpp"
50 #include "memory/metaspaceShared.hpp"
51 #include "memory/resourceArea.hpp"
52 #include "memory/universe.hpp"
53 #include "oops/compressedOops.inline.hpp"
54 #include "oops/instanceClassLoaderKlass.hpp"
55 #include "oops/instanceMirrorKlass.hpp"
56 #include "oops/instanceRefKlass.hpp"
57 #include "oops/methodData.hpp"
58 #include "oops/objArrayKlass.hpp"
59 #include "oops/objArrayOop.hpp"
60 #include "oops/oop.inline.hpp"
61 #include "oops/typeArrayKlass.hpp"
62 #include "prims/jvmtiRedefineClasses.hpp"
63 #include "runtime/handles.inline.hpp"
64 #include "runtime/os.hpp"
65 #include "runtime/safepointVerifiers.hpp"
66 #include "runtime/signature.hpp"
67 #include "runtime/timerTrace.hpp"
68 #include "runtime/vmThread.hpp"
69 #include "runtime/vmOperations.hpp"
70 #include "utilities/align.hpp"
71 #include "utilities/bitMap.inline.hpp"
72 #include "utilities/ostream.hpp"
73 #include "utilities/defaultStream.hpp"
770 fp.fingerprint();
771 }
772 }
773
774 // Objects of the Metadata types (such as Klass and ConstantPool) have C++ vtables.
775 // (In GCC this is the field <Type>::_vptr, i.e., first word in the object.)
776 //
777 // Addresses of the vtables and the methods may be different across JVM runs,
778 // if libjvm.so is dynamically loaded at a different base address.
779 //
780 // To ensure that the Metadata objects in the CDS archive always have the correct vtable:
781 //
782 // + at dump time: we redirect the _vptr to point to our own vtables inside
783 // the CDS image
784 // + at run time: we clone the actual contents of the vtables from libjvm.so
785 // into our own tables.
786
787 // Currently, the archive contain ONLY the following types of objects that have C++ vtables.
788 #define CPP_VTABLE_PATCH_TYPES_DO(f) \
789 f(ConstantPool) \
790 f(InstanceKlass) \
791 f(InstanceClassLoaderKlass) \
792 f(InstanceMirrorKlass) \
793 f(InstanceRefKlass) \
794 f(Method) \
795 f(ObjArrayKlass) \
796 f(TypeArrayKlass)
797
798 class CppVtableInfo {
799 intptr_t _vtable_size;
800 intptr_t _cloned_vtable[1];
801 public:
802 static int num_slots(int vtable_size) {
803 return 1 + vtable_size; // Need to add the space occupied by _vtable_size;
804 }
805 int vtable_size() { return int(uintx(_vtable_size)); }
806 void set_vtable_size(int n) { _vtable_size = intptr_t(n); }
807 intptr_t* cloned_vtable() { return &_cloned_vtable[0]; }
808 void zero() { memset(_cloned_vtable, 0, sizeof(intptr_t) * vtable_size()); }
809 // Returns the address of the next CppVtableInfo that can be placed immediately after this CppVtableInfo
810 static size_t byte_size(int vtable_size) {
811 CppVtableInfo i;
812 return pointer_delta(&i._cloned_vtable[vtable_size], &i, sizeof(u1));
813 }
814 };
815
816 static inline intptr_t* vtable_of(Metadata* m) {
1354 ShallowCopier(bool read_only) : _read_only(read_only) {}
1355
1356 virtual bool do_unique_ref(Ref* ref, bool read_only) {
1357 if (read_only == _read_only) {
1358 allocate(ref, read_only);
1359 }
1360 return true; // recurse into ref.obj()
1361 }
1362 };
1363
1364 // Relocate embedded pointers within a MetaspaceObj's shallow copy
1365 class ShallowCopyEmbeddedRefRelocator: public UniqueMetaspaceClosure {
1366 public:
1367 virtual bool do_unique_ref(Ref* ref, bool read_only) {
1368 address new_loc = get_new_loc(ref);
1369 RefRelocator refer;
1370 ref->metaspace_pointers_do_at(&refer, new_loc);
1371 return true; // recurse into ref.obj()
1372 }
1373 virtual void push_special(SpecialRef type, Ref* ref, intptr_t* p) {
1374 assert(type == _method_entry_ref, "only special type allowed for now");
1375 address obj = ref->obj();
1376 address new_obj = get_new_loc(ref);
1377 size_t offset = pointer_delta(p, obj, sizeof(u1));
1378 intptr_t* new_p = (intptr_t*)(new_obj + offset);
1379 assert(*p == *new_p, "must be a copy");
1380 ArchivePtrMarker::mark_pointer((address*)new_p);
1381 }
1382 };
1383
1384 // Relocate a reference to point to its shallow copy
1385 class RefRelocator: public MetaspaceClosure {
1386 public:
1387 virtual bool do_ref(Ref* ref, bool read_only) {
1388 if (ref->not_null()) {
1389 ref->update(get_new_loc(ref));
1390 ArchivePtrMarker::mark_pointer(ref->addr());
1391 }
1392 return false; // Do not recurse.
1393 }
1394 };
1395
1396 #ifdef ASSERT
1397 class IsRefInArchiveChecker: public MetaspaceClosure {
1398 public:
1399 virtual bool do_ref(Ref* ref, bool read_only) {
|
34 #include "classfile/symbolTable.hpp"
35 #include "classfile/stringTable.hpp"
36 #include "classfile/systemDictionary.hpp"
37 #include "classfile/systemDictionaryShared.hpp"
38 #include "code/codeCache.hpp"
39 #include "gc/shared/softRefPolicy.hpp"
40 #include "interpreter/bytecodeStream.hpp"
41 #include "interpreter/bytecodes.hpp"
42 #include "logging/log.hpp"
43 #include "logging/logMessage.hpp"
44 #include "memory/archiveUtils.inline.hpp"
45 #include "memory/dynamicArchive.hpp"
46 #include "memory/filemap.hpp"
47 #include "memory/heapShared.inline.hpp"
48 #include "memory/metaspace.hpp"
49 #include "memory/metaspaceClosure.hpp"
50 #include "memory/metaspaceShared.hpp"
51 #include "memory/resourceArea.hpp"
52 #include "memory/universe.hpp"
53 #include "oops/compressedOops.inline.hpp"
54 #include "oops/flatArrayKlass.hpp"
55 #include "oops/inlineKlass.hpp"
56 #include "oops/instanceClassLoaderKlass.hpp"
57 #include "oops/instanceMirrorKlass.hpp"
58 #include "oops/instanceRefKlass.hpp"
59 #include "oops/methodData.hpp"
60 #include "oops/objArrayKlass.hpp"
61 #include "oops/objArrayOop.hpp"
62 #include "oops/oop.inline.hpp"
63 #include "oops/typeArrayKlass.hpp"
64 #include "prims/jvmtiRedefineClasses.hpp"
65 #include "runtime/handles.inline.hpp"
66 #include "runtime/os.hpp"
67 #include "runtime/safepointVerifiers.hpp"
68 #include "runtime/signature.hpp"
69 #include "runtime/timerTrace.hpp"
70 #include "runtime/vmThread.hpp"
71 #include "runtime/vmOperations.hpp"
72 #include "utilities/align.hpp"
73 #include "utilities/bitMap.inline.hpp"
74 #include "utilities/ostream.hpp"
75 #include "utilities/defaultStream.hpp"
772 fp.fingerprint();
773 }
774 }
775
776 // Objects of the Metadata types (such as Klass and ConstantPool) have C++ vtables.
777 // (In GCC this is the field <Type>::_vptr, i.e., first word in the object.)
778 //
779 // Addresses of the vtables and the methods may be different across JVM runs,
780 // if libjvm.so is dynamically loaded at a different base address.
781 //
782 // To ensure that the Metadata objects in the CDS archive always have the correct vtable:
783 //
784 // + at dump time: we redirect the _vptr to point to our own vtables inside
785 // the CDS image
786 // + at run time: we clone the actual contents of the vtables from libjvm.so
787 // into our own tables.
788
789 // Currently, the archive contain ONLY the following types of objects that have C++ vtables.
790 #define CPP_VTABLE_PATCH_TYPES_DO(f) \
791 f(ConstantPool) \
792 f(InstanceClassLoaderKlass) \
793 f(InstanceKlass) \
794 f(InstanceMirrorKlass) \
795 f(InstanceRefKlass) \
796 f(Method) \
797 f(ObjArrayKlass) \
798 f(TypeArrayKlass) \
799 f(FlatArrayKlass) \
800 f(InlineKlass)
801
802 class CppVtableInfo {
803 intptr_t _vtable_size;
804 intptr_t _cloned_vtable[1];
805 public:
806 static int num_slots(int vtable_size) {
807 return 1 + vtable_size; // Need to add the space occupied by _vtable_size;
808 }
809 int vtable_size() { return int(uintx(_vtable_size)); }
810 void set_vtable_size(int n) { _vtable_size = intptr_t(n); }
811 intptr_t* cloned_vtable() { return &_cloned_vtable[0]; }
812 void zero() { memset(_cloned_vtable, 0, sizeof(intptr_t) * vtable_size()); }
813 // Returns the address of the next CppVtableInfo that can be placed immediately after this CppVtableInfo
814 static size_t byte_size(int vtable_size) {
815 CppVtableInfo i;
816 return pointer_delta(&i._cloned_vtable[vtable_size], &i, sizeof(u1));
817 }
818 };
819
820 static inline intptr_t* vtable_of(Metadata* m) {
1358 ShallowCopier(bool read_only) : _read_only(read_only) {}
1359
1360 virtual bool do_unique_ref(Ref* ref, bool read_only) {
1361 if (read_only == _read_only) {
1362 allocate(ref, read_only);
1363 }
1364 return true; // recurse into ref.obj()
1365 }
1366 };
1367
1368 // Relocate embedded pointers within a MetaspaceObj's shallow copy
1369 class ShallowCopyEmbeddedRefRelocator: public UniqueMetaspaceClosure {
1370 public:
1371 virtual bool do_unique_ref(Ref* ref, bool read_only) {
1372 address new_loc = get_new_loc(ref);
1373 RefRelocator refer;
1374 ref->metaspace_pointers_do_at(&refer, new_loc);
1375 return true; // recurse into ref.obj()
1376 }
1377 virtual void push_special(SpecialRef type, Ref* ref, intptr_t* p) {
1378 assert_valid(type);
1379
1380 address obj = ref->obj();
1381 address new_obj = get_new_loc(ref);
1382 size_t offset = pointer_delta(p, obj, sizeof(u1));
1383 intptr_t* new_p = (intptr_t*)(new_obj + offset);
1384 switch (type) {
1385 case _method_entry_ref:
1386 assert(*p == *new_p, "must be a copy");
1387 break;
1388 case _internal_pointer_ref:
1389 {
1390 size_t off = pointer_delta(*((address*)p), obj, sizeof(u1));
1391 assert(0 <= intx(off) && intx(off) < ref->size() * BytesPerWord, "must point to internal address");
1392 *((address*)new_p) = new_obj + off;
1393 }
1394 break;
1395 default:
1396 ShouldNotReachHere();
1397 }
1398 ArchivePtrMarker::mark_pointer((address*)new_p);
1399 }
1400 };
1401
1402 // Relocate a reference to point to its shallow copy
1403 class RefRelocator: public MetaspaceClosure {
1404 public:
1405 virtual bool do_ref(Ref* ref, bool read_only) {
1406 if (ref->not_null()) {
1407 ref->update(get_new_loc(ref));
1408 ArchivePtrMarker::mark_pointer(ref->addr());
1409 }
1410 return false; // Do not recurse.
1411 }
1412 };
1413
1414 #ifdef ASSERT
1415 class IsRefInArchiveChecker: public MetaspaceClosure {
1416 public:
1417 virtual bool do_ref(Ref* ref, bool read_only) {
|