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