blob: 80fd6e2f6ff724bd27e615db8965285bc2ed1e69 [file] [log] [blame]
Nicolas Geoffray4b361a82017-07-06 15:30:10 +01001/*
2 * Copyright (C) 2017 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
17import dalvik.system.VMRuntime;
18
19public class Main {
20 public static void main(String[] args) {
21 // Call our optimization API, we used to have a bug in the RegionSpace on large
22 // objects allocated through it.
23 Object[] o = (Object[]) VMRuntime.getRuntime().newUnpaddedArray(Object.class, 70000);
24
25 // Make the test run for 30 seconds to be less dependent on GC heuristics.
26 long time = System.currentTimeMillis();
27 int i = 1;
28 do {
29 allocateIntArray(i);
30 for (int j = 0; j < o.length; j++) {
31 if (o[j] != null) {
32 // Just print, not throw, to get into "interesting" issues (eg the first
33 // element that will not be null is the class of the object, the second is
34 // actually the first element of the int array).
35 System.out.println("Unexpected value: " + o[j]);
36 }
37 }
38 if (i < 100000) {
39 i++;
40 } else {
41 i = 0;
42 }
43 } while (System.currentTimeMillis() - time < 30000);
44 }
45
46 static void allocateIntArray(int i) {
47 int[] intArray = new int[i];
48 for (int j = 0; j < intArray.length; j++) {
49 intArray[j] = 1;
50 }
51 }
52}