8042310: TestStringDeduplicationMemoryUsage test failing

Fri, 30 May 2014 10:43:51 +0200

author
pliden
date
Fri, 30 May 2014 10:43:51 +0200
changeset 6707
660b3f6bf7d7
parent 6706
f644f1468780
child 6708
4a1062dc52d1
child 6709
73c839dda17e
child 6711
dbf0d88d867d

8042310: TestStringDeduplicationMemoryUsage test failing
Reviewed-by: ehelin, jwilhelm

test/gc/g1/TestStringDeduplicationMemoryUsage.java file | annotate | diff | comparison | revisions
test/gc/g1/TestStringDeduplicationTools.java file | annotate | diff | comparison | revisions
     1.1 --- a/test/gc/g1/TestStringDeduplicationMemoryUsage.java	Tue Jun 03 06:10:34 2014 +0000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,36 +0,0 @@
     1.4 -/*
     1.5 - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
     1.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 - *
     1.8 - * This code is free software; you can redistribute it and/or modify it
     1.9 - * under the terms of the GNU General Public License version 2 only, as
    1.10 - * published by the Free Software Foundation.
    1.11 - *
    1.12 - * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 - * version 2 for more details (a copy is included in the LICENSE file that
    1.16 - * accompanied this code).
    1.17 - *
    1.18 - * You should have received a copy of the GNU General Public License version
    1.19 - * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 - *
    1.22 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 - * or visit www.oracle.com if you need additional information or have any
    1.24 - * questions.
    1.25 - */
    1.26 -
    1.27 -/*
    1.28 - * @test TestStringDeduplicationMemoryUsage
    1.29 - * @summary Test string deduplication memory usage
    1.30 - * @bug 8029075
    1.31 - * @key gc
    1.32 - * @library /testlibrary
    1.33 - */
    1.34 -
    1.35 -public class TestStringDeduplicationMemoryUsage {
    1.36 -    public static void main(String[] args) throws Exception {
    1.37 -        TestStringDeduplicationTools.testMemoryUsage();
    1.38 -    }
    1.39 -}
     2.1 --- a/test/gc/g1/TestStringDeduplicationTools.java	Tue Jun 03 06:10:34 2014 +0000
     2.2 +++ b/test/gc/g1/TestStringDeduplicationTools.java	Fri May 30 10:43:51 2014 +0200
     2.3 @@ -294,55 +294,6 @@
     2.4          }
     2.5      }
     2.6  
     2.7 -    private static class MemoryUsageTest {
     2.8 -        public static void main(String[] args) {
     2.9 -            System.out.println("Begin: MemoryUsageTest");
    2.10 -
    2.11 -            final boolean useStringDeduplication = Boolean.parseBoolean(args[0]);
    2.12 -            final int numberOfStrings = LargeNumberOfStrings;
    2.13 -            final int numberOfUniqueStrings = 1;
    2.14 -
    2.15 -            ArrayList<String> list = createStrings(numberOfStrings, numberOfUniqueStrings);
    2.16 -            forceDeduplication(DefaultAgeThreshold, FullGC);
    2.17 -
    2.18 -            if (useStringDeduplication) {
    2.19 -                verifyStrings(list, numberOfUniqueStrings);
    2.20 -            }
    2.21 -
    2.22 -            System.gc();
    2.23 -
    2.24 -            System.out.println("Heap Memory Usage: " + ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed());
    2.25 -            System.out.println("Array Header Size: " + unsafe.ARRAY_CHAR_BASE_OFFSET);
    2.26 -
    2.27 -            System.out.println("End: MemoryUsageTest");
    2.28 -        }
    2.29 -
    2.30 -        public static OutputAnalyzer run(boolean useStringDeduplication) throws Exception {
    2.31 -            String[] extraArgs = new String[0];
    2.32 -
    2.33 -            if (useStringDeduplication) {
    2.34 -                extraArgs = new String[] {
    2.35 -                    "-XX:+UseStringDeduplication",
    2.36 -                    "-XX:+PrintStringDeduplicationStatistics",
    2.37 -                    "-XX:StringDeduplicationAgeThreshold=" + DefaultAgeThreshold
    2.38 -                };
    2.39 -            }
    2.40 -
    2.41 -            String[] defaultArgs = new String[] {
    2.42 -                "-XX:+PrintGC",
    2.43 -                "-XX:+PrintGCDetails",
    2.44 -                MemoryUsageTest.class.getName(),
    2.45 -                "" + useStringDeduplication
    2.46 -            };
    2.47 -
    2.48 -            ArrayList<String> args = new ArrayList<String>();
    2.49 -            args.addAll(Arrays.asList(extraArgs));
    2.50 -            args.addAll(Arrays.asList(defaultArgs));
    2.51 -
    2.52 -            return runTest(args.toArray(new String[args.size()]));
    2.53 -        }
    2.54 -    }
    2.55 -
    2.56      /*
    2.57       * Tests
    2.58       */
    2.59 @@ -480,44 +431,4 @@
    2.60          OutputAnalyzer output = InternedTest.run();
    2.61          output.shouldHaveExitValue(0);
    2.62      }
    2.63 -
    2.64 -    public static void testMemoryUsage() throws Exception {
    2.65 -        // Test that memory usage is reduced after deduplication
    2.66 -        OutputAnalyzer output;
    2.67 -        final String heapMemoryUsagePattern = "Heap Memory Usage: (\\d+)";
    2.68 -        final String arrayHeaderSizePattern = "Array Header Size: (\\d+)";
    2.69 -
    2.70 -        // Run without deduplication
    2.71 -        output = MemoryUsageTest.run(false);
    2.72 -        output.shouldHaveExitValue(0);
    2.73 -        final long heapMemoryUsageWithoutDedup = Long.parseLong(output.firstMatch(heapMemoryUsagePattern, 1));
    2.74 -        final long arrayHeaderSizeWithoutDedup = Long.parseLong(output.firstMatch(arrayHeaderSizePattern, 1));
    2.75 -
    2.76 -        // Run with deduplication
    2.77 -        output = MemoryUsageTest.run(true);
    2.78 -        output.shouldHaveExitValue(0);
    2.79 -        final long heapMemoryUsageWithDedup = Long.parseLong(output.firstMatch(heapMemoryUsagePattern, 1));
    2.80 -        final long arrayHeaderSizeWithDedup = Long.parseLong(output.firstMatch(arrayHeaderSizePattern, 1));
    2.81 -
    2.82 -        // Sanity check to make sure one instance isn't using compressed class pointers and the other not
    2.83 -        if (arrayHeaderSizeWithoutDedup != arrayHeaderSizeWithDedup) {
    2.84 -            throw new Exception("Unexpected difference between array header sizes");
    2.85 -        }
    2.86 -
    2.87 -        // Calculate expected memory usage with deduplication enabled. This calculation does
    2.88 -        // not take alignment and padding into account, so it's a conservative estimate.
    2.89 -        final long sizeOfChar = unsafe.ARRAY_CHAR_INDEX_SCALE;
    2.90 -        final long sizeOfCharArray = StringLength * sizeOfChar + arrayHeaderSizeWithoutDedup;
    2.91 -        final long bytesSaved = (LargeNumberOfStrings - 1) * sizeOfCharArray;
    2.92 -        final long heapMemoryUsageWithDedupExpected = heapMemoryUsageWithoutDedup - bytesSaved;
    2.93 -
    2.94 -        System.out.println("Memory usage summary:");
    2.95 -        System.out.println("   heapMemoryUsageWithoutDedup:      " + heapMemoryUsageWithoutDedup);
    2.96 -        System.out.println("   heapMemoryUsageWithDedup:         " + heapMemoryUsageWithDedup);
    2.97 -        System.out.println("   heapMemoryUsageWithDedupExpected: " + heapMemoryUsageWithDedupExpected);
    2.98 -
    2.99 -        if (heapMemoryUsageWithDedup > heapMemoryUsageWithDedupExpected) {
   2.100 -            throw new Exception("Unexpected memory usage, heapMemoryUsageWithDedup should be less or equal to heapMemoryUsageWithDedupExpected");
   2.101 -        }
   2.102 -    }
   2.103  }

mercurial