From a9033d73a118536ece62c7f90d7f56064b4298ab Mon Sep 17 00:00:00 2001 From: Mathieu Chartier Date: Thu, 1 Dec 2016 17:41:17 -0800 Subject: Add more detail to rosalloc fragmentation OOME Also include total number of free page bytes, space footprint, and space max capacity. Sample output: Throwing OutOfMemoryError "Failed to allocate a 7012 byte allocation with 103464 free bytes and 101KB until OOM; failed due to fragmentation (required continguous free 8192 bytes, largest contiguous free 4096 bytes, total free pages 4096 bytes, space footprint 268435456 bytes, space max capacity 268435456 bytes) Added a basic test to ensure the allocator coalesces properly. Bug: 32997082 Test: test-art-host Change-Id: I642b6ad34b98f6d98c10f242a6f6e926e0b42acc --- test/080-oom-fragmentation/src/Main.java | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 test/080-oom-fragmentation/src/Main.java (limited to 'test/080-oom-fragmentation/src/Main.java') diff --git a/test/080-oom-fragmentation/src/Main.java b/test/080-oom-fragmentation/src/Main.java new file mode 100644 index 0000000000..cf2113906f --- /dev/null +++ b/test/080-oom-fragmentation/src/Main.java @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +public class Main { + public static void main(String[] args) { + // Reserve around 1/4 of the RAM for keeping objects live. + long maxMem = Runtime.getRuntime().maxMemory(); + Object[] holder = new Object[(int)maxMem / 16]; + int count = 0; + try { + while (true) { + holder[count++] = new Object[1025]; // A bit over one page. + } + } catch (OutOfMemoryError e) {} + for (int i = 0; i < count; ++i) { + holder[i] = null; + } + // Make sure the heap can handle allocating large object array. This makes sure that free + // pages are correctly coalesced together by the allocator. + holder[0] = new Object[(int)maxMem / 8]; + } +} -- cgit v1.2.3-59-g8ed1b