8185590: ShouldNotReachHere from ClassLoaderData::try_get_next_class()
authorcoleenp
Tue, 01 Aug 2017 17:36:38 -0400
changeset 46739 89569d6a77c0
parent 46734 e77c53775f4e
child 46740 0f11e65a02bf
8185590: ShouldNotReachHere from ClassLoaderData::try_get_next_class() Summary: Counting number of instanceKlass code didn't work. Reviewed-by: shade, zgu, jiangli
hotspot/src/share/vm/classfile/classLoaderData.cpp
hotspot/src/share/vm/runtime/compilationPolicy.cpp
--- a/hotspot/src/share/vm/classfile/classLoaderData.cpp	Tue Aug 01 08:53:32 2017 -0700
+++ b/hotspot/src/share/vm/classfile/classLoaderData.cpp	Tue Aug 01 17:36:38 2017 -0400
@@ -469,7 +469,8 @@
   InstanceKlass* try_get_next_class() {
     assert(SafepointSynchronize::is_at_safepoint(), "only called at safepoint");
     int max_classes = InstanceKlass::number_of_instance_classes();
-    for (int i = 0; i < max_classes; i++) {
+    assert(max_classes > 0, "should not be called with no instance classes");
+    for (int i = 0; i < max_classes; ) {
 
       if (_current_class_entry != NULL) {
         Klass* k = _current_class_entry;
@@ -477,7 +478,9 @@
 
         if (k->is_instance_klass()) {
           InstanceKlass* ik = InstanceKlass::cast(k);
-          // Only return loaded classes
+          i++;  // count all instance classes found
+          // Not yet loaded classes are counted in max_classes
+          // but only return loaded classes.
           if (ik->is_loaded()) {
             return ik;
           }
@@ -495,9 +498,9 @@
         _current_class_entry = _current_loader_data->klasses();
       }
     }
-    // should never be reached: an InstanceKlass should be returned above
-    ShouldNotReachHere();
-    return NULL;   // Object_klass not even loaded?
+    // Should never be reached unless all instance classes have failed or are not fully loaded.
+    // Caller handles NULL.
+    return NULL;
   }
 
   // If the current class for the static iterator is a class being unloaded or
--- a/hotspot/src/share/vm/runtime/compilationPolicy.cpp	Tue Aug 01 08:53:32 2017 -0700
+++ b/hotspot/src/share/vm/runtime/compilationPolicy.cpp	Tue Aug 01 17:36:38 2017 -0400
@@ -313,7 +313,7 @@
   // at this point and hence SystemDictionary_lock is also not needed.
   assert(SafepointSynchronize::is_at_safepoint(), "can only be executed at a safepoint");
   int nclasses = InstanceKlass::number_of_instance_classes();
-  double classes_per_tick = nclasses * (CounterDecayMinIntervalLength * 1e-3 /
+  int classes_per_tick = nclasses * (CounterDecayMinIntervalLength * 1e-3 /
                                         CounterHalfLifeTime);
   for (int i = 0; i < classes_per_tick; i++) {
     InstanceKlass* k = ClassLoaderDataGraph::try_get_next_class();