diff options
| author | 2017-07-06 15:30:10 +0100 | |
|---|---|---|
| committer | 2017-07-07 11:28:08 +0100 | |
| commit | 4b361a87520643c888a3d2c52dffa050fabd7a0b (patch) | |
| tree | 6864a78324a58c3c44895cb63bf86b21244250e1 /test/659-unpadded-array/src-art/Main.java | |
| parent | 4ca07d1e8033a823b1732499ead728c47ea023c7 (diff) | |
Fix region space when used with SetLengthToUsableSizeVisitor.
The region space relies on obj->SizeOf for some of its logic.
By having SetLengthToUsableSizeVisitor "change" the SizeOf
what's being allocated.
The bug happens during RegionSpace::ClearFromSpace: for unevac regions
we iterate over following regions. If LiveBytes != Top() - Begin()
(which happen for large allocations using SetLengthToUsableSizeVisitor),
we break the loop.
The next region to analyze is a large tail, and we see LiveBytes() == 0
(tails apparently always have live bytes == 0), the code is then
happy to release the large tail, even though the large object is still
live.
bug: 37187694
bug: 62889232
Test: 659-unpadded-array
Change-Id: Ia99b67256b0e28a80095bd5cdae9068ea5e8b4a8
Diffstat (limited to 'test/659-unpadded-array/src-art/Main.java')
| -rw-r--r-- | test/659-unpadded-array/src-art/Main.java | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/test/659-unpadded-array/src-art/Main.java b/test/659-unpadded-array/src-art/Main.java new file mode 100644 index 0000000000..80fd6e2f6f --- /dev/null +++ b/test/659-unpadded-array/src-art/Main.java @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2017 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. + */ + +import dalvik.system.VMRuntime; + +public class Main { + public static void main(String[] args) { + // Call our optimization API, we used to have a bug in the RegionSpace on large + // objects allocated through it. + Object[] o = (Object[]) VMRuntime.getRuntime().newUnpaddedArray(Object.class, 70000); + + // Make the test run for 30 seconds to be less dependent on GC heuristics. + long time = System.currentTimeMillis(); + int i = 1; + do { + allocateIntArray(i); + for (int j = 0; j < o.length; j++) { + if (o[j] != null) { + // Just print, not throw, to get into "interesting" issues (eg the first + // element that will not be null is the class of the object, the second is + // actually the first element of the int array). + System.out.println("Unexpected value: " + o[j]); + } + } + if (i < 100000) { + i++; + } else { + i = 0; + } + } while (System.currentTimeMillis() - time < 30000); + } + + static void allocateIntArray(int i) { + int[] intArray = new int[i]; + for (int j = 0; j < intArray.length; j++) { + intArray[j] = 1; + } + } +} |