Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d3b8eb09 authored by Carl Shapiro's avatar Carl Shapiro
Browse files

Remove minimum heap size test now that the underlying interface is gone.

Change-Id: I4431247286dfd93ad0c3af9ebbba2ece92c35308
parent fb0a242b
Loading
Loading
Loading
Loading
+0 −67
Original line number Diff line number Diff line
@@ -46,73 +46,6 @@ public class HeapTest extends TestCase {
        return new WeakReference<Object>(new Object());
    }

    /**
     * Allocates the specified number of bytes. This is done in a separate method
     * to ensure that the Object's address isn't sitting in a stale local register.
     */
    private void allocateMemory(int size) {
        byte[] b = new byte[size];
    }

    @MediumTest
    public void testMinimumHeapSize() throws Exception {
        VMRuntime r = VMRuntime.getRuntime();
        final boolean RUN_FLAKY = false;

        long origSize = r.getMinimumHeapSize();
        if (RUN_FLAKY) {
            /* Check that the default value is zero.  This will break if anyone
             * in this process sets the minimum heap size to a positive value
             * before calling this test.
             */
            assertTrue(origSize == 0);
        }

        long size = 4 * 1024 * 1024;
        long oldSize = r.setMinimumHeapSize(size);
        assertTrue(oldSize == origSize);

        long newSize = r.getMinimumHeapSize();
        /* This will fail if the maximum heap size (-Xmx) is smaller than 4MB.
         */
        assertTrue(newSize == size);

        /* Make sure that getting the size doesn't change anything.
         */
        newSize = r.getMinimumHeapSize();
        assertTrue(newSize == size);

        /* This test is flaky; if the heap is already large and fragmented,
         * it can fail.  It can also fail if another thread causes a GC
         * at the wrong time.
         */
        if (RUN_FLAKY) {
            /* Increase the minimum size, allocate a big object, and make sure that
             * a GC didn't happen.
             */
            WeakReference ref = newRef();
            assertNotNull(ref.get());

            r.setMinimumHeapSize(8 * 1024 * 1024);
            allocateMemory(4 * 1024 * 1024);

            /* If a GC happened, this reference will be null.
             */
            assertNotNull(ref.get());
        }

        /* Restore the original setting.
         */
        r.setMinimumHeapSize(origSize);
        newSize = r.getMinimumHeapSize();
        assertTrue(newSize == origSize);

        /* Clean up any large stuff we've allocated,
         * and re-establish the normal utilization ratio.
         */
        Runtime.getRuntime().gc();
    }

    private static void makeRefs(Object objects[], SoftReference<Object> refs[]) {
        for (int i = 0; i < objects.length; i++) {
            objects[i] = (Object) new byte[8 * 1024];