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

src/share/vm/oops/instanceKlass.cpp

Print this page




 269   set_fields(NULL, 0);
 270   set_constants(NULL);
 271   set_class_loader_data(NULL);
 272   set_source_file_name_index(0);
 273   set_source_debug_extension(NULL, 0);
 274   set_array_name(NULL);
 275   set_inner_classes(NULL);
 276   set_static_oop_field_count(0);
 277   set_nonstatic_field_size(0);
 278   set_is_marked_dependent(false);
 279   set_init_state(InstanceKlass::allocated);
 280   set_init_thread(NULL);
 281   set_reference_type(rt);
 282   set_oop_map_cache(NULL);
 283   set_jni_ids(NULL);
 284   set_osr_nmethods_head(NULL);
 285   set_breakpoints(NULL);
 286   init_previous_versions();
 287   set_generic_signature_index(0);
 288   release_set_methods_jmethod_ids(NULL);
 289   release_set_methods_cached_itable_indices(NULL);
 290   set_annotations(NULL);
 291   set_jvmti_cached_class_field_map(NULL);
 292   set_initial_method_idnum(0);
 293   _dependencies = NULL;
 294   set_jvmti_cached_class_field_map(NULL);
 295   set_cached_class_file(NULL);
 296   set_initial_method_idnum(0);
 297   set_minor_version(0);
 298   set_major_version(0);
 299   NOT_PRODUCT(_verify_count = 0;)
 300 
 301   // initialize the non-header words to zero
 302   intptr_t* p = (intptr_t*)this;
 303   for (int index = InstanceKlass::header_size(); index < iksize; index++) {
 304     p[index] = NULL_WORD;
 305   }
 306 
 307   // Set temporary value until parseClassFile updates it with the real instance
 308   // size.
 309   set_layout_helper(Klass::instance_layout_helper(0, true));


