JDK-6569481 : AffineTransform causes memory leak and Access Violation
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 6
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2007-06-14
  • Updated: 2010-04-04
  • Resolved: 2007-06-14
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.6.0_01"
Java(TM) SE Runtime Environment (build 1.6.0_01-b06)
Java HotSpot(TM) Client VM (build 1.6.0_01-b06, mixed mode, sharing)

FULL OS VERSION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
I found in internet some example of using of the AffineTransform class and slightly changed it. Unfortunately, after couple of seconds the memory consumtion of this simple application starts to grow constantly and finally it crashes with Access Violation in ntdll.dll or fontmanager.dll

THE PROBLEM WAS REPRODUCIBLE WITH -Xint FLAG: Yes

THE PROBLEM WAS REPRODUCIBLE WITH -server FLAG: Did not try

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the provided application. Monitor the memory via Task Manager.

EXPECTED VERSUS ACTUAL BEHAVIOR :
I would expect smooth running of the application, hovewer after couple of seconds it starts to consume memory (takes more than a 1 Gb) and finally crashes with Access Violation
ERROR MESSAGES/STACK TRACES THAT OCCUR :
#
# An unexpected error has been detected by Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x7c910f29, pid=2380, tid=1252
#
# Java VM: Java HotSpot(TM) Client VM (1.6.0_01-b06 mixed mode, sharing)
# Problematic frame:
# C  [ntdll.dll+0x10f29]
#
# If you would like to submit a bug report, please visit:
#   http://java.sun.com/webapps/bugreport/crash.jsp
#

---------------  T H R E A D  ---------------

Current thread (0x02ae9000):  JavaThread "AWT-EventQueue-0" [_thread_in_native, id=1252]

siginfo: ExceptionCode=0xc0000005, reading address 0x00000000

Registers:
EAX=0x02b37318, EBX=0x003a0000, ECX=0x00000000, EDX=0x00000000
ESP=0x02fce8a8, EBP=0x02fce8b4, ESI=0x02b37310, EDI=0x02b35ea8
EIP=0x7c910f29, EFLAGS=0x00010246

  Top of Stack: (sp=0x02fce8a8)
0x02fce8a8:   003a0000 02b366d0 00000000 02fce988
0x02fce8b8:   7c910d5c 0ebd7008 00000000 02fce96c
0x02fce8c8:   00000000 02b1f630 02b366d8 00000030
0x02fce8d8:   03f10000 6d37c6a9 02b2fda0 01192c8d
0x02fce8e8:   7ffad000 00000000 7ffad000 2a139200
0x02fce8f8:   02fce944 6d36fa6b e0fc81e4 00010000
0x02fce908:   2a139200 00000000 e0fc81e4 00000000
0x02fce918:   2a139200 00010000 0003830c 40106000

Instructions: (pc=0x7c910f29)
0x7c910f19:   85 92 00 00 00 8b 4e 0c 8d 46 08 8b 10 89 4d 0c
0x7c910f29:   8b 09 3b 4a 04 89 55 14 0f 85 ea 0f 00 00 3b c8


