src/share/vm/oops/instanceKlass.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File hotspot Sdiff src/share/vm/oops

src/share/vm/oops/instanceKlass.cpp

Print this page




 129 
 130 InstanceKlass* InstanceKlass::allocate_instance_klass(
 131                                               ClassLoaderData* loader_data,
 132                                               int vtable_len,
 133                                               int itable_len,
 134                                               int static_field_size,
 135                                               int nonstatic_oop_map_size,
 136                                               ReferenceType rt,
 137                                               AccessFlags access_flags,
 138                                               Symbol* name,
 139                                               Klass* super_klass,
 140                                               bool is_anonymous,
 141                                               TRAPS) {
 142 
 143   int size = InstanceKlass::size(vtable_len, itable_len, nonstatic_oop_map_size,
 144                                  access_flags.is_interface(), is_anonymous);
 145 
 146   // Allocation
 147   InstanceKlass* ik;
 148   if (rt == REF_NONE) {
 149     if (name == vmSymbols::java_lang_Class()) {
 150       ik = new (loader_data, size, THREAD) InstanceMirrorKlass(
 151         vtable_len, itable_len, static_field_size, nonstatic_oop_map_size, rt,
 152         access_flags, is_anonymous);
 153     } else if (name == vmSymbols::java_lang_ClassLoader() ||
 154           (SystemDictionary::ClassLoader_klass_loaded() &&
 155           super_klass != NULL &&
 156           super_klass->is_subtype_of(SystemDictionary::ClassLoader_klass()))) {
 157       ik = new (loader_data, size, THREAD) InstanceClassLoaderKlass(
 158         vtable_len, itable_len, static_field_size, nonstatic_oop_map_size, rt,
 159         access_flags, is_anonymous);
 160     } else {
 161       // normal class
 162       ik = new (loader_data, size, THREAD) InstanceKlass(
 163         vtable_len, itable_len, static_field_size, nonstatic_oop_map_size, rt,
 164         access_flags, is_anonymous);
 165     }
 166   } else {
 167     // reference klass
 168     ik = new (loader_data, size, THREAD) InstanceRefKlass(
 169         vtable_len, itable_len, static_field_size, nonstatic_oop_map_size, rt,
 170         access_flags, is_anonymous);
 171   }
 172 
 173   // Check for pending exception before adding to the loader data and incrementing


1166     // Otherwise, allocate a new one.
1167     MutexLocker x(OopMapCacheAlloc_lock);
1168     // First time use. Allocate a cache in C heap
1169     if (_oop_map_cache == NULL) {
1170       // Release stores from OopMapCache constructor before assignment
1171       // to _oop_map_cache. C++ compilers on ppc do not emit the
1172       // required memory barrier only because of the volatile
1173       // qualifier of _oop_map_cache.
1174       OrderAccess::release_store_ptr(&_oop_map_cache, new OopMapCache());
1175     }
1176   }
1177   // _oop_map_cache is constant after init; lookup below does is own locking.
1178   _oop_map_cache->lookup(method, bci, entry_for);
1179 }
1180 
1181 
1182 bool InstanceKlass::find_local_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const {
1183   for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
1184     Symbol* f_name = fs.name();
1185     Symbol* f_sig  = fs.signature();
1186     if (f_name == name && f_sig == sig) {
1187       fd->reinitialize(const_cast<InstanceKlass*>(this), fs.index());
1188       return true;
1189     }
1190   }
1191   return false;
1192 }
1193 
1194 
1195 Klass* InstanceKlass::find_interface_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const {
1196   const int n = local_interfaces()->length();
1197   for (int i = 0; i < n; i++) {
1198     Klass* intf1 = local_interfaces()->at(i);
1199     assert(intf1->is_interface(), "just checking type");
1200     // search for field in current interface
1201     if (InstanceKlass::cast(intf1)->find_local_field(name, sig, fd)) {
1202       assert(fd->is_static(), "interface field must be static");
1203       return intf1;
1204     }
1205     // search for field in direct superinterfaces
1206     Klass* intf2 = InstanceKlass::cast(intf1)->find_interface_field(name, sig, fd);


1351   FREE_C_HEAP_ARRAY(int, fields_sorted);
1352 }
1353 
1354 
1355 void InstanceKlass::array_klasses_do(void f(Klass* k, TRAPS), TRAPS) {
1356   if (array_klasses() != NULL)
1357     ArrayKlass::cast(array_klasses())->array_klasses_do(f, THREAD);
1358 }
1359 
1360 void InstanceKlass::array_klasses_do(void f(Klass* k)) {
1361   if (array_klasses() != NULL)
1362     ArrayKlass::cast(array_klasses())->array_klasses_do(f);
1363 }
1364 
1365 #ifdef ASSERT
1366 static int linear_search(Array<Method*>* methods, Symbol* name, Symbol* signature) {
1367   int len = methods->length();
1368   for (int index = 0; index < len; index++) {
1369     Method* m = methods->at(index);
1370     assert(m->is_method(), "must be method");
1371     if (m->signature() == signature && m->name() == name) {
1372        return index;
1373     }
1374   }
1375   return -1;
1376 }
1377 #endif
1378 
1379 static int binary_search(Array<Method*>* methods, Symbol* name) {
1380   int len = methods->length();
1381   // methods are sorted, so do binary search
1382   int l = 0;
1383   int h = len - 1;
1384   while (l <= h) {
1385     int mid = (l + h) >> 1;
1386     Method* m = methods->at(mid);
1387     assert(m->is_method(), "must be method");
1388     int res = m->name()->fast_compare(name);
1389     if (res == 0) {
1390       return mid;
1391     } else if (res < 0) {


1419 
1420 // find_instance_method looks up the name/signature in the local methods array
1421 // and skips over static methods
1422 Method* InstanceKlass::find_instance_method(Symbol* name, Symbol* signature) {
1423     return InstanceKlass::find_instance_method(methods(), name, signature);
1424 }
1425 
1426 // find_method looks up the name/signature in the local methods array
1427 Method* InstanceKlass::find_method(
1428     Array<Method*>* methods, Symbol* name, Symbol* signature) {
1429   return InstanceKlass::find_method_impl(methods, name, signature, find_overpass, find_static);
1430 }
1431 
1432 Method* InstanceKlass::find_method_impl(
1433     Array<Method*>* methods, Symbol* name, Symbol* signature, OverpassLookupMode overpass_mode, StaticLookupMode static_mode) {
1434   int hit = find_method_index(methods, name, signature, overpass_mode, static_mode);
1435   return hit >= 0 ? methods->at(hit): NULL;
1436 }
1437 
1438 bool InstanceKlass::method_matches(Method* m, Symbol* signature, bool skipping_overpass, bool skipping_static) {
1439     return (m->signature() == signature) &&
1440             (!skipping_overpass || !m->is_overpass()) &&
1441             (!skipping_static || !m->is_static());
1442 }
1443 
1444 // Used directly for default_methods to find the index into the
1445 // default_vtable_indices, and indirectly by find_method
1446 // find_method_index looks in the local methods array to return the index
1447 // of the matching name/signature. If, overpass methods are being ignored,
1448 // the search continues to find a potential non-overpass match.  This capability
1449 // is important during method resolution to prefer a static method, for example,
1450 // over an overpass method.
1451 int InstanceKlass::find_method_index(
1452     Array<Method*>* methods, Symbol* name, Symbol* signature, OverpassLookupMode overpass_mode, StaticLookupMode static_mode) {
1453   bool skipping_overpass = (overpass_mode == skip_overpass);
1454   bool skipping_static = (static_mode == skip_static);
1455   int hit = binary_search(methods, name);
1456   if (hit != -1) {
1457     Method* m = methods->at(hit);
1458 
1459     // Do linear search to find matching signature.  First, quick check
1460     // for common case, ignoring overpasses if requested.
1461     if (method_matches(m, signature, skipping_overpass, skipping_static)) return hit;
1462 
1463     // search downwards through overloaded methods
1464     int i;
1465     for (i = hit - 1; i >= 0; --i) {
1466         Method* m = methods->at(i);
1467         assert(m->is_method(), "must be method");
1468         if (m->name() != name) break;
1469         if (method_matches(m, signature, skipping_overpass, skipping_static)) return i;
1470     }
1471     // search upwards
1472     for (i = hit + 1; i < methods->length(); ++i) {
1473         Method* m = methods->at(i);
1474         assert(m->is_method(), "must be method");
1475         if (m->name() != name) break;
1476         if (method_matches(m, signature, skipping_overpass, skipping_static)) return i;
1477     }
1478     // not found
1479 #ifdef ASSERT
1480     int index = (skipping_overpass || skipping_static) ? -1 : linear_search(methods, name, signature);
1481     assert(index == -1, err_msg("binary search should have found entry %d", index));
1482 #endif
1483   }
1484   return -1;
1485 }
1486 int InstanceKlass::find_method_by_name(Symbol* name, int* end) {
1487   return find_method_by_name(methods(), name, end);
1488 }
1489 
1490 int InstanceKlass::find_method_by_name(
1491     Array<Method*>* methods, Symbol* name, int* end_ptr) {
1492   assert(end_ptr != NULL, "just checking");
1493   int start = binary_search(methods, name);
1494   int end = start + 1;
1495   if (start != -1) {
1496     while (start - 1 >= 0 && (methods->at(start - 1))->name() == name) --start;
1497     while (end < methods->length() && (methods->at(end))->name() == name) ++end;
1498     *end_ptr = end;
1499     return start;
1500   }
1501   return -1;
1502 }
1503 
1504 // uncached_lookup_method searches both the local class methods array and all
1505 // superclasses methods arrays, skipping any overpass methods in superclasses.
1506 Method* InstanceKlass::uncached_lookup_method(Symbol* name, Symbol* signature, OverpassLookupMode overpass_mode) const {
1507   OverpassLookupMode overpass_local_mode = overpass_mode;
1508   Klass* klass = const_cast<InstanceKlass*>(this);
1509   while (klass != NULL) {
1510     Method* method = InstanceKlass::cast(klass)->find_method_impl(name, signature, overpass_local_mode, find_static);
1511     if (method != NULL) {
1512       return method;
1513     }
1514     klass = InstanceKlass::cast(klass)->super();
1515     overpass_local_mode = skip_overpass;   // Always ignore overpass methods in superclasses
1516   }
1517   return NULL;


2559 
2560   return InstanceKlass::is_same_class_package(classloader1, classname1,
2561                                               classloader2, classname2);
2562 }
2563 
2564 bool InstanceKlass::is_same_class_package(oop classloader2, Symbol* classname2) {
2565   Klass* class1 = this;
2566   oop classloader1 = InstanceKlass::cast(class1)->class_loader();
2567   Symbol* classname1 = class1->name();
2568 
2569   return InstanceKlass::is_same_class_package(classloader1, classname1,
2570                                               classloader2, classname2);
2571 }
2572 
2573 // return true if two classes are in the same package, classloader
2574 // and classname information is enough to determine a class's package
2575 bool InstanceKlass::is_same_class_package(oop class_loader1, Symbol* class_name1,
2576                                           oop class_loader2, Symbol* class_name2) {
2577   if (class_loader1 != class_loader2) {
2578     return false;
2579   } else if (class_name1 == class_name2) {
2580     return true;                // skip painful bytewise comparison
2581   } else {
2582     ResourceMark rm;
2583 
2584     // The Symbol*'s are in UTF8 encoding. Since we only need to check explicitly
2585     // for ASCII characters ('/', 'L', '['), we can keep them in UTF8 encoding.
2586     // Otherwise, we just compare jbyte values between the strings.
2587     const jbyte *name1 = class_name1->base();
2588     const jbyte *name2 = class_name2->base();
2589 
2590     const jbyte *last_slash1 = UTF8::strrchr(name1, class_name1->utf8_length(), '/');
2591     const jbyte *last_slash2 = UTF8::strrchr(name2, class_name2->utf8_length(), '/');
2592 
2593     if ((last_slash1 == NULL) || (last_slash2 == NULL)) {
2594       // One of the two doesn't have a package.  Only return true
2595       // if the other one also doesn't have a package.
2596       return last_slash1 == last_slash2;
2597     } else {
2598       // Skip over '['s
2599       if (*name1 == '[') {


2694   // two classes, we know they are in separate package members.
2695   return false;
2696 }
2697 
2698 
2699 jint InstanceKlass::compute_modifier_flags(TRAPS) const {
2700   jint access = access_flags().as_int();
2701 
2702   // But check if it happens to be member class.
2703   instanceKlassHandle ik(THREAD, this);
2704   InnerClassesIterator iter(ik);
2705   for (; !iter.done(); iter.next()) {
2706     int ioff = iter.inner_class_info_index();
2707     // Inner class attribute can be zero, skip it.
2708     // Strange but true:  JVM spec. allows null inner class refs.
2709     if (ioff == 0) continue;
2710 
2711     // only look at classes that are already loaded
2712     // since we are looking for the flags for our self.
2713     Symbol* inner_name = ik->constants()->klass_name_at(ioff);
2714     if ((ik->name() == inner_name)) {
2715       // This is really a member class.
2716       access = iter.inner_access_flags();
2717       break;
2718     }
2719   }
2720   // Remember to strip ACC_SUPER bit
2721   return (access & (~JVM_ACC_SUPER)) & JVM_ACC_WRITTEN_FLAGS;
2722 }
2723 
2724 jint InstanceKlass::jvmti_class_status() const {
2725   jint result = 0;
2726 
2727   if (is_linked()) {
2728     result |= JVMTI_CLASS_STATUS_VERIFIED | JVMTI_CLASS_STATUS_PREPARED;
2729   }
2730 
2731   if (is_initialized()) {
2732     assert(is_linked(), "Class status is not consistent");
2733     result |= JVMTI_CLASS_STATUS_INITIALIZED;
2734   }


3568     // clear out any matching EMCP method entries the hard way.
3569     int local_count = 0;
3570     for (int i = 0; i < old_methods->length(); i++) {
3571       Method* old_method = old_methods->at(i);
3572       if (old_method->is_obsolete()) {
3573         // only obsolete methods are interesting
3574         Symbol* m_name = old_method->name();
3575         Symbol* m_signature = old_method->signature();
3576 
3577         // previous versions are linked together through the InstanceKlass
3578         int j = 0;
3579         for (InstanceKlass* prev_version = _previous_versions;
3580              prev_version != NULL;
3581              prev_version = prev_version->previous_versions(), j++) {
3582 
3583           Array<Method*>* method_refs = prev_version->methods();
3584           for (int k = 0; k < method_refs->length(); k++) {
3585             Method* method = method_refs->at(k);
3586 
3587             if (!method->is_obsolete() &&
3588                 method->name() == m_name &&
3589                 method->signature() == m_signature) {
3590               // The current RedefineClasses() call has made all EMCP
3591               // versions of this method obsolete so mark it as obsolete
3592               RC_TRACE(0x00000400,
3593                 ("add: %s(%s): flush obsolete method @%d in version @%d",
3594                 m_name->as_C_string(), m_signature->as_C_string(), k, j));
3595 
3596               method->set_is_obsolete();
3597               break;
3598             }
3599           }
3600 
3601           // The previous loop may not find a matching EMCP method, but
3602           // that doesn't mean that we can optimize and not go any
3603           // further back in the PreviousVersion generations. The EMCP
3604           // method for this generation could have already been made obsolete,
3605           // but there still may be an older EMCP method that has not
3606           // been made obsolete.
3607         }
3608 
3609         if (++local_count >= obsolete_method_count) {




 129 
 130 InstanceKlass* InstanceKlass::allocate_instance_klass(
 131                                               ClassLoaderData* loader_data,
 132                                               int vtable_len,
 133                                               int itable_len,
 134                                               int static_field_size,
 135                                               int nonstatic_oop_map_size,
 136                                               ReferenceType rt,
 137                                               AccessFlags access_flags,
 138                                               Symbol* name,
 139                                               Klass* super_klass,
 140                                               bool is_anonymous,
 141                                               TRAPS) {
 142 
 143   int size = InstanceKlass::size(vtable_len, itable_len, nonstatic_oop_map_size,
 144                                  access_flags.is_interface(), is_anonymous);
 145 
 146   // Allocation
 147   InstanceKlass* ik;
 148   if (rt == REF_NONE) {
 149     if (name->equals(vmSymbols::java_lang_Class())) {
 150       ik = new (loader_data, size, THREAD) InstanceMirrorKlass(
 151         vtable_len, itable_len, static_field_size, nonstatic_oop_map_size, rt,
 152         access_flags, is_anonymous);
 153     } else if (name->equals(vmSymbols::java_lang_ClassLoader()) ||
 154           (SystemDictionary::ClassLoader_klass_loaded() &&
 155           super_klass != NULL &&
 156           super_klass->is_subtype_of(SystemDictionary::ClassLoader_klass()))) {
 157       ik = new (loader_data, size, THREAD) InstanceClassLoaderKlass(
 158         vtable_len, itable_len, static_field_size, nonstatic_oop_map_size, rt,
 159         access_flags, is_anonymous);
 160     } else {
 161       // normal class
 162       ik = new (loader_data, size, THREAD) InstanceKlass(
 163         vtable_len, itable_len, static_field_size, nonstatic_oop_map_size, rt,
 164         access_flags, is_anonymous);
 165     }
 166   } else {
 167     // reference klass
 168     ik = new (loader_data, size, THREAD) InstanceRefKlass(
 169         vtable_len, itable_len, static_field_size, nonstatic_oop_map_size, rt,
 170         access_flags, is_anonymous);
 171   }
 172 
 173   // Check for pending exception before adding to the loader data and incrementing


1166     // Otherwise, allocate a new one.
1167     MutexLocker x(OopMapCacheAlloc_lock);
1168     // First time use. Allocate a cache in C heap
1169     if (_oop_map_cache == NULL) {
1170       // Release stores from OopMapCache constructor before assignment
1171       // to _oop_map_cache. C++ compilers on ppc do not emit the
1172       // required memory barrier only because of the volatile
1173       // qualifier of _oop_map_cache.
1174       OrderAccess::release_store_ptr(&_oop_map_cache, new OopMapCache());
1175     }
1176   }
1177   // _oop_map_cache is constant after init; lookup below does is own locking.
1178   _oop_map_cache->lookup(method, bci, entry_for);
1179 }
1180 
1181 
1182 bool InstanceKlass::find_local_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const {
1183   for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
1184     Symbol* f_name = fs.name();
1185     Symbol* f_sig  = fs.signature();
1186     if (f_name->equals(name) && f_sig->equals(sig)) {
1187       fd->reinitialize(const_cast<InstanceKlass*>(this), fs.index());
1188       return true;
1189     }
1190   }
1191   return false;
1192 }
1193 
1194 
1195 Klass* InstanceKlass::find_interface_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const {
1196   const int n = local_interfaces()->length();
1197   for (int i = 0; i < n; i++) {
1198     Klass* intf1 = local_interfaces()->at(i);
1199     assert(intf1->is_interface(), "just checking type");
1200     // search for field in current interface
1201     if (InstanceKlass::cast(intf1)->find_local_field(name, sig, fd)) {
1202       assert(fd->is_static(), "interface field must be static");
1203       return intf1;
1204     }
1205     // search for field in direct superinterfaces
1206     Klass* intf2 = InstanceKlass::cast(intf1)->find_interface_field(name, sig, fd);


1351   FREE_C_HEAP_ARRAY(int, fields_sorted);
1352 }
1353 
1354 
1355 void InstanceKlass::array_klasses_do(void f(Klass* k, TRAPS), TRAPS) {
1356   if (array_klasses() != NULL)
1357     ArrayKlass::cast(array_klasses())->array_klasses_do(f, THREAD);
1358 }
1359 
1360 void InstanceKlass::array_klasses_do(void f(Klass* k)) {
1361   if (array_klasses() != NULL)
1362     ArrayKlass::cast(array_klasses())->array_klasses_do(f);
1363 }
1364 
1365 #ifdef ASSERT
1366 static int linear_search(Array<Method*>* methods, Symbol* name, Symbol* signature) {
1367   int len = methods->length();
1368   for (int index = 0; index < len; index++) {
1369     Method* m = methods->at(index);
1370     assert(m->is_method(), "must be method");
1371     if (m->signature()->equals(signature) && m->name()->equals(name)) {
1372        return index;
1373     }
1374   }
1375   return -1;
1376 }
1377 #endif
1378 
1379 static int binary_search(Array<Method*>* methods, Symbol* name) {
1380   int len = methods->length();
1381   // methods are sorted, so do binary search
1382   int l = 0;
1383   int h = len - 1;
1384   while (l <= h) {
1385     int mid = (l + h) >> 1;
1386     Method* m = methods->at(mid);
1387     assert(m->is_method(), "must be method");
1388     int res = m->name()->fast_compare(name);
1389     if (res == 0) {
1390       return mid;
1391     } else if (res < 0) {


1419 
1420 // find_instance_method looks up the name/signature in the local methods array
1421 // and skips over static methods
1422 Method* InstanceKlass::find_instance_method(Symbol* name, Symbol* signature) {
1423     return InstanceKlass::find_instance_method(methods(), name, signature);
1424 }
1425 
1426 // find_method looks up the name/signature in the local methods array
1427 Method* InstanceKlass::find_method(
1428     Array<Method*>* methods, Symbol* name, Symbol* signature) {
1429   return InstanceKlass::find_method_impl(methods, name, signature, find_overpass, find_static);
1430 }
1431 
1432 Method* InstanceKlass::find_method_impl(
1433     Array<Method*>* methods, Symbol* name, Symbol* signature, OverpassLookupMode overpass_mode, StaticLookupMode static_mode) {
1434   int hit = find_method_index(methods, name, signature, overpass_mode, static_mode);
1435   return hit >= 0 ? methods->at(hit): NULL;
1436 }
1437 
1438 bool InstanceKlass::method_matches(Method* m, Symbol* signature, bool skipping_overpass, bool skipping_static) {
1439     return (m->signature()->equals(signature)) &&
1440             (!skipping_overpass || !m->is_overpass()) &&
1441             (!skipping_static || !m->is_static());
1442 }
1443 
1444 // Used directly for default_methods to find the index into the
1445 // default_vtable_indices, and indirectly by find_method
1446 // find_method_index looks in the local methods array to return the index
1447 // of the matching name/signature. If, overpass methods are being ignored,
1448 // the search continues to find a potential non-overpass match.  This capability
1449 // is important during method resolution to prefer a static method, for example,
1450 // over an overpass method.
1451 int InstanceKlass::find_method_index(
1452     Array<Method*>* methods, Symbol* name, Symbol* signature, OverpassLookupMode overpass_mode, StaticLookupMode static_mode) {
1453   bool skipping_overpass = (overpass_mode == skip_overpass);
1454   bool skipping_static = (static_mode == skip_static);
1455   int hit = binary_search(methods, name);
1456   if (hit != -1) {
1457     Method* m = methods->at(hit);
1458 
1459     // Do linear search to find matching signature.  First, quick check
1460     // for common case, ignoring overpasses if requested.
1461     if (method_matches(m, signature, skipping_overpass, skipping_static)) return hit;
1462 
1463     // search downwards through overloaded methods
1464     int i;
1465     for (i = hit - 1; i >= 0; --i) {
1466         Method* m = methods->at(i);
1467         assert(m->is_method(), "must be method");
1468         if (m->name()->not_equals(name)) break;
1469         if (method_matches(m, signature, skipping_overpass, skipping_static)) return i;
1470     }
1471     // search upwards
1472     for (i = hit + 1; i < methods->length(); ++i) {
1473         Method* m = methods->at(i);
1474         assert(m->is_method(), "must be method");
1475         if (m->name()->not_equals(name)) break;
1476         if (method_matches(m, signature, skipping_overpass, skipping_static)) return i;
1477     }
1478     // not found
1479 #ifdef ASSERT
1480     int index = (skipping_overpass || skipping_static) ? -1 : linear_search(methods, name, signature);
1481     assert(index == -1, err_msg("binary search should have found entry %d", index));
1482 #endif
1483   }
1484   return -1;
1485 }
1486 int InstanceKlass::find_method_by_name(Symbol* name, int* end) {
1487   return find_method_by_name(methods(), name, end);
1488 }
1489 
1490 int InstanceKlass::find_method_by_name(
1491     Array<Method*>* methods, Symbol* name, int* end_ptr) {
1492   assert(end_ptr != NULL, "just checking");
1493   int start = binary_search(methods, name);
1494   int end = start + 1;
1495   if (start != -1) {
1496     while (start - 1 >= 0 && (methods->at(start - 1))->name()->equals(name)) --start;
1497     while (end < methods->length() && (methods->at(end))->name()->equals(name)) ++end;
1498     *end_ptr = end;
1499     return start;
1500   }
1501   return -1;
1502 }
1503 
1504 // uncached_lookup_method searches both the local class methods array and all
1505 // superclasses methods arrays, skipping any overpass methods in superclasses.
1506 Method* InstanceKlass::uncached_lookup_method(Symbol* name, Symbol* signature, OverpassLookupMode overpass_mode) const {
1507   OverpassLookupMode overpass_local_mode = overpass_mode;
1508   Klass* klass = const_cast<InstanceKlass*>(this);
1509   while (klass != NULL) {
1510     Method* method = InstanceKlass::cast(klass)->find_method_impl(name, signature, overpass_local_mode, find_static);
1511     if (method != NULL) {
1512       return method;
1513     }
1514     klass = InstanceKlass::cast(klass)->super();
1515     overpass_local_mode = skip_overpass;   // Always ignore overpass methods in superclasses
1516   }
1517   return NULL;


2559 
2560   return InstanceKlass::is_same_class_package(classloader1, classname1,
2561                                               classloader2, classname2);
2562 }
2563 
2564 bool InstanceKlass::is_same_class_package(oop classloader2, Symbol* classname2) {
2565   Klass* class1 = this;
2566   oop classloader1 = InstanceKlass::cast(class1)->class_loader();
2567   Symbol* classname1 = class1->name();
2568 
2569   return InstanceKlass::is_same_class_package(classloader1, classname1,
2570                                               classloader2, classname2);
2571 }
2572 
2573 // return true if two classes are in the same package, classloader
2574 // and classname information is enough to determine a class's package
2575 bool InstanceKlass::is_same_class_package(oop class_loader1, Symbol* class_name1,
2576                                           oop class_loader2, Symbol* class_name2) {
2577   if (class_loader1 != class_loader2) {
2578     return false;
2579   } else if (class_name1->equals(class_name2)) {
2580     return true;                // skip painful bytewise comparison
2581   } else {
2582     ResourceMark rm;
2583 
2584     // The Symbol*'s are in UTF8 encoding. Since we only need to check explicitly
2585     // for ASCII characters ('/', 'L', '['), we can keep them in UTF8 encoding.
2586     // Otherwise, we just compare jbyte values between the strings.
2587     const jbyte *name1 = class_name1->base();
2588     const jbyte *name2 = class_name2->base();
2589 
2590     const jbyte *last_slash1 = UTF8::strrchr(name1, class_name1->utf8_length(), '/');
2591     const jbyte *last_slash2 = UTF8::strrchr(name2, class_name2->utf8_length(), '/');
2592 
2593     if ((last_slash1 == NULL) || (last_slash2 == NULL)) {
2594       // One of the two doesn't have a package.  Only return true
2595       // if the other one also doesn't have a package.
2596       return last_slash1 == last_slash2;
2597     } else {
2598       // Skip over '['s
2599       if (*name1 == '[') {


2694   // two classes, we know they are in separate package members.
2695   return false;
2696 }
2697 
2698 
2699 jint InstanceKlass::compute_modifier_flags(TRAPS) const {
2700   jint access = access_flags().as_int();
2701 
2702   // But check if it happens to be member class.
2703   instanceKlassHandle ik(THREAD, this);
2704   InnerClassesIterator iter(ik);
2705   for (; !iter.done(); iter.next()) {
2706     int ioff = iter.inner_class_info_index();
2707     // Inner class attribute can be zero, skip it.
2708     // Strange but true:  JVM spec. allows null inner class refs.
2709     if (ioff == 0) continue;
2710 
2711     // only look at classes that are already loaded
2712     // since we are looking for the flags for our self.
2713     Symbol* inner_name = ik->constants()->klass_name_at(ioff);
2714     if ((ik->name()->equals(inner_name))) {
2715       // This is really a member class.
2716       access = iter.inner_access_flags();
2717       break;
2718     }
2719   }
2720   // Remember to strip ACC_SUPER bit
2721   return (access & (~JVM_ACC_SUPER)) & JVM_ACC_WRITTEN_FLAGS;
2722 }
2723 
2724 jint InstanceKlass::jvmti_class_status() const {
2725   jint result = 0;
2726 
2727   if (is_linked()) {
2728     result |= JVMTI_CLASS_STATUS_VERIFIED | JVMTI_CLASS_STATUS_PREPARED;
2729   }
2730 
2731   if (is_initialized()) {
2732     assert(is_linked(), "Class status is not consistent");
2733     result |= JVMTI_CLASS_STATUS_INITIALIZED;
2734   }


3568     // clear out any matching EMCP method entries the hard way.
3569     int local_count = 0;
3570     for (int i = 0; i < old_methods->length(); i++) {
3571       Method* old_method = old_methods->at(i);
3572       if (old_method->is_obsolete()) {
3573         // only obsolete methods are interesting
3574         Symbol* m_name = old_method->name();
3575         Symbol* m_signature = old_method->signature();
3576 
3577         // previous versions are linked together through the InstanceKlass
3578         int j = 0;
3579         for (InstanceKlass* prev_version = _previous_versions;
3580              prev_version != NULL;
3581              prev_version = prev_version->previous_versions(), j++) {
3582 
3583           Array<Method*>* method_refs = prev_version->methods();
3584           for (int k = 0; k < method_refs->length(); k++) {
3585             Method* method = method_refs->at(k);
3586 
3587             if (!method->is_obsolete() &&
3588                 method->name()->equals(m_name) &&
3589                 method->signature()->equals(m_signature)) {
3590               // The current RedefineClasses() call has made all EMCP
3591               // versions of this method obsolete so mark it as obsolete
3592               RC_TRACE(0x00000400,
3593                 ("add: %s(%s): flush obsolete method @%d in version @%d",
3594                 m_name->as_C_string(), m_signature->as_C_string(), k, j));
3595 
3596               method->set_is_obsolete();
3597               break;
3598             }
3599           }
3600 
3601           // The previous loop may not find a matching EMCP method, but
3602           // that doesn't mean that we can optimize and not go any
3603           // further back in the PreviousVersion generations. The EMCP
3604           // method for this generation could have already been made obsolete,
3605           // but there still may be an older EMCP method that has not
3606           // been made obsolete.
3607         }
3608 
3609         if (++local_count >= obsolete_method_count) {


src/share/vm/oops/instanceKlass.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File