aoqi@0: /* aoqi@0: * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: /** aoqi@0: * @test aoqi@0: * @bug 6589834 aoqi@0: * @summary deoptimization problem with -XX:+DeoptimizeALot aoqi@0: * aoqi@0: * @run main Test_ia32 aoqi@0: */ aoqi@0: aoqi@0: /*************************************************************************************** aoqi@0: NOTE: The bug shows up (with several "Bug!" message) even without the aoqi@0: flag -XX:+DeoptimizeALot. In a debug build, you may want to try aoqi@0: the flags -XX:+VerifyStack and -XX:+DeoptimizeALot to get more information. aoqi@0: ****************************************************************************************/ aoqi@0: import java.lang.reflect.Constructor; aoqi@0: aoqi@0: public class Test_ia32 { aoqi@0: aoqi@0: public static int NUM_THREADS = 100; aoqi@0: aoqi@0: public static int CLONE_LENGTH = 1000; aoqi@0: aoqi@0: public static void main(String[] args) throws InterruptedException, ClassNotFoundException { aoqi@0: aoqi@0: Reflector[] threads = new Reflector[NUM_THREADS]; aoqi@0: for (int i = 0; i < threads.length; i++) { aoqi@0: threads[i] = new Reflector(); aoqi@0: threads[i].start(); aoqi@0: } aoqi@0: aoqi@0: System.out.println("Give Reflector.run() some time to compile..."); aoqi@0: Thread.sleep(5000); aoqi@0: aoqi@0: System.out.println("Load RMISecurityException causing run() deoptimization"); aoqi@0: ClassLoader.getSystemClassLoader().loadClass("java.rmi.RMISecurityException"); aoqi@0: aoqi@0: for (Reflector thread : threads) aoqi@0: thread.requestStop(); aoqi@0: aoqi@0: for (Reflector thread : threads) aoqi@0: try { aoqi@0: thread.join(); aoqi@0: } catch (InterruptedException e) { aoqi@0: System.out.println(e); aoqi@0: } aoqi@0: aoqi@0: } aoqi@0: aoqi@0: } aoqi@0: aoqi@0: class Reflector extends Thread { aoqi@0: aoqi@0: volatile boolean _doSpin = true; aoqi@0: aoqi@0: Test_ia32[] _tests; aoqi@0: aoqi@0: Reflector() { aoqi@0: _tests = new Test_ia32[Test_ia32.CLONE_LENGTH]; aoqi@0: for (int i = 0; i < _tests.length; i++) { aoqi@0: _tests[i] = new Test_ia32(); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: static int g(int i1, int i2, Test_ia32[] arr, int i3, int i4) { aoqi@0: aoqi@0: if (!(i1==1 && i2==2 && i3==3 && i4==4)) { aoqi@0: System.out.println("Bug!"); aoqi@0: } aoqi@0: aoqi@0: return arr.length; aoqi@0: } aoqi@0: aoqi@0: static int f(Test_ia32[] arr) { aoqi@0: return g(1, 2, arr.clone(), 3, 4); aoqi@0: } aoqi@0: aoqi@0: @Override aoqi@0: public void run() { aoqi@0: Constructor[] ctrs = null; aoqi@0: Class klass = Test_ia32.class; aoqi@0: try { aoqi@0: ctrs = klass.getConstructors(); aoqi@0: } catch (SecurityException e) { aoqi@0: System.out.println(e); aoqi@0: } aoqi@0: aoqi@0: try { aoqi@0: while (_doSpin) { aoqi@0: if (f(_tests) < 0) aoqi@0: System.out.println("return value usage"); aoqi@0: } aoqi@0: } catch (NullPointerException e) { aoqi@0: e.printStackTrace(); aoqi@0: } aoqi@0: aoqi@0: System.out.println(this + " - stopped."); aoqi@0: } aoqi@0: aoqi@0: public void requestStop() { aoqi@0: System.out.println(this + " - stop requested."); aoqi@0: _doSpin = false; aoqi@0: } aoqi@0: aoqi@0: }