Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Virtual Machine / September 2007

Tip: Looking for answers? Try searching our database.

Synchronized implementations

Thread view: 
Joshua Cranmer - 13 Sep 2007 02:27 GMT
I have noticed a few times that Java implements synchronized blocks thusly:

aload 4
dup
astore 5
monitorenter
[ various instructions ]
aload 5
monitorexit

Why does it duplicate the variable when running synchronized blocks?
Signature

Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth

Roedy Green - 13 Sep 2007 08:16 GMT
On Thu, 13 Sep 2007 01:27:03 GMT, Joshua Cranmer
<Pidgeot18@verizon.net> wrote, quoted or indirectly quoted someone who
said :

>astore 5
>monitorenter
[quoted text clipped - 3 lines]
>
>Why does it duplicate the variable when running synchronized blocks?

Byte code has almost no optimisation.  Sun does all its optimisations
in HotSpot.
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Barb Knox - 13 Sep 2007 09:33 GMT
> I have noticed a few times that Java implements synchronized blocks thusly:
>
[quoted text clipped - 7 lines]
>
> Why does it duplicate the variable when running synchronized blocks?

Because you might have code like this:
   synchronized (something) {
       ...
       something := somethingElse;
       ...
   }

Signature

---------------------------

|  BBB                b    \     Barbara at LivingHistory stop co stop uk
|  B  B   aa     rrr  b     |
|  BBB   a  a   r     bbb   |    Quidquid latine dictum sit,
|  B  B  a  a   r     b  b  |    altum viditur.
|  BBB    aa a  r     bbb   |  
-----------------------------


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.