< prev index next >

src/hotspot/share/cds/cppVtables.cpp

Print this page

 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 "precompiled.hpp"
 26 #include "cds/archiveUtils.hpp"
 27 #include "cds/archiveBuilder.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/methodData.hpp"
 35 #include "oops/objArrayKlass.hpp"
 36 #include "oops/typeArrayKlass.hpp"
 37 #include "runtime/arguments.hpp"
 38 #include "utilities/globalDefinitions.hpp"
 39 
 40 // Objects of the Metadata types (such as Klass and ConstantPool) have C++ vtables.
 41 // (In GCC this is the field <Type>::_vptr, i.e., first word in the object.)
 42 //
 43 // Addresses of the vtables and the methods may be different across JVM runs,
 44 // if libjvm.so is dynamically loaded at a different base address.
 45 //
 46 // To ensure that the Metadata objects in the CDS archive always have the correct vtable:
 47 //
 48 // + at dump time:  we redirect the _vptr to point to our own vtables inside
 49 //                  the CDS image
 50 // + at run time:   we clone the actual contents of the vtables from libjvm.so
 51 //                  into our own tables.
 52 
 53 // Currently, the archive contains ONLY the following types of objects that have C++ vtables.

 54 #define CPP_VTABLE_TYPES_DO(f) \
 55   f(ConstantPool) \
 56   f(InstanceKlass) \
 57   f(InstanceClassLoaderKlass) \
 58   f(InstanceMirrorKlass) \
 59   f(InstanceRefKlass) \
 60   f(Method) \
 61   f(ObjArrayKlass) \
 62   f(TypeArrayKlass)


 63 
 64 class CppVtableInfo {
 65   intptr_t _vtable_size;
 66   intptr_t _cloned_vtable[1];
 67 public:
 68   static int num_slots(int vtable_size) {
 69     return 1 + vtable_size; // Need to add the space occupied by _vtable_size;
 70   }
 71   int vtable_size()           { return int(uintx(_vtable_size)); }
 72   void set_vtable_size(int n) { _vtable_size = intptr_t(n); }
 73   intptr_t* cloned_vtable()   { return &_cloned_vtable[0]; }
 74   void zero()                 { memset(_cloned_vtable, 0, sizeof(intptr_t) * vtable_size()); }
 75   // Returns the address of the next CppVtableInfo that can be placed immediately after this CppVtableInfo
 76   static size_t byte_size(int vtable_size) {
 77     CppVtableInfo i;
 78     return pointer_delta(&i._cloned_vtable[vtable_size], &i, sizeof(u1));
 79   }
 80 };
 81 
 82 static inline intptr_t* vtable_of(const Metadata* m) {

 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 "precompiled.hpp"
 26 #include "cds/archiveUtils.hpp"
 27 #include "cds/archiveBuilder.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/instanceMirrorKlass.hpp"
 35 #include "oops/instanceRefKlass.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 // NOTE: this table must be in-sync with sun.jvm.hotspot.memory.FileMapInfo::populateMetadataTypeArray().
 57 #define CPP_VTABLE_TYPES_DO(f) \
 58   f(ConstantPool) \
 59   f(InstanceKlass) \
 60   f(InstanceClassLoaderKlass) \
 61   f(InstanceMirrorKlass) \
 62   f(InstanceRefKlass) \
 63   f(Method) \
 64   f(ObjArrayKlass) \
 65   f(TypeArrayKlass) \
 66   f(FlatArrayKlass) \
 67   f(InlineKlass)
 68 
 69 class CppVtableInfo {
 70   intptr_t _vtable_size;
 71   intptr_t _cloned_vtable[1];
 72 public:
 73   static int num_slots(int vtable_size) {
 74     return 1 + vtable_size; // Need to add the space occupied by _vtable_size;
 75   }
 76   int vtable_size()           { return int(uintx(_vtable_size)); }
 77   void set_vtable_size(int n) { _vtable_size = intptr_t(n); }
 78   intptr_t* cloned_vtable()   { return &_cloned_vtable[0]; }
 79   void zero()                 { memset(_cloned_vtable, 0, sizeof(intptr_t) * vtable_size()); }
 80   // Returns the address of the next CppVtableInfo that can be placed immediately after this CppVtableInfo
 81   static size_t byte_size(int vtable_size) {
 82     CppVtableInfo i;
 83     return pointer_delta(&i._cloned_vtable[vtable_size], &i, sizeof(u1));
 84   }
 85 };
 86 
 87 static inline intptr_t* vtable_of(const Metadata* m) {
< prev index next >