Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2006

Tip: Looking for answers? Try searching our database.

inline methods

Thread view: 
G. Ralph Kuntz, MD - 05 Oct 2006 14:38 GMT
According to the Java language specification, a method can only be
"inlined" by the compiler if it is declared final (necessary, but not
complete requirement).

If I declare a class to be final, this implies that all of the methods
are final.  Will javac inline the methods (if other conditions are met)?
Chris Uppal - 05 Oct 2006 15:07 GMT
> According to the Java language specification, a method can only be
> "inlined" by the compiler if it is declared final (necessary, but not
> complete requirement).
>
> If I declare a class to be final, this implies that all of the methods
> are final.  Will javac inline the methods (if other conditions are met)?

As far as I know javac /never/ inlines method calls (and would be in error if
it did so).

The real compiler, on the other hand (the one that runs at runtime), is able[*]
in principle to inline /anything/, whether private, final, or anything else.

[*] "able" both legally (i.e. it is allowed by the JLS and JVM spec) and
technically (i.e. it has the technology, and does use it.)

   -- chris
Oliver Wong - 05 Oct 2006 15:18 GMT
> According to the Java language specification, a method can only be
> "inlined" by the compiler if it is declared final (necessary, but not
> complete requirement).
>
> If I declare a class to be final, this implies that all of the methods
> are final.  Will javac inline the methods (if other conditions are met)?

http://java.sun.com/docs/books/jls/third_edition/html/classes.html#14844
<quote>
A private method and all methods declared immediately within a final class
(§8.1.1.2) behave as if they are final, since it is impossible to override
them.
</quote>

   That said, your statement may be a bit misleading. javac will inline
methods only very rarely:

<quote>
Such inlining cannot be done at compile time unless it can be guaranteed
that Test and Point will always be recompiled together, so that whenever
Point-and specifically its move method-changes, the code for Test.main will
also be updated.
</quote>

   The much more common case will be the JVM, and not javac, doing the
inlining.

<quote>
At run time, a machine-code generator or optimizer can "inline" the body of
a final method, replacing an invocation of the method with the code in its
body.
</quote>

   - Oliver


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.