Hi,
I’ve had a niggly problem where my applet demo stalls for ages before displaying anything.
Here it is: http://www.keithwoodward.com/straightedge/index.html
I think I’ve figured out the problem- the applet stalls while it tries to download something, because
- When I pull out the network cable just after it begins to stall the applet just stays frozen forever.
- It only affects the applet version of the demo not the (http://www.keithwoodward.com/straightedge/straightedge.jnlp) webstart version
- When using appletviewer on my computer’s local version of the applet then there is no pause, it only occurs when the applet is hosted from my website.
- Running the applet using appletviewer.exe with the -Xprof option on the web-hosted applet shows that a lot of time is spent in the method java.net.SocketInputStream.socketRead0 in the thread which runs the code that stalls. The place where the code stalls is just before the constructor of my game’s View object. Using System.out.println I know that the stall occurs before the constructor is actually executed, and before the class is fully loaded (static{System.out.println();} is printed after the stall has ended and the applet continues).
I’ve got a feeling that the applet is trying to download the jts-1.11.jar when the classloader tries to load the View class, since the View class references code that requires the jts-1.11.jar file, and so the applet pauses while that jar is being downloaded. But this is just a guess :-\
So my question is, why is the applet trying to download stuff halfway thru execution? I thought eager downloading was the default and lazy downloading had to be specified?
Here’s my applet html code:
<applet code="straightedge.test.demo.AppletImpl.class"
archive="straightedge.jar, jts-1.11.jar"
width="500" height="500"
align="center"
alt="StraightEdge demo applet">
</applet>
And the huge -Xprof output from appletviewer. The last lines printed to the console when the stall occurs are 1/4 way down at:
MainApplet: init
: start 0
: start 1
: start .1
: start .2
: start .3.
C:\Users\Keith>c:\"Program Files"\Java\jdk1.6.0_20\bin\appletviewer.exe http://w
ww.keithwoodward.com/straightedge/index.html -J-Xprof
Flat profile of 0.01 secs (1 total ticks): AppContextCreator
Thread-local ticks:
100.0% 1 Unknown: no last frame
Flat profile of 0.98 secs (97 total ticks): main
Interpreted + native Method
52.6% 0 + 50 java.net.SocketInputStream.socketRead0
24.2% 0 + 23 sun.java2d.d3d.D3DRenderQueue.flushBuffer
2.1% 0 + 2 sun.java2d.d3d.D3DGraphicsDevice.initD3D
2.1% 0 + 2 java.io.WinNTFileSystem.canonicalize0
1.1% 0 + 1 java.io.WinNTFileSystem.getBooleanAttributes
1.1% 0 + 1 java.net.Inet6AddressImpl.lookupAllHostAddr
1.1% 0 + 1 java.lang.ClassLoader$NativeLibrary.load
1.1% 0 + 1 sun.awt.windows.WMenuItemPeer.create
1.1% 0 + 1 sun.awt.windows.WFramePeer.setMenuBar0
1.1% 0 + 1 java.io.WinNTFileSystem.checkAccess
1.1% 0 + 1 java.util.zip.ZipFile.open
1.1% 0 + 1 sun.awt.windows.WComponentPeer.pShow
1.1% 0 + 1 java.security.AccessController.getStackAccessControlCon
text
1.1% 1 + 0 java.lang.SecurityManager.checkRead
1.1% 1 + 0 java.lang.CharacterDataLatin1.getProperties
1.1% 1 + 0 java.awt.color.ICC_Profile.<init>
1.1% 1 + 0 java.net.SocketInputStream.read
1.1% 1 + 0 java.awt.Color.<clinit>
1.1% 1 + 0 sun.net.spi.DefaultProxySelector.select
96.8% 6 + 86 Total interpreted
Compiled + native Method
1.1% 0 + 1 java.util.Arrays.binarySearch0
1.1% 0 + 1 Total compiled
Stub + native Method
1.1% 0 + 1 java.lang.System.arraycopy
1.1% 0 + 1 Total stub
Thread-local ticks:
2.1% 2 Blocked (of total)
1.1% 1 Class loader
Flat profile of 2.81 secs (276 total ticks): Thread-3
Interpreted + native Method
96.7% 0 + 267 java.net.SocketInputStream.socketRead0
0.7% 0 + 2 sun.security.provider.NativeSeedGenerator.nativeGenerat
eSeed
0.4% 0 + 1 java.lang.ClassLoader.findBootstrapClass
0.4% 0 + 1 java.net.Inet6AddressImpl.lookupAllHostAddr
0.4% 1 + 0 java.util.LinkedHashMap.addEntry
0.4% 1 + 0 java.util.Arrays.copyOfRange
0.4% 1 + 0 java.util.HashMap.<init>
0.4% 1 + 0 java.lang.StringCoding$StringEncoder.encode
0.4% 0 + 1 java.io.WinNTFileSystem.list
100.0% 4 + 272 Total interpreted
MainApplet: init
: start 0
: start 1
: start .1
: start .2
: start .3.
Flat profile of 5.00 secs (494 total ticks): Keep-Alive-Timer
Thread-local ticks:
100.0% 494 Blocked (of total)
View : static 1
View : static 2
View: 1
View: 2
View: 3
View: 4
: start .4
: start 2
: start 3
: start 4
: start 5
: start 6
: start 7
Flat profile of 5.86 secs (577 total ticks): Thread-4
Interpreted + native Method
66.2% 0 + 382 java.net.SocketInputStream.socketRead0
2.4% 14 + 0 straightedge.test.demo.Player.makeImage
1.9% 11 + 0 straightedge.test.demo.Player.makeImage2
0.3% 0 + 2 java.lang.StrictMath.floor
0.3% 0 + 2 java.lang.ClassLoader.findBootstrapClass
0.3% 1 + 1 straightedge.test.demo.WorldLetters.fillMultiPolygonsLi
st
0.3% 0 + 2 sun.java2d.d3d.D3DRenderQueue.flushBuffer
0.3% 0 + 2 java.io.FileOutputStream.writeBytes
0.3% 1 + 1 java.lang.ClassLoader.defineClass1
0.2% 0 + 1 java.util.zip.Inflater.inflateBytes
0.2% 1 + 0 java.awt.geom.Path2D.getPathIterator
0.2% 0 + 1 com.vividsolutions.jts.geom.GeometryFactory.createLinea
rRing
0.2% 0 + 1 straightedge.geom.PolygonConverter.<init>
0.2% 1 + 0 sun.misc.URLClassPath$JarLoader$2.<init>
0.2% 0 + 1 sun.font.FileFont.getGlyphMetrics
0.2% 0 + 1 com.vividsolutions.jts.operation.buffer.OffsetCurveSetB
uilder.addCurve
0.2% 0 + 1 straightedge.geom.util.TileArrayIntersections$Tile.<ini
t>
0.2% 1 + 0 com.vividsolutions.jts.geomgraph.Label.<init>
0.2% 0 + 1 com.vividsolutions.jts.operation.buffer.OffsetCurveSetB
uilder.addPolygonRing
0.2% 1 + 0 straightedge.geom.KPoint.ptLineDistSq
0.2% 1 + 0 com.vividsolutions.jts.geom.Envelope.expandToInclude
0.2% 1 + 0 straightedge.geom.KPoint.createPointToward
0.2% 0 + 1 com.vividsolutions.jts.operation.buffer.BufferBuilder.c
reateSubgraphs
0.2% 0 + 1 straightedge.test.demo.EventHandler.init
0.2% 0 + 1 straightedge.geom.PolygonConverter.makeKPolygonListFrom
76.8% 35 + 408 Total interpreted (including elided)
Compiled + native Method
20.8% 120 + 0 straightedge.geom.KPolygon.getClosestIntersectionToFirs
tFromSecond
1.2% 7 + 0 straightedge.geom.path.NodeConnector.isConnectionPossib
leAndUseful
0.3% 2 + 0 straightedge.geom.path.NodeConnector.reConnectNodeAfter
Checks
0.2% 1 + 0 straightedge.geom.KPoint.relCCWDouble
0.2% 1 + 0 straightedge.test.demo.Player.makeImage
0.2% 1 + 0 straightedge.test.demo.Player.makeImage2
22.9% 132 + 0 Total compiled
Stub + native Method
0.3% 0 + 2 java.lang.System.arraycopy
0.3% 0 + 2 Total stub
MainApplet: stop
MainApplet: destroy
Flat profile of 9.51 secs (931 total ticks): thread applet-straightedge.test.dem
o.AppletImpl.class
Interpreted + native Method
100.0% 1 + 0 java.lang.ClassLoader.defineClass1
100.0% 1 + 0 Total interpreted
Thread-local ticks:
99.9% 930 Blocked (of total)
ViewPane: getGraphics() == null
Flat profile of 2.73 secs (258 total ticks): Loop
Interpreted + native Method
24.0% 0 + 24 sun.java2d.d3d.D3DRenderQueue.flushBuffer
19.0% 0 + 19 sun.java2d.loops.TransformHelper.Transform
3.0% 0 + 3 sun.java2d.loops.FillRect.FillRect
2.0% 2 + 0 sun.java2d.d3d.D3DScreenUpdateManager.wakeUpUpdateThrea
d
2.0% 0 + 2 sun.dc.pr.PathFiller.writeAlpha8
2.0% 0 + 2 sun.font.FileFont.getGlyphImage
2.0% 0 + 2 java.lang.System.nanoTime
1.0% 1 + 0 java.awt.BasicStroke.getLineWidth
1.0% 0 + 1 java.lang.Object.clone
1.0% 0 + 1 sun.java2d.pipe.ShapeSpanIterator.dispose
1.0% 1 + 0 straightedge.geom.util.Tracker.getCountID
1.0% 0 + 1 sun.awt.windows.WToolkit.nativeSync
1.0% 0 + 1 sun.java2d.loops.MaskFill.MaskFill
1.0% 0 + 1 sun.java2d.loops.MaskBlit.MaskBlit
1.0% 0 + 1 sun.dc.pr.PathStroker.closedSubpath
1.0% 0 + 1 java.lang.Thread.yield
1.0% 1 + 0 java.awt.Component.getFont_NoClientCode
1.0% 1 + 0 sun.java2d.pipe.LoopPipe.getFillSSI
1.0% 1 + 0 straightedge.geom.KMultiPolygon$KMultiPolygonIterator.<
init>
1.0% 1 + 0 sun.dc.pr.Rasterizer.<init>
1.0% 1 + 0 straightedge.test.demo.AcceleratedImage.getAndCheckVola
tileImage
1.0% 1 + 0 sun.font.GlyphList.getGrayBits
1.0% 0 + 1 sun.misc.Unsafe.compareAndSwapInt
1.0% 1 + 0 straightedge.geom.KPolygon.perimeterIntersects
1.0% 1 + 0 sun.java2d.d3d.D3DSurfaceData.validatePipe
74.0% 14 + 60 Total interpreted (including elided)
Compiled + native Method
3.0% 3 + 0 straightedge.geom.KPolygon.contains
1.0% 0 + 1 java.lang.Object.<init>
1.0% 1 + 0 straightedge.geom.KPoint.linesIntersect
1.0% 1 + 0 straightedge.geom.vision.VisionFinder.calc
1.0% 1 + 0 straightedge.geom.KPolygon.intersectsLine
7.0% 6 + 1 Total compiled
Stub + native Method
7.0% 0 + 7 sun.dc.pr.PathFiller.writeAlpha8
5.0% 0 + 5 sun.java2d.loops.MaskFill.MaskFill
3.0% 0 + 3 sun.java2d.pipe.ShapeSpanIterator.nextSpan
3.0% 0 + 3 java.lang.System.arraycopy
1.0% 0 + 1 java.lang.StrictMath.atan2
19.0% 0 + 19 Total stub
Thread-local ticks:
61.2% 158 Blocked (of total)
Flat profile of 9.87 secs (966 total ticks): AWT-Windows
Interpreted + native Method
97.2% 0 + 939 sun.awt.windows.WToolkit.eventLoop
2.4% 0 + 23 sun.java2d.d3d.D3DGraphicsDevice.getDeviceCapsNative
0.2% 0 + 2 sun.java2d.d3d.D3DSurfaceData.initFlipBackbuffer
0.1% 1 + 0 java.awt.KeyboardFocusManager.getGlobalFocusOwner
0.1% 0 + 1 sun.awt.windows.WToolkit.init
100.0% 1 + 965 Total interpreted
Flat profile of 9.43 secs (927 total ticks): D3D Screen Updater
Interpreted + native Method
100.0% 0 + 10 sun.java2d.d3d.D3DRenderQueue.flushBuffer
100.0% 0 + 10 Total interpreted
Thread-local ticks:
98.9% 917 Blocked (of total)
Flat profile of 0.10 secs (9 total ticks): Thread-1
Interpreted + native Method
100.0% 0 + 9 sun.awt.windows.WToolkit.shutdown
100.0% 0 + 9 Total interpreted
Flat profile of 0.14 secs (14 total ticks): Thread-6
Thread-local ticks:
92.9% 13 Blocked (of total)
100.0% 1 Unknown: no last frame
Flat profile of 2.88 secs (273 total ticks): Keep-Alive-Timer
Thread-local ticks:
100.0% 273 Blocked (of total)
Flat profile of 6.78 secs (663 total ticks): AWT-EventQueue-1
Interpreted + native Method
33.3% 0 + 1 sun.java2d.d3d.D3DRenderQueue.flushBuffer
33.3% 0 + 1 sun.awt.windows.WComponentPeer._requestFocus
33.3% 0 + 1 sun.awt.windows.WComponentPeer.hide
100.0% 0 + 3 Total interpreted
Thread-local ticks:
99.5% 660 Blocked (of total)
Flat profile of 6.81 secs (665 total ticks): TimerQueue
Thread-local ticks:
100.0% 665 Blocked (of total)
Flat profile of 9.55 secs (938 total ticks): DestroyJavaVM
Thread-local ticks:
100.0% 938 Blocked (of total)
Flat profile of 9.63 secs (943 total ticks): AWT-EventQueue-0
Interpreted + native Method
25.0% 0 + 2 sun.awt.windows.WGlobalCursorManager.setCursor
12.5% 1 + 0 java.awt.Component.contains
12.5% 0 + 1 sun.awt.windows.WGlobalCursorManager.getCursorPos
12.5% 0 + 1 sun.java2d.d3d.D3DRenderQueue.flushBuffer
12.5% 1 + 0 sun.awt.PostEventQueue.flush
12.5% 1 + 0 java.awt.EventQueue.dispatchEvent
12.5% 0 + 1 java.lang.Object.notifyAll
100.0% 3 + 5 Total interpreted
Thread-local ticks:
99.2% 935 Blocked (of total)
Flat profile of 9.92 secs (971 total ticks): AWT-Shutdown
Thread-local ticks:
100.0% 971 Blocked (of total)
Flat profile of 9.96 secs (975 total ticks): Java2D Disposer
Thread-local ticks:
100.0% 975 Blocked (of total)
Global summary of 10.58 seconds:
100.0% 1041 Received ticks
0.3% 3 Received GC ticks
1.0% 10 Compilation
0.1% 1 Other VM operations
0.1% 1 Class loader
0.1% 1 Unknown code
Thanks for any pointers
keith