Hotspot tools

1,978 views

Published on

Published in: Technology, Education
1 Comment
10 Likes
Statistics
Notes
No Downloads
Views
Total views
1,978
On SlideShare
0
From Embeds
0
Number of Embeds
57
Actions
Shares
0
Downloads
86
Comments
1
Likes
10
Embeds 0
No embeds

No notes for slide



















  • Memória dividida em duas grandes áreas.
  • Memória dividida em duas grandes áreas.
  • Old Generation divida
  • Old Generation divida
  • Old Generation divida








  • A Young Gen é então divida em 3 partes.

  • Objetos são imediatamente alocados no Eden Space.
    Busca-se manter o Eden sempre vazio, para que a alocação seja a mais rápida possível.
  • Objetos são imediatamente alocados no Eden Space.
    Busca-se manter o Eden sempre vazio, para que a alocação seja a mais rápida possível.


  • Como na Old Gen a frequência de coleta é bem menor, o impacto da compactação não é tão grande.


















































  • Hotspot tools

    1. 1. Ferramentas da Hotspot
    2. 2. 2
    3. 3. Agenda • jps • jstack • jinfo • jhat • jmap • jdb • jstat • hprof http://java.sun.com/javase/6/webnotes/trouble/TSG-VM/html/tooldescr.html 3
    4. 4. jps Lista processos Java 4
    5. 5. 5
    6. 6. $ jps -h illegal argument: -h usage: jps [-help] jps [-q] [-mlvV] [<hostid>] Definitions: <hostid>: <hostname>[:<port>] 6
    7. 7. $ ps | grep -i java 4008 p2 S+ 0:00.02 /bin/sh /Users/alegomes/JavaTools/jopr-server-2.2.0/jbossas/bin/ run.sh -P / 4017 p2 S+ 33:21.61 /Library/Java/Home/bin/java -Dprogram.name=run.sh -Dapp.name=rhq- server -Xm 11989 p4 R+ 0:00.00 grep -i java 840 p5 S+ 7:10.01 /Library/Java/Home/bin/java -Dprogram.name=run.sh -Xms128m -Xmx512m -Dsun.r 7
    8. 8. $ ps | grep -i java 4008 p2 S+ 0:00.02 /bin/sh /Users/alegomes/JavaTools/jopr-server-2.2.0/jbossas/bin/ run.sh -P / 4017 p2 S+ 33:21.61 /Library/Java/Home/bin/java -Dprogram.name=run.sh -Dapp.name=rhq- server -Xm 11989 p4 R+ 0:00.00 grep -i java 840 p5 S+ 7:10.01 /Library/Java/Home/bin/java -Dprogram.name=run.sh -Xms128m -Xmx512m -Dsun.r 7
    9. 9. $ jps 2989 2614 Jps 3614 $ jps -v 2617 Jps -Dapplication.home=/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/ Home -Xms8m 2989 -Xbootclasspath/a:/System/Library/PrivateFrameworks/ JavaApplicationLauncher.framework/Resources/LauncherSupport.jar - Dapple.laf.useScreenMenuBar=true -Dapple.awt.showGrowBox=true - Dapple.awt.antialiasing=false -Dcom.apple.mrj.application.apple.menu.about.name=FreeMind -Dcom.apple.mrj.application.live-resize=true -Dcom.apple.smallTabs=false - Dapple.awt.textantialiasing=false 3614 -Xbootclasspath/p:/Applications/Firefox 3.0.1.app/Contents/MacOS/plugins/ MRJPlugin.plugin/Contents/MacOS/MRJPlugin.jar -Dnetscape.oji.plugin.home=/Applications/ Firefox 3.0.1.app/Contents/MacOS/plugins/MRJPlugin.plugin/Contents/MacOS -Xmx96m - Djavaplugin.maxHeapSize=96m -Xbootclasspath/a:/System/Library/Frameworks/ JavaVM.framework/Versions/1.5/Home/lib/deploy.jar:/System/Library/Frameworks/ JavaVM.framework/Versions/1.5/Home/lib/plugin.jar:/System/Library/Frameworks/ JavaVM.framework/Versions/1.5/Home/lib/ext/apple_provider.jar -Xbootclasspath/p:/ Applications/Firefox 3.0.1.app/Contents/MacOS/plugins/JavaEmbeddingPlugin.bundle/ Contents/Resources/Java/JavaEmbeddingPlugin.jar -Djep.pluginhome=/Applications/Firefox 3.0.1.app/Contents/MacOS/plugins/JavaEmbeddingPlugin.bundle -Djep.version=0.9.6.4 - Djep.version.applet=true -Djep.debug.visibility.applet=true - Djep.debug.release.applet=true -Djep.debug.updates.applet=true -DtrustProxy=true vfprintf 8
    10. 10. jinfo informações de configuração 9
    11. 11. 10
    12. 12. $ jinfo Usage: jinfo [option] <pid> (to connect to a live java process) or jinfo [option] <executable> <core> (to connect to a core file) or jinfo [option] [server_id@]<remote server IP or hostname> (to connect to a remote debug server) where option must be one of: -flags to print VM flags -sysprops to print Java System properties <no option> to print both of the above -h | -help to print this help message 11
    13. 13. $ jinfo 2650 Attaching to process ID 2650, please wait... Debugger attached successfully. Client compiler detected. JVM version is 1.5.0_16-132 Java System Properties: java.vendor = Apple Computer, Inc. sun.java.launcher = SUN_STANDARD sun.management.compiler = HotSpot Client Compiler os.name = Mac OS X sun.boot.class.path = /Users/alegomes/jbtun/app/jboss-5.0.0.GA/bin/../lib/endorsed/activation.jar:/Users/ alegomes/jbtun/app/jboss-5.0.0.GA/bin/../lib/endorsed/jaxb-api.jar:/Users/alegomes/jbtun/app/ jboss-5.0.0.GA/bin/../lib/endorsed/resolver.jar:/Users/alegomes/jbtun/app/jboss-5.0.0.GA/bin/../lib/ endorsed/serializer.jar:/Users/alegomes/jbtun/app/jboss-5.0.0.GA/bin/../lib/endorsed/stax-api.jar:/Users/ alegomes/jbtun/app/jboss-5.0.0.GA/bin/../lib/endorsed/xalan.jar:/Users/alegomes/jbtun/app/jboss-5.0.0.GA/ bin/../lib/endorsed/xercesImpl.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Classes/ classes.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Classes/ui.jar:/System/Library/ Frameworks/JavaVM.framework/Versions/1.5.0/Classes/laf.jar:/System/Library/Frameworks/JavaVM.framework/ Versions/1.5.0/Classes/sunrsasign.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Classes/ jsse.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Classes/jce.jar:/System/Library/ Frameworks/JavaVM.framework/Versions/1.5.0/Classes/charsets.jar java.vm.specification.vendor = Sun Microsystems Inc. java.runtime.version = 1.5.0_16-b06-275 org.apache.catalina.core.StandardHost.autoDeploy = false user.name = alegomes jboss.remoting.version = 22 jboss.bind.address = 127.0.0.1 jboss.messaging.connector.bisocket.port = 4457 awt.nativeDoubleBuffering = true tomcat.util.buf.StringCache.byte.enabled = true jboss.home.dir = /Volumes/Data/Documents/sea/edu/jboss_tuning/app/jboss-5.0.0.GA com.arjuna.common.util.logging.DebugLevel = 0x00000000 java.naming.factory.initial = org.jnp.interfaces.NamingContextFactory user.language = en sun.boot.library.path = /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Libraries com.arjuna.ats.jta.lastResourceOptimisationInterface = org.jboss.tm.LastResource jboss.home.url = file:/Volumes/Data/Documents/sea/edu/jboss_tuning/app/jboss-5.0.0.GA/ java.version = 1.5.0_16omes$ 12
    14. 14. (...) java.rmi.server.codebase = http://127.0.0.1:8083/ java.io.tmpdir = /tmp java.vendor.url.bug = http://developer.apple.com/java/ jboss.server.data.dir = /Volumes/Data/Documents/sea/edu/jboss_tuning/app/jboss-5.0.0.GA/server/ default/data java.rmi.server.hostname = 127.0.0.1 jboss.vfs.forceCopy = true os.arch = ppc java.awt.graphicsenv = apple.awt.CGraphicsEnvironment org.apache.catalina.core.StandardHost.deployXML = false java.ext.dirs = /Library/Java/Extensions:/System/Library/Java/Extensions:/System/Library/ Frameworks/JavaVM.framework/Versions/1.5.0/Home/lib/ext PROPERTIES_FILE = tsmx.properties mrj.version = 1040.1.5.0_16-275 user.dir = /Volumes/Data/Documents/sea/edu/jboss_tuning/app/jboss-5.0.0.GA/bin org.apache.catalina.core.StandardHost.deployOnStartup = false apple.awt.graphics.UseQuartz = true line.separator = java.vm.name = Java HotSpot(TM) Client VM jboss.server.base.dir = /Volumes/Data/Documents/sea/edu/jboss_tuning/app/jboss-5.0.0.GA/server org.apache.commons.logging.Log = org.apache.commons.logging.impl.Log4JLogger com.arjuna.common.util.logging.FacilityLevel = 0xffffffff jboss.server.base.url = file:/Volumes/Data/Documents/sea/edu/jboss_tuning/app/jboss-5.0.0.GA/ server/ javax.management.builder.initial = org.jboss.mx.server.MBeanServerBuilderImpl file.encoding = MacRoman org.apache.catalina.core.StandardService.DELAY_CONNECTOR_STARTUP = true catalina.ext.dirs = /Volumes/Data/Documents/sea/edu/jboss_tuning/app/jboss-5.0.0.GA/server/default/ lib java.specification.version = 1.5 jboss.server.name = default VM Flags: -Dprogram.name=run.sh -Xms128m -Xmx512m -XX:MaxPermSize=256m -Dorg.jboss.resolver.warning=true - Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 - Djava.endorsed.dirs=/Users/alegomes/jbtun/app/jboss-5.0.0.GA/bin/../lib/endorsed 13
    15. 15. Garbage Collector 14
    16. 16. Regra Geral do GC 15 http://chaoticjava.com/posts/how-does-garbage-collection-work/
    17. 17. Problema As memórias estão cada vez maiores. 16
    18. 18. Constatação Alta mortalidade infantil de objetos 17
    19. 19. Idéia! 18
    20. 20. GC Geracional Old Young 19
    21. 21. GC Geracional Old Young alta mortalidade GC frequente espaço menor 19
    22. 22. GC Geracional Old Young baixa mortalidade alta mortalidade GC não tão frequente GC frequente espaço maior espaço menor 19
    23. 23. GC Geracional Perm Old Young 20
    24. 24. GC Geracional Perm Old Young Pouco espaço Coleta rápida Muitas coletas 20
    25. 25. GC Geracional Perm Old Young Muito espaço Pouco espaço Coleta demorada Coleta rápida Poucas coletas Muitas coletas 20
    26. 26. GC Geracional Perm Old Young Dados Muito espaço Pouco espaço permanentes. Coleta demorada Coleta rápida Poucas coletas Muitas coletas Coletados uma vez na vida e outra na morte 20
    27. 27. Compactação processo de alto custo 21
    28. 28. Compactação defragmentação mem frag cópia deleção cópia 22
    29. 29. Compactação defragmentação mem frag cópia deleção cópia 23
    30. 30. Compactação defragmentação mem frag cópia deleção cópia 24
    31. 31. Compactação defragmentação mem frag cópia deleção cópia 25
    32. 32. Copy menos custoso que a compactação 26
    33. 33. Copy defragmentação S0 S1 S0 cópia S1 27
    34. 34. Copy Na Young Generation, faz-se a cópia de objetos ao invés da compactação. Este mecanismo é eficiente pois atinge-se a defragmentação da memória sem a necessidade de varrê-la. 28
    35. 35. Perm Old S0 S1 Eden 29
    36. 36. Perm Old S0 S1 Eden Áreas temporárias para cópia de objetos 29
    37. 37. http://www.javaworld.com/javaworld/jw-01-2002/jw-0111-hotspotgc.html 30
    38. 38. 31
    39. 39. Minor Collection 31
    40. 40. 32 http://www.javaworld.com/javaworld/jw-01-2002/jw-0111-hotspotgc.html
    41. 41. Promoção 33 http://www.javaworld.com/javaworld/jw-01-2002/jw-0111-hotspotgc.html
    42. 42. Mark Sweep 34 http://www.javaworld.com/javaworld/jw-01-2002/jw-0111-hotspotgc.html
    43. 43. Resumo 35
    44. 44. jmap estatísticas de memória 36
    45. 45. 37
    46. 46. $ jmap Usage: jmap [option] <pid> (to connect to a live java process) or jmap [option] <executable> <core> (to connect to a core file) or jmap [option] [server_id@]<remote server IP or hostname> (to connect to a remote debug server) where option must be one of: <no option> same as -heap -heap to print java heap summary -heap:format=b|x to dump java heap in hprof binary format -histo to print histogram of java object heap -permstat to print permanent generation statistics -h | -help to print this help message 38
    47. 47. $ jmap -heap 2650 Attaching to process ID 2650, please wait... Debugger attached successfully. Client compiler detected. JVM version is 1.5.0_16-132 using thread-local object allocation. Mark Sweep Compact GC Heap Configuration: MinHeapFreeRatio = 40 MaxHeapFreeRatio = 70 MaxHeapSize = 536870912 (512.0MB) NewSize = 655360 (0.625MB) MaxNewSize = 4294836224 (4095.875MB) OldSize = 1441792 (1.375MB) NewRatio = 8 SurvivorRatio = 8 PermSize = 8388608 (8.0MB) MaxPermSize = 268435456 (256.0MB) 39
    48. 48. (...) Heap Usage: New Generation (Eden + 1 Survivor Space): capacity = 22413312 (21.375MB) used = 19454264 (18.55303192138672MB) free = 2959048 (2.8219680786132812MB) 86.79781015853436% used Eden Space: capacity = 19922944 (19.0MB) used = 19174288 (18.286026000976562MB) free = 748656 (0.7139739990234375MB) 96.24224211040296% used From Space: capacity = 2490368 (2.375MB) used = 279976 (0.26700592041015625MB) free = 2210392 (2.1079940795898438MB) 11.242354543585526% used To Space: capacity = 2490368 (2.375MB) used = 0 (0.0MB) free = 2490368 (2.375MB) 0.0% used tenured generation: capacity = 194772992 (185.75MB) used = 120429336 (114.8503646850586MB) free = 74343656 (70.8996353149414MB) 61.83061355857798% used Perm Generation: capacity = 45613056 (43.5MB) used = 45396720 (43.29368591308594MB) free = 216336 (0.2063140869140625MB) 99.5257147427263% used 40
    49. 49. $ jmap -histo 2650 Object Histogram: Size Count Class description ------------------------------------------------------- 26114008 232479 char[] 15697136 21720 byte[] 13056704 103094 * ConstMethodKlass 9788712 407863 java.lang.String 8013376 250418 java.util.TreeMap$Entry 6704152 147510 * SymbolKlass 5777192 103094 * MethodKlass 5671208 62558 java.util.HashMap$Entry[] 5589144 232881 java.util.HashMap$Entry 5561696 9877 * ConstantPoolKlass 4230480 9877 * InstanceKlassKlass 3768000 47100 java.lang.reflect.Method 3234112 44591 java.lang.Object[] 3134336 8290 * ConstantPoolCacheKlass 3089048 15456 int[] 2513760 31422 java.util.zip.ZipEntry 2375560 59389 java.util.HashMap 2267480 56687 java.util.TreeMap 2210048 69064 java.util.concurrent.ConcurrentHashMap$Segment 1673216 26144 org.jboss.mx.server.InvocationContext 1658616 69109 java.util.concurrent.locks.ReentrantLock$NonfairSync 1517520 31615 org.jboss.virtual.plugins.context.zip.ZipEntryHandler 1496760 69219 java.util.concurrent.ConcurrentHashMap$HashEntry[] 1442960 90185 org.jboss.logging.Logger 1442960 90185 org.jboss.logging.log4j.Log4jLoggerPlugin 41
    50. 50. $ jmap -permstat 2650 Attaching to process ID 2650, please wait... Debugger attached successfully. Client compiler detected. JVM version is 1.5.0_16-132 finding class loader instances ..Unknown oop at 0x065ee230 Oop's klass is null Finding object size using Printezis bits and skipping over... done. computing per loader stat ..done. please wait.. computing liveness....................................................................................Unknown oop at 0xf23b7c68 Oop's klass is 0x075bd890 Liveness analysis: WARNING: UnknownOopException for oop at 0xf23b7c68 LivenessAnalysis: WARNING: sun.jvm.hotspot.utilities.AssertionFailure: should not reach here during traversal Liveness analysis: WARNING: AddressException at 0x87859397 while traversing oop at 0x87859393 done. class_loader classes bytes parent_loader alive? type <bootstrap> 2740 5755040 null live <internal> 0x0db29710 3 4616 null live org/jboss/classloader/spi/base/ BaseClassLoader@0x26ddb718 0x102d5e68 1 1392 0x0b1572a8 dead sun/reflect/DelegatingClassLoader@0x265e0248 0x0a706728 1 1392 0x09e804e0 dead sun/reflect/DelegatingClassLoader@0x265e0248 0x0d7f8858 1 1392 0x0b1572a8 dead sun/reflect/DelegatingClassLoader@0x265e0248 0x0dc9c290 5 21608 null live org/jboss/classloader/spi/base/ BaseClassLoader@0x26ddb718 0x0f0380a0 1 1392 0x09e804e0 dead sun/reflect/DelegatingClassLoader@0x265e0248 0x0f4e31f0 1 1392 0x0dc9bf70 dead sun/reflect/DelegatingClassLoader@0x265e0248 0x0df37b30 1 1392 0x09e804e0 dead sun/reflect/DelegatingClassLoader@0x265e0248 0x09f38480 1 840 null dead sun/reflect/DelegatingClassLoader@0x265e0248 0x0e74a6a0 1 1392 0x0b1572a8 dead sun/reflect/DelegatingClassLoader@0x265e0248 0x0df6b9c8 1 840 0x09e804e0 dead sun/reflect/DelegatingClassLoader@0x265e0248 0x10c6a9b0 1 1392 0x0de052c8 dead sun/reflect/DelegatingClassLoader@0x265e0248 0x108fb740 1 1392 0x0de052c8 dead sun/reflect/DelegatingClassLoader@0x265e0248 ... total = 465 14242 31166840 N/A alive=98, dead=367 N/A 42
    51. 51. Java 5 $ jmap -heap:format=b 2650 Attaching to process ID 2650, please wait... Debugger attached successfully. Client compiler detected. JVM version is 1.5.0_16-132 Unknown oop at 0x065ee230 Oop's klass is null Finding object size using Printezis bits and skipping over... heap written to heap.bin $ du -sh heap.bin 144M heap.bin 43
    52. 52. Java 6 # jmap -dump:format=b,file=jboss.hprof 3421 Dumping heap to /root/jboss.hprof ... Heap dump file created 44
    53. 53. jstat estatísticas mil da JVM 45
    54. 54. 46
    55. 55. $ jstat invalid argument count Usage: jstat -help|-options jstat -<option> [-t] [-h<lines>] <vmid> [<interval> [<count>]] Definitions: <option> An option reported by the -options option <vmid> Virtual Machine Identifier. A vmid takes the following form: <lvmid>[@<hostname>[:<port>]] Where <lvmid> is the local vm identifier for the target Java virtual machine, typically a process id; <hostname> is the name of the host running the target Java virtual machine; and <port> is the port number for the rmiregistry on the target host. See the jvmstat documentation for a more complete description of the Virtual Machine Identifier. <lines> Number of samples between header lines. <interval> Sampling interval. The following forms are allowed: <n>["ms"|"s"] Where <n> is an integer and the suffix specifies the units as milliseconds("ms") or seconds("s"). The default units are "ms". <count> Number of samples to take before terminating. -J<flag> Pass <flag> directly to the runtime system. 47
    56. 56. $ jstat -options -class -compiler -gc -gccapacity -gccause -gcnew -gcnewcapacity -gcold -gcoldcapacity -gcpermcapacity -gcutil -printcompilation 48
    57. 57. Opções do jstat • class - estatísticas sobre os classloaders • compiler - estaitsticas sobre o compilador HotSpot • gc - estatisticas sobre a coleta de lixo • gccapcity - estatísticas sobre o espaçó total • gccause - resumo das estatísticas do GC • gcnew - estatísticas da new generation do GC • gcnewcapacity - estatísticas sobre a alocação de espaço da new generation do GC • gcold - estatísticas da old e permanent generation do GC • gcoldcapacity - estatísticas sobre a alocação de espaço da old e permanent generation do GC • gcutil - resumo das estatísticas do GC • printcompilation - estatísticas de compilação de métodos 49
    58. 58. $ jstat -class 2650 Loaded Bytes Unloaded Bytes Time 9920 11187.2 43 36.7 79.70 $ jstat -compiler 2650 Compiled Failed Invalid Time FailedType FailedMethod 3634 0 0 13.15 0 $ jstat -gc 2650 S0C S1C S0U S1U EC EU OC OU PC PU YGC YGCT FGC FGCT GCT 2432.0 2432.0 254.2 0.0 19456.0 14714.8 190208.0 117606.8 44544.0 44336.3 154 6.897 8 32.184 39.08 $ jstat -gccapacity 2650 NGCMN NGCMX NGC S0C S1C EC OGCMN OGCMX OGC OC PGCMN PGCMX PGC PC YGC FGC 14464.0 58240.0 24320.0 2432.0 2432.0 19456.0 116608.0 466048.0 190208.0 190208.0 8192.0 262144.0 44544.0 44544.0 154 8 $ jstat -gccause 2650 S0 S1 E O P YGC YGCT FGC FGCT GCT LGCC GCC 10.45 0.00 75.63 61.83 99.53 154 6.897 8 32.184 39.081 unknown GCCause No GC $ jstat -gcnew 2650 S0C S1C S0U S1U TT MTT DSS EC EU YGC YGCT 2432.0 2432.0 254.2 0.0 15 15 1216.0 19456.0 14714.8 154 6.897 50
    59. 59. $ jstat -gcutil 6299 S0 S1 E O P YGC YGCT FGC FGCT GCT 0.00 100.00 82.65 60.40 99.42 111 4.413 4 12.426 16.840 • S0 - % de uso do Survivor Space 0 • S1 - % de uso do Survivor Space 1 • E - % de uso do Eden Space • O - % de uso da Old Generation • P - % de uso da Permanent Generation • YGC - # de GCs na Young Generation • YGCT - Tempo total gasto em GCs na Young Generation • FGC - # de Full GCs • FGCT - Tempo total gasto em Full GCs • GCT - Tempo total gasto em GCs (YGCT + FGCT) Perm Old S0 S1 Eden 51
    60. 60. 52
    61. 61. 53
    62. 62. 54
    63. 63. 55
    64. 64. 56
    65. 65. 57
    66. 66. 58
    67. 67. 59
    68. 68. 60
    69. 69. 61
    70. 70. 62
    71. 71. jstack stack trace de todas as threads da VM 63
    72. 72. 64
    73. 73. $ jstack Usage: jstack [option] <pid> (to connect to a live java process) or jstack [option] <executable> <core> (to connect to a core file) or jstack [option] [server_id@]<remote server IP or hostname> (to connect to a remote debug server) where option must be one of: -m to print both java and native frames (mixed mode) -h | -help to print this help message 65
    74. 74. $ jstack 6299 Attaching to process ID 6299, please wait... Debugger attached successfully. Client compiler detected. JVM version is 1.5.0_16-132 Thread t@3847: (state = BLOCKED) - java.lang.Object.wait(long) @bci=0 (Compiled frame; information may be imprecise) - sun.awt.AWTAutoShutdown.run() @bci=79, line=278 (Compiled frame) - java.lang.Thread.run() @bci=11, line=613 (Interpreted frame) Thread t@4099: (state = IN_NATIVE) - java.net.PlainSocketImpl.socketAccept(java.net.SocketImpl) @bci=0 (Interpreted frame) - java.net.PlainSocketImpl.accept(java.net.SocketImpl) @bci=7, line=384 (Interpreted frame) - java.net.ServerSocket.implAccept(java.net.Socket) @bci=50, line=450 (Interpreted frame) - java.net.ServerSocket.accept() @bci=48, line=421 (Interpreted frame) - org.apache.tomcat.util.net.DefaultServerSocketFactory.acceptSocket(java.net.ServerSocket) @bci=1, line=61 (Interpreted frame) - org.apache.tomcat.util.net.JIoEndpoint$Acceptor.run() @bci=47, line=310 (Interpreted frame) - java.lang.Thread.run() @bci=11, line=613 (Interpreted frame) Thread t@4355: (state = IN_NATIVE) - java.net.PlainSocketImpl.socketAccept(java.net.SocketImpl) @bci=0 (Interpreted frame) - java.net.PlainSocketImpl.accept(java.net.SocketImpl) @bci=7, line=384 (Interpreted frame) - java.net.ServerSocket.implAccept(java.net.Socket) @bci=50, line=450 (Interpreted frame) - java.net.ServerSocket.accept() @bci=48, line=421 (Interpreted frame) - org.apache.tomcat.util.net.DefaultServerSocketFactory.acceptSocket(java.net.ServerSocket) @bci=1, line=61 (Interpreted frame) - org.apache.tomcat.util.net.JIoEndpoint$Acceptor.run() @bci=47, line=310 (Interpreted frame) - java.lang.Thread.run() @bci=11, line=613 (Interpreted frame) Thread t@4611: (state = BLOCKED) - java.lang.Object.wait(long) @bci=0 (Interpreted frame) - java.lang.Object.wait() @bci=2, line=474 (Interpreted frame) - org.jboss.bootstrap.AbstractServerImpl$LifeThread.run() @bci=11, line=789 (Interpreted frame) 66
    75. 75. jhat navegação e busca no grafo de objetos 67
    76. 76. 68
    77. 77. # jhat ERROR: No arguments supplied Usage: jhat [-stack <bool>] [-refs <bool>] [-port <port>] [-baseline <file>] [-debug <int>] [-version] [-h|-help] <file> -J<flag> Pass <flag> directly to the runtime system. For example, -J-mx512m to use a maximum heap size of 512MB -stack false: Turn off tracking object allocation call stack. -refs false: Turn off tracking of references to objects -port <port>: Set the port for the HTTP server. Defaults to 7000 -exclude <file>: Specify a file that lists data members that should be excluded from the reachableFrom query. -baseline <file>: Specify a baseline object dump. Objects in both heap dumps with the same ID and same class will be marked as not being "new". -debug <int>: Set debug level. 0: No debug output 1: Debug hprof file parsing 2: Debug hprof file parsing, no server -version Report version number -h|-help Print this help and exit <file> The file to read 69
    78. 78. # jmap -dump:format=b,file=jboss.hprof 3421 Dumping heap to /root/jboss.hprof ... Heap dump file created # jhat jboss.hprof Reading from /root/jboss.hprof... Dump file created Fri May 22 05:09:16 BRT 2009 Snapshot read, resolving... Resolving 464313 objects... WARNING: Failed to resolve object id 0x85e94490 for field constantPoolOop (signature L) ... WARNING: Failed to resolve object id 0x8571d198 for field constantPoolOop (signature L) WARNING: Failed to resolve object id 0x8571a9a8 for field constantPoolOop (signature L) Chasing references, expect 92 dots........................................................................................ .... Eliminating duplicate references.................................................................................. .......... Snapshot resolved. Started HTTP server on port 7000 Server is ready. 70
    79. 79. 71
    80. 80. 72
    81. 81. 73
    82. 82. 74
    83. 83. 75
    84. 84. jdb java debuger 76
    85. 85. $ jdb -listconnectors Available connectors are: Connector: com.sun.jdi.CommandLineLaunch Transport: dt_socket description: Launches target using Sun Java VM command line and attaches to it Argument: home Default value: /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home description: Home directory of the SDK or runtime environment used to launch the application Argument: options (no default) description: Launched VM options Required Argument: main (no default) description: Main class and arguments, or if -jar is an option, the main jar file and arguments Argument: suspend Default value: true description: All threads will be suspended before execution of main Required Argument: quote Default value: " description: Character used to combine space-delimited text into a single command line argument Required Argument: vmexec Default value: java description: Name of the Java VM launcher ... 77
    86. 86. $ jdb -connect sun.jvm.hotspot.jdi.SAPIDAttachingConnector:pid=6299 Initializing jdb ... > > help ** command list ** connectors -- list available connectors and transports in this VM run [class [args]] -- start execution of application's main class threads [threadgroup] -- list threads thread <thread id> -- set default thread suspend [thread id(s)] -- suspend threads (default: all) resume [thread id(s)] -- resume threads (default: all) where [<thread id> | all] -- dump a thread's stack wherei [<thread id> | all]-- dump a thread's stack, with pc info up [n frames] -- move up a thread's stack down [n frames] -- move down a thread's stack kill <thread id> <expr> -- kill a thread with the given exception object interrupt <thread id> -- interrupt a thread print <expr> -- print value of expression dump <expr> -- print all object information eval <expr> -- evaluate expression (same as print) set <lvalue> = <expr> -- assign new value to field/variable/array element locals -- print all local variables in current stack frame ... 78
    87. 87. ... classes -- list currently known classes class <class id> -- show details of named class methods <class id> -- list a class's methods fields <class id> -- list a class's fields threadgroups -- list threadgroups threadgroup <name> -- set current threadgroup stop in <class id>.<method>[(argument_type,...)] -- set a breakpoint in a method stop at <class id>:<line> -- set a breakpoint at a line clear <class id>.<method>[(argument_type,...)] -- clear a breakpoint in a method clear <class id>:<line> -- clear a breakpoint at a line clear -- list breakpoints catch [uncaught|caught|all] <class id>|<class pattern> -- break when specified exception occurs ignore [uncaught|caught|all] <class id>|<class pattern> -- cancel 'catch' for the specified exception watch [access|all] <class id>.<field name> -- watch access/modifications to a field unwatch [access|all] <class id>.<field name> -- discontinue watching access/modifications to a field trace methods [thread] -- trace method entry and exit untrace methods [thread] -- stop tracing method entry and exit step -- execute current line step up -- execute until the current method returns to its caller stepi -- execute current instruction next -- step one line (step OVER calls) cont -- continue execution from breakpoint 79
    88. 88. ... list [line number|method] -- print source code use (or sourcepath) [source file path] -- display or change the source path exclude [<class pattern>, ... | "none"] -- do not report step or method events for specified classes classpath -- print classpath info from target VM monitor <command> -- execute command each time the program stops monitor -- list monitors unmonitor <monitor#> -- delete a monitor read <filename> -- read and execute a command file lock <expr> -- print lock info for an object threadlocks [thread id] -- print lock info for a thread pop -- pop the stack through and including the current frame reenter -- same as pop, but current frame is reentered redefine <class id> <class file name> -- redefine the code for a class disablegc <expr> -- prevent garbage collection of an object enablegc <expr> -- permit garbage collection of an object 80
    89. 89. > threads Group system: (java.lang.ref.Reference$ReferenceHandler)0x41 Reference Handler unknown (java.lang.ref.Finalizer$FinalizerThread)0x40 Finalizer unknown (java.lang.Thread)0x3f Signal Dispatcher running (java.lang.Thread)0x3a RMI TCP Accept-1098 running (java.lang.Thread)0x38 RMI Reaper unknown (sun.misc.GC$Daemon)0x37 GC Daemon unknown (java.lang.Thread)0x34 RMI TCP Accept-1090 running (java.lang.Thread)0x33 RMI TCP Accept-0 running (java.lang.Thread)0x32 RMI RenewClean-[127.0.0.1:50475] unknown (java.lang.Thread)0x31 RMI LeaseChecker sleeping (java.lang.Thread)0x22 RMI TCP Accept-4444 running Group main: (java.lang.Thread)0x3e DestroyJavaVM running (java.lang.Thread)0x3 AWT-AppKit running Group jboss: (java.util.TimerThread)0x3d Timer-0 unknown (java.util.TimerThread)0x3c Timer-Log4jService unknown ... 81
    90. 90. hprof heap profiler 82
    91. 91. Divirta-se com todas as ferramentas apresentadas. Quem instanciou o objeto X? Quem está referenciando o objeto X? Quantas threads ficam bloqueadas durante os testes? Qual o pico de alocação da PermGen? Quais libs estão no classpath do classloader da aplicação? Qual a frequência de execução do GC na Young Gen? E na Old Gen? 83
    92. 92. P&R

    ×