Forums Register Login

assignment operators

+Pie Number of slices to send: Send
Will useing a assignment operator reduce the bite-code size.
ex. will x += y giva a smaller code than x = x + y?
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
Could you tell me how to see the assembler produced by a java code ?
Thank you,
Horaci Macias
+Pie Number of slices to send: Send
 

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
The government thinks you are too stupid to make your own lightbulb choices. But this tiny ad thinks you are smart:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 931 times.
Similar Threads
x-- -x/0??
I am new to Java programming
2D Boolean array and randomness
inc / dec Operations precedence
thread program
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 15:07:45.