1132   InterpreterOopMap* entry_for) {
1133   // Dirty read, then double-check under a lock.
1134   if (_oop_map_cache == NULL) {
1135     // Otherwise, allocate a new one.
1136     MutexLocker x(OopMapCacheAlloc_lock);
1137     // First time use. Allocate a cache in C heap
1138     if (_oop_map_cache == NULL) {
1139       _oop_map_cache = new OopMapCache();
1140     }
1141   }
1142   // _oop_map_cache is constant after init; lookup below does is own locking.
1143   _oop_map_cache->lookup(method, bci, entry_for);
1144 }
1145 
1146 
1147 bool InstanceKlass::find_local_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const {
1148   for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
1149     Symbol* f_name = fs.name();
1150     Symbol* f_sig  = fs.signature();
1151     if (f_name == name && f_sig == sig) {
1152       fd->initialize(const_cast<InstanceKlass*>(this), fs.index());
1153       return true;
1154     }
1155   }
1156   return false;
1157 }
1158 
1159 
1160 Klass* InstanceKlass::find_interface_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const {
1161   const int n = local_interfaces()->length();
1162   for (int i = 0; i < n; i++) {
1163     Klass* intf1 = local_interfaces()->at(i);
1164     assert(intf1->is_interface(), "just checking type");
1165     // search for field in current interface
1166     if (InstanceKlass::cast(intf1)->find_local_field(name, sig, fd)) {
1167       assert(fd->is_static(), "interface field must be static");
1168       return intf1;
1169     }
1170     // search for field in direct superinterfaces
1171     Klass* intf2 = InstanceKlass::cast(intf1)->find_interface_field(name, sig, fd);
1172     if (intf2 != NULL) return intf2;


1201   if (find_local_field(name, sig, fd)) {
1202     if (fd->is_static() == is_static) return const_cast<InstanceKlass*>(this);
1203   }
1204   // 2) search for field recursively in direct superinterfaces
1205   if (is_static) {
1206     Klass* intf = find_interface_field(name, sig, fd);
1207     if (intf != NULL) return intf;
1208   }
1209   // 3) apply field lookup recursively if superclass exists
1210   { Klass* supr = super();
1211     if (supr != NULL) return InstanceKlass::cast(supr)->find_field(name, sig, is_static, fd);
1212   }
1213   // 4) otherwise field lookup fails
1214   return NULL;
1215 }
1216 
1217 
1218 bool InstanceKlass::find_local_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const {
1219   for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
1220     if (fs.offset() == offset) {
1221       fd->initialize(const_cast<InstanceKlass*>(this), fs.index());
1222       if (fd->is_static() == is_static) return true;
1223     }
1224   }
1225   return false;
1226 }
1227 
1228 
1229 bool InstanceKlass::find_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const {
1230   Klass* klass = const_cast<InstanceKlass*>(this);
1231   while (klass != NULL) {
1232     if (InstanceKlass::cast(klass)->find_local_field_from_offset(offset, is_static, fd)) {
1233       return true;
1234     }
1235     klass = klass->super();
1236   }
1237   return false;
1238 }
1239 
1240 
1241 void InstanceKlass::methods_do(void f(Method* method)) {
1242   int len = methods()->length();
1243   for (int index = 0; index < len; index++) {
1244     Method* m = methods()->at(index);
1245     assert(m->is_method(), "must be method");
1246     f(m);
1247   }
1248 }
1249 
1250 
1251 void InstanceKlass::do_local_static_fields(FieldClosure* cl) {
1252   for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
1253     if (fs.access_flags().is_static()) {
1254       fieldDescriptor fd;
1255       fd.initialize(this, fs.index());
1256       cl->do_field(&fd);
1257     }
1258   }
1259 }
1260 
1261 
1262 void InstanceKlass::do_local_static_fields(void f(fieldDescriptor*, TRAPS), TRAPS) {
1263   instanceKlassHandle h_this(THREAD, this);
1264   do_local_static_fields_impl(h_this, f, CHECK);
1265 }
1266 
1267 
1268 void InstanceKlass::do_local_static_fields_impl(instanceKlassHandle this_oop, void f(fieldDescriptor* fd, TRAPS), TRAPS) {
1269   for (JavaFieldStream fs(this_oop()); !fs.done(); fs.next()) {
1270     if (fs.access_flags().is_static()) {
1271       fieldDescriptor fd;
1272       fd.initialize(this_oop(), fs.index());
1273       f(&fd, CHECK);
1274     }
1275   }
1276 }
1277 
1278 
1279 static int compare_fields_by_offset(int* a, int* b) {
1280   return a[0] - b[0];
1281 }
1282 
1283 void InstanceKlass::do_nonstatic_fields(FieldClosure* cl) {
1284   InstanceKlass* super = superklass();
1285   if (super != NULL) {
1286     super->do_nonstatic_fields(cl);
1287   }
1288   fieldDescriptor fd;
1289   int length = java_fields_count();
1290   // In DebugInfo nonstatic fields are sorted by offset.
1291   int* fields_sorted = NEW_C_HEAP_ARRAY(int, 2*(length+1), mtClass);
1292   int j = 0;
1293   for (int i = 0; i < length; i += 1) {
1294     fd.initialize(this, i);
1295     if (!fd.is_static()) {
1296       fields_sorted[j + 0] = fd.offset();
1297       fields_sorted[j + 1] = i;
1298       j += 2;
1299     }
1300   }
1301   if (j > 0) {
1302     length = j;
1303     // _sort_Fn is defined in growableArray.hpp.
1304     qsort(fields_sorted, length/2, 2*sizeof(int), (_sort_Fn)compare_fields_by_offset);
1305     for (int i = 0; i < length; i += 2) {
1306       fd.initialize(this, fields_sorted[i + 1]);
1307       assert(!fd.is_static() && fd.offset() == fields_sorted[i], "only nonstatic fields");
1308       cl->do_field(&fd);
1309     }
1310   }
1311   FREE_C_HEAP_ARRAY(int, fields_sorted, mtClass);
1312 }
1313 
1314 
1315 void InstanceKlass::array_klasses_do(void f(Klass* k, TRAPS), TRAPS) {
1316   if (array_klasses() != NULL)
1317     ArrayKlass::cast(array_klasses())->array_klasses_do(f, THREAD);
1318 }
1319 
1320 void InstanceKlass::array_klasses_do(void f(Klass* k)) {
1321   if (array_klasses() != NULL)
1322     ArrayKlass::cast(array_klasses())->array_klasses_do(f);
1323 }
1324 
1325 #ifdef ASSERT
1326 static int linear_search(Array<Method*>* methods, Symbol* name, Symbol* signature) {


1669   } else {
1670     *id_p = cache[idnum+1];  // fetch jmethodID (if any)
1671   }
1672 }
1673 
1674 
1675 // Lookup a jmethodID, NULL if not found.  Do no blocking, no allocations, no handles
1676 jmethodID InstanceKlass::jmethod_id_or_null(Method* method) {
1677   size_t idnum = (size_t)method->method_idnum();
1678   jmethodID* jmeths = methods_jmethod_ids_acquire();
1679   size_t length;                                // length assigned as debugging crumb
1680   jmethodID id = NULL;
1681   if (jmeths != NULL &&                         // If there is a cache
1682       (length = (size_t)jmeths[0]) > idnum) {   // and if it is long enough,
1683     id = jmeths[idnum+1];                       // Look up the id (may be NULL)
1684   }
1685   return id;
1686 }
1687 
1688 
1689 // Cache an itable index
1690 void InstanceKlass::set_cached_itable_index(size_t idnum, int index) {
1691   int* indices = methods_cached_itable_indices_acquire();
1692   int* to_dealloc_indices = NULL;
1693 
1694   // We use a double-check locking idiom here because this cache is
1695   // performance sensitive. In the normal system, this cache only
1696   // transitions from NULL to non-NULL which is safe because we use
1697   // release_set_methods_cached_itable_indices() to advertise the
1698   // new cache. A partially constructed cache should never be seen
1699   // by a racing thread. Cache reads and writes proceed without a
1700   // lock, but creation of the cache itself requires no leaks so a
1701   // lock is generally acquired in that case.
1702   //
1703   // If the RedefineClasses() API has been used, then this cache can
1704   // grow and we'll have transitions from non-NULL to bigger non-NULL.
1705   // Cache creation requires no leaks and we require safety between all
1706   // cache accesses and freeing of the old cache so a lock is generally
1707   // acquired when the RedefineClasses() API has been used.
1708 
1709   if (indices == NULL || idnum_can_increment()) {
1710     // we need a cache or the cache can grow
1711     MutexLocker ml(JNICachedItableIndex_lock);
1712     // reacquire the cache to see if another thread already did the work
1713     indices = methods_cached_itable_indices_acquire();
1714     size_t length = 0;
1715     // cache size is stored in element[0], other elements offset by one
1716     if (indices == NULL || (length = (size_t)indices[0]) <= idnum) {
1717       size_t size = MAX2(idnum+1, (size_t)idnum_allocated_count());
1718       int* new_indices = NEW_C_HEAP_ARRAY(int, size+1, mtClass);
1719       new_indices[0] = (int)size;
1720       // copy any existing entries
1721       size_t i;
1722       for (i = 0; i < length; i++) {
1723         new_indices[i+1] = indices[i+1];
1724       }
1725       // Set all the rest to -1
1726       for (i = length; i < size; i++) {
1727         new_indices[i+1] = -1;
1728       }
1729       if (indices != NULL) {
1730         // We have an old cache to delete so save it for after we
1731         // drop the lock.
1732         to_dealloc_indices = indices;
1733       }
1734       release_set_methods_cached_itable_indices(indices = new_indices);
1735     }
1736 
1737     if (idnum_can_increment()) {
1738       // this cache can grow so we have to write to it safely
1739       indices[idnum+1] = index;
1740     }
1741   } else {
1742     CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops());
1743   }
1744 
1745   if (!idnum_can_increment()) {
1746     // The cache cannot grow and this JNI itable index value does not
1747     // have to be unique like a jmethodID. If there is a race to set it,
1748     // it doesn't matter.
1749     indices[idnum+1] = index;
1750   }
1751 
1752   if (to_dealloc_indices != NULL) {
1753     // we allocated a new cache so free the old one
1754     FreeHeap(to_dealloc_indices);
1755   }
1756 }
1757 
1758 
1759 // Retrieve a cached itable index
1760 int InstanceKlass::cached_itable_index(size_t idnum) {
1761   int* indices = methods_cached_itable_indices_acquire();
1762   if (indices != NULL && ((size_t)indices[0]) > idnum) {
1763      // indices exist and are long enough, retrieve possible cached
1764     return indices[idnum+1];
1765   }
1766   return -1;
1767 }
1768 
1769 
1770 //
1771 // Walk the list of dependent nmethods searching for nmethods which
1772 // are dependent on the changes that were passed in and mark them for
1773 // deoptimization.  Returns the number of nmethods found.
1774 //
1775 int InstanceKlass::mark_dependent_nmethods(DepChange& changes) {
1776   assert_locked_or_safepoint(CodeCache_lock);
1777   int found = 0;
1778   nmethodBucket* b = _dependencies;
1779   while (b != NULL) {
1780     nmethod* nm = b->get_nmethod();
1781     // since dependencies aren't removed until an nmethod becomes a zombie,
1782     // the dependency list may contain nmethods which aren't alive.
1783     if (nm->is_alive() && !nm->is_marked_for_deoptimization() && nm->check_dependency_on(changes)) {
1784       if (TraceDependencies) {
1785         ResourceMark rm;
1786         tty->print_cr("Marked for deoptimization");
1787         tty->print_cr("  context = %s", this->external_name());
1788         changes.print();
1789         nm->print();


2309   JNIid::deallocate(jni_ids());
2310   set_jni_ids(NULL);
2311 
2312   jmethodID* jmeths = methods_jmethod_ids_acquire();
2313   if (jmeths != (jmethodID*)NULL) {
2314     release_set_methods_jmethod_ids(NULL);
2315     FreeHeap(jmeths);
2316   }
2317 
2318   // Deallocate MemberNameTable
2319   {
2320     Mutex* lock_or_null = SafepointSynchronize::is_at_safepoint() ? NULL : MemberNameTable_lock;
2321     MutexLockerEx ml(lock_or_null, Mutex::_no_safepoint_check_flag);
2322     MemberNameTable* mnt = member_names();
2323     if (mnt != NULL) {
2324       delete mnt;
2325       set_member_names(NULL);
2326     }
2327   }
2328 
2329   int* indices = methods_cached_itable_indices_acquire();
2330   if (indices != (int*)NULL) {
2331     release_set_methods_cached_itable_indices(NULL);
2332     FreeHeap(indices);
2333   }
2334 
2335   // release dependencies
2336   nmethodBucket* b = _dependencies;
2337   _dependencies = NULL;
2338   while (b != NULL) {
2339     nmethodBucket* next = b->next();
2340     delete b;
2341     b = next;
2342   }
2343 
2344   // Deallocate breakpoint records
2345   if (breakpoints() != 0x0) {
2346     methods_do(clear_all_breakpoints);
2347     assert(breakpoints() == 0x0, "should have cleared breakpoints");
2348   }
2349 
2350   // deallocate information about previous versions
2351   if (_previous_versions != NULL) {
2352     for (int i = _previous_versions->length() - 1; i >= 0; i--) {
2353       PreviousVersionNode * pv_node = _previous_versions->at(i);
2354       delete pv_node;


2765   DEBUG_ONLY(No_Safepoint_Verifier nsv);
2766 
2767   if (_member_names == NULL) {
2768     return NULL;
2769   }
2770   oop mem_name =_member_names->get_member_name(index);
2771   return mem_name;
2772 }
2773 
2774 // -----------------------------------------------------------------------------------------------------
2775 // Printing
2776 
2777 #ifndef PRODUCT
2778 
2779 #define BULLET  " - "
2780 
2781 static const char* state_names[] = {
2782   "allocated", "loaded", "linked", "being_initialized", "fully_initialized", "initialization_error"
2783 };
2784 












2785 void InstanceKlass::print_on(outputStream* st) const {
2786   assert(is_klass(), "must be klass");
2787   Klass::print_on(st);
2788 
2789   st->print(BULLET"instance size:     %d", size_helper());                        st->cr();
2790   st->print(BULLET"klass size:        %d", size());                               st->cr();
2791   st->print(BULLET"access:            "); access_flags().print_on(st);            st->cr();
2792   st->print(BULLET"state:             "); st->print_cr(state_names[_init_state]);
2793   st->print(BULLET"name:              "); name()->print_value_on(st);             st->cr();
2794   st->print(BULLET"super:             "); super()->print_value_on_maybe_null(st); st->cr();
2795   st->print(BULLET"sub:               ");
2796   Klass* sub = subklass();
2797   int n;
2798   for (n = 0; sub != NULL; n++, sub = sub->next_sibling()) {
2799     if (n < MaxSubklassPrintSize) {
2800       sub->print_value_on(st);
2801       st->print("   ");
2802     }
2803   }
2804   if (n >= MaxSubklassPrintSize) st->print("(%d more klasses...)", n - MaxSubklassPrintSize);
2805   st->cr();
2806 
2807   if (is_interface()) {
2808     st->print_cr(BULLET"nof implementors:  %d", nof_implementors());
2809     if (nof_implementors() == 1) {
2810       st->print_cr(BULLET"implementor:    ");
2811       st->print("   ");
2812       implementor()->print_value_on(st);
2813       st->cr();
2814     }
2815   }
2816 
2817   st->print(BULLET"arrays:            "); array_klasses()->print_value_on_maybe_null(st); st->cr();
2818   st->print(BULLET"methods:           "); methods()->print_value_on(st);                  st->cr();
2819   if (Verbose) {
2820     Array<Method*>* method_array = methods();
2821     for(int i = 0; i < method_array->length(); i++) {
2822       st->print("%d : ", i); method_array->at(i)->print_value(); st->cr();
2823     }
2824   }
2825   st->print(BULLET"method ordering:   "); method_ordering()->print_value_on(st);       st->cr();
2826   st->print(BULLET"local interfaces:  "); local_interfaces()->print_value_on(st);      st->cr();
2827   st->print(BULLET"trans. interfaces: "); transitive_interfaces()->print_value_on(st); st->cr();
2828   st->print(BULLET"constants:         "); constants()->print_value_on(st);         st->cr();
2829   if (class_loader_data() != NULL) {
2830     st->print(BULLET"class loader data:  ");
2831     class_loader_data()->print_value_on(st);
2832     st->cr();
2833   }
2834   st->print(BULLET"host class:        "); host_klass()->print_value_on_maybe_null(st); st->cr();
2835   if (source_file_name() != NULL) {
2836     st->print(BULLET"source file:       ");
2837     source_file_name()->print_value_on(st);
2838     st->cr();
2839   }


2857       PreviousVersionWalker pvw((InstanceKlass*)this);
2858       for (PreviousVersionInfo * pv_info = pvw.next_previous_version();
2859            pv_info != NULL; pv_info = pvw.next_previous_version()) {
2860         if (!have_pv)
2861           st->print(BULLET"previous version:  ");
2862         have_pv = true;
2863         pv_info->prev_constant_pool_handle()()->print_value_on(st);
2864       }
2865       if (have_pv)  st->cr();
2866     } // pvw is cleaned up
2867   } // rm is cleaned up
2868 
2869   if (generic_signature() != NULL) {
2870     st->print(BULLET"generic signature: ");
2871     generic_signature()->print_value_on(st);
2872     st->cr();
2873   }
2874   st->print(BULLET"inner classes:     "); inner_classes()->print_value_on(st);     st->cr();
2875   st->print(BULLET"java mirror:       "); java_mirror()->print_value_on(st);       st->cr();
2876   st->print(BULLET"vtable length      %d  (start addr: " INTPTR_FORMAT ")", vtable_length(), start_of_vtable());  st->cr();

2877   st->print(BULLET"itable length      %d (start addr: " INTPTR_FORMAT ")", itable_length(), start_of_itable()); st->cr();

2878   st->print_cr(BULLET"---- static fields (%d words):", static_field_size());
2879   FieldPrinter print_static_field(st);
2880   ((InstanceKlass*)this)->do_local_static_fields(&print_static_field);
2881   st->print_cr(BULLET"---- non-static fields (%d words):", nonstatic_field_size());
2882   FieldPrinter print_nonstatic_field(st);
2883   ((InstanceKlass*)this)->do_nonstatic_fields(&print_nonstatic_field);
2884 
2885   st->print(BULLET"non-static oop maps: ");
2886   OopMapBlock* map     = start_of_nonstatic_oop_maps();
2887   OopMapBlock* end_map = map + nonstatic_oop_map_count();
2888   while (map < end_map) {
2889     st->print("%d-%d ", map->offset(), map->offset() + heapOopSize*(map->count() - 1));
2890     map++;
2891   }
2892   st->cr();
2893 }
2894 
2895 #endif //PRODUCT
2896 
2897 void InstanceKlass::print_value_on(outputStream* st) const {
2898   assert(is_klass(), "must be klass");

2899   name()->print_value_on(st);
2900 }
2901 
2902 #ifndef PRODUCT
2903 
2904 void FieldPrinter::do_field(fieldDescriptor* fd) {
2905   _st->print(BULLET);
2906    if (_obj == NULL) {
2907      fd->print_on(_st);
2908      _st->cr();
2909    } else {
2910      fd->print_on_for(_st, _obj);
2911      _st->cr();
2912    }
2913 }
2914 
2915 
2916 void InstanceKlass::oop_print_on(oop obj, outputStream* st) {
2917   Klass::oop_print_on(obj, st);
2918 




 269   set_fields(NULL, 0);
 270   set_constants(NULL);
 271   set_class_loader_data(NULL);
 272   set_source_file_name_index(0);
 273   set_source_debug_extension(NULL, 0);
 274   set_array_name(NULL);
 275   set_inner_classes(NULL);
 276   set_static_oop_field_count(0);
 277   set_nonstatic_field_size(0);
 278   set_is_marked_dependent(false);
 279   set_init_state(InstanceKlass::allocated);
 280   set_init_thread(NULL);
 281   set_reference_type(rt);
 282   set_oop_map_cache(NULL);
 283   set_jni_ids(NULL);
 284   set_osr_nmethods_head(NULL);
 285   set_breakpoints(NULL);
 286   init_previous_versions();
 287   set_generic_signature_index(0);
 288   release_set_methods_jmethod_ids(NULL);

 289   set_annotations(NULL);
 290   set_jvmti_cached_class_field_map(NULL);
 291   set_initial_method_idnum(0);
 292   _dependencies = NULL;
 293   set_jvmti_cached_class_field_map(NULL);
 294   set_cached_class_file(NULL);
 295   set_initial_method_idnum(0);
 296   set_minor_version(0);
 297   set_major_version(0);
 298   NOT_PRODUCT(_verify_count = 0;)
 299 
 300   // initialize the non-header words to zero
 301   intptr_t* p = (intptr_t*)this;
 302   for (int index = InstanceKlass::header_size(); index < iksize; index++) {
 303     p[index] = NULL_WORD;
 304   }
 305 
 306   // Set temporary value until parseClassFile updates it with the real instance
 307   // size.
 308   set_layout_helper(Klass::instance_layout_helper(0, true));


1131   InterpreterOopMap* entry_for) {
1132   // Dirty read, then double-check under a lock.
1133   if (_oop_map_cache == NULL) {
1134     // Otherwise, allocate a new one.
1135     MutexLocker x(OopMapCacheAlloc_lock);
1136     // First time use. Allocate a cache in C heap
1137     if (_oop_map_cache == NULL) {
1138       _oop_map_cache = new OopMapCache();
1139     }
1140   }
1141   // _oop_map_cache is constant after init; lookup below does is own locking.
1142   _oop_map_cache->lookup(method, bci, entry_for);
1143 }
1144 
1145 
1146 bool InstanceKlass::find_local_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const {
1147   for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
1148     Symbol* f_name = fs.name();
1149     Symbol* f_sig  = fs.signature();
1150     if (f_name == name && f_sig == sig) {
1151       fd->reinitialize(const_cast<InstanceKlass*>(this), fs.index());
1152       return true;
1153     }
1154   }
1155   return false;
1156 }
1157 
1158 
1159 Klass* InstanceKlass::find_interface_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const {
1160   const int n = local_interfaces()->length();
1161   for (int i = 0; i < n; i++) {
1162     Klass* intf1 = local_interfaces()->at(i);
1163     assert(intf1->is_interface(), "just checking type");
1164     // search for field in current interface
1165     if (InstanceKlass::cast(intf1)->find_local_field(name, sig, fd)) {
1166       assert(fd->is_static(), "interface field must be static");
1167       return intf1;
1168     }
1169     // search for field in direct superinterfaces
1170     Klass* intf2 = InstanceKlass::cast(intf1)->find_interface_field(name, sig, fd);
1171     if (intf2 != NULL) return intf2;


1200   if (find_local_field(name, sig, fd)) {
1201     if (fd->is_static() == is_static) return const_cast<InstanceKlass*>(this);
1202   }
1203   // 2) search for field recursively in direct superinterfaces
1204   if (is_static) {
1205     Klass* intf = find_interface_field(name, sig, fd);
1206     if (intf != NULL) return intf;
1207   }
1208   // 3) apply field lookup recursively if superclass exists
1209   { Klass* supr = super();
1210     if (supr != NULL) return InstanceKlass::cast(supr)->find_field(name, sig, is_static, fd);
1211   }
1212   // 4) otherwise field lookup fails
1213   return NULL;
1214 }
1215 
1216 
1217 bool InstanceKlass::find_local_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const {
1218   for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
1219     if (fs.offset() == offset) {
1220       fd->reinitialize(const_cast<InstanceKlass*>(this), fs.index());
1221       if (fd->is_static() == is_static) return true;
1222     }
1223   }
1224   return false;
1225 }
1226 
1227 
1228 bool InstanceKlass::find_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const {
1229   Klass* klass = const_cast<InstanceKlass*>(this);
1230   while (klass != NULL) {
1231     if (InstanceKlass::cast(klass)->find_local_field_from_offset(offset, is_static, fd)) {
1232       return true;
1233     }
1234     klass = klass->super();
1235   }
1236   return false;
1237 }
1238 
1239 
1240 void InstanceKlass::methods_do(void f(Method* method)) {
1241   int len = methods()->length();
1242   for (int index = 0; index < len; index++) {
1243     Method* m = methods()->at(index);
1244     assert(m->is_method(), "must be method");
1245     f(m);
1246   }
1247 }
1248 
1249 
1250 void InstanceKlass::do_local_static_fields(FieldClosure* cl) {
1251   for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
1252     if (fs.access_flags().is_static()) {
1253       fieldDescriptor& fd = fs.field_descriptor();

1254       cl->do_field(&fd);
1255     }
1256   }
1257 }
1258 
1259 
1260 void InstanceKlass::do_local_static_fields(void f(fieldDescriptor*, TRAPS), TRAPS) {
1261   instanceKlassHandle h_this(THREAD, this);
1262   do_local_static_fields_impl(h_this, f, CHECK);
1263 }
1264 
1265 
1266 void InstanceKlass::do_local_static_fields_impl(instanceKlassHandle this_oop, void f(fieldDescriptor* fd, TRAPS), TRAPS) {
1267   for (JavaFieldStream fs(this_oop()); !fs.done(); fs.next()) {
1268     if (fs.access_flags().is_static()) {
1269       fieldDescriptor& fd = fs.field_descriptor();

1270       f(&fd, CHECK);
1271     }
1272   }
1273 }
1274 
1275 
1276 static int compare_fields_by_offset(int* a, int* b) {
1277   return a[0] - b[0];
1278 }
1279 
1280 void InstanceKlass::do_nonstatic_fields(FieldClosure* cl) {
1281   InstanceKlass* super = superklass();
1282   if (super != NULL) {
1283     super->do_nonstatic_fields(cl);
1284   }
1285   fieldDescriptor fd;
1286   int length = java_fields_count();
1287   // In DebugInfo nonstatic fields are sorted by offset.
1288   int* fields_sorted = NEW_C_HEAP_ARRAY(int, 2*(length+1), mtClass);
1289   int j = 0;
1290   for (int i = 0; i < length; i += 1) {
1291     fd.reinitialize(this, i);
1292     if (!fd.is_static()) {
1293       fields_sorted[j + 0] = fd.offset();
1294       fields_sorted[j + 1] = i;
1295       j += 2;
1296     }
1297   }
1298   if (j > 0) {
1299     length = j;
1300     // _sort_Fn is defined in growableArray.hpp.
1301     qsort(fields_sorted, length/2, 2*sizeof(int), (_sort_Fn)compare_fields_by_offset);
1302     for (int i = 0; i < length; i += 2) {
1303       fd.reinitialize(this, fields_sorted[i + 1]);
1304       assert(!fd.is_static() && fd.offset() == fields_sorted[i], "only nonstatic fields");
1305       cl->do_field(&fd);
1306     }
1307   }
1308   FREE_C_HEAP_ARRAY(int, fields_sorted, mtClass);
1309 }
1310 
1311 
1312 void InstanceKlass::array_klasses_do(void f(Klass* k, TRAPS), TRAPS) {
1313   if (array_klasses() != NULL)
1314     ArrayKlass::cast(array_klasses())->array_klasses_do(f, THREAD);
1315 }
1316 
1317 void InstanceKlass::array_klasses_do(void f(Klass* k)) {
1318   if (array_klasses() != NULL)
1319     ArrayKlass::cast(array_klasses())->array_klasses_do(f);
1320 }
1321 
1322 #ifdef ASSERT
1323 static int linear_search(Array<Method*>* methods, Symbol* name, Symbol* signature) {


1666   } else {
1667     *id_p = cache[idnum+1];  // fetch jmethodID (if any)
1668   }
1669 }
1670 
1671 
1672 // Lookup a jmethodID, NULL if not found.  Do no blocking, no allocations, no handles
1673 jmethodID InstanceKlass::jmethod_id_or_null(Method* method) {
1674   size_t idnum = (size_t)method->method_idnum();
1675   jmethodID* jmeths = methods_jmethod_ids_acquire();
1676   size_t length;                                // length assigned as debugging crumb
1677   jmethodID id = NULL;
1678   if (jmeths != NULL &&                         // If there is a cache
1679       (length = (size_t)jmeths[0]) > idnum) {   // and if it is long enough,
1680     id = jmeths[idnum+1];                       // Look up the id (may be NULL)
1681   }
1682   return id;
1683 }
1684 
1685 

















































































