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