Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/gc/gctests/FinalizerGC02/FinalizerGC02.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/FinalizerGC02.
29
* VM Testbase keywords: [gc]
30
* VM Testbase readme:
31
* In this contrived test, the finalizer creates more garbage. As the finalizer
32
* is invoked prior to garbage collection, this puts more stress on the
33
* garbage collector.
34
*
35
* @library /vmTestbase
36
* /test/lib
37
* @run main/othervm gc.gctests.FinalizerGC02.FinalizerGC02
38
*/
39
40
package gc.gctests.FinalizerGC02;
41
42
import nsk.share.TestFailure;
43
44
class node {
45
byte [] arr;
46
node next;
47
node prev;
48
node(int info){ arr = new byte[100]; }
49
}
50
51
class CircularLinkedList{
52
node Root;
53
54
private void addElement(int info) {
55
node newnode;
56
57
newnode = new node(info);
58
if (Root == null){
59
Root = newnode;
60
Root.next = Root;
61
Root.prev = Root;
62
} else {
63
newnode.next = Root.next;
64
Root.next.prev = newnode;
65
Root.next = newnode;
66
newnode.prev = Root;
67
}
68
}
69
70
int elementCount() {
71
node p;
72
int count;
73
74
p = Root;
75
count = 0;
76
77
do {
78
p = p.prev;
79
count++;
80
}while(p != Root);
81
return count;
82
}
83
84
public void buildNMegList(int N) {
85
for (int i = 0 ; i < N*10000 ; i++)
86
addElement(i);
87
}
88
89
protected void finalize () {
90
// generate 1Meg more garbage
91
FinalizerGC02.listHolder = new CircularLinkedList();
92
FinalizerGC02.listHolder.buildNMegList(1);
93
}
94
}
95
96
97
public class FinalizerGC02 {
98
99
static CircularLinkedList listHolder;
100
static int count;
101
static int returnCount() { return count; }
102
103
public static void main(String args[]) {
104
int memory_reserve[] = new int [1000];
105
106
listHolder = new CircularLinkedList();
107
listHolder.buildNMegList(1);
108
109
try {
110
while (count < 5) {
111
listHolder = new CircularLinkedList();
112
listHolder.buildNMegList(1);
113
count ++;
114
}
115
} catch (OutOfMemoryError e) {
116
memory_reserve = null;
117
System.gc();
118
throw new TestFailure("Test failed at " + count +"th iteration.");
119
}
120
System.out.println("Test Passed");
121
}
122
123
static void doComputation(){
124
long i = 0;
125
while ( i < 1000000) {
126
i ++;
127
}
128
}
129
}
130
131