src/share/vm/code/dependencies.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Sdiff src/share/vm/code

src/share/vm/code/dependencies.cpp

Print this page




1112   // Now we must check each implementor and each subclass.
1113   // Use a short worklist to avoid blowing the stack.
1114   // Each worklist entry is a *chain* of subklass siblings to process.
1115   const int CHAINMAX = 100;  // >= 1 + InstanceKlass::implementors_limit
1116   Klass* chains[CHAINMAX];
1117   int    chaini = 0;  // index into worklist
1118   Klass* chain;       // scratch variable
1119 #define ADD_SUBCLASS_CHAIN(k)                     {  \
1120     assert(chaini < CHAINMAX, "oob");                \
1121     chain = InstanceKlass::cast(k)->subklass();      \
1122     if (chain != NULL)  chains[chaini++] = chain;    }
1123 
1124   // Look for non-abstract subclasses.
1125   // (Note:  Interfaces do not have subclasses.)
1126   ADD_SUBCLASS_CHAIN(context_type);
1127 
1128   // If it is an interface, search its direct implementors.
1129   // (Their subclasses are additional indirect implementors.
1130   // See InstanceKlass::add_implementor.)
1131   // (Note:  nof_implementors is always zero for non-interfaces.)

1132   int nof_impls = InstanceKlass::cast(context_type)->nof_implementors();
1133   if (nof_impls > 1) {
1134     // Avoid this case: *I.m > { A.m, C }; B.m > C
1135     // Here, I.m has 2 concrete implementations, but m appears unique
1136     // as A.m, because the search misses B.m when checking C.
1137     // The inherited method B.m was getting missed by the walker
1138     // when interface 'I' was the starting point.
1139     // %%% Until this is fixed more systematically, bail out.
1140     // (Old CHA had the same limitation.)
1141     return context_type;
1142   }
1143   if (nof_impls > 0) {
1144     Klass* impl = InstanceKlass::cast(context_type)->implementor();
1145     assert(impl != NULL, "just checking");
1146     // If impl is the same as the context_type, then more than one
1147     // implementor has seen. No exact info in this case.
1148     if (impl == context_type) {
1149       return context_type;  // report an inexact witness to this sad affair
1150     }
1151     if (do_counts)
1152       { NOT_PRODUCT(deps_find_witness_steps++); }
1153     if (is_participant(impl)) {
1154       if (!participants_hide_witnesses) {
1155         ADD_SUBCLASS_CHAIN(impl);
1156       }
1157     } else if (is_witness(impl) && !ignore_witness(impl)) {
1158       return impl;
1159     } else {
1160       ADD_SUBCLASS_CHAIN(impl);
1161     }
1162   }

