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];
70 public:
71 static int num_slots(int vtable_size) {
72 return 1 + vtable_size; // Need to add the space occupied by _vtable_size;
73 }
74 int vtable_size() { return int(uintx(_vtable_size)); }
75 void set_vtable_size(int n) { _vtable_size = intptr_t(n); }
76 intptr_t* cloned_vtable() { return &_cloned_vtable[0]; }
77 void zero() { memset(_cloned_vtable, 0, sizeof(intptr_t) * vtable_size()); }
78 // Returns the address of the next CppVtableInfo that can be placed immediately after this CppVtableInfo
79 static size_t byte_size(int vtable_size) {
80 CppVtableInfo i;
81 return pointer_delta(&i._cloned_vtable[vtable_size], &i, sizeof(u1));
82 }
83 };
84
85 static inline intptr_t* vtable_of(const Metadata* m) {
|
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];
76 public:
77 static int num_slots(int vtable_size) {
78 return 1 + vtable_size; // Need to add the space occupied by _vtable_size;
79 }
80 int vtable_size() { return int(uintx(_vtable_size)); }
81 void set_vtable_size(int n) { _vtable_size = intptr_t(n); }
82 intptr_t* cloned_vtable() { return &_cloned_vtable[0]; }
83 void zero() { memset(_cloned_vtable, 0, sizeof(intptr_t) * vtable_size()); }
84 // Returns the address of the next CppVtableInfo that can be placed immediately after this CppVtableInfo
85 static size_t byte_size(int vtable_size) {
86 CppVtableInfo i;
87 return pointer_delta(&i._cloned_vtable[vtable_size], &i, sizeof(u1));
88 }
89 };
90
91 static inline intptr_t* vtable_of(const Metadata* m) {
|