changeset 49694:69f7e3ed043c

8201240: Improve releasing native resources of BufImgSurfaceData.ICMColorData Reviewed-by: prr, serb
author aivanov
date Thu, 12 Apr 2018 14:03:54 +0100
parents fa23ea24dade
children a4d1d2dec618
files src/java.desktop/share/classes/sun/awt/image/BufImgSurfaceData.java src/java.desktop/share/native/libawt/awt/image/BufImgSurfaceData.c
diffstat 2 files changed, 13 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.desktop/share/classes/sun/awt/image/BufImgSurfaceData.java	Mon Apr 09 13:28:47 2018 +0200
+++ b/src/java.desktop/share/classes/sun/awt/image/BufImgSurfaceData.java	Thu Apr 12 14:03:54 2018 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2018, 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
@@ -25,7 +25,6 @@
 
 package sun.awt.image;
 
-import java.awt.Color;
 import java.awt.Rectangle;
 import java.awt.GraphicsConfiguration;
 import java.awt.image.ColorModel;
@@ -38,9 +37,6 @@
 
 import sun.java2d.SurfaceData;
 import sun.java2d.SunGraphics2D;
-import sun.java2d.StateTrackable;
-import sun.java2d.StateTrackable.*;
-import sun.java2d.StateTracker;
 import sun.java2d.loops.SurfaceType;
 import sun.java2d.loops.CompositeType;
 import sun.java2d.loops.RenderLoops;
@@ -446,8 +442,6 @@
         // their pixels are immediately retrievable anyway.
     }
 
-    private static native void freeNativeICMData(long pData);
-
     /**
      * Returns destination Image associated with this SurfaceData.
      */
@@ -471,13 +465,5 @@
         private ICMColorData(long pData) {
             this.pData = pData;
         }
-
-        @SuppressWarnings("deprecation")
-        public void finalize() {
-            if (pData != 0L) {
-                BufImgSurfaceData.freeNativeICMData(pData);
-                pData = 0L;
-            }
-        }
     }
 }
--- a/src/java.desktop/share/native/libawt/awt/image/BufImgSurfaceData.c	Mon Apr 09 13:28:47 2018 +0200
+++ b/src/java.desktop/share/native/libawt/awt/image/BufImgSurfaceData.c	Thu Apr 12 14:03:54 2018 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2018, 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
@@ -32,6 +32,7 @@
 #include "jni_util.h"
 /* Define uintptr_t */
 #include "gdefs.h"
+#include "Disposer.h"
 
 /**
  * This include file contains support code for loops using the
@@ -80,19 +81,6 @@
 }
 
 /*
- * Class:     sun_java2d_SurfaceData
- * Method:    freeNativeICMData
- * Signature: (Ljava/awt/image/IndexColorModel;)V
- */
-JNIEXPORT void JNICALL
-Java_sun_awt_image_BufImgSurfaceData_freeNativeICMData
-    (JNIEnv *env, jclass sd, jlong pData)
-{
-    ColorData *cdata = (ColorData*)jlong_to_ptr(pData);
-    freeICMColorData(cdata);
-}
-
-/*
  * Class:     sun_awt_image_BufImgSurfaceData
  * Method:    initOps
  * Signature: (Ljava/lang/Object;IIIII)V
@@ -140,6 +128,15 @@
 }
 
 /*
+ * Releases native structures associated with BufImgSurfaceData.ICMColorData.
+ */
+static void BufImg_Dispose_ICMColorData(JNIEnv *env, jlong pData)
+{
+    ColorData *cdata = (ColorData*)jlong_to_ptr(pData);
+    freeICMColorData(cdata);
+}
+
+/*
  * Method for disposing native BufImgSD
  */
 static void BufImg_Dispose(JNIEnv *env, SurfaceDataOps *ops)
@@ -373,6 +370,7 @@
             }
 
             (*env)->SetObjectField(env, bisdo->icm, colorDataID, colorData);
+            Disposer_AddRecord(env, colorData, BufImg_Dispose_ICMColorData, pData);
         }
     }