Skip to content

Commit eceb3bb

Browse files
committed
8362452: [macOS] Remove CPrinterJob.finalize()
Reviewed-by: serb, psadhukhan, kizune
1 parent 3acdba3 commit eceb3bb

File tree

2 files changed

+51
-21
lines changed

2 files changed

+51
-21
lines changed

src/java.desktop/macosx/classes/sun/lwawt/macosx/CPrinterJob.java

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,31 @@
2626
package sun.lwawt.macosx;
2727

2828

29-
import java.awt.*;
29+
import java.awt.Color;
30+
import java.awt.EventQueue;
31+
import java.awt.HeadlessException;
32+
import java.awt.Font;
33+
import java.awt.Graphics;
34+
import java.awt.Graphics2D;
35+
import java.awt.GraphicsEnvironment;
36+
import java.awt.SecondaryLoop;
37+
import java.awt.Toolkit;
3038
import java.awt.geom.Rectangle2D;
3139
import java.awt.image.BufferedImage;
32-
import java.awt.print.*;
40+
import java.awt.print.Pageable;
41+
import java.awt.print.PageFormat;
42+
import java.awt.print.Paper;
43+
import java.awt.print.Printable;
44+
import java.awt.print.PrinterAbortException;
45+
import java.awt.print.PrinterException;
46+
import java.awt.print.PrinterJob;
3347
import java.net.URI;
3448
import java.util.concurrent.atomic.AtomicReference;
3549

36-
import javax.print.*;
50+
import javax.print.DocFlavor;
51+
import javax.print.PrintService;
52+
import javax.print.PrintServiceLookup;
53+
import javax.print.StreamPrintService;
3754
import javax.print.attribute.PrintRequestAttributeSet;
3855
import javax.print.attribute.HashPrintRequestAttributeSet;
3956
import javax.print.attribute.standard.Chromaticity;
@@ -48,8 +65,16 @@
4865
import javax.print.attribute.standard.Sides;
4966
import javax.print.attribute.Attribute;
5067

51-
import sun.java2d.*;
52-
import sun.print.*;
68+
import sun.java2d.Disposer;
69+
import sun.java2d.DisposerRecord;
70+
import sun.java2d.SunGraphics2D;
71+
import sun.java2d.SurfaceData;
72+
import sun.print.CustomMediaTray;
73+
import sun.print.CustomOutputBin;
74+
import sun.print.GrayscaleProxyGraphics2D;
75+
import sun.print.PeekGraphics;
76+
import sun.print.RasterPrinterJob;
77+
import sun.print.SunPageSelection;
5378

5479
public final class CPrinterJob extends RasterPrinterJob {
5580
// NOTE: This uses RasterPrinterJob as a base, but it doesn't use
@@ -82,7 +107,8 @@ public final class CPrinterJob extends RasterPrinterJob {
82107
// PageFormat data is passed in and set on the fNSPrintInfo on a per call
83108
// basis.
84109
private long fNSPrintInfo = -1;
85-
private Object fNSPrintInfoLock = new Object();
110+
private final Object fNSPrintInfoLock = new Object();
111+
private final Object disposerReferent = new Object();
86112

87113
static {
88114
// AWT has to be initialized for the native code to function correctly.
@@ -610,25 +636,29 @@ private boolean jobSetup(Pageable doc) {
610636

611637
// The following methods are CPrinterJob specific.
612638

613-
@Override
614-
@SuppressWarnings("removal")
615-
protected void finalize() {
616-
synchronized (fNSPrintInfoLock) {
617-
if (fNSPrintInfo != -1) {
618-
dispose(fNSPrintInfo);
619-
}
620-
fNSPrintInfo = -1;
639+
static class NSPrintInfoDisposer implements DisposerRecord {
640+
641+
private final long fNSPrintInfo;
642+
643+
NSPrintInfoDisposer(long ptr) {
644+
fNSPrintInfo = ptr;
645+
}
646+
647+
public void dispose() {
648+
CPrinterJob.disposeNSPrintInfo(fNSPrintInfo);
621649
}
622650
}
623651

624-
private native long createNSPrintInfo();
625-
private native void dispose(long printInfo);
652+
private static native long createNSPrintInfo();
653+
private static native void disposeNSPrintInfo(long printInfo);
626654

627655
private long getNSPrintInfo() {
628656
// This is called from the native side.
629657
synchronized (fNSPrintInfoLock) {
630658
if (fNSPrintInfo == -1) {
631659
fNSPrintInfo = createNSPrintInfo();
660+
Disposer.addRecord(disposerReferent,
661+
new NSPrintInfoDisposer(fNSPrintInfo));
632662
}
633663
return fNSPrintInfo;
634664
}

src/java.desktop/macosx/native/libawt_lwawt/awt/CPrinterJob.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -617,11 +617,11 @@ static void javaPrinterJobToNSPrintInfo(JNIEnv* env, jobject srcPrinterJob, jobj
617617
* Signature: ()J
618618
*/
619619
JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CPrinterJob_createNSPrintInfo
620-
(JNIEnv *env, jobject jthis)
620+
(JNIEnv *env, jclass clazz)
621621
{
622622
jlong result = -1;
623623
JNI_COCOA_ENTER(env);
624-
// This is used to create the NSPrintInfo for this PrinterJob. Thread
624+
// This is used to create the NSPrintInfo for a PrinterJob. Thread
625625
// safety is assured by the java side of this call.
626626

627627
NSPrintInfo* printInfo = createDefaultNSPrintInfo(env, NULL);
@@ -634,11 +634,11 @@ static void javaPrinterJobToNSPrintInfo(JNIEnv* env, jobject srcPrinterJob, jobj
634634

635635
/*
636636
* Class: sun_lwawt_macosx_CPrinterJob
637-
* Method: dispose
637+
* Method: disposeNSPrintInfo
638638
* Signature: (J)V
639639
*/
640-
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPrinterJob_dispose
641-
(JNIEnv *env, jobject jthis, jlong nsPrintInfo)
640+
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPrinterJob_disposeNSPrintInfo
641+
(JNIEnv *env, jclass clazz, jlong nsPrintInfo)
642642
{
643643
JNI_COCOA_ENTER(env);
644644
if (nsPrintInfo != -1)

0 commit comments

Comments
 (0)