Skip to main content

Client-Compiler and inlining

2 replies [Last post]
linuxhippy
Offline
Joined: 2004-01-07
Points: 0

Hi there,

I've developed a network-communication framework over the past 3 years which works under JME, Java-Http-1.1+ and Java-Http-1.2, Java+Socket.

Since it is a grown piece of code and the tons of backends came with time theres a lot of delegation. Even writing a single byte means invoking a lot of small virtual methods and I just wonder how well Hotspot-client optimizes this.

<br />
1.) The call from application code:<br />
palmeClientNet.writeByte(int b)</p>
<p>2.) Inside of palmeClientNet:<br />
public void writeByte(int byt) throws IOException<br />
{<br />
  clientNetwork.getDataOutput().writeByte(byt);<br />
}</p>
<p>3.) Inside of getDataOutput-Object:<br />
public void writeByte(int v) throws IOException<br />
{<br />
   output.writeByte(v);<br />
}</p>
<p>4.) output is a not-synchronized ByteArrayOutputStream in this case.<br />

In fact there 4 method calls not counting what happens inside of ByteArrayOutputStream and 4 member-variable accesses. (The objects these vMethods is called are always the same, so basically they are not really virtual).
Will HotSpot client optimize this, what can and what can't it do? Is it able to inline more than one hirarchy deep?
Will it be able to reduce member-field reads?

Thank you in advance, lg Clemens

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
neverever
Offline
Joined: 2006-05-22
Points: 0

The Client compiler uses a fairly static inlining policy so it may or may not do well on your code. That kind of fine grained delegation can be expensive for I/O even if it's fully inlined, though obviously it's a lot better if it's inlined.

What will get inlined will depend on what the declared types getDataOutput() and output are and maybe also on what classes override writeByte. If they are simply OutputStream then it will likely end up emitting virtual calls because there are many classes which extend OutputStream. If they are more precise it will probably inline them if there is only one method which might be called and they are less than 35 byte in length. Client will generally inline up to 9 levels deep if all these criteria are met though it rarely gets that far. If you have a more concrete example I could tell you more exactly.

Tom Rodriguez
Hotspot Compilers

linuxhippy
Offline
Joined: 2004-01-07
Points: 0

Hello,

I know that such an expensive design is simply stupid when it comes down to IO, however the framework really grew and time and existing code does not allow a rewrite.
I don't want to dig into ugly MSJVM/Netscape-4.08+ bugs again and figure out howto work arround them ;)

Your hints were really helpful:
- output was an very generic Interface-reference (java.io.DataOutput)
- getDataOutput() also returned typed as Interface

Since both interfaces could be easily replaced by their one and only useful implementation (the interfaces are used for different purposes elsewhere too) I don't even get lower code quality.

Thanks a lot, lg Clemens

PS: Thank you very much for this detailed explanation and the knowledge about inlining. I did not e.g. not find the information about inline depth anywhere...
It seems the client-compiler is a kind of cinderella, most used but only mentioned very little ;)