Mercurial > hg > truffle
comparison 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 |
comparison
equal
deleted
inserted
replaced
20306:e02e18f40eae | 20307:04d77ac27223 |
---|---|
1 /* | |
2 * Copyright (c) 2014, 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 TestEagerReclaimHumongousRegions2 | |
26 * @bug 8051973 | |
27 * @summary Test to make sure that eager reclaim of humongous objects correctly clears | |
28 * mark bitmaps at reclaim. | |
29 * @key gc | |
30 * @library /testlibrary | |
31 */ | |
32 | |
33 import java.util.ArrayList; | |
34 import java.util.LinkedList; | |
35 import java.util.Random; | |
36 | |
37 import com.oracle.java.testlibrary.OutputAnalyzer; | |
38 import com.oracle.java.testlibrary.ProcessTools; | |
39 | |
40 // An object that has a few references to other instances to slow down marking. | |
41 class ObjectWithSomeRefs { | |
42 public ObjectWithSomeRefs other1; | |
43 public ObjectWithSomeRefs other2; | |
44 public ObjectWithSomeRefs other3; | |
45 public ObjectWithSomeRefs other4; | |
46 } | |
47 | |
48 class ReclaimRegionFast { | |
49 public static final int M = 1024*1024; | |
50 | |
51 public static LinkedList<Object> garbageList = new LinkedList<Object>(); | |
52 | |
53 public static void genGarbage(Object large) { | |
54 for (int i = 0; i < 64*1024; i++) { | |
55 Object[] garbage = new Object[50]; | |
56 garbage[0] = large; | |
57 garbageList.add(garbage); | |
58 } | |
59 garbageList.clear(); | |
60 } | |
61 | |
62 public static ArrayList<ObjectWithSomeRefs> longList = new ArrayList<ObjectWithSomeRefs>(); | |
63 | |
64 public static void main(String[] args) { | |
65 | |
66 for (int i = 0; i < 16*1024; i++) { | |
67 longList.add(new ObjectWithSomeRefs()); | |
68 } | |
69 | |
70 Random rnd = new Random(); | |
71 for (int i = 0; i < longList.size(); i++) { | |
72 int len = longList.size(); | |
73 longList.get(i).other1 = longList.get(rnd.nextInt(len)); | |
74 longList.get(i).other2 = longList.get(rnd.nextInt(len)); | |
75 longList.get(i).other3 = longList.get(rnd.nextInt(len)); | |
76 longList.get(i).other4 = longList.get(rnd.nextInt(len)); | |
77 } | |
78 | |
79 int[] large1 = new int[M]; | |
80 int[] large2 = null; | |
81 int[] large3 = null; | |
82 int[] large4 = null; | |
83 | |
84 Object ref_from_stack = large1; | |
85 | |
86 for (int i = 0; i < 20; i++) { | |
87 // A set of large objects that will be reclaimed eagerly - and hopefully marked. | |
88 large1 = new int[M - 20]; | |
89 large2 = new int[M - 20]; | |
90 large3 = new int[M - 20]; | |
91 large4 = new int[M - 20]; | |
92 genGarbage(large1); | |
93 // Make sure that the compiler cannot completely remove | |
94 // the allocation of the large object until here. | |
95 System.out.println(large1 + " " + large2 + " " + large3 + " " + large4); | |
96 } | |
97 | |
98 // Keep the reference to the first object alive. | |
99 System.out.println(ref_from_stack); | |
100 } | |
101 } | |
102 | |
103 public class TestEagerReclaimHumongousRegions2 { | |
104 public static void main(String[] args) throws Exception { | |
105 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( | |
106 "-XX:+UseG1GC", | |
107 "-Xms128M", | |
108 "-Xmx128M", | |
109 "-Xmn2M", | |
110 "-XX:G1HeapRegionSize=1M", | |
111 "-XX:InitiatingHeapOccupancyPercent=0", // Want to have as much as possible initial marks. | |
112 "-XX:+PrintGC", | |
113 "-XX:+VerifyAfterGC", | |
114 "-XX:ConcGCThreads=1", // Want to make marking as slow as possible. | |
115 "-XX:+IgnoreUnrecognizedVMOptions", // G1VerifyBitmaps is develop only. | |
116 "-XX:+G1VerifyBitmaps", | |
117 ReclaimRegionFast.class.getName()); | |
118 OutputAnalyzer output = new OutputAnalyzer(pb.start()); | |
119 output.shouldHaveExitValue(0); | |
120 } | |
121 } | |
122 |