src/share/vm/oops/klassVtable.hpp

Fri, 20 Mar 2009 23:19:36 -0700

author
jrose
date
Fri, 20 Mar 2009 23:19:36 -0700
changeset 1100
c89f86385056
parent 451
f8236e79048a
child 1111
d3676b4cb78c
permissions
-rw-r--r--

6814659: separable cleanups and subroutines for 6655638
Summary: preparatory but separable changes for method handles
Reviewed-by: kvn, never

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

mercurial