[ https://issues.apache.org/jira/browse/PDFBOX-2901?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15628270#comment-15628270 ]
Evan Sayer commented on PDFBOX-2901: ------------------------------------ I believe we're hitting another variation of this problem that wasn't fixed by the patch here. I'll attach a stack-trace from a thread-dump of a JVM that has been churning through the shading code for > 10 minutes now to parse a ~200k PDF. This test is running version 2.0.1. We seem descend into the same costly shading code here as well, but before the logic in the patch here can clip the shaded area: https://github.com/apache/pdfbox/blob/2.0.1/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java#L588 > High CPU load and OutOfMemoryError when rendering shading > --------------------------------------------------------- > > Key: PDFBOX-2901 > URL: https://issues.apache.org/jira/browse/PDFBOX-2901 > Project: PDFBox > Issue Type: Bug > Components: Rendering > Affects Versions: 1.8.9, 1.8.10, 1.8.11, 2.0.0 > Reporter: Tilman Hausherr > Assignee: Tilman Hausherr > Fix For: 1.8.11, 2.0.0 > > Attachments: PDFBOX-2901-outofmemory.pdf > > > By Frank D. from the mailing list: > {quote} > When we try to convert the attached pdf, the CPU load of tomcat is raising > and it seems, that the process hangs. The tomcat process is no more > responsive and after a long while, we get an memory overflow. Also the server > load is very high meanwhile. > {quote} > Some debugging at 50 dpi: > {code} > PDFOperator{cs}: [COSName{CS0}] > PDFOperator{scn}: [COSName{P0}] > PDFOperator{gs}: [COSName{GS0}] > PDFOperator{m}: [COSFloat{-10551.00391}, COSFloat{667.6051}] > PDFOperator{l}: [COSFloat{-10551.00391}, COSFloat{1447.09143}] > PDFOperator{l}: [COSFloat{9338.57129}, COSFloat{1447.09143}] > PDFOperator{l}: [COSFloat{9338.57129}, COSFloat{667.6051}] > PDFOperator{f}: [] > f = Fill path using non zero winding rule > (...wait...) > PDFOperator{cs}: [COSName{CS0}] > PDFOperator{scn}: [COSName{P0}] > PDFOperator{gs}: [COSName{GS0}] > PDFOperator{m}: [COSFloat{-18801.79492}, COSFloat{667.6051}] > PDFOperator{l}: [COSFloat{-18801.79492}, COSFloat{1447.09143}] > PDFOperator{l}: [COSFloat{1087.7804}, COSFloat{1447.09143}] > PDFOperator{l}: [COSFloat{1087.7804}, COSFloat{667.6051}] > PDFOperator{f}: [] > (...wait...) > PDFOperator{cs}: [COSName{CS0}] > PDFOperator{scn}: [COSName{P0}] > PDFOperator{gs}: [COSName{GS0}] > PDFOperator{m}: [COSFloat{-18801.79492}, COSFloat{11.15869}] > PDFOperator{l}: [COSFloat{-18801.79492}, COSFloat{790.64502}] > PDFOperator{l}: [COSFloat{1087.7804}, COSFloat{790.64502}] > PDFOperator{l}: [COSFloat{1087.7804}, COSFloat{11.15869}] > PDFOperator{f}: [] > (...wait...) > (...wait...) > (...wait...) > PDFOperator{cs}: [COSName{CS0}] > PDFOperator{scn}: [COSName{P0}] > PDFOperator{gs}: [COSName{GS0}] > PDFOperator{m}: [COSFloat{-10551.00391}, COSFloat{667.6051}] > PDFOperator{l}: [COSFloat{-10551.00391}, COSFloat{1447.09143}] > PDFOperator{l}: [COSFloat{9338.57129}, COSFloat{1447.09143}] > PDFOperator{l}: [COSFloat{9338.57129}, COSFloat{667.6051}] > PDFOperator{f}: [] > Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit > exceeded > at sun.java2d.cmm.kcms.CMMImageLayout.<init>(Unknown Source) > at sun.java2d.cmm.kcms.ICC_Transform.colorConvert(Unknown Source) > at java.awt.color.ICC_ColorSpace.toRGB(Unknown Source) > at > org.apache.pdfbox.pdmodel.graphics.color.PDDeviceRGB.toRGB(PDDeviceRGB.java:82) > at > org.apache.pdfbox.pdmodel.graphics.shading.ShadingContext.convertToRGB(ShadingContext.java:142) > at > org.apache.pdfbox.pdmodel.graphics.shading.TriangleBasedShadingContext.evalFunctionAndConvertToRGB(TriangleBasedShadingContext.java:167) > at > org.apache.pdfbox.pdmodel.graphics.shading.TriangleBasedShadingContext.calcPixelTable(TriangleBasedShadingContext.java:121) > at > org.apache.pdfbox.pdmodel.graphics.shading.GouraudShadingContext.calcPixelTable(GouraudShadingContext.java:111) > at > org.apache.pdfbox.pdmodel.graphics.shading.TriangleBasedShadingContext.createPixelTable(TriangleBasedShadingContext.java:80) > at > org.apache.pdfbox.pdmodel.graphics.shading.Type4ShadingContext.<init>(Type4ShadingContext.java:65) > at > org.apache.pdfbox.pdmodel.graphics.shading.Type4ShadingPaint.createContext(Type4ShadingPaint.java:66) > at sun.java2d.pipe.AlphaPaintPipe.startSequence(Unknown Source) > at sun.java2d.pipe.SpanShapeRenderer$Composite.startSequence(Unknown > Source) > at sun.java2d.pipe.SpanShapeRenderer.renderSpans(Unknown Source) > at sun.java2d.pipe.SpanShapeRenderer.fill(Unknown Source) > at sun.java2d.pipe.ValidatePipe.fill(Unknown Source) > at sun.java2d.SunGraphics2D.fill(Unknown Source) > at > org.apache.pdfbox.rendering.PageDrawer.fillPath(PageDrawer.java:611) > {code} > The problem is that a type 4 shading ("gouraud shading") is called with huge > triangles (not shown here but I saw it in debugging) and huge device bounds > (e.g. x=-10551.004,y=667.6051,w=19889.574,h=779.4863). The shading routines > of types 4-7 create a mapping table for the color of every point in a shading > triangle. Because these triangles and the device bounds are so huge, the > table is huge and takes a long time to be calculated, uses a lot of memory, > with the result above. > IMHO it is a java bug, it should consider the clipping when calculating the > device bounds when calling Paint.createContext() and not pass device bounds > outside of the clipping region. The solution will be (once again :-( ) to do > ourselves what java doesn't. -- This message was sent by Atlassian JIRA (v6.3.4#6332) --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@pdfbox.apache.org For additional commands, e-mail: dev-h...@pdfbox.apache.org