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