/* * Copyright (c) 2015, 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 * @bug 8030099 * @summary Memory usage of java process increases after calling Win32ShellFolder:listFiles multiple times on some directory with large number of files/folders * @modules java.desktop/sun.awt.shell * @requires (os.family == "windows") * @run main/timeout=1000 ShellFolderMemoryLeak
*/ import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.logging.Level; import java.util.logging.Logger; import sun.awt.shell.ShellFolder;
publicclass ShellFolderMemoryLeak {
privatefinalstatic String tempDir = System.getProperty("java.io.tmpdir"); privatestatic Process process; publicstaticvoid main(String[] args) throws Exception { if (args.length == 0) { boolean testResultParallel
= createChildProcessWithParallelCollector();
String result = ""; if (!testResultParallel) {
result = "Test failed with Parallel collector";
} boolean testResultDefault
= createChildProcessWithDefaultCollector(); if (!testResultDefault && !testResultParallel) {
result += " and with default collector both.";
} elseif (!testResultDefault) {
result = "Test failed with default collector";
} if (!"".equals(result)) { thrownew RuntimeException(result);
}
} else {
testListFile(args[args.length - 1]);
}
}
//Memory used before calling listFiles long startmem = instance.totalMemory() - instance.freeMemory(); long start = System.currentTimeMillis(); long endmem = 0;
//Calling listFiles for 5 minutes with sleep of 10 ms. while ((System.currentTimeMillis() - start) < 300000) { try {
folder.listFiles(); Thread.sleep(10);
endmem = instance.totalMemory() - instance.freeMemory();
} catch (InterruptedException ex) {
Logger.getLogger(ShellFolderMemoryLeak.class.getName())
.log(Level.SEVERE, "InterruptedException", ex);
}
}
//Total increase in memory after 5 minutes long result = (endmem - startmem) / mb;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.