Skip to content

Instantly share code, notes, and snippets.

@AdamClements
Created July 22, 2014 17:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AdamClements/2ae6c4919964b71eb470 to your computer and use it in GitHub Desktop.
Save AdamClements/2ae6c4919964b71eb470 to your computer and use it in GitHub Desktop.
Weird monitorenter/monitorexit
;; Clojure example:
(defn test-locks [this]
(locking this
2))
// Java example:
public class TestMonitors {
public Object block(Integer a) {
int b;
synchronized (a) {
b = new Integer(2);
}
b = a + b;
return b;
}
}
public class example.test.TestMonitors {
public example.test.TestMonitors();
Code:
0: aload_0
1: invokespecial #1 // Method java/lang/Object."<init>":()V
4: return
public java.lang.Object block(java.lang.Integer);
Code:
0: aload_1
1: dup
2: astore_3
3: monitorenter
4: new #2 // class java/lang/Integer
7: dup
8: iconst_2
9: invokespecial #3 // Method java/lang/Integer."<init>":(I)V
12: invokevirtual #4 // Method java/lang/Integer.intValue:()I
15: istore_2
16: aload_3
17: monitorexit
18: goto 28
21: astore 4
23: aload_3
24: monitorexit
25: aload 4
27: athrow
28: aload_1
29: invokevirtual #4 // Method java/lang/Integer.intValue:()I
32: iload_2
33: iadd
34: istore_2
35: iload_2
36: invokestatic #5 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
39: areturn
Exception table:
from to target type
4 18 21 any
21 25 21 any
}
Compiled from "test.clj"
public final class example.test$test_locks extends clojure.lang.AFunction {
public static final java.lang.Object const__0;
public static {};
Code:
0: ldc2_w #10 // long 2l
3: invokestatic #17 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
6: putstatic #19 // Field const__0:Ljava/lang/Object;
9: return
public example.test$test_locks();
Code:
0: aload_0
1: invokespecial #22 // Method clojure/lang/AFunction."<init>":()V
4: return
public java.lang.Object invoke(java.lang.Object);
Code:
0: aload_1
1: aconst_null
2: astore_1
3: astore_2
4: aload_2
5: monitorenter
6: aconst_null
7: pop
8: getstatic #19 // Field const__0:Ljava/lang/Object;
11: astore_3
12: aload_2
13: aconst_null
14: astore_2
15: monitorexit
16: aconst_null
17: pop
18: goto 32
21: astore 4
23: aload_2
24: aconst_null
25: astore_2
26: monitorexit
27: aconst_null
28: pop
29: aload 4
31: athrow
32: aload_3
33: areturn
Exception table:
from to target type
4 12 21 any
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment