Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/gc/gctests/FinalizerGC01/FinalizerGC01.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/FinalizerGC01.
29
* VM Testbase keywords: [gc]
30
* VM Testbase readme:
31
* This rather contrived test checks the interplay of garbage collection
32
* and finalizers. Just before a 0.5 Meg linked list is garbage collected,
33
* the finalizer generates more garbage . The test fails if an OutOfMemoryError
34
* is thrown.
35
*
36
* @library /vmTestbase
37
* /test/lib
38
* @run main/othervm gc.gctests.FinalizerGC01.FinalizerGC01
39
*/
40
41
package gc.gctests.FinalizerGC01;
42
43
import nsk.share.TestFailure;
44
45
class node {
46
byte [] arr;
47
node next;
48
node prev;
49
node(int info){ arr = new byte[128]; }
50
}
51
52
class CircularLinkedList{
53
private void addElement(int info) {
54
node newnode;
55
newnode = new node(info);
56
if (Root == null){
57
Root = newnode;
58
Root.next = Root;
59
Root.prev = Root;
60
} else{
61
newnode.next = Root.next;
62
Root.next.prev = newnode;
63
Root.next = newnode;
64
newnode.prev = Root;
65
}
66
}
67
int elementCount() {
68
node p;
69
int count;
70
p = Root;
71
count = 0;
72
do {
73
p = p.prev;
74
count++;
75
}while(p != Root);
76
return count;
77
}
78
public void build1MegList() {
79
for (int i = 0 ; i < NELEMENTS ; i++)
80
addElement(i);
81
}
82
node Root=null;
83
static final int NELEMENTS=4096;
84
}
85
class CircularLinkedListFinal extends CircularLinkedList {
86
protected void finalize () {
87
CircularLinkedList cl = null;
88
// generate 1.5Meg more garbage
89
int i = 0;
90
int gcFails=0;
91
while (i < 3){
92
Root = null;
93
gcFails=0;
94
while (gcFails < NGCFAILS) {
95
try {
96
cl = new CircularLinkedList();
97
cl.build1MegList();
98
cl = null;
99
break;
100
}
101
catch (OutOfMemoryError e) {
102
System.gc();
103
gcFails++;
104
}
105
}
106
if (gcFails >= NGCFAILS) break;
107
i++;
108
}
109
if (i < 3) throw new OutOfMemoryError();
110
}
111
private static final int NGCFAILS=10;
112
}
113
114
public class FinalizerGC01 {
115
public static void main(String args[]) {
116
int count = 0;
117
int gcFails = 0;
118
CircularLinkedListFinal cl = null;
119
while (count < 64) {
120
gcFails = 0;
121
while (gcFails<NGCFAILS) {
122
try {
123
cl = new CircularLinkedListFinal();
124
cl.build1MegList();
125
doComputation();
126
cl = null;
127
break;
128
} catch (OutOfMemoryError e) {
129
gcFails++;
130
System.gc();
131
}
132
}
133
if (gcFails >= NGCFAILS) break;
134
count++;
135
}
136
if (count < 64)
137
throw new TestFailure("Test failed on " + count + " iteration");
138
else
139
System.out.println("Test Passed");
140
}
141
static void doComputation(){
142
long i = 0;
143
while ( i < 1000000L) { i++; }
144
}
145
private static final int NGCFAILS=10;
146
}
147
148