Path: blob/master/test/hotspot/jtreg/compiler/profiling/TestSpecTrapClassUnloading.java
41152 views
/*1* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 803175226* @summary speculative traps need to be cleaned up at GC27*28* @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-TieredCompilation29* -XX:-UseOnStackReplacement -XX:-BackgroundCompilation30* -XX:CompileThreshold=1000031* -XX:+UseTypeSpeculation -XX:TypeProfileLevel=22232* -XX:CompileCommand=exclude,java.lang.reflect.Method::invoke33* -XX:CompileCommand=exclude,sun.reflect.DelegatingMethodAccessorImpl::invoke34* -Xmx512M35* compiler.profiling.TestSpecTrapClassUnloading36*/3738package compiler.profiling;3940import java.lang.reflect.Method;4142public class TestSpecTrapClassUnloading {43static class B {44final public boolean m(Object o) {45if (o.getClass() == B.class) {46return true;47}48return false;49}50}5152static class MemoryChunk {53MemoryChunk other;54long[] array;55MemoryChunk(MemoryChunk other) {56this.other = other;57array = new long[1024 * 1024 * 1024];58}59}6061static void m1(B b, Object o) {62b.m(o);63}6465static void m2(B b, Object o) {66b.m(o);67}6869public static void main(String[] args) throws Exception {70Method m = B.class.getMethod("m", Object.class);71Object o = new Object();72B b = new B();7374// add speculative trap in B.m() for m175for (int i = 0; i < 20000; i++) {76m1(b, b);77}78m1(b, o);7980// add speculative trap in B.m() for code generated by reflection81for (int i = 0; i < 20000; i++) {82m.invoke(b, b);83}84m.invoke(b, o);8586m = null;8788// add speculative trap in B.m() for m289for (int i = 0; i < 20000; i++) {90m2(b, b);91}92m2(b, o);9394// Exhaust memory which causes the code generated by95// reflection to be unloaded but B.m() is not.96MemoryChunk root = null;97try {98while (true) {99root = new MemoryChunk(root);100}101} catch(OutOfMemoryError e) {102root = null;103}104}105}106107108