--- old/src/hotspot/share/oops/instanceKlass.cpp 2020-07-10 16:22:56.326813149 +0000 +++ new/src/hotspot/share/oops/instanceKlass.cpp 2020-07-10 16:22:55.380789955 +0000 @@ -2825,7 +2825,17 @@ check_prohibited_package(name(), loader_data, CHECK); } - TempNewSymbol pkg_name = pkg_entry != NULL ? pkg_entry->name() : ClassLoader::package_from_class_name(name()); + // ClassLoader::package_from_class_name has already incremented the refcount of the symbol + // it returns, so we need to decrement it when the current function exits. + TempNewSymbol from_class_name = + (pkg_entry != NULL) ? NULL : ClassLoader::package_from_class_name(name()); + + Symbol* pkg_name; + if (pkg_entry != NULL) { + pkg_name = pkg_entry->name(); + } else { + pkg_name = from_class_name; + } if (pkg_name != NULL && loader_data != NULL) {