1 /*
2 * Copyright (c) 2003, 2010, 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 * @bug 4530538
27 * @summary Basic unit test of
28 * RuntimeMXBean.getObjectPendingFinalizationCount()
29 * 1. GC and runFinalization() to get the current pending number
30 * 2. Create some number of objects with reference and without ref.
31 * 3. Clear all the references
32 * 4. GC and runFinalization() and the finalizable objects should
33 * be garbage collected.
34 * @author Alexei Guibadoulline and Mandy Chung
35 *
36 */
37
38 import java.lang.management.*;
39
40 public class Pending {
41 final static int NO_REF_COUNT = 600;
42 final static int REF_COUNT = 500;
43 final static int TOTAL_FINALIZABLE = (NO_REF_COUNT + REF_COUNT);
44 private static int finalized = 0;
45 private static MemoryMXBean mbean
46 = ManagementFactory.getMemoryMXBean();
47
48 private static final String INDENT = " ";
49 private static void printFinalizerInstanceCount() {
50 if (!trace) return;
51
52 int count = sun.misc.VM.getFinalRefCount();
53 System.out.println(INDENT + "Finalizable object Count = " + count);
54
55 count = sun.misc.VM.getPeakFinalRefCount();
|
1 /*
2 * Copyright (c) 2003, 2015, 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 * @bug 4530538
27 * @modules java.base/sun.misc
28 * java.management
29 * @summary Basic unit test of
30 * RuntimeMXBean.getObjectPendingFinalizationCount()
31 * 1. GC and runFinalization() to get the current pending number
32 * 2. Create some number of objects with reference and without ref.
33 * 3. Clear all the references
34 * 4. GC and runFinalization() and the finalizable objects should
35 * be garbage collected.
36 * @author Alexei Guibadoulline and Mandy Chung
37 */
38
39 import java.lang.management.*;
40
41 public class Pending {
42 final static int NO_REF_COUNT = 600;
43 final static int REF_COUNT = 500;
44 final static int TOTAL_FINALIZABLE = (NO_REF_COUNT + REF_COUNT);
45 private static int finalized = 0;
46 private static MemoryMXBean mbean
47 = ManagementFactory.getMemoryMXBean();
48
49 private static final String INDENT = " ";
50 private static void printFinalizerInstanceCount() {
51 if (!trace) return;
52
53 int count = sun.misc.VM.getFinalRefCount();
54 System.out.println(INDENT + "Finalizable object Count = " + count);
55
56 count = sun.misc.VM.getPeakFinalRefCount();
|