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. $ 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
24. GC Geracional
Perm Old Young
Pouco espaço
Coleta rápida
Muitas coletas
20
25. GC Geracional
Perm Old Young
Muito espaço Pouco espaço
Coleta demorada Coleta rápida
Poucas coletas Muitas coletas
20
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
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
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. $ 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. (...)
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
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. 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. Java 6
# jmap -dump:format=b,file=jboss.hprof 3421
Dumping heap to /root/jboss.hprof ...
Heap dump file created
44
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
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
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
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
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. # 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
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. $ 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. ...
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. ...
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
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
Mem&#xF3;ria dividida em duas grandes &#xE1;reas.
Mem&#xF3;ria dividida em duas grandes &#xE1;reas.
Old Generation divida
Old Generation divida
Old Generation divida
A Young Gen &#xE9; ent&#xE3;o divida em 3 partes.
Objetos s&#xE3;o imediatamente alocados no Eden Space.
Busca-se manter o Eden sempre vazio, para que a aloca&#xE7;&#xE3;o seja a mais r&#xE1;pida poss&#xED;vel.
Objetos s&#xE3;o imediatamente alocados no Eden Space.
Busca-se manter o Eden sempre vazio, para que a aloca&#xE7;&#xE3;o seja a mais r&#xE1;pida poss&#xED;vel.
Como na Old Gen a frequ&#xEA;ncia de coleta &#xE9; bem menor, o impacto da compacta&#xE7;&#xE3;o n&#xE3;o &#xE9; t&#xE3;o grande.