MTSafetyTest.java revision 0
1637N/A/*
1637N/A * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
1637N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1637N/A *
1637N/A * This code is free software; you can redistribute it and/or modify it
1637N/A * under the terms of the GNU General Public License version 2 only, as
1637N/A * published by the Free Software Foundation.
1637N/A *
1637N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1637N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1637N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1637N/A * version 2 for more details (a copy is included in the LICENSE file that
1637N/A * accompanied this code).
1637N/A *
1637N/A * You should have received a copy of the GNU General Public License version
1637N/A * 2 along with this work; if not, write to the Free Software Foundation,
1637N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1637N/A *
1637N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
1637N/A * CA 95054 USA or visit www.sun.com if you need additional information or
1637N/A * have any questions.
1637N/A */
3723N/A
1637N/A/**
1637N/A * @test
1637N/A * @bug 6476665
1637N/A * @summary Verifies MT safety of color conversions
1637N/A * @run main MTSafetyTest
3723N/A */
1637N/A
1637N/Aimport java.util.Vector;
1637N/Aimport java.awt.*;
1637N/Aimport java.awt.color.*;
3723N/Aimport java.awt.image.*;
1637N/A
1637N/Apublic class MTSafetyTest {
1637N/A
3723N/A static boolean failed = false;
3661N/A
3996N/A static int[] colorSpaceType = {
3996N/A ColorSpace.CS_CIEXYZ,
3996N/A ColorSpace.CS_GRAY,
1637N/A ColorSpace.CS_LINEAR_RGB,
1637N/A ColorSpace.CS_PYCC,
1637N/A ColorSpace.CS_sRGB
1637N/A };
1637N/A
1637N/A static private final int[] imageTypes = new int[] {
1637N/A BufferedImage.TYPE_INT_RGB,
1637N/A BufferedImage.TYPE_INT_ARGB,
1637N/A BufferedImage.TYPE_INT_ARGB_PRE,
1637N/A BufferedImage.TYPE_INT_BGR,
1637N/A BufferedImage.TYPE_3BYTE_BGR,
1637N/A BufferedImage.TYPE_4BYTE_ABGR,
1637N/A BufferedImage.TYPE_4BYTE_ABGR_PRE,
1637N/A BufferedImage.TYPE_USHORT_565_RGB,
1637N/A BufferedImage.TYPE_USHORT_555_RGB,
1637N/A BufferedImage.TYPE_BYTE_GRAY,
1637N/A BufferedImage.TYPE_USHORT_GRAY,
3723N/A BufferedImage.TYPE_BYTE_BINARY,
3723N/A BufferedImage.TYPE_BYTE_INDEXED
3723N/A };
3723N/A
3723N/A
1637N/A public static void main(String[] args) {
1874N/A int nImgTypes = imageTypes.length;
1637N/A int nCSTypes = colorSpaceType.length;
1874N/A Vector<Thread> threads =
1637N/A new Vector<Thread>(nImgTypes*nCSTypes*nCSTypes);
3723N/A
1637N/A for (int i = 0; i < nImgTypes; i++) {
1637N/A BufferedImage origImage =
3996N/A new BufferedImage(300, 300, imageTypes[i]);
3996N/A
3996N/A for (int j = 0; j < nCSTypes; j++) {
for (int k = 0; k < nCSTypes; k++) {
Graphics2D g2 = (Graphics2D) origImage.getGraphics();
g2.fillRect(0, 0, 300, 150);
ColorConvertOp colorOp = getColorConvertOp(j,k);
ColorConvert cc = new ColorConvert(origImage, colorOp);
Thread colorThread = new Thread(cc);
threads.add(colorThread);
colorThread.start();
}
}
}
try {
for (Thread thread : threads) {
thread.join();
}
} catch (InterruptedException e) {
throw new RuntimeException("Unexpected exception" + e);
}
if (failed) {
throw new RuntimeException("Unexpected exception");
}
}
private static ColorConvertOp getColorConvertOp(int srcIndex,
int destIndex)
{
ColorSpace srcColorSpace = ColorSpace.getInstance(
colorSpaceType[srcIndex]);
ColorSpace destColorSpace = ColorSpace.getInstance(
colorSpaceType[destIndex]);
return new ColorConvertOp(srcColorSpace, destColorSpace, null);
}
static class ColorConvert implements Runnable {
BufferedImage original = null;
ColorConvertOp colorOp = null;
public ColorConvert(BufferedImage orig, ColorConvertOp ccOp) {
original = orig;
colorOp = ccOp;
}
public void run() {
try {
colorOp.filter(original, null);
} catch (OutOfMemoryError e) {
/* Skipping OOM exception. We cannot just enlarge stack and heap
* because it causes problem to disappear
*/
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
failed = true;
}
}
}
}