< prev index next >

test/jdk/java/awt/image/BufferedImage/ICMColorDataTest/ICMColorDataTest.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.

@@ -28,18 +28,23 @@
 import java.awt.image.IndexColorModel;
 import java.awt.image.MultiPixelPackedSampleModel;
 import java.awt.image.Raster;
 import java.awt.image.SampleModel;
 import java.awt.image.WritableRaster;
+import java.lang.ref.PhantomReference;
+import java.lang.ref.Reference;
+import java.lang.ref.ReferenceQueue;
+import java.util.ArrayList;
+import java.util.List;
 
 /*
  * @test
- * @bug 8201433
+ * @bug 8201433 8232634
  * @summary This test may throw OOME or NPE from native code,
  *          it should not crash
  * @requires os.maxMemory >= 2G
- * @run main/othervm/timeout=300000 -Xms1000m -Xmx1000m ICMColorDataTest
+ * @run main/othervm/timeout=600 -Xms1000m -Xmx1000m -XX:+UseSerialGC ICMColorDataTest
  */
 public class ICMColorDataTest {
     private static final int WIDTH  = 90;
     private static final int HEIGHT = 90;
     private static final int BITS_PER_PIXEL = 1;

@@ -48,13 +53,24 @@
     // Color model components
     private static final byte[] RED   = { (byte) 255, 0 };
     private static final byte[] GREEN = { (byte) 255, 0 };
     private static final byte[] BLUE  = { (byte) 255, 0 };
 
+    private static final int MAX_SIZE = 10;
+
+    private static final ReferenceQueue<Object> refQueue =
+            new ReferenceQueue<>();
+    private static final List<Reference<Object>> refList =
+            new ArrayList<>(MAX_SIZE);
+
     public static void main(String[] args) {
         try {
-            for (long i = 0; i < 300_000; i++) {
+            for (long i = 0; i < 30_000; i++) {
+                if (refQueue.poll() != null) {
+                    System.err.println("Garbage collector was invoked");
+                    break;
+                }
                 makeImage();
             }
         } catch (OutOfMemoryError | NullPointerException e) {
             System.err.println("Caught expected exception:\n" +
                     e.getClass() + ": " + e.getMessage());

@@ -79,7 +95,11 @@
                                                    indexModel.isAlphaPremultiplied(), null);
 
         Graphics g = bufImage.getGraphics();
         g.drawRect(0, 0, WIDTH - 1, HEIGHT - 1);
         g.dispose();
+
+        if (refList.size() < MAX_SIZE) {
+            refList.add(new PhantomReference<>(bufImage, refQueue));
+        }
     }
 }
< prev index next >