blob: 32537d69c540809dec7896dc30e7ddbd11e42ee3 [file] [log] [blame]
jeffhaoc1160702011-10-27 15:48:45 -07001/*
2 * Copyright (C) 2011 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 java.util.ArrayList;
18import java.util.Arrays;
19import java.util.Collections;
20import java.util.HashMap;
21import java.util.List;
22import java.util.Map;
23
24public class GrowthLimit {
25
26 public static void main(String[] args) throws Exception {
27
28 int alloc1 = 1;
29 try {
30 List<byte[]> l = new ArrayList<byte[]>();
31 while (true) {
32 // Allocate a MB at a time
33 l.add(new byte[1048576]);
34 alloc1++;
35 }
36 } catch (OutOfMemoryError e) {
37 }
38 // Expand the heap to the maximum size
39 dalvik.system.VMRuntime.getRuntime().clearGrowthLimit();
40
41 int alloc2 = 1;
42 try {
43 List<byte[]> l = new ArrayList<byte[]>();
44 while (true) {
45 // Allocate a MB at a time
46 l.add(new byte[1048576]);
47 alloc2++;
48 }
49 } catch (OutOfMemoryError e2) {
50 if (alloc1 > alloc2) {
51 System.out.println("ERROR: Allocated less memory after growth" +
52 "limit cleared (" + alloc1 + " MBs > " + alloc2 + " MBs");
53 System.exit(1);
54 }
55 }
56 }
57}