Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/gc/gctests/mallocWithGC2/mallocWithGC2.java
41161 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/mallocWithGC2.
29
* VM Testbase keywords: [gc]
30
* VM Testbase readme:
31
* LD_LIBRARY PATH must include "$TESTBASE/src/misc/gc/utils/lib/sparc(or i386)"
32
* while running these tests. The native code for all the mallocWithGC* tests
33
* has been bunched up into a single .so.
34
* In this test, 2 threads are created, one thread(javaHeapEater)
35
* creates garbage by nulling out the elements of a vector, which formerly
36
* held points to circular linked lists. These elements are again repopulated
37
* with new linked lists. The second thread invokes a native function
38
* that continually mallocs and frees one byte of memory for 3 minutes
39
* a hold on a malloc lock.
40
* The difference between mallocWithGC1 mallocWithGC2 is the way the locks
41
* are held. here the "malloc" lock is more efficiently held, not by
42
* the expiration of a timer but as long as the java heap devourer thread
43
* stays alive.
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 gc.gctests.mallocWithGC2.mallocWithGC2
54
*/
55
56
package gc.gctests.mallocWithGC2;
57
58
import nsk.share.test.*;
59
import nsk.share.gc.*;
60
import nsk.share.TestFailure;
61
import java.util.Vector;
62
63
public class mallocWithGC2 extends TestBase {
64
static {
65
System.loadLibrary("mallocWithGC2");
66
}
67
68
public native void getMallocLock02();
69
70
private class javaHeapEater extends Thread {
71
private Vector v;
72
73
javaHeapEater(Vector v) {
74
this.v = v;
75
}
76
77
public void run() throws OutOfMemoryError {
78
int gc_count;
79
80
for(int i = 0; i < 10 ; i++)
81
v.addElement(buildCircularLinkedList());
82
gc_count = 0;
83
while( gc_count < 10 ) {
84
85
for(int i = 0; i < 10 ; i++)
86
v.setElementAt(null, i);
87
88
for(int i = 0; i < 10 ; i++)
89
v.setElementAt(buildCircularLinkedList(),i);
90
91
gc_count++;
92
log.info("Finished iteration # " + gc_count);
93
}
94
}
95
}
96
97
98
private class cHeapEater extends Thread{
99
public void run() {
100
getMallocLock02();
101
}
102
}
103
104
public void run() {
105
Vector v = new Vector(10);
106
Thread tArray[] = new Thread[2];
107
108
tArray[0] = new javaHeapEater(v);
109
tArray[1] = new cHeapEater();
110
111
try {
112
for(int i = 0; i < tArray.length ; i++ )
113
tArray[i].start();
114
115
tArray[0].join(); // wait for the javaHeapEater Thread to finish
116
tArray[1].stop(); // Once javaHeapEater is finished, stop the
117
// the cHeapEater thread.
118
} catch (Exception e) {
119
throw new TestFailure("Test Failed.", e);
120
}
121
log.info("Test Passed.");
122
}
123
124
// build a circular linked list of 0.2 Meg
125
126
private CircularLinkedList buildCircularLinkedList() {
127
CircularLinkedList cl;
128
129
cl = new CircularLinkedList(100);
130
for(int i = 0; i < 2000; i++)
131
cl.grow();
132
return cl;
133
}
134
135
public static void main(String args[]) {
136
Tests.runTest(new mallocWithGC2(), args);
137
}
138
139
}
140
141