< prev index next >

src/hotspot/share/cds/cppVtables.cpp

Print this page

 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   }

 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/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];
 69 public:
 70   static int num_slots(int vtable_size) {
 71     return 1 + vtable_size; // Need to add the space occupied by _vtable_size;
 72   }
 73   int vtable_size()           { return int(uintx(_vtable_size)); }
 74   void set_vtable_size(int n) { _vtable_size = intptr_t(n); }
 75   intptr_t* cloned_vtable()   { return &_cloned_vtable[0]; }
 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     CppVtableInfo i;
 80     return pointer_delta(&i._cloned_vtable[vtable_size], &i, sizeof(u1));
 81   }
< prev index next >