JVM bytecode engineering 101

Kees Jan Koster
kjkoster@java-monitor.com
Wednesday, November 6, 13
Wednesday, November 6, 13
•

http://java-monitor.com/livedemo.html

•
•
•
•

free, on-line service
up and running in 5 minutes
access server stats f...
java-monitor
probe
java-monitor
probe

java-monitor
probe
java-monitor
server
java-monitor
plugin

java-monitor
probe

jav...
Wednesday, November 6, 13
Wednesday, November 6, 13
Wednesday, November 6, 13
Wednesday, November 6, 13
•
•
•

workflow and toolchain
JVM architecture
instruction set basics

Wednesday, November 6, 13
write in
java
compile
to .class
decompile

tweak
bootstrap
recompile
to .class
debug

Wednesday, November 6, 13
CA FE BA BE 00 04 AD 00 DA 00 .. .. ..

verifier

class loader

class

JVM

Wednesday, November 6, 13
CA FE BA BE 00 04 AD 00 DA 00 .. .. ..
0xCAFEBABE

version #

constant pool
e.g. strings

access flags
class info
fields
m...
CA FE BA BE 00 04 AD 00 DA 00 .. .. ..
0xCAFEBABE

version #

constant pool

Transformer

e.g. strings

access flags
class...
CA FE BA BE 00 04 AD 00 DA 00 .. .. ..

Transformer
CA FE BA BE 00 04 AD 00 BE 45 76 .. .. ..

verifier

class loader

cla...
AspectJ

Spring

http://www.slideshare.net/tcurdt/no-dark-magic-byte-code-engineering-in-the-real-world
Wednesday, Novembe...
•
•
•
•
•
•

operand stack
local variables
• this pointer
stack frames and invoking methods
constant pool
atomic vs object...
•
•
•

push 1
push 2
iadd
...
...

Wednesday, November 6, 13
•
•
•

push 1
push 2
iadd
...
...

Wednesday, November 6, 13
•
•
•

push 1
push 2
iadd
1
...
...

Wednesday, November 6, 13
•
•
•

push 1
push 2
iadd

2
1
...
...

Wednesday, November 6, 13
•
•
•

push 1
push 2
iadd
3
...
...

Wednesday, November 6, 13
write in
java
javap
ASMifier
bytecode plugin

compile
to .class
decompile

tweak
bootstrap
recompile
to .class
debug

Wedn...
write in
java
compile
to .class
decompile

tweak
bootstrap
recompile
to .class

ASM CheckClassAdapter
debug

Wednesday, No...
nobody forced you

Wednesday, November 6, 13
Upcoming SlideShare
Loading in …5
×

JVM bytecode engineering 101

483 views
344 views

Published on

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
483
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
9
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

JVM bytecode engineering 101

  1. 1. JVM bytecode engineering 101 Kees Jan Koster kjkoster@java-monitor.com Wednesday, November 6, 13
  2. 2. Wednesday, November 6, 13
  3. 3. • http://java-monitor.com/livedemo.html • • • • free, on-line service up and running in 5 minutes access server stats from your mobile get help in the integrated forum Wednesday, November 6, 13
  4. 4. java-monitor probe java-monitor probe java-monitor probe java-monitor server java-monitor plugin java-monitor probe java-monitor probe Wednesday, November 6, 13
  5. 5. Wednesday, November 6, 13
  6. 6. Wednesday, November 6, 13
  7. 7. Wednesday, November 6, 13
  8. 8. Wednesday, November 6, 13
  9. 9. • • • workflow and toolchain JVM architecture instruction set basics Wednesday, November 6, 13
  10. 10. write in java compile to .class decompile tweak bootstrap recompile to .class debug Wednesday, November 6, 13
  11. 11. CA FE BA BE 00 04 AD 00 DA 00 .. .. .. verifier class loader class JVM Wednesday, November 6, 13
  12. 12. CA FE BA BE 00 04 AD 00 DA 00 .. .. .. 0xCAFEBABE version # constant pool e.g. strings access flags class info fields methods attributes Wednesday, November 6, 13
  13. 13. CA FE BA BE 00 04 AD 00 DA 00 .. .. .. 0xCAFEBABE version # constant pool Transformer e.g. strings access flags class info fields methods attributes Wednesday, November 6, 13 static final Logger __log = new ... __log.info(…); __log.info(…);
  14. 14. CA FE BA BE 00 04 AD 00 DA 00 .. .. .. Transformer CA FE BA BE 00 04 AD 00 BE 45 76 .. .. .. verifier class loader class JVM Wednesday, November 6, 13
  15. 15. AspectJ Spring http://www.slideshare.net/tcurdt/no-dark-magic-byte-code-engineering-in-the-real-world Wednesday, November 6, 13
  16. 16. • • • • • • operand stack local variables • this pointer stack frames and invoking methods constant pool atomic vs object types exceptions Wednesday, November 6, 13
  17. 17. • • • push 1 push 2 iadd ... ... Wednesday, November 6, 13
  18. 18. • • • push 1 push 2 iadd ... ... Wednesday, November 6, 13
  19. 19. • • • push 1 push 2 iadd 1 ... ... Wednesday, November 6, 13
  20. 20. • • • push 1 push 2 iadd 2 1 ... ... Wednesday, November 6, 13
  21. 21. • • • push 1 push 2 iadd 3 ... ... Wednesday, November 6, 13
  22. 22. write in java javap ASMifier bytecode plugin compile to .class decompile tweak bootstrap recompile to .class debug Wednesday, November 6, 13
  23. 23. write in java compile to .class decompile tweak bootstrap recompile to .class ASM CheckClassAdapter debug Wednesday, November 6, 13
  24. 24. nobody forced you Wednesday, November 6, 13

×