United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-4898726 Nonstatic method calls take lot more time than static method calls
JDK-4898726 : Nonstatic method calls take lot more time than static method calls

Details
Type:
Enhancement
Submit Date:
2003-07-30
Status:
Closed
Updated Date:
2003-10-29
Project Name:
JDK
Resolved Date:
2003-10-29
Component:
hotspot
OS:
linux
Sub-Component:
runtime
CPU:
x86
Priority:
P4
Resolution:
Duplicate
Affected Versions:
1.4.2
Fixed Versions:

Related Reports
Duplicate:

Sub Tasks

Description

Name: gm110360			Date: 07/30/2003


A DESCRIPTION OF THE REQUEST :
I was surprised to see nonstatic method calls taking anyhwere from 25% to 100% more time to execute than static methods. I was hoping it will be in the range of 5%! :-(

BTW, I got these numbers looking at javacc (http://javacc.dev.java.net) generated code. JavaCC has an option called STATIC which when set, generates static/single use parsers. We introduced this way back in 1996 becase those days nonstatic method calls were extremely expensive - we have seen overheads upto 20 times! Now, I am looking at ways of simplifying and improving JavaCC and wanted to see if STATIC still made sense. I was blown away by the slowdowns with nonstatic methods.

JUSTIFICATION :
If fixed. it can enhance performance of almost all Java applications, including appservers etc.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Would like nonstatic methods to be in the 5% overhead range as compared to static methods.
ACTUAL -
It is between 25%-100%

---------- BEGIN SOURCE ----------
public class t
{
   static int cnt;
   static public void f()
   {
      if (cnt-- == 0) return;
      g();
   }

   static public void g() { f(); }

   public void nonstatic_f()
   {
      if (cnt-- == 0) return;
      nonstatic_g();
   }

   public void nonstatic_g() { nonstatic_f(); }

   public static void main(String[] args) throws Throwable
   {
      long l = System.currentTimeMillis();
      int tmp = Integer.parseInt(args[0]);
      try
      {
         t o = new t();
         for (int i = 0; i < tmp; i++) { cnt = tmp; o.f(); }
      }
      finally
      {
         System.out.println("Static calls take: " + (System.currentTimeMillis() - l) + " ms.");
      }

      l = System.currentTimeMillis();
      try
      {
         t o = new t();
         for (int i = 0; i < tmp; i++) { cnt = tmp; o.nonstatic_f(); }
      }
      finally
      {
         System.out.println("Nonstatic calls take: " + (System.currentTimeMillis() - l) + " ms.");
      }
   }
}



Just run java t 10000 to see the difference in time taken for static vs. nonstatic
---------- END SOURCE ----------
(Incident Review ID: 192927) 
======================================================================

                                    

Comments
EVALUATION

This is a dup of 4803284..
###@###.### 2003-10-29
                                     
2003-10-29



Hardware and Software, Engineered to Work Together