Re: Optimizations on synchronized methods in java/C++

Marco van de Voort <marcov@turtle.stack.nl>
Wed, 21 Jul 2010 11:58:06 +0000 (UTC)

          From comp.compilers

Related articles
Optimizations on synchronized methods in java/C++ srikiraju@gmail.com (Srikanth Raju) (2010-07-20)
Re: Optimizations on synchronized methods in java/C++ marcov@turtle.stack.nl (Marco van de Voort) (2010-07-21)
Re: Optimizations on synchronized methods in java/C++ Pidgeot18@verizon.invalid (Joshua Cranmer) (2010-07-21)
| List of all articles for this month |
From: Marco van de Voort <marcov@turtle.stack.nl>
Newsgroups: comp.compilers
Date: Wed, 21 Jul 2010 11:58:06 +0000 (UTC)
Organization: Stack Usenet News Service
References: 10-07-023
Keywords: optimize, Java
Posted-Date: 22 Jul 2010 13:34:48 EDT

On 2010-07-20, Srikanth Raju <srikiraju@gmail.com> wrote:
> 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?


I'm no Java expert, but looking at this piece of code, not the state is
flagged as synchronized, but the method, so I don't see how the compiler
could see it is all about "a" and "b" in the first place.



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.