test/jdk/sun/java2d/DirectX/StrikeDisposalCrashTest/StrikeDisposalCrashTest.java
author pnarayanan
Fri, 02 Mar 2018 14:39:29 +0530
changeset 49217 3b820b878ebe
parent 47216 71c04702a3d5
permissions -rw-r--r--
8198613: Test cases result in failure or timeout when run with OpenGL backend Reviewed-by: serb, jdv
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
     1
/*
49217
3b820b878ebe 8198613: Test cases result in failure or timeout when run with OpenGL backend
pnarayanan
parents: 47216
diff changeset
     2
 * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
     4
 *
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
     7
 * published by the Free Software Foundation.
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
     8
 *
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    13
 * accompanied this code).
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    14
 *
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 887
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 887
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 887
diff changeset
    21
 * questions.
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    22
 */
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    23
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    24
/**
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    25
 * @test
39056
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 5506
diff changeset
    26
 * @key headful
49217
3b820b878ebe 8198613: Test cases result in failure or timeout when run with OpenGL backend
pnarayanan
parents: 47216
diff changeset
    27
 * @bug 6705443 8198613
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    28
 * @summary tests that we don't crash during exit if font strikes were disposed
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    29
 * during the lifetime of the application
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    30
 *
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    31
 * @run main/othervm -Dsun.java2d.font.reftype=weak StrikeDisposalCrashTest
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    32
 * @run main/othervm -Dsun.java2d.font.reftype=weak -Dsun.java2d.noddraw=true StrikeDisposalCrashTest
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    33
 */
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    34
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    35
import java.awt.Font;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    36
import java.awt.Frame;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    37
import java.awt.Graphics2D;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    38
import java.awt.GraphicsConfiguration;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    39
import java.awt.GraphicsDevice;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    40
import java.awt.GraphicsEnvironment;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    41
import java.awt.RenderingHints;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    42
import java.awt.Toolkit;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    43
import java.awt.image.VolatileImage;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    44
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    45
public class StrikeDisposalCrashTest {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    46
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    47
    public static void main(String[] args) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    48
        System.setProperty("sun.java2d.font.reftype", "weak");
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    49
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    50
        GraphicsDevice gd[] =
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    51
            GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    52
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    53
        Frame frames[] = new Frame[gd.length];
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    54
        for (int i = 0; i < frames.length; i++) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    55
            GraphicsConfiguration gc = gd[i].getDefaultConfiguration();
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    56
            Frame f = new Frame("Frame on "+gc, gc);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    57
            f.setSize(100, 100);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    58
            f.setLocation(gc.getBounds().x, gc.getBounds().y);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    59
            f.pack();
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    60
            frames[i] = f;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    61
        }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    62
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    63
        Font f1 = new Font("Dialog", Font.PLAIN, 10);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    64
        Font f2 = new Font("Dialog", Font.ITALIC, 12);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    65
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    66
        for (int i = 0; i < frames.length/2; i++) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    67
            // making sure the glyphs are cached in the accel. cache on
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    68
            // one frame, then the other
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    69
            renderText(frames[i], f1);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    70
            renderText(frames[frames.length -1 - i], f1);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    71
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    72
            // and now the other way around, with different glyphs
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    73
            renderText(frames[frames.length -1 - i], f2);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    74
            renderText(frames[i], f2);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    75
        }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    76
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    77
        // try to force strike disposal (note that we have to use
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    78
        // -Dsun.java2d.font.reftype=weak to facilitate the disposal)
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    79
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    80
        System.gc();
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    81
        System.runFinalization();
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    82
        System.gc();
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    83
        System.runFinalization();
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    84
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    85
        for (Frame f : frames) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    86
            f.dispose();
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    87
        }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    88
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    89
        System.err.println("Exiting. If the test crashed after this it FAILED");
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    90
    }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    91
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    92
    private static final String text =
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    93
        "The quick brown fox jumps over the lazy dog 1234567890";
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    94
    private static void renderText(Frame frame, Font f1) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    95
        VolatileImage vi = frame.createVolatileImage(256, 32);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    96
        vi.validate(frame.getGraphicsConfiguration());
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    97
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    98
        Graphics2D g = vi.createGraphics();
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
    99
        g.setFont(f1);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
   100
        g.drawString(text, 0, vi.getHeight()/2);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
   101
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
   102
                           RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
   103
        g.drawString(text, 0, vi.getHeight()/2);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
   104
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
   105
                           RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
   106
        g.drawString(text, 0, vi.getHeight()/2);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
   107
        Toolkit.getDefaultToolkit().sync();
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
   108
    }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents:
diff changeset
   109
}