1163 
1164   // Recursively process each non-trivial sibling chain.
1165   while (chaini > 0) {
1166     Klass* chain = chains[--chaini];
1167     for (Klass* sub = chain; sub != NULL; sub = sub->next_sibling()) {
1168       if (do_counts) { NOT_PRODUCT(deps_find_witness_steps++); }





1169       if (is_participant(sub)) {
1170         if (participants_hide_witnesses)  continue;
1171         // else fall through to process this guy's subclasses
1172       } else if (is_witness(sub) && !ignore_witness(sub)) {
1173         return sub;
1174       }
1175       if (chaini < (VerifyDependencies? 2: CHAINMAX)) {
1176         // Fast path.  (Partially disabled if VerifyDependencies.)
1177         ADD_SUBCLASS_CHAIN(sub);
1178       } else {
1179         // Worklist overflow.  Do a recursive call.  Should be rare.
1180         // The recursive call will have its own worklist, of course.
1181         // (Note that sub has already been tested, so that there is
1182         // no need for the recursive call to re-test.  That's handy,
1183         // since the recursive call sees sub as the context_type.)
1184         if (do_counts) { NOT_PRODUCT(deps_find_witness_recursions++); }
1185         Klass* witness = find_witness_anywhere(sub,
1186                                                  participants_hide_witnesses,
1187                                                  /*top_level_call=*/ false);
1188         if (witness != NULL)  return witness;




1112   // Now we must check each implementor and each subclass.
1113   // Use a short worklist to avoid blowing the stack.
1114   // Each worklist entry is a *chain* of subklass siblings to process.
1115   const int CHAINMAX = 100;  // >= 1 + InstanceKlass::implementors_limit
1116   Klass* chains[CHAINMAX];
1117   int    chaini = 0;  // index into worklist
1118   Klass* chain;       // scratch variable
1119 #define ADD_SUBCLASS_CHAIN(k)                     {  \
1120     assert(chaini < CHAINMAX, "oob");                \
1121     chain = InstanceKlass::cast(k)->subklass();      \
1122     if (chain != NULL)  chains[chaini++] = chain;    }
1123 
1124   // Look for non-abstract subclasses.
1125   // (Note:  Interfaces do not have subclasses.)
1126   ADD_SUBCLASS_CHAIN(context_type);
1127 
1128   // If it is an interface, search its direct implementors.
1129   // (Their subclasses are additional indirect implementors.
1130   // See InstanceKlass::add_implementor.)
1131   // (Note:  nof_implementors is always zero for non-interfaces.)
1132   if (top_level_call) {
1133     int nof_impls = InstanceKlass::cast(context_type)->nof_implementors();
1134     if (nof_impls > 1) {
1135       // Avoid this case: *I.m > { A.m, C }; B.m > C
1136       // Here, I.m has 2 concrete implementations, but m appears unique
1137       // as A.m, because the search misses B.m when checking C.
1138       // The inherited method B.m was getting missed by the walker
1139       // when interface 'I' was the starting point.
1140       // %%% Until this is fixed more systematically, bail out.
1141       // (Old CHA had the same limitation.)
1142       return context_type;
1143     }
1144     if (nof_impls > 0) {
1145       Klass* impl = InstanceKlass::cast(context_type)->implementor();
1146       assert(impl != NULL, "just checking");
1147       // If impl is the same as the context_type, then more than one
1148       // implementor has seen. No exact info in this case.
1149       if (impl == context_type) {
1150         return context_type;  // report an inexact witness to this sad affair
1151       }
1152       if (do_counts)
1153         { NOT_PRODUCT(deps_find_witness_steps++); }
1154       if (is_participant(impl)) {
1155         if (!participants_hide_witnesses) {
1156           ADD_SUBCLASS_CHAIN(impl);
1157         }
1158       } else if (is_witness(impl) && !ignore_witness(impl)) {
1159         return impl;
1160       } else {
1161         ADD_SUBCLASS_CHAIN(impl);
1162       }
1163     }
1164   }
1165 
1166   // Recursively process each non-trivial sibling chain.
1167   while (chaini > 0) {
1168     Klass* chain = chains[--chaini];
1169     for (Klass* sub = chain; sub != NULL; sub = sub->next_sibling()) {
1170       if (do_counts) { NOT_PRODUCT(deps_find_witness_steps++); }
1171       if (!sub->oop_is_instance()) {
1172         // This may happen for Klass java.lang.Object because it is a superclass
1173         // of all other Klasses including non-instance Klasses like ObjArrayKlass.
1174         continue;
1175       }
1176       if (is_participant(sub)) {
1177         if (participants_hide_witnesses)  continue;
1178         // else fall through to process this guy's subclasses
1179       } else if (is_witness(sub) && !ignore_witness(sub)) {
1180         return sub;
1181       }
1182       if (chaini < (VerifyDependencies? 2: CHAINMAX)) {
1183         // Fast path.  (Partially disabled if VerifyDependencies.)
1184         ADD_SUBCLASS_CHAIN(sub);
1185       } else {
1186         // Worklist overflow.  Do a recursive call.  Should be rare.
1187         // The recursive call will have its own worklist, of course.
1188         // (Note that sub has already been tested, so that there is
1189         // no need for the recursive call to re-test.  That's handy,
1190         // since the recursive call sees sub as the context_type.)
1191         if (do_counts) { NOT_PRODUCT(deps_find_witness_recursions++); }
1192         Klass* witness = find_witness_anywhere(sub,
1193                                                  participants_hide_witnesses,
1194                                                  /*top_level_call=*/ false);
1195         if (witness != NULL)  return witness;


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