changeset 59291:0b032112c89e nestmates

8241252: Cleanup nest related logging Reviewed-by: coleenp, hseigel
author dholmes
date Mon, 23 Mar 2020 18:26:01 -0400
parents 130434292f7a
children a13281715852
files src/hotspot/share/oops/instanceKlass.cpp src/hotspot/share/prims/jvm.cpp
diffstat 2 files changed, 39 insertions(+), 79 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/oops/instanceKlass.cpp	Mon Mar 23 20:05:49 2020 +0000
+++ b/src/hotspot/share/oops/instanceKlass.cpp	Mon Mar 23 18:26:01 2020 -0400
@@ -236,33 +236,26 @@
     return nest_host_k;
   }
 
-  const bool doLog = log_is_enabled(Trace, class, nestmates);
+  ResourceMark rm(THREAD);
 
   // need to resolve and save our nest-host class.
   if (_nest_host_index != 0) { // we have a real nest_host
     // Before trying to resolve check if we're in a suitable context
     if (!THREAD->can_call_java() && !_constants->tag_at(_nest_host_index).is_klass()) {
-      if (doLog) {
-        ResourceMark rm(THREAD);
-        log_trace(class, nestmates)("Rejected resolution of nest-host of %s in unsuitable thread",
-                                    this->external_name());
-      }
+      log_trace(class, nestmates)("Rejected resolution of nest-host of %s in unsuitable thread",
+                                  this->external_name());
       return NULL; // sentinel to say "try again from a different context"
     }
 
-    if (doLog) {
-      ResourceMark rm(THREAD);
-      log_trace(class, nestmates)("Resolving nest-host of %s using cp entry for %s",
-                                  this->external_name(),
-                                  _constants->klass_name_at(_nest_host_index)->as_C_string());
-    }
+    log_trace(class, nestmates)("Resolving nest-host of %s using cp entry for %s",
+                                this->external_name(),
+                                _constants->klass_name_at(_nest_host_index)->as_C_string());
 
     Klass* k = _constants->klass_at(_nest_host_index, THREAD);
     if (HAS_PENDING_EXCEPTION) {
       if (PENDING_EXCEPTION->is_a(SystemDictionary::VirtualMachineError_klass())) {
         return NULL; // propagate VMEs
       }
-      ResourceMark rm(THREAD);
       stringStream ss;
       char* target_host_class = _constants->klass_name_at(_nest_host_index)->as_C_string();
       ss.print("Nest host resolution of %s with host %s failed: ",
@@ -272,9 +265,8 @@
       // ensure we see _nest_host_res_error is set if _nest_host is non-NULL
       OrderAccess::storestore();
       CLEAR_PENDING_EXCEPTION;
-      if (doLog) {
-        log_trace(class, nestmates)("%s", _nest_host_res_error);
-      }
+
+      log_trace(class, nestmates)("%s", _nest_host_res_error);
     } else {
       // A valid nest-host is an instance class in the current package that lists this
       // class as a nest member. If any of these conditions are not met the class is
@@ -292,11 +284,9 @@
           if (!HAS_PENDING_EXCEPTION) {
             if (is_member) {
               _nest_host = nest_host_k; // save resolved nest-host value
-              if (doLog) {
-                ResourceMark rm(THREAD);
-                log_trace(class, nestmates)("Resolved nest-host of %s to %s",
-                                            this->external_name(), k->external_name());
-              }
+
+              log_trace(class, nestmates)("Resolved nest-host of %s to %s",
+                                          this->external_name(), k->external_name());
               return nest_host_k;
             } else {
               error = "current type is not listed as a nest member";
@@ -319,7 +309,6 @@
 
       // something went wrong, so record what and log it
       {
-        ResourceMark rm(THREAD);
         stringStream ss;
         ss.print("Type %s (loader: %s) is not a nest member of type %s (loader: %s): %s",
                  this->external_name(),
@@ -331,17 +320,12 @@
         // ensure we see _nest_host_res_error is set if _nest_host is non-NULL
         OrderAccess::storestore();
 
-        if (doLog) {
-          log_trace(class, nestmates)("%s", _nest_host_res_error);
-        }
+        log_trace(class, nestmates)("%s", _nest_host_res_error);
       }
     }
   } else {
-    if (doLog) {
-      ResourceMark rm(THREAD);
-      log_trace(class, nestmates)("Type %s is not part of a nest: setting nest-host to self",
-                                  this->external_name());
-    }
+    log_trace(class, nestmates)("Type %s is not part of a nest: setting nest-host to self",
+                                this->external_name());
   }
 
   // Either not in an explicit nest, or else an error occurred, so
@@ -414,14 +398,11 @@
 
   bool access = (cur_host == k_nest_host);
 
-  if (log_is_enabled(Trace, class, nestmates)) {
-    ResourceMark rm(THREAD);
-    log_trace(class, nestmates)("Class %s does %shave nestmate access to %s",
-                                this->external_name(),
-                                access ? "" : "NOT ",
-                                k->external_name());
-  }
-
+  ResourceMark rm(THREAD);
+  log_trace(class, nestmates)("Class %s does %shave nestmate access to %s",
+                              this->external_name(),
+                              access ? "" : "NOT ",
+                              k->external_name());
   return access;
 }
 
--- a/src/hotspot/share/prims/jvm.cpp	Mon Mar 23 20:05:49 2020 +0000
+++ b/src/hotspot/share/prims/jvm.cpp	Mon Mar 23 18:26:01 2020 -0400
@@ -1023,15 +1023,13 @@
     host_class = InstanceKlass::cast(lookup_k)->nest_host(CHECK_NULL);
   }
 
-  if (log_is_enabled(Info, class, nestmates)) {
-    log_info(class, nestmates)("LookupDefineClass: %s - %s%s, %s, %s, %s",
-                               name,
-                               is_nestmate ? "with dynamic nest-host " : "non-nestmate",
-                               is_nestmate ? host_class->external_name() : "",
-                               is_hidden ? "hidden" : "not hidden",
-                               is_strong ? "strong" : "weak",
-                               vm_annotations ? "with vm annotations" : "without vm annotation");
-  }
+  log_info(class, nestmates)("LookupDefineClass: %s - %s%s, %s, %s, %s",
+                             name,
+                             is_nestmate ? "with dynamic nest-host " : "non-nestmate",
+                             is_nestmate ? host_class->external_name() : "",
+                             is_hidden ? "hidden" : "not hidden",
+                             is_strong ? "strong" : "weak",
+                             vm_annotations ? "with vm annotations" : "without vm annotation");
 
   if (!is_hidden) {
     // classData is only applicable for hidden classes
@@ -2063,27 +2061,20 @@
 {
   // current is not a primitive or array class
   JVMWrapper("JVM_GetNestMembers");
+  ResourceMark rm(THREAD);
   Klass* c = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(current));
   assert(c->is_instance_klass(), "must be");
   InstanceKlass* ck = InstanceKlass::cast(c);
   InstanceKlass* host = ck->nest_host(THREAD);
 
-  const bool doLog = log_is_enabled(Trace, class, nestmates);
-
-  if (doLog) {
-    ResourceMark rm(THREAD);
-    log_trace(class, nestmates)("Calling GetNestMembers for type %s with nest-host %s",
-                                ck->external_name(), host->external_name());
-  }
-
+  log_trace(class, nestmates)("Calling GetNestMembers for type %s with nest-host %s",
+                              ck->external_name(), host->external_name());
   {
     JvmtiVMObjectAllocEventCollector oam;
     Array<u2>* members = host->nest_members();
     int length = members == NULL ? 0 : members->length();
 
-    if (doLog) {
-      log_trace(class, nestmates)(" - host has %d listed nest members", length);
-    }
+    log_trace(class, nestmates)(" - host has %d listed nest members", length);
 
     // nest host is first in the array so make it one bigger
     objArrayOop r = oopFactory::new_objArray(SystemDictionary::Class_klass(),
@@ -2099,8 +2090,7 @@
           if (PENDING_EXCEPTION->is_a(SystemDictionary::VirtualMachineError_klass())) {
             return NULL; // propagate VMEs
           }
-          if (doLog) {
-            ResourceMark rm(THREAD);
+          if (log_is_enabled(Trace, class, nestmates)) {
             stringStream ss;
             char* target_member_class = host->constants()->klass_name_at(cp_index)->as_C_string();
             ss.print(" - resolution of nest member %s failed: ", target_member_class);
@@ -2116,32 +2106,21 @@
           if (nest_host_k == host) {
             result->obj_at_put(count+1, k->java_mirror());
             count++;
-            if (doLog) {
-              ResourceMark rm(THREAD);
-              log_trace(class, nestmates)(" - [%d] = %s", count, ik->external_name());
-            }
+            log_trace(class, nestmates)(" - [%d] = %s", count, ik->external_name());
           } else {
-            if (doLog) {
-              ResourceMark rm(THREAD);
-              log_trace(class, nestmates)(" - skipping member %s with different host %s",
-                                          ik->external_name(), nest_host_k->external_name());
-            }
+            log_trace(class, nestmates)(" - skipping member %s with different host %s",
+                                        ik->external_name(), nest_host_k->external_name());
           }
         } else {
-          if (doLog) {
-            ResourceMark rm(THREAD);
-            log_trace(class, nestmates)(" - skipping member %s that is not an instance class",
-                                        k->external_name());
-          }
+          log_trace(class, nestmates)(" - skipping member %s that is not an instance class",
+                                      k->external_name());
         }
       }
       if (count < length) {
         // we had invalid entries so we need to compact the array
-        if (doLog) {
-          ResourceMark rm(THREAD);
-          log_trace(class, nestmates)(" - compacting array from length %d to %d",
-                                      length + 1, count + 1);
-        }
+        log_trace(class, nestmates)(" - compacting array from length %d to %d",
+                                    length + 1, count + 1);
+
         objArrayOop r2 = oopFactory::new_objArray(SystemDictionary::Class_klass(),
                                                   count + 1, CHECK_NULL);
         objArrayHandle result2(THREAD, r2);