Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: 1 2 [3]
  ignore  |  Print  
  Are static non member methods faster?  (Read 13956 times)
0 Members and 1 Guest are viewing this topic.
Offline Jeff

JGO Coder




Got any cats?


« Reply #60 - Posted 2003-10-30 10:54:14 »

Okay,

Its late here--  is everyone as coinfused as I am?

I'll look at it all tomorrow with a clearer head...

JK

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline Jeff

JGO Coder




Got any cats?


« Reply #61 - Posted 2003-10-30 10:59:10 »

Okay, somethinh WEIRD is happening the first time around the loop to the static calls.  I don't believe that it is really de-optimizing that.  Ill look at it more tomorrow.

jk

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #62 - Posted 2003-10-30 12:31:10 »

Quote
In re client/server. On MacOSX I had no perceivable difference between -client and -server.  It would be good for whoever else had reported OSX numbers to check my results to see if they line up.  As I say, taken literally, my numbers show that static is (nominally) SLOWER on MacOSX.


Jeff, you are aware that there is no server VM on the Mac?  Try it
Scott-Palmers-Computer:~ scottpalmer$ java -server -version
java version "1.4.1_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-99)
Java HotSpot(TM) Client VM (build 1.4.1_01-27, mixed mode)
Scott-Palmers-Computer:~ scottpalmer$

If you dig deeper you will see that server VM is a symbolic link to the client VM library.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline princec

JGO Kernel


Medals: 342
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #63 - Posted 2003-10-30 12:49:30 »

When you specify -server on the Mac it changes the memory allocation settings only. Why I know this is anyone's guess.

Cas Smiley

Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #64 - Posted 2003-10-30 14:43:13 »

1  
2  
3  
4  
5  
6  
7  
Scott-Palmers-Computer:~ scottpalmer$ ls -l /System/Library/Frameworks/JavaVM.framework/Libraries/
...
-rwxr-xr-x  1 root  wheel  2659672 24 Sep 03:01 libhotspot.dylib
lrwxr-xr-x  1 root  wheel       16 24 Oct 23:06 libclient.dylib -> libhotspot.dylib
lrwxr-xr-x  1 root  wheel       16 24 Oct 23:06 libjvm.dylib -> libhotspot.dylib
lrwxr-xr-x  1 root  wheel       16 24 Oct 23:06 libserver.dylib -> libhotspot.dylib
...


VMs all use the same code...

Now for settings...
1  
2  
3  
4  
5  
6  
Scott-Palmers-Computer:~ scottpalmer$ ls -l /System/Library/Frameworks/JavaVM.framework/Home/lib
...
-rw-r--r--   1 root  wheel      668 13 Sep 20:12 client_jvm.cfg
-rw-r--r--   1 root  wheel      668 13 Sep 20:12 jvm.cfg
-rw-r--r--   1 root  wheel      668 13 Sep 20:12 server_jvm.cfg
...


each file is identical except that the order of the VMs is changed so that -server or -client is specified first. (e.g. will be the default).. since these are already in files that are differentiated by 'client' and 'server' in the names.. one wonders why they need to
do any of this, since the only way to pick the right file is to know which VM was specified..   Not sure, as I don't really know how this works.

In any case I can't find a place where you can see what parameters are changed between client and server.  I suspected that things like CompileThreshold etc are different.

Offline princec

JGO Kernel


Medals: 342
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #65 - Posted 2003-10-30 15:22:29 »

Your question answered: Apple Java dev thing

Cas Smiley

Offline Jeff

JGO Coder




Got any cats?


« Reply #66 - Posted 2003-10-30 16:38:37 »

Inerestingly enough though, it benchamrks out more like "server" even though they say its a client VM.

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline Jeff

JGO Coder




Got any cats?


« Reply #67 - Posted 2003-10-30 17:00:31 »

Okay.

I made the fixes you suggested (the one wrong call and calling through the class name for static).

Didn't change things much on my system under 1.4.2_02:

Server run:
1  
2  
3  
4  
5  
6  
7  
java -Xcompile -server benchmarks.SimplifiedTest
Instance method (-705032721) 4126ms
Static method (-705032721) 4046ms
Instance method (-705032721) 4076ms
Static method (-705032721) 4326ms
Instance method (-705032721) 4016ms
Static method (-705032721) 4326ms


Client run:
1  
2  
3  
4  
5  
6  
7  
java -Xcompile -client benchmarks.SimplifiedTest
Instance method (-705032721) 11276ms
Static method (-705032721) 9594ms
Instance method (-705032721) 11286ms
Static method (-705032721) 9594ms
Instance method (-705032721) 11576ms
Static method (-705032721) 10285ms


Source:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
package benchmarks;


public class SimplifiedTest {

public static final int SIZE = 100000000;

  public int iadd(int a, int b) {
    return a + b;
  }

  public static int sadd(int a, int b) {
    return a+b;
  }




