test/compiler/uncommontrap/TestSpecTrapClassUnloading.java

changeset 6377
b8413a9cbb84
child 6383
f258347cec12
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/compiler/uncommontrap/TestSpecTrapClassUnloading.java	Tue Feb 25 18:16:24 2014 +0100
     1.3 @@ -0,0 +1,97 @@
     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
    1.29 + * @bug 8031752
    1.30 + * @summary speculative traps need to be cleaned up at GC
    1.31 + * @run main/othervm -XX:-TieredCompilation -XX:-UseOnStackReplacement -XX:-BackgroundCompilation -XX:+UnlockExperimentalVMOptions -XX:+UseTypeSpeculation -XX:TypeProfileLevel=222 -XX:CompileCommand=exclude,java.lang.reflect.Method::invoke -XX:CompileCommand=exclude,sun.reflect.DelegatingMethodAccessorImpl::invoke -Xmx1M TestSpecTrapClassUnloading
    1.32 + *
    1.33 + */
    1.34 +
    1.35 +import java.lang.reflect.Method;
    1.36 +
    1.37 +public class TestSpecTrapClassUnloading {
    1.38 +    static class B {
    1.39 +        final public boolean m(Object o) {
    1.40 +            if (o.getClass() == B.class) {
    1.41 +                return true;
    1.42 +            }
    1.43 +            return false;
    1.44 +        }
    1.45 +    }
    1.46 +
    1.47 +    static class MemoryChunk {
    1.48 +        MemoryChunk other;
    1.49 +        long[] array;
    1.50 +        MemoryChunk(MemoryChunk other) {
    1.51 +            other = other;
    1.52 +            array = new long[1024 * 1024 * 1024];
    1.53 +        }
    1.54 +    }
    1.55 +
    1.56 +    static void m1(B b, Object o) {
    1.57 +        b.m(o);
    1.58 +    }
    1.59 +
    1.60 +    static void m2(B b, Object o) {
    1.61 +        b.m(o);
    1.62 +    }
    1.63 +
    1.64 +    public static void main(String[] args) throws Exception {
    1.65 +        Method m = B.class.getMethod("m", Object.class);
    1.66 +        Object o = new Object();
    1.67 +        B b = new B();
    1.68 +
    1.69 +        // add speculative trap in B.m() for m1
    1.70 +        for (int i = 0; i < 20000; i++) {
    1.71 +            m1(b, b);
    1.72 +        }
    1.73 +        m1(b, o);
    1.74 +
    1.75 +        // add speculative trap in B.m() for code generated by reflection
    1.76 +        for (int i = 0; i < 20000; i++) {
    1.77 +            m.invoke(b, b);
    1.78 +        }
    1.79 +        m.invoke(b, o);
    1.80 +
    1.81 +        m = null;
    1.82 +
    1.83 +        // add speculative trap in B.m() for m2
    1.84 +        for (int i = 0; i < 20000; i++) {
    1.85 +            m2(b, b);
    1.86 +        }
    1.87 +        m2(b, o);
    1.88 +
    1.89 +        // Exhaust memory which causes the code generated by
    1.90 +        // reflection to be unloaded but B.m() is not.
    1.91 +        MemoryChunk root = null;
    1.92 +        try {
    1.93 +            while (true) {
    1.94 +                root = new MemoryChunk(root);
    1.95 +            }
    1.96 +        } catch(OutOfMemoryError e) {
    1.97 +            root = null;
    1.98 +        }
    1.99 +    }
   1.100 +}

mercurial