Avor Nadal wrote:Could the line this.myField = myField be inlined into the caller method
Avor Nadal wrote:Or is the accessibility constraint applicable at compiling time only but no at runtime?
R. Jain wrote:Are you talking about some automatic inlining done by the compiler as in C++? If yes, then that feature is not available in Java.
Avor Nadal wrote:I'd like to know how method inlining deals with the accessibility of object's fields or members.
Avor Nadal wrote:Could the line this.myField = myField be inlined into the caller method, even although the caller hasn't got access to the field myField. Or is the accessibility constraint applicable at compiling time only but no at runtime?
R. Jain wrote:Now, as for the getters and setters accessing private fields, I don't think JIT will inline such methods, as that will break the code.
Jesper de Jong wrote:
R. Jain wrote:Now, as for the getters and setters accessing private fields, I don't think JIT will inline such methods, as that will break the code.
How will that break the code? From the point of view of the source code, the accessibility rules are still followed. What the JIT does at runtime to optimize things, doesn't affect the rules of the language.
Jesper de Jong wrote:These two things do not have anything to do with each other.
The check whether a field is accessible or not is done by the compiler, at compile time. Inlining is done later, at runtime, by the JIT, long after the compiler has translated the source code to byte code.
Jesper de Jong wrote:Yes and yes, and it doesn't violate any accessibility rules. The inlining that the JIT does is a low-level optimization.
R. Jain wrote:...
Avor Nadal wrote:Really what made me ask this question was the fact that the JVM is used to run "other languages" too. Some of them haven't got the same notion about field accessibility that Java has. So I wondered if the JVM had to deal with accessibility or was just a concept from "higher" levels.
Avor Nadal wrote:What you commented about the JVM making its own assumptions (if they're safe) makes sense to me too. I didn't know whether the JVM considered the bytecode generated by javac already safe in this sense or needed to do its own analysis before. But reading the specifications that you've linked, it's more clear. After having checked the bytecode, I guess that a JVM considers the new code derived (optimised) from it also safe, Right?.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:Indeed, most problems seem to crop up when people try to code in a particular way, based on assumptions about what they do.
Avor Nadal wrote:Touché! It's one of my defects....Thank you for your help .
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here