1686 //
1687 // Walk the list of dependent nmethods searching for nmethods which
1688 // are dependent on the changes that were passed in and mark them for
1689 // deoptimization.  Returns the number of nmethods found.
1690 //
1691 int InstanceKlass::mark_dependent_nmethods(DepChange& changes) {
1692   assert_locked_or_safepoint(CodeCache_lock);
1693   int found = 0;
1694   nmethodBucket* b = _dependencies;
1695   while (b != NULL) {
1696     nmethod* nm = b->get_nmethod();
1697     // since dependencies aren't removed until an nmethod becomes a zombie,
1698     // the dependency list may contain nmethods which aren't alive.
1699     if (nm->is_alive() && !nm->is_marked_for_deoptimization() && nm->check_dependency_on(changes)) {
1700       if (TraceDependencies) {
1701         ResourceMark rm;
1702         tty->print_cr("Marked for deoptimization");
1703         tty->print_cr("  context = %s", this->external_name());
1704         changes.print();
1705         nm->print();


2225   JNIid::deallocate(jni_ids());
2226   set_jni_ids(NULL);
2227 
2228   jmethodID* jmeths = methods_jmethod_ids_acquire();
2229   if (jmeths != (jmethodID*)NULL) {
2230     release_set_methods_jmethod_ids(NULL);
2231     FreeHeap(jmeths);
2232   }
2233 
2234   // Deallocate MemberNameTable
2235   {
2236     Mutex* lock_or_null = SafepointSynchronize::is_at_safepoint() ? NULL : MemberNameTable_lock;
2237     MutexLockerEx ml(lock_or_null, Mutex::_no_safepoint_check_flag);
2238     MemberNameTable* mnt = member_names();
2239     if (mnt != NULL) {
2240       delete mnt;
2241       set_member_names(NULL);
2242     }
2243   }
2244 






2245   // release dependencies
2246   nmethodBucket* b = _dependencies;
2247   _dependencies = NULL;
2248   while (b != NULL) {
2249     nmethodBucket* next = b->next();
2250     delete b;
2251     b = next;
2252   }
2253 
2254   // Deallocate breakpoint records
2255   if (breakpoints() != 0x0) {
2256     methods_do(clear_all_breakpoints);
2257     assert(breakpoints() == 0x0, "should have cleared breakpoints");
2258   }
2259 
2260   // deallocate information about previous versions
2261   if (_previous_versions != NULL) {
2262     for (int i = _previous_versions->length() - 1; i >= 0; i--) {
2263       PreviousVersionNode * pv_node = _previous_versions->at(i);
2264       delete pv_node;


2675   DEBUG_ONLY(No_Safepoint_Verifier nsv);
2676 
2677   if (_member_names == NULL) {
2678     return NULL;
2679   }
2680   oop mem_name =_member_names->get_member_name(index);
2681   return mem_name;
2682 }
2683 
2684 // -----------------------------------------------------------------------------------------------------
2685 // Printing
2686 
2687 #ifndef PRODUCT
2688 
2689 #define BULLET  " - "
2690 
2691 static const char* state_names[] = {
2692   "allocated", "loaded", "linked", "being_initialized", "fully_initialized", "initialization_error"
2693 };
2694 
2695 static void print_vtable(intptr_t* start, int len, outputStream* st) {
2696   for (int i = 0; i < len; i++) {
2697     intptr_t e = start[i];
2698     st->print("%d : " INTPTR_FORMAT, i, e);
2699     if (e != 0 && ((Metadata*)e)->is_metaspace_object()) {
2700       st->print(" ");
2701       ((Metadata*)e)->print_value_on(st);
2702     }
2703     st->cr();
2704   }
2705 }
2706 
2707 void InstanceKlass::print_on(outputStream* st) const {
2708   assert(is_klass(), "must be klass");
2709   Klass::print_on(st);
2710 
2711   st->print(BULLET"instance size:     %d", size_helper());                        st->cr();
2712   st->print(BULLET"klass size:        %d", size());                               st->cr();
2713   st->print(BULLET"access:            "); access_flags().print_on(st);            st->cr();
2714   st->print(BULLET"state:             "); st->print_cr(state_names[_init_state]);
2715   st->print(BULLET"name:              "); name()->print_value_on(st);             st->cr();
2716   st->print(BULLET"super:             "); super()->print_value_on_maybe_null(st); st->cr();
2717   st->print(BULLET"sub:               ");
2718   Klass* sub = subklass();
2719   int n;
2720   for (n = 0; sub != NULL; n++, sub = sub->next_sibling()) {
2721     if (n < MaxSubklassPrintSize) {
2722       sub->print_value_on(st);
2723       st->print("   ");
2724     }
2725   }
2726   if (n >= MaxSubklassPrintSize) st->print("(%d more klasses...)", n - MaxSubklassPrintSize);
2727   st->cr();
2728 
2729   if (is_interface()) {
2730     st->print_cr(BULLET"nof implementors:  %d", nof_implementors());
2731     if (nof_implementors() == 1) {
2732       st->print_cr(BULLET"implementor:    ");
2733       st->print("   ");
2734       implementor()->print_value_on(st);
2735       st->cr();
2736     }
2737   }
2738 
2739   st->print(BULLET"arrays:            "); array_klasses()->print_value_on_maybe_null(st); st->cr();
2740   st->print(BULLET"methods:           "); methods()->print_value_on(st);                  st->cr();
2741   if (Verbose || WizardMode) {
2742     Array<Method*>* method_array = methods();
2743     for(int i = 0; i < method_array->length(); i++) {
2744       st->print("%d : ", i); method_array->at(i)->print_value(); st->cr();
2745     }
2746   }
2747   st->print(BULLET"method ordering:   "); method_ordering()->print_value_on(st);       st->cr();
2748   st->print(BULLET"local interfaces:  "); local_interfaces()->print_value_on(st);      st->cr();
2749   st->print(BULLET"trans. interfaces: "); transitive_interfaces()->print_value_on(st); st->cr();
2750   st->print(BULLET"constants:         "); constants()->print_value_on(st);         st->cr();
2751   if (class_loader_data() != NULL) {
2752     st->print(BULLET"class loader data:  ");
2753     class_loader_data()->print_value_on(st);
2754     st->cr();
2755   }
2756   st->print(BULLET"host class:        "); host_klass()->print_value_on_maybe_null(st); st->cr();
2757   if (source_file_name() != NULL) {
2758     st->print(BULLET"source file:       ");
2759     source_file_name()->print_value_on(st);
2760     st->cr();
2761   }


2779       PreviousVersionWalker pvw((InstanceKlass*)this);
2780       for (PreviousVersionInfo * pv_info = pvw.next_previous_version();
2781            pv_info != NULL; pv_info = pvw.next_previous_version()) {
2782         if (!have_pv)
2783           st->print(BULLET"previous version:  ");
2784         have_pv = true;
2785         pv_info->prev_constant_pool_handle()()->print_value_on(st);
2786       }
2787       if (have_pv)  st->cr();
2788     } // pvw is cleaned up
2789   } // rm is cleaned up
2790 
2791   if (generic_signature() != NULL) {
2792     st->print(BULLET"generic signature: ");
2793     generic_signature()->print_value_on(st);
2794     st->cr();
2795   }
2796   st->print(BULLET"inner classes:     "); inner_classes()->print_value_on(st);     st->cr();
2797   st->print(BULLET"java mirror:       "); java_mirror()->print_value_on(st);       st->cr();
2798   st->print(BULLET"vtable length      %d  (start addr: " INTPTR_FORMAT ")", vtable_length(), start_of_vtable());  st->cr();
2799   if (vtable_length() > 0 && (Verbose || WizardMode))  print_vtable(start_of_vtable(), vtable_length(), st);
2800   st->print(BULLET"itable length      %d (start addr: " INTPTR_FORMAT ")", itable_length(), start_of_itable()); st->cr();
2801   if (itable_length() > 0 && (Verbose || WizardMode))  print_vtable(start_of_itable(), itable_length(), st);
2802   st->print_cr(BULLET"---- static fields (%d words):", static_field_size());
2803   FieldPrinter print_static_field(st);
2804   ((InstanceKlass*)this)->do_local_static_fields(&print_static_field);
2805   st->print_cr(BULLET"---- non-static fields (%d words):", nonstatic_field_size());
2806   FieldPrinter print_nonstatic_field(st);
2807   ((InstanceKlass*)this)->do_nonstatic_fields(&print_nonstatic_field);
2808 
2809   st->print(BULLET"non-static oop maps: ");
2810   OopMapBlock* map     = start_of_nonstatic_oop_maps();
2811   OopMapBlock* end_map = map + nonstatic_oop_map_count();
2812   while (map < end_map) {
2813     st->print("%d-%d ", map->offset(), map->offset() + heapOopSize*(map->count() - 1));
2814     map++;
2815   }
2816   st->cr();
2817 }
2818 
2819 #endif //PRODUCT
2820 
2821 void InstanceKlass::print_value_on(outputStream* st) const {
2822   assert(is_klass(), "must be klass");
2823   if (Verbose || WizardMode)  access_flags().print_on(st);
2824   name()->print_value_on(st);
2825 }
2826 
2827 #ifndef PRODUCT
2828 
2829 void FieldPrinter::do_field(fieldDescriptor* fd) {
2830   _st->print(BULLET);
2831    if (_obj == NULL) {
2832      fd->print_on(_st);
2833      _st->cr();
2834    } else {
2835      fd->print_on_for(_st, _obj);
2836      _st->cr();
2837    }
2838 }
2839 
2840 
2841 void InstanceKlass::oop_print_on(oop obj, outputStream* st) {
2842   Klass::oop_print_on(obj, st);
2843 


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