1112 int i = method_compare(a, b); |
1112 int i = method_compare(a, b); |
1113 if (i != 0) return i; |
1113 if (i != 0) return i; |
1114 return ( a < b ? -1 : (a == b ? 0 : 1)); |
1114 return ( a < b ? -1 : (a == b ? 0 : 1)); |
1115 } |
1115 } |
1116 |
1116 |
|
1117 // We implement special compare versions for narrow oops to avoid |
|
1118 // testing for UseCompressedOops on every comparison. |
|
1119 static int method_compare_narrow(narrowOop* a, narrowOop* b) { |
|
1120 methodOop m = (methodOop)oopDesc::load_decode_heap_oop(a); |
|
1121 methodOop n = (methodOop)oopDesc::load_decode_heap_oop(b); |
|
1122 return m->name()->fast_compare(n->name()); |
|
1123 } |
|
1124 |
|
1125 static int method_compare_narrow_idempotent(narrowOop* a, narrowOop* b) { |
|
1126 int i = method_compare_narrow(a, b); |
|
1127 if (i != 0) return i; |
|
1128 return ( a < b ? -1 : (a == b ? 0 : 1)); |
|
1129 } |
|
1130 |
1117 typedef int (*compareFn)(const void*, const void*); |
1131 typedef int (*compareFn)(const void*, const void*); |
1118 } |
1132 } |
1119 |
1133 |
1120 |
1134 |
1121 // This is only done during class loading, so it is OK to assume method_idnum matches the methods() array |
1135 // This is only done during class loading, so it is OK to assume method_idnum matches the methods() array |
1164 } |
1178 } |
1165 } |
1179 } |
1166 |
1180 |
1167 // Use a simple bubble sort for small number of methods since |
1181 // Use a simple bubble sort for small number of methods since |
1168 // qsort requires a functional pointer call for each comparison. |
1182 // qsort requires a functional pointer call for each comparison. |
1169 if (UseCompressedOops || length < 8) { |
1183 if (length < 8) { |
1170 bool sorted = true; |
1184 bool sorted = true; |
1171 for (int i=length-1; i>0; i--) { |
1185 for (int i=length-1; i>0; i--) { |
1172 for (int j=0; j<i; j++) { |
1186 for (int j=0; j<i; j++) { |
1173 methodOop m1 = (methodOop)methods->obj_at(j); |
1187 methodOop m1 = (methodOop)methods->obj_at(j); |
1174 methodOop m2 = (methodOop)methods->obj_at(j+1); |
1188 methodOop m2 = (methodOop)methods->obj_at(j+1); |
1180 } |
1194 } |
1181 if (sorted) break; |
1195 if (sorted) break; |
1182 sorted = true; |
1196 sorted = true; |
1183 } |
1197 } |
1184 } else { |
1198 } else { |
1185 // XXX This doesn't work for UseCompressedOops because the compare fn |
1199 compareFn compare = |
1186 // will have to decode the methodOop anyway making it not much faster |
1200 (UseCompressedOops ? |
1187 // than above. |
1201 (compareFn) (idempotent ? method_compare_narrow_idempotent : method_compare_narrow): |
1188 compareFn compare = (compareFn) (idempotent ? method_compare_idempotent : method_compare); |
1202 (compareFn) (idempotent ? method_compare_idempotent : method_compare)); |
1189 qsort(methods->base(), length, heapOopSize, compare); |
1203 qsort(methods->base(), length, heapOopSize, compare); |
1190 } |
1204 } |
1191 |
1205 |
1192 // Sort annotations if necessary |
1206 // Sort annotations if necessary |
1193 assert(methods_annotations == NULL || methods_annotations->length() == methods->length(), ""); |
1207 assert(methods_annotations == NULL || methods_annotations->length() == methods->length(), ""); |