Migrate, Modernize and Build Java Web Apps on Azure: This live workshop will cover methods to enhance Java application development workflow.
Modern Digital Website Security: Prepare to face any form of malicious web activity and enable your sites to optimally serve your customers.
Chief Architect at CIME Software Labs
San Francisco, US
Joined Apr 2008
About
@ciurana
Stats
Reputation: | 526 |
Pageviews: | 0 |
Articles: | 0 |
Comments: | 5 |
Nothing here yet! Would you like to post an article?
Refcards
NoSQL and Data Scalability
Scalability and High Availability
Apache Hadoop Deployment
Getting Started with NoSQL and Data Scalability
SOA Patterns
Comments
Mar 26, 2013 · Eugene Ciurana
Mar 25, 2013 · Mr B Loid
Hola.
Not a lot of JIT magic there. If you dump the .class file to JVM bytecodes, you will see that the compiler sets the space to be allocated when the method first enters scope, regardless of where in the method the variable was declared.
Outside:
<code>
public class Test {
public static void main(java.lang.String...) throws java.lang.Exception;
Code:
0: iconst_0
1: istore_2
2: iload_2
3: bipush 10
5: if_icmpge 28
8: iload_2
9: i2d
10: iload_2
11: i2d
12: iconst_2
13: iload_2
14: imul
15: i2d
16: invokestatic #2 // Method java/lang/Math.pow:(DD)D
19: dmul
20: d2i
21: istore_1
22: iinc 2, 1
25: goto 2
28: return
}
</code>
Inside:
<code>
public class Test {
public static void main(java.lang.String...) throws java.lang.Exception;
Code:
0: iconst_0
1: istore_1
2: iload_1
3: bipush 10
5: if_icmpge 28
8: iload_1
9: i2d
10: iload_1
11: i2d
12: iconst_2
13: iload_1
14: imul
15: i2d
16: invokestatic #2 // Method java/lang/Math.pow:(DD)D
19: dmul
20: d2i
21: istore_2
22: iinc 1, 1
25: goto 2
28: return
}
</code>
A better practice for new programmers, though, might be to remind them to not allocate/release resource-intensive objects in a loop. I was surprised to recently see some very slow code from experienced guys who did just that.
Anyway -- check your own code's behavior with:
<code>
javap -c YourClassFileHere.class
</code>
Cheers!
pr3d
Mar 25, 2013 · Allen Coin
Hola.
Not a lot of JIT magic there. If you dump the .class file to JVM bytecodes, you will see that the compiler sets the space to be allocated when the method first enters scope, regardless of where in the method the variable was declared.
Outside:
<code>
public class Test {
public static void main(java.lang.String...) throws java.lang.Exception;
Code:
0: iconst_0
1: istore_2
2: iload_2
3: bipush 10
5: if_icmpge 28
8: iload_2
9: i2d
10: iload_2
11: i2d
12: iconst_2
13: iload_2
14: imul
15: i2d
16: invokestatic #2 // Method java/lang/Math.pow:(DD)D
19: dmul
20: d2i
21: istore_1
22: iinc 2, 1
25: goto 2
28: return
}
</code>
Inside:
<code>
public class Test {
public static void main(java.lang.String...) throws java.lang.Exception;
Code:
0: iconst_0
1: istore_1
2: iload_1
3: bipush 10
5: if_icmpge 28
8: iload_1
9: i2d
10: iload_1
11: i2d
12: iconst_2
13: iload_1
14: imul
15: i2d
16: invokestatic #2 // Method java/lang/Math.pow:(DD)D
19: dmul
20: d2i
21: istore_2
22: iinc 1, 1
25: goto 2
28: return
}
</code>
A better practice for new programmers, though, might be to remind them to not allocate/release resource-intensive objects in a loop. I was surprised to recently see some very slow code from experienced guys who did just that.
Anyway -- check your own code's behavior with:
<code>
javap -c YourClassFileHere.class
</code>
Cheers!
pr3d
Mar 05, 2010 · Joseph Ottinger
Feb 23, 2010 · Eugene Ciurana