0001: /*
0002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
0003: */
0004: package com.tc.object.bytecode;
0005:
0006: import com.tc.asm.ClassAdapter;
0007: import com.tc.asm.MethodAdapter;
0008: import com.tc.asm.ClassVisitor;
0009: import com.tc.asm.Label;
0010: import com.tc.asm.MethodVisitor;
0011: import com.tc.asm.Opcodes;
0012: import com.tc.object.SerializationUtil;
0013:
0014: public class JavaUtilConcurrentLinkedBlockingQueueClassAdapter extends
0015: ClassAdapter implements Opcodes {
0016: private static final String TC_TAKE_METHOD_NAME = ByteCodeUtil.TC_METHOD_PREFIX
0017: + "take";
0018: private static final String TC_PUT_METHOD_NAME = ByteCodeUtil.TC_METHOD_PREFIX
0019: + "put";
0020: private static final String TC_EXTRACT_METHOD_NAME = ByteCodeUtil.TC_METHOD_PREFIX
0021: + "extract";
0022: private static final String TC_EXTRACT_METHOD_DESC = "()Ljava/lang/Object;";
0023:
0024: private static final String GET_ITEM_METHOD_NAME = "getItem";
0025: private static final String GET_ITEM_METHOD_DESC = "()Ljava/lang/Object;";
0026:
0027: public JavaUtilConcurrentLinkedBlockingQueueClassAdapter(
0028: ClassVisitor cv) {
0029: super (cv);
0030: }
0031:
0032: public void visitEnd() {
0033: addTCExtractMethod();
0034: addTCTakeMethod();
0035: addTCPutMethod();
0036: addInitMethodCode();
0037: super .visitEnd();
0038: }
0039:
0040: public MethodVisitor visitMethod(int access, String name,
0041: String desc, String signature, String[] exceptions) {
0042: MethodVisitor mv = super .visitMethod(access, name, desc,
0043: signature, exceptions);
0044: // Recreating these 4 methods because the instrumented code is very ad hoc.
0045: mv = new NodeMethodAdapter(mv);
0046: if ("remove".equals(name)
0047: && "(Ljava/lang/Object;)Z".equals(desc)) {
0048: recreateRemoveMethod(mv);
0049: return null;
0050: } else if ("offer".equals(name)
0051: && "(Ljava/lang/Object;)Z".equals(desc)) {
0052: recreateOfferMethod(mv);
0053: return null;
0054: } else if ("offer".equals(name)
0055: && "(Ljava/lang/Object;JLjava/util/concurrent/TimeUnit;)Z"
0056: .equals(desc)) {
0057: recreateOfferTimeoutMethod(mv);
0058: return null;
0059: } else if ("put".equals(name)
0060: && "(Ljava/lang/Object;)V".equals(desc)) {
0061: recreatePutMethod(mv);
0062: return null;
0063: }
0064:
0065: return mv;
0066: }
0067:
0068: /*
0069: * The __tc_put() is a non-blocking version of put() and is called in the applicator only.
0070: * We allow it to go over the capacity of the LinkedBlockingQueue but the capacity should
0071: * eventually goes down by take() method in the application thread.
0072: */
0073: private void addTCPutMethod() {
0074: MethodVisitor mv = super .visitMethod(ACC_PUBLIC,
0075: TC_PUT_METHOD_NAME, "(Ljava/lang/Object;)V", null,
0076: new String[] { "java/lang/InterruptedException" });
0077: mv.visitCode();
0078: Label l0 = new Label();
0079: Label l1 = new Label();
0080: mv.visitTryCatchBlock(l0, l1, l1, null);
0081: Label l2 = new Label();
0082: Label l3 = new Label();
0083: mv.visitTryCatchBlock(l2, l3, l1, null);
0084: Label l4 = new Label();
0085: mv.visitLabel(l4);
0086: mv.visitVarInsn(ALOAD, 1);
0087: Label l5 = new Label();
0088: mv.visitJumpInsn(IFNONNULL, l5);
0089: mv.visitTypeInsn(NEW, "java/lang/NullPointerException");
0090: mv.visitInsn(DUP);
0091: mv.visitMethodInsn(INVOKESPECIAL,
0092: "java/lang/NullPointerException", "<init>", "()V");
0093: mv.visitInsn(ATHROW);
0094: mv.visitLabel(l5);
0095: mv.visitInsn(ICONST_M1);
0096: mv.visitVarInsn(ISTORE, 2);
0097: Label l6 = new Label();
0098: mv.visitLabel(l6);
0099: mv.visitVarInsn(ALOAD, 0);
0100: mv.visitFieldInsn(GETFIELD,
0101: "java/util/concurrent/LinkedBlockingQueue", "putLock",
0102: "Ljava/util/concurrent/locks/ReentrantLock;");
0103: mv.visitVarInsn(ASTORE, 3);
0104: Label l7 = new Label();
0105: mv.visitLabel(l7);
0106: mv.visitVarInsn(ALOAD, 0);
0107: mv.visitFieldInsn(GETFIELD,
0108: "java/util/concurrent/LinkedBlockingQueue", "count",
0109: "Ljava/util/concurrent/atomic/AtomicInteger;");
0110: mv.visitVarInsn(ASTORE, 4);
0111: Label l8 = new Label();
0112: mv.visitLabel(l8);
0113: mv.visitVarInsn(ALOAD, 3);
0114: mv.visitMethodInsn(INVOKEVIRTUAL,
0115: "java/util/concurrent/locks/ReentrantLock",
0116: "lockInterruptibly", "()V");
0117: mv.visitLabel(l0);
0118: mv.visitVarInsn(ALOAD, 0);
0119: mv.visitVarInsn(ALOAD, 1);
0120: mv.visitMethodInsn(INVOKESPECIAL,
0121: "java/util/concurrent/LinkedBlockingQueue", "insert",
0122: "(Ljava/lang/Object;)V");
0123: Label l9 = new Label();
0124: mv.visitLabel(l9);
0125: mv.visitVarInsn(ALOAD, 4);
0126: mv.visitMethodInsn(INVOKEVIRTUAL,
0127: "java/util/concurrent/atomic/AtomicInteger",
0128: "getAndIncrement", "()I");
0129: mv.visitVarInsn(ISTORE, 2);
0130: Label l10 = new Label();
0131: mv.visitLabel(l10);
0132: mv.visitVarInsn(ILOAD, 2);
0133: mv.visitInsn(ICONST_1);
0134: mv.visitInsn(IADD);
0135: mv.visitVarInsn(ALOAD, 0);
0136: mv.visitFieldInsn(GETFIELD,
0137: "java/util/concurrent/LinkedBlockingQueue", "capacity",
0138: "I");
0139: mv.visitJumpInsn(IF_ICMPGE, l2);
0140: mv.visitVarInsn(ALOAD, 0);
0141: mv.visitFieldInsn(GETFIELD,
0142: "java/util/concurrent/LinkedBlockingQueue", "notFull",
0143: "Ljava/util/concurrent/locks/Condition;");
0144: mv
0145: .visitMethodInsn(INVOKEINTERFACE,
0146: "java/util/concurrent/locks/Condition",
0147: "signal", "()V");
0148: mv.visitJumpInsn(GOTO, l2);
0149: mv.visitLabel(l1);
0150: mv.visitVarInsn(ASTORE, 6);
0151: Label l11 = new Label();
0152: mv.visitJumpInsn(JSR, l11);
0153: Label l12 = new Label();
0154: mv.visitLabel(l12);
0155: mv.visitVarInsn(ALOAD, 6);
0156: mv.visitInsn(ATHROW);
0157: mv.visitLabel(l11);
0158: mv.visitVarInsn(ASTORE, 5);
0159: Label l13 = new Label();
0160: mv.visitLabel(l13);
0161: mv.visitVarInsn(ALOAD, 3);
0162: mv.visitMethodInsn(INVOKEVIRTUAL,
0163: "java/util/concurrent/locks/ReentrantLock", "unlock",
0164: "()V");
0165: Label l14 = new Label();
0166: mv.visitLabel(l14);
0167: mv.visitVarInsn(RET, 5);
0168: mv.visitLabel(l2);
0169: mv.visitJumpInsn(JSR, l11);
0170: mv.visitLabel(l3);
0171: mv.visitVarInsn(ILOAD, 2);
0172: Label l15 = new Label();
0173: mv.visitJumpInsn(IFNE, l15);
0174: mv.visitVarInsn(ALOAD, 0);
0175: mv.visitMethodInsn(INVOKESPECIAL,
0176: "java/util/concurrent/LinkedBlockingQueue",
0177: "signalNotEmpty", "()V");
0178: mv.visitLabel(l15);
0179: mv.visitInsn(RETURN);
0180: Label l16 = new Label();
0181: mv.visitLabel(l16);
0182: mv.visitMaxs(0, 0);
0183: mv.visitEnd();
0184: }
0185:
0186: /**
0187: * The __tc_take() method is the non-blocking version of take and is used by the applicator
0188: * only. We allow the capacity to fall below 0, but the capacity should eventually goes up
0189: * by the put() method in the application thread.
0190: */
0191: private void addTCTakeMethod() {
0192: MethodVisitor mv = super .visitMethod(ACC_PUBLIC,
0193: TC_TAKE_METHOD_NAME, "()Ljava/lang/Object;", null,
0194: new String[] { "java/lang/InterruptedException" });
0195: mv.visitCode();
0196: Label l0 = new Label();
0197: Label l1 = new Label();
0198: mv.visitTryCatchBlock(l0, l1, l1, null);
0199: Label l2 = new Label();
0200: Label l3 = new Label();
0201: mv.visitTryCatchBlock(l2, l3, l1, null);
0202: Label l4 = new Label();
0203: mv.visitLabel(l4);
0204: mv.visitInsn(ICONST_M1);
0205: mv.visitVarInsn(ISTORE, 2);
0206: Label l5 = new Label();
0207: mv.visitLabel(l5);
0208: mv.visitVarInsn(ALOAD, 0);
0209: mv.visitFieldInsn(GETFIELD,
0210: "java/util/concurrent/LinkedBlockingQueue", "count",
0211: "Ljava/util/concurrent/atomic/AtomicInteger;");
0212: mv.visitVarInsn(ASTORE, 3);
0213: Label l6 = new Label();
0214: mv.visitLabel(l6);
0215: mv.visitVarInsn(ALOAD, 0);
0216: mv.visitFieldInsn(GETFIELD,
0217: "java/util/concurrent/LinkedBlockingQueue", "takeLock",
0218: "Ljava/util/concurrent/locks/ReentrantLock;");
0219: mv.visitVarInsn(ASTORE, 4);
0220: Label l7 = new Label();
0221: mv.visitLabel(l7);
0222: mv.visitVarInsn(ALOAD, 4);
0223: mv.visitMethodInsn(INVOKEVIRTUAL,
0224: "java/util/concurrent/locks/ReentrantLock",
0225: "lockInterruptibly", "()V");
0226: mv.visitLabel(l0);
0227: mv.visitVarInsn(ALOAD, 0);
0228: mv.visitFieldInsn(GETFIELD,
0229: "java/util/concurrent/LinkedBlockingQueue", "head",
0230: "Ljava/util/concurrent/LinkedBlockingQueue$Node;");
0231: mv.visitVarInsn(ALOAD, 0);
0232: mv.visitFieldInsn(GETFIELD,
0233: "java/util/concurrent/LinkedBlockingQueue", "last",
0234: "Ljava/util/concurrent/LinkedBlockingQueue$Node;");
0235: Label l8 = new Label();
0236: mv.visitJumpInsn(IF_ACMPNE, l8);
0237: Label l9 = new Label();
0238: mv.visitLabel(l9);
0239: mv.visitTypeInsn(NEW, "com/tc/exception/TCRuntimeException");
0240: mv.visitInsn(DUP);
0241: mv.visitLdcInsn(TC_TAKE_METHOD_NAME
0242: + ": Trying to do a take from an empty queue.");
0243: mv.visitMethodInsn(INVOKESPECIAL,
0244: "com/tc/exception/TCRuntimeException", "<init>",
0245: "(Ljava/lang/String;)V");
0246: mv.visitInsn(ATHROW);
0247: mv.visitLabel(l8);
0248: mv.visitVarInsn(ALOAD, 0);
0249: mv.visitMethodInsn(INVOKESPECIAL,
0250: "java/util/concurrent/LinkedBlockingQueue",
0251: TC_EXTRACT_METHOD_NAME, TC_EXTRACT_METHOD_DESC);
0252: mv.visitVarInsn(ASTORE, 1);
0253: Label l10 = new Label();
0254: mv.visitLabel(l10);
0255: mv.visitVarInsn(ALOAD, 3);
0256: mv.visitMethodInsn(INVOKEVIRTUAL,
0257: "java/util/concurrent/atomic/AtomicInteger",
0258: "getAndDecrement", "()I");
0259: mv.visitVarInsn(ISTORE, 2);
0260: mv.visitJumpInsn(GOTO, l2);
0261: mv.visitLabel(l1);
0262: mv.visitVarInsn(ASTORE, 6);
0263: Label l11 = new Label();
0264: mv.visitJumpInsn(JSR, l11);
0265: Label l12 = new Label();
0266: mv.visitLabel(l12);
0267: mv.visitVarInsn(ALOAD, 6);
0268: mv.visitInsn(ATHROW);
0269: mv.visitLabel(l11);
0270: mv.visitVarInsn(ASTORE, 5);
0271: Label l13 = new Label();
0272: mv.visitLabel(l13);
0273: mv.visitVarInsn(ALOAD, 4);
0274: mv.visitMethodInsn(INVOKEVIRTUAL,
0275: "java/util/concurrent/locks/ReentrantLock", "unlock",
0276: "()V");
0277: Label l14 = new Label();
0278: mv.visitLabel(l14);
0279: mv.visitVarInsn(RET, 5);
0280: mv.visitLabel(l2);
0281: mv.visitJumpInsn(JSR, l11);
0282: mv.visitLabel(l3);
0283: mv.visitVarInsn(ILOAD, 2);
0284: mv.visitVarInsn(ALOAD, 0);
0285: mv.visitFieldInsn(GETFIELD,
0286: "java/util/concurrent/LinkedBlockingQueue", "capacity",
0287: "I");
0288: Label l15 = new Label();
0289: mv.visitJumpInsn(IF_ICMPNE, l15);
0290: mv.visitVarInsn(ALOAD, 0);
0291: mv.visitMethodInsn(INVOKESPECIAL,
0292: "java/util/concurrent/LinkedBlockingQueue",
0293: "signalNotFull", "()V");
0294: mv.visitLabel(l15);
0295: mv.visitVarInsn(ALOAD, 1);
0296: mv.visitInsn(ARETURN);
0297: Label l16 = new Label();
0298: mv.visitLabel(l16);
0299: mv.visitMaxs(0, 0);
0300: mv.visitEnd();
0301: }
0302:
0303: private MethodVisitor recreateOfferTimeoutMethod(MethodVisitor mv) {
0304: mv.visitCode();
0305: Label l0 = new Label();
0306: Label l1 = new Label();
0307: mv.visitTryCatchBlock(l0, l1, l1,
0308: "java/lang/InterruptedException");
0309: Label l2 = new Label();
0310: Label l3 = new Label();
0311: Label l4 = new Label();
0312: mv.visitTryCatchBlock(l2, l3, l4, null);
0313: mv.visitTryCatchBlock(l0, l4, l4, null);
0314: Label l5 = new Label();
0315: mv.visitLabel(l5);
0316: mv.visitLineNumber(325, l5);
0317: mv.visitVarInsn(ALOAD, 1);
0318: Label l6 = new Label();
0319: mv.visitJumpInsn(IFNONNULL, l6);
0320: mv.visitTypeInsn(NEW, "java/lang/NullPointerException");
0321: mv.visitInsn(DUP);
0322: mv.visitMethodInsn(INVOKESPECIAL,
0323: "java/lang/NullPointerException", "<init>", "()V");
0324: mv.visitInsn(ATHROW);
0325: mv.visitLabel(l6);
0326: mv.visitLineNumber(326, l6);
0327: mv.visitVarInsn(ALOAD, 4);
0328: mv.visitVarInsn(LLOAD, 2);
0329: mv.visitMethodInsn(INVOKEVIRTUAL,
0330: "java/util/concurrent/TimeUnit", "toNanos", "(J)J");
0331: mv.visitVarInsn(LSTORE, 5);
0332: Label l7 = new Label();
0333: mv.visitLabel(l7);
0334: mv.visitLineNumber(327, l7);
0335: mv.visitInsn(ICONST_M1);
0336: mv.visitVarInsn(ISTORE, 7);
0337: Label l8 = new Label();
0338: mv.visitLabel(l8);
0339: mv.visitLineNumber(328, l8);
0340: mv.visitInsn(ICONST_M1);
0341: mv.visitVarInsn(ISTORE, 8);
0342: Label l9 = new Label();
0343: mv.visitLabel(l9);
0344: mv.visitLineNumber(329, l9);
0345: mv.visitVarInsn(ALOAD, 0);
0346: mv.visitFieldInsn(GETFIELD,
0347: "java/util/concurrent/LinkedBlockingQueue", "putLock",
0348: "Ljava/util/concurrent/locks/ReentrantLock;");
0349: mv.visitVarInsn(ASTORE, 9);
0350: Label l10 = new Label();
0351: mv.visitLabel(l10);
0352: mv.visitLineNumber(330, l10);
0353: mv.visitVarInsn(ALOAD, 0);
0354: mv.visitFieldInsn(GETFIELD,
0355: "java/util/concurrent/LinkedBlockingQueue", "count",
0356: "Ljava/util/concurrent/atomic/AtomicInteger;");
0357: mv.visitVarInsn(ASTORE, 10);
0358: Label l11 = new Label();
0359: mv.visitLabel(l11);
0360: mv.visitLineNumber(331, l11);
0361: mv.visitVarInsn(ALOAD, 9);
0362: mv.visitMethodInsn(INVOKEVIRTUAL,
0363: "java/util/concurrent/locks/ReentrantLock",
0364: "lockInterruptibly", "()V");
0365: mv.visitLabel(l2);
0366: mv.visitLineNumber(334, l2);
0367: mv.visitVarInsn(ALOAD, 10);
0368: mv.visitMethodInsn(INVOKEVIRTUAL,
0369: "java/util/concurrent/atomic/AtomicInteger", "get",
0370: "()I");
0371: mv.visitVarInsn(ALOAD, 0);
0372: mv.visitFieldInsn(GETFIELD,
0373: "java/util/concurrent/LinkedBlockingQueue", "capacity",
0374: "I");
0375: Label l12 = new Label();
0376: mv.visitJumpInsn(IF_ICMPGE, l12);
0377: Label l13 = new Label();
0378: mv.visitLabel(l13);
0379: mv.visitLineNumber(335, l13);
0380: mv.visitVarInsn(ALOAD, 0);
0381: mv.visitVarInsn(ALOAD, 1);
0382: mv.visitMethodInsn(INVOKESPECIAL,
0383: "java/util/concurrent/LinkedBlockingQueue", "insert",
0384: "(Ljava/lang/Object;)V");
0385: Label l14 = new Label();
0386: mv.visitLabel(l14);
0387: mv.visitLineNumber(336, l14);
0388: mv.visitVarInsn(ALOAD, 0);
0389: mv.visitMethodInsn(INVOKESTATIC,
0390: "com/tc/object/bytecode/ManagerUtil", "isManaged",
0391: "(Ljava/lang/Object;)Z");
0392: Label l15 = new Label();
0393: mv.visitJumpInsn(IFEQ, l15);
0394: Label l16 = new Label();
0395: mv.visitLabel(l16);
0396: mv.visitLineNumber(337, l16);
0397: mv.visitVarInsn(ALOAD, 10);
0398: mv.visitMethodInsn(INVOKEVIRTUAL,
0399: "java/util/concurrent/atomic/AtomicInteger", "get",
0400: "()I");
0401: mv.visitVarInsn(ISTORE, 7);
0402: Label l17 = new Label();
0403: mv.visitLabel(l17);
0404: mv.visitLineNumber(338, l17);
0405: mv.visitVarInsn(ALOAD, 0);
0406: mv.visitVarInsn(ALOAD, 9);
0407: mv.visitLdcInsn("put(Ljava/lang/Object;)V");
0408: mv.visitInsn(ICONST_1);
0409: mv.visitTypeInsn(ANEWARRAY, "java/lang/Object");
0410: mv.visitInsn(DUP);
0411: mv.visitInsn(ICONST_0);
0412: mv.visitVarInsn(ALOAD, 1);
0413: mv.visitInsn(AASTORE);
0414: mv
0415: .visitMethodInsn(INVOKESTATIC,
0416: "com/tc/object/bytecode/ManagerUtil",
0417: "logicalInvokeWithTransaction",
0418: "(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/String;[Ljava/lang/Object;)V");
0419: Label l18 = new Label();
0420: mv.visitLabel(l18);
0421: mv.visitLineNumber(339, l18);
0422: mv.visitVarInsn(ALOAD, 10);
0423: mv.visitMethodInsn(INVOKEVIRTUAL,
0424: "java/util/concurrent/atomic/AtomicInteger",
0425: "getAndIncrement", "()I");
0426: mv.visitVarInsn(ISTORE, 8);
0427: Label l19 = new Label();
0428: mv.visitJumpInsn(GOTO, l19);
0429: mv.visitLabel(l15);
0430: mv.visitLineNumber(341, l15);
0431: mv.visitVarInsn(ALOAD, 10);
0432: mv.visitMethodInsn(INVOKEVIRTUAL,
0433: "java/util/concurrent/atomic/AtomicInteger",
0434: "getAndIncrement", "()I");
0435: mv.visitVarInsn(ISTORE, 7);
0436: mv.visitLabel(l19);
0437: mv.visitLineNumber(343, l19);
0438: mv.visitVarInsn(ILOAD, 7);
0439: mv.visitInsn(ICONST_1);
0440: mv.visitInsn(IADD);
0441: mv.visitVarInsn(ALOAD, 0);
0442: mv.visitFieldInsn(GETFIELD,
0443: "java/util/concurrent/LinkedBlockingQueue", "capacity",
0444: "I");
0445: Label l20 = new Label();
0446: mv.visitJumpInsn(IF_ICMPGE, l20);
0447: mv.visitVarInsn(ALOAD, 0);
0448: mv.visitFieldInsn(GETFIELD,
0449: "java/util/concurrent/LinkedBlockingQueue", "notFull",
0450: "Ljava/util/concurrent/locks/Condition;");
0451: mv
0452: .visitMethodInsn(INVOKEINTERFACE,
0453: "java/util/concurrent/locks/Condition",
0454: "signal", "()V");
0455: Label l21 = new Label();
0456: mv.visitLabel(l21);
0457: mv.visitLineNumber(344, l21);
0458: mv.visitJumpInsn(GOTO, l20);
0459: mv.visitLabel(l12);
0460: mv.visitLineNumber(346, l12);
0461: mv.visitVarInsn(LLOAD, 5);
0462: mv.visitInsn(LCONST_0);
0463: mv.visitInsn(LCMP);
0464: mv.visitJumpInsn(IFGT, l0);
0465: mv.visitLabel(l3);
0466: mv.visitLineNumber(355, l3);
0467: mv.visitVarInsn(ALOAD, 9);
0468: mv.visitMethodInsn(INVOKEVIRTUAL,
0469: "java/util/concurrent/locks/ReentrantLock", "unlock",
0470: "()V");
0471: Label l22 = new Label();
0472: mv.visitLabel(l22);
0473: mv.visitLineNumber(346, l22);
0474: mv.visitInsn(ICONST_0);
0475: mv.visitInsn(IRETURN);
0476: mv.visitLabel(l0);
0477: mv.visitLineNumber(348, l0);
0478: mv.visitVarInsn(ALOAD, 0);
0479: mv.visitFieldInsn(GETFIELD,
0480: "java/util/concurrent/LinkedBlockingQueue", "notFull",
0481: "Ljava/util/concurrent/locks/Condition;");
0482: mv.visitVarInsn(LLOAD, 5);
0483: mv.visitMethodInsn(INVOKEINTERFACE,
0484: "java/util/concurrent/locks/Condition", "awaitNanos",
0485: "(J)J");
0486: mv.visitVarInsn(LSTORE, 5);
0487: mv.visitJumpInsn(GOTO, l2);
0488: mv.visitLabel(l1);
0489: mv.visitLineNumber(349, l1);
0490: mv.visitVarInsn(ASTORE, 11);
0491: Label l23 = new Label();
0492: mv.visitLabel(l23);
0493: mv.visitLineNumber(350, l23);
0494: mv.visitVarInsn(ALOAD, 0);
0495: mv.visitFieldInsn(GETFIELD,
0496: "java/util/concurrent/LinkedBlockingQueue", "notFull",
0497: "Ljava/util/concurrent/locks/Condition;");
0498: mv
0499: .visitMethodInsn(INVOKEINTERFACE,
0500: "java/util/concurrent/locks/Condition",
0501: "signal", "()V");
0502: Label l24 = new Label();
0503: mv.visitLabel(l24);
0504: mv.visitLineNumber(351, l24);
0505: mv.visitVarInsn(ALOAD, 11);
0506: mv.visitInsn(ATHROW);
0507: Label l25 = new Label();
0508: mv.visitLabel(l25);
0509: mv.visitLineNumber(333, l25);
0510: mv.visitJumpInsn(GOTO, l2);
0511: mv.visitJumpInsn(GOTO, l20);
0512: mv.visitLabel(l4);
0513: mv.visitLineNumber(354, l4);
0514: mv.visitVarInsn(ASTORE, 12);
0515: Label l26 = new Label();
0516: mv.visitLabel(l26);
0517: mv.visitLineNumber(355, l26);
0518: mv.visitVarInsn(ALOAD, 9);
0519: mv.visitMethodInsn(INVOKEVIRTUAL,
0520: "java/util/concurrent/locks/ReentrantLock", "unlock",
0521: "()V");
0522: Label l27 = new Label();
0523: mv.visitLabel(l27);
0524: mv.visitLineNumber(356, l27);
0525: mv.visitVarInsn(ALOAD, 12);
0526: mv.visitInsn(ATHROW);
0527: mv.visitLabel(l20);
0528: mv.visitLineNumber(355, l20);
0529: mv.visitVarInsn(ALOAD, 9);
0530: mv.visitMethodInsn(INVOKEVIRTUAL,
0531: "java/util/concurrent/locks/ReentrantLock", "unlock",
0532: "()V");
0533: Label l28 = new Label();
0534: mv.visitLabel(l28);
0535: mv.visitLineNumber(357, l28);
0536: mv.visitVarInsn(ILOAD, 7);
0537: Label l29 = new Label();
0538: mv.visitJumpInsn(IFEQ, l29);
0539: mv.visitVarInsn(ILOAD, 8);
0540: Label l30 = new Label();
0541: mv.visitJumpInsn(IFNE, l30);
0542: mv.visitLabel(l29);
0543: mv.visitVarInsn(ALOAD, 0);
0544: mv.visitMethodInsn(INVOKESPECIAL,
0545: "java/util/concurrent/LinkedBlockingQueue",
0546: "signalNotEmpty", "()V");
0547: mv.visitLabel(l30);
0548: mv.visitLineNumber(358, l30);
0549: mv.visitInsn(ICONST_1);
0550: mv.visitInsn(IRETURN);
0551: Label l31 = new Label();
0552: mv.visitLabel(l31);
0553: mv.visitLocalVariable("this",
0554: "Ljava/util/concurrent/LinkedBlockingQueue;",
0555: "Ljava/util/concurrent/LinkedBlockingQueue<TE;>;", l5,
0556: l31, 0);
0557: mv.visitLocalVariable("o", "Ljava/lang/Object;", "TE;", l5,
0558: l31, 1);
0559: mv.visitLocalVariable("timeout", "J", null, l5, l31, 2);
0560: mv.visitLocalVariable("unit",
0561: "Ljava/util/concurrent/TimeUnit;", null, l5, l31, 4);
0562: mv.visitLocalVariable("nanos", "J", null, l7, l31, 5);
0563: mv.visitLocalVariable("c", "I", null, l8, l31, 7);
0564: mv.visitLocalVariable("d", "I", null, l9, l31, 8);
0565: mv.visitLocalVariable("putLock",
0566: "Ljava/util/concurrent/locks/ReentrantLock;", null,
0567: l10, l31, 9);
0568: mv.visitLocalVariable("count",
0569: "Ljava/util/concurrent/atomic/AtomicInteger;", null,
0570: l11, l31, 10);
0571: mv.visitLocalVariable("ie", "Ljava/lang/InterruptedException;",
0572: null, l23, l25, 11);
0573: mv.visitMaxs(7, 13);
0574: mv.visitEnd();
0575: return null;
0576: }
0577:
0578: private MethodVisitor recreatePutMethod(MethodVisitor mv) {
0579: mv.visitCode();
0580: Label l0 = new Label();
0581: Label l1 = new Label();
0582: mv.visitTryCatchBlock(l0, l1, l1,
0583: "java/lang/InterruptedException");
0584: Label l2 = new Label();
0585: mv.visitTryCatchBlock(l0, l2, l2, null);
0586: Label l3 = new Label();
0587: mv.visitLabel(l3);
0588: mv.visitLineNumber(280, l3);
0589: mv.visitVarInsn(ALOAD, 1);
0590: Label l4 = new Label();
0591: mv.visitJumpInsn(IFNONNULL, l4);
0592: mv.visitTypeInsn(NEW, "java/lang/NullPointerException");
0593: mv.visitInsn(DUP);
0594: mv.visitMethodInsn(INVOKESPECIAL,
0595: "java/lang/NullPointerException", "<init>", "()V");
0596: mv.visitInsn(ATHROW);
0597: mv.visitLabel(l4);
0598: mv.visitLineNumber(283, l4);
0599: mv.visitInsn(ICONST_M1);
0600: mv.visitVarInsn(ISTORE, 2);
0601: Label l5 = new Label();
0602: mv.visitLabel(l5);
0603: mv.visitLineNumber(284, l5);
0604: mv.visitVarInsn(ALOAD, 0);
0605: mv.visitFieldInsn(GETFIELD,
0606: "java/util/concurrent/LinkedBlockingQueue", "putLock",
0607: "Ljava/util/concurrent/locks/ReentrantLock;");
0608: mv.visitVarInsn(ASTORE, 3);
0609: Label l6 = new Label();
0610: mv.visitLabel(l6);
0611: mv.visitLineNumber(285, l6);
0612: mv.visitVarInsn(ALOAD, 0);
0613: mv.visitFieldInsn(GETFIELD,
0614: "java/util/concurrent/LinkedBlockingQueue", "count",
0615: "Ljava/util/concurrent/atomic/AtomicInteger;");
0616: mv.visitVarInsn(ASTORE, 4);
0617: Label l7 = new Label();
0618: mv.visitLabel(l7);
0619: mv.visitLineNumber(286, l7);
0620: mv.visitVarInsn(ALOAD, 3);
0621: mv.visitMethodInsn(INVOKEVIRTUAL,
0622: "java/util/concurrent/locks/ReentrantLock",
0623: "lockInterruptibly", "()V");
0624: Label l8 = new Label();
0625: mv.visitLabel(l8);
0626: mv.visitLineNumber(287, l8);
0627: mv.visitInsn(ICONST_M1);
0628: mv.visitVarInsn(ISTORE, 5);
0629: mv.visitLabel(l0);
0630: mv.visitLineNumber(295, l0);
0631: Label l9 = new Label();
0632: mv.visitJumpInsn(GOTO, l9);
0633: Label l10 = new Label();
0634: mv.visitLabel(l10);
0635: mv.visitLineNumber(296, l10);
0636: mv.visitVarInsn(ALOAD, 0);
0637: mv.visitFieldInsn(GETFIELD,
0638: "java/util/concurrent/LinkedBlockingQueue", "notFull",
0639: "Ljava/util/concurrent/locks/Condition;");
0640: mv.visitMethodInsn(INVOKEINTERFACE,
0641: "java/util/concurrent/locks/Condition", "await", "()V");
0642: mv.visitLabel(l9);
0643: mv.visitLineNumber(295, l9);
0644: mv.visitVarInsn(ALOAD, 4);
0645: mv.visitMethodInsn(INVOKEVIRTUAL,
0646: "java/util/concurrent/atomic/AtomicInteger", "get",
0647: "()I");
0648: mv.visitVarInsn(ALOAD, 0);
0649: mv.visitFieldInsn(GETFIELD,
0650: "java/util/concurrent/LinkedBlockingQueue", "capacity",
0651: "I");
0652: mv.visitJumpInsn(IF_ICMPGE, l10);
0653: Label l11 = new Label();
0654: mv.visitJumpInsn(GOTO, l11);
0655: mv.visitLabel(l1);
0656: mv.visitLineNumber(298, l1);
0657: mv.visitVarInsn(ASTORE, 6);
0658: Label l12 = new Label();
0659: mv.visitLabel(l12);
0660: mv.visitLineNumber(299, l12);
0661: mv.visitVarInsn(ALOAD, 0);
0662: mv.visitFieldInsn(GETFIELD,
0663: "java/util/concurrent/LinkedBlockingQueue", "notFull",
0664: "Ljava/util/concurrent/locks/Condition;");
0665: mv
0666: .visitMethodInsn(INVOKEINTERFACE,
0667: "java/util/concurrent/locks/Condition",
0668: "signal", "()V");
0669: Label l13 = new Label();
0670: mv.visitLabel(l13);
0671: mv.visitLineNumber(300, l13);
0672: mv.visitVarInsn(ALOAD, 6);
0673: mv.visitInsn(ATHROW);
0674: mv.visitLabel(l11);
0675: mv.visitLineNumber(302, l11);
0676: mv.visitVarInsn(ALOAD, 0);
0677: mv.visitVarInsn(ALOAD, 1);
0678: mv.visitMethodInsn(INVOKESPECIAL,
0679: "java/util/concurrent/LinkedBlockingQueue", "insert",
0680: "(Ljava/lang/Object;)V");
0681: Label l14 = new Label();
0682: mv.visitLabel(l14);
0683: mv.visitLineNumber(303, l14);
0684: mv.visitVarInsn(ALOAD, 0);
0685: mv.visitMethodInsn(INVOKESTATIC,
0686: "com/tc/object/bytecode/ManagerUtil", "isManaged",
0687: "(Ljava/lang/Object;)Z");
0688: Label l15 = new Label();
0689: mv.visitJumpInsn(IFEQ, l15);
0690: Label l16 = new Label();
0691: mv.visitLabel(l16);
0692: mv.visitLineNumber(304, l16);
0693: mv.visitVarInsn(ALOAD, 4);
0694: mv.visitMethodInsn(INVOKEVIRTUAL,
0695: "java/util/concurrent/atomic/AtomicInteger", "get",
0696: "()I");
0697: mv.visitVarInsn(ISTORE, 2);
0698: Label l17 = new Label();
0699: mv.visitLabel(l17);
0700: mv.visitLineNumber(305, l17);
0701: mv.visitVarInsn(ALOAD, 0);
0702: mv.visitVarInsn(ALOAD, 3);
0703: mv.visitLdcInsn("put(Ljava/lang/Object;)V");
0704: mv.visitInsn(ICONST_1);
0705: mv.visitTypeInsn(ANEWARRAY, "java/lang/Object");
0706: mv.visitInsn(DUP);
0707: mv.visitInsn(ICONST_0);
0708: mv.visitVarInsn(ALOAD, 1);
0709: mv.visitInsn(AASTORE);
0710: mv
0711: .visitMethodInsn(INVOKESTATIC,
0712: "com/tc/object/bytecode/ManagerUtil",
0713: "logicalInvokeWithTransaction",
0714: "(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/String;[Ljava/lang/Object;)V");
0715: Label l18 = new Label();
0716: mv.visitLabel(l18);
0717: mv.visitLineNumber(306, l18);
0718: mv.visitVarInsn(ALOAD, 4);
0719: mv.visitMethodInsn(INVOKEVIRTUAL,
0720: "java/util/concurrent/atomic/AtomicInteger",
0721: "getAndIncrement", "()I");
0722: mv.visitVarInsn(ISTORE, 5);
0723: Label l19 = new Label();
0724: mv.visitJumpInsn(GOTO, l19);
0725: mv.visitLabel(l15);
0726: mv.visitLineNumber(308, l15);
0727: mv.visitVarInsn(ALOAD, 4);
0728: mv.visitMethodInsn(INVOKEVIRTUAL,
0729: "java/util/concurrent/atomic/AtomicInteger",
0730: "getAndIncrement", "()I");
0731: mv.visitVarInsn(ISTORE, 2);
0732: mv.visitLabel(l19);
0733: mv.visitLineNumber(310, l19);
0734: mv.visitVarInsn(ILOAD, 2);
0735: mv.visitInsn(ICONST_1);
0736: mv.visitInsn(IADD);
0737: mv.visitVarInsn(ALOAD, 0);
0738: mv.visitFieldInsn(GETFIELD,
0739: "java/util/concurrent/LinkedBlockingQueue", "capacity",
0740: "I");
0741: Label l20 = new Label();
0742: mv.visitJumpInsn(IF_ICMPGE, l20);
0743: mv.visitVarInsn(ALOAD, 0);
0744: mv.visitFieldInsn(GETFIELD,
0745: "java/util/concurrent/LinkedBlockingQueue", "notFull",
0746: "Ljava/util/concurrent/locks/Condition;");
0747: mv
0748: .visitMethodInsn(INVOKEINTERFACE,
0749: "java/util/concurrent/locks/Condition",
0750: "signal", "()V");
0751: mv.visitJumpInsn(GOTO, l20);
0752: mv.visitLabel(l2);
0753: mv.visitLineNumber(311, l2);
0754: mv.visitVarInsn(ASTORE, 7);
0755: Label l21 = new Label();
0756: mv.visitLabel(l21);
0757: mv.visitLineNumber(312, l21);
0758: mv.visitVarInsn(ALOAD, 3);
0759: mv.visitMethodInsn(INVOKEVIRTUAL,
0760: "java/util/concurrent/locks/ReentrantLock", "unlock",
0761: "()V");
0762: Label l22 = new Label();
0763: mv.visitLabel(l22);
0764: mv.visitLineNumber(313, l22);
0765: mv.visitVarInsn(ALOAD, 7);
0766: mv.visitInsn(ATHROW);
0767: mv.visitLabel(l20);
0768: mv.visitLineNumber(312, l20);
0769: mv.visitVarInsn(ALOAD, 3);
0770: mv.visitMethodInsn(INVOKEVIRTUAL,
0771: "java/util/concurrent/locks/ReentrantLock", "unlock",
0772: "()V");
0773: Label l23 = new Label();
0774: mv.visitLabel(l23);
0775: mv.visitLineNumber(314, l23);
0776: mv.visitVarInsn(ILOAD, 2);
0777: Label l24 = new Label();
0778: mv.visitJumpInsn(IFEQ, l24);
0779: mv.visitVarInsn(ILOAD, 5);
0780: Label l25 = new Label();
0781: mv.visitJumpInsn(IFNE, l25);
0782: mv.visitLabel(l24);
0783: mv.visitVarInsn(ALOAD, 0);
0784: mv.visitMethodInsn(INVOKESPECIAL,
0785: "java/util/concurrent/LinkedBlockingQueue",
0786: "signalNotEmpty", "()V");
0787: mv.visitLabel(l25);
0788: mv.visitLineNumber(320, l25);
0789: mv.visitInsn(RETURN);
0790: Label l26 = new Label();
0791: mv.visitLabel(l26);
0792: mv.visitLocalVariable("this",
0793: "Ljava/util/concurrent/LinkedBlockingQueue;",
0794: "Ljava/util/concurrent/LinkedBlockingQueue<TE;>;", l3,
0795: l26, 0);
0796: mv.visitLocalVariable("o", "Ljava/lang/Object;", "TE;", l3,
0797: l26, 1);
0798: mv.visitLocalVariable("c", "I", null, l5, l26, 2);
0799: mv.visitLocalVariable("putLock",
0800: "Ljava/util/concurrent/locks/ReentrantLock;", null, l6,
0801: l26, 3);
0802: mv.visitLocalVariable("count",
0803: "Ljava/util/concurrent/atomic/AtomicInteger;", null,
0804: l7, l26, 4);
0805: mv.visitLocalVariable("d", "I", null, l0, l26, 5);
0806: mv.visitLocalVariable("ie", "Ljava/lang/InterruptedException;",
0807: null, l12, l11, 6);
0808: mv.visitMaxs(7, 8);
0809: mv.visitEnd();
0810: return null;
0811: }
0812:
0813: private MethodVisitor recreateOfferMethod(MethodVisitor mv) {
0814: mv.visitCode();
0815: Label l0 = new Label();
0816: Label l1 = new Label();
0817: mv.visitTryCatchBlock(l0, l1, l1, null);
0818: Label l2 = new Label();
0819: mv.visitLabel(l2);
0820: mv.visitLineNumber(370, l2);
0821: mv.visitVarInsn(ALOAD, 1);
0822: Label l3 = new Label();
0823: mv.visitJumpInsn(IFNONNULL, l3);
0824: mv.visitTypeInsn(NEW, "java/lang/NullPointerException");
0825: mv.visitInsn(DUP);
0826: mv.visitMethodInsn(INVOKESPECIAL,
0827: "java/lang/NullPointerException", "<init>", "()V");
0828: mv.visitInsn(ATHROW);
0829: mv.visitLabel(l3);
0830: mv.visitLineNumber(371, l3);
0831: mv.visitVarInsn(ALOAD, 0);
0832: mv.visitFieldInsn(GETFIELD,
0833: "java/util/concurrent/LinkedBlockingQueue", "count",
0834: "Ljava/util/concurrent/atomic/AtomicInteger;");
0835: mv.visitVarInsn(ASTORE, 2);
0836: Label l4 = new Label();
0837: mv.visitLabel(l4);
0838: mv.visitLineNumber(372, l4);
0839: mv.visitVarInsn(ALOAD, 2);
0840: mv.visitMethodInsn(INVOKEVIRTUAL,
0841: "java/util/concurrent/atomic/AtomicInteger", "get",
0842: "()I");
0843: mv.visitVarInsn(ALOAD, 0);
0844: mv.visitFieldInsn(GETFIELD,
0845: "java/util/concurrent/LinkedBlockingQueue", "capacity",
0846: "I");
0847: Label l5 = new Label();
0848: mv.visitJumpInsn(IF_ICMPLT, l5);
0849: mv.visitInsn(ICONST_0);
0850: mv.visitInsn(IRETURN);
0851: mv.visitLabel(l5);
0852: mv.visitLineNumber(373, l5);
0853: mv.visitInsn(ICONST_M1);
0854: mv.visitVarInsn(ISTORE, 3);
0855: Label l6 = new Label();
0856: mv.visitLabel(l6);
0857: mv.visitLineNumber(374, l6);
0858: mv.visitInsn(ICONST_M1);
0859: mv.visitVarInsn(ISTORE, 4);
0860: Label l7 = new Label();
0861: mv.visitLabel(l7);
0862: mv.visitLineNumber(375, l7);
0863: mv.visitVarInsn(ALOAD, 0);
0864: mv.visitFieldInsn(GETFIELD,
0865: "java/util/concurrent/LinkedBlockingQueue", "putLock",
0866: "Ljava/util/concurrent/locks/ReentrantLock;");
0867: mv.visitVarInsn(ASTORE, 5);
0868: Label l8 = new Label();
0869: mv.visitLabel(l8);
0870: mv.visitLineNumber(376, l8);
0871: mv.visitVarInsn(ALOAD, 5);
0872: mv.visitMethodInsn(INVOKEVIRTUAL,
0873: "java/util/concurrent/locks/ReentrantLock", "lock",
0874: "()V");
0875: mv.visitLabel(l0);
0876: mv.visitLineNumber(378, l0);
0877: mv.visitVarInsn(ALOAD, 2);
0878: mv.visitMethodInsn(INVOKEVIRTUAL,
0879: "java/util/concurrent/atomic/AtomicInteger", "get",
0880: "()I");
0881: mv.visitVarInsn(ALOAD, 0);
0882: mv.visitFieldInsn(GETFIELD,
0883: "java/util/concurrent/LinkedBlockingQueue", "capacity",
0884: "I");
0885: Label l9 = new Label();
0886: mv.visitJumpInsn(IF_ICMPGE, l9);
0887: Label l10 = new Label();
0888: mv.visitLabel(l10);
0889: mv.visitLineNumber(379, l10);
0890: mv.visitVarInsn(ALOAD, 0);
0891: mv.visitVarInsn(ALOAD, 1);
0892: mv.visitMethodInsn(INVOKESPECIAL,
0893: "java/util/concurrent/LinkedBlockingQueue", "insert",
0894: "(Ljava/lang/Object;)V");
0895: Label l11 = new Label();
0896: mv.visitLabel(l11);
0897: mv.visitLineNumber(380, l11);
0898: mv.visitVarInsn(ALOAD, 0);
0899: mv.visitMethodInsn(INVOKESTATIC,
0900: "com/tc/object/bytecode/ManagerUtil", "isManaged",
0901: "(Ljava/lang/Object;)Z");
0902: Label l12 = new Label();
0903: mv.visitJumpInsn(IFEQ, l12);
0904: Label l13 = new Label();
0905: mv.visitLabel(l13);
0906: mv.visitLineNumber(381, l13);
0907: mv.visitVarInsn(ALOAD, 2);
0908: mv.visitMethodInsn(INVOKEVIRTUAL,
0909: "java/util/concurrent/atomic/AtomicInteger", "get",
0910: "()I");
0911: mv.visitVarInsn(ISTORE, 3);
0912: Label l14 = new Label();
0913: mv.visitLabel(l14);
0914: mv.visitLineNumber(382, l14);
0915: mv.visitVarInsn(ALOAD, 0);
0916: mv.visitVarInsn(ALOAD, 5);
0917: mv.visitLdcInsn("put(Ljava/lang/Object;)V");
0918: mv.visitInsn(ICONST_1);
0919: mv.visitTypeInsn(ANEWARRAY, "java/lang/Object");
0920: mv.visitInsn(DUP);
0921: mv.visitInsn(ICONST_0);
0922: mv.visitVarInsn(ALOAD, 1);
0923: mv.visitInsn(AASTORE);
0924: mv
0925: .visitMethodInsn(INVOKESTATIC,
0926: "com/tc/object/bytecode/ManagerUtil",
0927: "logicalInvokeWithTransaction",
0928: "(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/String;[Ljava/lang/Object;)V");
0929: Label l15 = new Label();
0930: mv.visitLabel(l15);
0931: mv.visitLineNumber(383, l15);
0932: mv.visitVarInsn(ALOAD, 2);
0933: mv.visitMethodInsn(INVOKEVIRTUAL,
0934: "java/util/concurrent/atomic/AtomicInteger",
0935: "getAndIncrement", "()I");
0936: mv.visitVarInsn(ISTORE, 4);
0937: Label l16 = new Label();
0938: mv.visitJumpInsn(GOTO, l16);
0939: mv.visitLabel(l12);
0940: mv.visitLineNumber(385, l12);
0941: mv.visitVarInsn(ALOAD, 2);
0942: mv.visitMethodInsn(INVOKEVIRTUAL,
0943: "java/util/concurrent/atomic/AtomicInteger",
0944: "getAndIncrement", "()I");
0945: mv.visitVarInsn(ISTORE, 3);
0946: mv.visitLabel(l16);
0947: mv.visitLineNumber(387, l16);
0948: mv.visitVarInsn(ILOAD, 3);
0949: mv.visitInsn(ICONST_1);
0950: mv.visitInsn(IADD);
0951: mv.visitVarInsn(ALOAD, 0);
0952: mv.visitFieldInsn(GETFIELD,
0953: "java/util/concurrent/LinkedBlockingQueue", "capacity",
0954: "I");
0955: mv.visitJumpInsn(IF_ICMPGE, l9);
0956: mv.visitVarInsn(ALOAD, 0);
0957: mv.visitFieldInsn(GETFIELD,
0958: "java/util/concurrent/LinkedBlockingQueue", "notFull",
0959: "Ljava/util/concurrent/locks/Condition;");
0960: mv
0961: .visitMethodInsn(INVOKEINTERFACE,
0962: "java/util/concurrent/locks/Condition",
0963: "signal", "()V");
0964: mv.visitJumpInsn(GOTO, l9);
0965: mv.visitLabel(l1);
0966: mv.visitLineNumber(389, l1);
0967: mv.visitVarInsn(ASTORE, 6);
0968: Label l17 = new Label();
0969: mv.visitLabel(l17);
0970: mv.visitLineNumber(390, l17);
0971: mv.visitVarInsn(ALOAD, 5);
0972: mv.visitMethodInsn(INVOKEVIRTUAL,
0973: "java/util/concurrent/locks/ReentrantLock", "unlock",
0974: "()V");
0975: Label l18 = new Label();
0976: mv.visitLabel(l18);
0977: mv.visitLineNumber(391, l18);
0978: mv.visitVarInsn(ALOAD, 6);
0979: mv.visitInsn(ATHROW);
0980: mv.visitLabel(l9);
0981: mv.visitLineNumber(390, l9);
0982: mv.visitVarInsn(ALOAD, 5);
0983: mv.visitMethodInsn(INVOKEVIRTUAL,
0984: "java/util/concurrent/locks/ReentrantLock", "unlock",
0985: "()V");
0986: Label l19 = new Label();
0987: mv.visitLabel(l19);
0988: mv.visitLineNumber(392, l19);
0989: mv.visitVarInsn(ILOAD, 3);
0990: Label l20 = new Label();
0991: mv.visitJumpInsn(IFEQ, l20);
0992: mv.visitVarInsn(ILOAD, 4);
0993: Label l21 = new Label();
0994: mv.visitJumpInsn(IFNE, l21);
0995: mv.visitLabel(l20);
0996: mv.visitVarInsn(ALOAD, 0);
0997: mv.visitMethodInsn(INVOKESPECIAL,
0998: "java/util/concurrent/LinkedBlockingQueue",
0999: "signalNotEmpty", "()V");
1000: mv.visitLabel(l21);
1001: mv.visitLineNumber(393, l21);
1002: mv.visitVarInsn(ILOAD, 3);
1003: Label l22 = new Label();
1004: mv.visitJumpInsn(IFLT, l22);
1005: mv.visitInsn(ICONST_1);
1006: mv.visitInsn(IRETURN);
1007: mv.visitLabel(l22);
1008: mv.visitInsn(ICONST_0);
1009: mv.visitInsn(IRETURN);
1010: Label l23 = new Label();
1011: mv.visitLabel(l23);
1012: mv.visitLocalVariable("this",
1013: "Ljava/util/concurrent/LinkedBlockingQueue;",
1014: "Ljava/util/concurrent/LinkedBlockingQueue<TE;>;", l2,
1015: l23, 0);
1016: mv.visitLocalVariable("o", "Ljava/lang/Object;", "TE;", l2,
1017: l23, 1);
1018: mv.visitLocalVariable("count",
1019: "Ljava/util/concurrent/atomic/AtomicInteger;", null,
1020: l4, l23, 2);
1021: mv.visitLocalVariable("c", "I", null, l6, l23, 3);
1022: mv.visitLocalVariable("d", "I", null, l7, l23, 4);
1023: mv.visitLocalVariable("putLock",
1024: "Ljava/util/concurrent/locks/ReentrantLock;", null, l8,
1025: l23, 5);
1026: mv.visitMaxs(0, 0);
1027: mv.visitEnd();
1028: return null;
1029: }
1030:
1031: // Rewriting the remove(Object) method of LinkedBlockingQueue with instrumented code.
1032: private MethodVisitor recreateRemoveMethod(MethodVisitor mv) {
1033: mv.visitCode();
1034: Label l0 = new Label();
1035: Label l1 = new Label();
1036: mv.visitTryCatchBlock(l0, l1, l1, null);
1037: Label l2 = new Label();
1038: mv.visitLabel(l2);
1039: mv.visitInsn(ICONST_0);
1040: mv.visitVarInsn(ISTORE, 2);
1041: Label l3 = new Label();
1042: mv.visitLabel(l3);
1043: mv.visitVarInsn(ALOAD, 1);
1044: Label l4 = new Label();
1045: mv.visitJumpInsn(IFNONNULL, l4);
1046: mv.visitInsn(ICONST_0);
1047: mv.visitInsn(IRETURN);
1048: mv.visitLabel(l4);
1049: mv.visitInsn(ICONST_0);
1050: mv.visitVarInsn(ISTORE, 3);
1051: Label l5 = new Label();
1052: mv.visitLabel(l5);
1053: mv.visitVarInsn(ALOAD, 0);
1054: mv.visitMethodInsn(INVOKESPECIAL,
1055: "java/util/concurrent/LinkedBlockingQueue",
1056: "fullyLock", "()V");
1057: mv.visitLabel(l0);
1058: mv.visitVarInsn(ALOAD, 0);
1059: mv.visitFieldInsn(GETFIELD,
1060: "java/util/concurrent/LinkedBlockingQueue", "head",
1061: "Ljava/util/concurrent/LinkedBlockingQueue$Node;");
1062: mv.visitVarInsn(ASTORE, 4);
1063: Label l6 = new Label();
1064: mv.visitLabel(l6);
1065: mv.visitVarInsn(ALOAD, 0);
1066: mv.visitFieldInsn(GETFIELD,
1067: "java/util/concurrent/LinkedBlockingQueue", "head",
1068: "Ljava/util/concurrent/LinkedBlockingQueue$Node;");
1069: mv.visitFieldInsn(GETFIELD,
1070: "java/util/concurrent/LinkedBlockingQueue$Node",
1071: "next",
1072: "Ljava/util/concurrent/LinkedBlockingQueue$Node;");
1073: mv.visitVarInsn(ASTORE, 5);
1074: Label l7 = new Label();
1075: mv.visitLabel(l7);
1076: Label l8 = new Label();
1077: mv.visitJumpInsn(GOTO, l8);
1078: Label l9 = new Label();
1079: mv.visitLabel(l9);
1080: mv.visitVarInsn(ALOAD, 1);
1081: mv.visitVarInsn(ALOAD, 5);
1082: mv.visitFieldInsn(GETFIELD,
1083: "java/util/concurrent/LinkedBlockingQueue$Node",
1084: "item", "Ljava/lang/Object;");
1085: mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object", "equals",
1086: "(Ljava/lang/Object;)Z");
1087: Label l10 = new Label();
1088: mv.visitJumpInsn(IFEQ, l10);
1089: Label l11 = new Label();
1090: mv.visitLabel(l11);
1091: mv.visitInsn(ICONST_1);
1092: mv.visitVarInsn(ISTORE, 3);
1093: Label l12 = new Label();
1094: mv.visitLabel(l12);
1095: Label l13 = new Label();
1096: mv.visitJumpInsn(GOTO, l13);
1097: mv.visitLabel(l10);
1098: mv.visitVarInsn(ALOAD, 5);
1099: mv.visitVarInsn(ASTORE, 4);
1100: Label l14 = new Label();
1101: mv.visitLabel(l14);
1102: mv.visitVarInsn(ALOAD, 5);
1103: mv.visitFieldInsn(GETFIELD,
1104: "java/util/concurrent/LinkedBlockingQueue$Node",
1105: "next",
1106: "Ljava/util/concurrent/LinkedBlockingQueue$Node;");
1107: mv.visitVarInsn(ASTORE, 5);
1108: Label l15 = new Label();
1109: mv.visitLabel(l15);
1110: mv.visitIincInsn(2, 1);
1111: mv.visitLabel(l8);
1112: mv.visitVarInsn(ALOAD, 5);
1113: mv.visitJumpInsn(IFNONNULL, l9);
1114: mv.visitLabel(l13);
1115: mv.visitVarInsn(ILOAD, 3);
1116: Label l16 = new Label();
1117: mv.visitJumpInsn(IFEQ, l16);
1118: Label l17 = new Label();
1119: mv.visitLabel(l17);
1120: mv.visitVarInsn(ALOAD, 5);
1121: mv.visitInsn(ACONST_NULL);
1122: mv.visitFieldInsn(PUTFIELD,
1123: "java/util/concurrent/LinkedBlockingQueue$Node",
1124: "item", "Ljava/lang/Object;");
1125: Label l18 = new Label();
1126: mv.visitLabel(l18);
1127: mv.visitVarInsn(ALOAD, 4);
1128: mv.visitVarInsn(ALOAD, 5);
1129: mv.visitFieldInsn(GETFIELD,
1130: "java/util/concurrent/LinkedBlockingQueue$Node",
1131: "next",
1132: "Ljava/util/concurrent/LinkedBlockingQueue$Node;");
1133: mv.visitFieldInsn(PUTFIELD,
1134: "java/util/concurrent/LinkedBlockingQueue$Node",
1135: "next",
1136: "Ljava/util/concurrent/LinkedBlockingQueue$Node;");
1137: Label l19 = new Label();
1138: mv.visitLabel(l19);
1139: mv.visitVarInsn(ALOAD, 0);
1140: mv.visitMethodInsn(INVOKESTATIC,
1141: "com/tc/object/bytecode/ManagerUtil", "isManaged",
1142: "(Ljava/lang/Object;)Z");
1143: Label l20 = new Label();
1144: mv.visitJumpInsn(IFEQ, l20);
1145: Label l21 = new Label();
1146: mv.visitLabel(l21);
1147: mv.visitVarInsn(ALOAD, 0);
1148: mv.visitLdcInsn(SerializationUtil.REMOVE_AT_SIGNATURE);
1149: mv.visitInsn(ICONST_1);
1150: mv.visitTypeInsn(ANEWARRAY, "java/lang/Object");
1151: mv.visitInsn(DUP);
1152: mv.visitInsn(ICONST_0);
1153: mv.visitTypeInsn(NEW, "java/lang/Integer");
1154: mv.visitInsn(DUP);
1155: mv.visitVarInsn(ILOAD, 2);
1156: mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Integer",
1157: "<init>", "(I)V");
1158: mv.visitInsn(AASTORE);
1159: mv
1160: .visitMethodInsn(INVOKESTATIC,
1161: "com/tc/object/bytecode/ManagerUtil",
1162: "logicalInvoke",
1163: "(Ljava/lang/Object;Ljava/lang/String;[Ljava/lang/Object;)V");
1164: mv.visitLabel(l20);
1165: mv.visitVarInsn(ALOAD, 0);
1166: mv.visitFieldInsn(GETFIELD,
1167: "java/util/concurrent/LinkedBlockingQueue", "last",
1168: "Ljava/util/concurrent/LinkedBlockingQueue$Node;");
1169: mv.visitVarInsn(ALOAD, 5);
1170: Label l22 = new Label();
1171: mv.visitJumpInsn(IF_ACMPNE, l22);
1172: mv.visitVarInsn(ALOAD, 0);
1173: mv.visitVarInsn(ALOAD, 4);
1174: mv.visitFieldInsn(PUTFIELD,
1175: "java/util/concurrent/LinkedBlockingQueue", "last",
1176: "Ljava/util/concurrent/LinkedBlockingQueue$Node;");
1177: mv.visitLabel(l22);
1178: mv.visitVarInsn(ALOAD, 0);
1179: mv.visitFieldInsn(GETFIELD,
1180: "java/util/concurrent/LinkedBlockingQueue", "count",
1181: "Ljava/util/concurrent/atomic/AtomicInteger;");
1182: mv.visitMethodInsn(INVOKEVIRTUAL,
1183: "java/util/concurrent/atomic/AtomicInteger",
1184: "getAndDecrement", "()I");
1185: mv.visitVarInsn(ALOAD, 0);
1186: mv.visitFieldInsn(GETFIELD,
1187: "java/util/concurrent/LinkedBlockingQueue", "capacity",
1188: "I");
1189: mv.visitJumpInsn(IF_ICMPNE, l16);
1190: mv.visitVarInsn(ALOAD, 0);
1191: mv.visitFieldInsn(GETFIELD,
1192: "java/util/concurrent/LinkedBlockingQueue", "notFull",
1193: "Ljava/util/concurrent/locks/Condition;");
1194: mv.visitMethodInsn(INVOKEINTERFACE,
1195: "java/util/concurrent/locks/Condition", "signalAll",
1196: "()V");
1197: mv.visitJumpInsn(GOTO, l16);
1198: mv.visitLabel(l1);
1199: mv.visitVarInsn(ASTORE, 6);
1200: Label l23 = new Label();
1201: mv.visitLabel(l23);
1202: mv.visitVarInsn(ALOAD, 0);
1203: mv.visitMethodInsn(INVOKESPECIAL,
1204: "java/util/concurrent/LinkedBlockingQueue",
1205: "fullyUnlock", "()V");
1206: Label l24 = new Label();
1207: mv.visitLabel(l24);
1208: mv.visitVarInsn(ALOAD, 6);
1209: mv.visitInsn(ATHROW);
1210: mv.visitLabel(l16);
1211: mv.visitVarInsn(ALOAD, 0);
1212: mv.visitMethodInsn(INVOKESPECIAL,
1213: "java/util/concurrent/LinkedBlockingQueue",
1214: "fullyUnlock", "()V");
1215: Label l25 = new Label();
1216: mv.visitLabel(l25);
1217: mv.visitVarInsn(ILOAD, 3);
1218: mv.visitInsn(IRETURN);
1219: Label l26 = new Label();
1220: mv.visitLabel(l26);
1221: mv.visitMaxs(0, 0);
1222: mv.visitEnd();
1223: return null;
1224: }
1225:
1226: private void addInitMethodCode() {
1227: MethodVisitor mv = super .visitMethod(ACC_PRIVATE
1228: + ACC_SYNTHETIC, "init", "()V", null, null);
1229: mv.visitCode();
1230: ByteCodeUtil.pushThis(mv);
1231: ByteCodeUtil.pushThis(mv);
1232: mv.visitFieldInsn(GETFIELD,
1233: "java/util/concurrent/LinkedBlockingQueue", "takeLock",
1234: "Ljava/util/concurrent/locks/ReentrantLock;");
1235: mv.visitMethodInsn(INVOKEVIRTUAL,
1236: "java/util/concurrent/locks/ReentrantLock",
1237: "newCondition",
1238: "()Ljava/util/concurrent/locks/Condition;");
1239: mv.visitFieldInsn(PUTFIELD,
1240: "java/util/concurrent/LinkedBlockingQueue", "notEmpty",
1241: "Ljava/util/concurrent/locks/Condition;");
1242: ByteCodeUtil.pushThis(mv);
1243: ByteCodeUtil.pushThis(mv);
1244: mv.visitFieldInsn(GETFIELD,
1245: "java/util/concurrent/LinkedBlockingQueue", "putLock",
1246: "Ljava/util/concurrent/locks/ReentrantLock;");
1247: mv.visitMethodInsn(INVOKEVIRTUAL,
1248: "java/util/concurrent/locks/ReentrantLock",
1249: "newCondition",
1250: "()Ljava/util/concurrent/locks/Condition;");
1251: mv.visitFieldInsn(PUTFIELD,
1252: "java/util/concurrent/LinkedBlockingQueue", "notFull",
1253: "Ljava/util/concurrent/locks/Condition;");
1254: mv.visitInsn(RETURN);
1255: mv.visitMaxs(0, 0);
1256: mv.visitEnd();
1257: }
1258:
1259: private void addTCExtractMethod() {
1260: MethodVisitor mv = cv.visitMethod(ACC_PRIVATE,
1261: TC_EXTRACT_METHOD_NAME, TC_EXTRACT_METHOD_DESC,
1262: "()TE;", null);
1263: mv.visitCode();
1264: Label l0 = new Label();
1265: mv.visitLabel(l0);
1266: mv.visitLineNumber(144, l0);
1267: mv.visitVarInsn(ALOAD, 0);
1268: mv.visitFieldInsn(GETFIELD,
1269: "java/util/concurrent/LinkedBlockingQueue", "head",
1270: "Ljava/util/concurrent/LinkedBlockingQueue$Node;");
1271: mv.visitFieldInsn(GETFIELD,
1272: "java/util/concurrent/LinkedBlockingQueue$Node",
1273: "next",
1274: "Ljava/util/concurrent/LinkedBlockingQueue$Node;");
1275: mv.visitVarInsn(ASTORE, 1);
1276: Label l1 = new Label();
1277: mv.visitLabel(l1);
1278: mv.visitLineNumber(145, l1);
1279: mv.visitVarInsn(ALOAD, 0);
1280: mv.visitVarInsn(ALOAD, 1);
1281: mv.visitFieldInsn(PUTFIELD,
1282: "java/util/concurrent/LinkedBlockingQueue", "head",
1283: "Ljava/util/concurrent/LinkedBlockingQueue$Node;");
1284: Label l2 = new Label();
1285: mv.visitLabel(l2);
1286: mv.visitLineNumber(146, l2);
1287: mv.visitVarInsn(ALOAD, 1);
1288: mv.visitFieldInsn(GETFIELD,
1289: "java/util/concurrent/LinkedBlockingQueue$Node",
1290: "item", "Ljava/lang/Object;");
1291: mv.visitVarInsn(ASTORE, 2);
1292: Label l3 = new Label();
1293: mv.visitLabel(l3);
1294: mv.visitLineNumber(147, l3);
1295: mv.visitVarInsn(ALOAD, 1);
1296: mv.visitInsn(ACONST_NULL);
1297: mv.visitFieldInsn(PUTFIELD,
1298: "java/util/concurrent/LinkedBlockingQueue$Node",
1299: "item", "Ljava/lang/Object;");
1300: Label l4 = new Label();
1301: mv.visitLabel(l4);
1302: mv.visitLineNumber(148, l4);
1303: mv.visitVarInsn(ALOAD, 2);
1304: mv.visitInsn(ARETURN);
1305: Label l5 = new Label();
1306: mv.visitLabel(l5);
1307: mv.visitLocalVariable("this",
1308: "Ljava/util/concurrent/LinkedBlockingQueue;",
1309: "Ljava/util/concurrent/LinkedBlockingQueue<TE;>;", l0,
1310: l5, 0);
1311: mv.visitLocalVariable("first",
1312: "Ljava/util/concurrent/LinkedBlockingQueue$Node;",
1313: "Ljava/util/concurrent/LinkedBlockingQueue$Node<TE;>;",
1314: l1, l5, 1);
1315: mv.visitLocalVariable("x", "Ljava/lang/Object;", "TE;", l3, l5,
1316: 2);
1317: mv.visitMaxs(2, 3);
1318: mv.visitEnd();
1319: }
1320:
1321: static class NodeMethodAdapter extends MethodAdapter implements
1322: Opcodes {
1323: public NodeMethodAdapter(MethodVisitor mv) {
1324: super (mv);
1325: }
1326:
1327: public void visitFieldInsn(int opcode, String owner,
1328: String name, String desc) {
1329: if (GETFIELD == opcode
1330: && "java/util/concurrent/LinkedBlockingQueue$Node"
1331: .equals(owner) && "item".equals(name)
1332: && "Ljava/lang/Object;".equals(desc)) {
1333: mv.visitMethodInsn(INVOKEVIRTUAL, owner,
1334: GET_ITEM_METHOD_NAME, GET_ITEM_METHOD_DESC);
1335: } else {
1336: super.visitFieldInsn(opcode, owner, name, desc);
1337: }
1338: }
1339: }
1340: }
|