Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/gc/gctests/mallocWithGC1/mallocWithGC1.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/mallocWithGC1.
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 idea here is to see if the vm deadlocks (if it does, it is ofcourse
41
* a failure ). This test was created because of the following problem
42
* that the vm used to have :
43
* "The malloc/GC deadlock problem is that a gc may suspend a thread (in native
44
* or VM code) that is in the middle of a malloc, so it has the "malloc" lock.
45
* GC may want to do a malloc, but it can't get the lock, so it deadlocks. "
46
*
47
* @library /vmTestbase
48
* /test/lib
49
* @run main/othervm/native/timeout=300 gc.gctests.mallocWithGC1.mallocWithGC1
50
*/
51
52
package gc.gctests.mallocWithGC1;
53
54
import nsk.share.test.*;
55
import nsk.share.gc.*;
56
import nsk.share.TestFailure;
57
import java.util.Vector;
58
59
public class mallocWithGC1 implements Test {
60
private int objectSize = 100;
61
62
static {
63
System.loadLibrary("mallocWithGC1");
64
}
65
66
public native void getMallocLock01();
67
68
class javaHeapEater extends Thread {
69
private Vector v;
70
71
public javaHeapEater(Vector v) {
72
this.v = v;
73
}
74
75
public void run() throws OutOfMemoryError {
76
int gc_count;
77
78
for(int i = 0; i < 5 ; i++)
79
v.addElement(buildCircularLinkedList());
80
gc_count = 0;
81
while( gc_count < 10 ) {
82
83
for(int i = 0; i < 5 ; i++)
84
v.setElementAt(null, i);
85
86
for(int i = 0; i < 5 ; i++)
87
v.setElementAt(buildCircularLinkedList(),i);
88
89
gc_count++;
90
System.out.println("Finished iteration # " + gc_count);
91
}
92
}
93
}
94
95
class cHeapEater extends Thread{
96
public void run() {
97
getMallocLock01();
98
}
99
}
100
101
public void run() {
102
Vector v = new Vector(5);
103
Thread tArray[] = new Thread[2];
104
105
tArray[0] = new javaHeapEater(v);
106
tArray[1] = new cHeapEater();
107
108
try {
109
for(int i = 0; i < tArray.length ; i++ )
110
tArray[i].start();
111
for(int i = 0; i < tArray.length ; i++ )
112
tArray[i].join();
113
} catch (Exception e) {
114
throw new TestFailure("Test Failed.", e);
115
}
116
System.out.println("Test Passed.");
117
}
118
119
// build a circular linked list of 0.2 Meg
120
121
private CircularLinkedList buildCircularLinkedList() {
122
CircularLinkedList cl = new CircularLinkedList(objectSize);
123
for(int i = 0; i < 2000; i++)
124
cl.grow();
125
return cl;
126
}
127
128
public static void main(String args[]){
129
Tests.runTest(new mallocWithGC1(), args);
130
}
131
}
132
133