viewing Java disassembly
-
I am in IntelliJ IDEA. I want to view the disassembly of this code to see if it does two comparisons:
if (-0.0 == 0.0) System.out.println("they're equal");
Based on searching, it sounds like IntelliJ can't do that. Anyone know of a Java IDE that can do this? Thank you.
-
I am in IntelliJ IDEA. I want to view the disassembly of this code to see if it does two comparisons:
if (-0.0 == 0.0) System.out.println("they're equal");
Based on searching, it sounds like IntelliJ can't do that. Anyone know of a Java IDE that can do this? Thank you.
At the command prompt in your directory enter the following command:
javap -c your_program_name
where "
your_program_name
" is the name of the class containing the compiled code. If you want more information on the Java development utilities you can find it at Home: Java Platform, Standard Edition (Java SE) 8 Release 8[^]. -
At the command prompt in your directory enter the following command:
javap -c your_program_name
where "
your_program_name
" is the name of the class containing the compiled code. If you want more information on the Java development utilities you can find it at Home: Java Platform, Standard Edition (Java SE) 8 Release 8[^]. -
I am in IntelliJ IDEA. I want to view the disassembly of this code to see if it does two comparisons:
if (-0.0 == 0.0) System.out.println("they're equal");
Based on searching, it sounds like IntelliJ can't do that. Anyone know of a Java IDE that can do this? Thank you.
-
There is only ever a single comparison made for each comparison operator, so if your code only has a single '==' operator, the JIT'd code will only generate a single IL comparison. -0.0 does occur when a negative floating-point value is so small that is cannot be represented. That does NOT mean it's a different 0 from positive 0.0. You can see this is you try to convert an extremely small value to a string and output it. You can get -0.0. If your code, the compiler will evaluate the comparison and optimize it out, replacing the expression with just 'true'. The resulting code, and what you see in the disassembly, will be very close to:
if (true) System.out.println("they're equal");
or, depending on code around this, maybe even:
System.out.println("they're equal");
If you want to know how numbers are represented in Java, and most other languages, read The IEEE Standard for Floating-Point Arithmetic (IEEE 754)[^]
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles. Dave Kreskowiak
-
In addition redirecting that to a file is probably going to be a good idea. Even a small class is going to have a lot of output.