KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > object > bytecode > JavaUtilConcurrentLinkedBlockingQueueClassAdapter


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.object.bytecode;
5
6 import com.tc.asm.ClassAdapter;
7 import com.tc.asm.MethodAdapter;
8 import com.tc.asm.ClassVisitor;
9 import com.tc.asm.Label;
10 import com.tc.asm.MethodVisitor;
11 import com.tc.asm.Opcodes;
12 import com.tc.object.SerializationUtil;
13
14 public class JavaUtilConcurrentLinkedBlockingQueueClassAdapter extends ClassAdapter implements Opcodes {
15   private static final String JavaDoc TC_TAKE_METHOD_NAME = ByteCodeUtil.TC_METHOD_PREFIX + "take";
16   private static final String JavaDoc TC_PUT_METHOD_NAME = ByteCodeUtil.TC_METHOD_PREFIX + "put";
17   private static final String JavaDoc TC_EXTRACT_METHOD_NAME = ByteCodeUtil.TC_METHOD_PREFIX + "extract";
18   private static final String JavaDoc TC_EXTRACT_METHOD_DESC = "()Ljava/lang/Object;";
19
20   private static final String JavaDoc GET_ITEM_METHOD_NAME = "getItem";
21   private static final String JavaDoc GET_ITEM_METHOD_DESC = "()Ljava/lang/Object;";
22
23   public JavaUtilConcurrentLinkedBlockingQueueClassAdapter(ClassVisitor cv) {
24     super(cv);
25   }
26
27   public void visitEnd() {
28     addTCExtractMethod();
29     addTCTakeMethod();
30     addTCPutMethod();
31     addInitMethodCode();
32     super.visitEnd();
33   }
34
35   public MethodVisitor visitMethod(int access, String JavaDoc name, String JavaDoc desc, String JavaDoc signature, String JavaDoc[] exceptions) {
36     MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
37     // Recreating the instrumented method because it is simpler and it performs a little better than
38
// injecting code.
39
mv = new NodeMethodAdapter(mv);
40     if ("remove".equals(name) && "(Ljava/lang/Object;)Z".equals(desc)) {
41       recreateRemoveMethod(mv);
42       return null;
43     } else if ("offer".equals(name) && "(Ljava/lang/Object;)Z".equals(desc)) {
44       recreateOfferMethod(mv);
45       return null;
46     } else if ("offer".equals(name) && "(Ljava/lang/Object;JLjava/util/concurrent/TimeUnit;)Z".equals(desc)) {
47       recreateOfferTimeoutMethod(mv);
48       return null;
49     } else if ("put".equals(name) && "(Ljava/lang/Object;)V".equals(desc)) {
50       recreatePutMethod(mv);
51       return null;
52     }
53
54     return mv;
55   }
56   
57   /*
58    * The __tc_put() is a non-blocking version of put() and is called in the applicator only.
59    * We allow it to go over the capacity of the LinkedBlockingQueue but the capacity should
60    * eventually goes down by take() method in the application thread.
61    */

62   private void addTCPutMethod() {
63     MethodVisitor mv = super.visitMethod(ACC_PUBLIC, TC_PUT_METHOD_NAME, "(Ljava/lang/Object;)V", null, new String JavaDoc[] { "java/lang/InterruptedException" });
64     mv.visitCode();
65     Label l0 = new Label();
66     Label l1 = new Label();
67     mv.visitTryCatchBlock(l0, l1, l1, null);
68     Label l2 = new Label();
69     Label l3 = new Label();
70     mv.visitTryCatchBlock(l2, l3, l1, null);
71     Label l4 = new Label();
72     mv.visitLabel(l4);
73     mv.visitVarInsn(ALOAD, 1);
74     Label l5 = new Label();
75     mv.visitJumpInsn(IFNONNULL, l5);
76     mv.visitTypeInsn(NEW, "java/lang/NullPointerException");
77     mv.visitInsn(DUP);
78     mv.visitMethodInsn(INVOKESPECIAL, "java/lang/NullPointerException", "<init>", "()V");
79     mv.visitInsn(ATHROW);
80     mv.visitLabel(l5);
81     mv.visitInsn(ICONST_M1);
82     mv.visitVarInsn(ISTORE, 2);
83     Label l6 = new Label();
84     mv.visitLabel(l6);
85     mv.visitVarInsn(ALOAD, 0);
86     mv.visitFieldInsn(GETFIELD, "java/util/concurrent/LinkedBlockingQueue", "putLock", "Ljava/util/concurrent/locks/ReentrantLock;");
87     mv.visitVarInsn(ASTORE, 3);
88     Label l7 = new Label();
89     mv.visitLabel(l7);
90     mv.visitVarInsn(ALOAD, 0);
91     mv.visitFieldInsn(GETFIELD, "java/util/concurrent/LinkedBlockingQueue", "count", "Ljava/util/concurrent/atomic/AtomicInteger;");
92     mv.visitVarInsn(ASTORE, 4);
93     Label l8 = new Label();
94     mv.visitLabel(l8);
95     mv.visitVarInsn(ALOAD, 3);
96     mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/concurrent/locks/ReentrantLock", "lockInterruptibly", "()V");
97     mv.visitLabel(l0);
98     mv.visitVarInsn(ALOAD, 0);
99     mv.visitVarInsn(ALOAD, 1);
100     mv.visitMethodInsn(INVOKESPECIAL, "java/util/concurrent/LinkedBlockingQueue", "insert", "(Ljava/lang/Object;)V");
101     Label l9 = new Label();
102     mv.visitLabel(l9);
103     mv.visitVarInsn(ALOAD, 4);
104     mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/concurrent/atomic/AtomicInteger", "getAndIncrement", "()I");
105     mv.visitVarInsn(ISTORE, 2);
106     Label l10 = new Label();
107     mv.visitLabel(l10);
108     mv.visitVarInsn(ILOAD, 2);
109     mv.visitInsn(ICONST_1);
110     mv.visitInsn(IADD);
111     mv.visitVarInsn(ALOAD, 0);
112     mv.visitFieldInsn(GETFIELD, "java/util/concurrent/LinkedBlockingQueue", "capacity", "I");
113     mv.visitJumpInsn(IF_ICMPGE, l2);
114     mv.visitVarInsn(ALOAD, 0);
115     mv.visitFieldInsn(GETFIELD, "java/util/concurrent/LinkedBlockingQueue", "notFull", "Ljava/util/concurrent/locks/Condition;");
116     mv.visitMethodInsn(INVOKEINTERFACE, "java/util/concurrent/locks/Condition", "signal", "()V");
117     mv.visitJumpInsn(GOTO, l2);
118     mv.visitLabel(l1);
119     mv.visitVarInsn(ASTORE, 6);
120     Label l11 = new Label();
121     mv.visitJumpInsn(JSR, l11);
122     Label l12 = new Label();
123     mv.visitLabel(l12);
124     mv.visitVarInsn(ALOAD, 6);
125     mv.visitInsn(ATHROW);
126     mv.visitLabel(l11);
127     mv.visitVarInsn(ASTORE, 5);
128     Label l13 = new Label();
129     mv.visitLabel(l13);
130     mv.visitVarInsn(ALOAD, 3);
131     mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/concurrent/locks/ReentrantLock", "unlock", "()V");
132     Label l14 = new Label();
133     mv.visitLabel(l14);
134     mv.visitVarInsn(RET, 5);
135     mv.visitLabel(l2);
136     mv.visitJumpInsn(JSR, l11);
137     mv.visitLabel(l3);
138     mv.visitVarInsn(ILOAD, 2);
139     Label l15 = new Label();
140     mv.visitJumpInsn(IFNE, l15);
141     mv.visitVarInsn(ALOAD, 0);
142     mv.visitMethodInsn(INVOKESPECIAL, "java/util/concurrent/LinkedBlockingQueue", "signalNotEmpty", "()V");
143     mv.visitLabel(l15);
144     mv.visitInsn(RETURN);
145     Label l16 = new Label();
146     mv.visitLabel(l16);
147     mv.visitMaxs(0, 0);
148     mv.visitEnd();
149   }
150
151   /**
152    * The __tc_take() method is the non-blocking version of take and is used by the applicator
153    * only. We allow the capacity to fall below 0, but the capacity should eventually goes up
154    * by the put() method in the application thread.
155    */

156   private void addTCTakeMethod() {
157     MethodVisitor mv = super.visitMethod(ACC_PUBLIC, TC_TAKE_METHOD_NAME, "()Ljava/lang/Object;", null,
158                                          new String JavaDoc[] { "java/lang/InterruptedException" });
159     mv.visitCode();
160     Label l0 = new Label();
161     Label l1 = new Label();
162     mv.visitTryCatchBlock(l0, l1, l1, null);
163     Label l2 = new Label();
164     Label l3 = new Label();
165     mv.visitTryCatchBlock(l2, l3, l1, null);
166     Label l4 = new Label();
167     mv.visitLabel(l4);
168     mv.visitInsn(ICONST_M1);
169     mv.visitVarInsn(ISTORE, 2);
170     Label l5 = new Label();
171     mv.visitLabel(l5);
172     mv.visitVarInsn(ALOAD, 0);
173     mv.visitFieldInsn(GETFIELD, "java/util/concurrent/LinkedBlockingQueue", "count",
174                       "Ljava/util/concurrent/atomic/AtomicInteger;");
175     mv.visitVarInsn(ASTORE, 3);
176     Label l6 = new Label();
177     mv.visitLabel(l6);
178     mv.visitVarInsn(ALOAD, 0);
179     mv.visitFieldInsn(GETFIELD, "java/util/concurrent/LinkedBlockingQueue", "takeLock",
180                       "Ljava/util/concurrent/locks/ReentrantLock;");
181     mv.visitVarInsn(ASTORE, 4);
182     Label l7 = new Label();
183     mv.visitLabel(l7);
184     mv.visitVarInsn(ALOAD, 4);
185     mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/concurrent/locks/ReentrantLock", "lockInterruptibly", "()V");
186     mv.visitLabel(l0);
187     mv.visitVarInsn(ALOAD, 0);
188     mv.visitFieldInsn(GETFIELD, "java/util/concurrent/LinkedBlockingQueue", "head",
189                       "Ljava/util/concurrent/LinkedBlockingQueue$Node;");
190     mv.visitVarInsn(ALOAD, 0);
191     mv.visitFieldInsn(GETFIELD, "java/util/concurrent/LinkedBlockingQueue", "last",
192                       "Ljava/util/concurrent/LinkedBlockingQueue$Node;");
193     Label l8 = new Label();
194     mv.visitJumpInsn(IF_ACMPNE, l8);
195     Label l9 = new Label();
196     mv.visitLabel(l9);
197     mv.visitTypeInsn(NEW, "com/tc/exception/TCRuntimeException");
198     mv.visitInsn(DUP);
199     mv.visitLdcInsn(TC_TAKE_METHOD_NAME + ": Trying to do a take from an empty queue.");
200     mv.visitMethodInsn(INVOKESPECIAL, "com/tc/exception/TCRuntimeException", "<init>", "(Ljava/lang/String;)V");
201     mv.visitInsn(ATHROW);
202     mv.visitLabel(l8);
203     mv.visitVarInsn(ALOAD, 0);
204     mv.visitMethodInsn(INVOKESPECIAL, "java/util/concurrent/LinkedBlockingQueue", TC_EXTRACT_METHOD_NAME,
205                        TC_EXTRACT_METHOD_DESC);
206     mv.visitVarInsn(ASTORE, 1);
207     Label l10 = new Label();
208     mv.visitLabel(l10);
209     mv.visitVarInsn(ALOAD, 3);
210     mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/concurrent/atomic/AtomicInteger", "getAndDecrement", "()I");
211     mv.visitVarInsn(ISTORE, 2);
212     mv.visitJumpInsn(GOTO, l2);
213     mv.visitLabel(l1);
214     mv.visitVarInsn(ASTORE, 6);
215     Label l11 = new Label();
216     mv.visitJumpInsn(JSR, l11);
217     Label l12 = new Label();
218     mv.visitLabel(l12);
219     mv.visitVarInsn(ALOAD, 6);
220     mv.visitInsn(ATHROW);
221     mv.visitLabel(l11);
222     mv.visitVarInsn(ASTORE, 5);
223     Label l13 = new Label();
224     mv.visitLabel(l13);
225     mv.visitVarInsn(ALOAD, 4);
226     mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/concurrent/locks/ReentrantLock", "unlock", "()V");
227     Label l14 = new Label();
228     mv.visitLabel(l14);
229     mv.visitVarInsn(RET, 5);
230     mv.visitLabel(l2);
231     mv.visitJumpInsn(JSR, l11);
232     mv.visitLabel(l3);
233     mv.visitVarInsn(ILOAD, 2);
234     mv.visitVarInsn(ALOAD, 0);
235     mv.visitFieldInsn(GETFIELD, "java/util/concurrent/LinkedBlockingQueue", "capacity", "I");
236     Label l15 = new Label();
237     mv.visitJumpInsn(IF_ICMPNE, l15);
238     mv.visitVarInsn(ALOAD, 0);
239     mv.visitMethodInsn(INVOKESPECIAL, "java/util/concurrent/LinkedBlockingQueue", "signalNotFull", "()V");
240     mv.visitLabel(l15);
241     mv.visitVarInsn(ALOAD, 1);
242     mv.visitInsn(ARETURN);
243     Label l16 = new Label();
244     mv.visitLabel(l16);
245     mv.visitMaxs(0, 0);
246     mv.visitEnd();
247   }
248   
249   private void recreateOfferTimeoutMethod(MethodVisitor mv) {
250     mv.visitCode();
251     Label l0 = new Label();
252     Label l1 = new Label();
253     mv.visitTryCatchBlock(l0, l1, l1, "java/lang/InterruptedException");
254     Label l2 = new Label();
255     Label l3 = new Label();
256     Label l4 = new Label();
257     mv.visitTryCatchBlock(l2, l3, l4, null);
258     mv.visitTryCatchBlock(l0, l4, l4, null);
259     Label l5 = new Label();
260     mv.visitLabel(l5);
261     mv.visitLineNumber(325, l5);
262     mv.visitVarInsn(ALOAD, 1);
263     Label l6 = new Label();
264     mv.visitJumpInsn(IFNONNULL, l6);
265     mv.visitTypeInsn(NEW, "java/lang/NullPointerException");
266     mv.visitInsn(DUP);
267     mv.visitMethodInsn(INVOKESPECIAL, "java/lang/NullPointerException", "<init>", "()V");
268     mv.visitInsn(ATHROW);
269     mv.visitLabel(l6);
270     mv.visitLineNumber(326, l6);
271     mv.visitVarInsn(ALOAD, 4);
272     mv.visitVarInsn(LLOAD, 2);
273     mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/concurrent/TimeUnit", "toNanos", "(J)J");
274     mv.visitVarInsn(LSTORE, 5);
275     Label l7 = new Label();
276     mv.visitLabel(l7);
277     mv.visitLineNumber(327, l7);
278     mv.visitInsn(ICONST_M1);
279     mv.visitVarInsn(ISTORE, 7);
280     Label l8 = new Label();
281     mv.visitLabel(l8);
282     mv.visitLineNumber(328, l8);
283     mv.visitInsn(ICONST_M1);
284     mv.visitVarInsn(ISTORE, 8);
285     Label l9 = new Label();
286     mv.visitLabel(l9);
287     mv.visitLineNumber(329, l9);
288     mv.visitVarInsn(ALOAD, 0);
289     mv.visitFieldInsn(GETFIELD, "java/util/concurrent/LinkedBlockingQueue", "putLock", "Ljava/util/concurrent/locks/ReentrantLock;");
290     mv.visitVarInsn(ASTORE, 9);
291     Label l10 = new Label();
292     mv.visitLabel(l10);
293     mv.visitLineNumber(330, l10);
294     mv.visitVarInsn(ALOAD, 0);
295     mv.visitFieldInsn(GETFIELD, "java/util/concurrent/LinkedBlockingQueue", "count", "Ljava/util/concurrent/atomic/AtomicInteger;");
296     mv.visitVarInsn(ASTORE, 10);
297     Label l11 = new Label();
298     mv.visitLabel(l11);
299     mv.visitLineNumber(331, l11);
300     mv.visitVarInsn(ALOAD, 9);
301     mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/concurrent/locks/ReentrantLock", "lockInterruptibly", "()V");
302     mv.visitLabel(l2);
303     mv.visitLineNumber(334, l2);
304     mv.visitVarInsn(ALOAD, 10);
305     mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/concurrent/atomic/AtomicInteger", "get", "()I");
306     mv.visitVarInsn(ALOAD, 0);
307     mv.visitFieldInsn(GETFIELD, "java/util/concurrent/LinkedBlockingQueue", "capacity", "I");
308     Label l12 = new Label();
309     mv.visitJumpInsn(IF_ICMPGE, l12);
310     Label l13 = new Label();
311     mv.visitLabel(l13);
312     mv.visitLineNumber(335, l13);
313     mv.visitVarInsn(ALOAD, 0);
314     mv.visitVarInsn(ALOAD, 1);
315     mv.visitMethodInsn(INVOKESPECIAL, "java/util/concurrent/LinkedBlockingQueue", "insert", "(Ljava/lang/Object;)V");
316     Label l14 = new Label();
317     mv.visitLabel(l14);
318     mv.visitLineNumber(336, l14);
319     mv.visitVarInsn(ALOAD, 0);
320     mv.visitMethodInsn(INVOKESTATIC, "com/tc/object/bytecode/ManagerUtil", "isManaged", "(Ljava/lang/Object;)Z");
321     Label l15 = new Label();
322     mv.visitJumpInsn(IFEQ, l15);
323     Label l16 = new Label();
324     mv.visitLabel(l16);
325     mv.visitLineNumber(337, l16);
326     mv.visitVarInsn(ALOAD, 10);
327     mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/concurrent/atomic/AtomicInteger", "get", "()I");
328     mv.visitVarInsn(ISTORE, 7);
329     Label l17 = new Label();
330     mv.visitLabel(l17);
331     mv.visitLineNumber(338, l17);
332     mv.visitVarInsn(ALOAD, 0);
333     mv.visitVarInsn(ALOAD, 9);
334     mv.visitLdcInsn("put(Ljava/lang/Object;)V");
335     mv.visitInsn(ICONST_1);
336     mv.visitTypeInsn(ANEWARRAY, "java/lang/Object");
337     mv.visitInsn(DUP);
338     mv.visitInsn(ICONST_0);
339     mv.visitVarInsn(ALOAD, 1);
340     mv.visitInsn(AASTORE);
341     mv.visitMethodInsn(INVOKESTATIC, "com/tc/object/bytecode/ManagerUtil", "logicalInvokeWithTransaction", "(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/String;[Ljava/lang/Object;)V");
342     Label l18 = new Label();
343     mv.visitLabel(l18);
344     mv.visitLineNumber(339, l18);
345     mv.visitVarInsn(ALOAD, 10);
346     mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/concurrent/atomic/AtomicInteger", "getAndIncrement", "()I");
347     mv.visitVarInsn(ISTORE, 8);
348     Label l19 = new Label();
349     mv.visitJumpInsn(GOTO, l19);
350     mv.visitLabel(l15);
351     mv.visitLineNumber(341, l15);
352     mv.visitVarInsn(ALOAD, 10);
353     mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/concurrent/atomic/AtomicInteger", "getAndIncrement", "()I");
354     mv.visitVarInsn(ISTORE, 7);
355     mv.visitLabel(l19);
356     mv.visitLineNumber(343, l19);
357     mv.visitVarInsn(ILOAD, 7);
358     mv.visitInsn(ICONST_1);
359     mv.visitInsn(IADD);
360     mv.visitVarInsn(ALOAD, 0);
361     mv.visitFieldInsn(GETFIELD, "java/util/concurrent/LinkedBlockingQueue", "capacity", "I");
362     Label l20 = new Label();
363     mv.visitJumpInsn(IF_ICMPGE, l20);
364     mv.visitVarInsn(ALOAD, 0);
365     mv.visitFieldInsn(GETFIELD, "java/util/concurrent/LinkedBlockingQueue", "notFull", "Ljava/util/concurrent/locks/Condition;");
366     mv.visitMethodInsn(INVOKEINTERFACE, "java/util/concurrent/locks/Condition", "signal", "()V");
367     Label l21 = new Label();
368     mv.visitLabel(l21);
369     mv.visitLineNumber(344, l21);
370     mv.visitJumpInsn(GOTO, l20);
371     mv.visitLabel(l12);
372     mv.visitLineNumber(346, l12);
373     mv.visitVarInsn(LLOAD, 5);
374     mv.visitInsn(LCONST_0);
375     mv.visitInsn(LCMP);
376     mv.visitJumpInsn(IFGT, l0);
377     mv.visitLabel(l3);
378     mv.visitLineNumber(355, l3);
379     mv.visitVarInsn(ALOAD, 9);
380     mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/concurrent/locks/ReentrantLock", "unlock", "()V");
381     Label l22 = new Label();
382     mv.visitLabel(l22);
383     mv.visitLineNumber(346, l22);
384     mv.visitInsn(ICONST_0);
385     mv.visitInsn(IRETURN);
386     mv.visitLabel(l0);
387     mv.visitLineNumber(348, l0);
388     mv.visitVarInsn(ALOAD, 0);
389     mv.visitFieldInsn(GETFIELD, "java/util/concurrent/LinkedBlockingQueue", "notFull", "Ljava/util/concurrent/locks/Condition;");
390     mv.visitVarInsn(LLOAD, 5);
391     mv.visitMethodInsn(INVOKEINTERFACE, "java/util/concurrent/locks/Condition", "awaitNanos", "(J)J");
392     mv.visitVarInsn(LSTORE, 5);
393     mv.visitJumpInsn(GOTO, l2);
394     mv.visitLabel(l1);
395     mv.visitLineNumber(349, l1);
396     mv.visitVarInsn(ASTORE, 11);
397     Label l23 = new Label();
398     mv.visitLabel(l23);
399     mv.visitLineNumber(350, l23);
400     mv.visitVarInsn(ALOAD, 0);
401     mv.visitFieldInsn(GETFIELD, "java/util/concurrent/LinkedBlockingQueue", "notFull", "Ljava/util/concurrent/locks/Condition;");
402     mv.visitMethodInsn(INVOKEINTERFACE, "java/util/concurrent/locks/Condition", "signal", "()V");
403     Label l24 = new Label();
404     mv.visitLabel(l24);
405     mv.visitLineNumber(351, l24);
406     mv.visitVarInsn(ALOAD, 11);
407     mv.visitInsn(ATHROW);
408     Label l25 = new Label();
409     mv.visitLabel(l25);
410     mv.visitLineNumber(333, l25);
411     mv.visitJumpInsn(GOTO, l2);
412     mv.visitJumpInsn(GOTO, l20);
413     mv.visitLabel(l4);
414     mv.visitLineNumber(354, l4);
415     mv.visitVarInsn(ASTORE, 12);
416     Label l26 = new Label();
417     mv.visitLabel(l26);
418     mv.visitLineNumber(355, l26);
419     mv.visitVarInsn(ALOAD, 9);
420     mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/concurrent/locks/ReentrantLock", "unlock", "()V");
421     Label l27 = new Label();
422     mv.visitLabel(l27);
423     mv.visitLineNumber(356, l27);
424     mv.visitVarInsn(ALOAD, 12);
425     mv.visitInsn(ATHROW);
426     mv.visitLabel(l20);
427     mv.visitLineNumber(355, l20);
428     mv.visitVarInsn(ALOAD, 9);
429     mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/concurrent/locks/ReentrantLock", "unlock", "()V");
430     Label l28 = new Label();
431     mv.visitLabel(l28);
432     mv.visitLineNumber(357, l28);
433     mv.visitVarInsn(ILOAD, 7);
434     Label l29 = new Label();
435     mv.visitJumpInsn(IFEQ, l29);
436     mv.visitVarInsn(ILOAD, 8);
437     Label l30 = new Label();
438     mv.visitJumpInsn(IFNE, l30);
439     mv.visitLabel(l29);
440     mv.visitVarInsn(ALOAD, 0);
441     mv.visitMethodInsn(INVOKESPECIAL, "java/util/concurrent/LinkedBlockingQueue", "signalNotEmpty", "()V");
442     mv.visitLabel(l30);
443     mv.visitLineNumber(358, l30);
444     mv.visitInsn(ICONST_1);
445     mv.visitInsn(IRETURN);
446     Label l31 = new Label();
447     mv.visitLabel(l31);
448     mv.visitLocalVariable("this", "Ljava/util/concurrent/LinkedBlockingQueue;", "Ljava/util/concurrent/LinkedBlockingQueue<TE;>;", l5, l31, 0);
449     mv.visitLocalVariable("o", "Ljava/lang/Object;", "TE;", l5, l31, 1);
450     mv.visitLocalVariable("timeout", "J", null, l5, l31, 2);
451     mv.visitLocalVariable("unit", "Ljava/util/concurrent/TimeUnit;", null, l5, l31, 4);
452     mv.visitLocalVariable("nanos", "J", null, l7, l31, 5);
453     mv.visitLocalVariable("c", "I", null, l8, l31, 7);
454     mv.visitLocalVariable("d", "I", null, l9, l31, 8);
455     mv.visitLocalVariable("putLock", "Ljava/util/concurrent/locks/ReentrantLock;", null, l10, l31, 9);
456     mv.visitLocalVariable("count", "Ljava/util/concurrent/atomic/AtomicInteger;", null, l11, l31, 10);
457     mv.visitLocalVariable("ie", "Ljava/lang/InterruptedException;", null, l23, l25, 11);
458     mv.visitMaxs(7, 13);
459     mv.visitEnd();
460   }
461
462   private void recreatePutMethod(MethodVisitor mv) {
463     mv.visitCode();
464     Label l0 = new Label();
465     Label l1 = new Label();
466     mv.visitTryCatchBlock(l0, l1, l1, "java/lang/InterruptedException");
467     Label l2 = new Label();
468     mv.visitTryCatchBlock(l0, l2, l2, null);
469     Label l3 = new Label();
470     mv.visitLabel(l3);
471     mv.visitLineNumber(275, l3);
472     mv.visitVarInsn(ALOAD, 1);
473     Label l4 = new Label();
474     mv.visitJumpInsn(IFNONNULL, l4);
475     mv.visitTypeInsn(NEW, "java/lang/NullPointerException");
476     mv.visitInsn(DUP);
477     mv.visitMethodInsn(INVOKESPECIAL, "java/lang/NullPointerException", "<init>", "()V");
478     mv.visitInsn(ATHROW);
479     mv.visitLabel(l4);
480     mv.visitLineNumber(278, l4);
481     mv.visitInsn(ICONST_M1);
482     mv.visitVarInsn(ISTORE, 2);
483     Label l5 = new Label();
484     mv.visitLabel(l5);
485     mv.visitLineNumber(279, l5);
486     mv.visitInsn(ICONST_M1);
487     mv.visitVarInsn(ISTORE, 3);
488     Label l6 = new Label();
489     mv.visitLabel(l6);
490     mv.visitLineNumber(280, l6);
491     mv.visitVarInsn(ALOAD, 0);
492     mv.visitFieldInsn(GETFIELD, "java/util/concurrent/LinkedBlockingQueue", "putLock", "Ljava/util/concurrent/locks/ReentrantLock;");
493     mv.visitVarInsn(ASTORE, 4);
494     Label l7 = new Label();
495     mv.visitLabel(l7);
496     mv.visitLineNumber(281, l7);
497     mv.visitVarInsn(ALOAD, 0);
498     mv.visitFieldInsn(GETFIELD, "java/util/concurrent/LinkedBlockingQueue", "count", "Ljava/util/concurrent/atomic/AtomicInteger;");
499     mv.visitVarInsn(ASTORE, 5);
500     Label l8 = new Label();
501     mv.visitLabel(l8);
502     mv.visitLineNumber(282, l8);
503     mv.visitVarInsn(ALOAD, 4);
504     mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/concurrent/locks/ReentrantLock", "lockInterruptibly", "()V");
505     mv.visitLabel(l0);
506     mv.visitLineNumber(290, l0);
507     Label l9 = new Label();
508     mv.visitJumpInsn(GOTO, l9);
509     Label l10 = new Label();
510     mv.visitLabel(l10);
511     mv.visitLineNumber(291, l10);
512     mv.visitVarInsn(ALOAD, 0);
513     mv.visitFieldInsn(GETFIELD, "java/util/concurrent/LinkedBlockingQueue", "notFull", "Ljava/util/concurrent/locks/Condition;");
514     mv.visitMethodInsn(INVOKEINTERFACE, "java/util/concurrent/locks/Condition", "await", "()V");
515     mv.visitLabel(l9);
516     mv.visitLineNumber(290, l9);
517     mv.visitVarInsn(ALOAD, 5);
518     mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/concurrent/atomic/AtomicInteger", "get", "()I");
519     mv.visitVarInsn(ALOAD, 0);
520     mv.visitFieldInsn(GETFIELD, "java/util/concurrent/LinkedBlockingQueue", "capacity", "I");
521     mv.visitJumpInsn(IF_ICMPEQ, l10);
522     Label l11 = new Label();
523     mv.visitJumpInsn(GOTO, l11);
524     mv.visitLabel(l1);
525     mv.visitLineNumber(292, l1);
526     mv.visitVarInsn(ASTORE, 6);
527     Label l12 = new Label();
528     mv.visitLabel(l12);
529     mv.visitLineNumber(293, l12);
530     mv.visitVarInsn(ALOAD, 0);
531     mv.visitFieldInsn(GETFIELD, "java/util/concurrent/LinkedBlockingQueue", "notFull", "Ljava/util/concurrent/locks/Condition;");
532     mv.visitMethodInsn(INVOKEINTERFACE, "java/util/concurrent/locks/Condition", "signal", "()V");
533     Label l13 = new Label();
534     mv.visitLabel(l13);
535     mv.visitLineNumber(294, l13);
536     mv.visitVarInsn(ALOAD, 6);
537     mv.visitInsn(ATHROW);
538     mv.visitLabel(l11);
539     mv.visitLineNumber(296, l11);
540     mv.visitVarInsn(ALOAD, 0);
541     mv.visitVarInsn(ALOAD, 1);
542     mv.visitMethodInsn(INVOKESPECIAL, "java/util/concurrent/LinkedBlockingQueue", "insert", "(Ljava/lang/Object;)V");
543     Label l14 = new Label();
544     mv.visitLabel(l14);
545     mv.visitLineNumber(297, l14);
546     mv.visitVarInsn(ALOAD, 0);
547     mv.visitMethodInsn(INVOKESTATIC, "com/tc/object/bytecode/ManagerUtil", "isManaged", "(Ljava/lang/Object;)Z");
548     Label l15 = new Label();
549     mv.visitJumpInsn(IFEQ, l15);
550     Label l16 = new Label();
551     mv.visitLabel(l16);
552     mv.visitLineNumber(298, l16);
553     mv.visitVarInsn(ALOAD, 5);
554     mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/concurrent/atomic/AtomicInteger", "get", "()I");
555     mv.visitVarInsn(ISTORE, 2);
556     Label l17 = new Label();
557     mv.visitLabel(l17);
558     mv.visitLineNumber(299, l17);
559     mv.visitVarInsn(ALOAD, 0);
560     mv.visitVarInsn(ALOAD, 4);
561     mv.visitLdcInsn("put(Ljava/lang/Object;)V");
562     mv.visitInsn(ICONST_1);
563     mv.visitTypeInsn(ANEWARRAY, "java/lang/Object");
564     mv.visitInsn(DUP);
565     mv.visitInsn(ICONST_0);
566     mv.visitVarInsn(ALOAD, 1);
567     mv.visitInsn(AASTORE);
568     mv.visitMethodInsn(INVOKESTATIC, "com/tc/object/bytecode/ManagerUtil", "logicalInvokeWithTransaction", "(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/String;[Ljava/lang/Object;)V");
569     Label l18 = new Label();
570     mv.visitLabel(l18);
571     mv.visitLineNumber(300, l18);
572     mv.visitVarInsn(ALOAD, 5);
573     mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/concurrent/atomic/AtomicInteger", "getAndIncrement", "()I");
574     mv.visitVarInsn(ISTORE, 3);
575     Label l19 = new Label();
576     mv.visitJumpInsn(GOTO, l19);
577     mv.visitLabel(l15);
578     mv.visitLineNumber(302, l15);
579     mv.visitVarInsn(ALOAD, 5);
580     mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/concurrent/atomic/AtomicInteger", "getAndIncrement", "()I");
581     mv.visitVarInsn(ISTORE, 2);
582     mv.visitLabel(l19);
583     mv.visitLineNumber(304, l19);
584     mv.visitVarInsn(ILOAD, 2);
585     mv.visitInsn(ICONST_1);
586     mv.visitInsn(IADD);
587     mv.visitVarInsn(ALOAD, 0);
588     mv.visitFieldInsn(GETFIELD, "java/util/concurrent/LinkedBlockingQueue", "capacity", "I");
589     Label l20 = new Label();
590     mv.visitJumpInsn(IF_ICMPGE, l20);
591     mv.visitVarInsn(ALOAD, 0);
592     mv.visitFieldInsn(GETFIELD, "java/util/concurrent/LinkedBlockingQueue", "notFull", "Ljava/util/concurrent/locks/Condition;");
593     mv.visitMethodInsn(INVOKEINTERFACE, "java/util/concurrent/locks/Condition", "signal", "()V");
594     mv.visitJumpInsn(GOTO, l20);
595     mv.visitLabel(l2);
596     mv.visitLineNumber(305, l2);
597     mv.visitVarInsn(ASTORE, 7);
598     Label l21 = new Label();
599     mv.visitLabel(l21);
600     mv.visitLineNumber(306, l21);
601     mv.visitVarInsn(ALOAD, 4);
602     mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/concurrent/locks/ReentrantLock", "unlock", "()V");
603     Label l22 = new Label();
604     mv.visitLabel(l22);
605     mv.visitLineNumber(307, l22);
606     mv.visitVarInsn(ALOAD, 7);
607     mv.visitInsn(ATHROW);
608     mv.visitLabel(l20);
609     mv.visitLineNumber(306, l20);
610     mv.visitVarInsn(ALOAD, 4);
611     mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/concurrent/locks/ReentrantLock", "unlock", "()V");
612     Label l23 = new Label();
613     mv.visitLabel(l23);
614     mv.visitLineNumber(308, l23);
615     mv.visitVarInsn(ILOAD, 2);
616     Label l24 = new Label();
617     mv.visitJumpInsn(IFEQ, l24);
618     mv.visitVarInsn(ILOAD, 3);
619     Label l25 = new Label();
620     mv.visitJumpInsn(IFNE, l25);
621     mv.visitLabel(l24);
622     mv.visitVarInsn(ALOAD, 0);
623     mv.visitMethodInsn(INVOKESPECIAL, "java/util/concurrent/LinkedBlockingQueue", "signalNotEmpty", "()V");
624     mv.visitLabel(l25);
625     mv.visitLineNumber(309, l25);
626     mv.visitInsn(RETURN);
627     Label l26 = new Label();
628     mv.visitLabel(l26);
629     mv.visitLocalVariable("this", "Ljava/util/concurrent/LinkedBlockingQueue;", "Ljava/util/concurrent/LinkedBlockingQueue<TE;>;", l3, l26, 0);
630     mv.visitLocalVariable("o", "Ljava/lang/Object;", "TE;", l3, l26, 1);
631     mv.visitLocalVariable("c", "I", null, l5, l26, 2);
632     mv.visitLocalVariable("d", "I", null, l6, l26, 3);
633     mv.visitLocalVariable("putLock", "Ljava/util/concurrent/locks/ReentrantLock;", null, l7, l26, 4);
634     mv.visitLocalVariable("count", "Ljava/util/concurrent/atomic/AtomicInteger;", null, l8, l26, 5);
635     mv.visitLocalVariable("ie", "Ljava/lang/InterruptedException;", null, l12, l11, 6);
636     mv.visitMaxs(7, 8);
637     mv.visitEnd();
638   }
639
640   private void recreateOfferMethod(MethodVisitor mv) {
641     mv.visitCode();
642     Label l0 = new Label();
643     Label l1 = new Label();
644     mv.visitTryCatchBlock(l0, l1, l1, null);
645     Label l2 = new Label();
646     mv.visitLabel(l2);
647     mv.visitLineNumber(370, l2);
648     mv.visitVarInsn(ALOAD, 1);
649     Label l3 = new Label();
650     mv.visitJumpInsn(IFNONNULL, l3);
651     mv.visitTypeInsn(NEW, "java/lang/NullPointerException");
652     mv.visitInsn(DUP);
653     mv.visitMethodInsn(INVOKESPECIAL, "java/lang/NullPointerException", "<init>", "()V");
654     mv.visitInsn(ATHROW);
655     mv.visitLabel(l3);
656     mv.visitLineNumber(371, l3);
657     mv.visitVarInsn(ALOAD, 0);
658     mv.visitFieldInsn(GETFIELD, "java/util/concurrent/LinkedBlockingQueue", "count", "Ljava/util/concurrent/atomic/AtomicInteger;");
659     mv.visitVarInsn(ASTORE, 2);
660     Label l4 = new Label();
661     mv.visitLabel(l4);
662     mv.visitLineNumber(372, l4);
663     mv.visitVarInsn(ALOAD, 2);
664     mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/concurrent/atomic/AtomicInteger", "get", "()I");
665     mv.visitVarInsn(ALOAD, 0);
666     mv.visitFieldInsn(GETFIELD, "java/util/concurrent/LinkedBlockingQueue", "capacity", "I");
667     Label l5 = new Label();
668     mv.visitJumpInsn(IF_ICMPNE, l5);
669     mv.visitInsn(ICONST_0);
670     mv.visitInsn(IRETURN);
671     mv.visitLabel(l5);
672     mv.visitLineNumber(373, l5);
673     mv.visitInsn(ICONST_M1);
674     mv.visitVarInsn(ISTORE, 3);
675     Label l6 = new Label();
676     mv.visitLabel(l6);
677     mv.visitLineNumber(374, l6);
678     mv.visitInsn(ICONST_M1);
679     mv.visitVarInsn(ISTORE, 4);
680     Label l7 = new Label();
681     mv.visitLabel(l7);
682     mv.visitLineNumber(375, l7);
683     mv.visitVarInsn(ALOAD, 0);
684     mv.visitFieldInsn(GETFIELD, "java/util/concurrent/LinkedBlockingQueue", "putLock", "Ljava/util/concurrent/locks/ReentrantLock;");
685     mv.visitVarInsn(ASTORE, 5);
686     Label l8 = new Label();
687     mv.visitLabel(l8);
688     mv.visitLineNumber(376, l8);
689     mv.visitVarInsn(ALOAD, 5);
690     mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/concurrent/locks/ReentrantLock", "lock", "()V");
691     mv.visitLabel(l0);
692     mv.visitLineNumber(378, l0);
693     mv.visitVarInsn(ALOAD, 2);
694     mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/concurrent/atomic/AtomicInteger", "get", "()I");
695     mv.visitVarInsn(ALOAD, 0);
696     mv.visitFieldInsn(GETFIELD, "java/util/concurrent/LinkedBlockingQueue", "capacity", "I");
697     Label l9 = new Label();
698     mv.visitJumpInsn(IF_ICMPGE, l9);
699     Label l10 = new Label();
700     mv.visitLabel(l10);
701     mv.visitLineNumber(379, l10);
702     mv.visitVarInsn(ALOAD, 0);
703     mv.visitVarInsn(ALOAD, 1);
704     mv.visitMethodInsn(INVOKESPECIAL, "java/util/concurrent/LinkedBlockingQueue", "insert", "(Ljava/lang/Object;)V");
705     Label l11 = new Label();
706     mv.visitLabel(l11);
707     mv.visitLineNumber(380, l11);
708     mv.visitVarInsn(ALOAD, 0);
709     mv.visitMethodInsn(INVOKESTATIC, "com/tc/object/bytecode/ManagerUtil", "isManaged", "(Ljava/lang/Object;)Z");
710     Label l12 = new Label();
711     mv.visitJumpInsn(IFEQ, l12);
712     Label l13 = new Label();
713     mv.visitLabel(l13);
714     mv.visitLineNumber(381, l13);
715     mv.visitVarInsn(ALOAD, 2);
716     mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/concurrent/atomic/AtomicInteger", "get", "()I");
717     mv.visitVarInsn(ISTORE, 3);
718     Label l14 = new Label();
719     mv.visitLabel(l14);
720     mv.visitLineNumber(382, l14);
721     mv.visitVarInsn(ALOAD, 0);
722     mv.visitVarInsn(ALOAD, 5);
723     mv.visitLdcInsn("put(Ljava/lang/Object;)V");
724     mv.visitInsn(ICONST_1);
725     mv.visitTypeInsn(ANEWARRAY, "java/lang/Object");
726     mv.visitInsn(DUP);
727     mv.visitInsn(ICONST_0);
728     mv.visitVarInsn(ALOAD, 1);
729     mv.visitInsn(AASTORE);
730     mv.visitMethodInsn(INVOKESTATIC, "com/tc/object/bytecode/ManagerUtil", "logicalInvokeWithTransaction", "(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/String;[Ljava/lang/Object;)V");
731     Label l15 = new Label();
732     mv.visitLabel(l15);
733     mv.visitLineNumber(383, l15);
734     mv.visitVarInsn(ALOAD, 2);
735     mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/concurrent/atomic/AtomicInteger", "getAndIncrement", "()I");
736     mv.visitVarInsn(ISTORE, 4);
737     Label l16 = new Label();
738     mv.visitJumpInsn(GOTO, l16);
739     mv.visitLabel(l12);
740     mv.visitLineNumber(385, l12);
741     mv.visitVarInsn(ALOAD, 2);
742     mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/concurrent/atomic/AtomicInteger", "getAndIncrement", "()I");
743     mv.visitVarInsn(ISTORE, 3);
744     mv.visitLabel(l16);
745     mv.visitLineNumber(387, l16);
746     mv.visitVarInsn(ILOAD, 3);
747     mv.visitInsn(ICONST_1);
748     mv.visitInsn(IADD);
749     mv.visitVarInsn(ALOAD, 0);
750     mv.visitFieldInsn(GETFIELD, "java/util/concurrent/LinkedBlockingQueue", "capacity", "I");
751     mv.visitJumpInsn(IF_ICMPGE, l9);
752     mv.visitVarInsn(ALOAD, 0);
753     mv.visitFieldInsn(GETFIELD, "java/util/concurrent/LinkedBlockingQueue", "notFull", "Ljava/util/concurrent/locks/Condition;");
754     mv.visitMethodInsn(INVOKEINTERFACE, "java/util/concurrent/locks/Condition", "signal", "()V");
755     mv.visitJumpInsn(GOTO, l9);
756     mv.visitLabel(l1);
757     mv.visitLineNumber(389, l1);
758     mv.visitVarInsn(ASTORE, 6);
759     Label l17 = new Label();
760     mv.visitLabel(l17);
761     mv.visitLineNumber(390, l17);
762     mv.visitVarInsn(ALOAD, 5);
763     mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/concurrent/locks/ReentrantLock", "unlock", "()V");
764     Label l18 = new Label();
765     mv.visitLabel(l18);
766     mv.visitLineNumber(391, l18);
767     mv.visitVarInsn(ALOAD, 6);
768     mv.visitInsn(ATHROW);
769     mv.visitLabel(l9);
770     mv.visitLineNumber(390, l9);
771     mv.visitVarInsn(ALOAD, 5);
772     mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/concurrent/locks/ReentrantLock", "unlock", "()V");
773     Label l19 = new Label();
774     mv.visitLabel(l19);
775     mv.visitLineNumber(392, l19);
776     mv.visitVarInsn(ILOAD, 3);
777     Label l20 = new Label();
778     mv.visitJumpInsn(IFEQ, l20);
779     mv.visitVarInsn(ILOAD, 4);
780     Label l21 = new Label();
781     mv.visitJumpInsn(IFNE, l21);
782     mv.visitLabel(l20);
783     mv.visitVarInsn(ALOAD, 0);
784     mv.visitMethodInsn(INVOKESPECIAL, "java/util/concurrent/LinkedBlockingQueue", "signalNotEmpty", "()V");
785     mv.visitLabel(l21);
786     mv.visitLineNumber(393, l21);
787     mv.visitVarInsn(ILOAD, 3);
788     Label l22 = new Label();
789     mv.visitJumpInsn(IFLT, l22);
790     mv.visitInsn(ICONST_1);
791     mv.visitInsn(IRETURN);
792     mv.visitLabel(l22);
793     mv.visitInsn(ICONST_0);
794     mv.visitInsn(IRETURN);
795     Label l23 = new Label();
796     mv.visitLabel(l23);
797     mv.visitLocalVariable("this", "Ljava/util/concurrent/LinkedBlockingQueue;", "Ljava/util/concurrent/LinkedBlockingQueue<TE;>;", l2, l23, 0);
798     mv.visitLocalVariable("o", "Ljava/lang/Object;", "TE;", l2, l23, 1);
799     mv.visitLocalVariable("count", "Ljava/util/concurrent/atomic/AtomicInteger;", null, l4, l23, 2);
800     mv.visitLocalVariable("c", "I", null, l6, l23, 3);
801     mv.visitLocalVariable("d", "I", null, l7, l23, 4);
802     mv.visitLocalVariable("putLock", "Ljava/util/concurrent/locks/ReentrantLock;", null, l8, l23, 5);
803     mv.visitMaxs(7, 7);
804     mv.visitEnd();
805   }
806
807   // Rewriting the remove(Object) method of LinkedBlockingQueue with instrumented code.
808
private void recreateRemoveMethod(MethodVisitor mv) {
809     mv.visitCode();
810     Label l0 = new Label();
811     Label l1 = new Label();
812     mv.visitTryCatchBlock(l0, l1, l1, null);
813     Label l2 = new Label();
814     mv.visitLabel(l2);
815     mv.visitInsn(ICONST_0);
816     mv.visitVarInsn(ISTORE, 2);
817     Label l3 = new Label();
818     mv.visitLabel(l3);
819     mv.visitVarInsn(ALOAD, 1);
820     Label l4 = new Label();
821     mv.visitJumpInsn(IFNONNULL, l4);
822     mv.visitInsn(ICONST_0);
823     mv.visitInsn(IRETURN);
824     mv.visitLabel(l4);
825     mv.visitInsn(ICONST_0);
826     mv.visitVarInsn(ISTORE, 3);
827     Label l5 = new Label();
828     mv.visitLabel(l5);
829     mv.visitVarInsn(ALOAD, 0);
830     mv.visitMethodInsn(INVOKESPECIAL, "java/util/concurrent/LinkedBlockingQueue", "fullyLock", "()V");
831     mv.visitLabel(l0);
832     mv.visitVarInsn(ALOAD, 0);
833     mv.visitFieldInsn(GETFIELD, "java/util/concurrent/LinkedBlockingQueue", "head",
834                       "Ljava/util/concurrent/LinkedBlockingQueue$Node;");
835     mv.visitVarInsn(ASTORE, 4);
836     Label l6 = new Label();
837     mv.visitLabel(l6);
838     mv.visitVarInsn(ALOAD, 0);
839     mv.visitFieldInsn(GETFIELD, "java/util/concurrent/LinkedBlockingQueue", "head",
840                       "Ljava/util/concurrent/LinkedBlockingQueue$Node;");
841     mv.visitFieldInsn(GETFIELD, "java/util/concurrent/LinkedBlockingQueue$Node", "next",
842                       "Ljava/util/concurrent/LinkedBlockingQueue$Node;");
843     mv.visitVarInsn(ASTORE, 5);
844     Label l7 = new Label();
845     mv.visitLabel(l7);
846     Label l8 = new Label();
847     mv.visitJumpInsn(GOTO, l8);
848     Label l9 = new Label();
849     mv.visitLabel(l9);
850     mv.visitVarInsn(ALOAD, 1);
851     mv.visitVarInsn(ALOAD, 5);
852     mv.visitFieldInsn(GETFIELD, "java/util/concurrent/LinkedBlockingQueue$Node", "item", "Ljava/lang/Object;");
853     mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object", "equals", "(Ljava/lang/Object;)Z");
854     Label l10 = new Label();
855     mv.visitJumpInsn(IFEQ, l10);
856     Label l11 = new Label();
857     mv.visitLabel(l11);
858     mv.visitInsn(ICONST_1);
859     mv.visitVarInsn(ISTORE, 3);
860     Label l12 = new Label();
861     mv.visitLabel(l12);
862     Label l13 = new Label();
863     mv.visitJumpInsn(GOTO, l13);
864     mv.visitLabel(l10);
865     mv.visitVarInsn(ALOAD, 5);
866     mv.visitVarInsn(ASTORE, 4);
867     Label l14 = new Label();
868     mv.visitLabel(l14);
869     mv.visitVarInsn(ALOAD, 5);
870     mv.visitFieldInsn(GETFIELD, "java/util/concurrent/LinkedBlockingQueue$Node", "next",
871                       "Ljava/util/concurrent/LinkedBlockingQueue$Node;");
872     mv.visitVarInsn(ASTORE, 5);
873     Label l15 = new Label();
874     mv.visitLabel(l15);
875     mv.visitIincInsn(2, 1);
876     mv.visitLabel(l8);
877     mv.visitVarInsn(ALOAD, 5);
878     mv.visitJumpInsn(IFNONNULL, l9);
879     mv.visitLabel(l13);
880     mv.visitVarInsn(ILOAD, 3);
881     Label l16 = new Label();
882     mv.visitJumpInsn(IFEQ, l16);
883     Label l17 = new Label();
884     mv.visitLabel(l17);
885     mv.visitVarInsn(ALOAD, 5);
886     mv.visitInsn(ACONST_NULL);
887     mv.visitFieldInsn(PUTFIELD, "java/util/concurrent/LinkedBlockingQueue$Node", "item", "Ljava/lang/Object;");
888     Label l18 = new Label();
889     mv.visitLabel(l18);
890     mv.visitVarInsn(ALOAD, 4);
891     mv.visitVarInsn(ALOAD, 5);
892     mv.visitFieldInsn(GETFIELD, "java/util/concurrent/LinkedBlockingQueue$Node", "next",
893                       "Ljava/util/concurrent/LinkedBlockingQueue$Node;");
894     mv.visitFieldInsn(PUTFIELD, "java/util/concurrent/LinkedBlockingQueue$Node", "next",
895                       "Ljava/util/concurrent/LinkedBlockingQueue$Node;");
896     Label l19 = new Label();
897     mv.visitLabel(l19);
898     mv.visitVarInsn(ALOAD, 0);
899     mv.visitMethodInsn(INVOKESTATIC, "com/tc/object/bytecode/ManagerUtil", "isManaged", "(Ljava/lang/Object;)Z");
900     Label l20 = new Label();
901     mv.visitJumpInsn(IFEQ, l20);
902     Label l21 = new Label();
903     mv.visitLabel(l21);
904     mv.visitVarInsn(ALOAD, 0);
905     mv.visitLdcInsn(SerializationUtil.REMOVE_AT_SIGNATURE);
906     mv.visitInsn(ICONST_1);
907     mv.visitTypeInsn(ANEWARRAY, "java/lang/Object");
908     mv.visitInsn(DUP);
909     mv.visitInsn(ICONST_0);
910     mv.visitTypeInsn(NEW, "java/lang/Integer");
911     mv.visitInsn(DUP);
912     mv.visitVarInsn(ILOAD, 2);
913     mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Integer", "<init>", "(I)V");
914     mv.visitInsn(AASTORE);
915     mv.visitMethodInsn(INVOKESTATIC, "com/tc/object/bytecode/ManagerUtil", "logicalInvoke",
916                        "(Ljava/lang/Object;Ljava/lang/String;[Ljava/lang/Object;)V");
917     mv.visitLabel(l20);
918     mv.visitVarInsn(ALOAD, 0);
919     mv.visitFieldInsn(GETFIELD, "java/util/concurrent/LinkedBlockingQueue", "last",
920                       "Ljava/util/concurrent/LinkedBlockingQueue$Node;");
921     mv.visitVarInsn(ALOAD, 5);
922     Label l22 = new Label();
923     mv.visitJumpInsn(IF_ACMPNE, l22);
924     mv.visitVarInsn(ALOAD, 0);
925     mv.visitVarInsn(ALOAD, 4);
926     mv.visitFieldInsn(PUTFIELD, "java/util/concurrent/LinkedBlockingQueue", "last",
927                       "Ljava/util/concurrent/LinkedBlockingQueue$Node;");
928     mv.visitLabel(l22);
929     mv.visitVarInsn(ALOAD, 0);
930     mv.visitFieldInsn(GETFIELD, "java/util/concurrent/LinkedBlockingQueue", "count",
931                       "Ljava/util/concurrent/atomic/AtomicInteger;");
932     mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/concurrent/atomic/AtomicInteger", "getAndDecrement", "()I");
933     mv.visitVarInsn(ALOAD, 0);
934     mv.visitFieldInsn(GETFIELD, "java/util/concurrent/LinkedBlockingQueue", "capacity", "I");
935     mv.visitJumpInsn(IF_ICMPNE, l16);
936     mv.visitVarInsn(ALOAD, 0);
937     mv.visitFieldInsn(GETFIELD, "java/util/concurrent/LinkedBlockingQueue", "notFull",
938                       "Ljava/util/concurrent/locks/Condition;");
939     mv.visitMethodInsn(INVOKEINTERFACE, "java/util/concurrent/locks/Condition", "signalAll", "()V");
940     mv.visitJumpInsn(GOTO, l16);
941     mv.visitLabel(l1);
942     mv.visitVarInsn(ASTORE, 6);
943     Label l23 = new Label();
944     mv.visitLabel(l23);
945     mv.visitVarInsn(ALOAD, 0);
946     mv.visitMethodInsn(INVOKESPECIAL, "java/util/concurrent/LinkedBlockingQueue", "fullyUnlock", "()V");
947     Label l24 = new Label();
948     mv.visitLabel(l24);
949     mv.visitVarInsn(ALOAD, 6);
950     mv.visitInsn(ATHROW);
951     mv.visitLabel(l16);
952     mv.visitVarInsn(ALOAD, 0);
953     mv.visitMethodInsn(INVOKESPECIAL, "java/util/concurrent/LinkedBlockingQueue", "fullyUnlock", "()V");
954     Label l25 = new Label();
955     mv.visitLabel(l25);
956     mv.visitVarInsn(ILOAD, 3);
957     mv.visitInsn(IRETURN);
958     Label l26 = new Label();
959     mv.visitLabel(l26);
960     mv.visitMaxs(0, 0);
961     mv.visitEnd();
962   }
963
964   private void addInitMethodCode() {
965     MethodVisitor mv = super.visitMethod(ACC_PRIVATE + ACC_SYNTHETIC, "init", "()V", null, null);
966     mv.visitCode();
967     ByteCodeUtil.pushThis(mv);
968     ByteCodeUtil.pushThis(mv);
969     mv.visitFieldInsn(GETFIELD, "java/util/concurrent/LinkedBlockingQueue", "takeLock",
970                       "Ljava/util/concurrent/locks/ReentrantLock;");
971     mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/concurrent/locks/ReentrantLock", "newCondition",
972                        "()Ljava/util/concurrent/locks/Condition;");
973     mv.visitFieldInsn(PUTFIELD, "java/util/concurrent/LinkedBlockingQueue", "notEmpty",
974                       "Ljava/util/concurrent/locks/Condition;");
975     ByteCodeUtil.pushThis(mv);
976     ByteCodeUtil.pushThis(mv);
977     mv.visitFieldInsn(GETFIELD, "java/util/concurrent/LinkedBlockingQueue", "putLock",
978                       "Ljava/util/concurrent/locks/ReentrantLock;");
979     mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/concurrent/locks/ReentrantLock", "newCondition",
980                        "()Ljava/util/concurrent/locks/Condition;");
981     mv.visitFieldInsn(PUTFIELD, "java/util/concurrent/LinkedBlockingQueue", "notFull",
982                       "Ljava/util/concurrent/locks/Condition;");
983     mv.visitInsn(RETURN);
984     mv.visitMaxs(0, 0);
985     mv.visitEnd();
986   }
987   
988   private void addTCExtractMethod() {
989     MethodVisitor mv = cv.visitMethod(ACC_PRIVATE, TC_EXTRACT_METHOD_NAME, TC_EXTRACT_METHOD_DESC, "()TE;", null);
990     mv.visitCode();
991     Label l0 = new Label();
992     mv.visitLabel(l0);
993     mv.visitLineNumber(144, l0);
994     mv.visitVarInsn(ALOAD, 0);
995     mv.visitFieldInsn(GETFIELD, "java/util/concurrent/LinkedBlockingQueue", "head", "Ljava/util/concurrent/LinkedBlockingQueue$Node;");
996     mv.visitFieldInsn(GETFIELD, "java/util/concurrent/LinkedBlockingQueue$Node", "next", "Ljava/util/concurrent/LinkedBlockingQueue$Node;");
997     mv.visitVarInsn(ASTORE, 1);
998     Label l1 = new Label();
999     mv.visitLabel(l1);
1000    mv.visitLineNumber(145, l1);
1001    mv.visitVarInsn(ALOAD, 0);
1002    mv.visitVarInsn(ALOAD, 1);
1003    mv.visitFieldInsn(PUTFIELD, "java/util/concurrent/LinkedBlockingQueue", "head", "Ljava/util/concurrent/LinkedBlockingQueue$Node;");
1004    Label l2 = new Label();
1005    mv.visitLabel(l2);
1006    mv.visitLineNumber(146, l2);
1007    mv.visitVarInsn(ALOAD, 1);
1008    mv.visitFieldInsn(GETFIELD, "java/util/concurrent/LinkedBlockingQueue$Node", "item", "Ljava/lang/Object;");
1009    mv.visitVarInsn(ASTORE, 2);
1010    Label l3 = new Label();
1011    mv.visitLabel(l3);
1012    mv.visitLineNumber(147, l3);
1013    mv.visitVarInsn(ALOAD, 1);
1014    mv.visitInsn(ACONST_NULL);
1015    mv.visitFieldInsn(PUTFIELD, "java/util/concurrent/LinkedBlockingQueue$Node", "item", "Ljava/lang/Object;");
1016    Label l4 = new Label();
1017    mv.visitLabel(l4);
1018    mv.visitLineNumber(148, l4);
1019    mv.visitVarInsn(ALOAD, 2);
1020    mv.visitInsn(ARETURN);
1021    Label l5 = new Label();
1022    mv.visitLabel(l5);
1023    mv.visitLocalVariable("this", "Ljava/util/concurrent/LinkedBlockingQueue;", "Ljava/util/concurrent/LinkedBlockingQueue<TE;>;", l0, l5, 0);
1024    mv.visitLocalVariable("first", "Ljava/util/concurrent/LinkedBlockingQueue$Node;", "Ljava/util/concurrent/LinkedBlockingQueue$Node<TE;>;", l1, l5, 1);
1025    mv.visitLocalVariable("x", "Ljava/lang/Object;", "TE;", l3, l5, 2);
1026    mv.visitMaxs(2, 3);
1027    mv.visitEnd();
1028  }
1029
1030  static class NodeMethodAdapter extends MethodAdapter implements Opcodes {
1031    public NodeMethodAdapter(MethodVisitor mv) {
1032      super(mv);
1033    }
1034
1035    public void visitFieldInsn(int opcode, String JavaDoc owner, String JavaDoc name, String JavaDoc desc) {
1036      if (GETFIELD == opcode && "java/util/concurrent/LinkedBlockingQueue$Node".equals(owner) && "item".equals(name)
1037          && "Ljava/lang/Object;".equals(desc)) {
1038        mv.visitMethodInsn(INVOKEVIRTUAL, owner, GET_ITEM_METHOD_NAME, GET_ITEM_METHOD_DESC);
1039      } else {
1040        super.visitFieldInsn(opcode, owner, name, desc);
1041      }
1042    }
1043  }
1044}
1045
Popular Tags