8218851: JVM crash in custom classloader stress test, JDK 12 & 13
authorcoleenp
Fri, 15 Feb 2019 08:21:08 -0500
changeset 53776 7c17199fa37d
parent 53775 5d20b085d893
child 53777 9bfeac2ee88a
8218851: JVM crash in custom classloader stress test, JDK 12 & 13 Summary: Handle NULL and unloaded constraint class in loader constraint table, also cope with unloaded but not cleaned out klass in loader constraint entries. Reviewed-by: hseigel, huntch, stuefe
src/hotspot/share/classfile/loaderConstraints.cpp
src/hotspot/share/classfile/systemDictionary.cpp
--- a/src/hotspot/share/classfile/loaderConstraints.cpp	Fri Feb 15 14:15:10 2019 +0100
+++ b/src/hotspot/share/classfile/loaderConstraints.cpp	Fri Feb 15 08:21:08 2019 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -77,7 +77,10 @@
     if (p->hash() == hash) {
       if (p->name() == name) {
         for (int i = p->num_loaders() - 1; i >= 0; i--) {
-          if (p->loader_data(i) == loader_data) {
+          if (p->loader_data(i) == loader_data &&
+              // skip unloaded klasses
+              (p->klass() == NULL ||
+               p->klass()->is_loader_alive())) {
             return pp;
           }
         }
--- a/src/hotspot/share/classfile/systemDictionary.cpp	Fri Feb 15 14:15:10 2019 +0100
+++ b/src/hotspot/share/classfile/systemDictionary.cpp	Fri Feb 15 08:21:08 2019 -0500
@@ -2114,7 +2114,7 @@
         ss.print(" wants to load %s %s.",
                  k->external_kind(), k->external_name());
         Klass *existing_klass = constraints()->find_constrained_klass(name, class_loader);
-        if (existing_klass->class_loader() != class_loader()) {
+        if (existing_klass != NULL && existing_klass->class_loader() != class_loader()) {
           ss.print(" A different %s with the same name was previously loaded by %s. (%s)",
                    existing_klass->external_kind(),
                    existing_klass->class_loader_data()->loader_name_and_id(),