File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

assignment operators

 
Rob MacKinnon
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Will useing a assignment operator reduce the bite-code size.
ex. will x += y giva a smaller code than x = x + y?
 
Peter Haggar
author
Ranch Hand
Posts: 106
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The bytecode size is the same, although the bytecode is slightly different. However, the difference is not going to amount to much, if anything. In addition, if you run with a JIT, it will most likely be compiled into the same instructions. Using the IBM JDK 1.3 with its JIT, I got the following bytecode and assembler:

produced this bytecode:

Note they are the same length, but the opcode at location 1 is different. x = x + y; uses iload_0 while x+=y; uses a dup.
You're unlikely to see any difference even if you are running interpreted. Since you probably are not, it's more important to see what the JIT produces. Both method's foo and bar produced the same assembler with the IBM JIT:

Peter Haggar
------------------
Senior Software Engineer, IBM
author of: Practical Java
 
Horaci Macias
Ranch Hand
Posts: 74
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you tell me how to see the assembler produced by a java code ?
Thank you,
Horaci Macias
 
Peter Haggar
author
Ranch Hand
Posts: 106
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Horaci Macias:
Could you tell me how to see the assembler produced by a java code ?

The bytecode is produced by using the javap tool. On a class file named test.class this works on Windows:
javap -c test > test.bc
To see the assembler, the JVM you run with must have a JIT (most do). I took the code above and wrapped it in an infinite loop. I then ran the program and debugged the java process with the Microsoft Visual C++ debugger. When the debugger starts, I break the execution of the program. Since the code I wanted to see is spinning in an infinite loop, it's quite easy to see that code as you step through the assembler.
Peter Haggar
------------------
Senior Software Engineer, IBM
author of: Practical Java
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic