comparison src/share/vm/oops/klassVtable.cpp @ 6948:e522a00b91aa

Merge with http://hg.openjdk.java.net/hsx/hsx25/hotspot/ after NPG - C++ build works
author Doug Simon <doug.simon@oracle.com>
date Mon, 12 Nov 2012 23:14:12 +0100
parents 18fb7da42534
children 070d523b96a7
comparison
equal deleted inserted replaced
6711:ae13cc658b80 6948:e522a00b91aa
1 /* 1 /*
2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
28 #include "gc_implementation/shared/markSweep.inline.hpp" 28 #include "gc_implementation/shared/markSweep.inline.hpp"
29 #include "memory/gcLocker.hpp" 29 #include "memory/gcLocker.hpp"
30 #include "memory/resourceArea.hpp" 30 #include "memory/resourceArea.hpp"
31 #include "memory/universe.inline.hpp" 31 #include "memory/universe.inline.hpp"
32 #include "oops/instanceKlass.hpp" 32 #include "oops/instanceKlass.hpp"
33 #include "oops/klassOop.hpp"
34 #include "oops/klassVtable.hpp" 33 #include "oops/klassVtable.hpp"
35 #include "oops/methodOop.hpp" 34 #include "oops/method.hpp"
36 #include "oops/objArrayOop.hpp" 35 #include "oops/objArrayOop.hpp"
37 #include "oops/oop.inline.hpp" 36 #include "oops/oop.inline.hpp"
38 #include "prims/jvmtiRedefineClassesTrace.hpp" 37 #include "prims/jvmtiRedefineClassesTrace.hpp"
39 #include "runtime/arguments.hpp" 38 #include "runtime/arguments.hpp"
40 #include "runtime/handles.inline.hpp" 39 #include "runtime/handles.inline.hpp"
41 #include "utilities/copy.hpp" 40 #include "utilities/copy.hpp"
42 41
43 inline instanceKlass* klassVtable::ik() const { 42 inline InstanceKlass* klassVtable::ik() const {
44 Klass* k = _klass()->klass_part(); 43 Klass* k = _klass();
45 assert(k->oop_is_instance(), "not an instanceKlass"); 44 assert(k->oop_is_instance(), "not an InstanceKlass");
46 return (instanceKlass*)k; 45 return (InstanceKlass*)k;
47 } 46 }
48 47
49 48
50 // this function computes the vtable size (including the size needed for miranda 49 // this function computes the vtable size (including the size needed for miranda
51 // methods) and the number of miranda methods in this class 50 // methods) and the number of miranda methods in this class
53 // interface I. Let's say there is a method m in I that neither C nor any 52 // interface I. Let's say there is a method m in I that neither C nor any
54 // of its super classes implement (i.e there is no method of any access, with 53 // of its super classes implement (i.e there is no method of any access, with
55 // the same name and signature as m), then m is a Miranda method which is 54 // the same name and signature as m), then m is a Miranda method which is
56 // entered as a public abstract method in C's vtable. From then on it should 55 // entered as a public abstract method in C's vtable. From then on it should
57 // treated as any other public method in C for method over-ride purposes. 56 // treated as any other public method in C for method over-ride purposes.
58 void klassVtable::compute_vtable_size_and_num_mirandas(int &vtable_length, 57 void klassVtable::compute_vtable_size_and_num_mirandas(
59 int &num_miranda_methods, 58 int* vtable_length_ret, int* num_new_mirandas,
60 klassOop super, 59 GrowableArray<Method*>* all_mirandas, Klass* super,
61 objArrayOop methods, 60 Array<Method*>* methods, AccessFlags class_flags,
62 AccessFlags class_flags, 61 Handle classloader, Symbol* classname, Array<Klass*>* local_interfaces,
63 Handle classloader, 62 TRAPS) {
64 Symbol* classname,
65 objArrayOop local_interfaces,
66 TRAPS
67 ) {
68
69 No_Safepoint_Verifier nsv; 63 No_Safepoint_Verifier nsv;
70 64
71 // set up default result values 65 // set up default result values
72 vtable_length = 0; 66 int vtable_length = 0;
73 num_miranda_methods = 0;
74 67
75 // start off with super's vtable length 68 // start off with super's vtable length
76 instanceKlass* sk = (instanceKlass*)super->klass_part(); 69 InstanceKlass* sk = (InstanceKlass*)super;
77 vtable_length = super == NULL ? 0 : sk->vtable_length(); 70 vtable_length = super == NULL ? 0 : sk->vtable_length();
78 71
79 // go thru each method in the methods table to see if it needs a new entry 72 // go thru each method in the methods table to see if it needs a new entry
80 int len = methods->length(); 73 int len = methods->length();
81 for (int i = 0; i < len; i++) { 74 for (int i = 0; i < len; i++) {
82 assert(methods->obj_at(i)->is_method(), "must be a methodOop"); 75 assert(methods->at(i)->is_method(), "must be a Method*");
83 methodHandle mh(THREAD, methodOop(methods->obj_at(i))); 76 methodHandle mh(THREAD, methods->at(i));
84 77
85 if (needs_new_vtable_entry(mh, super, classloader, classname, class_flags, THREAD)) { 78 if (needs_new_vtable_entry(mh, super, classloader, classname, class_flags, THREAD)) {
86 vtable_length += vtableEntry::size(); // we need a new entry 79 vtable_length += vtableEntry::size(); // we need a new entry
87 } 80 }
88 } 81 }
89 82
83 GrowableArray<Method*> new_mirandas(20);
90 // compute the number of mirandas methods that must be added to the end 84 // compute the number of mirandas methods that must be added to the end
91 num_miranda_methods = get_num_mirandas(super, methods, local_interfaces); 85 get_mirandas(&new_mirandas, all_mirandas, super, methods, local_interfaces);
92 vtable_length += (num_miranda_methods * vtableEntry::size()); 86 *num_new_mirandas = new_mirandas.length();
87
88 vtable_length += *num_new_mirandas * vtableEntry::size();
93 89
94 if (Universe::is_bootstrapping() && vtable_length == 0) { 90 if (Universe::is_bootstrapping() && vtable_length == 0) {
95 // array classes don't have their superclass set correctly during 91 // array classes don't have their superclass set correctly during
96 // bootstrapping 92 // bootstrapping
97 vtable_length = Universe::base_vtable_size(); 93 vtable_length = Universe::base_vtable_size();
108 } 104 }
109 assert(super != NULL || vtable_length == Universe::base_vtable_size(), 105 assert(super != NULL || vtable_length == Universe::base_vtable_size(),
110 "bad vtable size for class Object"); 106 "bad vtable size for class Object");
111 assert(vtable_length % vtableEntry::size() == 0, "bad vtable length"); 107 assert(vtable_length % vtableEntry::size() == 0, "bad vtable length");
112 assert(vtable_length >= Universe::base_vtable_size(), "vtable too small"); 108 assert(vtable_length >= Universe::base_vtable_size(), "vtable too small");
113 } 109
114 110 *vtable_length_ret = vtable_length;
115 int klassVtable::index_of(methodOop m, int len) const { 111 }
112
113 int klassVtable::index_of(Method* m, int len) const {
116 assert(m->vtable_index() >= 0, "do not ask this of non-vtable methods"); 114 assert(m->vtable_index() >= 0, "do not ask this of non-vtable methods");
117 return m->vtable_index(); 115 return m->vtable_index();
118 } 116 }
119 117
120 int klassVtable::initialize_from_super(KlassHandle super) { 118 int klassVtable::initialize_from_super(KlassHandle super) {
121 if (super.is_null()) { 119 if (super.is_null()) {
122 return 0; 120 return 0;
123 } else { 121 } else {
124 // copy methods from superKlass 122 // copy methods from superKlass
125 // can't inherit from array class, so must be instanceKlass 123 // can't inherit from array class, so must be InstanceKlass
126 assert(super->oop_is_instance(), "must be instance klass"); 124 assert(super->oop_is_instance(), "must be instance klass");
127 instanceKlass* sk = (instanceKlass*)super()->klass_part(); 125 InstanceKlass* sk = (InstanceKlass*)super();
128 klassVtable* superVtable = sk->vtable(); 126 klassVtable* superVtable = sk->vtable();
129 assert(superVtable->length() <= _length, "vtable too short"); 127 assert(superVtable->length() <= _length, "vtable too short");
130 #ifdef ASSERT 128 #ifdef ASSERT
131 superVtable->verify(tty, true); 129 superVtable->verify(tty, true);
132 #endif 130 #endif
168 166
169 int super_vtable_len = initialize_from_super(super); 167 int super_vtable_len = initialize_from_super(super);
170 if (klass()->oop_is_array()) { 168 if (klass()->oop_is_array()) {
171 assert(super_vtable_len == _length, "arrays shouldn't introduce new methods"); 169 assert(super_vtable_len == _length, "arrays shouldn't introduce new methods");
172 } else { 170 } else {
173 assert(_klass->oop_is_instance(), "must be instanceKlass"); 171 assert(_klass->oop_is_instance(), "must be InstanceKlass");
174 172
175 objArrayHandle methods(THREAD, ik()->methods()); 173 Array<Method*>* methods = ik()->methods();
176 int len = methods()->length(); 174 int len = methods->length();
177 int initialized = super_vtable_len; 175 int initialized = super_vtable_len;
178 176
179 // update_inherited_vtable can stop for gc - ensure using handles 177 // update_inherited_vtable can stop for gc - ensure using handles
180 for (int i = 0; i < len; i++) { 178 for (int i = 0; i < len; i++) {
181 HandleMark hm(THREAD); 179 HandleMark hm(THREAD);
182 assert(methods()->obj_at(i)->is_method(), "must be a methodOop"); 180 assert(methods->at(i)->is_method(), "must be a Method*");
183 methodHandle mh(THREAD, (methodOop)methods()->obj_at(i)); 181 methodHandle mh(THREAD, methods->at(i));
184 182
185 bool needs_new_entry = update_inherited_vtable(ik(), mh, super_vtable_len, checkconstraints, CHECK); 183 bool needs_new_entry = update_inherited_vtable(ik(), mh, super_vtable_len, checkconstraints, CHECK);
186 184
187 if (needs_new_entry) { 185 if (needs_new_entry) {
188 put_method_at(mh(), initialized); 186 put_method_at(mh(), initialized);
190 initialized++; 188 initialized++;
191 } 189 }
192 } 190 }
193 191
194 // add miranda methods; it will also update the value of initialized 192 // add miranda methods; it will also update the value of initialized
195 fill_in_mirandas(initialized); 193 fill_in_mirandas(&initialized);
196 194
197 // In class hierarchies where the accessibility is not increasing (i.e., going from private -> 195 // In class hierarchies where the accessibility is not increasing (i.e., going from private ->
198 // package_private -> publicprotected), the vtable might actually be smaller than our initial 196 // package_private -> publicprotected), the vtable might actually be smaller than our initial
199 // calculation. 197 // calculation.
200 assert(initialized <= _length, "vtable initialization failed"); 198 assert(initialized <= _length, "vtable initialization failed");
207 205
208 // Called for cases where a method does not override its superclass' vtable entry 206 // Called for cases where a method does not override its superclass' vtable entry
209 // For bytecodes not produced by javac together it is possible that a method does not override 207 // For bytecodes not produced by javac together it is possible that a method does not override
210 // the superclass's method, but might indirectly override a super-super class's vtable entry 208 // the superclass's method, but might indirectly override a super-super class's vtable entry
211 // If none found, return a null superk, else return the superk of the method this does override 209 // If none found, return a null superk, else return the superk of the method this does override
212 instanceKlass* klassVtable::find_transitive_override(instanceKlass* initialsuper, methodHandle target_method, 210 InstanceKlass* klassVtable::find_transitive_override(InstanceKlass* initialsuper, methodHandle target_method,
213 int vtable_index, Handle target_loader, Symbol* target_classname, Thread * THREAD) { 211 int vtable_index, Handle target_loader, Symbol* target_classname, Thread * THREAD) {
214 instanceKlass* superk = initialsuper; 212 InstanceKlass* superk = initialsuper;
215 while (superk != NULL && superk->super() != NULL) { 213 while (superk != NULL && superk->super() != NULL) {
216 instanceKlass* supersuperklass = instanceKlass::cast(superk->super()); 214 InstanceKlass* supersuperklass = InstanceKlass::cast(superk->super());
217 klassVtable* ssVtable = supersuperklass->vtable(); 215 klassVtable* ssVtable = supersuperklass->vtable();
218 if (vtable_index < ssVtable->length()) { 216 if (vtable_index < ssVtable->length()) {
219 methodOop super_method = ssVtable->method_at(vtable_index); 217 Method* super_method = ssVtable->method_at(vtable_index);
220 #ifndef PRODUCT 218 #ifndef PRODUCT
221 Symbol* name= target_method()->name(); 219 Symbol* name= target_method()->name();
222 Symbol* signature = target_method()->signature(); 220 Symbol* signature = target_method()->signature();
223 assert(super_method->name() == name && super_method->signature() == signature, "vtable entry name/sig mismatch"); 221 assert(super_method->name() == name && super_method->signature() == signature, "vtable entry name/sig mismatch");
224 #endif 222 #endif
238 #endif /*PRODUCT*/ 236 #endif /*PRODUCT*/
239 break; // return found superk 237 break; // return found superk
240 } 238 }
241 } else { 239 } else {
242 // super class has no vtable entry here, stop transitive search 240 // super class has no vtable entry here, stop transitive search
243 superk = (instanceKlass*)NULL; 241 superk = (InstanceKlass*)NULL;
244 break; 242 break;
245 } 243 }
246 // if no override found yet, continue to search up 244 // if no override found yet, continue to search up
247 superk = instanceKlass::cast(superk->super()); 245 superk = InstanceKlass::cast(superk->super());
248 } 246 }
249 247
250 return superk; 248 return superk;
251 } 249 }
252 250
251 // Methods that are "effectively" final don't need vtable entries.
252 bool method_is_effectively_final(
253 AccessFlags klass_flags, methodHandle target) {
254 return target->is_final() || klass_flags.is_final() && !target->is_overpass();
255 }
253 256
254 // Update child's copy of super vtable for overrides 257 // Update child's copy of super vtable for overrides
255 // OR return true if a new vtable entry is required 258 // OR return true if a new vtable entry is required
256 // Only called for instanceKlass's, i.e. not for arrays 259 // Only called for InstanceKlass's, i.e. not for arrays
257 // If that changed, could not use _klass as handle for klass 260 // If that changed, could not use _klass as handle for klass
258 bool klassVtable::update_inherited_vtable(instanceKlass* klass, methodHandle target_method, int super_vtable_len, 261 bool klassVtable::update_inherited_vtable(InstanceKlass* klass, methodHandle target_method, int super_vtable_len,
259 bool checkconstraints, TRAPS) { 262 bool checkconstraints, TRAPS) {
260 ResourceMark rm; 263 ResourceMark rm;
261 bool allocate_new = true; 264 bool allocate_new = true;
262 assert(klass->oop_is_instance(), "must be instanceKlass"); 265 assert(klass->oop_is_instance(), "must be InstanceKlass");
263 266
264 // Initialize the method's vtable index to "nonvirtual". 267 // Initialize the method's vtable index to "nonvirtual".
265 // If we allocate a vtable entry, we will update it to a non-negative number. 268 // If we allocate a vtable entry, we will update it to a non-negative number.
266 target_method()->set_vtable_index(methodOopDesc::nonvirtual_vtable_index); 269 target_method()->set_vtable_index(Method::nonvirtual_vtable_index);
267 270
268 // Static and <init> methods are never in 271 // Static and <init> methods are never in
269 if (target_method()->is_static() || target_method()->name() == vmSymbols::object_initializer_name()) { 272 if (target_method()->is_static() || target_method()->name() == vmSymbols::object_initializer_name()) {
270 return false; 273 return false;
271 } 274 }
272 275
273 if (klass->is_final() || target_method()->is_final()) { 276 if (method_is_effectively_final(klass->access_flags(), target_method)) {
274 // a final method never needs a new entry; final methods can be statically 277 // a final method never needs a new entry; final methods can be statically
275 // resolved and they have to be present in the vtable only if they override 278 // resolved and they have to be present in the vtable only if they override
276 // a super's method, in which case they re-use its entry 279 // a super's method, in which case they re-use its entry
277 allocate_new = false; 280 allocate_new = false;
278 } 281 }
294 // which can block for gc, once we are in this loop, use handles 297 // which can block for gc, once we are in this loop, use handles
295 // For classfiles built with >= jdk7, we now look for transitive overrides 298 // For classfiles built with >= jdk7, we now look for transitive overrides
296 299
297 Symbol* name = target_method()->name(); 300 Symbol* name = target_method()->name();
298 Symbol* signature = target_method()->signature(); 301 Symbol* signature = target_method()->signature();
299 Handle target_loader(THREAD, _klass->class_loader()); 302 Handle target_loader(THREAD, _klass()->class_loader());
300 Symbol* target_classname = _klass->name(); 303 Symbol* target_classname = _klass->name();
301 for(int i = 0; i < super_vtable_len; i++) { 304 for(int i = 0; i < super_vtable_len; i++) {
302 methodOop super_method = method_at(i); 305 Method* super_method = method_at(i);
303 // Check if method name matches 306 // Check if method name matches
304 if (super_method->name() == name && super_method->signature() == signature) { 307 if (super_method->name() == name && super_method->signature() == signature) {
305 308
306 // get super_klass for method_holder for the found method 309 // get super_klass for method_holder for the found method
307 instanceKlass* super_klass = instanceKlass::cast(super_method->method_holder()); 310 InstanceKlass* super_klass = super_method->method_holder();
308 311
309 if ((super_klass->is_override(super_method, target_loader, target_classname, THREAD)) || 312 if ((super_klass->is_override(super_method, target_loader, target_classname, THREAD)) ||
310 ((klass->major_version() >= VTABLE_TRANSITIVE_OVERRIDE_VERSION) 313 ((klass->major_version() >= VTABLE_TRANSITIVE_OVERRIDE_VERSION)
311 && ((super_klass = find_transitive_override(super_klass, target_method, i, target_loader, 314 && ((super_klass = find_transitive_override(super_klass, target_method, i, target_loader,
312 target_classname, THREAD)) != (instanceKlass*)NULL))) { 315 target_classname, THREAD)) != (InstanceKlass*)NULL))) {
313 // overriding, so no new entry 316 // overriding, so no new entry
314 allocate_new = false; 317 allocate_new = false;
315 318
316 if (checkconstraints) { 319 if (checkconstraints) {
317 // Override vtable entry if passes loader constraint check 320 // Override vtable entry if passes loader constraint check
379 } 382 }
380 } 383 }
381 return allocate_new; 384 return allocate_new;
382 } 385 }
383 386
384 void klassVtable::put_method_at(methodOop m, int index) { 387 void klassVtable::put_method_at(Method* m, int index) {
385 assert(m->is_oop_or_null(), "Not an oop or null");
386 #ifndef PRODUCT 388 #ifndef PRODUCT
387 if (PrintVtables && Verbose) { 389 if (PrintVtables && Verbose) {
388 ResourceMark rm; 390 ResourceMark rm;
389 tty->print_cr("adding %s::%s at index %d", _klass->internal_name(), 391 tty->print_cr("adding %s::%s at index %d", _klass->internal_name(),
390 (m != NULL) ? m->name()->as_C_string() : "<NULL>", index); 392 (m != NULL) ? m->name()->as_C_string() : "<NULL>", index);
391 } 393 }
392 assert(unchecked_method_at(index)->is_oop_or_null(), "Not an oop or null");
393 #endif 394 #endif
394 table()[index].set(m); 395 table()[index].set(m);
395 } 396 }
396 397
397 // Find out if a method "m" with superclass "super", loader "classloader" and 398 // Find out if a method "m" with superclass "super", loader "classloader" and
398 // name "classname" needs a new vtable entry. Let P be a class package defined 399 // name "classname" needs a new vtable entry. Let P be a class package defined
399 // by "classloader" and "classname". 400 // by "classloader" and "classname".
400 // NOTE: The logic used here is very similar to the one used for computing 401 // NOTE: The logic used here is very similar to the one used for computing
401 // the vtables indices for a method. We cannot directly use that function because, 402 // the vtables indices for a method. We cannot directly use that function because,
402 // we allocate the instanceKlass at load time, and that requires that the 403 // we allocate the InstanceKlass at load time, and that requires that the
403 // superclass has been loaded. 404 // superclass has been loaded.
404 // However, the vtable entries are filled in at link time, and therefore 405 // However, the vtable entries are filled in at link time, and therefore
405 // the superclass' vtable may not yet have been filled in. 406 // the superclass' vtable may not yet have been filled in.
406 bool klassVtable::needs_new_vtable_entry(methodHandle target_method, 407 bool klassVtable::needs_new_vtable_entry(methodHandle target_method,
407 klassOop super, 408 Klass* super,
408 Handle classloader, 409 Handle classloader,
409 Symbol* classname, 410 Symbol* classname,
410 AccessFlags class_flags, 411 AccessFlags class_flags,
411 TRAPS) { 412 TRAPS) {
412 if ((class_flags.is_final() || target_method()->is_final()) || 413
414 if (method_is_effectively_final(class_flags, target_method) ||
413 // a final method never needs a new entry; final methods can be statically 415 // a final method never needs a new entry; final methods can be statically
414 // resolved and they have to be present in the vtable only if they override 416 // resolved and they have to be present in the vtable only if they override
415 // a super's method, in which case they re-use its entry 417 // a super's method, in which case they re-use its entry
416 (target_method()->is_static()) || 418 (target_method()->is_static()) ||
417 // static methods don't need to be in vtable 419 // static methods don't need to be in vtable
436 // search through the super class hierarchy to see if we need 438 // search through the super class hierarchy to see if we need
437 // a new entry 439 // a new entry
438 ResourceMark rm; 440 ResourceMark rm;
439 Symbol* name = target_method()->name(); 441 Symbol* name = target_method()->name();
440 Symbol* signature = target_method()->signature(); 442 Symbol* signature = target_method()->signature();
441 klassOop k = super; 443 Klass* k = super;
442 methodOop super_method = NULL; 444 Method* super_method = NULL;
443 instanceKlass *holder = NULL; 445 InstanceKlass *holder = NULL;
444 methodOop recheck_method = NULL; 446 Method* recheck_method = NULL;
445 while (k != NULL) { 447 while (k != NULL) {
446 // lookup through the hierarchy for a method with matching name and sign. 448 // lookup through the hierarchy for a method with matching name and sign.
447 super_method = instanceKlass::cast(k)->lookup_method(name, signature); 449 super_method = InstanceKlass::cast(k)->lookup_method(name, signature);
448 if (super_method == NULL) { 450 if (super_method == NULL) {
449 break; // we still have to search for a matching miranda method 451 break; // we still have to search for a matching miranda method
450 } 452 }
451 // get the class holding the matching method 453 // get the class holding the matching method
452 // make sure you use that class for is_override 454 // make sure you use that class for is_override
453 instanceKlass* superk = instanceKlass::cast(super_method->method_holder()); 455 InstanceKlass* superk = super_method->method_holder();
454 // we want only instance method matches 456 // we want only instance method matches
455 // pretend private methods are not in the super vtable 457 // pretend private methods are not in the super vtable
456 // since we do override around them: e.g. a.m pub/b.m private/c.m pub, 458 // since we do override around them: e.g. a.m pub/b.m private/c.m pub,
457 // ignore private, c.m pub does override a.m pub 459 // ignore private, c.m pub does override a.m pub
458 // For classes that were not javac'd together, we also do transitive overriding around 460 // For classes that were not javac'd together, we also do transitive overriding around
471 473
472 // if the target method is public or protected it may have a matching 474 // if the target method is public or protected it may have a matching
473 // miranda method in the super, whose entry it should re-use. 475 // miranda method in the super, whose entry it should re-use.
474 // Actually, to handle cases that javac would not generate, we need 476 // Actually, to handle cases that javac would not generate, we need
475 // this check for all access permissions. 477 // this check for all access permissions.
476 instanceKlass *sk = instanceKlass::cast(super); 478 InstanceKlass *sk = InstanceKlass::cast(super);
477 if (sk->has_miranda_methods()) { 479 if (sk->has_miranda_methods()) {
478 if (sk->lookup_method_in_all_interfaces(name, signature) != NULL) { 480 if (sk->lookup_method_in_all_interfaces(name, signature) != NULL) {
479 return false; // found a matching miranda; we do not need a new entry 481 return false; // found a matching miranda; we do not need a new entry
480 } 482 }
481 } 483 }
486 488
487 // get the vtable index of a miranda method with matching "name" and "signature" 489 // get the vtable index of a miranda method with matching "name" and "signature"
488 int klassVtable::index_of_miranda(Symbol* name, Symbol* signature) { 490 int klassVtable::index_of_miranda(Symbol* name, Symbol* signature) {
489 // search from the bottom, might be faster 491 // search from the bottom, might be faster
490 for (int i = (length() - 1); i >= 0; i--) { 492 for (int i = (length() - 1); i >= 0; i--) {
491 methodOop m = table()[i].method(); 493 Method* m = table()[i].method();
492 if (is_miranda_entry_at(i) && 494 if (is_miranda_entry_at(i) &&
493 m->name() == name && m->signature() == signature) { 495 m->name() == name && m->signature() == signature) {
494 return i; 496 return i;
495 } 497 }
496 } 498 }
497 return methodOopDesc::invalid_vtable_index; 499 return Method::invalid_vtable_index;
498 } 500 }
499 501
500 // check if an entry is miranda 502 // check if an entry is miranda
501 bool klassVtable::is_miranda_entry_at(int i) { 503 bool klassVtable::is_miranda_entry_at(int i) {
502 methodOop m = method_at(i); 504 Method* m = method_at(i);
503 klassOop method_holder = m->method_holder(); 505 Klass* method_holder = m->method_holder();
504 instanceKlass *mhk = instanceKlass::cast(method_holder); 506 InstanceKlass *mhk = InstanceKlass::cast(method_holder);
505 507
506 // miranda methods are interface methods in a class's vtable 508 // miranda methods are interface methods in a class's vtable
507 if (mhk->is_interface()) { 509 if (mhk->is_interface()) {
508 assert(m->is_public() && m->is_abstract(), "should be public and abstract"); 510 assert(m->is_public(), "should be public");
509 assert(ik()->implements_interface(method_holder) , "this class should implement the interface"); 511 assert(ik()->implements_interface(method_holder) , "this class should implement the interface");
510 assert(is_miranda(m, ik()->methods(), ik()->super()), "should be a miranda_method"); 512 assert(is_miranda(m, ik()->methods(), ik()->super()), "should be a miranda_method");
511 return true; 513 return true;
512 } 514 }
513 return false; 515 return false;
514 } 516 }
515 517
516 // check if a method is a miranda method, given a class's methods table and it's super 518 // check if a method is a miranda method, given a class's methods table and it's super
517 // the caller must make sure that the method belongs to an interface implemented by the class 519 // the caller must make sure that the method belongs to an interface implemented by the class
518 bool klassVtable::is_miranda(methodOop m, objArrayOop class_methods, klassOop super) { 520 bool klassVtable::is_miranda(Method* m, Array<Method*>* class_methods, Klass* super) {
519 Symbol* name = m->name(); 521 Symbol* name = m->name();
520 Symbol* signature = m->signature(); 522 Symbol* signature = m->signature();
521 if (instanceKlass::find_method(class_methods, name, signature) == NULL) { 523 if (InstanceKlass::find_method(class_methods, name, signature) == NULL) {
522 // did not find it in the method table of the current class 524 // did not find it in the method table of the current class
523 if (super == NULL) { 525 if (super == NULL) {
524 // super doesn't exist 526 // super doesn't exist
525 return true; 527 return true;
526 } 528 }
527 529
528 methodOop mo = instanceKlass::cast(super)->lookup_method(name, signature); 530 Method* mo = InstanceKlass::cast(super)->lookup_method(name, signature);
529 if (mo == NULL || mo->access_flags().is_private() ) { 531 if (mo == NULL || mo->access_flags().is_private() ) {
530 // super class hierarchy does not implement it or protection is different 532 // super class hierarchy does not implement it or protection is different
531 return true; 533 return true;
532 } 534 }
533 } 535 }
534 536
535 return false; 537 return false;
536 } 538 }
537 539
538 void klassVtable::add_new_mirandas_to_list(GrowableArray<methodOop>* list_of_current_mirandas, 540 void klassVtable::add_new_mirandas_to_lists(
539 objArrayOop current_interface_methods, 541 GrowableArray<Method*>* new_mirandas, GrowableArray<Method*>* all_mirandas,
540 objArrayOop class_methods, 542 Array<Method*>* current_interface_methods, Array<Method*>* class_methods,
541 klassOop super) { 543 Klass* super) {
542 // iterate thru the current interface's method to see if it a miranda 544 // iterate thru the current interface's method to see if it a miranda
543 int num_methods = current_interface_methods->length(); 545 int num_methods = current_interface_methods->length();
544 for (int i = 0; i < num_methods; i++) { 546 for (int i = 0; i < num_methods; i++) {
545 methodOop im = methodOop(current_interface_methods->obj_at(i)); 547 Method* im = current_interface_methods->at(i);
546 bool is_duplicate = false; 548 bool is_duplicate = false;
547 int num_of_current_mirandas = list_of_current_mirandas->length(); 549 int num_of_current_mirandas = new_mirandas->length();
548 // check for duplicate mirandas in different interfaces we implement 550 // check for duplicate mirandas in different interfaces we implement
549 for (int j = 0; j < num_of_current_mirandas; j++) { 551 for (int j = 0; j < num_of_current_mirandas; j++) {
550 methodOop miranda = list_of_current_mirandas->at(j); 552 Method* miranda = new_mirandas->at(j);
551 if ((im->name() == miranda->name()) && 553 if ((im->name() == miranda->name()) &&
552 (im->signature() == miranda->signature())) { 554 (im->signature() == miranda->signature())) {
553 is_duplicate = true; 555 is_duplicate = true;
554 break; 556 break;
555 } 557 }
556 } 558 }
557 559
558 if (!is_duplicate) { // we don't want duplicate miranda entries in the vtable 560 if (!is_duplicate) { // we don't want duplicate miranda entries in the vtable
559 if (is_miranda(im, class_methods, super)) { // is it a miranda at all? 561 if (is_miranda(im, class_methods, super)) { // is it a miranda at all?
560 instanceKlass *sk = instanceKlass::cast(super); 562 InstanceKlass *sk = InstanceKlass::cast(super);
561 // check if it is a duplicate of a super's miranda 563 // check if it is a duplicate of a super's miranda
562 if (sk->lookup_method_in_all_interfaces(im->name(), im->signature()) == NULL) { 564 if (sk->lookup_method_in_all_interfaces(im->name(), im->signature()) == NULL) {
563 list_of_current_mirandas->append(im); 565 new_mirandas->append(im);
566 }
567 if (all_mirandas != NULL) {
568 all_mirandas->append(im);
564 } 569 }
565 } 570 }
566 } 571 }
567 } 572 }
568 } 573 }
569 574
570 void klassVtable::get_mirandas(GrowableArray<methodOop>* mirandas, 575 void klassVtable::get_mirandas(GrowableArray<Method*>* new_mirandas,
571 klassOop super, objArrayOop class_methods, 576 GrowableArray<Method*>* all_mirandas,
572 objArrayOop local_interfaces) { 577 Klass* super, Array<Method*>* class_methods,
573 assert((mirandas->length() == 0) , "current mirandas must be 0"); 578 Array<Klass*>* local_interfaces) {
579 assert((new_mirandas->length() == 0) , "current mirandas must be 0");
574 580
575 // iterate thru the local interfaces looking for a miranda 581 // iterate thru the local interfaces looking for a miranda
576 int num_local_ifs = local_interfaces->length(); 582 int num_local_ifs = local_interfaces->length();
577 for (int i = 0; i < num_local_ifs; i++) { 583 for (int i = 0; i < num_local_ifs; i++) {
578 instanceKlass *ik = instanceKlass::cast(klassOop(local_interfaces->obj_at(i))); 584 InstanceKlass *ik = InstanceKlass::cast(local_interfaces->at(i));
579 add_new_mirandas_to_list(mirandas, ik->methods(), class_methods, super); 585 add_new_mirandas_to_lists(new_mirandas, all_mirandas,
586 ik->methods(), class_methods, super);
580 // iterate thru each local's super interfaces 587 // iterate thru each local's super interfaces
581 objArrayOop super_ifs = ik->transitive_interfaces(); 588 Array<Klass*>* super_ifs = ik->transitive_interfaces();
582 int num_super_ifs = super_ifs->length(); 589 int num_super_ifs = super_ifs->length();
583 for (int j = 0; j < num_super_ifs; j++) { 590 for (int j = 0; j < num_super_ifs; j++) {
584 instanceKlass *sik = instanceKlass::cast(klassOop(super_ifs->obj_at(j))); 591 InstanceKlass *sik = InstanceKlass::cast(super_ifs->at(j));
585 add_new_mirandas_to_list(mirandas, sik->methods(), class_methods, super); 592 add_new_mirandas_to_lists(new_mirandas, all_mirandas,
586 } 593 sik->methods(), class_methods, super);
587 } 594 }
588 } 595 }
589
590 // get number of mirandas
591 int klassVtable::get_num_mirandas(klassOop super, objArrayOop class_methods, objArrayOop local_interfaces) {
592 ResourceMark rm;
593 GrowableArray<methodOop>* mirandas = new GrowableArray<methodOop>(20);
594 get_mirandas(mirandas, super, class_methods, local_interfaces);
595 return mirandas->length();
596 } 596 }
597 597
598 // fill in mirandas 598 // fill in mirandas
599 void klassVtable::fill_in_mirandas(int& initialized) { 599 void klassVtable::fill_in_mirandas(int* initialized) {
600 ResourceMark rm; 600 GrowableArray<Method*> mirandas(20);
601 GrowableArray<methodOop>* mirandas = new GrowableArray<methodOop>(20); 601 get_mirandas(&mirandas, NULL, ik()->super(), ik()->methods(),
602 instanceKlass *this_ik = ik(); 602 ik()->local_interfaces());
603 get_mirandas(mirandas, this_ik->super(), this_ik->methods(), this_ik->local_interfaces()); 603 for (int i = 0; i < mirandas.length(); i++) {
604 int num_mirandas = mirandas->length(); 604 put_method_at(mirandas.at(i), *initialized);
605 for (int i = 0; i < num_mirandas; i++) { 605 ++(*initialized);
606 put_method_at(mirandas->at(i), initialized);
607 initialized++;
608 } 606 }
609 } 607 }
610 608
611 void klassVtable::copy_vtable_to(vtableEntry* start) { 609 void klassVtable::copy_vtable_to(vtableEntry* start) {
612 Copy::disjoint_words((HeapWord*)table(), (HeapWord*)start, _length * vtableEntry::size()); 610 Copy::disjoint_words((HeapWord*)table(), (HeapWord*)start, _length * vtableEntry::size());
613 } 611 }
614 612
615 void klassVtable::adjust_method_entries(methodOop* old_methods, methodOop* new_methods, 613 void klassVtable::adjust_method_entries(Method** old_methods, Method** new_methods,
616 int methods_length, bool * trace_name_printed) { 614 int methods_length, bool * trace_name_printed) {
617 // search the vtable for uses of either obsolete or EMCP methods 615 // search the vtable for uses of either obsolete or EMCP methods
618 for (int j = 0; j < methods_length; j++) { 616 for (int j = 0; j < methods_length; j++) {
619 methodOop old_method = old_methods[j]; 617 Method* old_method = old_methods[j];
620 methodOop new_method = new_methods[j]; 618 Method* new_method = new_methods[j];
621 619
622 // In the vast majority of cases we could get the vtable index 620 // In the vast majority of cases we could get the vtable index
623 // by using: old_method->vtable_index() 621 // by using: old_method->vtable_index()
624 // However, there are rare cases, eg. sun.awt.X11.XDecoratedPeer.getX() 622 // However, there are rare cases, eg. sun.awt.X11.XDecoratedPeer.getX()
625 // in sun.awt.X11.XFramePeer where methods occur more than once in the 623 // in sun.awt.X11.XFramePeer where methods occur more than once in the
630 628
631 if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) { 629 if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
632 if (!(*trace_name_printed)) { 630 if (!(*trace_name_printed)) {
633 // RC_TRACE_MESG macro has an embedded ResourceMark 631 // RC_TRACE_MESG macro has an embedded ResourceMark
634 RC_TRACE_MESG(("adjust: name=%s", 632 RC_TRACE_MESG(("adjust: name=%s",
635 Klass::cast(old_method->method_holder())->external_name())); 633 old_method->method_holder()->external_name()));
636 *trace_name_printed = true; 634 *trace_name_printed = true;
637 } 635 }
638 // RC_TRACE macro has an embedded ResourceMark 636 // RC_TRACE macro has an embedded ResourceMark
639 RC_TRACE(0x00100000, ("vtable method update: %s(%s)", 637 RC_TRACE(0x00100000, ("vtable method update: %s(%s)",
640 new_method->name()->as_C_string(), 638 new_method->name()->as_C_string(),
652 650
653 bool klassVtable::is_initialized() { 651 bool klassVtable::is_initialized() {
654 return _length == 0 || table()[0].method() != NULL; 652 return _length == 0 || table()[0].method() != NULL;
655 } 653 }
656 654
657
658 // Garbage collection
659 void klassVtable::oop_follow_contents() {
660 int len = length();
661 for (int i = 0; i < len; i++) {
662 MarkSweep::mark_and_push(adr_method_at(i));
663 }
664 }
665
666 #ifndef SERIALGC
667 void klassVtable::oop_follow_contents(ParCompactionManager* cm) {
668 int len = length();
669 for (int i = 0; i < len; i++) {
670 PSParallelCompact::mark_and_push(cm, adr_method_at(i));
671 }
672 }
673 #endif // SERIALGC
674
675 void klassVtable::oop_adjust_pointers() {
676 int len = length();
677 for (int i = 0; i < len; i++) {
678 MarkSweep::adjust_pointer(adr_method_at(i));
679 }
680 }
681
682 #ifndef SERIALGC
683 void klassVtable::oop_update_pointers(ParCompactionManager* cm) {
684 const int n = length();
685 for (int i = 0; i < n; i++) {
686 PSParallelCompact::adjust_pointer(adr_method_at(i));
687 }
688 }
689 #endif // SERIALGC
690
691 // Iterators
692 void klassVtable::oop_oop_iterate(OopClosure* blk) {
693 int len = length();
694 for (int i = 0; i < len; i++) {
695 blk->do_oop(adr_method_at(i));
696 }
697 }
698
699 void klassVtable::oop_oop_iterate_m(OopClosure* blk, MemRegion mr) {
700 int len = length();
701 int i;
702 for (i = 0; i < len; i++) {
703 if ((HeapWord*)adr_method_at(i) >= mr.start()) break;
704 }
705 for (; i < len; i++) {
706 oop* adr = adr_method_at(i);
707 if ((HeapWord*)adr < mr.end()) blk->do_oop(adr);
708 }
709 }
710
711 //----------------------------------------------------------------------------------------- 655 //-----------------------------------------------------------------------------------------
712 // Itable code 656 // Itable code
713 657
714 // Initialize a itableMethodEntry 658 // Initialize a itableMethodEntry
715 void itableMethodEntry::initialize(methodOop m) { 659 void itableMethodEntry::initialize(Method* m) {
716 if (m == NULL) return; 660 if (m == NULL) return;
717 661
718 _method = m; 662 _method = m;
719 } 663 }
720 664
723 667
724 if (klass->itable_length() > 0) { 668 if (klass->itable_length() > 0) {
725 itableOffsetEntry* offset_entry = (itableOffsetEntry*)klass->start_of_itable(); 669 itableOffsetEntry* offset_entry = (itableOffsetEntry*)klass->start_of_itable();
726 if (offset_entry != NULL && offset_entry->interface_klass() != NULL) { // Check that itable is initialized 670 if (offset_entry != NULL && offset_entry->interface_klass() != NULL) { // Check that itable is initialized
727 // First offset entry points to the first method_entry 671 // First offset entry points to the first method_entry
728 intptr_t* method_entry = (intptr_t *)(((address)klass->as_klassOop()) + offset_entry->offset()); 672 intptr_t* method_entry = (intptr_t *)(((address)klass()) + offset_entry->offset());
729 intptr_t* end = klass->end_of_itable(); 673 intptr_t* end = klass->end_of_itable();
730 674
731 _table_offset = (intptr_t*)offset_entry - (intptr_t*)klass->as_klassOop(); 675 _table_offset = (intptr_t*)offset_entry - (intptr_t*)klass();
732 _size_offset_table = (method_entry - ((intptr_t*)offset_entry)) / itableOffsetEntry::size(); 676 _size_offset_table = (method_entry - ((intptr_t*)offset_entry)) / itableOffsetEntry::size();
733 _size_method_table = (end - method_entry) / itableMethodEntry::size(); 677 _size_method_table = (end - method_entry) / itableMethodEntry::size();
734 assert(_table_offset >= 0 && _size_offset_table >= 0 && _size_method_table >= 0, "wrong computation"); 678 assert(_table_offset >= 0 && _size_offset_table >= 0 && _size_method_table >= 0, "wrong computation");
735 return; 679 return;
736 } 680 }
739 // The length of the itable was either zero, or it has not yet been initialized. 683 // The length of the itable was either zero, or it has not yet been initialized.
740 _table_offset = 0; 684 _table_offset = 0;
741 _size_offset_table = 0; 685 _size_offset_table = 0;
742 _size_method_table = 0; 686 _size_method_table = 0;
743 } 687 }
744
745 // Garbage Collection
746
747 void klassItable::oop_follow_contents() {
748 // offset table
749 itableOffsetEntry* ioe = offset_entry(0);
750 for(int i = 0; i < _size_offset_table; i++) {
751 MarkSweep::mark_and_push((oop*)&ioe->_interface);
752 ioe++;
753 }
754
755 // method table
756 itableMethodEntry* ime = method_entry(0);
757 for(int j = 0; j < _size_method_table; j++) {
758 MarkSweep::mark_and_push((oop*)&ime->_method);
759 ime++;
760 }
761 }
762
763 #ifndef SERIALGC
764 void klassItable::oop_follow_contents(ParCompactionManager* cm) {
765 // offset table
766 itableOffsetEntry* ioe = offset_entry(0);
767 for(int i = 0; i < _size_offset_table; i++) {
768 PSParallelCompact::mark_and_push(cm, (oop*)&ioe->_interface);
769 ioe++;
770 }
771
772 // method table
773 itableMethodEntry* ime = method_entry(0);
774 for(int j = 0; j < _size_method_table; j++) {
775 PSParallelCompact::mark_and_push(cm, (oop*)&ime->_method);
776 ime++;
777 }
778 }
779 #endif // SERIALGC
780
781 void klassItable::oop_adjust_pointers() {
782 // offset table
783 itableOffsetEntry* ioe = offset_entry(0);
784 for(int i = 0; i < _size_offset_table; i++) {
785 MarkSweep::adjust_pointer((oop*)&ioe->_interface);
786 ioe++;
787 }
788
789 // method table
790 itableMethodEntry* ime = method_entry(0);
791 for(int j = 0; j < _size_method_table; j++) {
792 MarkSweep::adjust_pointer((oop*)&ime->_method);
793 ime++;
794 }
795 }
796
797 #ifndef SERIALGC
798 void klassItable::oop_update_pointers(ParCompactionManager* cm) {
799 // offset table
800 itableOffsetEntry* ioe = offset_entry(0);
801 for(int i = 0; i < _size_offset_table; i++) {
802 PSParallelCompact::adjust_pointer((oop*)&ioe->_interface);
803 ioe++;
804 }
805
806 // method table
807 itableMethodEntry* ime = method_entry(0);
808 for(int j = 0; j < _size_method_table; j++) {
809 PSParallelCompact::adjust_pointer((oop*)&ime->_method);
810 ime++;
811 }
812 }
813 #endif // SERIALGC
814
815 // Iterators
816 void klassItable::oop_oop_iterate(OopClosure* blk) {
817 // offset table
818 itableOffsetEntry* ioe = offset_entry(0);
819 for(int i = 0; i < _size_offset_table; i++) {
820 blk->do_oop((oop*)&ioe->_interface);
821 ioe++;
822 }
823
824 // method table
825 itableMethodEntry* ime = method_entry(0);
826 for(int j = 0; j < _size_method_table; j++) {
827 blk->do_oop((oop*)&ime->_method);
828 ime++;
829 }
830 }
831
832 void klassItable::oop_oop_iterate_m(OopClosure* blk, MemRegion mr) {
833 // offset table
834 itableOffsetEntry* ioe = offset_entry(0);
835 for(int i = 0; i < _size_offset_table; i++) {
836 oop* adr = (oop*)&ioe->_interface;
837 if (mr.contains(adr)) blk->do_oop(adr);
838 ioe++;
839 }
840
841 // method table
842 itableMethodEntry* ime = method_entry(0);
843 for(int j = 0; j < _size_method_table; j++) {
844 oop* adr = (oop*)&ime->_method;
845 if (mr.contains(adr)) blk->do_oop(adr);
846 ime++;
847 }
848 }
849
850 688
851 static int initialize_count = 0; 689 static int initialize_count = 0;
852 690
853 // Initialization 691 // Initialization
854 void klassItable::initialize_itable(bool checkconstraints, TRAPS) { 692 void klassItable::initialize_itable(bool checkconstraints, TRAPS) {
868 706
869 // Iterate through all interfaces 707 // Iterate through all interfaces
870 int i; 708 int i;
871 for(i = 0; i < num_interfaces; i++) { 709 for(i = 0; i < num_interfaces; i++) {
872 itableOffsetEntry* ioe = offset_entry(i); 710 itableOffsetEntry* ioe = offset_entry(i);
711 HandleMark hm(THREAD);
873 KlassHandle interf_h (THREAD, ioe->interface_klass()); 712 KlassHandle interf_h (THREAD, ioe->interface_klass());
874 assert(interf_h() != NULL && ioe->offset() != 0, "bad offset entry in itable"); 713 assert(interf_h() != NULL && ioe->offset() != 0, "bad offset entry in itable");
875 initialize_itable_for_interface(ioe->offset(), interf_h, checkconstraints, CHECK); 714 initialize_itable_for_interface(ioe->offset(), interf_h, checkconstraints, CHECK);
876 } 715 }
877 716
881 guarantee(ioe->interface_klass() == NULL && ioe->offset() == 0, "terminator entry missing"); 720 guarantee(ioe->interface_klass() == NULL && ioe->offset() == 0, "terminator entry missing");
882 } 721 }
883 722
884 723
885 void klassItable::initialize_itable_for_interface(int method_table_offset, KlassHandle interf_h, bool checkconstraints, TRAPS) { 724 void klassItable::initialize_itable_for_interface(int method_table_offset, KlassHandle interf_h, bool checkconstraints, TRAPS) {
886 objArrayHandle methods(THREAD, instanceKlass::cast(interf_h())->methods()); 725 Array<Method*>* methods = InstanceKlass::cast(interf_h())->methods();
887 int nof_methods = methods()->length(); 726 int nof_methods = methods->length();
888 HandleMark hm; 727 HandleMark hm;
889 KlassHandle klass = _klass; 728 KlassHandle klass = _klass;
890 assert(nof_methods > 0, "at least one method must exist for interface to be in vtable"); 729 assert(nof_methods > 0, "at least one method must exist for interface to be in vtable");
891 Handle interface_loader (THREAD, instanceKlass::cast(interf_h())->class_loader()); 730 Handle interface_loader (THREAD, InstanceKlass::cast(interf_h())->class_loader());
892 int ime_num = 0; 731 int ime_num = 0;
893 732
894 // Skip first methodOop if it is a class initializer 733 // Skip first Method* if it is a class initializer
895 int i = ((methodOop)methods()->obj_at(0))->is_static_initializer() ? 1 : 0; 734 int i = methods->at(0)->is_static_initializer() ? 1 : 0;
896 735
897 // m, method_name, method_signature, klass reset each loop so they 736 // m, method_name, method_signature, klass reset each loop so they
898 // don't need preserving across check_signature_loaders call 737 // don't need preserving across check_signature_loaders call
899 // methods needs a handle in case of gc from check_signature_loaders 738 // methods needs a handle in case of gc from check_signature_loaders
900 for(; i < nof_methods; i++) { 739 for(; i < nof_methods; i++) {
901 methodOop m = (methodOop)methods()->obj_at(i); 740 Method* m = methods->at(i);
902 Symbol* method_name = m->name(); 741 Symbol* method_name = m->name();
903 Symbol* method_signature = m->signature(); 742 Symbol* method_signature = m->signature();
904 743
905 // This is same code as in Linkresolver::lookup_instance_method_in_klasses 744 // This is same code as in Linkresolver::lookup_instance_method_in_klasses
906 methodOop target = klass->uncached_lookup_method(method_name, method_signature); 745 Method* target = klass->uncached_lookup_method(method_name, method_signature);
907 while (target != NULL && target->is_static()) { 746 while (target != NULL && target->is_static()) {
908 // continue with recursive lookup through the superclass 747 // continue with recursive lookup through the superclass
909 klassOop super = Klass::cast(target->method_holder())->super(); 748 Klass* super = target->method_holder()->super();
910 target = (super == NULL) ? methodOop(NULL) : Klass::cast(super)->uncached_lookup_method(method_name, method_signature); 749 target = (super == NULL) ? (Method*)NULL : Klass::cast(super)->uncached_lookup_method(method_name, method_signature);
911 } 750 }
912 if (target == NULL || !target->is_public() || target->is_abstract()) { 751 if (target == NULL || !target->is_public() || target->is_abstract()) {
913 // Entry do not resolve. Leave it empty 752 // Entry do not resolve. Leave it empty
914 } else { 753 } else {
915 // Entry did resolve, check loader constraints before initializing 754 // Entry did resolve, check loader constraints before initializing
916 // if checkconstraints requested 755 // if checkconstraints requested
917 methodHandle target_h (THREAD, target); // preserve across gc 756 methodHandle target_h (THREAD, target); // preserve across gc
918 if (checkconstraints) { 757 if (checkconstraints) {
919 Handle method_holder_loader (THREAD, instanceKlass::cast(target->method_holder())->class_loader()); 758 Handle method_holder_loader (THREAD, target->method_holder()->class_loader());
920 if (method_holder_loader() != interface_loader()) { 759 if (method_holder_loader() != interface_loader()) {
921 ResourceMark rm(THREAD); 760 ResourceMark rm(THREAD);
922 char* failed_type_name = 761 char* failed_type_name =
923 SystemDictionary::check_signature_loaders(method_signature, 762 SystemDictionary::check_signature_loaders(method_signature,
924 method_holder_loader, 763 method_holder_loader,
933 "used in the signature"; 772 "used in the signature";
934 char* sig = target_h()->name_and_sig_as_C_string(); 773 char* sig = target_h()->name_and_sig_as_C_string();
935 const char* loader1 = SystemDictionary::loader_name(method_holder_loader()); 774 const char* loader1 = SystemDictionary::loader_name(method_holder_loader());
936 char* current = klass->name()->as_C_string(); 775 char* current = klass->name()->as_C_string();
937 const char* loader2 = SystemDictionary::loader_name(interface_loader()); 776 const char* loader2 = SystemDictionary::loader_name(interface_loader());
938 char* iface = instanceKlass::cast(interf_h())->name()->as_C_string(); 777 char* iface = InstanceKlass::cast(interf_h())->name()->as_C_string();
939 size_t buflen = strlen(msg) + strlen(sig) + strlen(loader1) + 778 size_t buflen = strlen(msg) + strlen(sig) + strlen(loader1) +
940 strlen(current) + strlen(loader2) + strlen(iface) + 779 strlen(current) + strlen(loader2) + strlen(iface) +
941 strlen(failed_type_name); 780 strlen(failed_type_name);
942 char* buf = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, buflen); 781 char* buf = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, buflen);
943 jio_snprintf(buf, buflen, msg, sig, loader1, current, loader2, 782 jio_snprintf(buf, buflen, msg, sig, loader1, current, loader2,
953 // Progress to next entry 792 // Progress to next entry
954 ime_num++; 793 ime_num++;
955 } 794 }
956 } 795 }
957 796
958 // Update entry for specific methodOop 797 // Update entry for specific Method*
959 void klassItable::initialize_with_method(methodOop m) { 798 void klassItable::initialize_with_method(Method* m) {
960 itableMethodEntry* ime = method_entry(0); 799 itableMethodEntry* ime = method_entry(0);
961 for(int i = 0; i < _size_method_table; i++) { 800 for(int i = 0; i < _size_method_table; i++) {
962 if (ime->method() == m) { 801 if (ime->method() == m) {
963 ime->initialize(m); 802 ime->initialize(m);
964 } 803 }
965 ime++; 804 ime++;
966 } 805 }
967 } 806 }
968 807
969 void klassItable::adjust_method_entries(methodOop* old_methods, methodOop* new_methods, 808 void klassItable::adjust_method_entries(Method** old_methods, Method** new_methods,
970 int methods_length, bool * trace_name_printed) { 809 int methods_length, bool * trace_name_printed) {
971 // search the itable for uses of either obsolete or EMCP methods 810 // search the itable for uses of either obsolete or EMCP methods
972 for (int j = 0; j < methods_length; j++) { 811 for (int j = 0; j < methods_length; j++) {
973 methodOop old_method = old_methods[j]; 812 Method* old_method = old_methods[j];
974 methodOop new_method = new_methods[j]; 813 Method* new_method = new_methods[j];
975 itableMethodEntry* ime = method_entry(0); 814 itableMethodEntry* ime = method_entry(0);
976 815
977 // The itable can describe more than one interface and the same 816 // The itable can describe more than one interface and the same
978 // method signature can be specified by more than one interface. 817 // method signature can be specified by more than one interface.
979 // This means we have to do an exhaustive search to find all the 818 // This means we have to do an exhaustive search to find all the
984 823
985 if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) { 824 if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
986 if (!(*trace_name_printed)) { 825 if (!(*trace_name_printed)) {
987 // RC_TRACE_MESG macro has an embedded ResourceMark 826 // RC_TRACE_MESG macro has an embedded ResourceMark
988 RC_TRACE_MESG(("adjust: name=%s", 827 RC_TRACE_MESG(("adjust: name=%s",
989 Klass::cast(old_method->method_holder())->external_name())); 828 old_method->method_holder()->external_name()));
990 *trace_name_printed = true; 829 *trace_name_printed = true;
991 } 830 }
992 // RC_TRACE macro has an embedded ResourceMark 831 // RC_TRACE macro has an embedded ResourceMark
993 RC_TRACE(0x00200000, ("itable method update: %s(%s)", 832 RC_TRACE(0x00200000, ("itable method update: %s(%s)",
994 new_method->name()->as_C_string(), 833 new_method->name()->as_C_string(),
995 new_method->signature()->as_C_string())); 834 new_method->signature()->as_C_string()));
996 } 835 }
997 break; 836 // Cannot break because there might be another entry for this method
998 } 837 }
999 ime++; 838 ime++;
1000 } 839 }
1001 } 840 }
1002 } 841 }
1003 842
1004 843
1005 // Setup 844 // Setup
1006 class InterfaceVisiterClosure : public StackObj { 845 class InterfaceVisiterClosure : public StackObj {
1007 public: 846 public:
1008 virtual void doit(klassOop intf, int method_count) = 0; 847 virtual void doit(Klass* intf, int method_count) = 0;
1009 }; 848 };
1010 849
1011 // Visit all interfaces with at-least one method (excluding <clinit>) 850 // Visit all interfaces with at-least one method (excluding <clinit>)
1012 void visit_all_interfaces(objArrayOop transitive_intf, InterfaceVisiterClosure *blk) { 851 void visit_all_interfaces(Array<Klass*>* transitive_intf, InterfaceVisiterClosure *blk) {
1013 // Handle array argument 852 // Handle array argument
1014 for(int i = 0; i < transitive_intf->length(); i++) { 853 for(int i = 0; i < transitive_intf->length(); i++) {
1015 klassOop intf = (klassOop)transitive_intf->obj_at(i); 854 Klass* intf = transitive_intf->at(i);
1016 assert(Klass::cast(intf)->is_interface(), "sanity check"); 855 assert(Klass::cast(intf)->is_interface(), "sanity check");
1017 856
1018 // Find no. of methods excluding a <clinit> 857 // Find no. of methods excluding a <clinit>
1019 int method_count = instanceKlass::cast(intf)->methods()->length(); 858 int method_count = InstanceKlass::cast(intf)->methods()->length();
1020 if (method_count > 0) { 859 if (method_count > 0) {
1021 methodOop m = (methodOop)instanceKlass::cast(intf)->methods()->obj_at(0); 860 Method* m = InstanceKlass::cast(intf)->methods()->at(0);
1022 assert(m != NULL && m->is_method(), "sanity check"); 861 assert(m != NULL && m->is_method(), "sanity check");
1023 if (m->name() == vmSymbols::object_initializer_name()) { 862 if (m->name() == vmSymbols::object_initializer_name()) {
1024 method_count--; 863 method_count--;
1025 } 864 }
1026 } 865 }
1040 CountInterfacesClosure() { _nof_methods = 0; _nof_interfaces = 0; } 879 CountInterfacesClosure() { _nof_methods = 0; _nof_interfaces = 0; }
1041 880
1042 int nof_methods() const { return _nof_methods; } 881 int nof_methods() const { return _nof_methods; }
1043 int nof_interfaces() const { return _nof_interfaces; } 882 int nof_interfaces() const { return _nof_interfaces; }
1044 883
1045 void doit(klassOop intf, int method_count) { _nof_methods += method_count; _nof_interfaces++; } 884 void doit(Klass* intf, int method_count) { _nof_methods += method_count; _nof_interfaces++; }
1046 }; 885 };
1047 886
1048 class SetupItableClosure : public InterfaceVisiterClosure { 887 class SetupItableClosure : public InterfaceVisiterClosure {
1049 private: 888 private:
1050 itableOffsetEntry* _offset_entry; 889 itableOffsetEntry* _offset_entry;
1057 _method_entry = method_entry; 896 _method_entry = method_entry;
1058 } 897 }
1059 898
1060 itableMethodEntry* method_entry() const { return _method_entry; } 899 itableMethodEntry* method_entry() const { return _method_entry; }
1061 900
1062 void doit(klassOop intf, int method_count) { 901 void doit(Klass* intf, int method_count) {
1063 int offset = ((address)_method_entry) - _klass_begin; 902 int offset = ((address)_method_entry) - _klass_begin;
1064 _offset_entry->initialize(intf, offset); 903 _offset_entry->initialize(intf, offset);
1065 _offset_entry++; 904 _offset_entry++;
1066 _method_entry += method_count; 905 _method_entry += method_count;
1067 } 906 }
1068 }; 907 };
1069 908
1070 int klassItable::compute_itable_size(objArrayHandle transitive_interfaces) { 909 int klassItable::compute_itable_size(Array<Klass*>* transitive_interfaces) {
1071 // Count no of interfaces and total number of interface methods 910 // Count no of interfaces and total number of interface methods
1072 CountInterfacesClosure cic; 911 CountInterfacesClosure cic;
1073 visit_all_interfaces(transitive_interfaces(), &cic); 912 visit_all_interfaces(transitive_interfaces, &cic);
1074 913
1075 // There's alway an extra itable entry so we can null-terminate it. 914 // There's alway an extra itable entry so we can null-terminate it.
1076 int itable_size = calc_itable_size(cic.nof_interfaces() + 1, cic.nof_methods()); 915 int itable_size = calc_itable_size(cic.nof_interfaces() + 1, cic.nof_methods());
1077 916
1078 // Statistics 917 // Statistics
1094 int nof_interfaces = cic.nof_interfaces(); 933 int nof_interfaces = cic.nof_interfaces();
1095 934
1096 // Add one extra entry so we can null-terminate the table 935 // Add one extra entry so we can null-terminate the table
1097 nof_interfaces++; 936 nof_interfaces++;
1098 937
1099 assert(compute_itable_size(objArrayHandle(klass->transitive_interfaces())) == 938 assert(compute_itable_size(klass->transitive_interfaces()) ==
1100 calc_itable_size(nof_interfaces, nof_methods), 939 calc_itable_size(nof_interfaces, nof_methods),
1101 "mismatch calculation of itable size"); 940 "mismatch calculation of itable size");
1102 941
1103 // Fill-out offset table 942 // Fill-out offset table
1104 itableOffsetEntry* ioe = (itableOffsetEntry*)klass->start_of_itable(); 943 itableOffsetEntry* ioe = (itableOffsetEntry*)klass->start_of_itable();
1106 intptr_t* end = klass->end_of_itable(); 945 intptr_t* end = klass->end_of_itable();
1107 assert((oop*)(ime + nof_methods) <= (oop*)klass->start_of_nonstatic_oop_maps(), "wrong offset calculation (1)"); 946 assert((oop*)(ime + nof_methods) <= (oop*)klass->start_of_nonstatic_oop_maps(), "wrong offset calculation (1)");
1108 assert((oop*)(end) == (oop*)(ime + nof_methods), "wrong offset calculation (2)"); 947 assert((oop*)(end) == (oop*)(ime + nof_methods), "wrong offset calculation (2)");
1109 948
1110 // Visit all interfaces and initialize itable offset table 949 // Visit all interfaces and initialize itable offset table
1111 SetupItableClosure sic((address)klass->as_klassOop(), ioe, ime); 950 SetupItableClosure sic((address)klass(), ioe, ime);
1112 visit_all_interfaces(klass->transitive_interfaces(), &sic); 951 visit_all_interfaces(klass->transitive_interfaces(), &sic);
1113 952
1114 #ifdef ASSERT 953 #ifdef ASSERT
1115 ime = sic.method_entry(); 954 ime = sic.method_entry();
1116 oop* v = (oop*) klass->end_of_itable(); 955 oop* v = (oop*) klass->end_of_itable();
1118 #endif 957 #endif
1119 } 958 }
1120 959
1121 960
1122 // m must be a method in an interface 961 // m must be a method in an interface
1123 int klassItable::compute_itable_index(methodOop m) { 962 int klassItable::compute_itable_index(Method* m) {
1124 klassOop intf = m->method_holder(); 963 InstanceKlass* intf = m->method_holder();
1125 assert(instanceKlass::cast(intf)->is_interface(), "sanity check"); 964 assert(intf->is_interface(), "sanity check");
1126 objArrayOop methods = instanceKlass::cast(intf)->methods(); 965 Array<Method*>* methods = intf->methods();
1127 int index = 0; 966 int index = 0;
1128 while(methods->obj_at(index) != m) { 967 while(methods->at(index) != m) {
1129 index++; 968 index++;
1130 assert(index < methods->length(), "should find index for resolve_invoke"); 969 assert(index < methods->length(), "should find index for resolve_invoke");
1131 } 970 }
1132 // Adjust for <clinit>, which is left out of table if first method 971 // Adjust for <clinit>, which is left out of table if first method
1133 if (methods->length() > 0 && ((methodOop)methods->obj_at(0))->is_static_initializer()) { 972 if (methods->length() > 0 && methods->at(0)->is_static_initializer()) {
1134 index--; 973 index--;
1135 } 974 }
1136 return index; 975 return index;
1137 } 976 }
1138 977
1139 978
1140 // inverse to compute_itable_index 979 // inverse to compute_itable_index
1141 methodOop klassItable::method_for_itable_index(klassOop intf, int itable_index) { 980 Method* klassItable::method_for_itable_index(Klass* intf, int itable_index) {
1142 assert(instanceKlass::cast(intf)->is_interface(), "sanity check"); 981 assert(InstanceKlass::cast(intf)->is_interface(), "sanity check");
1143 objArrayOop methods = instanceKlass::cast(intf)->methods(); 982 Array<Method*>* methods = InstanceKlass::cast(intf)->methods();
1144 983
1145 int index = itable_index; 984 int index = itable_index;
1146 // Adjust for <clinit>, which is left out of table if first method 985 // Adjust for <clinit>, which is left out of table if first method
1147 if (methods->length() > 0 && ((methodOop)methods->obj_at(0))->is_static_initializer()) { 986 if (methods->length() > 0 && methods->at(0)->is_static_initializer()) {
1148 index++; 987 index++;
1149 } 988 }
1150 989
1151 if (itable_index < 0 || index >= methods->length()) 990 if (itable_index < 0 || index >= methods->length())
1152 return NULL; // help caller defend against bad indexes 991 return NULL; // help caller defend against bad indexes
1153 992
1154 methodOop m = (methodOop)methods->obj_at(index); 993 Method* m = methods->at(index);
1155 assert(compute_itable_index(m) == itable_index, "correct inverse"); 994 assert(compute_itable_index(m) == itable_index, "correct inverse");
1156 995
1157 return m; 996 return m;
1158 } 997 }
1159 998
1172 "end)", _klass->internal_name())); 1011 "end)", _klass->internal_name()));
1173 } 1012 }
1174 1013
1175 for (int i = 0; i < _length; i++) table()[i].verify(this, st); 1014 for (int i = 0; i < _length; i++) table()[i].verify(this, st);
1176 // verify consistency with superKlass vtable 1015 // verify consistency with superKlass vtable
1177 klassOop super = _klass->super(); 1016 Klass* super = _klass->super();
1178 if (super != NULL) { 1017 if (super != NULL) {
1179 instanceKlass* sk = instanceKlass::cast(super); 1018 InstanceKlass* sk = InstanceKlass::cast(super);
1180 klassVtable* vt = sk->vtable(); 1019 klassVtable* vt = sk->vtable();
1181 for (int i = 0; i < vt->length(); i++) { 1020 for (int i = 0; i < vt->length(); i++) {
1182 verify_against(st, vt, i); 1021 verify_against(st, vt, i);
1183 } 1022 }
1184 } 1023 }
1236 static int fixed; // total fixed overhead in bytes 1075 static int fixed; // total fixed overhead in bytes
1237 static int filler; // overhead caused by filler bytes 1076 static int filler; // overhead caused by filler bytes
1238 static int entries; // total bytes consumed by vtable entries 1077 static int entries; // total bytes consumed by vtable entries
1239 static int array_entries; // total bytes consumed by array vtable entries 1078 static int array_entries; // total bytes consumed by array vtable entries
1240 1079
1241 static void do_class(klassOop k) { 1080 static void do_class(Klass* k) {
1242 Klass* kl = k->klass_part(); 1081 Klass* kl = k;
1243 klassVtable* vt = kl->vtable(); 1082 klassVtable* vt = kl->vtable();
1244 if (vt == NULL) return; 1083 if (vt == NULL) return;
1245 no_klasses++; 1084 no_klasses++;
1246 if (kl->oop_is_instance()) { 1085 if (kl->oop_is_instance()) {
1247 no_instance_klasses++; 1086 no_instance_klasses++;
1256 1095
1257 static void compute() { 1096 static void compute() {
1258 SystemDictionary::classes_do(do_class); 1097 SystemDictionary::classes_do(do_class);
1259 fixed = no_klasses * oopSize; // vtable length 1098 fixed = no_klasses * oopSize; // vtable length
1260 // filler size is a conservative approximation 1099 // filler size is a conservative approximation
1261 filler = oopSize * (no_klasses - no_instance_klasses) * (sizeof(instanceKlass) - sizeof(arrayKlass) - 1); 1100 filler = oopSize * (no_klasses - no_instance_klasses) * (sizeof(InstanceKlass) - sizeof(ArrayKlass) - 1);
1262 entries = sizeof(vtableEntry) * sum_of_vtable_len; 1101 entries = sizeof(vtableEntry) * sum_of_vtable_len;
1263 array_entries = sizeof(vtableEntry) * sum_of_array_vtable_len; 1102 array_entries = sizeof(vtableEntry) * sum_of_array_vtable_len;
1264 } 1103 }
1265 }; 1104 };
1266 1105
1288 } 1127 }
1289 1128
1290 bool klassVtable::check_no_old_entries() { 1129 bool klassVtable::check_no_old_entries() {
1291 // Check that there really is no entry 1130 // Check that there really is no entry
1292 for (int i = 0; i < length(); i++) { 1131 for (int i = 0; i < length(); i++) {
1293 methodOop m = unchecked_method_at(i); 1132 Method* m = unchecked_method_at(i);
1294 if (m != NULL) { 1133 if (m != NULL) {
1295 if (m->is_old()) { 1134 if (!m->is_valid() || m->is_old()) {
1296 return false; 1135 return false;
1297 } 1136 }
1298 } 1137 }
1299 } 1138 }
1300 return true; 1139 return true;
1301 } 1140 }
1302 1141
1303 void klassVtable::dump_vtable() { 1142 void klassVtable::dump_vtable() {
1304 tty->print_cr("vtable dump --"); 1143 tty->print_cr("vtable dump --");
1305 for (int i = 0; i < length(); i++) { 1144 for (int i = 0; i < length(); i++) {
1306 methodOop m = unchecked_method_at(i); 1145 Method* m = unchecked_method_at(i);
1307 if (m != NULL) { 1146 if (m != NULL) {
1308 tty->print(" (%5d) ", i); 1147 tty->print(" (%5d) ", i);
1309 m->access_flags().print_on(tty); 1148 m->access_flags().print_on(tty);
1310 tty->print(" -- "); 1149 tty->print(" -- ");
1311 m->print_name(tty); 1150 m->print_name(tty);
1312 tty->cr(); 1151 tty->cr();
1313 } 1152 }
1314 } 1153 }
1315 } 1154 }
1316 1155
1156 bool klassItable::check_no_old_entries() {
1157 itableMethodEntry* ime = method_entry(0);
1158 for(int i = 0; i < _size_method_table; i++) {
1159 Method* m = ime->method();
1160 if (m != NULL && (!m->is_valid() || m->is_old())) return false;
1161 ime++;
1162 }
1163 return true;
1164 }
1165
1317 int klassItable::_total_classes; // Total no. of classes with itables 1166 int klassItable::_total_classes; // Total no. of classes with itables
1318 long klassItable::_total_size; // Total no. of bytes used for itables 1167 long klassItable::_total_size; // Total no. of bytes used for itables
1319 1168
1320 void klassItable::print_statistics() { 1169 void klassItable::print_statistics() {
1321 tty->print_cr("itable statistics:"); 1170 tty->print_cr("itable statistics:");