Table2 Kilsl JVM

Skip Navigation LinksHome  /  Support  /  Forums  /  DynamicPDF Merger for Java (v8)  /  Re: Table2 Kilsl JVM

DynamicPDF Merger for Java (v8) Forum

 Jan 19 2017 4:02 PM
The following code will kill the JVM when executed in a 64-bit JVM (tested in 1.8_111 - some earlier JVMs are OK)

package com.test.pdf.table;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Random;

import com.cete.dynamicpdf.Document;
import com.cete.dynamicpdf.Font;
import com.cete.dynamicpdf.Page;
import com.cete.dynamicpdf.PageSize;
import com.cete.dynamicpdf.RgbColor;
import com.cete.dynamicpdf.TextAlign;
import com.cete.dynamicpdf.pageelements.Label;
import com.cete.dynamicpdf.pageelements.Row2;
import com.cete.dynamicpdf.pageelements.Table2;

public class TableCreator {
        private int rowCount = 0;
        private int colCount = 0;
        private Random RAND = new Random(System.currentTimeMillis());
        private String rowCellData = "X";
        public static File pdfDir = new File(System.getProperty("user.dir") + File.separator + "pdfs");
        
        public TableCreator( final int rows, final int cols) {
                this.rowCount = rows;
                this.colCount = cols;
        }
        
        public void run()
        {
                System.out.println("Printing table: ROWS = " + rowCount + ", COLS = " + colCount);

                String fileName = "out-" + rowCount + "-" + colCount + ".pdf";

                File out = new File(System.getProperty("user.dir") + File.separator + "pdfs", fileName);
                System.out.println("Will create file at: " + out.getAbsolutePath());

                FileOutputStream fos = null;
                try {
                        // Create a document and set it's properties
                        Document document = new Document();

                        Table2 table = new Table2(0, 0, 512, 676, Font.getHelvetica(), 12);

                        buildTable(table);

                        addPage(document, table, "(1, 1)");

                        addPage(document, table.getOverflowColumns(), "(1, 2)");

                        Table2 overflowRowTable = table.getOverflowRows();
                        if (overflowRowTable != null) {
                                addPage(document, overflowRowTable, "(2, 1)");
                                Table2 overflowColumns = overflowRowTable.getOverflowColumns();
                                if (overflowColumns != null) {
                                        addPage(document, overflowColumns, "(2, 2)");
                                }
                        }

                        fos = new FileOutputStream(out);

                        document.draw(fos);
                } catch (Throwable t) {
                        t.printStackTrace();
                } finally {
                        if (fos != null) {
                                try {
                                        fos.close();
                                } catch (IOException e) {
                                }
                        }
                }
        }

        private void addPage(Document document, Table2 table, String pageLabel) {
                Page page = new Page(PageSize.LETTER);
                if (table != null) {
                        page.getElements().add(table);
                }
                page.getElements().add(new Label(pageLabel, 0, page.getDimensions().getBody().getHeight() - 12,
                                page.getDimensions().getBody().getWidth(), 12, Font.getHelvetica(), 12, TextAlign.CENTER));
                document.getPages().add(page);
        }

        private void buildTable(Table2 table) {
                // add columns to table
                for( int idx=0; idx<this.colCount; idx++) {
                        table.getColumns().add(50);
                }
                
                // add data rows to table
                for (int row = 0; row<rowCount; row++) {
                        final boolean flag = RAND.nextBoolean();

                        // FIXME: This is where the JVM crashes - change to false to not fail
                        addRow(table, flag, true);
                        //
                }
        }
        
        private float addRow(final Table2 currentTable, final boolean flag, final boolean fail) {
                Row2 row = null;
                if( flag ) {
                        row = currentTable.getRows().add(20, Font.getHelveticaBold(), 10, RgbColor.getBlue(), RgbColor.getLightGrey());
                        for (int col=0; col<colCount; col++) {
                                if( !fail ) {
                                        row.getCells().add(rowCellData, Font.getHelveticaBold(), 10, RgbColor.getBlue(), RgbColor.getLightGrey(), 1);
                                } else {
                                        row.getCells().add(rowCellData);
                                }
                        }
                } else {
                        row = currentTable.getRows().add();
                        for (int col=0; col<colCount; col++) {
                                if (col == 0) {
                                        row.getCells().add(rowCellData, Font.getHelveticaBold(), 6, RgbColor.getBlack(), RgbColor.getWhite(), 1);
                                } else {
                                        row.getCells().add(rowCellData, Font.getHelvetica(), 6, RgbColor.getBlack(), RgbColor.getWhite(), 4);
                                }
                        }
                }
                return row == null ? 0f : row.getActualRowHeight();
        }

}
 Jan 20 2017 10:50 AM
Posted by a ceTe Software moderator
Hello,

We are currently investigating this issue. We will post an update once the issue is resolved.

Thanks,
ceTe Software Support Team.
 Jan 23 2017 2:05 PM
We have a (very) temporary workaround for this issue, the fix changes for each Dynamic PDF release - due to obfuscation of class and method names

What you have to do is force the failure and then review the JVM Crash report for the obfuscated method path of the failure

You can then include the following JVM directive:
-XX:CompileCommand=exclude,com.cete.dynamicpdf.pageelements.B::K

The "B" and "K" are the obfuscated class and method names, respectively for the specific release you are running against.


For example, here is the part of the crash report to look at:

# JRE version: Java(TM) SE Runtime Environment (8.0_111-b14) (build 1.8.0_111-b14)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.111-b14 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# J 23231 C2 com.cete.dynamicpdf.pageelements.x.J()V (365 bytes) @ 0x00007f1697c3f265 [0x00007f1697c3eb20+0x745]

That last line shows you what to put in your "CompileCommand" directive - in this case "com.cete.dynamicpdf.pageelements.x.J" -> "com.cete.dynamicpdf.pageelements.x::J"
 Jan 23 2017 2:11 PM
I should note, in the reproduce code I had a switch off of "if( !fail )" which contained code which would either reproduce or not reproduce the issue.

It does not. I have had it fail using both.
 Feb 15 2017 4:57 PM
Posted by a ceTe Software moderator
Hello,

This issue is fixed in the latest build of the product.

The latest build is available for download here

Thanks,
ceTe Software Support Team.

All times are US Eastern Standard time. The time now is 4:01 AM.