src/share/vm/oops/klassVtable.hpp

Mon, 12 Aug 2019 18:30:40 +0300

author
apetushkov
date
Mon, 12 Aug 2019 18:30:40 +0300
changeset 9858
b985cbb00e68
parent 8509
cb4af293fe70
child 8604
04d83ba48607
permissions
-rw-r--r--

8223147: JFR Backport
8199712: Flight Recorder
8203346: JFR: Inconsistent signature of jfr_add_string_constant
8195817: JFR.stop should require name of recording
8195818: JFR.start should increase autogenerated name by one
8195819: Remove recording=x from jcmd JFR.check output
8203921: JFR thread sampling is missing fixes from JDK-8194552
8203929: Limit amount of data for JFR.dump
8203664: JFR start failure after AppCDS archive created with JFR StartFlightRecording
8003209: JFR events for network utilization
8207392: [PPC64] Implement JFR profiling
8202835: jfr/event/os/TestSystemProcess.java fails on missing events
Summary: Backport JFR from JDK11. Initial integration
Reviewed-by: neugens

duke@435 1 /*
sspitsyn@7636 2 * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #ifndef SHARE_VM_OOPS_KLASSVTABLE_HPP
stefank@2314 26 #define SHARE_VM_OOPS_KLASSVTABLE_HPP
stefank@2314 27
stefank@2314 28 #include "memory/allocation.hpp"
stefank@2314 29 #include "oops/oopsHierarchy.hpp"
stefank@2314 30 #include "runtime/handles.hpp"
stefank@2314 31 #include "utilities/growableArray.hpp"
stefank@2314 32
coleenp@4037 33 // A klassVtable abstracts the variable-length vtable that is embedded in InstanceKlass
coleenp@4142 34 // and ArrayKlass. klassVtable objects are used just as convenient transient accessors to the vtable,
duke@435 35 // not to actually hold the vtable data.
duke@435 36 // Note: the klassVtable should not be accessed before the class has been verified
duke@435 37 // (until that point, the vtable is uninitialized).
duke@435 38
duke@435 39 // Currently a klassVtable contains a direct reference to the vtable data, and is therefore
duke@435 40 // not preserved across GCs.
duke@435 41
duke@435 42 class vtableEntry;
duke@435 43
duke@435 44 class klassVtable : public ResourceObj {
duke@435 45 KlassHandle _klass; // my klass
duke@435 46 int _tableOffset; // offset of start of vtable data within klass
duke@435 47 int _length; // length of vtable (number of entries)
duke@435 48 #ifndef PRODUCT
duke@435 49 int _verify_count; // to make verify faster
duke@435 50 #endif
duke@435 51
duke@435 52 // Ordering important, so greater_than (>) can be used as an merge operator.
duke@435 53 enum AccessType {
duke@435 54 acc_private = 0,
duke@435 55 acc_package_private = 1,
duke@435 56 acc_publicprotected = 2
duke@435 57 };
duke@435 58
duke@435 59 public:
duke@435 60 klassVtable(KlassHandle h_klass, void* base, int length) : _klass(h_klass) {
duke@435 61 _tableOffset = (address)base - (address)h_klass(); _length = length;
duke@435 62 }
duke@435 63
duke@435 64 // accessors
duke@435 65 vtableEntry* table() const { return (vtableEntry*)(address(_klass()) + _tableOffset); }
duke@435 66 KlassHandle klass() const { return _klass; }
duke@435 67 int length() const { return _length; }
coleenp@4037 68 inline Method* method_at(int i) const;
coleenp@4037 69 inline Method* unchecked_method_at(int i) const;
coleenp@4037 70 inline Method** adr_method_at(int i) const;
duke@435 71
duke@435 72 // searching; all methods return -1 if not found
coleenp@4037 73 int index_of(Method* m) const { return index_of(m, _length); }
coleenp@2497 74 int index_of_miranda(Symbol* name, Symbol* signature);
duke@435 75
duke@435 76 void initialize_vtable(bool checkconstraints, TRAPS); // initialize vtable of a new klass
duke@435 77
coleenp@2777 78 // CDS/RedefineClasses support - clear vtables so they can be reinitialized
coleenp@2777 79 // at dump time. Clearing gives us an easy way to tell if the vtable has
coleenp@2777 80 // already been reinitialized at dump time (see dump.cpp). Vtables can
coleenp@2777 81 // be initialized at run time by RedefineClasses so dumping the right order
coleenp@2777 82 // is necessary.
coleenp@2777 83 void clear_vtable();
coleenp@2777 84 bool is_initialized();
coleenp@2777 85
coleenp@2777 86 // computes vtable length (in words) and the number of miranda methods
kamg@4245 87 static void compute_vtable_size_and_num_mirandas(
kamg@4245 88 int* vtable_length, int* num_new_mirandas,
kamg@4245 89 GrowableArray<Method*>* all_mirandas, Klass* super,
kamg@4245 90 Array<Method*>* methods, AccessFlags class_flags, Handle classloader,
kamg@4245 91 Symbol* classname, Array<Klass*>* local_interfaces, TRAPS);
duke@435 92
dcubed@4562 93 #if INCLUDE_JVMTI
duke@435 94 // RedefineClasses() API support:
duke@435 95 // If any entry of this vtable points to any of old_methods,
duke@435 96 // replace it with the corresponding new_method.
duke@435 97 // trace_name_printed is set to true if the current call has
duke@435 98 // printed the klass name so that other routines in the adjust_*
duke@435 99 // group don't print the klass name.
acorn@5848 100 bool adjust_default_method(int vtable_index, Method* old_method, Method* new_method);
sspitsyn@7636 101 void adjust_method_entries(InstanceKlass* holder, bool * trace_name_printed);
dcubed@4562 102 bool check_no_old_or_obsolete_entries();
dcubed@4562 103 void dump_vtable();
dcubed@4562 104 #endif // INCLUDE_JVMTI
duke@435 105
duke@435 106 // Debugging code
duke@435 107 void print() PRODUCT_RETURN;
duke@435 108 void verify(outputStream* st, bool force = false);
duke@435 109 static void print_statistics() PRODUCT_RETURN;
duke@435 110
duke@435 111 protected:
duke@435 112 friend class vtableEntry;
duke@435 113 private:
acorn@1087 114 enum { VTABLE_TRANSITIVE_OVERRIDE_VERSION = 51 } ;
duke@435 115 void copy_vtable_to(vtableEntry* start);
duke@435 116 int initialize_from_super(KlassHandle super);
coleenp@4037 117 int index_of(Method* m, int len) const; // same as index_of, but search only up to len
coleenp@4037 118 void put_method_at(Method* m, int index);
coleenp@4037 119 static bool needs_new_vtable_entry(methodHandle m, Klass* super, Handle classloader, Symbol* classname, AccessFlags access_flags, TRAPS);
duke@435 120
acorn@5848 121 bool update_inherited_vtable(InstanceKlass* klass, methodHandle target_method, int super_vtable_len, int default_index, bool checkconstraints, TRAPS);
coleenp@4037 122 InstanceKlass* find_transitive_override(InstanceKlass* initialsuper, methodHandle target_method, int vtable_index,
coleenp@2497 123 Handle target_loader, Symbol* target_classname, Thread* THREAD);
duke@435 124
duke@435 125 // support for miranda methods
duke@435 126 bool is_miranda_entry_at(int i);
drchase@5732 127 int fill_in_mirandas(int initialized);
acorn@5848 128 static bool is_miranda(Method* m, Array<Method*>* class_methods,
acorn@5848 129 Array<Method*>* default_methods, Klass* super);
kamg@4245 130 static void add_new_mirandas_to_lists(
kamg@4245 131 GrowableArray<Method*>* new_mirandas,
kamg@4245 132 GrowableArray<Method*>* all_mirandas,
acorn@5848 133 Array<Method*>* current_interface_methods,
acorn@5848 134 Array<Method*>* class_methods,
acorn@5848 135 Array<Method*>* default_methods,
kamg@4245 136 Klass* super);
kamg@4245 137 static void get_mirandas(
kamg@4245 138 GrowableArray<Method*>* new_mirandas,
kamg@4245 139 GrowableArray<Method*>* all_mirandas, Klass* super,
acorn@5848 140 Array<Method*>* class_methods,
acorn@5848 141 Array<Method*>* default_methods,
acorn@5848 142 Array<Klass*>* local_interfaces);
duke@435 143 void verify_against(outputStream* st, klassVtable* vt, int index);
coleenp@4037 144 inline InstanceKlass* ik() const;
jiangli@8509 145 // When loading a class from CDS archive at run time, and no class redefintion
jiangli@8509 146 // has happened, it is expected that the class's itable/vtables are
jiangli@8509 147 // laid out exactly the same way as they had been during dump time.
jiangli@8509 148 // Therefore, in klassVtable::initialize_[iv]table, we do not layout the
jiangli@8509 149 // tables again. Instead, we only rerun the process to create/check
jiangli@8509 150 // the class loader constraints. In non-product builds, we add asserts to
jiangli@8509 151 // guarantee that the table's layout would be the same as at dump time.
jiangli@8509 152 //
jiangli@8509 153 // If JVMTI redefines any class, the read-only shared memory are remapped
jiangli@8509 154 // as read-write. A shared class' vtable/itable are re-initialized and
jiangli@8509 155 // might have different layout due to class redefinition of the shared class
jiangli@8509 156 // or its super types.
jiangli@8509 157 bool is_preinitialized_vtable();
duke@435 158 };
duke@435 159
duke@435 160
duke@435 161 // private helper class for klassVtable
duke@435 162 // description of entry points:
duke@435 163 // destination is interpreted:
duke@435 164 // from_compiled_code_entry_point -> c2iadapter
duke@435 165 // from_interpreter_entry_point -> interpreter entry point
duke@435 166 // destination is compiled:
duke@435 167 // from_compiled_code_entry_point -> nmethod entry point
duke@435 168 // from_interpreter_entry_point -> i2cadapter
duke@435 169 class vtableEntry VALUE_OBJ_CLASS_SPEC {
twisti@5726 170 friend class VMStructs;
twisti@5726 171
duke@435 172 public:
duke@435 173 // size in words
duke@435 174 static int size() {
duke@435 175 return sizeof(vtableEntry) / sizeof(HeapWord);
duke@435 176 }
duke@435 177 static int method_offset_in_bytes() { return offset_of(vtableEntry, _method); }
coleenp@4037 178 Method* method() const { return _method; }
duke@435 179
duke@435 180 private:
coleenp@4037 181 Method* _method;
coleenp@4037 182 void set(Method* method) { assert(method != NULL, "use clear"); _method = method; }
duke@435 183 void clear() { _method = NULL; }
duke@435 184 void print() PRODUCT_RETURN;
duke@435 185 void verify(klassVtable* vt, outputStream* st);
duke@435 186
duke@435 187 friend class klassVtable;
duke@435 188 };
duke@435 189
duke@435 190
coleenp@4037 191 inline Method* klassVtable::method_at(int i) const {
duke@435 192 assert(i >= 0 && i < _length, "index out of bounds");
duke@435 193 assert(table()[i].method() != NULL, "should not be null");
coleenp@4037 194 assert(((Metadata*)table()[i].method())->is_method(), "should be method");
duke@435 195 return table()[i].method();
duke@435 196 }
duke@435 197
coleenp@4037 198 inline Method* klassVtable::unchecked_method_at(int i) const {
duke@435 199 assert(i >= 0 && i < _length, "index out of bounds");
duke@435 200 return table()[i].method();
duke@435 201 }
duke@435 202
coleenp@4037 203 inline Method** klassVtable::adr_method_at(int i) const {
duke@435 204 // Allow one past the last entry to be referenced; useful for loop bounds.
duke@435 205 assert(i >= 0 && i <= _length, "index out of bounds");
coleenp@4037 206 return (Method**)(address(table() + i) + vtableEntry::method_offset_in_bytes());
duke@435 207 }
duke@435 208
duke@435 209 // --------------------------------------------------------------------------------
duke@435 210 class klassItable;
duke@435 211 class itableMethodEntry;
duke@435 212
duke@435 213 class itableOffsetEntry VALUE_OBJ_CLASS_SPEC {
duke@435 214 private:
coleenp@4037 215 Klass* _interface;
duke@435 216 int _offset;
duke@435 217 public:
coleenp@4037 218 Klass* interface_klass() const { return _interface; }
duke@435 219 int offset() const { return _offset; }
duke@435 220
coleenp@4037 221 static itableMethodEntry* method_entry(Klass* k, int offset) { return (itableMethodEntry*)(((address)k) + offset); }
coleenp@4037 222 itableMethodEntry* first_method_entry(Klass* k) { return method_entry(k, _offset); }
duke@435 223
coleenp@4037 224 void initialize(Klass* interf, int offset) { _interface = interf; _offset = offset; }
duke@435 225
duke@435 226 // Static size and offset accessors
duke@435 227 static int size() { return sizeof(itableOffsetEntry) / HeapWordSize; } // size in words
duke@435 228 static int interface_offset_in_bytes() { return offset_of(itableOffsetEntry, _interface); }
duke@435 229 static int offset_offset_in_bytes() { return offset_of(itableOffsetEntry, _offset); }
duke@435 230
duke@435 231 friend class klassItable;
duke@435 232 };
duke@435 233
duke@435 234
duke@435 235 class itableMethodEntry VALUE_OBJ_CLASS_SPEC {
duke@435 236 private:
coleenp@4037 237 Method* _method;
duke@435 238
duke@435 239 public:
coleenp@4037 240 Method* method() const { return _method; }
duke@435 241
duke@435 242 void clear() { _method = NULL; }
duke@435 243
coleenp@4037 244 void initialize(Method* method);
duke@435 245
duke@435 246 // Static size and offset accessors
duke@435 247 static int size() { return sizeof(itableMethodEntry) / HeapWordSize; } // size in words
duke@435 248 static int method_offset_in_bytes() { return offset_of(itableMethodEntry, _method); }
duke@435 249
duke@435 250 friend class klassItable;
duke@435 251 };
duke@435 252
duke@435 253 //
duke@435 254 // Format of an itable
duke@435 255 //
duke@435 256 // ---- offset table ---
coleenp@4037 257 // Klass* of interface 1 \
duke@435 258 // offset to vtable from start of oop / offset table entry
duke@435 259 // ...
coleenp@4037 260 // Klass* of interface n \
duke@435 261 // offset to vtable from start of oop / offset table entry
duke@435 262 // --- vtable for interface 1 ---
coleenp@4037 263 // Method* \
duke@435 264 // compiler entry point / method table entry
duke@435 265 // ...
coleenp@4037 266 // Method* \
duke@435 267 // compiler entry point / method table entry
duke@435 268 // -- vtable for interface 2 ---
duke@435 269 // ...
duke@435 270 //
duke@435 271 class klassItable : public ResourceObj {
duke@435 272 private:
duke@435 273 instanceKlassHandle _klass; // my klass
duke@435 274 int _table_offset; // offset of start of itable data within klass (in words)
duke@435 275 int _size_offset_table; // size of offset table (in itableOffset entries)
duke@435 276 int _size_method_table; // size of methodtable (in itableMethodEntry entries)
duke@435 277
duke@435 278 void initialize_itable_for_interface(int method_table_offset, KlassHandle interf_h, bool checkconstraints, TRAPS);
duke@435 279 public:
duke@435 280 klassItable(instanceKlassHandle klass);
duke@435 281
duke@435 282 itableOffsetEntry* offset_entry(int i) { assert(0 <= i && i <= _size_offset_table, "index out of bounds");
duke@435 283 return &((itableOffsetEntry*)vtable_start())[i]; }
duke@435 284
duke@435 285 itableMethodEntry* method_entry(int i) { assert(0 <= i && i <= _size_method_table, "index out of bounds");
duke@435 286 return &((itableMethodEntry*)method_start())[i]; }
duke@435 287
dcubed@451 288 int size_offset_table() { return _size_offset_table; }
duke@435 289
duke@435 290 // Initialization
duke@435 291 void initialize_itable(bool checkconstraints, TRAPS);
duke@435 292
duke@435 293 // Updates
coleenp@4037 294 void initialize_with_method(Method* m);
duke@435 295
dcubed@4562 296 #if INCLUDE_JVMTI
duke@435 297 // RedefineClasses() API support:
duke@435 298 // if any entry of this itable points to any of old_methods,
duke@435 299 // replace it with the corresponding new_method.
duke@435 300 // trace_name_printed is set to true if the current call has
duke@435 301 // printed the klass name so that other routines in the adjust_*
duke@435 302 // group don't print the klass name.
sspitsyn@7636 303 void adjust_method_entries(InstanceKlass* holder, bool * trace_name_printed);
dcubed@4562 304 bool check_no_old_or_obsolete_entries();
dcubed@4562 305 void dump_itable();
dcubed@4562 306 #endif // INCLUDE_JVMTI
duke@435 307
duke@435 308 // Setup of itable
acorn@5848 309 static int assign_itable_indices_for_interface(Klass* klass);
drchase@5732 310 static int method_count_for_interface(Klass* klass);
coleenp@4037 311 static int compute_itable_size(Array<Klass*>* transitive_interfaces);
duke@435 312 static void setup_itable_offset_table(instanceKlassHandle klass);
duke@435 313
duke@435 314 // Resolving of method to index
coleenp@4037 315 static Method* method_for_itable_index(Klass* klass, int itable_index);
duke@435 316
duke@435 317 // Debugging/Statistics
duke@435 318 static void print_statistics() PRODUCT_RETURN;
duke@435 319 private:
duke@435 320 intptr_t* vtable_start() const { return ((intptr_t*)_klass()) + _table_offset; }
duke@435 321 intptr_t* method_start() const { return vtable_start() + _size_offset_table * itableOffsetEntry::size(); }
duke@435 322
duke@435 323 // Helper methods
duke@435 324 static int calc_itable_size(int num_interfaces, int num_methods) { return (num_interfaces * itableOffsetEntry::size()) + (num_methods * itableMethodEntry::size()); }
duke@435 325
duke@435 326 // Statistics
duke@435 327 NOT_PRODUCT(static int _total_classes;) // Total no. of classes with itables
duke@435 328 NOT_PRODUCT(static long _total_size;) // Total no. of bytes used for itables
duke@435 329
duke@435 330 static void update_stats(int size) PRODUCT_RETURN NOT_PRODUCT({ _total_classes++; _total_size += size; })
duke@435 331 };
stefank@2314 332
stefank@2314 333 #endif // SHARE_VM_OOPS_KLASSVTABLE_HPP

mercurial