Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/gc/gctests/MTasyncGC/MTasyncGC.java
41155 views
1
/*
2
* Copyright (c) 2002, 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
*
27
* @summary converted from VM Testbase gc/gctests/MTasyncGC.
28
* VM Testbase keywords: [gc]
29
* VM Testbase readme:
30
* This test creates 1000 threads that run in a sequential
31
* fashion with each thread in turn generating 1Meg of garbage.
32
* The test relies upon the garbage collector asynchrnonously
33
* reclaiming garbage.
34
* The test fails if an OutOfMemoryError is thrown and passes
35
* if the test proceeds to completion without an exception being
36
* thrown.
37
*
38
* @library /vmTestbase
39
* /test/lib
40
* @run main/othervm gc.gctests.MTasyncGC.MTasyncGC
41
*/
42
43
package gc.gctests.MTasyncGC;
44
45
import java.util.Vector;
46
import nsk.share.TestFailure;
47
48
// Each thread creates 1Meg of garbage in the run() method.
49
50
class MemEvil extends Thread {
51
static Vector v = new Vector();
52
static {
53
for(int i = 0; i < 10; i++)
54
v.addElement(new char [100000]);
55
}
56
57
public void run () {
58
int i = 0;
59
while(i < 10) {
60
v.setElementAt(new char[100000], i);
61
i++;
62
}
63
}
64
}
65
66
67
public class MTasyncGC {
68
69
public static void main(String args[] ){
70
int i;
71
int memory_reserve[] = new int [10000];
72
Thread threadsHolder[] = new Thread[1000];
73
74
for(i = 0; i < threadsHolder.length; i++)
75
threadsHolder[i] = new MemEvil();
76
77
i = 0;
78
while(i < threadsHolder.length ){
79
try {
80
threadsHolder[i].start();
81
threadsHolder[i].join();
82
} catch ( Exception e ) {
83
memory_reserve = null;
84
System.gc();
85
throw new TestFailure("Test Failed.", e);
86
}
87
threadsHolder[i] = null;
88
i++;
89
}
90
}
91
}
92
93