Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.compilers    |    Compiler construction, theory, etc. (Mod    |    2,753 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 1,923 of 2,753    |
|    Srikanth Raju to All    |
|    Optimizations on synchronized methods in    |
|    20 Jul 10 01:35:31    |
   
   From: srikiraju@gmail.com   
      
   I was wondering whether any optimizations are automatically done by   
   the compiler or VM in Java in classes where methods are defined as   
   synchronized. I'm working with a library where a typical function is   
   defined so,   
      
   class Foo   
   {   
   private int a = 0;   
   private int b = 0;   
   public synchronized doSomethingWithA( int var )   
   {   
    int tmp = some_function( var ); // heavy computation   
    a += tmp;   
   }   
   public synchronized doSomethingWithB( int var )   
   {   
    int tmp = some_function( var ); // heavy computation   
    b += tmp;   
   }   
   };   
      
   Can the compiler see that the first statement in the methods are local   
   and therefore not lock the object for that statement, and hold the   
   lock only for the actual addition part, so that it saves time?   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca