annotate src/share/vm/oops/klassVtable.hpp @ 0:a61af66fc99e

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children f8236e79048a
rev   line source
duke@0 1 /*
duke@0 2 * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved.
duke@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 4 *
duke@0 5 * This code is free software; you can redistribute it and/or modify it
duke@0 6 * under the terms of the GNU General Public License version 2 only, as
duke@0 7 * published by the Free Software Foundation.
duke@0 8 *
duke@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@0 13 * accompanied this code).
duke@0 14 *
duke@0 15 * You should have received a copy of the GNU General Public License version
duke@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 18 *
duke@0 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@0 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@0 21 * have any questions.
duke@0 22 *
duke@0 23 */
duke@0 24
duke@0 25 // A klassVtable abstracts the variable-length vtable that is embedded in instanceKlass
duke@0 26 // and arrayKlass. klassVtable objects are used just as convenient transient accessors to the vtable,
duke@0 27 // not to actually hold the vtable data.
duke@0 28 // Note: the klassVtable should not be accessed before the class has been verified
duke@0 29 // (until that point, the vtable is uninitialized).
duke@0 30
duke@0 31 // Currently a klassVtable contains a direct reference to the vtable data, and is therefore
duke@0 32 // not preserved across GCs.
duke@0 33
duke@0 34 class vtableEntry;
duke@0 35
duke@0 36 class klassVtable : public ResourceObj {
duke@0 37 KlassHandle _klass; // my klass
duke@0 38 int _tableOffset; // offset of start of vtable data within klass
duke@0 39 int _length; // length of vtable (number of entries)
duke@0 40 #ifndef PRODUCT
duke@0 41 int _verify_count; // to make verify faster
duke@0 42 #endif
duke@0 43
duke@0 44 // Ordering important, so greater_than (>) can be used as an merge operator.
duke@0 45 enum AccessType {
duke@0 46 acc_private = 0,
duke@0 47 acc_package_private = 1,
duke@0 48 acc_publicprotected = 2
duke@0 49 };
duke@0 50
duke@0 51 public:
duke@0 52 klassVtable(KlassHandle h_klass, void* base, int length) : _klass(h_klass) {
duke@0 53 _tableOffset = (address)base - (address)h_klass(); _length = length;
duke@0 54 }
duke@0 55
duke@0 56 // accessors
duke@0 57 vtableEntry* table() const { return (vtableEntry*)(address(_klass()) + _tableOffset); }
duke@0 58 KlassHandle klass() const { return _klass; }
duke@0 59 int length() const { return _length; }
duke@0 60 inline methodOop method_at(int i) const;
duke@0 61 inline methodOop unchecked_method_at(int i) const;
duke@0 62 inline oop* adr_method_at(int i) const;
duke@0 63
duke@0 64 // searching; all methods return -1 if not found
duke@0 65 int index_of(methodOop m) const { return index_of(m, _length); }
duke@0 66 int index_of_miranda(symbolOop name, symbolOop signature);
duke@0 67
duke@0 68 void initialize_vtable(bool checkconstraints, TRAPS); // initialize vtable of a new klass
duke@0 69
duke@0 70 // conputes vtable length (in words) and the number of miranda methods
duke@0 71 static void compute_vtable_size_and_num_mirandas(int &vtable_length, int &num_miranda_methods,
duke@0 72 klassOop super, objArrayOop methods,
duke@0 73 AccessFlags class_flags, oop classloader,
duke@0 74 symbolOop classname, objArrayOop local_interfaces);
duke@0 75
duke@0 76 // RedefineClasses() API support:
duke@0 77 // If any entry of this vtable points to any of old_methods,
duke@0 78 // replace it with the corresponding new_method.
duke@0 79 // trace_name_printed is set to true if the current call has
duke@0 80 // printed the klass name so that other routines in the adjust_*
duke@0 81 // group don't print the klass name.
duke@0 82 void adjust_method_entries(methodOop* old_methods, methodOop* new_methods,
duke@0 83 int methods_length, bool * trace_name_printed);
duke@0 84
duke@0 85 // Garbage collection
duke@0 86 void oop_follow_contents();
duke@0 87 void oop_adjust_pointers();
duke@0 88
duke@0 89 #ifndef SERIALGC
duke@0 90 // Parallel Old
duke@0 91 void oop_follow_contents(ParCompactionManager* cm);
duke@0 92 void oop_update_pointers(ParCompactionManager* cm);
duke@0 93 void oop_update_pointers(ParCompactionManager* cm,
duke@0 94 HeapWord* beg_addr, HeapWord* end_addr);
duke@0 95 #endif // SERIALGC
duke@0 96
duke@0 97 // Iterators
duke@0 98 void oop_oop_iterate(OopClosure* blk);
duke@0 99 void oop_oop_iterate_m(OopClosure* blk, MemRegion mr);
duke@0 100
duke@0 101 // Debugging code
duke@0 102 void print() PRODUCT_RETURN;
duke@0 103 void verify(outputStream* st, bool force = false);
duke@0 104 static void print_statistics() PRODUCT_RETURN;
duke@0 105
duke@0 106 #ifndef PRODUCT
duke@0 107 bool check_no_old_entries();
duke@0 108 void dump_vtable();
duke@0 109 #endif
duke@0 110
duke@0 111 protected:
duke@0 112 friend class vtableEntry;
duke@0 113 private:
duke@0 114 void copy_vtable_to(vtableEntry* start);
duke@0 115 int initialize_from_super(KlassHandle super);
duke@0 116 int index_of(methodOop m, int len) const; // same as index_of, but search only up to len
duke@0 117 void put_method_at(methodOop m, int index);
duke@0 118 static bool needs_new_vtable_entry(methodOop m, klassOop super, oop classloader, symbolOop classname, AccessFlags access_flags);
duke@0 119 AccessType vtable_accessibility_at(int i);
duke@0 120
duke@0 121 bool update_super_vtable(instanceKlass* klass, methodHandle target_method, int super_vtable_len, bool checkconstraints, TRAPS);
duke@0 122
duke@0 123 // support for miranda methods
duke@0 124 bool is_miranda_entry_at(int i);
duke@0 125 void fill_in_mirandas(int& initialized);
duke@0 126 static bool is_miranda(methodOop m, objArrayOop class_methods, klassOop super);
duke@0 127 static void add_new_mirandas_to_list(GrowableArray<methodOop>* list_of_current_mirandas, objArrayOop current_interface_methods, objArrayOop class_methods, klassOop super);
duke@0 128 static void get_mirandas(GrowableArray<methodOop>* mirandas, klassOop super, objArrayOop class_methods, objArrayOop local_interfaces);
duke@0 129 static int get_num_mirandas(klassOop super, objArrayOop class_methods, objArrayOop local_interfaces);
duke@0 130
duke@0 131
duke@0 132 void verify_against(outputStream* st, klassVtable* vt, int index);
duke@0 133 inline instanceKlass* ik() const;
duke@0 134 };
duke@0 135
duke@0 136
duke@0 137 // private helper class for klassVtable
duke@0 138 // description of entry points:
duke@0 139 // destination is interpreted:
duke@0 140 // from_compiled_code_entry_point -> c2iadapter
duke@0 141 // from_interpreter_entry_point -> interpreter entry point
duke@0 142 // destination is compiled:
duke@0 143 // from_compiled_code_entry_point -> nmethod entry point
duke@0 144 // from_interpreter_entry_point -> i2cadapter
duke@0 145 class vtableEntry VALUE_OBJ_CLASS_SPEC {
duke@0 146 public:
duke@0 147 // size in words
duke@0 148 static int size() {
duke@0 149 return sizeof(vtableEntry) / sizeof(HeapWord);
duke@0 150 }
duke@0 151 static int method_offset_in_bytes() { return offset_of(vtableEntry, _method); }
duke@0 152 methodOop method() const { return _method; }
duke@0 153
duke@0 154 private:
duke@0 155 methodOop _method;
duke@0 156 void set(methodOop method) { assert(method != NULL, "use clear"); _method = method; }
duke@0 157 void clear() { _method = NULL; }
duke@0 158 void print() PRODUCT_RETURN;
duke@0 159 void verify(klassVtable* vt, outputStream* st);
duke@0 160
duke@0 161 friend class klassVtable;
duke@0 162 };
duke@0 163
duke@0 164
duke@0 165 inline methodOop klassVtable::method_at(int i) const {
duke@0 166 assert(i >= 0 && i < _length, "index out of bounds");
duke@0 167 assert(table()[i].method() != NULL, "should not be null");
duke@0 168 assert(oop(table()[i].method())->is_method(), "should be method");
duke@0 169 return table()[i].method();
duke@0 170 }
duke@0 171
duke@0 172 inline methodOop klassVtable::unchecked_method_at(int i) const {
duke@0 173 assert(i >= 0 && i < _length, "index out of bounds");
duke@0 174 return table()[i].method();
duke@0 175 }
duke@0 176
duke@0 177 inline oop* klassVtable::adr_method_at(int i) const {
duke@0 178 // Allow one past the last entry to be referenced; useful for loop bounds.
duke@0 179 assert(i >= 0 && i <= _length, "index out of bounds");
duke@0 180 return (oop*)(address(table() + i) + vtableEntry::method_offset_in_bytes());
duke@0 181 }
duke@0 182
duke@0 183 // --------------------------------------------------------------------------------
duke@0 184 class klassItable;
duke@0 185 class itableMethodEntry;
duke@0 186
duke@0 187 class itableOffsetEntry VALUE_OBJ_CLASS_SPEC {
duke@0 188 private:
duke@0 189 klassOop _interface;
duke@0 190 int _offset;
duke@0 191 public:
duke@0 192 klassOop interface_klass() const { return _interface; }
duke@0 193 int offset() const { return _offset; }
duke@0 194
duke@0 195 static itableMethodEntry* method_entry(klassOop k, int offset) { return (itableMethodEntry*)(((address)k) + offset); }
duke@0 196 itableMethodEntry* first_method_entry(klassOop k) { return method_entry(k, _offset); }
duke@0 197
duke@0 198 void initialize(klassOop interf, int offset) { _interface = interf; _offset = offset; }
duke@0 199
duke@0 200 // Static size and offset accessors
duke@0 201 static int size() { return sizeof(itableOffsetEntry) / HeapWordSize; } // size in words
duke@0 202 static int interface_offset_in_bytes() { return offset_of(itableOffsetEntry, _interface); }
duke@0 203 static int offset_offset_in_bytes() { return offset_of(itableOffsetEntry, _offset); }
duke@0 204
duke@0 205 friend class klassItable;
duke@0 206 };
duke@0 207
duke@0 208
duke@0 209 class itableMethodEntry VALUE_OBJ_CLASS_SPEC {
duke@0 210 private:
duke@0 211 methodOop _method;
duke@0 212
duke@0 213 public:
duke@0 214 methodOop method() const { return _method; }
duke@0 215
duke@0 216 void clear() { _method = NULL; }
duke@0 217
duke@0 218 void initialize(methodOop method);
duke@0 219
duke@0 220 // Static size and offset accessors
duke@0 221 static int size() { return sizeof(itableMethodEntry) / HeapWordSize; } // size in words
duke@0 222 static int method_offset_in_bytes() { return offset_of(itableMethodEntry, _method); }
duke@0 223
duke@0 224 friend class klassItable;
duke@0 225 };
duke@0 226
duke@0 227 //
duke@0 228 // Format of an itable
duke@0 229 //
duke@0 230 // ---- offset table ---
duke@0 231 // klassOop of interface 1 \
duke@0 232 // offset to vtable from start of oop / offset table entry
duke@0 233 // ...
duke@0 234 // klassOop of interface n \
duke@0 235 // offset to vtable from start of oop / offset table entry
duke@0 236 // --- vtable for interface 1 ---
duke@0 237 // methodOop \
duke@0 238 // compiler entry point / method table entry
duke@0 239 // ...
duke@0 240 // methodOop \
duke@0 241 // compiler entry point / method table entry
duke@0 242 // -- vtable for interface 2 ---
duke@0 243 // ...
duke@0 244 //
duke@0 245 class klassItable : public ResourceObj {
duke@0 246 private:
duke@0 247 instanceKlassHandle _klass; // my klass
duke@0 248 int _table_offset; // offset of start of itable data within klass (in words)
duke@0 249 int _size_offset_table; // size of offset table (in itableOffset entries)
duke@0 250 int _size_method_table; // size of methodtable (in itableMethodEntry entries)
duke@0 251
duke@0 252 void initialize_itable_for_interface(int method_table_offset, KlassHandle interf_h, bool checkconstraints, TRAPS);
duke@0 253 public:
duke@0 254 klassItable(instanceKlassHandle klass);
duke@0 255
duke@0 256 itableOffsetEntry* offset_entry(int i) { assert(0 <= i && i <= _size_offset_table, "index out of bounds");
duke@0 257 return &((itableOffsetEntry*)vtable_start())[i]; }
duke@0 258
duke@0 259 itableMethodEntry* method_entry(int i) { assert(0 <= i && i <= _size_method_table, "index out of bounds");
duke@0 260 return &((itableMethodEntry*)method_start())[i]; }
duke@0 261
duke@0 262 int nof_interfaces() { return _size_offset_table; }
duke@0 263
duke@0 264 // Initialization
duke@0 265 void initialize_itable(bool checkconstraints, TRAPS);
duke@0 266
duke@0 267 // Updates
duke@0 268 void initialize_with_method(methodOop m);
duke@0 269
duke@0 270 // RedefineClasses() API support:
duke@0 271 // if any entry of this itable points to any of old_methods,
duke@0 272 // replace it with the corresponding new_method.
duke@0 273 // trace_name_printed is set to true if the current call has
duke@0 274 // printed the klass name so that other routines in the adjust_*
duke@0 275 // group don't print the klass name.
duke@0 276 void adjust_method_entries(methodOop* old_methods, methodOop* new_methods,
duke@0 277 int methods_length, bool * trace_name_printed);
duke@0 278
duke@0 279 // Garbage collection
duke@0 280 void oop_follow_contents();
duke@0 281 void oop_adjust_pointers();
duke@0 282
duke@0 283 #ifndef SERIALGC
duke@0 284 // Parallel Old
duke@0 285 void oop_follow_contents(ParCompactionManager* cm);
duke@0 286 void oop_update_pointers(ParCompactionManager* cm);
duke@0 287 void oop_update_pointers(ParCompactionManager* cm,
duke@0 288 HeapWord* beg_addr, HeapWord* end_addr);
duke@0 289 #endif // SERIALGC
duke@0 290
duke@0 291 // Iterators
duke@0 292 void oop_oop_iterate(OopClosure* blk);
duke@0 293 void oop_oop_iterate_m(OopClosure* blk, MemRegion mr);
duke@0 294
duke@0 295 // Setup of itable
duke@0 296 static int compute_itable_size(objArrayHandle transitive_interfaces);
duke@0 297 static void setup_itable_offset_table(instanceKlassHandle klass);
duke@0 298
duke@0 299 // Resolving of method to index
duke@0 300 static int compute_itable_index(methodOop m);
duke@0 301
duke@0 302 // Debugging/Statistics
duke@0 303 static void print_statistics() PRODUCT_RETURN;
duke@0 304 private:
duke@0 305 intptr_t* vtable_start() const { return ((intptr_t*)_klass()) + _table_offset; }
duke@0 306 intptr_t* method_start() const { return vtable_start() + _size_offset_table * itableOffsetEntry::size(); }
duke@0 307
duke@0 308 // Helper methods
duke@0 309 static int calc_itable_size(int num_interfaces, int num_methods) { return (num_interfaces * itableOffsetEntry::size()) + (num_methods * itableMethodEntry::size()); }
duke@0 310
duke@0 311 // Statistics
duke@0 312 NOT_PRODUCT(static int _total_classes;) // Total no. of classes with itables
duke@0 313 NOT_PRODUCT(static long _total_size;) // Total no. of bytes used for itables
duke@0 314
duke@0 315 static void update_stats(int size) PRODUCT_RETURN NOT_PRODUCT({ _total_classes++; _total_size += size; })
duke@0 316 };