Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/java2d/Disposer/TestDisposerLeak.java
41149 views
1
/*
2
* Copyright (c) 2015, 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
import java.util.LinkedList;
25
import java.util.List;
26
27
import sun.java2d.Disposer;
28
import sun.java2d.DisposerRecord;
29
30
/**
31
* @test
32
* @bug 8129457
33
* @summary Check Disposer disposes all objects without any memory leaks
34
* @run main/othervm -mx128m TestDisposerLeak
35
* @modules java.desktop/sun.java2d
36
*/
37
public final class TestDisposerLeak {
38
39
private static final int COUNT = 30000;
40
41
private static volatile boolean disposerComplete;
42
43
private static volatile boolean readyForDispose;
44
45
static int disposeCount = 0;
46
47
public static void main(String[] args) throws Exception {
48
TestDisposerLeak test = new TestDisposerLeak();
49
test.testLeak();
50
while (!disposerComplete) {}
51
if (disposeCount != COUNT) {
52
System.err.println("dispose called " + disposeCount);
53
throw new RuntimeException("All objects are not disposed");
54
}else {
55
System.out.println("Test PASSED");
56
}
57
}
58
59
public void testLeak() throws Exception {
60
MyDisposerRec disposerRecord = new MyDisposerRec();
61
for (int i = 0; i < 30000; i++) {
62
Disposer.addObjectRecord(new Object(), disposerRecord);
63
}
64
generateOOME();
65
readyForDispose = true;
66
Disposer.addObjectRecord(new Object(), new EndRec());
67
generateOOME();
68
}
69
70
class MyDisposerRec implements DisposerRecord, Disposer.PollDisposable {
71
72
public void dispose() {
73
while (!readyForDispose) {}
74
disposeCount++;
75
Disposer.pollRemove();
76
}
77
}
78
79
class EndRec implements DisposerRecord, Disposer.PollDisposable {
80
81
public void dispose() {
82
disposerComplete = true;
83
}
84
}
85
86
private static void generateOOME() throws Exception {
87
List<Object> leak = new LinkedList<>();
88
try {
89
while (true) {
90
leak.add(new byte[1024 * 1024]);
91
}
92
} catch (OutOfMemoryError e) {
93
}
94
// Give the GC a chance at that weakref in case of slow systems
95
Thread.sleep(2000);
96
}
97
}
98
99