hotspot/test/compiler/uncommontrap/TestSpecTrapClassUnloading.java
author roland
Mon, 26 May 2014 10:48:58 +0200
changeset 24672 f39a3df32983
parent 23208 4c37d91b8b09
permissions -rw-r--r--
8042557: compiler/uncommontrap/TestSpecTrapClassUnloading.java fails with: GC triggered before VM initialization completed Summary: larger heap size, bug fix when trying to exhaust memory Reviewed-by: vlivanov, twisti, kvn
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
24672
f39a3df32983 8042557: compiler/uncommontrap/TestSpecTrapClassUnloading.java fails with: GC triggered before VM initialization completed
roland
parents: 23208
diff changeset
    28
 * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-TieredCompilation -XX:-UseOnStackReplacement -XX:-BackgroundCompilation -XX:+UseTypeSpeculation -XX:TypeProfileLevel=222 -XX:CompileCommand=exclude,java.lang.reflect.Method::invoke -XX:CompileCommand=exclude,sun.reflect.DelegatingMethodAccessorImpl::invoke -Xmx512M TestSpecTrapClassUnloading
22916
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    29
 *
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    30
 */
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    31
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    32
import java.lang.reflect.Method;
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    33
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    34
public class TestSpecTrapClassUnloading {
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    35
    static class B {
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    36
        final public boolean m(Object o) {
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    37
            if (o.getClass() == B.class) {
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    38
                return true;
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    39
            }
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    40
            return false;
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
    }
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    43
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    44
    static class MemoryChunk {
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    45
        MemoryChunk other;
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    46
        long[] array;
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    47
        MemoryChunk(MemoryChunk other) {
24672
f39a3df32983 8042557: compiler/uncommontrap/TestSpecTrapClassUnloading.java fails with: GC triggered before VM initialization completed
roland
parents: 23208
diff changeset
    48
            this.other = other;
22916
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    49
            array = new long[1024 * 1024 * 1024];
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
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    53
    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
    54
        b.m(o);
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    55
    }
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    56
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    57
    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
    58
        b.m(o);
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
    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
    62
        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
    63
        Object o = new Object();
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    64
        B b = new B();
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    65
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    66
        // 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
    67
        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
    68
            m1(b, b);
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    69
        }
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    70
        m1(b, o);
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    71
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    72
        // 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
    73
        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
    74
            m.invoke(b, b);
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    75
        }
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    76
        m.invoke(b, o);
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
        m = null;
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 m2
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
            m2(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
        m2(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
        // 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
    87
        // 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
    88
        MemoryChunk root = null;
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    89
        try {
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    90
            while (true) {
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    91
                root = new MemoryChunk(root);
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    92
            }
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    93
        } catch(OutOfMemoryError e) {
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    94
            root = null;
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    95
        }
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    96
    }
582da2ed4dfa 8031752: Failed speculative optimizations should be reattempted when root of compilation is different
roland
parents:
diff changeset
    97
}