Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/awt/shell/FileSystemViewMemoryLeak.java
41152 views
1
/*
2
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
* @test
26
* @bug 8175015
27
* @summary FileSystemView.isDrive(File) memory leak on "C:\" file reference
28
* @modules java.desktop/sun.awt.shell
29
* @requires (os.family == "windows")
30
* @run main/othervm/timeout=320 -Xmx8m FileSystemViewMemoryLeak
31
*/
32
import java.io.File;
33
import java.text.NumberFormat;
34
import java.util.concurrent.TimeUnit;
35
36
import javax.swing.filechooser.FileSystemView;
37
38
public class FileSystemViewMemoryLeak {
39
40
public static void main(String[] args) {
41
test();
42
}
43
44
// Will run the test no more than 300 seconds
45
static long endtime = System.nanoTime() + TimeUnit.SECONDS.toNanos(300);
46
47
private static void test() {
48
49
File root = new File("C:\\");
50
System.out.println("Root Exists: " + root.exists());
51
System.out.println("Root Absolute Path: " + root.getAbsolutePath());
52
System.out.println("Root Is Directory?: " + root.isDirectory());
53
54
FileSystemView fileSystemView = FileSystemView.getFileSystemView();
55
NumberFormat nf = NumberFormat.getNumberInstance();
56
57
int iMax = 50000;
58
long lastPercentFinished = 0L;
59
for (int i = 0; i < iMax; i++) {
60
if (isComplete()) {
61
System.out.println("Time is over");
62
return;
63
}
64
65
long percentFinished = Math.round(((i * 1000d) / (double) iMax));
66
67
if (lastPercentFinished != percentFinished) {
68
double pf = ((double) percentFinished) / 10d;
69
String pfMessage = String.valueOf(pf) + " % (" + i + "/" + iMax + ")";
70
71
long totalMemory = Runtime.getRuntime().totalMemory() / 1024;
72
long freeMemory = Runtime.getRuntime().freeMemory() / 1024;
73
long maxMemory = Runtime.getRuntime().maxMemory() / 1024;
74
String memMessage = "[Memory Used: " + nf.format(totalMemory) +
75
" kb Free=" + nf.format(freeMemory) +
76
" kb Max: " + nf.format(maxMemory) + " kb]";
77
78
System.out.println(pfMessage + " " + memMessage);
79
lastPercentFinished = percentFinished;
80
}
81
82
boolean floppyDrive = fileSystemView.isFloppyDrive(root);
83
boolean computerNode = fileSystemView.isComputerNode(root);
84
85
// "isDrive()" seems to be the painful method...
86
boolean drive = fileSystemView.isDrive(root);
87
}
88
}
89
90
private static boolean isComplete() {
91
return endtime - System.nanoTime() < 0;
92
}
93
}
94
95
96