blob: f4f697dc29749b2099188e1ddbac278b6a2c3b4f [file] [log] [blame]
Mathieu Chartierbba47a42012-05-30 10:53:58 -07001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Mathieu Chartierbba47a42012-05-30 10:53:58 -070017import java.util.Random;
18
Ian Rogersffb56002013-01-10 20:07:57 -080019public class Main {
Mathieu Chartierbba47a42012-05-30 10:53:58 -070020 private static final int buckets = 16 * 1024;
21 private static final int bufferSize = 1024;
22
23 static class ByteContainer {
24 public byte[] bytes;
25 }
26
27 public static void main(String[] args) throws Exception {
Ian Rogers35c360e2013-01-11 10:45:46 -080028 ByteContainer[] l = new ByteContainer[buckets];
Mathieu Chartierbba47a42012-05-30 10:53:58 -070029
Ian Rogers35c360e2013-01-11 10:45:46 -080030 for (int i = 0; i < buckets; ++i) {
31 l[i] = new ByteContainer();
32 }
33
34 Random rnd = new Random(123456);
35 for (int i = 0; i < buckets / 256; ++i) {
36 int index = rnd.nextInt(buckets);
37 l[index].bytes = new byte[bufferSize];
38
39 // Try to get GC to run if we can
40 Runtime.getRuntime().gc();
41
42 // Shuffle the array to try cause the lost object problem:
43 // This problem occurs when an object is white, it may be
44 // only referenced from a white or grey object. If the white
45 // object is moved during a CMS to be a black object's field, it
46 // causes the moved object to not get marked. This can result in
47 // heap corruption. A typical way to address this issue is by
48 // having a card table.
49 // This aspect of the test is meant to ensure that card
50 // dirtying works and that we check the marked cards after
51 // marking.
52 // If these operations are not done, a segfault / failed assert
53 // should occur.
54 for (int j = 0; j < l.length; ++j) {
55 int a = l.length - i - 1;
56 int b = rnd.nextInt(a);
57 byte[] temp = l[a].bytes;
58 l[a].bytes = l[b].bytes;
59 l[b].bytes = temp;
Mathieu Chartierbba47a42012-05-30 10:53:58 -070060 }
Mathieu Chartierbba47a42012-05-30 10:53:58 -070061 }
Ian Rogersffb56002013-01-10 20:07:57 -080062 System.out.println("Test complete");
Mathieu Chartierbba47a42012-05-30 10:53:58 -070063 }
64}