annotate test/gc/g1/TestEagerReclaimHumongousRegions2.java @ 20307:04d77ac27223

8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap Summary: Eager reclaim also needs to clear marks of eagerly reclaimed regions if they have already been marked during concurrent mark. Reviewed-by: jmasa
author tschatzl
date Thu, 31 Jul 2014 09:23:24 +0200
parents
children 2d1534aa7131
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
20307
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
1 /*
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
4 *
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
7 * published by the Free Software Foundation.
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
8 *
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
13 * accompanied this code).
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
14 *
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
18 *
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
21 * questions.
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
22 */
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
23
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
24 /*
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
25 * @test TestEagerReclaimHumongousRegions2
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
26 * @bug 8051973
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
27 * @summary Test to make sure that eager reclaim of humongous objects correctly clears
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
28 * mark bitmaps at reclaim.
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
29 * @key gc
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
30 * @library /testlibrary
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
31 */
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
32
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
33 import java.util.ArrayList;
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
34 import java.util.LinkedList;
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
35 import java.util.Random;
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
36
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
37 import com.oracle.java.testlibrary.OutputAnalyzer;
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
38 import com.oracle.java.testlibrary.ProcessTools;
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
39
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
40 // An object that has a few references to other instances to slow down marking.
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
41 class ObjectWithSomeRefs {
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
42 public ObjectWithSomeRefs other1;
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
43 public ObjectWithSomeRefs other2;
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
44 public ObjectWithSomeRefs other3;
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
45 public ObjectWithSomeRefs other4;
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
46 }
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
47
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
48 class ReclaimRegionFast {
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
49 public static final int M = 1024*1024;
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
50
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
51 public static LinkedList<Object> garbageList = new LinkedList<Object>();
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
52
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
53 public static void genGarbage(Object large) {
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
54 for (int i = 0; i < 64*1024; i++) {
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
55 Object[] garbage = new Object[50];
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
56 garbage[0] = large;
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
57 garbageList.add(garbage);
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
58 }
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
59 garbageList.clear();
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
60 }
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
61
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
62 public static ArrayList<ObjectWithSomeRefs> longList = new ArrayList<ObjectWithSomeRefs>();
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
63
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
64 public static void main(String[] args) {
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
65
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
66 for (int i = 0; i < 16*1024; i++) {
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
67 longList.add(new ObjectWithSomeRefs());
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
68 }
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
69
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
70 Random rnd = new Random();
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
71 for (int i = 0; i < longList.size(); i++) {
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
72 int len = longList.size();
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
73 longList.get(i).other1 = longList.get(rnd.nextInt(len));
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
74 longList.get(i).other2 = longList.get(rnd.nextInt(len));
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
75 longList.get(i).other3 = longList.get(rnd.nextInt(len));
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
76 longList.get(i).other4 = longList.get(rnd.nextInt(len));
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
77 }
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
78
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
79 int[] large1 = new int[M];
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
80 int[] large2 = null;
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
81 int[] large3 = null;
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
82 int[] large4 = null;
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
83
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
84 Object ref_from_stack = large1;
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
85
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
86 for (int i = 0; i < 20; i++) {
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
87 // A set of large objects that will be reclaimed eagerly - and hopefully marked.
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
88 large1 = new int[M - 20];
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
89 large2 = new int[M - 20];
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
90 large3 = new int[M - 20];
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
91 large4 = new int[M - 20];
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
92 genGarbage(large1);
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
93 // Make sure that the compiler cannot completely remove
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
94 // the allocation of the large object until here.
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
95 System.out.println(large1 + " " + large2 + " " + large3 + " " + large4);
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
96 }
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
97
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
98 // Keep the reference to the first object alive.
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
99 System.out.println(ref_from_stack);
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
100 }
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
101 }
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
102
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
103 public class TestEagerReclaimHumongousRegions2 {
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
104 public static void main(String[] args) throws Exception {
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
105 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
106 "-XX:+UseG1GC",
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
107 "-Xms128M",
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
108 "-Xmx128M",
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
109 "-Xmn2M",
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
110 "-XX:G1HeapRegionSize=1M",
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
111 "-XX:InitiatingHeapOccupancyPercent=0", // Want to have as much as possible initial marks.
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
112 "-XX:+PrintGC",
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
113 "-XX:+VerifyAfterGC",
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
114 "-XX:ConcGCThreads=1", // Want to make marking as slow as possible.
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
115 "-XX:+IgnoreUnrecognizedVMOptions", // G1VerifyBitmaps is develop only.
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
116 "-XX:+G1VerifyBitmaps",
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
117 ReclaimRegionFast.class.getName());
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
118 OutputAnalyzer output = new OutputAnalyzer(pb.start());
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
119 output.shouldHaveExitValue(0);
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
120 }
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
121 }
04d77ac27223 8051973: Eager reclaim leaves marks of marked but reclaimed objects on the next bitmap
tschatzl
parents:
diff changeset
122