Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JVM opcodes

 
Dennis Grimbergen
Ranch Hand
Posts: 159
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm a Java developer since 2002 and recently I noticed that my knowledge about the JVM was bad. So I started to read some things in the JVM specification. Ofcourse subjects like opcodes/bytecode are discussed. I liked those opcode instruction code, but how useful is it to have (some) knowledge about that?
Are there any advantages of knowing opcodes and be able to read it? Can it improve my java skills in general? Just curious
 
Steve Luke
Bartender
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, the JVM specification is nice to know if you need to or want to implement a JVM. A general peek at some parts might be useful to understand if something is defined as a specification or is just an implementation detail. But generally no - knowing or reading the JVM spec is not important to your Java skills, and knowing opcodes and what not is not going to help in any way.
 
Jayesh A Lalwani
Rancher
Posts: 2756
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are going to use the ASM library, you will need to know opcodes (although there are ways of using ASM without learning all the opcodes.. it has a utility that will generate opcodes from a template for you) Besides that you shouldn;t really need to know opcodes

I have to say that knowing opcodes makes you sound like a badass, though. So, if you have time to learn it, you might want to learn them just for the bragging rights.
 
Dennis Grimbergen
Ranch Hand
Posts: 159
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understand that for example opcode aload_0 has hex representation 2A and means 'this' and that this by itself is not very important to know. But can viewing opcode instructions be useful for things like debugging? It's hard to find some uses of opcodes/bytecode, so probably is not that exciting...
 
Campbell Ritchie
Sheriff
Posts: 48921
58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would not have thought reading opcodes is any good for debugging. The people who need to know opcodes are compiler writers, and similar. If you are trying to compile an Eiffel program, for example, so it runs on a JVM, you need to know the opcodes to put into your compiler.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15274
38
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JDK includes a tool, javap, with which you can disassemble class files (use the -c option to do that). You'll get to see the implementation of methods in the form of JVM assembly language, with opcodes.

Sometimes it's useful to be able to understand what happens exactly in a class, but I wouldn't say it's really an important thing to know for most Java developers.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic