Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/gc/gctests/FinalizeTest05/FinalizeTest05.java
41159 views
1
/*
2
* Copyright (c) 2009, 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
* @test
26
* @key stress randomness
27
*
28
* @summary converted from VM Testbase gc/gctests/FinalizeTest05.
29
* VM Testbase keywords: [gc, stress, stressopt, nonconcurrent]
30
*
31
* @library /vmTestbase
32
* /test/lib
33
* @run main/othervm -XX:-UseGCOverheadLimit gc.gctests.FinalizeTest05.FinalizeTest05
34
*/
35
36
package gc.gctests.FinalizeTest05;
37
38
import nsk.share.gc.*;
39
import java.util.*;
40
import nsk.share.TestFailure;
41
import nsk.share.test.ExecutionController;
42
import nsk.share.test.Stresser;
43
44
/**
45
*/
46
public class FinalizeTest05 extends GCTestBase {
47
48
private final int allocRatio = 5;
49
private final int size = 1024 * 2;
50
private int count = 1000;
51
private ExecutionController stresser;
52
53
private void runOne() {
54
ArrayList objs = new ArrayList(count);
55
Object o;
56
for (int i = 0; i < count; i++) {
57
if (i % allocRatio == 0) {
58
o = new FinMemoryObject(size);
59
objs.add(o);
60
} else {
61
o = new byte[size - Memory.getObjectExtraSize()];
62
}
63
}
64
FinMemoryObject.dumpStatistics();
65
o = null;
66
67
/* force finalization */
68
Algorithms.eatMemory(stresser);
69
System.gc();
70
Runtime.getRuntime().runFinalization();
71
System.gc();
72
Runtime.getRuntime().runFinalization();
73
74
FinMemoryObject.dumpStatistics();
75
76
boolean error;
77
System.out.println("Allocated: " + FinMemoryObject.getAllocatedCount());
78
System.out.println("Finalized: " + FinMemoryObject.getFinalizedCount());
79
error = (FinMemoryObject.getFinalizedCount() != 0);
80
81
// Just hit the objs array to do say VM that we use this object
82
// and it should be alive in this point.
83
objs.clear();
84
if (error) {
85
throw new TestFailure("Test failed.");
86
}
87
}
88
89
public void run() {
90
stresser = new Stresser(runParams.getStressOptions());
91
stresser.start(runParams.getIterations());
92
count = (int) Math.min(runParams.getTestMemory() / size, Integer.MAX_VALUE);
93
System.out.println("Allocating " + count
94
+ " objects. 1 out of " + allocRatio
95
+ " will have a finalizer.");
96
System.out.flush();
97
runOne();
98
}
99
100
public static void main(String[] args) {
101
GC.runTest(new FinalizeTest05(), args);
102
}
103
}
104
105