Wed, 21 May 2014 10:56:41 -0700
Added tag jdk8u20-b15 for changeset 8c785f9bde6f
roland@6377 | 1 | /* |
roland@6377 | 2 | * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
roland@6377 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
roland@6377 | 4 | * |
roland@6377 | 5 | * This code is free software; you can redistribute it and/or modify it |
roland@6377 | 6 | * under the terms of the GNU General Public License version 2 only, as |
roland@6377 | 7 | * published by the Free Software Foundation. |
roland@6377 | 8 | * |
roland@6377 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
roland@6377 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
roland@6377 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
roland@6377 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
roland@6377 | 13 | * accompanied this code). |
roland@6377 | 14 | * |
roland@6377 | 15 | * You should have received a copy of the GNU General Public License version |
roland@6377 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
roland@6377 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
roland@6377 | 18 | * |
roland@6377 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
roland@6377 | 20 | * or visit www.oracle.com if you need additional information or have any |
roland@6377 | 21 | * questions. |
roland@6377 | 22 | */ |
roland@6377 | 23 | |
roland@6377 | 24 | /* |
roland@6377 | 25 | * @test |
roland@6377 | 26 | * @bug 8031752 |
roland@6377 | 27 | * @summary speculative traps need to be cleaned up at GC |
roland@6384 | 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 -Xmx1M TestSpecTrapClassUnloading |
roland@6377 | 29 | * |
roland@6377 | 30 | */ |
roland@6377 | 31 | |
roland@6377 | 32 | import java.lang.reflect.Method; |
roland@6377 | 33 | |
roland@6377 | 34 | public class TestSpecTrapClassUnloading { |
roland@6377 | 35 | static class B { |
roland@6377 | 36 | final public boolean m(Object o) { |
roland@6377 | 37 | if (o.getClass() == B.class) { |
roland@6377 | 38 | return true; |
roland@6377 | 39 | } |
roland@6377 | 40 | return false; |
roland@6377 | 41 | } |
roland@6377 | 42 | } |
roland@6377 | 43 | |
roland@6377 | 44 | static class MemoryChunk { |
roland@6377 | 45 | MemoryChunk other; |
roland@6377 | 46 | long[] array; |
roland@6377 | 47 | MemoryChunk(MemoryChunk other) { |
roland@6377 | 48 | other = other; |
roland@6377 | 49 | array = new long[1024 * 1024 * 1024]; |
roland@6377 | 50 | } |
roland@6377 | 51 | } |
roland@6377 | 52 | |
roland@6377 | 53 | static void m1(B b, Object o) { |
roland@6377 | 54 | b.m(o); |
roland@6377 | 55 | } |
roland@6377 | 56 | |
roland@6377 | 57 | static void m2(B b, Object o) { |
roland@6377 | 58 | b.m(o); |
roland@6377 | 59 | } |
roland@6377 | 60 | |
roland@6377 | 61 | public static void main(String[] args) throws Exception { |
roland@6377 | 62 | Method m = B.class.getMethod("m", Object.class); |
roland@6377 | 63 | Object o = new Object(); |
roland@6377 | 64 | B b = new B(); |
roland@6377 | 65 | |
roland@6377 | 66 | // add speculative trap in B.m() for m1 |
roland@6377 | 67 | for (int i = 0; i < 20000; i++) { |
roland@6377 | 68 | m1(b, b); |
roland@6377 | 69 | } |
roland@6377 | 70 | m1(b, o); |
roland@6377 | 71 | |
roland@6377 | 72 | // add speculative trap in B.m() for code generated by reflection |
roland@6377 | 73 | for (int i = 0; i < 20000; i++) { |
roland@6377 | 74 | m.invoke(b, b); |
roland@6377 | 75 | } |
roland@6377 | 76 | m.invoke(b, o); |
roland@6377 | 77 | |
roland@6377 | 78 | m = null; |
roland@6377 | 79 | |
roland@6377 | 80 | // add speculative trap in B.m() for m2 |
roland@6377 | 81 | for (int i = 0; i < 20000; i++) { |
roland@6377 | 82 | m2(b, b); |
roland@6377 | 83 | } |
roland@6377 | 84 | m2(b, o); |
roland@6377 | 85 | |
roland@6377 | 86 | // Exhaust memory which causes the code generated by |
roland@6377 | 87 | // reflection to be unloaded but B.m() is not. |
roland@6377 | 88 | MemoryChunk root = null; |
roland@6377 | 89 | try { |
roland@6377 | 90 | while (true) { |
roland@6377 | 91 | root = new MemoryChunk(root); |
roland@6377 | 92 | } |
roland@6377 | 93 | } catch(OutOfMemoryError e) { |
roland@6377 | 94 | root = null; |
roland@6377 | 95 | } |
roland@6377 | 96 | } |
roland@6377 | 97 | } |