hotspot/test/compiler/whitebox/ForceNMethodSweepTest.java
author chegar
Tue, 22 Mar 2016 15:26:07 +0000
changeset 36694 182a5e7a519e
parent 34185 ee71c590a456
child 36818 b40330c06dea
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
27917
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
     1
/*
29678
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 28727
diff changeset
     2
 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
27917
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
     4
 *
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
     7
 * published by the Free Software Foundation.
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
     8
 *
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    13
 * accompanied this code).
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    14
 *
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    18
 *
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    21
 * questions.
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    22
 *
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    23
 */
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    24
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    25
import java.lang.reflect.Method;
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    26
import java.util.EnumSet;
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    27
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    28
import sun.hotspot.WhiteBox;
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    29
import sun.hotspot.code.BlobType;
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    30
30604
b8d532cb6420 8067013: Rename the com.oracle.java.testlibary package
ykantser
parents: 29678
diff changeset
    31
import jdk.test.lib.Asserts;
b8d532cb6420 8067013: Rename the com.oracle.java.testlibary package
ykantser
parents: 29678
diff changeset
    32
import jdk.test.lib.InfiniteLoop;
34155
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents: 30604
diff changeset
    33
import compiler.whitebox.CompilerWhiteBoxTest;
27917
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    34
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    35
/*
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    36
 * @test
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    37
 * @bug 8059624 8064669
34185
neliasso
parents: 33730 34155
diff changeset
    38
 * @library /testlibrary /test/lib /
29678
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 28727
diff changeset
    39
 * @modules java.management
27917
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    40
 * @build ForceNMethodSweepTest
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    41
 * @run main ClassFileInstaller sun.hotspot.WhiteBox
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    42
 *                              sun.hotspot.WhiteBox$WhiteBoxPermission
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    43
 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    44
 *                   -XX:-TieredCompilation -XX:+WhiteBoxAPI
34155
8d9e0cbf93a2 8138689: use package for /compiler/whitebox common classes
dpochepk
parents: 30604
diff changeset
    45
 *                   -XX:CompileCommand=compileonly,compiler.whitebox.SimpleTestCase$Helper::*
28727
3e314e9c40f1 8066998: [TESTBUG] compiler/whitebox/ForceNMethodSweepTest.java : sweep shouldn't increase usage
pchistyakov
parents: 28487
diff changeset
    46
 *                   -XX:-BackgroundCompilation ForceNMethodSweepTest
27917
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    47
 * @summary testing of WB::forceNMethodSweep
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    48
 */
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    49
public class ForceNMethodSweepTest extends CompilerWhiteBoxTest {
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    50
    public static void main(String[] args) throws Exception {
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    51
        CompilerWhiteBoxTest.main(ForceNMethodSweepTest::new, args);
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    52
    }
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    53
    private final EnumSet<BlobType> blobTypes;
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    54
    private ForceNMethodSweepTest(TestCase testCase) {
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    55
        super(testCase);
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    56
        // to prevent inlining of #method
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    57
        WHITE_BOX.testSetDontInlineMethod(method, true);
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    58
        blobTypes = BlobType.getAvailable();
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    59
    }
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    60
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    61
    @Override
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    62
    protected void test() throws Exception {
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    63
        checkNotCompiled();
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    64
        guaranteedSweep();
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    65
        int usage = getTotalUsage();
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    66
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    67
        compile();
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    68
        checkCompiled();
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    69
        int afterCompilation = getTotalUsage();
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    70
        Asserts.assertGT(afterCompilation, usage,
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    71
                "compilation should increase usage");
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    72
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    73
        guaranteedSweep();
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    74
        int afterSweep = getTotalUsage();
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    75
        Asserts.assertLTE(afterSweep, afterCompilation,
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    76
                "sweep shouldn't increase usage");
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    77
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    78
        deoptimize();
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    79
        guaranteedSweep();
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    80
        int afterDeoptAndSweep = getTotalUsage();
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    81
        Asserts.assertLT(afterDeoptAndSweep, afterSweep,
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    82
                "sweep after deoptimization should decrease usage");
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    83
     }
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    84
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    85
    private int getTotalUsage() {
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    86
        int usage = 0;
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    87
        for (BlobType type : blobTypes) {
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    88
           usage += type.getMemoryPool().getUsage().getUsed();
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    89
        }
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    90
        return usage;
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    91
    }
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    92
    private void guaranteedSweep() {
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    93
        // not entrant -> ++stack_traversal_mark -> zombie -> reclamation -> flushed
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    94
        for (int i = 0; i < 5; ++i) {
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    95
            WHITE_BOX.fullGC();
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    96
            WHITE_BOX.forceNMethodSweep();
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    97
        }
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    98
    }
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    99
}