Java and inlining

A

Aaron Fude

Hi,

Is there a good article to read about the inlining of functions in Java. For
example, how inefficient would it be to write double sum(double x) { return
Math.sin(x) + Math.cos(x); }

Thanks!

Aaron Fude
 
C

Chris Smith

Aaron Fude said:
Is there a good article to read about the inlining of functions in Java. For
example, how inefficient would it be to write double sum(double x) { return
Math.sin(x) + Math.cos(x); }

I don't know of a good article to read. In practice, I wouldn't worry
about it. If your code is performing poorly, there are certainly bigger
concerns. A profiler will tell you more.

If you're just curious, though, then read on. My comments from here on
apply to the Sun JVM for various platforms; other virtual machines --
and especially those on small J2ME platforms such as mobile phones --
may differ considerably. Inlining is performed by the JIT compiler at
runtime, and can be applied very widely in modern virtual machines.
Inlining will be most widely applied to methods that are declared as
private, static, or final, or are in final classes. However,
conditional inlining is also performed on polymorphics methods when
possible. The latter optimization is one of the benefits of adaptive
optimizations like the JVM does over static optimization of other
languages.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
A

Aaron Fude

Chris Smith said:
I don't know of a good article to read. In practice, I wouldn't worry
about it. If your code is performing poorly, there are certainly bigger
concerns. A profiler will tell you more.

If you're just curious, though, then read on. My comments from here on
apply to the Sun JVM for various platforms; other virtual machines --
and especially those on small J2ME platforms such as mobile phones --
may differ considerably. Inlining is performed by the JIT compiler at
runtime, and can be applied very widely in modern virtual machines.
Inlining will be most widely applied to methods that are declared as
private, static, or final, or are in final classes. However,
conditional inlining is also performed on polymorphics methods when
possible. The latter optimization is one of the benefits of adaptive
optimizations like the JVM does over static optimization of other
languages.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

Actually, thowing in "final" speeded up the code tremendously.
Interesting... I also used to think that "final" makes little difference,
but the difference turned out to be tremendous is this case!
 
S

Skip

Actually, thowing in "final" speeded up the code tremendously.
Interesting... I also used to think that "final" makes little difference,
but the difference turned out to be tremendous is this case!

Which VM? On the most recent VMs (Suns 1.4 / 1.5) it shouldn't really
matter.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top