Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/gc/gctests/mallocWithGC3/mallocWithGC3.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/mallocWithGC3.
29
* VM Testbase keywords: [gc]
30
* VM Testbase readme:
31
* ********************************************************
32
* LD_LIBRARY PATH must include "$TESTBASE/src/misc/gc/utils/lib/sparc(or i386)"
33
* while running these tests. The native code for all the mallocWithGC* tests
34
* has been bunched up into a single .so.
35
* ********************************************************
36
* In this test, 2 threads are created, one thread(javaHeapEater)
37
* creates garbage by nulling out the elements of a vector, which formerly
38
* held points to circular linked lists. These elements are again repopulated
39
* with new linked lists. The second thread invokes a native function
40
* that continually mallocs and frees one byte of memory for 3 minutes
41
* a hold on a malloc lock.
42
* In this test, the GC is called synchronously while another
43
* thread contines to malloc/free in a loop.
44
* The idea here is to see if the vm deadlocks (if it does, it is ofcourse
45
* a failure ). This test was created because of the following problem
46
* that the vm used to have :
47
* "The malloc/GC deadlock problem is that a gc may suspend a thread (in native
48
* or VM code) that is in the middle of a malloc, so it has the "malloc" lock.
49
* GC may want to do a malloc, but it can't get the lock, so it deadlocks. "
50
*
51
* @library /vmTestbase
52
* /test/lib
53
* @run main/othervm/native/timeout=300 gc.gctests.mallocWithGC3.mallocWithGC3
54
*/
55
56
package gc.gctests.mallocWithGC3;
57
58
import nsk.share.test.*;
59
import nsk.share.gc.*;
60
import java.util.Vector;
61
62
public class mallocWithGC3 extends TestBase {
63
static {
64
System.loadLibrary("mallocWithGC3");
65
}
66
67
public native void getMallocLock03();
68
69
private class javaHeapEater extends Thread {
70
private Vector v;
71
72
public javaHeapEater(Vector v) {
73
this.v = v;
74
}
75
76
public void run() throws OutOfMemoryError {
77
int gc_count;
78
79
for(int i = 0; i < 5 ; i++)
80
v.addElement(buildCircularLinkedList());
81
gc_count = 0;
82
83
while( gc_count < 10 ) {
84
for (int i = 0; i < 5 ; i++)
85
v.setElementAt(null, i);
86
87
System.gc(); // Forcibly call GC.
88
89
for (int i = 0; i < 5 ; i++)
90
v.setElementAt(buildCircularLinkedList(),i);
91
92
gc_count++;
93
log.info("Finished iteration # " + gc_count);
94
}
95
}
96
}
97
98
private class cHeapEater extends Thread {
99
public void run() {
100
getMallocLock03();
101
}
102
}
103
104
public void run() {
105
Vector v = new Vector(5);
106
Thread tArray[] = new Thread[2];
107
108
tArray[0] = new javaHeapEater(v);
109
tArray[1] = new cHeapEater();
110
111
112
try {
113
for(int i = 0; i < tArray.length ; i++ )
114
tArray[i].start();
115
for(int i = 0; i < tArray.length ; i++ )
116
tArray[i].join();
117
} catch (Exception e) {
118
setFailed(true);
119
}
120
}
121
122
// build a circular linked list of 0.4 Meg
123
private CircularLinkedList buildCircularLinkedList() {
124
CircularLinkedList cl;
125
126
cl = new CircularLinkedList(100);
127
for(int i = 0; i < 2000; i++)
128
cl.grow();
129
return cl;
130
}
131
132
public static void main(String args[]){
133
Tests.runTest(new mallocWithGC3(), args);
134
}
135
136
}
137
138