changeset 54939:7c17199fa37d

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
author coleenp
date Fri, 15 Feb 2019 08:21:08 -0500
parents 5d20b085d893
children a7f32db74cf7 89a63b923b21 f4fbdceb01b5 4c3d6ee38dfc c8dea6b36b35 6d8b17943a63 ef51f5d6d10d 2bd29eb6f135 339137b028f0 1ecccc7748df 9bfeac2ee88a
files src/hotspot/share/classfile/loaderConstraints.cpp src/hotspot/share/classfile/systemDictionary.cpp
diffstat 2 files changed, 6 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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(),