test/hotspot/jtreg/compiler/profiling/TestSpecTrapClassUnloading.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 40059 hotspot/test/compiler/profiling/TestSpecTrapClassUnloading.java@c2304140ed64
child 52005 4236fa9582bb
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
22916
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
     1
/*
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
     4
 *
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
     7
 * published by the Free Software Foundation.
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
     8
 *
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    13
 * accompanied this code).
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    14
 *
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    18
 *
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    21
 * questions.
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    22
 */
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    23
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    24
/*
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    25
 * @test
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    26
 * @bug 8031752
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    27
 * @summary speculative traps need to be cleaned up at GC
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    28
 *
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 25635
diff changeset
    29
 * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-TieredCompilation
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 25635
diff changeset
    30
 *                   -XX:-UseOnStackReplacement -XX:-BackgroundCompilation
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 25635
diff changeset
    31
 *                   -XX:+UseTypeSpeculation -XX:TypeProfileLevel=222
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 25635
diff changeset
    32
 *                   -XX:CompileCommand=exclude,java.lang.reflect.Method::invoke
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 25635
diff changeset
    33
 *                   -XX:CompileCommand=exclude,sun.reflect.DelegatingMethodAccessorImpl::invoke
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 25635
diff changeset
    34
 *                   -Xmx512M
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 25635
diff changeset
    35
 *                   compiler.profiling.TestSpecTrapClassUnloading
22916
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    36
 */
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    37
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 25635
diff changeset
    38
package compiler.profiling;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 25635
diff changeset
    39
22916
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    40
import java.lang.reflect.Method;
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    41
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    42
public class TestSpecTrapClassUnloading {
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    43
    static class B {
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    44
        final public boolean m(Object o) {
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    45
            if (o.getClass() == B.class) {
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    46
                return true;
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    47
            }
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    48
            return false;
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    49
        }
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    50
    }
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    51
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    52
    static class MemoryChunk {
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    53
        MemoryChunk other;
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    54
        long[] array;
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    55
        MemoryChunk(MemoryChunk other) {
24672
f39a3df32983 8042557: compiler/uncommontrap/TestSpecTrapClassUnloading.java fails with: GC triggered before VM initialization completed
roland
parents: 23208
diff changeset
    56
            this.other = other;
22916
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    57
            array = new long[1024 * 1024 * 1024];
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    58
        }
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    59
    }
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    60
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    61
    static void m1(B b, Object o) {
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    62
        b.m(o);
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    63
    }
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    64
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    65
    static void m2(B b, Object o) {
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    66
        b.m(o);
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    67
    }
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    68
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    69
    public static void main(String[] args) throws Exception {
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    70
        Method m = B.class.getMethod("m", Object.class);
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    71
        Object o = new Object();
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    72
        B b = new B();
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    73
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    74
        // add speculative trap in B.m() for m1
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    75
        for (int i = 0; i < 20000; i++) {
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    76
            m1(b, b);
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    77
        }
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    78
        m1(b, o);
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    79
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    80
        // add speculative trap in B.m() for code generated by reflection
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    81
        for (int i = 0; i < 20000; i++) {
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    82
            m.invoke(b, b);
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    83
        }
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    84
        m.invoke(b, o);
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    85
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    86
        m = null;
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    87
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    88
        // add speculative trap in B.m() for m2
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    89
        for (int i = 0; i < 20000; i++) {
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    90
            m2(b, b);
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    91
        }
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    92
        m2(b, o);
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    93
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    94
        // Exhaust memory which causes the code generated by
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    95
        // reflection to be unloaded but B.m() is not.
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    96
        MemoryChunk root = null;
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    97
        try {
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    98
            while (true) {
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    99
                root = new MemoryChunk(root);
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
   100
            }
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
   101
        } catch(OutOfMemoryError e) {
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
   102
            root = null;
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
   103
        }
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
   104
    }
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
   105
}