Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.help > #749

Re: `It would be better like this but we can't afford this due to CPU time reasons': dynamic and static links in Java

From Roedy Green <see_website@mindprod.com.invalid>
Newsgroups comp.lang.java.help
Subject Re: `It would be better like this but we can't afford this due to CPU time reasons': dynamic and static links in Java
Date 2011-06-06 11:08 -0700
Organization Canadian Mind Products
Message-ID <bc5qu6pc1vigpamo2jfe83q9jjl82o6mqb@4ax.com> (permalink)
References <877h91fm80.fsf@merciadriluca-station.MERCIADRILUCA>

Show all headers | View raw


On Sat, 04 Jun 2011 21:08:47 +0200, Merciadri Luca
<Luca.Merciadri@student.ulg.ac.be> wrote, quoted or indirectly quoted
someone who said :

>However, would it really be `better?' I think the aforementioned fact
>(see the text before AFAIK) is often used in Java programming, isn't
>it? Could one provide more details on this choice, and on its implications?


It is traditional whenever a newbie asks any question about
performance to bawl them out and say they have no business thinking
about such things in general, only after benchmarking some particular
case and determining there is a significant bottleneck.

I see no problem with such inquiry, so long as you only use such
knowledge to improve code, without disturbing its legibility.

If a method is static or final and never overridden, the compiler
knows exactly which version of the method is needed at compile time.

In the JVM where are several invoke instructions, each needing a
different amount of information available at compile time.  The more
information is available, the faster the link can be:


invokeinterface (slowest)
invokevirtual
invokestatic (fastest)

In the early interpreters there was a huge difference in number of
cycles.  In the latest hot spot, with the addition of dynamically
gleaned information and clever machine code optimisation, the penalty
has been drastically reduced, to the point sane people recommend using
interface references when they did not have to.


-- 
Roedy Green Canadian Mind Products
http://mindprod.com
How long did it take after the car was invented before owners understood 
cars would not work unless you regularly changed the oil and the tires?
We have gone 33 years and still it is rare to uncover a user who 
understands computers don't work without regular backups.

Back to comp.lang.java.help | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

`It would be better like this but we can't afford this due to CPU time reasons': dynamic and static links in Java Merciadri Luca <Luca.Merciadri@student.ulg.ac.be> - 2011-06-04 21:08 +0200
  Re: `It would be better like this but we can't afford this due to CPU time reasons': dynamic and static links in Java Roedy Green <see_website@mindprod.com.invalid> - 2011-06-06 11:08 -0700
  Re: `It would be better like this but we can't afford this due to CPU time reasons': dynamic and static links in Java Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-06-06 12:50 -0700
    Re: `It would be better like this but we can't afford this due to CPU time reasons': dynamic and static links in Java Roedy Green <see_website@mindprod.com.invalid> - 2011-06-21 11:53 -0700

csiph-web