Wed, 06 Feb 2019 04:09:15 +0000
Merge
src/share/vm/prims/jvm.cpp | file | annotate | diff | comparison | revisions |
1.1 --- a/.hgtags Fri Feb 01 10:47:30 2019 +0100 1.2 +++ b/.hgtags Wed Feb 06 04:09:15 2019 +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,4 +1220,38 @@ 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 +f85cae50e04085dd498cc573cea5f829a6ab8d95 jdk8u201-b04 1.26 +2b490d8df3575cc40caf7f9ab54df2ff82ca1d6f jdk8u201-b74 1.27 +4b17023e0a3a168bd527b3a4cf2ca58fb77c691a jdk8u201-b05 1.28 +3f6c3bf8f0b17113a8b7d39962fc04db9cef360e jdk8u201-b75 1.29 +6ee55134973590878c9c922bdf76be9f1ac76940 jdk8u201-b06 1.30 +f53cabbd1a91af46b61230315e54df42c353b181 jdk8u201-b76 1.31 +dee6a1ce4a0c526c47d71ef402d10e4b8915c5cb jdk8u201-b07 1.32 +e4daab85ac15ae3c51f14ed8fba888e54e4c6830 jdk8u201-b77 1.33 +e2c2448a1ca75333879e055655f11525decc2c39 jdk8u201-b08 1.34 +48947e4db9f3b88fd0ec55801e969a3bd6cb74a9 jdk8u201-b09 1.35 +bd988b43db1b5ca6ee545097e79ddc5a4c8b5c87 jdk8u201-b79 1.36 +b9347a42530a741b7028e0cce47ce0bdd70697a3 jdk8u201-b25 1.37 +fb760c9d9649ab7d107b777a41f1424eebfb4883 jdk8u201-b26 1.38 +48947e4db9f3b88fd0ec55801e969a3bd6cb74a9 jdk8u201-ga 1.39 79b4c0a88c00226dcd14496652adf84d53b5cb9c jdk8u202-b01 1.40 +9ce27f0a4683a2083d3aed59a40d6a3ccfc8e397 jdk8u202-b02 1.41 +c0836eee40e5cfc7b3eebbb7a53bfcd98bc66278 jdk8u202-b03 1.42 +270570f695e077f3dbd8e051a7a14c312bcad3cf jdk8u202-b04 1.43 +04b9a5286eca10f676132ede70f29ba643f9b78b jdk8u202-b05 1.44 +2fa6434658660b4341be233828362e533782f036 jdk8u202-b06 1.45 +32c99b1faf57d7ed59e026339a4d7eb8f86b2d83 jdk8u202-b07 1.46 +818b1963f7a227a2368a4f363d5500dd226a529e jdk8u202-b08 1.47 +1083b49a881011f43667ebebc280d519f077f9e6 jdk8u202-b25 1.48 +7a69774c67cb79a79ccb2ac2d6d258a11e22aa6f jdk8u202-b26 1.49 +818b1963f7a227a2368a4f363d5500dd226a529e jdk8u202-ga
2.1 --- a/THIRD_PARTY_README Fri Feb 01 10:47:30 2019 +0100 2.2 +++ b/THIRD_PARTY_README Wed Feb 06 04:09:15 2019 +0000 2.3 @@ -1668,13 +1668,13 @@ 2.4 2.5 ------------------------------------------------------------------------------- 2.6 2.7 -%% This notice is provided with respect to Little CMS 2.7, which may be 2.8 +%% This notice is provided with respect to Little CMS 2.9, which may be 2.9 included with JRE 8, JDK 8, and OpenJDK 8. 2.10 2.11 --- begin of LICENSE --- 2.12 2.13 Little CMS 2.14 -Copyright (c) 1998-2015 Marti Maria Saguer 2.15 +Copyright (c) 1998-2011 Marti Maria Saguer 2.16 2.17 Permission is hereby granted, free of charge, to any person obtaining a copy 2.18 of this software and associated documentation files (the "Software"), to deal
3.1 --- a/src/share/vm/classfile/classFileParser.cpp Fri Feb 01 10:47:30 2019 +0100 3.2 +++ b/src/share/vm/classfile/classFileParser.cpp Wed Feb 06 04:09:15 2019 +0000 3.3 @@ -4210,9 +4210,6 @@ 3.4 this_klass(), &all_mirandas, CHECK_(nullHandle)); 3.5 } 3.6 3.7 - // Update the loader_data graph. 3.8 - record_defined_class_dependencies(this_klass, CHECK_NULL); 3.9 - 3.10 ClassLoadingService::notify_class_loaded(InstanceKlass::cast(this_klass()), 3.11 false /* not shared class */); 3.12 3.13 @@ -4498,30 +4495,6 @@ 3.14 } 3.15 } 3.16 3.17 -// Attach super classes and interface classes to class loader data 3.18 -void ClassFileParser::record_defined_class_dependencies(instanceKlassHandle defined_klass, TRAPS) { 3.19 - ClassLoaderData * defining_loader_data = defined_klass->class_loader_data(); 3.20 - if (defining_loader_data->is_the_null_class_loader_data()) { 3.21 - // Dependencies to null class loader data are implicit. 3.22 - return; 3.23 - } else { 3.24 - // add super class dependency 3.25 - Klass* super = defined_klass->super(); 3.26 - if (super != NULL) { 3.27 - defining_loader_data->record_dependency(super, CHECK); 3.28 - } 3.29 - 3.30 - // add super interface dependencies 3.31 - Array<Klass*>* local_interfaces = defined_klass->local_interfaces(); 3.32 - if (local_interfaces != NULL) { 3.33 - int length = local_interfaces->length(); 3.34 - for (int i = 0; i < length; i++) { 3.35 - defining_loader_data->record_dependency(local_interfaces->at(i), CHECK); 3.36 - } 3.37 - } 3.38 - } 3.39 -} 3.40 - 3.41 // utility methods for appending an array with check for duplicates 3.42 3.43 void append_interfaces(GrowableArray<Klass*>* result, Array<Klass*>* ifs) {
4.1 --- a/src/share/vm/classfile/dictionary.cpp Fri Feb 01 10:47:30 2019 +0100 4.2 +++ b/src/share/vm/classfile/dictionary.cpp Wed Feb 06 04:09:15 2019 +0000 4.3 @@ -1,5 +1,5 @@ 4.4 /* 4.5 - * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved. 4.6 + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. 4.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4.8 * 4.9 * This code is free software; you can redistribute it and/or modify it 4.10 @@ -159,33 +159,9 @@ 4.11 if (!is_strongly_reachable(loader_data, e)) { 4.12 // Entry was not visited in phase1 (negated test from phase1) 4.13 assert(!loader_data->is_the_null_class_loader_data(), "unloading entry with null class loader"); 4.14 - ClassLoaderData* k_def_class_loader_data = ik->class_loader_data(); 4.15 - 4.16 - // Do we need to delete this system dictionary entry? 4.17 - bool purge_entry = false; 4.18 4.19 // Do we need to delete this system dictionary entry? 4.20 if (loader_data->is_unloading()) { 4.21 - // If the loader is not live this entry should always be 4.22 - // removed (will never be looked up again). 4.23 - purge_entry = true; 4.24 - } else { 4.25 - // The loader in this entry is alive. If the klass is dead, 4.26 - // (determined by checking the defining class loader) 4.27 - // the loader must be an initiating loader (rather than the 4.28 - // defining loader). Remove this entry. 4.29 - if (k_def_class_loader_data->is_unloading()) { 4.30 - // If we get here, the class_loader_data must not be the defining 4.31 - // loader, it must be an initiating one. 4.32 - assert(k_def_class_loader_data != loader_data, 4.33 - "cannot have live defining loader and unreachable klass"); 4.34 - // Loader is live, but class and its defining loader are dead. 4.35 - // Remove the entry. The class is going away. 4.36 - purge_entry = true; 4.37 - } 4.38 - } 4.39 - 4.40 - if (purge_entry) { 4.41 *p = probe->next(); 4.42 if (probe == _current_class_entry) { 4.43 _current_class_entry = NULL;
5.1 --- a/src/share/vm/classfile/systemDictionary.cpp Fri Feb 01 10:47:30 2019 +0100 5.2 +++ b/src/share/vm/classfile/systemDictionary.cpp Wed Feb 06 04:09:15 2019 +0000 5.3 @@ -816,7 +816,16 @@ 5.4 check_constraints(d_index, d_hash, k, class_loader, false, THREAD); 5.5 5.6 // Need to check for a PENDING_EXCEPTION again; check_constraints 5.7 - // can throw and doesn't use the CHECK macro. 5.8 + // can throw but we may have to remove entry from the placeholder table below. 5.9 + if (!HAS_PENDING_EXCEPTION) { 5.10 + // Record dependency for non-parent delegation. 5.11 + // This recording keeps the defining class loader of the klass (k) found 5.12 + // from being unloaded while the initiating class loader is loaded 5.13 + // even if the reference to the defining class loader is dropped 5.14 + // before references to the initiating class loader. 5.15 + loader_data->record_dependency(k(), THREAD); 5.16 + } 5.17 + 5.18 if (!HAS_PENDING_EXCEPTION) { 5.19 { // Grabbing the Compile_lock prevents systemDictionary updates 5.20 // during compilations.
6.1 --- a/src/share/vm/classfile/verificationType.cpp Fri Feb 01 10:47:30 2019 +0100 6.2 +++ b/src/share/vm/classfile/verificationType.cpp Wed Feb 06 04:09:15 2019 +0000 6.3 @@ -63,7 +63,6 @@ 6.4 name(), Handle(THREAD, klass->class_loader()), 6.5 Handle(THREAD, klass->protection_domain()), true, CHECK_false); 6.6 KlassHandle this_class(THREAD, obj); 6.7 - klass->class_loader_data()->record_dependency(obj, CHECK_false); 6.8 6.9 if (this_class->is_interface() && (!from_field_is_protected || 6.10 from.name() != vmSymbols::java_lang_Object())) { 6.11 @@ -75,7 +74,6 @@ 6.12 Klass* from_class = SystemDictionary::resolve_or_fail( 6.13 from.name(), Handle(THREAD, klass->class_loader()), 6.14 Handle(THREAD, klass->protection_domain()), true, CHECK_false); 6.15 - klass->class_loader_data()->record_dependency(from_class, CHECK_false); 6.16 bool result = InstanceKlass::cast(from_class)->is_subclass_of(this_class()); 6.17 if (result && DumpSharedSpaces) { 6.18 if (klass()->is_subclass_of(from_class) && klass()->is_subclass_of(this_class())) {
7.1 --- a/src/share/vm/classfile/verifier.cpp Fri Feb 01 10:47:30 2019 +0100 7.2 +++ b/src/share/vm/classfile/verifier.cpp Wed Feb 06 04:09:15 2019 +0000 7.3 @@ -1,5 +1,5 @@ 7.4 /* 7.5 - * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved. 7.6 + * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved. 7.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7.8 * 7.9 * This code is free software; you can redistribute it and/or modify it 7.10 @@ -1949,11 +1949,9 @@ 7.11 oop loader = current_class()->class_loader(); 7.12 oop protection_domain = current_class()->protection_domain(); 7.13 7.14 - Klass* kls = SystemDictionary::resolve_or_fail( 7.15 + return SystemDictionary::resolve_or_fail( 7.16 name, Handle(THREAD, loader), Handle(THREAD, protection_domain), 7.17 true, CHECK_NULL); 7.18 - current_class()->class_loader_data()->record_dependency(kls, CHECK_NULL); 7.19 - return kls; 7.20 } 7.21 7.22 bool ClassVerifier::is_protected_access(instanceKlassHandle this_class,
8.1 --- a/src/share/vm/oops/constantPool.cpp Fri Feb 01 10:47:30 2019 +0100 8.2 +++ b/src/share/vm/oops/constantPool.cpp Wed Feb 06 04:09:15 2019 +0000 8.3 @@ -339,8 +339,6 @@ 8.4 // Only updated constant pool - if it is resolved. 8.5 do_resolve = this_oop->tag_at(which).is_unresolved_klass(); 8.6 if (do_resolve) { 8.7 - ClassLoaderData* this_key = this_oop->pool_holder()->class_loader_data(); 8.8 - this_key->record_dependency(k(), CHECK_NULL); // Can throw OOM 8.9 this_oop->klass_at_put(which, k()); 8.10 } 8.11 }
9.1 --- a/src/share/vm/oops/cpCache.cpp Fri Feb 01 10:47:30 2019 +0100 9.2 +++ b/src/share/vm/oops/cpCache.cpp Wed Feb 06 04:09:15 2019 +0000 9.3 @@ -1,5 +1,5 @@ 9.4 /* 9.5 - * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved. 9.6 + * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved. 9.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 9.8 * 9.9 * This code is free software; you can redistribute it and/or modify it 9.10 @@ -209,12 +209,22 @@ 9.11 if (byte_no == 1) { 9.12 assert(invoke_code != Bytecodes::_invokevirtual && 9.13 invoke_code != Bytecodes::_invokeinterface, ""); 9.14 + bool do_resolve = true; 9.15 // Don't mark invokespecial to method as resolved if sender is an interface. The receiver 9.16 // has to be checked that it is a subclass of the current class every time this bytecode 9.17 // is executed. 9.18 - if (invoke_code != Bytecodes::_invokespecial || !sender_is_interface || 9.19 - method->name() == vmSymbols::object_initializer_name()) { 9.20 - set_bytecode_1(invoke_code); 9.21 + if (invoke_code == Bytecodes::_invokespecial && sender_is_interface && 9.22 + method->name() != vmSymbols::object_initializer_name()) { 9.23 + do_resolve = false; 9.24 + } 9.25 + // Don't mark invokestatic to method as resolved if the holder class has not yet completed 9.26 + // initialization. An invokestatic must only proceed if the class is initialized, but if 9.27 + // we resolve it before then that class initialization check is skipped. 9.28 + if (invoke_code == Bytecodes::_invokestatic && !method->method_holder()->is_initialized()) { 9.29 + do_resolve = false; 9.30 + } 9.31 + if (do_resolve) { 9.32 + set_bytecode_1(invoke_code); 9.33 } 9.34 } else if (byte_no == 2) { 9.35 if (change_to_virtual) {
10.1 --- a/src/share/vm/prims/jvm.cpp Fri Feb 01 10:47:30 2019 +0100 10.2 +++ b/src/share/vm/prims/jvm.cpp Wed Feb 06 04:09:15 2019 +0000 10.3 @@ -1064,12 +1064,6 @@ 10.4 Handle h_prot (THREAD, protection_domain); 10.5 jclass result = find_class_from_class_loader(env, h_name, init, h_loader, 10.6 h_prot, true, thread); 10.7 - if (result != NULL) { 10.8 - oop mirror = JNIHandles::resolve_non_null(result); 10.9 - Klass* to_class = java_lang_Class::as_Klass(mirror); 10.10 - ClassLoaderData* cld = ClassLoaderData::class_loader_data(h_loader()); 10.11 - cld->record_dependency(to_class, CHECK_NULL); 10.12 - } 10.13 10.14 if (TraceClassResolution && result != NULL) { 10.15 // this function is generally only used for class loading during verification.
11.1 --- a/src/share/vm/runtime/sharedRuntime.cpp Fri Feb 01 10:47:30 2019 +0100 11.2 +++ b/src/share/vm/runtime/sharedRuntime.cpp Wed Feb 06 04:09:15 2019 +0000 11.3 @@ -1232,6 +1232,14 @@ 11.4 } 11.5 #endif 11.6 11.7 + // Do not patch call site for static call when the class is not 11.8 + // fully initialized. 11.9 + if (invoke_code == Bytecodes::_invokestatic && 11.10 + !callee_method->method_holder()->is_initialized()) { 11.11 + assert(callee_method->method_holder()->is_linked(), "must be"); 11.12 + return callee_method; 11.13 + } 11.14 + 11.15 // JSR 292 key invariant: 11.16 // If the resolved method is a MethodHandle invoke target, the call 11.17 // site must be a MethodHandle call site, because the lambda form might tail-call
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 12.2 +++ b/test/runtime/ClassUnload/ConstantPoolDependsTest.java Wed Feb 06 04:09:15 2019 +0000 12.3 @@ -0,0 +1,86 @@ 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 ConstantPoolDependsTest 12.29 + * @bug 8210094 12.30 + * @summary Create ClassLoader dependency from initiating loader to class loader through constant pool reference 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 ConstantPoolDependsTest 12.39 + */ 12.40 + 12.41 +import sun.hotspot.WhiteBox; 12.42 + 12.43 + 12.44 +public class ConstantPoolDependsTest { 12.45 + public static WhiteBox wb = WhiteBox.getWhiteBox(); 12.46 + public static final String MY_TEST = "ConstantPoolDependsTest$c1c"; 12.47 + 12.48 + public static class c1c { 12.49 + private void test() throws Exception { 12.50 + // ConstantPool.klass_at_impl loads through constant pool and creates dependency 12.51 + p2.c2 c2_obj = new p2.c2(); 12.52 + c2_obj.method2(); 12.53 + } 12.54 + 12.55 + public c1c () throws Exception { 12.56 + test(); 12.57 + ClassUnloadCommon.triggerUnloading(); // should not unload anything 12.58 + test(); 12.59 + ClassUnloadCommon.triggerUnloading(); // should not unload anything 12.60 + } 12.61 + } 12.62 + 12.63 + static void test() throws Throwable { 12.64 + 12.65 + // now use the same loader to load class MyTest 12.66 + Class MyTest_class = new MyDiffClassLoader(MY_TEST).loadClass(MY_TEST); 12.67 + 12.68 + try { 12.69 + // Call MyTest to load p2.c2 twice and call p2.c2.method2 12.70 + MyTest_class.newInstance(); 12.71 + } catch (Exception e) { 12.72 + throw new RuntimeException("Test FAILED if NoSuchMethodException is thrown"); 12.73 + } 12.74 + ClassUnloadCommon.triggerUnloading(); // should not unload anything 12.75 + ClassUnloadCommon.failIf(!wb.isClassAlive(MY_TEST), "should not be unloaded"); 12.76 + ClassUnloadCommon.failIf(!wb.isClassAlive("p2.c2"), "should not be unloaded"); 12.77 + // Unless MyTest_class is referenced here, the compiler can unload it. 12.78 + System.out.println("Should not unload anything before here because " + MyTest_class + " is still alive."); 12.79 + } 12.80 + 12.81 + public static void main(String args[]) throws Throwable { 12.82 + test(); 12.83 + ClassUnloadCommon.triggerUnloading(); // should unload 12.84 + System.gc(); 12.85 + System.out.println("Should unload p2.c2 just now"); 12.86 + ClassUnloadCommon.failIf(wb.isClassAlive(MY_TEST), "should be unloaded"); 12.87 + ClassUnloadCommon.failIf(wb.isClassAlive("p2.c2"), "should be unloaded"); 12.88 + } 12.89 +}
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 13.2 +++ b/test/runtime/ClassUnload/DictionaryDependsTest.java Wed Feb 06 04:09:15 2019 +0000 13.3 @@ -0,0 +1,89 @@ 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 +/* 13.28 + * @test DictionaryDependsTest 13.29 + * @bug 8210094 13.30 + * @summary Create ClassLoader dependency from initiating loader to class loader through reflection 13.31 + * @modules java.base/jdk.internal.misc 13.32 + * java.compiler 13.33 + * @library /testlibrary /testlibrary/whitebox /runtime/testlibrary 13.34 + * @build sun.hotspot.WhiteBox 13.35 + * @compile p2/c2.java MyDiffClassLoader.java 13.36 + * @run main ClassFileInstaller sun.hotspot.WhiteBox 13.37 + * sun.hotspot.WhiteBox$WhiteBoxPermission 13.38 + * @run main/othervm -Xbootclasspath/a:. -Xmn8m -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI DictionaryDependsTest 13.39 + */ 13.40 +import sun.hotspot.WhiteBox; 13.41 +import java.lang.reflect.Method; 13.42 + 13.43 +public class DictionaryDependsTest { 13.44 + public static WhiteBox wb = WhiteBox.getWhiteBox(); 13.45 + public static final String MY_TEST = "DictionaryDependsTest$c1r"; 13.46 + 13.47 + static public class c1r { 13.48 + 13.49 + private void test() throws Exception { 13.50 + // forName loads through reflection and doesn't create dependency 13.51 + Class<?> x = Class.forName("p2.c2", true, c1r.class.getClassLoader()); 13.52 + Method m = x.getMethod("method2"); 13.53 + java.lang.Object t = x.newInstance(); 13.54 + m.invoke(t); 13.55 + } 13.56 + 13.57 + public c1r () throws Exception { 13.58 + test(); 13.59 + ClassUnloadCommon.triggerUnloading(); // should unload p2.c2 13.60 + test(); 13.61 + ClassUnloadCommon.triggerUnloading(); // should unload p2.c2 13.62 + } 13.63 + } 13.64 + 13.65 + public void test() throws Throwable { 13.66 + 13.67 + // now use the same loader to load class MyTest 13.68 + Class MyTest_class = new MyDiffClassLoader(MY_TEST).loadClass(MY_TEST); 13.69 + 13.70 + try { 13.71 + // Call MyTest to load p2.c2 twice and call p2.c2.method2 13.72 + MyTest_class.newInstance(); 13.73 + } catch (Exception e) { 13.74 + System.out.println("Not expected NSME"); 13.75 + throw new RuntimeException("Not expecting NSME"); 13.76 + } 13.77 + ClassUnloadCommon.triggerUnloading(); // should not unload anything 13.78 + ClassUnloadCommon.failIf(!wb.isClassAlive(MY_TEST), "should not be unloaded"); 13.79 + ClassUnloadCommon.failIf(!wb.isClassAlive("p2.c2"), "should not be unloaded"); 13.80 + // Unless MyTest_class is referenced here, the compiler can unload it. 13.81 + System.out.println("Should not unload anything before here because " + MyTest_class + " is still alive."); 13.82 + } 13.83 + 13.84 + public static void main(String args[]) throws Throwable { 13.85 + DictionaryDependsTest d = new DictionaryDependsTest(); 13.86 + d.test(); 13.87 + ClassUnloadCommon.triggerUnloading(); // should not unload anything 13.88 + System.out.println("Should unload MyTest and p2.c2 just now"); 13.89 + ClassUnloadCommon.failIf(wb.isClassAlive(MY_TEST), "should be unloaded"); 13.90 + ClassUnloadCommon.failIf(wb.isClassAlive("p2.c2"), "should be unloaded"); 13.91 + } 13.92 +}
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 14.2 +++ b/test/runtime/ClassUnload/MyDiffClassLoader.java Wed Feb 06 04:09:15 2019 +0000 14.3 @@ -0,0 +1,75 @@ 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 +import java.io.*; 14.28 +import com.oracle.java.testlibrary.InMemoryJavaCompiler; 14.29 + 14.30 +public class MyDiffClassLoader extends ClassLoader { 14.31 + 14.32 + public String loaderName; 14.33 + public static boolean switchClassData = false; 14.34 + 14.35 + MyDiffClassLoader(String name) { 14.36 + this.loaderName = name; 14.37 + } 14.38 + 14.39 + public Class loadClass(String name) throws ClassNotFoundException { 14.40 + if (!name.contains("c1r") && 14.41 + !name.contains("c1c") && 14.42 + !name.contains("c1s") && 14.43 + !name.equals("p2.c2")) { 14.44 + return super.loadClass(name); 14.45 + } 14.46 + 14.47 + // new loader loads p2.c2 14.48 + if (name.equals("p2.c2") && !loaderName.equals("C2Loader")) { 14.49 + Class<?> c = new MyDiffClassLoader("C2Loader").loadClass(name); 14.50 + switchClassData = true; 14.51 + return c; 14.52 + } 14.53 + 14.54 + byte[] data = switchClassData ? getNewClassData(name) : getClassData(name); 14.55 + System.out.println("name is " + name); 14.56 + return defineClass(name, data, 0, data.length); 14.57 + } 14.58 + byte[] getClassData(String name) { 14.59 + try { 14.60 + String TempName = name.replaceAll("\\.", "/"); 14.61 + String currentDir = System.getProperty("test.classes"); 14.62 + String filename = currentDir + File.separator + TempName + ".class"; 14.63 + FileInputStream fis = new FileInputStream(filename); 14.64 + byte[] b = new byte[5000]; 14.65 + int cnt = fis.read(b, 0, 5000); 14.66 + byte[] c = new byte[cnt]; 14.67 + for (int i=0; i<cnt; i++) c[i] = b[i]; 14.68 + return c; 14.69 + } catch (IOException e) { 14.70 + return null; 14.71 + } 14.72 + } 14.73 + 14.74 + // Return p2.c2 with everything removed 14.75 + byte[] getNewClassData(String name) { 14.76 + return InMemoryJavaCompiler.compile("p2.c2", "package p2; public class c2 { }"); 14.77 + } 14.78 +}
15.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 15.2 +++ b/test/runtime/ClassUnload/SuperDependsTest.java Wed Feb 06 04:09:15 2019 +0000 15.3 @@ -0,0 +1,81 @@ 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 + 15.27 +/* 15.28 + * @test SuperDependsTest 15.29 + * @bug 8210094 15.30 + * @summary Create ClassLoader dependency from initiating loader to class loader through subclassing 15.31 + * @modules java.base/jdk.internal.misc 15.32 + * java.compiler 15.33 + * @library /testlibrary /testlibrary/whitebox /runtime/testlibrary 15.34 + * @build sun.hotspot.WhiteBox 15.35 + * @compile p2/c2.java MyDiffClassLoader.java 15.36 + * @run main ClassFileInstaller sun.hotspot.WhiteBox 15.37 + * sun.hotspot.WhiteBox$WhiteBoxPermission 15.38 + * @run main/othervm -Xbootclasspath/a:. -Xmn8m -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI SuperDependsTest 15.39 + */ 15.40 +import sun.hotspot.WhiteBox; 15.41 +import p2.*; 15.42 + 15.43 +public class SuperDependsTest { 15.44 + public static WhiteBox wb = WhiteBox.getWhiteBox(); 15.45 + public static final String MY_TEST = "SuperDependsTest$c1s"; 15.46 + 15.47 + 15.48 + // p2.c2 loads through super class and creates dependency 15.49 + public static class c1s extends p2.c2 { 15.50 + 15.51 + private void test() throws Exception { 15.52 + method2(); 15.53 + } 15.54 + 15.55 + public c1s () throws Exception { 15.56 + test(); 15.57 + ClassUnloadCommon.triggerUnloading(); // should not unload anything 15.58 + test(); 15.59 + } 15.60 + } 15.61 + 15.62 + public void test() throws Throwable { 15.63 + 15.64 + // now use the same loader to load class MyTest 15.65 + Class MyTest_class = new MyDiffClassLoader(MY_TEST).loadClass(MY_TEST); 15.66 + 15.67 + // Call MyTest to load p2.c2 twice and call p2.c2.method2 15.68 + MyTest_class.newInstance(); 15.69 + ClassUnloadCommon.triggerUnloading(); // should not unload anything 15.70 + ClassUnloadCommon.failIf(!wb.isClassAlive(MY_TEST), "should not be unloaded"); 15.71 + ClassUnloadCommon.failIf(!wb.isClassAlive("p2.c2"), "should not be unloaded"); 15.72 + // Unless MyTest_class is referenced here, the compiler can unload it. 15.73 + System.out.println("Should not unload anything before here because " + MyTest_class + " is still alive."); 15.74 + } 15.75 + 15.76 + public static void main(String args[]) throws Throwable { 15.77 + SuperDependsTest d = new SuperDependsTest(); 15.78 + d.test(); 15.79 + ClassUnloadCommon.triggerUnloading(); // should not unload anything 15.80 + System.out.println("Should unload MyTest and p2.c2 just now"); 15.81 + ClassUnloadCommon.failIf(wb.isClassAlive(MY_TEST), "should be unloaded"); 15.82 + ClassUnloadCommon.failIf(wb.isClassAlive("p2.c2"), "should be unloaded"); 15.83 + } 15.84 +}
16.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 16.2 +++ b/test/runtime/ClassUnload/p2/c2.java Wed Feb 06 04:09:15 2019 +0000 16.3 @@ -0,0 +1,28 @@ 16.4 +/* 16.5 + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. 16.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 16.7 + * 16.8 + * This code is free software; you can redistribute it and/or modify it 16.9 + * under the terms of the GNU General Public License version 2 only, as 16.10 + * published by the Free Software Foundation. 16.11 + * 16.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 16.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 16.15 + * version 2 for more details (a copy is included in the LICENSE file that 16.16 + * accompanied this code). 16.17 + * 16.18 + * You should have received a copy of the GNU General Public License version 16.19 + * 2 along with this work; if not, write to the Free Software Foundation, 16.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 16.21 + * 16.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 16.23 + * or visit www.oracle.com if you need additional information or have any 16.24 + * questions. 16.25 + */ 16.26 +package p2; 16.27 + 16.28 +public class c2 { 16.29 + int i; 16.30 + public void method2() { i = 5; System.out.println("c2 method2 called"); } 16.31 +}