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/archiveUtils.hpp"
27 #include "cds/archiveBuilder.hpp"
28 #include "cds/cdsConfig.hpp"
29 #include "cds/cppVtables.hpp"
30 #include "cds/metaspaceShared.hpp"
31 #include "logging/log.hpp"
32 #include "oops/instanceClassLoaderKlass.hpp"
33 #include "oops/instanceMirrorKlass.hpp"
34 #include "oops/instanceRefKlass.hpp"
35 #include "oops/instanceStackChunkKlass.hpp"
36 #include "oops/methodData.hpp"
37 #include "oops/objArrayKlass.hpp"
38 #include "oops/typeArrayKlass.hpp"
39 #include "runtime/arguments.hpp"
40 #include "utilities/globalDefinitions.hpp"
41
42 // Objects of the Metadata types (such as Klass and ConstantPool) have C++ vtables.
43 // (In GCC this is the field <Type>::_vptr, i.e., first word in the object.)
44 //
45 // Addresses of the vtables and the methods may be different across JVM runs,
46 // if libjvm.so is dynamically loaded at a different base address.
47 //
48 // To ensure that the Metadata objects in the CDS archive always have the correct vtable:
49 //
50 // + at dump time: we redirect the _vptr to point to our own vtables inside
51 // the CDS image
52 // + at run time: we clone the actual contents of the vtables from libjvm.so
53 // into our own tables.
54
55 // Currently, the archive contains ONLY the following types of objects that have C++ vtables.
56 #define CPP_VTABLE_TYPES_DO(f) \
57 f(ConstantPool) \
58 f(InstanceKlass) \
59 f(InstanceClassLoaderKlass) \
60 f(InstanceMirrorKlass) \
61 f(InstanceRefKlass) \
62 f(InstanceStackChunkKlass) \
63 f(Method) \
64 f(ObjArrayKlass) \
65 f(TypeArrayKlass)
66
67 class CppVtableInfo {
68 intptr_t _vtable_size;
69 intptr_t _cloned_vtable[1]; // Pseudo flexible array member.
70 static size_t cloned_vtable_offset() { return offset_of(CppVtableInfo, _cloned_vtable); }
71 public:
72 int vtable_size() { return int(uintx(_vtable_size)); }
73 void set_vtable_size(int n) { _vtable_size = intptr_t(n); }
74 // Using _cloned_vtable[i] for i > 0 causes undefined behavior. We use address calculation instead.
75 intptr_t* cloned_vtable() { return (intptr_t*)((char*)this + cloned_vtable_offset()); }
76 void zero() { memset(cloned_vtable(), 0, sizeof(intptr_t) * vtable_size()); }
77 // Returns the address of the next CppVtableInfo that can be placed immediately after this CppVtableInfo
78 static size_t byte_size(int vtable_size) {
79 return cloned_vtable_offset() + (sizeof(intptr_t) * vtable_size);
80 }
81 };
82
83 static inline intptr_t* vtable_of(const Metadata* m) {
84 return *((intptr_t**)m);
85 }
|
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/archiveUtils.hpp"
27 #include "cds/archiveBuilder.hpp"
28 #include "cds/cdsConfig.hpp"
29 #include "cds/cppVtables.hpp"
30 #include "cds/metaspaceShared.hpp"
31 #include "logging/log.hpp"
32 #include "oops/flatArrayKlass.hpp"
33 #include "oops/inlineKlass.hpp"
34 #include "oops/instanceClassLoaderKlass.hpp"
35 #include "oops/instanceKlass.inline.hpp"
36 #include "oops/instanceMirrorKlass.hpp"
37 #include "oops/instanceRefKlass.hpp"
38 #include "oops/instanceStackChunkKlass.hpp"
39 #include "oops/methodData.hpp"
40 #include "oops/objArrayKlass.hpp"
41 #include "oops/typeArrayKlass.hpp"
42 #include "runtime/arguments.hpp"
43 #include "utilities/globalDefinitions.hpp"
44
45 // Objects of the Metadata types (such as Klass and ConstantPool) have C++ vtables.
46 // (In GCC this is the field <Type>::_vptr, i.e., first word in the object.)
47 //
48 // Addresses of the vtables and the methods may be different across JVM runs,
49 // if libjvm.so is dynamically loaded at a different base address.
50 //
51 // To ensure that the Metadata objects in the CDS archive always have the correct vtable:
52 //
53 // + at dump time: we redirect the _vptr to point to our own vtables inside
54 // the CDS image
55 // + at run time: we clone the actual contents of the vtables from libjvm.so
56 // into our own tables.
57
58 // Currently, the archive contains ONLY the following types of objects that have C++ vtables.
59 // NOTE: this table must be in-sync with sun.jvm.hotspot.memory.FileMapInfo::populateMetadataTypeArray().
60 #define CPP_VTABLE_TYPES_DO(f) \
61 f(ConstantPool) \
62 f(InstanceKlass) \
63 f(InstanceClassLoaderKlass) \
64 f(InstanceMirrorKlass) \
65 f(InstanceRefKlass) \
66 f(InstanceStackChunkKlass) \
67 f(Method) \
68 f(ObjArrayKlass) \
69 f(TypeArrayKlass) \
70 f(FlatArrayKlass) \
71 f(InlineKlass)
72
73 class CppVtableInfo {
74 intptr_t _vtable_size;
75 intptr_t _cloned_vtable[1]; // Pseudo flexible array member.
76 static size_t cloned_vtable_offset() { return offset_of(CppVtableInfo, _cloned_vtable); }
77 public:
78 int vtable_size() { return int(uintx(_vtable_size)); }
79 void set_vtable_size(int n) { _vtable_size = intptr_t(n); }
80 // Using _cloned_vtable[i] for i > 0 causes undefined behavior. We use address calculation instead.
81 intptr_t* cloned_vtable() { return (intptr_t*)((char*)this + cloned_vtable_offset()); }
82 void zero() { memset(cloned_vtable(), 0, sizeof(intptr_t) * vtable_size()); }
83 // Returns the address of the next CppVtableInfo that can be placed immediately after this CppVtableInfo
84 static size_t byte_size(int vtable_size) {
85 return cloned_vtable_offset() + (sizeof(intptr_t) * vtable_size);
86 }
87 };
88
89 static inline intptr_t* vtable_of(const Metadata* m) {
90 return *((intptr_t**)m);
91 }
|