0N/A/*
2362N/A * Copyright (c) 2004, 2007, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/*
0N/A @test
0N/A @bug 5085626
0N/A @summary Exponential performance regression in AWT components (multiple mon)
0N/A @run main WPanelPeerPerf
0N/A*/
0N/A
0N/Aimport java.awt.*;
0N/Aimport java.awt.event.*;
0N/Aimport javax.swing.*;
0N/A
0N/A/**
0N/A * This test must be run on a multi-screen system.
0N/A * This test works by moving a Frame back and forth between the screens a few
0N/A * times. When the bug is active, the first move will overwhelm the EDT with
0N/A * recursive display change calls. The test fails if it takes too long to
0N/A * service the setLocation() calls and send componentMoved() events.
0N/A */
0N/Apublic class WPanelPeerPerf {
0N/A
0N/A private static final int NESTED_PANELS = 25;
0N/A private static final int ITERATIONS_PER_SCREEN = 3;
0N/A private static final int MAX_WAIT_PER_SCREEN = 2500;
0N/A private static final int PAUSE_BETWEEN_MOVES = 500;
0N/A
0N/A
0N/A private static Object showLock = new Object();
0N/A
0N/A private static Counter instance = null;
0N/A public static Counter getCounter() {
0N/A if (instance == null) {
0N/A instance = new Counter();
0N/A }
0N/A return instance;
0N/A }
0N/A
0N/A private static class Counter {
0N/A int counter;
0N/A Counter() { counter = 0; }
0N/A }
0N/A
0N/A // This one is very slow!
0N/A public static void testAWT() {
0N/A // fail if only on one screen
0N/A int numScreens = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices().length;
0N/A if (numScreens < 2) {
0N/A System.err.println("Test must be run on a multiscreen system");
0N/A return;
0N/A }
0N/A final Frame frame = new Frame("AWT WPanelPeerPerf");
0N/A frame.addWindowListener(new WindowAdapter() {
0N/A public void windowClosing(WindowEvent ev) {
0N/A System.exit(0);
0N/A }
0N/A public void windowOpened(WindowEvent e) {
0N/A synchronized(showLock) {
0N/A showLock.notify();
0N/A }
0N/A }
0N/A });
0N/A frame.setLayout(new BorderLayout());
0N/A Label label = new Label("Hello world");
0N/A frame.add(label, BorderLayout.NORTH);
0N/A Panel panel = new Panel(new BorderLayout());
0N/A Panel currentPanel = panel;
0N/A for (int i = 0; i < NESTED_PANELS; i++) {
0N/A Panel newPanel = new Panel(new BorderLayout());
0N/A currentPanel.add(newPanel, BorderLayout.CENTER);
0N/A currentPanel = newPanel;
0N/A }
0N/A currentPanel.add(new Label("WPanelPeerPerf"));
0N/A frame.add(panel, BorderLayout.CENTER);
0N/A Button btn = new Button("OK");
0N/A frame.add(btn, BorderLayout.SOUTH);
0N/A frame.pack();
0N/A
0N/A frame.addComponentListener(new ComponentAdapter() {
0N/A public void componentMoved(ComponentEvent e) {
0N/A System.out.println("Frame moved: ");
0N/A Counter ctr = getCounter();
0N/A synchronized(ctr) {
0N/A ctr.counter++;
0N/A ctr.notify();
0N/A }
0N/A }
0N/A });
0N/A synchronized(showLock) {
0N/A try {
0N/A frame.setVisible(true);
0N/A showLock.wait();
0N/A }
0N/A catch (InterruptedException e) {
0N/A e.printStackTrace();
0N/A throw new RuntimeException("Problem with showLock");
0N/A }
0N/A }
0N/A runTest(frame);
0N/A }
0N/A
0N/A public static void runTest(Frame theFrame) {
0N/A System.out.println("Running test");
0N/A GraphicsDevice[] devs = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
0N/A Point[] points = new Point[devs.length];
0N/A
0N/A for (int i = 0; i < points.length; i++) {
0N/A Rectangle bounds = devs[i].getDefaultConfiguration().getBounds();
0N/A points[i] = new Point(bounds.x + (bounds.width / 2),
0N/A bounds.y + (bounds.height / 2));
0N/A System.out.println("Added point:" + points[i]);
0N/A }
0N/A
0N/A final Frame localFrame = theFrame;
0N/A
0N/A for (int n = 0; n < ITERATIONS_PER_SCREEN; n++) {
0N/A for (int i = 0; i < points.length; i++) {
0N/A final Point contextPoint = points[i];
0N/A SwingUtilities.invokeLater(new Runnable() {
0N/A public void run() {
0N/A localFrame.setLocation(contextPoint);
0N/A }
0N/A });
0N/A try {
0N/A Thread.sleep(PAUSE_BETWEEN_MOVES);
0N/A }
0N/A catch (InterruptedException e) {
0N/A System.out.println("Interrupted during iteration");
0N/A }
0N/A }
0N/A }
0N/A Counter ctr = getCounter();
0N/A synchronized(ctr) {
0N/A try {
0N/A if (ctr.counter < ITERATIONS_PER_SCREEN * devs.length) {
0N/A // If test hasn't finished, wait for maximum time
0N/A // If we get interrupted, test fails
0N/A ctr.wait((long)(ITERATIONS_PER_SCREEN * MAX_WAIT_PER_SCREEN * devs.length));
0N/A System.out.println("after wait");
0N/A if (ctr.counter < ITERATIONS_PER_SCREEN * devs.length) {
0N/A throw new RuntimeException("Waited too long for all the componentMoved()s");
0N/A }
0N/A }
0N/A }
0N/A catch(InterruptedException e) {
0N/A e.printStackTrace();
0N/A throw new RuntimeException("Wait interrupted - ???");
0N/A }
0N/A System.out.println("Counter reads: " + ctr.counter);
0N/A }
0N/A
0N/A }
0N/A public static void main(String[] args) {
0N/A testAWT();
0N/A }
0N/A}