-
Bug
-
Resolution: Fixed
-
P3
-
6
FULL PRODUCT VERSION :
Java(TM) SE Runtime Environment (build 1.6.0_03-b05)
Java HotSpot(TM) Client VM (build 1.6.0_03-b05, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Windows XP Professional
A DESCRIPTION OF THE PROBLEM :
We have an application that overrides Printable.print method in which we does several
Graphics2D.drawString() in loop.
The problem is that the amount of time to be executed and the object created increases with memory usage
when drawString method is called compared to Java1.4.2.
This leads to Garbage Collection to occur often. In a result, there is a noticeable performance degradation in our application.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the following test case
ACTUAL -
Java1.4 - 14813ms
Java6.0 - 57797ms
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.print.*;
import java.awt.geom.*;
import javax.print.*;
import javax.print.attribute.*;
import javax.print.attribute.standard.*;
class PrintTest implements Printable {
/** Printer Job Name */
static String JOB_NAME = "TestPrint";
/** Print Data(1 Line) */
static String PRINT_DATA = "ABCDE FGHIJ KLMNO PQRST UVWXY Z";
/** Page No */
static int PAGE = 400;
/** Line */
static int LINE = 100;
/** Font Name */
static String FONT_NAME = "Courier New";
/** Font Size */
static int FONT_SIZE = 8;
/** Font Setting */
static Font FONT_SETTING = new Font(FONT_NAME, Font.PLAIN, FONT_SIZE);
/** Previous Page */
private int iOldPage = -1;
public static void main(String[] args) {
PrintTest pt = new PrintTest();
pt.printStart();
}
private void printStart() {
PrintService printService = PrintServiceLookup
.lookupDefaultPrintService();
if (printService == null) {
System.err.println("No Print Service is available");
System.exit(1);
}
DocPrintJob job = printService.createPrintJob();
MediaSizeName mediaSizeName = MediaSizeName.ISO_A4;
PrintRequestAttributeSet attr = new HashPrintRequestAttributeSet();
attr.add(new JobName(JOB_NAME, null));
attr.add(OrientationRequested.PORTRAIT);
attr.add(mediaSizeName);
Object obj = printService.getSupportedAttributeValues(
MediaPrintableArea.class,
DocFlavor.SERVICE_FORMATTED.PRINTABLE, attr);
MediaPrintableArea[] mpa0 = (MediaPrintableArea[]) obj;
if (mpa0 == null) {
System.err.println("Print Service is unsuccessful");
System.exit(1);
}
DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
Doc doc = new SimpleDoc(this, flavor, null);
try {
long start = System.currentTimeMillis();
job.print(doc, attr);
long end = System.currentTimeMillis() - start;
System.out.println(end);
} catch (PrintException e) {
System.err.println("Print failed");
}
}
public int print(Graphics g, PageFormat pf, int index) {
try {
Graphics2D g2d = (Graphics2D) g;
float x, y;
float dy = 0;
Rectangle2D r2d = FONT_SETTING.getMaxCharBounds(g2d
.getFontRenderContext());
if (r2d instanceof Rectangle2D.Double) {
dy = (float) ((Rectangle2D.Double) r2d).getHeight();
} else if (r2d instanceof Rectangle2D.Float) {
dy = (float) ((Rectangle2D.Float) r2d).getHeight();
}
x = (float) pf.getImageableX();
y = (float) pf.getImageableY() + dy;
for (int iLine = 1; iLine <= LINE; iLine++) {
g2d.drawString(PRINT_DATA, x, y);
y += dy;
}
if (index < PAGE) {
return Printable.PAGE_EXISTS;
} else {
iOldPage = index;
return Printable.NO_SUCH_PAGE;
}
} finally {
iOldPage = index;
}
}
}
---------- END SOURCE ----------
Release Regression From : 6
The above release value was the last known release where this
bug was not reproducible. Since then there has been a regression.
Java(TM) SE Runtime Environment (build 1.6.0_03-b05)
Java HotSpot(TM) Client VM (build 1.6.0_03-b05, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Windows XP Professional
A DESCRIPTION OF THE PROBLEM :
We have an application that overrides Printable.print method in which we does several
Graphics2D.drawString() in loop.
The problem is that the amount of time to be executed and the object created increases with memory usage
when drawString method is called compared to Java1.4.2.
This leads to Garbage Collection to occur often. In a result, there is a noticeable performance degradation in our application.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the following test case
ACTUAL -
Java1.4 - 14813ms
Java6.0 - 57797ms
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.print.*;
import java.awt.geom.*;
import javax.print.*;
import javax.print.attribute.*;
import javax.print.attribute.standard.*;
class PrintTest implements Printable {
/** Printer Job Name */
static String JOB_NAME = "TestPrint";
/** Print Data(1 Line) */
static String PRINT_DATA = "ABCDE FGHIJ KLMNO PQRST UVWXY Z";
/** Page No */
static int PAGE = 400;
/** Line */
static int LINE = 100;
/** Font Name */
static String FONT_NAME = "Courier New";
/** Font Size */
static int FONT_SIZE = 8;
/** Font Setting */
static Font FONT_SETTING = new Font(FONT_NAME, Font.PLAIN, FONT_SIZE);
/** Previous Page */
private int iOldPage = -1;
public static void main(String[] args) {
PrintTest pt = new PrintTest();
pt.printStart();
}
private void printStart() {
PrintService printService = PrintServiceLookup
.lookupDefaultPrintService();
if (printService == null) {
System.err.println("No Print Service is available");
System.exit(1);
}
DocPrintJob job = printService.createPrintJob();
MediaSizeName mediaSizeName = MediaSizeName.ISO_A4;
PrintRequestAttributeSet attr = new HashPrintRequestAttributeSet();
attr.add(new JobName(JOB_NAME, null));
attr.add(OrientationRequested.PORTRAIT);
attr.add(mediaSizeName);
Object obj = printService.getSupportedAttributeValues(
MediaPrintableArea.class,
DocFlavor.SERVICE_FORMATTED.PRINTABLE, attr);
MediaPrintableArea[] mpa0 = (MediaPrintableArea[]) obj;
if (mpa0 == null) {
System.err.println("Print Service is unsuccessful");
System.exit(1);
}
DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
Doc doc = new SimpleDoc(this, flavor, null);
try {
long start = System.currentTimeMillis();
job.print(doc, attr);
long end = System.currentTimeMillis() - start;
System.out.println(end);
} catch (PrintException e) {
System.err.println("Print failed");
}
}
public int print(Graphics g, PageFormat pf, int index) {
try {
Graphics2D g2d = (Graphics2D) g;
float x, y;
float dy = 0;
Rectangle2D r2d = FONT_SETTING.getMaxCharBounds(g2d
.getFontRenderContext());
if (r2d instanceof Rectangle2D.Double) {
dy = (float) ((Rectangle2D.Double) r2d).getHeight();
} else if (r2d instanceof Rectangle2D.Float) {
dy = (float) ((Rectangle2D.Float) r2d).getHeight();
}
x = (float) pf.getImageableX();
y = (float) pf.getImageableY() + dy;
for (int iLine = 1; iLine <= LINE; iLine++) {
g2d.drawString(PRINT_DATA, x, y);
y += dy;
}
if (index < PAGE) {
return Printable.PAGE_EXISTS;
} else {
iOldPage = index;
return Printable.NO_SUCH_PAGE;
}
} finally {
iOldPage = index;
}
}
}
---------- END SOURCE ----------
Release Regression From : 6
The above release value was the last known release where this
bug was not reproducible. Since then there has been a regression.