blob: cf2113906f237e354e80a0efc19549c0a81f2471 [file] [log] [blame]
Mathieu Chartiera9033d72016-12-01 17:41:17 -08001/*
2 * Copyright (C) 2016 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
17public class Main {
18 public static void main(String[] args) {
19 // Reserve around 1/4 of the RAM for keeping objects live.
20 long maxMem = Runtime.getRuntime().maxMemory();
21 Object[] holder = new Object[(int)maxMem / 16];
22 int count = 0;
23 try {
24 while (true) {
25 holder[count++] = new Object[1025]; // A bit over one page.
26 }
27 } catch (OutOfMemoryError e) {}
28 for (int i = 0; i < count; ++i) {
29 holder[i] = null;
30 }
31 // Make sure the heap can handle allocating large object array. This makes sure that free
32 // pages are correctly coalesced together by the allocator.
33 holder[0] = new Object[(int)maxMem / 8];
34 }
35}