1.1 --- a/src/share/vm/oops/instanceKlass.cpp Thu Nov 01 13:05:47 2012 +0100 1.2 +++ b/src/share/vm/oops/instanceKlass.cpp Thu Oct 11 12:25:42 2012 -0400 1.3 @@ -743,6 +743,35 @@ 1.4 } 1.5 } 1.6 1.7 + if (this_oop->has_default_methods()) { 1.8 + // Step 7.5: initialize any interfaces which have default methods 1.9 + for (int i = 0; i < this_oop->local_interfaces()->length(); ++i) { 1.10 + Klass* iface = this_oop->local_interfaces()->at(i); 1.11 + InstanceKlass* ik = InstanceKlass::cast(iface); 1.12 + if (ik->has_default_methods() && ik->should_be_initialized()) { 1.13 + ik->initialize(THREAD); 1.14 + 1.15 + if (HAS_PENDING_EXCEPTION) { 1.16 + Handle e(THREAD, PENDING_EXCEPTION); 1.17 + CLEAR_PENDING_EXCEPTION; 1.18 + { 1.19 + EXCEPTION_MARK; 1.20 + // Locks object, set state, and notify all waiting threads 1.21 + this_oop->set_initialization_state_and_notify( 1.22 + initialization_error, THREAD); 1.23 + 1.24 + // ignore any exception thrown, superclass initialization error is 1.25 + // thrown below 1.26 + CLEAR_PENDING_EXCEPTION; 1.27 + } 1.28 + DTRACE_CLASSINIT_PROBE_WAIT( 1.29 + super__failed, InstanceKlass::cast(this_oop()), -1, wait); 1.30 + THROW_OOP(e()); 1.31 + } 1.32 + } 1.33 + } 1.34 + } 1.35 + 1.36 // Step 8 1.37 { 1.38 assert(THREAD->is_Java_thread(), "non-JavaThread in initialize_impl"); 1.39 @@ -1252,11 +1281,7 @@ 1.40 } 1.41 #endif 1.42 1.43 -Method* InstanceKlass::find_method(Symbol* name, Symbol* signature) const { 1.44 - return InstanceKlass::find_method(methods(), name, signature); 1.45 -} 1.46 - 1.47 -Method* InstanceKlass::find_method(Array<Method*>* methods, Symbol* name, Symbol* signature) { 1.48 +static int binary_search(Array<Method*>* methods, Symbol* name) { 1.49 int len = methods->length(); 1.50 // methods are sorted, so do binary search 1.51 int l = 0; 1.52 @@ -1267,43 +1292,70 @@ 1.53 assert(m->is_method(), "must be method"); 1.54 int res = m->name()->fast_compare(name); 1.55 if (res == 0) { 1.56 - // found matching name; do linear search to find matching signature 1.57 - // first, quick check for common case 1.58 - if (m->signature() == signature) return m; 1.59 - // search downwards through overloaded methods 1.60 - int i; 1.61 - for (i = mid - 1; i >= l; i--) { 1.62 - Method* m = methods->at(i); 1.63 - assert(m->is_method(), "must be method"); 1.64 - if (m->name() != name) break; 1.65 - if (m->signature() == signature) return m; 1.66 - } 1.67 - // search upwards 1.68 - for (i = mid + 1; i <= h; i++) { 1.69 - Method* m = methods->at(i); 1.70 - assert(m->is_method(), "must be method"); 1.71 - if (m->name() != name) break; 1.72 - if (m->signature() == signature) return m; 1.73 - } 1.74 - // not found 1.75 -#ifdef ASSERT 1.76 - int index = linear_search(methods, name, signature); 1.77 - assert(index == -1, err_msg("binary search should have found entry %d", index)); 1.78 -#endif 1.79 - return NULL; 1.80 + return mid; 1.81 } else if (res < 0) { 1.82 l = mid + 1; 1.83 } else { 1.84 h = mid - 1; 1.85 } 1.86 } 1.87 + return -1; 1.88 +} 1.89 + 1.90 +Method* InstanceKlass::find_method(Symbol* name, Symbol* signature) const { 1.91 + return InstanceKlass::find_method(methods(), name, signature); 1.92 +} 1.93 + 1.94 +Method* InstanceKlass::find_method( 1.95 + Array<Method*>* methods, Symbol* name, Symbol* signature) { 1.96 + int hit = binary_search(methods, name); 1.97 + if (hit != -1) { 1.98 + Method* m = methods->at(hit); 1.99 + // Do linear search to find matching signature. First, quick check 1.100 + // for common case 1.101 + if (m->signature() == signature) return m; 1.102 + // search downwards through overloaded methods 1.103 + int i; 1.104 + for (i = hit - 1; i >= 0; --i) { 1.105 + Method* m = methods->at(i); 1.106 + assert(m->is_method(), "must be method"); 1.107 + if (m->name() != name) break; 1.108 + if (m->signature() == signature) return m; 1.109 + } 1.110 + // search upwards 1.111 + for (i = hit + 1; i < methods->length(); ++i) { 1.112 + Method* m = methods->at(i); 1.113 + assert(m->is_method(), "must be method"); 1.114 + if (m->name() != name) break; 1.115 + if (m->signature() == signature) return m; 1.116 + } 1.117 + // not found 1.118 #ifdef ASSERT 1.119 - int index = linear_search(methods, name, signature); 1.120 - assert(index == -1, err_msg("binary search should have found entry %d", index)); 1.121 + int index = linear_search(methods, name, signature); 1.122 + assert(index == -1, err_msg("binary search should have found entry %d", index)); 1.123 #endif 1.124 + } 1.125 return NULL; 1.126 } 1.127 1.128 +int InstanceKlass::find_method_by_name(Symbol* name, int* end) { 1.129 + return find_method_by_name(methods(), name, end); 1.130 +} 1.131 + 1.132 +int InstanceKlass::find_method_by_name( 1.133 + Array<Method*>* methods, Symbol* name, int* end_ptr) { 1.134 + assert(end_ptr != NULL, "just checking"); 1.135 + int start = binary_search(methods, name); 1.136 + int end = start + 1; 1.137 + if (start != -1) { 1.138 + while (start - 1 >= 0 && (methods->at(start - 1))->name() == name) --start; 1.139 + while (end < methods->length() && (methods->at(end))->name() == name) ++end; 1.140 + *end_ptr = end; 1.141 + return start; 1.142 + } 1.143 + return -1; 1.144 +} 1.145 + 1.146 Method* InstanceKlass::uncached_lookup_method(Symbol* name, Symbol* signature) const { 1.147 Klass* klass = const_cast<InstanceKlass*>(this); 1.148 while (klass != NULL) {