hotspot/test/compiler/whitebox/ForceNMethodSweepTest.java
author tpivovarova
Tue, 12 Jul 2016 18:24:48 +0300
changeset 40059 c2304140ed64
parent 38152 80e5da81fb2c
child 40631 ed82623d7831
permissions -rw-r--r--
8132919: Put compiler tests in packages Reviewed-by: vlivanov, dpochepk Contributed-by: igor.ignatyev@oracle.com
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
/*
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    26
 * @test
38020
4fa831d0f4bf 8153265: [TESTBUG] compiler/whitebox/ForceNMethodSweepTest should not assume asserts are benign
shade
parents: 36818
diff changeset
    27
 * @bug 8059624 8064669 8153265
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    28
 * @summary testing of WB::forceNMethodSweep
34185
neliasso
parents: 33730 34155
diff changeset
    29
 * @library /testlibrary /test/lib /
38152
80e5da81fb2c 8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents: 38025
diff changeset
    30
 * @modules java.base/jdk.internal.misc
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    31
 *          java.management
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    32
 * @build compiler.whitebox.ForceNMethodSweepTest
38025
5ed9ce1e4a2f 8151880: EnqueueMethodForCompilationTest.java still fails to compile method
neliasso
parents: 38020
diff changeset
    33
 * @run driver ClassFileInstaller sun.hotspot.WhiteBox
5ed9ce1e4a2f 8151880: EnqueueMethodForCompilationTest.java still fails to compile method
neliasso
parents: 38020
diff changeset
    34
 *                                sun.hotspot.WhiteBox$WhiteBoxPermission
27917
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    35
 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    36
 *                   -XX:-TieredCompilation -XX:+WhiteBoxAPI
38025
5ed9ce1e4a2f 8151880: EnqueueMethodForCompilationTest.java still fails to compile method
neliasso
parents: 38020
diff changeset
    37
 *                   -XX:CompileCommand=compileonly,compiler.whitebox.SimpleTestCaseHelper::*
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    38
 *                   -XX:-BackgroundCompilation -XX:-UseCounterDecay
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    39
 *                   compiler.whitebox.ForceNMethodSweepTest
27917
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    40
 */
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    41
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    42
package compiler.whitebox;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    43
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    44
import jdk.test.lib.Asserts;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    45
import sun.hotspot.code.BlobType;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    46
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    47
import java.util.EnumSet;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    48
27917
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 {
38020
4fa831d0f4bf 8153265: [TESTBUG] compiler/whitebox/ForceNMethodSweepTest should not assume asserts are benign
shade
parents: 36818
diff changeset
    63
        // prime the asserts: get their bytecodes loaded, any lazy computation
4fa831d0f4bf 8153265: [TESTBUG] compiler/whitebox/ForceNMethodSweepTest should not assume asserts are benign
shade
parents: 36818
diff changeset
    64
        // resolved, and executed once
4fa831d0f4bf 8153265: [TESTBUG] compiler/whitebox/ForceNMethodSweepTest should not assume asserts are benign
shade
parents: 36818
diff changeset
    65
        Asserts.assertGT(1, 0, "message");
4fa831d0f4bf 8153265: [TESTBUG] compiler/whitebox/ForceNMethodSweepTest should not assume asserts are benign
shade
parents: 36818
diff changeset
    66
        Asserts.assertLTE(0, 0, "message");
4fa831d0f4bf 8153265: [TESTBUG] compiler/whitebox/ForceNMethodSweepTest should not assume asserts are benign
shade
parents: 36818
diff changeset
    67
        Asserts.assertLT(-1, 0, "message");
4fa831d0f4bf 8153265: [TESTBUG] compiler/whitebox/ForceNMethodSweepTest should not assume asserts are benign
shade
parents: 36818
diff changeset
    68
27917
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    69
        checkNotCompiled();
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    70
        guaranteedSweep();
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    71
        int usage = getTotalUsage();
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
        compile();
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    74
        checkCompiled();
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    75
        int afterCompilation = getTotalUsage();
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    76
        Asserts.assertGT(afterCompilation, usage,
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    77
                "compilation should increase usage");
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    78
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 afterSweep = getTotalUsage();
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    81
        Asserts.assertLTE(afterSweep, afterCompilation,
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    82
                "sweep shouldn't increase 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
        deoptimize();
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    85
        guaranteedSweep();
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    86
        int afterDeoptAndSweep = getTotalUsage();
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    87
        Asserts.assertLT(afterDeoptAndSweep, afterSweep,
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    88
                "sweep after deoptimization should decrease usage");
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
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    91
    private int getTotalUsage() {
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    92
        int usage = 0;
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    93
        for (BlobType type : blobTypes) {
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    94
           usage += type.getMemoryPool().getUsage().getUsed();
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    95
        }
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
    96
        return usage;
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
    private void guaranteedSweep() {
36818
b40330c06dea 8136458: Remove "marked for reclamation" nmethod state
thartmann
parents: 34185
diff changeset
    99
        // not entrant -> ++stack_traversal_mark -> zombie -> flushed
27917
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
   100
        for (int i = 0; i < 5; ++i) {
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
   101
            WHITE_BOX.fullGC();
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
   102
            WHITE_BOX.forceNMethodSweep();
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
   103
        }
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
   104
    }
c5937f7b4e8b 8064669: compiler/whitebox/AllocationCodeBlobTest.java crashes / asserts
iignatyev
parents:
diff changeset
   105
}