Talk:Java performance: Difference between revisions

Content deleted Content added
Reverted 4 edits by Roman ali12 (talk): Rv edits to a bot's talk page message
m Replaced deprecated <source> tags with <syntaxhighlight> (via WP:JWB)
Line 210:
: There are two reasons why Java JIT compiler can rearrange calls to foo and bar, first is because there are no pointers in java, making it easier for the compiler to prove that the reordering (or inlining) will not change anything, second is because of deoptimization, the JIT compiler can make aggressive optimizations based on assumptions (not proof), and deoptimize the code (un-JIT it) if it appear over the time that its assumptions were not true anymore. Concerning your Apple / Fruit example, arrays are objects not pointers in Java, so you are not allowed to put something which is not an Apple in an Apple array. In C/C++, you can put anything in it since an array is just a pointer. [[User:Hervegirod|Hervegirod]] ([[User talk:Hervegirod|talk]]) 17:18, 23 October 2011 (UTC)
:: In this example, it cannot be 'easier' because cost of this for C/C++ is zero. Aggressive (dangerous) optimizations, again, involve run-time check. "No pointers" is more a naming issue. In C, if you have struct complex { float re,im; }; and never take addresses of its fields - re and im (why would you?), but only take addresses of struct complex - you get the same "no pointers" situation as in Java. You miss the Apple/Fruit example entirely. Java disallows this only at run-time, inserting dynamic type-checks. C++ disallows at compile-time. Well you can still put a Pear in Apple array (do you even know how? a simple typecast won't work), but it violates the rules. For one thing you can be sure, there will be no dynamic check for that just because compiler wasn't clever enough to prove it is not necessary.
<sourcesyntaxhighlight lang="java">
class aa {
static class Fruit{}
Line 221:
}
}
</syntaxhighlight>
</source>
[[User:Alliumnsk|Alliumnsk]] ([[User talk:Alliumnsk|talk]])
:: The fact that Java hides pointer semantics from the programmer means nothing about the underlying architecture. Actually, ''every'' object in Java is a pointer, wrapped in a shiny name "reference", except for the primitives.[[User:1exec1|1exec1]] ([[User talk:1exec1|talk]]) 23:08, 25 October 2011 (UTC)