Path: blob/master/test/jdk/sun/java2d/cmm/ProfileOp/DisposalCrashTest.java
41153 views
/*1* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 802451126* @summary Verifies that instances of color profiles are destroyed correctly.27* A crash during profile destruction indicates failure.28*29* @run main DisposalCrashTest30*/3132import static java.awt.color.ColorSpace.*;33import java.awt.color.ICC_Profile;34import java.lang.ref.Reference;35import java.lang.ref.ReferenceQueue;36import java.lang.ref.WeakReference;37import java.util.Vector;3839public class DisposalCrashTest {4041static final ReferenceQueue<ICC_Profile> queue = new ReferenceQueue<>();42static final Vector<Reference<? extends ICC_Profile>> v = new Vector<>();4344public static void main(String[] args) {45int[] ids = new int[]{46CS_sRGB, CS_CIEXYZ, CS_GRAY, CS_LINEAR_RGB, CS_PYCC47};4849for (int id : ids) {50ICC_Profile p = getCopyOf(id);51}5253while (!v.isEmpty()) {54System.gc();55System.out.println(".");56try {57Thread.sleep(500);58} catch (InterruptedException e) {};5960final Reference<? extends ICC_Profile> ref = queue.poll();61System.out.println("Got reference: " + ref);6263v.remove(ref);64}6566System.out.println("Test PASSED.");67}6869private static ICC_Profile getCopyOf(int id) {70ICC_Profile std = ICC_Profile.getInstance(id);7172byte[] data = std.getData();7374ICC_Profile p = ICC_Profile.getInstance(data);7576WeakReference<ICC_Profile> ref = new WeakReference<>(p, queue);7778v.add(ref);7980return p;81}82}838485