Thu, 08 Nov 2018 18:33:43 +0000
Merge
1.1 --- a/.hgtags Wed Nov 07 05:13:44 2018 -0800 1.2 +++ b/.hgtags Thu Nov 08 18:33:43 2018 +0000 1.3 @@ -1189,6 +1189,7 @@ 1.4 464ed8cea5d6cdbfacc9be7035297af88f57f708 jdk8u181-b12 1.5 eed8e846c982d7474dd07fc873ba02f83ad1f847 jdk8u181-b13 1.6 21a3fffc43418f4d75c2091bf03478330b8a9a98 jdk8u191-b01 1.7 +2bf8498a25ec87c92584a6542f8724644c8c5706 jdk8u201-b00 1.8 5aa3d728164a674d08ad847811be6bdd853e9bf8 jdk8u191-b02 1.9 dd79b482625361458b2b34e7d669ee982eee06a4 jdk8u191-b03 1.10 541c205d7fd15ab840f48aaeeaea3f63209d1687 jdk8u191-b04 1.11 @@ -1219,6 +1220,16 @@ 1.12 8df818c645d6081a387cf4fe9b9c14c0b5b639b1 jdk8u192-b11 1.13 1f822ff877d1a250165d5d2d52faf6957f8fcd00 jdk8u192-b12 1.14 e0e4c3a86ef0e4daf4fe96bd058045a2b13ebf84 jdk8u192-b26 1.15 +f7bd3ef62b03503c2abd2c877103fce4c41752ec jdk8u181-b31 1.16 +a2be8e761961b9aea1641593f2638406c8052bff jdk8u181-b32 1.17 +9d9f4c81eb3df5991f4409429a8eed5da385e138 jdk8u181-b33 1.18 +2ac6a4ff7b3c9c45bda2a449523f7f1babffd857 jdk8u181-b34 1.19 +f3eb9719e6961890add8af56c43a3273bedd3510 jdk8u181-b35 1.20 +5418d85b93ea93af1b75a700501cab9e53e282c5 jdk8u181-b36 1.21 +310a8a03be9363e47cc0856e43661cf71b516101 jdk8u181-b37 1.22 +cec91c1510a4f6b54f454f8a18c2ce19e1ef4002 jdk8u201-b01 1.23 +242132d678006ccd4139c33c1a188f09a09683c6 jdk8u201-b02 1.24 +68ee3b18354df0572de37bc04c3a7a8046d5a654 jdk8u201-b03 1.25 79b4c0a88c00226dcd14496652adf84d53b5cb9c jdk8u202-b01 1.26 9ce27f0a4683a2083d3aed59a40d6a3ccfc8e397 jdk8u202-b02 1.27 c0836eee40e5cfc7b3eebbb7a53bfcd98bc66278 jdk8u202-b03
2.1 --- a/src/share/vm/classfile/classFileParser.cpp Wed Nov 07 05:13:44 2018 -0800 2.2 +++ b/src/share/vm/classfile/classFileParser.cpp Thu Nov 08 18:33:43 2018 +0000 2.3 @@ -4210,9 +4210,6 @@ 2.4 this_klass(), &all_mirandas, CHECK_(nullHandle)); 2.5 } 2.6 2.7 - // Update the loader_data graph. 2.8 - record_defined_class_dependencies(this_klass, CHECK_NULL); 2.9 - 2.10 ClassLoadingService::notify_class_loaded(InstanceKlass::cast(this_klass()), 2.11 false /* not shared class */); 2.12 2.13 @@ -4498,30 +4495,6 @@ 2.14 } 2.15 } 2.16 2.17 -// Attach super classes and interface classes to class loader data 2.18 -void ClassFileParser::record_defined_class_dependencies(instanceKlassHandle defined_klass, TRAPS) { 2.19 - ClassLoaderData * defining_loader_data = defined_klass->class_loader_data(); 2.20 - if (defining_loader_data->is_the_null_class_loader_data()) { 2.21 - // Dependencies to null class loader data are implicit. 2.22 - return; 2.23 - } else { 2.24 - // add super class dependency 2.25 - Klass* super = defined_klass->super(); 2.26 - if (super != NULL) { 2.27 - defining_loader_data->record_dependency(super, CHECK); 2.28 - } 2.29 - 2.30 - // add super interface dependencies 2.31 - Array<Klass*>* local_interfaces = defined_klass->local_interfaces(); 2.32 - if (local_interfaces != NULL) { 2.33 - int length = local_interfaces->length(); 2.34 - for (int i = 0; i < length; i++) { 2.35 - defining_loader_data->record_dependency(local_interfaces->at(i), CHECK); 2.36 - } 2.37 - } 2.38 - } 2.39 -} 2.40 - 2.41 // utility methods for appending an array with check for duplicates 2.42 2.43 void append_interfaces(GrowableArray<Klass*>* result, Array<Klass*>* ifs) {
3.1 --- a/src/share/vm/classfile/dictionary.cpp Wed Nov 07 05:13:44 2018 -0800 3.2 +++ b/src/share/vm/classfile/dictionary.cpp Thu Nov 08 18:33:43 2018 +0000 3.3 @@ -1,5 +1,5 @@ 3.4 /* 3.5 - * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved. 3.6 + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. 3.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3.8 * 3.9 * This code is free software; you can redistribute it and/or modify it 3.10 @@ -159,33 +159,9 @@ 3.11 if (!is_strongly_reachable(loader_data, e)) { 3.12 // Entry was not visited in phase1 (negated test from phase1) 3.13 assert(!loader_data->is_the_null_class_loader_data(), "unloading entry with null class loader"); 3.14 - ClassLoaderData* k_def_class_loader_data = ik->class_loader_data(); 3.15 - 3.16 - // Do we need to delete this system dictionary entry? 3.17 - bool purge_entry = false; 3.18 3.19 // Do we need to delete this system dictionary entry? 3.20 if (loader_data->is_unloading()) { 3.21 - // If the loader is not live this entry should always be 3.22 - // removed (will never be looked up again). 3.23 - purge_entry = true; 3.24 - } else { 3.25 - // The loader in this entry is alive. If the klass is dead, 3.26 - // (determined by checking the defining class loader) 3.27 - // the loader must be an initiating loader (rather than the 3.28 - // defining loader). Remove this entry. 3.29 - if (k_def_class_loader_data->is_unloading()) { 3.30 - // If we get here, the class_loader_data must not be the defining 3.31 - // loader, it must be an initiating one. 3.32 - assert(k_def_class_loader_data != loader_data, 3.33 - "cannot have live defining loader and unreachable klass"); 3.34 - // Loader is live, but class and its defining loader are dead. 3.35 - // Remove the entry. The class is going away. 3.36 - purge_entry = true; 3.37 - } 3.38 - } 3.39 - 3.40 - if (purge_entry) { 3.41 *p = probe->next(); 3.42 if (probe == _current_class_entry) { 3.43 _current_class_entry = NULL;
4.1 --- a/src/share/vm/classfile/systemDictionary.cpp Wed Nov 07 05:13:44 2018 -0800 4.2 +++ b/src/share/vm/classfile/systemDictionary.cpp Thu Nov 08 18:33:43 2018 +0000 4.3 @@ -816,7 +816,16 @@ 4.4 check_constraints(d_index, d_hash, k, class_loader, false, THREAD); 4.5 4.6 // Need to check for a PENDING_EXCEPTION again; check_constraints 4.7 - // can throw and doesn't use the CHECK macro. 4.8 + // can throw but we may have to remove entry from the placeholder table below. 4.9 + if (!HAS_PENDING_EXCEPTION) { 4.10 + // Record dependency for non-parent delegation. 4.11 + // This recording keeps the defining class loader of the klass (k) found 4.12 + // from being unloaded while the initiating class loader is loaded 4.13 + // even if the reference to the defining class loader is dropped 4.14 + // before references to the initiating class loader. 4.15 + loader_data->record_dependency(k(), THREAD); 4.16 + } 4.17 + 4.18 if (!HAS_PENDING_EXCEPTION) { 4.19 { // Grabbing the Compile_lock prevents systemDictionary updates 4.20 // during compilations.
5.1 --- a/src/share/vm/classfile/verificationType.cpp Wed Nov 07 05:13:44 2018 -0800 5.2 +++ b/src/share/vm/classfile/verificationType.cpp Thu Nov 08 18:33:43 2018 +0000 5.3 @@ -63,7 +63,6 @@ 5.4 name(), Handle(THREAD, klass->class_loader()), 5.5 Handle(THREAD, klass->protection_domain()), true, CHECK_false); 5.6 KlassHandle this_class(THREAD, obj); 5.7 - klass->class_loader_data()->record_dependency(obj, CHECK_false); 5.8 5.9 if (this_class->is_interface() && (!from_field_is_protected || 5.10 from.name() != vmSymbols::java_lang_Object())) { 5.11 @@ -75,7 +74,6 @@ 5.12 Klass* from_class = SystemDictionary::resolve_or_fail( 5.13 from.name(), Handle(THREAD, klass->class_loader()), 5.14 Handle(THREAD, klass->protection_domain()), true, CHECK_false); 5.15 - klass->class_loader_data()->record_dependency(from_class, CHECK_false); 5.16 bool result = InstanceKlass::cast(from_class)->is_subclass_of(this_class()); 5.17 if (result && DumpSharedSpaces) { 5.18 if (klass()->is_subclass_of(from_class) && klass()->is_subclass_of(this_class())) {
6.1 --- a/src/share/vm/classfile/verifier.cpp Wed Nov 07 05:13:44 2018 -0800 6.2 +++ b/src/share/vm/classfile/verifier.cpp Thu Nov 08 18:33:43 2018 +0000 6.3 @@ -1,5 +1,5 @@ 6.4 /* 6.5 - * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved. 6.6 + * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved. 6.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6.8 * 6.9 * This code is free software; you can redistribute it and/or modify it 6.10 @@ -1949,11 +1949,9 @@ 6.11 oop loader = current_class()->class_loader(); 6.12 oop protection_domain = current_class()->protection_domain(); 6.13 6.14 - Klass* kls = SystemDictionary::resolve_or_fail( 6.15 + return SystemDictionary::resolve_or_fail( 6.16 name, Handle(THREAD, loader), Handle(THREAD, protection_domain), 6.17 true, CHECK_NULL); 6.18 - current_class()->class_loader_data()->record_dependency(kls, CHECK_NULL); 6.19 - return kls; 6.20 } 6.21 6.22 bool ClassVerifier::is_protected_access(instanceKlassHandle this_class,
7.1 --- a/src/share/vm/oops/constantPool.cpp Wed Nov 07 05:13:44 2018 -0800 7.2 +++ b/src/share/vm/oops/constantPool.cpp Thu Nov 08 18:33:43 2018 +0000 7.3 @@ -339,8 +339,6 @@ 7.4 // Only updated constant pool - if it is resolved. 7.5 do_resolve = this_oop->tag_at(which).is_unresolved_klass(); 7.6 if (do_resolve) { 7.7 - ClassLoaderData* this_key = this_oop->pool_holder()->class_loader_data(); 7.8 - this_key->record_dependency(k(), CHECK_NULL); // Can throw OOM 7.9 this_oop->klass_at_put(which, k()); 7.10 } 7.11 }
8.1 --- a/src/share/vm/oops/cpCache.cpp Wed Nov 07 05:13:44 2018 -0800 8.2 +++ b/src/share/vm/oops/cpCache.cpp Thu Nov 08 18:33:43 2018 +0000 8.3 @@ -1,5 +1,5 @@ 8.4 /* 8.5 - * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved. 8.6 + * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved. 8.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 8.8 * 8.9 * This code is free software; you can redistribute it and/or modify it 8.10 @@ -209,12 +209,22 @@ 8.11 if (byte_no == 1) { 8.12 assert(invoke_code != Bytecodes::_invokevirtual && 8.13 invoke_code != Bytecodes::_invokeinterface, ""); 8.14 + bool do_resolve = true; 8.15 // Don't mark invokespecial to method as resolved if sender is an interface. The receiver 8.16 // has to be checked that it is a subclass of the current class every time this bytecode 8.17 // is executed. 8.18 - if (invoke_code != Bytecodes::_invokespecial || !sender_is_interface || 8.19 - method->name() == vmSymbols::object_initializer_name()) { 8.20 - set_bytecode_1(invoke_code); 8.21 + if (invoke_code == Bytecodes::_invokespecial && sender_is_interface && 8.22 + method->name() != vmSymbols::object_initializer_name()) { 8.23 + do_resolve = false; 8.24 + } 8.25 + // Don't mark invokestatic to method as resolved if the holder class has not yet completed 8.26 + // initialization. An invokestatic must only proceed if the class is initialized, but if 8.27 + // we resolve it before then that class initialization check is skipped. 8.28 + if (invoke_code == Bytecodes::_invokestatic && !method->method_holder()->is_initialized()) { 8.29 + do_resolve = false; 8.30 + } 8.31 + if (do_resolve) { 8.32 + set_bytecode_1(invoke_code); 8.33 } 8.34 } else if (byte_no == 2) { 8.35 if (change_to_virtual) {
9.1 --- a/src/share/vm/prims/jvm.cpp Wed Nov 07 05:13:44 2018 -0800 9.2 +++ b/src/share/vm/prims/jvm.cpp Thu Nov 08 18:33:43 2018 +0000 9.3 @@ -991,12 +991,6 @@ 9.4 Handle h_prot (THREAD, protection_domain); 9.5 jclass result = find_class_from_class_loader(env, h_name, init, h_loader, 9.6 h_prot, true, thread); 9.7 - if (result != NULL) { 9.8 - oop mirror = JNIHandles::resolve_non_null(result); 9.9 - Klass* to_class = java_lang_Class::as_Klass(mirror); 9.10 - ClassLoaderData* cld = ClassLoaderData::class_loader_data(h_loader()); 9.11 - cld->record_dependency(to_class, CHECK_NULL); 9.12 - } 9.13 9.14 if (TraceClassResolution && result != NULL) { 9.15 // this function is generally only used for class loading during verification.
10.1 --- a/src/share/vm/runtime/sharedRuntime.cpp Wed Nov 07 05:13:44 2018 -0800 10.2 +++ b/src/share/vm/runtime/sharedRuntime.cpp Thu Nov 08 18:33:43 2018 +0000 10.3 @@ -1232,6 +1232,14 @@ 10.4 } 10.5 #endif 10.6 10.7 + // Do not patch call site for static call when the class is not 10.8 + // fully initialized. 10.9 + if (invoke_code == Bytecodes::_invokestatic && 10.10 + !callee_method->method_holder()->is_initialized()) { 10.11 + assert(callee_method->method_holder()->is_linked(), "must be"); 10.12 + return callee_method; 10.13 + } 10.14 + 10.15 // JSR 292 key invariant: 10.16 // If the resolved method is a MethodHandle invoke target, the call 10.17 // site must be a MethodHandle call site, because the lambda form might tail-call
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 11.2 +++ b/test/runtime/ClassUnload/ConstantPoolDependsTest.java Thu Nov 08 18:33:43 2018 +0000 11.3 @@ -0,0 +1,86 @@ 11.4 +/* 11.5 + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. 11.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 11.7 + * 11.8 + * This code is free software; you can redistribute it and/or modify it 11.9 + * under the terms of the GNU General Public License version 2 only, as 11.10 + * published by the Free Software Foundation. 11.11 + * 11.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 11.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11.15 + * version 2 for more details (a copy is included in the LICENSE file that 11.16 + * accompanied this code). 11.17 + * 11.18 + * You should have received a copy of the GNU General Public License version 11.19 + * 2 along with this work; if not, write to the Free Software Foundation, 11.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 11.21 + * 11.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 11.23 + * or visit www.oracle.com if you need additional information or have any 11.24 + * questions. 11.25 + */ 11.26 + 11.27 +/* 11.28 + * @test ConstantPoolDependsTest 11.29 + * @bug 8210094 11.30 + * @summary Create ClassLoader dependency from initiating loader to class loader through constant pool reference 11.31 + * @modules java.base/jdk.internal.misc 11.32 + * java.compiler 11.33 + * @library /testlibrary /testlibrary/whitebox /runtime/testlibrary 11.34 + * @build sun.hotspot.WhiteBox 11.35 + * @compile p2/c2.java MyDiffClassLoader.java 11.36 + * @run main ClassFileInstaller sun.hotspot.WhiteBox 11.37 + * sun.hotspot.WhiteBox$WhiteBoxPermission 11.38 + * @run main/othervm -Xbootclasspath/a:. -Xmn8m -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI ConstantPoolDependsTest 11.39 + */ 11.40 + 11.41 +import sun.hotspot.WhiteBox; 11.42 + 11.43 + 11.44 +public class ConstantPoolDependsTest { 11.45 + public static WhiteBox wb = WhiteBox.getWhiteBox(); 11.46 + public static final String MY_TEST = "ConstantPoolDependsTest$c1c"; 11.47 + 11.48 + public static class c1c { 11.49 + private void test() throws Exception { 11.50 + // ConstantPool.klass_at_impl loads through constant pool and creates dependency 11.51 + p2.c2 c2_obj = new p2.c2(); 11.52 + c2_obj.method2(); 11.53 + } 11.54 + 11.55 + public c1c () throws Exception { 11.56 + test(); 11.57 + ClassUnloadCommon.triggerUnloading(); // should not unload anything 11.58 + test(); 11.59 + ClassUnloadCommon.triggerUnloading(); // should not unload anything 11.60 + } 11.61 + } 11.62 + 11.63 + static void test() throws Throwable { 11.64 + 11.65 + // now use the same loader to load class MyTest 11.66 + Class MyTest_class = new MyDiffClassLoader(MY_TEST).loadClass(MY_TEST); 11.67 + 11.68 + try { 11.69 + // Call MyTest to load p2.c2 twice and call p2.c2.method2 11.70 + MyTest_class.newInstance(); 11.71 + } catch (Exception e) { 11.72 + throw new RuntimeException("Test FAILED if NoSuchMethodException is thrown"); 11.73 + } 11.74 + ClassUnloadCommon.triggerUnloading(); // should not unload anything 11.75 + ClassUnloadCommon.failIf(!wb.isClassAlive(MY_TEST), "should not be unloaded"); 11.76 + ClassUnloadCommon.failIf(!wb.isClassAlive("p2.c2"), "should not be unloaded"); 11.77 + // Unless MyTest_class is referenced here, the compiler can unload it. 11.78 + System.out.println("Should not unload anything before here because " + MyTest_class + " is still alive."); 11.79 + } 11.80 + 11.81 + public static void main(String args[]) throws Throwable { 11.82 + test(); 11.83 + ClassUnloadCommon.triggerUnloading(); // should unload 11.84 + System.gc(); 11.85 + System.out.println("Should unload p2.c2 just now"); 11.86 + ClassUnloadCommon.failIf(wb.isClassAlive(MY_TEST), "should be unloaded"); 11.87 + ClassUnloadCommon.failIf(wb.isClassAlive("p2.c2"), "should be unloaded"); 11.88 + } 11.89 +}
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 12.2 +++ b/test/runtime/ClassUnload/DictionaryDependsTest.java Thu Nov 08 18:33:43 2018 +0000 12.3 @@ -0,0 +1,89 @@ 12.4 +/* 12.5 + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. 12.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 12.7 + * 12.8 + * This code is free software; you can redistribute it and/or modify it 12.9 + * under the terms of the GNU General Public License version 2 only, as 12.10 + * published by the Free Software Foundation. 12.11 + * 12.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 12.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12.15 + * version 2 for more details (a copy is included in the LICENSE file that 12.16 + * accompanied this code). 12.17 + * 12.18 + * You should have received a copy of the GNU General Public License version 12.19 + * 2 along with this work; if not, write to the Free Software Foundation, 12.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 12.21 + * 12.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 12.23 + * or visit www.oracle.com if you need additional information or have any 12.24 + * questions. 12.25 + */ 12.26 + 12.27 +/* 12.28 + * @test DictionaryDependsTest 12.29 + * @bug 8210094 12.30 + * @summary Create ClassLoader dependency from initiating loader to class loader through reflection 12.31 + * @modules java.base/jdk.internal.misc 12.32 + * java.compiler 12.33 + * @library /testlibrary /testlibrary/whitebox /runtime/testlibrary 12.34 + * @build sun.hotspot.WhiteBox 12.35 + * @compile p2/c2.java MyDiffClassLoader.java 12.36 + * @run main ClassFileInstaller sun.hotspot.WhiteBox 12.37 + * sun.hotspot.WhiteBox$WhiteBoxPermission 12.38 + * @run main/othervm -Xbootclasspath/a:. -Xmn8m -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI DictionaryDependsTest 12.39 + */ 12.40 +import sun.hotspot.WhiteBox; 12.41 +import java.lang.reflect.Method; 12.42 + 12.43 +public class DictionaryDependsTest { 12.44 + public static WhiteBox wb = WhiteBox.getWhiteBox(); 12.45 + public static final String MY_TEST = "DictionaryDependsTest$c1r"; 12.46 + 12.47 + static public class c1r { 12.48 + 12.49 + private void test() throws Exception { 12.50 + // forName loads through reflection and doesn't create dependency 12.51 + Class<?> x = Class.forName("p2.c2", true, c1r.class.getClassLoader()); 12.52 + Method m = x.getMethod("method2"); 12.53 + java.lang.Object t = x.newInstance(); 12.54 + m.invoke(t); 12.55 + } 12.56 + 12.57 + public c1r () throws Exception { 12.58 + test(); 12.59 + ClassUnloadCommon.triggerUnloading(); // should unload p2.c2 12.60 + test(); 12.61 + ClassUnloadCommon.triggerUnloading(); // should unload p2.c2 12.62 + } 12.63 + } 12.64 + 12.65 + public void test() throws Throwable { 12.66 + 12.67 + // now use the same loader to load class MyTest 12.68 + Class MyTest_class = new MyDiffClassLoader(MY_TEST).loadClass(MY_TEST); 12.69 + 12.70 + try { 12.71 + // Call MyTest to load p2.c2 twice and call p2.c2.method2 12.72 + MyTest_class.newInstance(); 12.73 + } catch (Exception e) { 12.74 + System.out.println("Not expected NSME"); 12.75 + throw new RuntimeException("Not expecting NSME"); 12.76 + } 12.77 + ClassUnloadCommon.triggerUnloading(); // should not unload anything 12.78 + ClassUnloadCommon.failIf(!wb.isClassAlive(MY_TEST), "should not be unloaded"); 12.79 + ClassUnloadCommon.failIf(!wb.isClassAlive("p2.c2"), "should not be unloaded"); 12.80 + // Unless MyTest_class is referenced here, the compiler can unload it. 12.81 + System.out.println("Should not unload anything before here because " + MyTest_class + " is still alive."); 12.82 + } 12.83 + 12.84 + public static void main(String args[]) throws Throwable { 12.85 + DictionaryDependsTest d = new DictionaryDependsTest(); 12.86 + d.test(); 12.87 + ClassUnloadCommon.triggerUnloading(); // should not unload anything 12.88 + System.out.println("Should unload MyTest and p2.c2 just now"); 12.89 + ClassUnloadCommon.failIf(wb.isClassAlive(MY_TEST), "should be unloaded"); 12.90 + ClassUnloadCommon.failIf(wb.isClassAlive("p2.c2"), "should be unloaded"); 12.91 + } 12.92 +}
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 13.2 +++ b/test/runtime/ClassUnload/MyDiffClassLoader.java Thu Nov 08 18:33:43 2018 +0000 13.3 @@ -0,0 +1,75 @@ 13.4 +/* 13.5 + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. 13.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 13.7 + * 13.8 + * This code is free software; you can redistribute it and/or modify it 13.9 + * under the terms of the GNU General Public License version 2 only, as 13.10 + * published by the Free Software Foundation. 13.11 + * 13.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 13.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13.15 + * version 2 for more details (a copy is included in the LICENSE file that 13.16 + * accompanied this code). 13.17 + * 13.18 + * You should have received a copy of the GNU General Public License version 13.19 + * 2 along with this work; if not, write to the Free Software Foundation, 13.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 13.21 + * 13.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 13.23 + * or visit www.oracle.com if you need additional information or have any 13.24 + * questions. 13.25 + */ 13.26 + 13.27 +import java.io.*; 13.28 +import com.oracle.java.testlibrary.InMemoryJavaCompiler; 13.29 + 13.30 +public class MyDiffClassLoader extends ClassLoader { 13.31 + 13.32 + public String loaderName; 13.33 + public static boolean switchClassData = false; 13.34 + 13.35 + MyDiffClassLoader(String name) { 13.36 + this.loaderName = name; 13.37 + } 13.38 + 13.39 + public Class loadClass(String name) throws ClassNotFoundException { 13.40 + if (!name.contains("c1r") && 13.41 + !name.contains("c1c") && 13.42 + !name.contains("c1s") && 13.43 + !name.equals("p2.c2")) { 13.44 + return super.loadClass(name); 13.45 + } 13.46 + 13.47 + // new loader loads p2.c2 13.48 + if (name.equals("p2.c2") && !loaderName.equals("C2Loader")) { 13.49 + Class<?> c = new MyDiffClassLoader("C2Loader").loadClass(name); 13.50 + switchClassData = true; 13.51 + return c; 13.52 + } 13.53 + 13.54 + byte[] data = switchClassData ? getNewClassData(name) : getClassData(name); 13.55 + System.out.println("name is " + name); 13.56 + return defineClass(name, data, 0, data.length); 13.57 + } 13.58 + byte[] getClassData(String name) { 13.59 + try { 13.60 + String TempName = name.replaceAll("\\.", "/"); 13.61 + String currentDir = System.getProperty("test.classes"); 13.62 + String filename = currentDir + File.separator + TempName + ".class"; 13.63 + FileInputStream fis = new FileInputStream(filename); 13.64 + byte[] b = new byte[5000]; 13.65 + int cnt = fis.read(b, 0, 5000); 13.66 + byte[] c = new byte[cnt]; 13.67 + for (int i=0; i<cnt; i++) c[i] = b[i]; 13.68 + return c; 13.69 + } catch (IOException e) { 13.70 + return null; 13.71 + } 13.72 + } 13.73 + 13.74 + // Return p2.c2 with everything removed 13.75 + byte[] getNewClassData(String name) { 13.76 + return InMemoryJavaCompiler.compile("p2.c2", "package p2; public class c2 { }"); 13.77 + } 13.78 +}
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 14.2 +++ b/test/runtime/ClassUnload/SuperDependsTest.java Thu Nov 08 18:33:43 2018 +0000 14.3 @@ -0,0 +1,81 @@ 14.4 +/* 14.5 + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. 14.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 14.7 + * 14.8 + * This code is free software; you can redistribute it and/or modify it 14.9 + * under the terms of the GNU General Public License version 2 only, as 14.10 + * published by the Free Software Foundation. 14.11 + * 14.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 14.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14.15 + * version 2 for more details (a copy is included in the LICENSE file that 14.16 + * accompanied this code). 14.17 + * 14.18 + * You should have received a copy of the GNU General Public License version 14.19 + * 2 along with this work; if not, write to the Free Software Foundation, 14.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 14.21 + * 14.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 14.23 + * or visit www.oracle.com if you need additional information or have any 14.24 + * questions. 14.25 + */ 14.26 + 14.27 +/* 14.28 + * @test SuperDependsTest 14.29 + * @bug 8210094 14.30 + * @summary Create ClassLoader dependency from initiating loader to class loader through subclassing 14.31 + * @modules java.base/jdk.internal.misc 14.32 + * java.compiler 14.33 + * @library /testlibrary /testlibrary/whitebox /runtime/testlibrary 14.34 + * @build sun.hotspot.WhiteBox 14.35 + * @compile p2/c2.java MyDiffClassLoader.java 14.36 + * @run main ClassFileInstaller sun.hotspot.WhiteBox 14.37 + * sun.hotspot.WhiteBox$WhiteBoxPermission 14.38 + * @run main/othervm -Xbootclasspath/a:. -Xmn8m -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI SuperDependsTest 14.39 + */ 14.40 +import sun.hotspot.WhiteBox; 14.41 +import p2.*; 14.42 + 14.43 +public class SuperDependsTest { 14.44 + public static WhiteBox wb = WhiteBox.getWhiteBox(); 14.45 + public static final String MY_TEST = "SuperDependsTest$c1s"; 14.46 + 14.47 + 14.48 + // p2.c2 loads through super class and creates dependency 14.49 + public static class c1s extends p2.c2 { 14.50 + 14.51 + private void test() throws Exception { 14.52 + method2(); 14.53 + } 14.54 + 14.55 + public c1s () throws Exception { 14.56 + test(); 14.57 + ClassUnloadCommon.triggerUnloading(); // should not unload anything 14.58 + test(); 14.59 + } 14.60 + } 14.61 + 14.62 + public void test() throws Throwable { 14.63 + 14.64 + // now use the same loader to load class MyTest 14.65 + Class MyTest_class = new MyDiffClassLoader(MY_TEST).loadClass(MY_TEST); 14.66 + 14.67 + // Call MyTest to load p2.c2 twice and call p2.c2.method2 14.68 + MyTest_class.newInstance(); 14.69 + ClassUnloadCommon.triggerUnloading(); // should not unload anything 14.70 + ClassUnloadCommon.failIf(!wb.isClassAlive(MY_TEST), "should not be unloaded"); 14.71 + ClassUnloadCommon.failIf(!wb.isClassAlive("p2.c2"), "should not be unloaded"); 14.72 + // Unless MyTest_class is referenced here, the compiler can unload it. 14.73 + System.out.println("Should not unload anything before here because " + MyTest_class + " is still alive."); 14.74 + } 14.75 + 14.76 + public static void main(String args[]) throws Throwable { 14.77 + SuperDependsTest d = new SuperDependsTest(); 14.78 + d.test(); 14.79 + ClassUnloadCommon.triggerUnloading(); // should not unload anything 14.80 + System.out.println("Should unload MyTest and p2.c2 just now"); 14.81 + ClassUnloadCommon.failIf(wb.isClassAlive(MY_TEST), "should be unloaded"); 14.82 + ClassUnloadCommon.failIf(wb.isClassAlive("p2.c2"), "should be unloaded"); 14.83 + } 14.84 +}
15.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 15.2 +++ b/test/runtime/ClassUnload/p2/c2.java Thu Nov 08 18:33:43 2018 +0000 15.3 @@ -0,0 +1,28 @@ 15.4 +/* 15.5 + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. 15.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 15.7 + * 15.8 + * This code is free software; you can redistribute it and/or modify it 15.9 + * under the terms of the GNU General Public License version 2 only, as 15.10 + * published by the Free Software Foundation. 15.11 + * 15.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 15.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15.15 + * version 2 for more details (a copy is included in the LICENSE file that 15.16 + * accompanied this code). 15.17 + * 15.18 + * You should have received a copy of the GNU General Public License version 15.19 + * 2 along with this work; if not, write to the Free Software Foundation, 15.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 15.21 + * 15.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 15.23 + * or visit www.oracle.com if you need additional information or have any 15.24 + * questions. 15.25 + */ 15.26 +package p2; 15.27 + 15.28 +public class c2 { 15.29 + int i; 15.30 + public void method2() { i = 5; System.out.println("c2 method2 called"); } 15.31 +}