  public static void main(String[] argv) {
    SimplifiedTest t = new SimplifiedTest();
    for (int q = 0; q < 3; q++) {
      int v = 0;
      long start = System.currentTimeMillis();
      for (int i = 0; i < SIZE * 10; i++) {
        int a = t.iadd(i, 1);
        v = t.iadd(v, a);
        v = t.iadd(v, i);
        v = t.iadd(v, 5);
        v = t.iadd(v, v);
        v = t.iadd(i, v);
      }
      System.out.println("Instance method (" + v + ") " +
                         (System.currentTimeMillis() - start) + "ms");
      v = 0;
      start = System.currentTimeMillis();
      for (int i = 0; i < SIZE * 10; i++) {
        int a = SimplifiedTest.sadd(i, 1);
        v = SimplifiedTest.sadd(v, a);
        v = SimplifiedTest.sadd(v, i);
        v = SimplifiedTest.sadd(v, 5);
        v = SimplifiedTest.sadd(v, v);
        v = SimplifiedTest.sadd(i, v);
      }
      System.out.println("Static method (" + v + ") " +
                         (System.currentTimeMillis() - start) + "ms");
    }
  }
}


Writing the Vm guys now to ask about client...

jk

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline Jeff

JGO Coder




Got any cats?


« Reply #68 - Posted 2003-10-30 19:43:42 »

Turns out its exactly what I expected... a (known) bug in the client compiler Smiley


Invocation of instance methods implies a null check and there's a bug in the current null check eliminator in the client compiler which makes it unable to eliminate one of the null checks in the loop which accounts for the difference between the instance and static case. Otherwise the code is exactly the same for both cases.  However as mike points out you aren't really measuring what you think you're measuring.


(Mike noted that, as SIZE is constant the compiler will fold down a lot of the logic because it can compute it ahead of time.)

Here is the general comment on this whole issue.  Has a bit more detail then I was able to give but its basically the same answer.


As far as your question goes, here's my take.  Static methods have fixed properties, namely that they are statically bindable and don't require null checks.  Instance methods have dynamic properties, namely that they require null checks, which may be eliminated, and they may be statically bindable depending on optimizations in your vm and/or their accessibility, i.e. a private method is always statically bindable and final may be.  So under many conditions they are interchangable performance-wise, it just depends on what your class hierarchy looks like and what the VM can prove about the nullness or non-nullness of your instance, and also of course what your method is going to do.


SO in a NON-BUGGY modern compiler static in of itself should make no appreciable difference.  Anywhere wher it would make a difference is by definition somepalce you couldn't use static to begin with (p[olymorphic behavior).  Unfortunately the client compiler doesn't yet qualify Sad

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #69 - Posted 2003-10-30 22:13:22 »

Excellent, thanks a lot for getting to the bottom of this.  Is this known bug in the publicly accessible bug database? Got a Bug Id number?  (I.e. is this something that people can vote for or is it an internal thing that we aren't really supposed have to deal with?)

Is it expected to be fixed for 1.5?

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #70 - Posted 2003-10-30 22:15:49 »

Quote
Inerestingly enough though, it benchamrks out more like "server" even though they say its a client VM.

I just tell people that's 'cause a PowerPC has an architecture that  you don't have to be ashamed of.  *cough* Intel sucks *cough*
Wink

Hey did you ever get to try this on a Sparc system?

Offline Jeff

JGO Coder




Got any cats?


« Reply #71 - Posted 2003-10-30 22:18:40 »

Quote

I just tell people that's 'cause a PowerPC has an architecture that  you don't have to be ashamed of.  *cough* Intel sucks *cough*
Wink

Hey did you ever get to try this on a Sparc system?


Sparc?  Whats a Sparc?

Just kidding.  i have one on my desk i use for corporate things but at the moment most of my developmentt is mac/PC so it woudl be a pain to set up the test on my Sparc.

And lets face it, everyone reading this is a Client programmer so who really cares about Sparc?  Rasie your hands... anyone... Bueller ... anyone ... ?

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline Jeff

JGO Coder




Got any cats?


« Reply #72 - Posted 2003-10-30 22:22:59 »

Quote
Excellent, thanks a lot for getting to the bottom of this.  Is this known bug in the publicly accessible bug database? Got a Bug Id number?  


Likely, but I'd have to search for it just like you Tongue

Quote

Is it expected to be fixed for 1.5?


I would assume so but thats a guess as I don't have the VM team's schedule infront of me.

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline nonnus29

Senior Member




Giving Java a second chance after ludumdare fiasco


« Reply #73 - Posted 2003-11-06 00:53:25 »

Heh, I come back and you all have done the testing for me...  Very interesting stuff!

Origionally, I was just coming from the perspective of the classic c/c++ debate that the added level of abstraction given by oop makes c++ slower than c.  I'd actually seen some benchmarks that showed a very small but real difference in performance, but that was awhile ago and I certainly don't remember the details.  I was curious if the same idea applied in Java.
Offline Jeff

JGO Coder




Got any cats?


« Reply #74 - Posted 2003-11-06 02:58:02 »

Quote
HOrigionally, I was just coming from the perspective of the classic c/c++ debate that the added level of abstraction given by oop makes c++ slower than c.


I figured that which was why I originally answered as I did, though these bums made me prove it (and found a bug in doing so.  Good going guys.)

Forget what you know about C++ and performance.  Late compilation makes it a whole new ball-game.

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Pages: 1 2 [3]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (24 views)
2014-07-24 01:59:36

Riven (24 views)
2014-07-23 21:16:32

Riven (18 views)
2014-07-23 21:07:15

Riven (21 views)
2014-07-23 20:56:16

ctomni231 (50 views)
2014-07-18 06:55:21

Zero Volt (45 views)
2014-07-17 23:47:54

danieldean (36 views)
2014-07-17 23:41:23

MustardPeter (39 views)
2014-07-16 23:30:00

Cero (56 views)
2014-07-16 00:42:17

Riven (55 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!