Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > inline methods

Reply
Thread Tools

inline methods

 
 
G. Ralph Kuntz, MD
Guest
Posts: n/a
 
      10-05-2006
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)?

 
Reply With Quote
 
 
 
 
Chris Uppal
Guest
Posts: n/a
 
      10-05-2006
G. Ralph Kuntz, MD wrote:

> 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


 
Reply With Quote
 
 
 
 
Oliver Wong
Guest
Posts: n/a
 
      10-05-2006
"G. Ralph Kuntz, MD" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> 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/t...ses.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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there a way to find the class methods of a class, just like'methods' finds the instance methods? Kenneth McDonald Ruby 5 09-26-2008 03:09 PM
Tool which expands implicitly inline inline functions tthunder@gmx.de C++ 3 06-16-2005 12:54 AM
To inline or not to inline? Alvin C++ 7 05-06-2005 03:04 PM
External inline functions calling internal inline functions Daniel Vallstrom C Programming 2 11-21-2003 01:57 PM
inline or not to inline in C++ Abhi C++ 2 07-03-2003 12:07 AM



Advertisments