blob: 1a9e88eba2dd01b1c33c1a43fb2c3ea633c19eda [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 {
28 try {
29 ByteContainer[] l = new ByteContainer[buckets];
30
31 for (int i = 0; i < buckets; ++i) {
32 l[i] = new ByteContainer();
33 }
34
35 Random rnd = new Random(123456);
36 for (int i = 0; i < buckets / 256; ++i) {
37 int index = rnd.nextInt(buckets);
38 l[index].bytes = new byte[bufferSize];
39
40 // Try to get GC to run if we can
41 Runtime.getRuntime().gc();
42
43 // Shuffle the array to try cause the lost object problem:
44 // This problem occurs when an object is white, it may be
45 // only referenced from a white or grey object. If the white
46 // object is moved during a CMS to be a black object's field, it
47 // causes the moved object to not get marked. This can result in
48 // heap corruption. A typical way to address this issue is by
49 // having a card table.
50 // This aspect of the test is meant to ensure that card
51 // dirtying works and that we check the marked cards after
52 // marking.
53 // If these operations are not done, a segfault / failed assert
54 // should occur.
55 for (int j = 0; j < l.length; ++j) {
56 int a = l.length - i - 1;
57 int b = rnd.nextInt(a);
58 byte[] temp = l[a].bytes;
59 l[a].bytes = l[b].bytes;
60 l[b].bytes = temp;
61 }
62 }
63 } catch (OutOfMemoryError e) {
64 }
Ian Rogersffb56002013-01-10 20:07:57 -080065 System.out.println("Test complete");
Mathieu Chartierbba47a42012-05-30 10:53:58 -070066 }
67}