Stack: [0x02f80000,0x02fd0000),  sp=0x02fce8a8,  free space=314k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C  [ntdll.dll+0x10f29]
C  [ntdll.dll+0x10d5c]
C  [msvcr71.dll+0x218a]

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
J  sun.font.FileFont.getGlyphImage(JI)J
J  sun.font.FileFontStrike.getGlyphImagePtr(I)J
J  sun.font.FileFontStrike.getGlyphMetrics(I)Ljava/awt/geom/Point2D$Float;
v  ~StubRoutines::call_stub
j  sun.font.SunLayoutEngine.nativeLayout(Lsun/font/Font2D;Lsun/font/FontStrike;[FII[CIIIIIIILjava/awt/geom/Point2D$Float;Lsun/font/GlyphLayout$GVData;)V+0
j  sun.font.SunLayoutEngine.layout(Lsun/font/FontStrikeDesc;[FIILsun/font/TextRecord;ILjava/awt/geom/Point2D$Float;Lsun/font/GlyphLayout$GVData;)V+70
j  sun.font.GlyphLayout$EngineRecord.layout()V+95
j  sun.font.GlyphLayout.layout(Ljava/awt/Font;Ljava/awt/font/FontRenderContext;[CIIILsun/font/StandardGlyphVector;)Lsun/font/StandardGlyphVector;+541
j  sun.font.ExtendedTextSourceLabel.createGV()Lsun/font/StandardGlyphVector;+63
j  sun.font.ExtendedTextSourceLabel.getGV()Lsun/font/StandardGlyphVector;+9
j  sun.font.ExtendedTextSourceLabel.createLogicalBounds()Ljava/awt/geom/Rectangle2D;+1
j  sun.font.ExtendedTextSourceLabel.getAdvance()F+9
j  java.awt.font.TextLine.init()V+626
j  java.awt.font.TextLine.<init>(Ljava/awt/font/FontRenderContext;[Lsun/font/TextLineComponent;[F[CII[I[BZ)V+79
j  java.awt.font.TextLine.fastCreateTextLine(Ljava/awt/font/FontRenderContext;[CLjava/awt/Font;Lsun/font/CoreMetrics;Ljava/util/Map;)Ljava/awt/font/TextLine;+337
j  java.awt.font.TextLayout.fastInit([CLjava/awt/Font;Ljava/util/Map;Ljava/awt/font/FontRenderContext;)V+83
j  java.awt.font.TextLayout.<init>(Ljava/lang/String;Ljava/awt/Font;Ljava/awt/font/FontRenderContext;)V+124
j  sun.java2d.pipe.OutlineTextRenderer.drawString(Lsun/java2d/SunGraphics2D;Ljava/lang/String;DD)V+23
j  sun.java2d.pipe.GlyphListPipe.drawString(Lsun/java2d/SunGraphics2D;Ljava/lang/String;DD)V+24
j  sun.java2d.SunGraphics2D.drawString(Ljava/lang/String;FF)V+58
j  Test.paint(Ljava/awt/Graphics;)V+65
j  java.awt.Container.update(Ljava/awt/Graphics;)V+33
j  sun.awt.RepaintArea.updateComponent(Ljava/awt/Component;Ljava/awt/Graphics;)V+6
j  sun.awt.RepaintArea.paint(Ljava/lang/Object;Z)V+263
j  sun.awt.windows.WComponentPeer.handleEvent(Ljava/awt/AWTEvent;)V+107
j  java.awt.Component.dispatchEventImpl(Ljava/awt/AWTEvent;)V+849
j  java.awt.Container.dispatchEventImpl(Ljava/awt/AWTEvent;)V+42
j  java.awt.Window.dispatchEventImpl(Ljava/awt/AWTEvent;)V+19
j  java.awt.Component.dispatchEvent(Ljava/awt/AWTEvent;)V+2
j  java.awt.EventQueue.dispatchEvent(Ljava/awt/AWTEvent;)V+46
j  java.awt.EventDispatchThread.pumpOneEventForFilters(I)Z+156
j  java.awt.EventDispatchThread.pumpEventsForFilter(ILjava/awt/Conditional;Ljava/awt/EventFilter;)V+30
j  java.awt.EventDispatchThread.pumpEventsForHierarchy(ILjava/awt/Conditional;Ljava/awt/Component;)V+11
j  java.awt.EventDispatchThread.pumpEvents(ILjava/awt/Conditional;)V+4
j  java.awt.EventDispatchThread.pumpEvents(Ljava/awt/Conditional;)V+3
j  java.awt.EventDispatchThread.run()V+9
v  ~StubRoutines::call_stub

---------------  P R O C E S S  ---------------

Java Threads: ( => current thread )
  0x003a7000 JavaThread "DestroyJavaVM" [_thread_blocked, id=3612]
  0x02b1fc00 JavaThread "Thread-2" [_thread_blocked, id=2448]
=>0x02ae9000 JavaThread "AWT-EventQueue-0" [_thread_in_native, id=1252]
  0x02ae7000 JavaThread "AWT-Windows" daemon [_thread_in_native, id=1336]
  0x02ae6400 JavaThread "AWT-Shutdown" [_thread_blocked, id=812]
  0x02ae4400 JavaThread "Java2D Disposer" daemon [_thread_blocked, id=2516]
  0x02aa4000 JavaThread "Low Memory Detector" daemon [_thread_blocked, id=2916]
  0x02a9f400 JavaThread "CompilerThread0" daemon [_thread_blocked, id=2716]
  0x02a9e400 JavaThread "Attach Listener" daemon [_thread_blocked, id=3152]
  0x02a9d400 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=3524]
  0x02a62400 JavaThread "Finalizer" daemon [_thread_blocked, id=3672]
  0x02a5e000 JavaThread "Reference Handler" daemon [_thread_blocked, id=2680]

Other Threads:
  0x02a54c00 VMThread [id=872]
  0x02aa5800 WatcherThread [id=3692]

VM state:not at safepoint (normal execution)

VM Mutex/Monitor currently owned by a thread: None

Heap
 def new generation   total 960K, used 448K [0x22990000, 0x22a90000, 0x22e70000)
  eden space 896K,  42% used [0x22990000, 0x229f0220, 0x22a70000)
  from space 64K, 100% used [0x22a70000, 0x22a80000, 0x22a80000)
  to   space 64K,   0% used [0x22a80000, 0x22a80000, 0x22a90000)
 tenured generation   total 4096K, used 1687K [0x22e70000, 0x23270000, 0x26990000)
   the space 4096K,  41% used [0x22e70000, 0x23015d80, 0x23015e00, 0x23270000)
 compacting perm gen  total 12288K, used 293K [0x26990000, 0x27590000, 0x2a990000)
   the space 12288K,   2% used [0x26990000, 0x269d9538, 0x269d9600, 0x27590000)
    ro space 8192K,  66% used [0x2a990000, 0x2aedc5d0, 0x2aedc600, 0x2b190000)
    rw space 12288K,  52% used [0x2b190000, 0x2b7d8c98, 0x2b7d8e00, 0x2bd90000)

Dynamic libraries:
0x00400000 - 0x00423000 	C:\Program Files\Java\jdk1.6.0_01\bin\javaw.exe
0x7c900000 - 0x7c9b0000 	C:\WINDOWS\system32\ntdll.dll
0x7c800000 - 0x7c8f4000 	C:\WINDOWS\system32\kernel32.dll
0x77dd0000 - 0x77e6b000 	C:\WINDOWS\system32\ADVAPI32.dll
0x77e70000 - 0x77f01000 	C:\WINDOWS\system32\RPCRT4.dll
0x7e410000 - 0x7e4a0000 	C:\WINDOWS\system32\USER32.dll
0x77f10000 - 0x77f57000 	C:\WINDOWS\system32\GDI32.dll
0x629c0000 - 0x629c9000 	C:\WINDOWS\system32\LPK.DLL
0x74d90000 - 0x74dfb000 	C:\WINDOWS\system32\USP10.dll
0x77c10000 - 0x77c68000 	C:\WINDOWS\system32\msvcrt.dll
0x7c340000 - 0x7c396000 	C:\Program Files\Java\jdk1.6.0_01\jre\bin\msvcr71.dll
0x6d870000 - 0x6dab7000 	C:\Program Files\Java\jdk1.6.0_01\jre\bin\client\jvm.dll
0x76b40000 - 0x76b6d000 	C:\WINDOWS\system32\WINMM.dll
0x6d3c0000 - 0x6d3c8000 	C:\Program Files\Java\jdk1.6.0_01\jre\bin\hpi.dll
0x76bf0000 - 0x76bfb000 	C:\WINDOWS\system32\PSAPI.DLL
0x6d820000 - 0x6d82c000 	C:\Program Files\Java\jdk1.6.0_01\jre\bin\verify.dll
0x6d460000 - 0x6d47f000 	C:\Program Files\Java\jdk1.6.0_01\jre\bin\java.dll
0x6d860000 - 0x6d86f000 	C:\Program Files\Java\jdk1.6.0_01\jre\bin\zip.dll
0x6d0b0000 - 0x6d273000 	C:\Program Files\Java\jdk1.6.0_01\jre\bin\awt.dll
0x73000000 - 0x73026000 	C:\WINDOWS\system32\WINSPOOL.DRV
0x76390000 - 0x763ad000 	C:\WINDOWS\system32\IMM32.dll
0x774e0000 - 0x7761d000 	C:\WINDOWS\system32\ole32.dll
0x5ad70000 - 0x5ada8000 	C:\WINDOWS\system32\uxtheme.dll
0x73760000 - 0x737a9000 	C:\WINDOWS\system32\ddraw.dll
0x73bc0000 - 0x73bc6000 	C:\WINDOWS\system32\DCIMAN32.dll
0x6d360000 - 0x6d3b3000 	C:\Program Files\Java\jdk1.6.0_01\jre\bin\fontmanager.dll
0x74720000 - 0x7476b000 	C:\WINDOWS\system32\MSCTF.dll
0x6d620000 - 0x6d633000 	C:\Program Files\Java\jdk1.6.0_01\jre\bin\net.dll
0x71ab0000 - 0x71ac7000 	C:\WINDOWS\system32\WS2_32.dll
0x71aa0000 - 0x71aa8000 	C:\WINDOWS\system32\WS2HELP.dll
0x6d640000 - 0x6d649000 	C:\Program Files\Java\jdk1.6.0_01\jre\bin\nio.dll

VM Arguments:
java_command: Test
Launcher Type: SUN_STANDARD

Environment Variables:
JAVA_HOME=D:\gs\jdk1.5.0_07
PATH=.;C:\Borland\JBuilder2005\bin;C:\Borland\JBuilder2005\jdk1.4\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\QuickTime\QTSystem\;C:\Program Files\Microsoft SQL Server\80\Tools\BINN;C:\Borland\JBuilder2005\debug\sa;C:\Borland\JBuilder2005\lib
USERNAME=max
OS=Windows_NT
PROCESSOR_IDENTIFIER=x86 Family 15 Model 4 Stepping 1, GenuineIntel



---------------  S Y S T E M  ---------------

OS: Windows XP Build 2600 Service Pack 2

CPU:total 2 family 15, cmov, cx8, fxsr, mmx, sse, sse2, ht

Memory: 4k page, physical 1038404k(5540k free), swap 2541608k(539788k free)

vm_info: Java HotSpot(TM) Client VM (1.6.0_01-b06) for windows-x86, built on Mar 14 2007 00:24:02 by "java_re" with unknown MS VC++:1310

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.Graphics2D;
import javax.swing.JFrame;
import java.awt.Graphics;
import java.awt.Color;

public class Test extends JFrame {
  java.awt.geom.AffineTransform aft = new java.awt.geom.AffineTransform();
  double shx, shy;
  
  Test() {
    setSize(200, 200);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setVisible(true);
    aft.setToRotation(Math.PI / 8.0);
    new Thread() {
      public void run() {
        for (shx = 0; shx < 2; shx += .1) {
          for (shy = 0; shy < 2; shy += .1) {
            aft.setToShear(shx, shy);
            repaint();
            try {
              sleep(800);
            }
            catch (InterruptedException e) {}
          }
        }
      }
    }.start();
  }

  public static void main(String[] args) {
    new Test();
  }

  public void paint(Graphics g) {
    super.paint(g);
    g.setColor(Color.RED);
    g.drawString("" + shx + "   " + shy, 50, 190);
    g.setColor(Color.BLACK);
    Graphics2D g2D = (Graphics2D) g;
    String s = "Rotated Hello World";

    for (int i = 0; i < 16; i++) {
      g2D.drawString(s, 0.0f, 0.0f);
      g2D.transform(aft);
    }
  }
}
---------- END SOURCE ----------

Comments
EVALUATION This is a duplicate of 6533413: REGRESSION:JEudlid bean crashes with font sizes 180 and greater The transform being used in this test eventually reaches some really large values - point sizess of 12,000 (!) and we use a ton of memory because the unusual transform causes us to use a segmented cache which also implies always getting images with advances. 6533413 is fixed in 6u2 and the crash is no longer reproducible and memory is stable. However a separate issue, is that because of the way the transform is being mutated it occasionally ends up as a non-invertible transform. On those cases you see an Error thrown : Exception in thread "AWT-EventQueue-0" java.lang.InternalError at sun.font.GlyphLayout$SDCache.<init>(GlyphLayout.java:222) at sun.font.GlyphLayout$SDCache.get(GlyphLayout.java:322) at sun.font.GlyphLayout.layout(GlyphLayout.java:367) at sun.font.ExtendedTextSourceLabel.createGV(ExtendedTextSourceLabel.jav a:308) at sun.font.ExtendedTextSourceLabel.getGV(ExtendedTextSourceLabel.java:2 94) at sun.font.ExtendedTextSourceLabel.createLogicalBounds(ExtendedTextSour ceLabel.java:208) at sun.font.ExtendedTextSourceLabel.getAdvance(ExtendedTextSourceLabel.j ava:117) at java.awt.font.TextLine.init(TextLine.java:264) at java.awt.font.TextLine.<init>(TextLine.java:110) at java.awt.font.TextLine.fastCreateTextLine(TextLine.java:952) at java.awt.font.TextLayout.fastInit(TextLayout.java:585) at java.awt.font.TextLayout.<init>(TextLayout.java:374) .... Putting in a check into the test app as follows : if (g2D.getTransform().getDeterminant() == 0.0) { System.out.println("NON inv TX: " + g2D.getTransform()); } else { g2D.drawString(s, 0.0f, 0.0f); } ... detects and avoids these : NON inv TX: AffineTransform[[6347.443148437502, 3548.3286523437505, 0.0], [10994 .094031250006, 6145.885507812502, 0.0]] NON inv TX: AffineTransform[[3788.148902169519, 2479.933178699981, 0.0], [5576.0 04205000602, 3650.3627997917592, 0.0]] NON inv TX: AffineTransform[[2964.6162944327693, 1666.2427877769223, 0.0], [4528 .526191912553, 2545.227900387329, 0.0]] NON inv TX: AffineTransform[[6314.358444597575, 3548.363117070685, 0.0], [11236. 483204057175, 6314.358444597576, 0.0]] NON inv TX: AffineTransform[[3676.4292292428636, 2807.929301026101, 0.0], [4608. 647937053389, 3519.9256598312836, 0.0]] .. The code that threw the Error looks like this : if (!dtx.isIdentity()) { try { invdtx = dtx.createInverse(); } catch (NoninvertibleTransformException e) { throw new InternalError(); } } Its highly questionable whether its an internal error that an app specified such a TX, but its a separate question than the subject of this bug report.
14-06-2007