< prev index next >

src/hotspot/share/cds/cppVtables.cpp

Print this page

 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/aotGrowableArray.hpp"
 26 #include "cds/aotMetaspace.hpp"
 27 #include "cds/archiveBuilder.hpp"
 28 #include "cds/archiveUtils.hpp"
 29 #include "cds/cdsConfig.hpp"
 30 #include "cds/cppVtables.hpp"
 31 #include "logging/log.hpp"
 32 #include "memory/resourceArea.hpp"


 33 #include "oops/instanceClassLoaderKlass.hpp"

 34 #include "oops/instanceMirrorKlass.hpp"
 35 #include "oops/instanceRefKlass.hpp"
 36 #include "oops/instanceStackChunkKlass.hpp"
 37 #include "oops/methodCounters.hpp"
 38 #include "oops/methodData.hpp"
 39 #include "oops/objArrayKlass.hpp"

 40 #include "oops/trainingData.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 
 59 #ifndef PRODUCT
 60 
 61 // AOTGrowableArray has a vtable only when in non-product builds (due to
 62 // the virtual printing functions in AnyObj).
 63 
 64 using GrowableArray_ModuleEntry_ptr = AOTGrowableArray<ModuleEntry*>;
 65 
 66 #define DEBUG_CPP_VTABLE_TYPES_DO(f) \
 67   f(GrowableArray_ModuleEntry_ptr) \
 68 
 69 #endif
 70 
 71 // Currently, the archive contains ONLY the following types of objects that have C++ vtables.

 72 #define CPP_VTABLE_TYPES_DO(f) \
 73   f(ConstantPool) \
 74   f(InstanceKlass) \
 75   f(InstanceClassLoaderKlass) \
 76   f(InstanceMirrorKlass) \
 77   f(InstanceRefKlass) \
 78   f(InstanceStackChunkKlass) \
 79   f(Method) \
 80   f(MethodData) \
 81   f(MethodCounters) \
 82   f(ObjArrayKlass) \
 83   f(TypeArrayKlass) \




 84   f(KlassTrainingData) \
 85   f(MethodTrainingData) \
 86   f(CompileTrainingData) \
 87   NOT_PRODUCT(DEBUG_CPP_VTABLE_TYPES_DO(f))
 88 
 89 class CppVtableInfo {
 90   intptr_t _vtable_size;
 91   intptr_t _cloned_vtable[1]; // Pseudo flexible array member.
 92   static size_t cloned_vtable_offset() { return offset_of(CppVtableInfo, _cloned_vtable); }
 93 public:
 94   int vtable_size()           { return int(uintx(_vtable_size)); }
 95   void set_vtable_size(int n) { _vtable_size = intptr_t(n); }
 96   // Using _cloned_vtable[i] for i > 0 causes undefined behavior. We use address calculation instead.
 97   intptr_t* cloned_vtable()   { return (intptr_t*)((char*)this + cloned_vtable_offset()); }
 98   void zero()                 { memset(cloned_vtable(), 0, sizeof(intptr_t) * vtable_size()); }
 99   // Returns the address of the next CppVtableInfo that can be placed immediately after this CppVtableInfo
100   static size_t byte_size(int vtable_size) {
101     return cloned_vtable_offset() + (sizeof(intptr_t) * vtable_size);
102   }
103 };

 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/aotGrowableArray.hpp"
 26 #include "cds/aotMetaspace.hpp"
 27 #include "cds/archiveBuilder.hpp"
 28 #include "cds/archiveUtils.hpp"
 29 #include "cds/cdsConfig.hpp"
 30 #include "cds/cppVtables.hpp"
 31 #include "logging/log.hpp"
 32 #include "memory/resourceArea.hpp"
 33 #include "oops/flatArrayKlass.hpp"
 34 #include "oops/inlineKlass.hpp"
 35 #include "oops/instanceClassLoaderKlass.hpp"
 36 #include "oops/instanceKlass.inline.hpp"
 37 #include "oops/instanceMirrorKlass.hpp"
 38 #include "oops/instanceRefKlass.hpp"
 39 #include "oops/instanceStackChunkKlass.hpp"
 40 #include "oops/methodCounters.hpp"
 41 #include "oops/methodData.hpp"
 42 #include "oops/objArrayKlass.hpp"
 43 #include "oops/refArrayKlass.hpp"
 44 #include "oops/trainingData.hpp"
 45 #include "oops/typeArrayKlass.hpp"
 46 #include "runtime/arguments.hpp"
 47 #include "utilities/globalDefinitions.hpp"
 48 
 49 // Objects of the Metadata types (such as Klass and ConstantPool) have C++ vtables.
 50 // (In GCC this is the field <Type>::_vptr, i.e., first word in the object.)
 51 //
 52 // Addresses of the vtables and the methods may be different across JVM runs,
 53 // if libjvm.so is dynamically loaded at a different base address.
 54 //
 55 // To ensure that the Metadata objects in the CDS archive always have the correct vtable:
 56 //
 57 // + at dump time:  we redirect the _vptr to point to our own vtables inside
 58 //                  the CDS image
 59 // + at run time:   we clone the actual contents of the vtables from libjvm.so
 60 //                  into our own tables.
 61 
 62 
 63 #ifndef PRODUCT
 64 
 65 // AOTGrowableArray has a vtable only when in non-product builds (due to
 66 // the virtual printing functions in AnyObj).
 67 
 68 using GrowableArray_ModuleEntry_ptr = AOTGrowableArray<ModuleEntry*>;
 69 
 70 #define DEBUG_CPP_VTABLE_TYPES_DO(f) \
 71   f(GrowableArray_ModuleEntry_ptr) \
 72 
 73 #endif
 74 
 75 // Currently, the archive contains ONLY the following types of objects that have C++ vtables.
 76 // NOTE: this table must be in-sync with sun.jvm.hotspot.memory.FileMapInfo::populateMetadataTypeArray().
 77 #define CPP_VTABLE_TYPES_DO(f) \
 78   f(ConstantPool) \
 79   f(InstanceKlass) \
 80   f(InstanceClassLoaderKlass) \
 81   f(InstanceMirrorKlass) \
 82   f(InstanceRefKlass) \
 83   f(InstanceStackChunkKlass) \
 84   f(Method) \
 85   f(MethodData) \
 86   f(MethodCounters) \

 87   f(TypeArrayKlass) \
 88   f(ObjArrayKlass) \
 89   f(RefArrayKlass) \
 90   f(FlatArrayKlass) \
 91   f(InlineKlass) \
 92   f(KlassTrainingData) \
 93   f(MethodTrainingData) \
 94   f(CompileTrainingData) \
 95   NOT_PRODUCT(DEBUG_CPP_VTABLE_TYPES_DO(f))
 96 
 97 class CppVtableInfo {
 98   intptr_t _vtable_size;
 99   intptr_t _cloned_vtable[1]; // Pseudo flexible array member.
100   static size_t cloned_vtable_offset() { return offset_of(CppVtableInfo, _cloned_vtable); }
101 public:
102   int vtable_size()           { return int(uintx(_vtable_size)); }
103   void set_vtable_size(int n) { _vtable_size = intptr_t(n); }
104   // Using _cloned_vtable[i] for i > 0 causes undefined behavior. We use address calculation instead.
105   intptr_t* cloned_vtable()   { return (intptr_t*)((char*)this + cloned_vtable_offset()); }
106   void zero()                 { memset(cloned_vtable(), 0, sizeof(intptr_t) * vtable_size()); }
107   // Returns the address of the next CppVtableInfo that can be placed immediately after this CppVtableInfo
108   static size_t byte_size(int vtable_size) {
109     return cloned_vtable_offset() + (sizeof(intptr_t) * vtable_size);
110   }
111 };
< prev index next >