< 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 "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/methodCounters.hpp"
 36 #include "oops/methodData.hpp"
 37 #include "oops/trainingData.hpp"
 38 #include "oops/objArrayKlass.hpp"

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

 57 #define CPP_VTABLE_TYPES_DO(f) \
 58   f(ConstantPool) \
 59   f(InstanceKlass) \
 60   f(InstanceClassLoaderKlass) \
 61   f(InstanceMirrorKlass) \
 62   f(InstanceRefKlass) \
 63   f(InstanceStackChunkKlass) \
 64   f(Method) \
 65   f(MethodData) \
 66   f(MethodCounters) \
 67   f(ObjArrayKlass) \
 68   f(TypeArrayKlass) \



 69   f(KlassTrainingData) \
 70   f(MethodTrainingData) \
 71   f(CompileTrainingData)
 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 

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