Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4898726
Votes 1
Synopsis Nonstatic method calls take lot more time than static method calls
Category java:runtime
Reported Against 1.4.2
Release Fixed
State 11-Closed, duplicate of 4803284, request for enhancement
Priority: 4-Low
Related Bugs 4803284
Submit Date 30-JUL-2003
Description




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) 
======================================================================
Work Around
N/A
Evaluation
This is a dup of 4803284..
  xxxxx@xxxxx   2003-10-29
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang