Skip to content

Commit

Permalink
8304292: Memory leak related to ClassLoader::update_class_path_entry_…
Browse files Browse the repository at this point in the history
…list

Reviewed-by: dholmes, iklam
  • Loading branch information
calvinccheung committed Aug 10, 2023
1 parent 71d6d93 commit de315b0
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 6 deletions.
19 changes: 13 additions & 6 deletions test/hotspot/jtreg/runtime/cds/appcds/ClassPathAttr.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,18 @@ static void testNormalOps() throws Exception {
"CpAttr2", "CpAttr3", "CpAttr4", "CpAttr5");
buildCpAttr("cpattr5_123456789_223456789_323456789_423456789_523456789_623456789", "cpattr5_extra_long.mf", "CpAttr5", "CpAttr5");

String[] classlist = { "CpAttr1", "CpAttr2", "CpAttr3", "CpAttr4", "CpAttr5"};
String jar4 = TestCommon.getTestJar("cpattr4.jar");
for (int i=1; i<=2; i++) {
String jar1 = TestCommon.getTestJar("cpattr1.jar");
String jar4 = TestCommon.getTestJar("cpattr4.jar");
if (i == 2) {
// Test case #2 -- same as #1, except we use cpattr1_long.jar, which has a super-long
// Class-Path: attribute.
jar1 = TestCommon.getTestJar("cpattr1_long.jar");
}
String cp = jar1 + File.pathSeparator + jar4;

TestCommon.testDump(cp, TestCommon.list("CpAttr1",
"CpAttr2",
"CpAttr3",
"CpAttr4",
"CpAttr5"));
TestCommon.testDump(cp, classlist);

TestCommon.run(
"-cp", cp,
Expand All @@ -86,6 +83,16 @@ static void testNormalOps() throws Exception {
output.shouldMatch("checking shared classpath entry: .*cpattr3.jar");
});
}

// test duplicate jars in the "Class-path" attribute in the jar manifest
buildCpAttr("cpattr_dup", "cpattr_dup.mf", "CpAttr1", "CpAttr1");
String cp = TestCommon.getTestJar("cpattr_dup.jar") + File.pathSeparator + jar4;
TestCommon.testDump(cp, classlist);

TestCommon.run(
"-cp", cp,
"CpAttr1")
.assertNormalExit();
}

static void testNonExistentJars() throws Exception {
Expand Down
42 changes: 42 additions & 0 deletions test/hotspot/jtreg/runtime/cds/appcds/DuplicateClassPaths.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2023, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/

/*
* @test
* @summary duplicate class paths test
* @requires vm.cds
* @library /test/lib
* @compile test-classes/Hello.java
* @run driver DuplicateClassPaths
*/

import java.io.File;

public class DuplicateClassPaths {
public static void main(String[] args) throws Exception {
String appJar = JarBuilder.getOrCreateHelloJar();
String jars = appJar + File.pathSeparator + appJar;
TestCommon.test(jars, TestCommon.list("Hello"), "Hello");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Class-Path: cpattr2.jar cpattr2.jar
Created-By: 1.9.0-internal (Oracle Corporation)

0 comments on commit de315b0

Please sign in to comment.