JDK-6979122 : Endless loop while concurrently rendering text in multiple threads
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 6
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux_suse_sles_11
  • CPU: x86
  • Submitted: 2010-08-23
  • Updated: 2012-06-11
  • Resolved: 2012-06-11
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :


A DESCRIPTION OF THE PROBLEM :
Within method sun.font.SunLayoutEngine.getEngine() the field cacheref and the HashMap contained within are accessed without synchronisation.
Concurrent execution of methods calling sun.font.SunLayoutEngine.getEngine() leads to a corrupt HashMap and as a result in endless loops.
This is the case if TextLayout is used from mutliple threads concurrently. TextLayout subsequently calls SunLayoutEngine.getEngine():

	at sun.font.SunLayoutEngine.getEngine()
	at sun.font.GlyphLayout$EngineRecord.init()
	at sun.font.GlyphLayout.nextEngineRecord()
	at sun.font.GlyphLayout.layout()
	at sun.font.ExtendedTextSourceLabel.createGV()
	at sun.font.ExtendedTextSourceLabel.getGV()
	at sun.font.ExtendedTextSourceLabel.createLogicalBounds()
	at sun.font.ExtendedTextSourceLabel.getAdvance()
	at java.awt.font.TextLine.init()
	at java.awt.font.TextLine.()
	at java.awt.font.TextLine.fastCreateTextLine()
	at java.awt.font.TextLayout.fastInit()
	at java.awt.font.TextLayout.()


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
The bug is not reproducible all the time. The attached source code will at least cause sun.font.SunLayoutEngine.getEngine() to be called concurrently from multiple threads.


REPRODUCIBILITY :
This bug can be reproduced occasionally.

---------- BEGIN SOURCE ----------
import java.awt.Font;
import java.awt.font.FontRenderContext;
import java.awt.font.TextLayout;
import java.awt.geom.AffineTransform;


public class TextLayoutBug implements Runnable {
  public void run() {
    FontRenderContext FRC = new FontRenderContext(AffineTransform.getScaleInstance(1.0, 1.0), true, true);
    while (true) {
      Font f = new Font("Helvetica", Font.PLAIN, 16);
      new TextLayout("Test", f, FRC);
    }
  }
  
  public static void main(String[] args) {
    for (int i=0; i<2000; i++)
      new Thread(new TextLayoutBug()).start();
  }
}

---------- END SOURCE ----------