In a message dated 12/31/00 2:16:58 PM Pacific Standard Time, 
[EMAIL PROTECTED] writes:

>  For compilers in which this is not the case, synchronized methods will
>  probably result in slightly trimmer code than synchronized blocks for
>  methods with multiple return points (a single instruction to release
>  the lock rather than one instruction per return).

A fairly large bytecode savings.  Making the whole method synchronized blocks 
any concurrent calls to that object, though.

class SyncTest {
    int a;

    void gar(int foo) {
        synchronized(this) {
            a = foo;
            }
        }

    synchronized void gar2(int foo) {
        a = foo;
        }
    }

Method void gar(int)
   0 aload_0
   1 astore_2
   2 aload_2
   3 monitorenter
   4 aload_0
   5 iload_1
   6 putfield #2 <Field int a>
   9 aload_2
  10 monitorexit
  11 goto 19
  14 astore_3
  15 aload_2
  16 monitorexit
  17 aload_3
  18 athrow
  19 return
Exception table:
   from   to  target type
     4    14    14   any

Method void gar2(int)
   0 aload_0
   1 iload_1
   2 putfield #2 <Field int a>
   5 return

_______________________________________________
Freenet-dev mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/mailman/listinfo/freenet-dev

Reply via email to