Out of memory when printing PDFs

Having problems with building or using the JCEF Java binding? Ask your questions here.

Out of memory when printing PDFs

Postby Phylanx » Tue Jan 10, 2017 11:07 am

Hi!

Our customer reported that our java client application crashes when we try to print specific PDFs.
We could reproduce that problem with the detailed MainFrame application and the PDF given by the customer.
We must not append the failing PDF, because our customer is a hospital and the PDF contains patient sensitive data.
I will provide an image containing blacked out screenshots and if you need more informations, I can support you with them on contact.

Error messages:
JVM crashes when printing, the JCEF Logfile prints an Out of memory error (logfiles will be appended):
[0110/161653:FATAL:memory_win.cc(38)] Out of memory, size = 139177987

Details:
Windows 10 64 bit
JDK 1.8.0_60 32 bit
JCEF version: 2704 32 bit compiled release version (tried upgrading to a newer version but stopped due to the crashpadhandler error: https://bitbucket.org/chromiumembedded/ ... issues/249 )
Used JVM arguments: -Xmx1024m
Used Application arguments: --ppapi-flash-path=\\pepflashplayer32.dll --allow-outdated-plugins --noerrdialogs --log-file=D:\Temp\head_ci\CEF_DUMMY.log --log-severity=verbose

Analysis:
Due to the Java Memory model every Java process has memory reserved for java objects (defined by -Xmx JVM parameter), the rest is used for native memory (loaded DLLs, native objects, CEF/JCEF native code,...).
The more memory we use for the java heap, the less memory is available for the native part of the application.
If we use for example -Xmx1024m, the native part that CEF is allowed to use is lower than if we define -Xmx512m.
Now the following things happen:
Our client application starts a JCEF application with -Xmx1024m which is initialized correctly, loads the problematic PDF and tries to print it.
The PDF has 8 pages, its size is about 165kB, so that shouldn't be a problem.
When printing, some native code tries to allocate 139177987 bytes (about 139MB).
We could reduce the problem to the first page, printing only page 1 fails, while printing 2-8 works fine.

The special things on page 1 are two images (one on top with the logo of the hospital, one on the footer with contact details; They are marked red in the appended screenshots; the barcode is also on pages 2-8 so it should not be the problem).

Now we have following questions:
1.
On the ongoing analysis we found following issue:
https://bitbucket.org/chromiumembedded/cef/issues/1855
Can that be the same problem and would it be possible that this fix fixes our issue?
2.
Why does CEF/PDFium need 139MB to parse a 165k PDF?
Is there already a known issue or a fix in a newer pdfium/chromium/cef/jcef version?
3.
Is there anything else we can do to avoid that problem (other than open the PDF in an external viewer)?

Thx for your help, I hope we could provide you with enough informations.
Attachments
SR_screens.jpg
SR_screens.jpg (361.09 KiB) Viewed 33028 times
detailedMainFrame.log
(80.86 KiB) Downloaded 778 times
CEF_log.log
(230.95 KiB) Downloaded 768 times
Phylanx
Expert
 
Posts: 201
Joined: Thu Aug 11, 2016 8:17 am

Re: Out of memory when printing PDFs

Postby magreenblatt » Tue Jan 10, 2017 12:18 pm

Try a build with the /LARGEADDRESSAWARE flag applied to all native binaries to see if that resolves your problem.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: Out of memory when printing PDFs

Postby Phylanx » Wed Jan 11, 2017 5:26 am

We had problems building up the whole 2704 CEF build mechanism, so we tried another approach.

We tried the same PDFs with a newer JCEF version (2883) where "/LARGEADDRESSAWARE" is already set: https://bitbucket.org/chromiumembedded/cef/issues/1855
Is that enough or do we have to apply that compiler flag on additional dlls?

Here is exactly what we did:

Version:
JCEF Version = 3.2883.0
CEF Version = 3.2883.1539
Chromium Version = 55.0.2883.59
We applied the hack we need to show the PDF in PDFium removing the "disable-extensions" commandline switch in client_app.cpp (viewtopic.php?f=17&t=14161&p=30774#p30756)
We built the whole native/java code
We executed the detailed MainFrame application with -Xmx1024m and following application arguments: --allow-outdated-plugins --noerrdialogs --log-file=D:\Temp\head_ci\CEF_TEST.log --log-severity=verbose
The result was nearly the same.
The JVM crashed, but the JCEF logfile didn't give an out of memory.
I guess the out of memory still happens, but is simply not printed because of the Crashpadhandler crash when initializing the CefApp (https://bitbucket.org/chromiumembedded/ ... ll-cefapps).
Phylanx
Expert
 
Posts: 201
Joined: Thu Aug 11, 2016 8:17 am

Re: Out of memory when printing PDFs

Postby magreenblatt » Wed Jan 11, 2017 9:28 am

Is there a value of -Xmx that does not crash?
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: Out of memory when printing PDFs

Postby Phylanx » Thu Jan 12, 2017 4:01 am

Hi!
Sorry, forgot to mention that the other day...
For now we could test following Xmx settings:
-Xmx1024 crashes
-Xmx512 works
-Xmx768 works
Our client needs 1024m, so we can't reduce that. Also if other PDFs need more memory, that also would be a problem.

In the meanwhile we could do further analysis:
Using the Adobe Editor license of our marketing department, we could test single components of the problematic PDF.
The Problem occurs if we reduce the whole PDF to contain only the barcode (see attached file "BC.pdf", on the bottom of the page).
But it is not only the barcode, a PDF where we only removed the barcode also crashed.

We would love to implement a workaround or a hack or anything helping, but we have no chance to influence the PDF printing in any way :-(
Might be delegating the printing to an external jcef_helper process be a valid alternative for CEF/JCEF?
Attachments
BC.pdf
(9.13 KiB) Downloaded 723 times
Phylanx
Expert
 
Posts: 201
Joined: Thu Aug 11, 2016 8:17 am

Re: Out of memory when printing PDFs

Postby magreenblatt » Thu Jan 12, 2017 9:58 am

Can you use a 64-bit JVM? That would likely also resolve the problem.

Chromium doesn't know about the memory usage constraints that the JVM is applying, so it can't do anything to keep its memory usage under that (arbitrary) limit.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: Out of memory when printing PDFs

Postby Phylanx » Thu Jan 12, 2017 10:18 am

I'm sorry, a 64 bit JVM is no option for our product.
We have many other native DLLs we would need to support in 64 bit too (we already estimated such work for over 50 days).

Why does such a small operation need so much memory?

And isn't it generally a good idea to do such memory intensive things in another process if it can be a problem to get 139 MB in native?
That could be a problem for loading bigger things into JCEF too (What if we had to open 150MB PDFs?).

After some further testing we had the same out of memory issues with 768m too.
Phylanx
Expert
 
Posts: 201
Joined: Thu Aug 11, 2016 8:17 am

Re: Out of memory when printing PDFs

Postby magreenblatt » Thu Jan 12, 2017 10:25 am

Can you provide a symbolized call stack for the out of memory crash?
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: Out of memory when printing PDFs

Postby Phylanx » Thu Jan 12, 2017 10:35 am

Unfortunatly no.
The problem is, that chromium overrides the out of memory error handling:

See: https://cs.chromium.org/chromium/src/ba ... in.cc?l=41

So no hs_err logfile is created, the application itself calls exit and the JVM is also terminated.

I can reproduce the problem, can I add any runtime parameters to get such or to prevent exiting with the _exit call?
Phylanx
Expert
 
Posts: 201
Joined: Thu Aug 11, 2016 8:17 am

Re: Out of memory when printing PDFs

Postby magreenblatt » Thu Jan 12, 2017 11:38 am

If you place the PDB file next to libcef.dll and attach a windows debugger to the process before it crashes then you should get a stack trace.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Next

Return to JCEF Forum

Who is online

Users browsing this forum: No registered users and 19 guests