author | prr |
Fri, 25 May 2018 12:12:24 -0700 | |
changeset 50347 | b2f046ae8eb6 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
34400
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
1 |
/* |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
2 |
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
4 |
* |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
8 |
* |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
13 |
* accompanied this code). |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
14 |
* |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
18 |
* |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
21 |
* questions. |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
22 |
*/ |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
23 |
|
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
24 |
/* |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
25 |
* @test |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
26 |
* @bug 8030099 |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
27 |
* @summary Memory usage of java process increases |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
28 |
after calling Win32ShellFolder:listFiles |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
29 |
multiple times on some directory with |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
30 |
large number of files/folders |
35315 | 31 |
* @modules java.desktop/sun.awt.shell |
34400
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
32 |
* @requires (os.family == "windows") |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
33 |
* @run main/timeout=1000 ShellFolderMemoryLeak |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
34 |
*/ |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
35 |
import java.io.BufferedReader; |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
36 |
import java.io.File; |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
37 |
import java.io.FileNotFoundException; |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
38 |
import java.io.IOException; |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
39 |
import java.io.InputStream; |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
40 |
import java.io.InputStreamReader; |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
41 |
import java.util.logging.Level; |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
42 |
import java.util.logging.Logger; |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
43 |
import sun.awt.shell.ShellFolder; |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
44 |
|
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
45 |
public class ShellFolderMemoryLeak { |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
46 |
|
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
47 |
private final static String tempDir = System.getProperty("java.io.tmpdir"); |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
48 |
private static Process process; |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
49 |
public static void main(String[] args) throws Exception { |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
50 |
if (args.length == 0) { |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
51 |
boolean testResultParallel |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
52 |
= createChildProcessWithParallelCollector(); |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
53 |
String result = ""; |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
54 |
if (!testResultParallel) { |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
55 |
result = "Test failed with Parallel collector"; |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
56 |
} |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
57 |
boolean testResultDefault |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
58 |
= createChildProcessWithDefaultCollector(); |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
59 |
if (!testResultDefault && !testResultParallel) { |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
60 |
result += " and with default collector both."; |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
61 |
} else if (!testResultDefault) { |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
62 |
result = "Test failed with default collector"; |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
63 |
} |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
64 |
if (!"".equals(result)) { |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
65 |
throw new RuntimeException(result); |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
66 |
} |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
67 |
} else { |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
68 |
testListFile(args[args.length - 1]); |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
69 |
} |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
70 |
} |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
71 |
|
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
72 |
public static boolean createChildProcessWithDefaultCollector() |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
73 |
throws Exception { |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
74 |
String testDirectory = "TestDirectory1"; |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
75 |
testDirectory = tempDir + testDirectory +File.separator; |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
76 |
createTestData(testDirectory); |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
77 |
return runProcess("", testDirectory); |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
78 |
} |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
79 |
|
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
80 |
public static boolean createChildProcessWithParallelCollector() |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
81 |
throws Exception { |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
82 |
String testDirectory = "TestDirectory2"; |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
83 |
testDirectory = tempDir + testDirectory +File.separator; |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
84 |
createTestData(testDirectory); |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
85 |
return runProcess(" -XX:+UseParallelGC", testDirectory); |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
86 |
} |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
87 |
|
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
88 |
public static boolean runProcess(String arg1, String arg2) throws Exception { |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
89 |
String javaPath = System.getProperty("java.home"); |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
90 |
String classPathDir = System.getProperty("java.class.path"); |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
91 |
|
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
92 |
//creating java process which run same class with different Xmx value |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
93 |
String command = javaPath + File.separator + "bin" + File.separator |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
94 |
+ "java -Xmx256M" + arg1 + " -cp " |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
95 |
+ classPathDir |
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
36511
diff
changeset
|
96 |
+ " --add-exports=java.desktop/sun.awt.shell=ALL-UNNAMED" |
34400
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
97 |
+ " ShellFolderMemoryLeak " + arg2; |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
98 |
process = Runtime.getRuntime().exec(command); |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
99 |
BufferedReader input = null; |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
100 |
InputStream errorStream = null; |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
101 |
String line = null; |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
102 |
try { |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
103 |
int exitVal = process.waitFor(); |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
104 |
input = new BufferedReader(new InputStreamReader( |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
105 |
process.getInputStream())); |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
106 |
while ((line = input.readLine()) != null) { |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
107 |
} |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
108 |
errorStream = process.getErrorStream(); |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
109 |
if (checkExceptions(errorStream) || exitVal != 0) { |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
110 |
return false; |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
111 |
} |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
112 |
} catch (IllegalThreadStateException e) { |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
113 |
throw new RuntimeException(e); |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
114 |
} finally { |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
115 |
if (input != null) { |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
116 |
input.close(); |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
117 |
} |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
118 |
if (errorStream != null) { |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
119 |
errorStream.close(); |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
120 |
} |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
121 |
process.destroy(); |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
122 |
} |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
123 |
return true; |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
124 |
} |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
125 |
|
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
126 |
public static boolean checkExceptions(InputStream in) throws IOException { |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
127 |
String tempString; |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
128 |
int count = in.available(); |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
129 |
boolean exception = false; |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
130 |
while (count > 0) { |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
131 |
byte[] b = new byte[count]; |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
132 |
in.read(b); |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
133 |
tempString = new String(b); |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
134 |
if (!exception) { |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
135 |
exception = tempString.contains("RunTimeException"); |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
136 |
} |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
137 |
count = in.available(); |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
138 |
} |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
139 |
return exception; |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
140 |
} |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
141 |
|
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
142 |
private static void createTestData(String testDirectory) { |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
143 |
String folder = "folder_"; |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
144 |
File testFolder = new File(testDirectory); |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
145 |
if (testFolder.exists()) { |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
146 |
clearTestData(testDirectory); |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
147 |
} else { |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
148 |
if (testFolder.mkdir()) { |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
149 |
for (int inx = 0; inx < 100; inx++) { |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
150 |
new File(testFolder + File.separator + folder + inx).mkdir(); |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
151 |
} |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
152 |
} else { |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
153 |
throw new RuntimeException("Failed to create testDirectory"); |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
154 |
} |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
155 |
} |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
156 |
} |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
157 |
|
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
158 |
public static void deleteDirectory(File file) |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
159 |
throws IOException { |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
160 |
|
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
161 |
if (file.isDirectory()) { |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
162 |
if (file.list().length == 0) { |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
163 |
file.delete(); |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
164 |
} else { |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
165 |
String files[] = file.list(); |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
166 |
for (String temp : files) { |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
167 |
File fileDelete = new File(file, temp); |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
168 |
deleteDirectory(fileDelete); |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
169 |
} |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
170 |
if (file.list().length == 0) { |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
171 |
file.delete(); |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
172 |
} |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
173 |
} |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
174 |
} |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
175 |
} |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
176 |
|
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
177 |
private static void testListFile(String testDirectory) { |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
178 |
try { |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
179 |
int mb = 1024 * 1024; |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
180 |
ShellFolder folder = ShellFolder.getShellFolder( |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
181 |
new File(testDirectory)); |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
182 |
Runtime instance = Runtime.getRuntime(); |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
183 |
|
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
184 |
//Memory used before calling listFiles |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
185 |
long startmem = instance.totalMemory() - instance.freeMemory(); |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
186 |
long start = System.currentTimeMillis(); |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
187 |
long endmem = 0; |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
188 |
|
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
189 |
//Calling listFiles for 5 minutes with sleep of 10 ms. |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
190 |
while ((System.currentTimeMillis() - start) < 300000) { |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
191 |
try { |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
192 |
folder.listFiles(); |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
193 |
Thread.sleep(10); |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
194 |
endmem = instance.totalMemory() - instance.freeMemory(); |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
195 |
} catch (InterruptedException ex) { |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
196 |
Logger.getLogger(ShellFolderMemoryLeak.class.getName()) |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
197 |
.log(Level.SEVERE, "InterruptedException", ex); |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
198 |
} |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
199 |
} |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
200 |
|
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
201 |
//Total increase in memory after 5 minutes |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
202 |
long result = (endmem - startmem) / mb; |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
203 |
|
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
204 |
if (result > 100) { |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
205 |
clearTestData(testDirectory); |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
206 |
throw new RuntimeException("Test Failed"); |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
207 |
} |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
208 |
clearTestData(testDirectory); |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
209 |
} catch (FileNotFoundException ex) { |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
210 |
if(process != null && process.isAlive()) { |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
211 |
process.destroy(); |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
212 |
} |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
213 |
Logger.getLogger(ShellFolderMemoryLeak.class.getName()) |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
214 |
.log(Level.SEVERE, "File Not Found Exception", ex); |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
215 |
} |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
216 |
} |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
217 |
|
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
218 |
private static void clearTestData(String testDirectory) { |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
219 |
File testFolder = new File(testDirectory); |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
220 |
try { |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
221 |
deleteDirectory(testFolder); |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
222 |
} catch (IOException ex) { |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
223 |
Logger.getLogger(ShellFolderMemoryLeak.class.getName()) |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
224 |
.log(Level.SEVERE, "Unable to delete files", ex); |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
225 |
} |
8f60c2783555
8030099: Memory usage of java process increases after pressing start button in test window
rchamyal
parents:
diff
changeset
|
226 |
} |
35315 | 227 |
} |