From 2b04f898a163c07c495eae1d9ce88533163bccb2 Mon Sep 17 00:00:00 2001 From: hseigel Date: Wed, 8 Nov 2017 09:17:12 -0500 Subject: [PATCH] 8189123: More consistent classloading Reviewed-by: acorn, ahgross, rhalade Contributed-by: harold.seigel@oracle.com --- src/share/vm/classfile/verificationType.cpp | 4 +++- src/share/vm/classfile/verifier.cpp | 4 +++- src/share/vm/prims/jvm.cpp | 7 +++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/share/vm/classfile/verificationType.cpp b/src/share/vm/classfile/verificationType.cpp index 716a72d0d..61715d92d 100644 --- a/src/share/vm/classfile/verificationType.cpp +++ b/src/share/vm/classfile/verificationType.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2017, 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 @@ -63,6 +63,7 @@ bool VerificationType::is_reference_assignable_from( name(), Handle(THREAD, klass->class_loader()), Handle(THREAD, klass->protection_domain()), true, CHECK_false); KlassHandle this_class(THREAD, obj); + klass->class_loader_data()->record_dependency(obj, CHECK_false); if (this_class->is_interface() && (!from_field_is_protected || from.name() != vmSymbols::java_lang_Object())) { @@ -74,6 +75,7 @@ bool VerificationType::is_reference_assignable_from( Klass* from_class = SystemDictionary::resolve_or_fail( from.name(), Handle(THREAD, klass->class_loader()), Handle(THREAD, klass->protection_domain()), true, CHECK_false); + klass->class_loader_data()->record_dependency(from_class, CHECK_false); bool result = InstanceKlass::cast(from_class)->is_subclass_of(this_class()); if (result && DumpSharedSpaces) { if (klass()->is_subclass_of(from_class) && klass()->is_subclass_of(this_class())) { diff --git a/src/share/vm/classfile/verifier.cpp b/src/share/vm/classfile/verifier.cpp index b53b4aeda..82509ff16 100644 --- a/src/share/vm/classfile/verifier.cpp +++ b/src/share/vm/classfile/verifier.cpp @@ -1949,9 +1949,11 @@ Klass* ClassVerifier::load_class(Symbol* name, TRAPS) { oop loader = current_class()->class_loader(); oop protection_domain = current_class()->protection_domain(); - return SystemDictionary::resolve_or_fail( + Klass* kls = SystemDictionary::resolve_or_fail( name, Handle(THREAD, loader), Handle(THREAD, protection_domain), true, CHECK_NULL); + current_class()->class_loader_data()->record_dependency(kls, CHECK_NULL); + return kls; } bool ClassVerifier::is_protected_access(instanceKlassHandle this_class, diff --git a/src/share/vm/prims/jvm.cpp b/src/share/vm/prims/jvm.cpp index 7efc2775e..17caabbee 100644 --- a/src/share/vm/prims/jvm.cpp +++ b/src/share/vm/prims/jvm.cpp @@ -24,6 +24,7 @@ #include "precompiled.hpp" #include "classfile/classLoader.hpp" +#include "classfile/classLoaderData.inline.hpp" #include "classfile/classLoaderExt.hpp" #include "classfile/javaAssertions.hpp" #include "classfile/javaClasses.hpp" @@ -952,6 +953,12 @@ JVM_ENTRY(jclass, JVM_FindClassFromClass(JNIEnv *env, const char *name, Handle h_prot (THREAD, protection_domain); jclass result = find_class_from_class_loader(env, h_name, init, h_loader, h_prot, true, thread); + if (result != NULL) { + oop mirror = JNIHandles::resolve_non_null(result); + Klass* to_class = java_lang_Class::as_Klass(mirror); + ClassLoaderData* cld = ClassLoaderData::class_loader_data(h_loader()); + cld->record_dependency(to_class, CHECK_NULL); + } if (TraceClassResolution && result != NULL) { // this function is generally only used for class loading during verification. -- GitLab