Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/serviceability/dcmd/gc/FinalizerInfoTest.java
32285 views
1
/*
2
* Copyright (c) 2015, 2017, 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
import com.oracle.java.testlibrary.JDKToolFinder;
25
import com.oracle.java.testlibrary.OutputAnalyzer;
26
import com.oracle.java.testlibrary.ProcessTools;
27
28
import java.util.concurrent.TimeUnit;
29
import java.util.concurrent.locks.Condition;
30
import java.util.concurrent.locks.ReentrantLock;
31
32
/*
33
* @test
34
* @summary
35
* @library /testlibrary
36
* @run main FinalizerInfoTest
37
*/
38
public class FinalizerInfoTest {
39
static ReentrantLock lock = new ReentrantLock();
40
static volatile int wasInitialized = 0;
41
static volatile int wasTrapped = 0;
42
static final String cmd = "GC.finalizer_info";
43
static final int objectsCount = 1000;
44
45
class MyObject {
46
public MyObject() {
47
// Make sure object allocation/deallocation is not optimized out
48
wasInitialized += 1;
49
}
50
51
protected void finalize() {
52
// Trap the object in a finalization queue
53
wasTrapped += 1;
54
lock.lock();
55
}
56
}
57
58
void run() throws Exception {
59
try {
60
lock.lock();
61
for(int i = 0; i < objectsCount; ++i) {
62
new MyObject();
63
}
64
System.out.println("Objects initialized: " + objectsCount);
65
System.gc();
66
67
while(wasTrapped < 1) {
68
// Waiting for gc thread.
69
}
70
71
72
String pid = Integer.toString(ProcessTools.getProcessId());
73
ProcessBuilder pb = new ProcessBuilder();
74
pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, cmd});
75
OutputAnalyzer output = new OutputAnalyzer(pb.start());
76
output.shouldContain("MyObject");
77
} finally {
78
lock.unlock();
79
}
80
}
81
82
public static void main(String[] args) throws Exception {
83
new FinalizerInfoTest().run();
84
}
85
86
87
}
88
89