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.ClassVisitor;
0008: import com.tc.asm.FieldVisitor;
0009: import com.tc.asm.Label;
0010: import com.tc.asm.MethodAdapter;
0011: import com.tc.asm.MethodVisitor;
0012: import com.tc.asm.Opcodes;
0013:
0014: public class JavaUtilConcurrentFutureTaskSyncAdapter implements Opcodes {
0015: public static class JavaUtilConcurrentFutureTaskSyncClassAdapter
0016: extends ClassAdapter implements Opcodes {
0017: private final static String MANAGED_OBJECT_LOCK_FIELD_NAME = "managedLock";
0018: private final static String PROXY_RUNNER_FIELD_NAME = "proxyRunner";
0019: private final static String MAANGED_INNER_CANCEL_METHOD_NAME = "managedInnerCancel";
0020: private final static String MANAGED_INNER_SET_METHOD_NAME = "managedInnerSet";
0021: private final static String MANAGED_TRY_RELEASE_SHARED_METHOD = "managedTryReleaseShared";
0022:
0023: //private final static String MANAGED_RELEASE_SHARED = "managedReleaseShared";
0024:
0025: public JavaUtilConcurrentFutureTaskSyncClassAdapter(
0026: ClassVisitor cv) {
0027: super (cv);
0028: }
0029:
0030: public FieldVisitor visitField(int access, String name,
0031: String desc, String signature, Object value) {
0032: if ("runner".equals(name)
0033: && "Ljava/lang/Thread;".equals(desc)) {
0034: access += ACC_TRANSIENT;
0035: }
0036: return super .visitField(access, name, desc, signature,
0037: value);
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: if ("<init>".equals(name)) {
0045: mv = new Constructor(mv);
0046: } else if ("innerGet".equals(name)
0047: && "()Ljava/lang/Object;".equals(desc)) {
0048: return rewriteInnerGetMethod(mv);
0049: } else if ("innerGet".equals(name)
0050: && "(J)Ljava/lang/Object;".equals(desc)) {
0051: return rewriteTimedInnerGetMethod(mv);
0052: } else if ("innerSet".equals(name)) {
0053: return rewriteInnerSetMethod(mv);
0054: } else if ("innerSetException".equals(name)) {
0055: return rewriteInnerSetExceptionMethod(mv);
0056: } else if ("innerCancel".equals(name)) {
0057: return rewriteInnerCancelMethod(mv);
0058: } else if ("innerIsDone".equals(name)) {
0059: return rewriteInnerIsDoneMethod(mv);
0060: } else if ("innerRun".equals(name)) {
0061: return rewriteInnerRunMethod(mv);
0062: } else if ("tryReleaseShared".equals(name)) {
0063: return rewriteTryReleaseSharedMethod(mv);
0064: }
0065:
0066: return mv;
0067: }
0068:
0069: public void visitEnd() {
0070: addManagedLockField();
0071: addProxyRunnerField();
0072: addManagedInnerCancelMethod();
0073: addManagedTryReleaseSharedMethod();
0074: //addManagedReleaseSharedMethod();
0075: //addTryManagedReleaseMethod();
0076: addManagedInnerSetMethod();
0077: super .visitEnd();
0078: }
0079:
0080: private void addManagedLockField() {
0081: cv.visitField(ACC_PRIVATE + ACC_SYNTHETIC,
0082: MANAGED_OBJECT_LOCK_FIELD_NAME,
0083: "Ljava/lang/Object;", null, null);
0084: }
0085:
0086: private void addProxyRunnerField() {
0087: cv.visitField(ACC_PRIVATE + ACC_VOLATILE + ACC_SYNTHETIC,
0088: PROXY_RUNNER_FIELD_NAME, "Ljava/lang/Object;",
0089: null, null);
0090: }
0091:
0092: private void addManagedInnerSetMethod() {
0093: MethodVisitor mv = cv.visitMethod(0,
0094: MANAGED_INNER_SET_METHOD_NAME,
0095: "(Ljava/lang/Object;)V", null, null);
0096: mv.visitCode();
0097: Label l0 = new Label();
0098: mv.visitLabel(l0);
0099: mv.visitVarInsn(ALOAD, 0);
0100: mv.visitMethodInsn(INVOKEVIRTUAL,
0101: "java/util/concurrent/FutureTask$Sync", "getState",
0102: "()I");
0103: mv.visitVarInsn(ISTORE, 2);
0104: Label l1 = new Label();
0105: mv.visitLabel(l1);
0106: mv.visitVarInsn(ALOAD, 0);
0107: mv.visitVarInsn(ILOAD, 2);
0108: mv.visitMethodInsn(INVOKESPECIAL,
0109: "java/util/concurrent/FutureTask$Sync",
0110: "ranOrCancelled", "(I)Z");
0111: Label l2 = new Label();
0112: mv.visitJumpInsn(IFEQ, l2);
0113: mv.visitInsn(RETURN);
0114: mv.visitLabel(l2);
0115: mv.visitVarInsn(ALOAD, 0);
0116: mv.visitInsn(ICONST_2);
0117: mv.visitMethodInsn(INVOKEVIRTUAL,
0118: "java/util/concurrent/FutureTask$Sync", "setState",
0119: "(I)V");
0120: Label l3 = new Label();
0121: mv.visitLabel(l3);
0122: mv.visitVarInsn(ALOAD, 0);
0123: mv.visitVarInsn(ALOAD, 1);
0124: mv.visitFieldInsn(PUTFIELD,
0125: "java/util/concurrent/FutureTask$Sync", "result",
0126: "Ljava/lang/Object;");
0127: Label l4 = new Label();
0128: mv.visitLabel(l4);
0129: mv.visitVarInsn(ALOAD, 0);
0130: mv.visitMethodInsn(INVOKESPECIAL,
0131: "java/util/concurrent/FutureTask$Sync",
0132: "managedTryReleaseShared", "()Z");
0133: mv.visitInsn(POP);
0134: Label l5 = new Label();
0135: mv.visitLabel(l5);
0136: mv.visitVarInsn(ALOAD, 0);
0137: mv.visitFieldInsn(GETFIELD,
0138: "java/util/concurrent/FutureTask$Sync", "this$0",
0139: "Ljava/util/concurrent/FutureTask;");
0140: mv.visitMethodInsn(INVOKEVIRTUAL,
0141: "java/util/concurrent/FutureTask", "done", "()V");
0142: Label l6 = new Label();
0143: mv.visitLabel(l6);
0144: mv.visitInsn(RETURN);
0145: Label l7 = new Label();
0146: mv.visitLabel(l7);
0147: mv.visitMaxs(0, 0);
0148: mv.visitEnd();
0149: }
0150:
0151: private MethodVisitor rewriteTryReleaseSharedMethod(
0152: MethodVisitor mv) {
0153: mv.visitCode();
0154: Label l0 = new Label();
0155: mv.visitLabel(l0);
0156: mv.visitVarInsn(ALOAD, 0);
0157: mv.visitMethodInsn(INVOKESPECIAL,
0158: "java/util/concurrent/FutureTask$Sync",
0159: "managedTryReleaseShared", "()Z");
0160: mv.visitInsn(POP);
0161: Label l1 = new Label();
0162: mv.visitLabel(l1);
0163: mv.visitInsn(ICONST_1);
0164: mv.visitInsn(IRETURN);
0165: Label l2 = new Label();
0166: mv.visitLabel(l2);
0167: mv.visitMaxs(0, 0);
0168: mv.visitEnd();
0169: return null;
0170: }
0171:
0172: private MethodVisitor rewriteInnerRunMethod(MethodVisitor mv) {
0173: mv.visitCode();
0174: Label l0 = new Label();
0175: Label l1 = new Label();
0176: Label l2 = new Label();
0177: mv.visitTryCatchBlock(l0, l1, l2, null);
0178: Label l3 = new Label();
0179: mv.visitTryCatchBlock(l2, l3, l2, null);
0180: Label l4 = new Label();
0181: Label l5 = new Label();
0182: Label l6 = new Label();
0183: mv.visitTryCatchBlock(l4, l5, l6, null);
0184: Label l7 = new Label();
0185: mv.visitTryCatchBlock(l6, l7, l6, null);
0186: Label l8 = new Label();
0187: Label l9 = new Label();
0188: Label l10 = new Label();
0189: mv.visitTryCatchBlock(l8, l9, l10, null);
0190: Label l11 = new Label();
0191: mv.visitTryCatchBlock(l10, l11, l10, null);
0192: Label l12 = new Label();
0193: Label l13 = new Label();
0194: mv.visitTryCatchBlock(l12, l13, l13, "java/lang/Throwable");
0195: Label l14 = new Label();
0196: Label l15 = new Label();
0197: mv.visitTryCatchBlock(l14, l15, l15, "java/lang/Throwable");
0198: Label l16 = new Label();
0199: mv.visitLabel(l16);
0200: mv.visitVarInsn(ALOAD, 0);
0201: mv.visitInsn(ICONST_0);
0202: mv.visitInsn(ICONST_1);
0203: mv.visitMethodInsn(INVOKEVIRTUAL,
0204: "java/util/concurrent/FutureTask$Sync",
0205: "compareAndSetState", "(II)Z");
0206: Label l17 = new Label();
0207: mv.visitJumpInsn(IFNE, l17);
0208: mv.visitInsn(RETURN);
0209: mv.visitLabel(l17);
0210: mv.visitVarInsn(ALOAD, 0);
0211: mv.visitFieldInsn(GETFIELD,
0212: "java/util/concurrent/FutureTask$Sync", "this$0",
0213: "Ljava/util/concurrent/FutureTask;");
0214: mv.visitMethodInsn(INVOKESTATIC,
0215: "com/tc/object/bytecode/ManagerUtil", "isManaged",
0216: "(Ljava/lang/Object;)Z");
0217: mv.visitJumpInsn(IFEQ, l14);
0218: mv.visitLabel(l12);
0219: mv.visitVarInsn(ALOAD, 0);
0220: mv.visitMethodInsn(INVOKESTATIC, "java/lang/Thread",
0221: "currentThread", "()Ljava/lang/Thread;");
0222: mv.visitFieldInsn(PUTFIELD,
0223: "java/util/concurrent/FutureTask$Sync", "runner",
0224: "Ljava/lang/Thread;");
0225: Label l18 = new Label();
0226: mv.visitLabel(l18);
0227: mv.visitInsn(ICONST_0);
0228: mv.visitVarInsn(ISTORE, 1);
0229: Label l19 = new Label();
0230: mv.visitLabel(l19);
0231: mv.visitVarInsn(ALOAD, 0);
0232: mv.visitFieldInsn(GETFIELD,
0233: "java/util/concurrent/FutureTask$Sync",
0234: "managedLock", "Ljava/lang/Object;");
0235: mv.visitInsn(DUP);
0236: mv.visitVarInsn(ASTORE, 2);
0237: mv.visitInsn(MONITORENTER);
0238: mv.visitLabel(l0);
0239: mv.visitVarInsn(ALOAD, 0);
0240: mv.visitVarInsn(ALOAD, 0);
0241: mv.visitFieldInsn(GETFIELD,
0242: "java/util/concurrent/FutureTask$Sync", "runner",
0243: "Ljava/lang/Thread;");
0244: mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Thread",
0245: "toString", "()Ljava/lang/String;");
0246: mv.visitFieldInsn(PUTFIELD,
0247: "java/util/concurrent/FutureTask$Sync",
0248: "proxyRunner", "Ljava/lang/Object;");
0249: Label l20 = new Label();
0250: mv.visitLabel(l20);
0251: /*mv.visitFieldInsn(GETSTATIC, "java/lang/System", "err", "Ljava/io/PrintStream;");
0252: mv.visitTypeInsn(NEW, "java/lang/StringBuilder");
0253: mv.visitInsn(DUP);
0254: mv.visitLdcInsn("InnerRun state1: ");
0255: mv.visitMethodInsn(INVOKESPECIAL, "java/lang/StringBuilder", "<init>", "(Ljava/lang/String;)V");
0256: mv.visitVarInsn(ALOAD, 0);
0257: mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/concurrent/FutureTask$Sync", "getState", "()I");
0258: mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(I)Ljava/lang/StringBuilder;");
0259: mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;");
0260: mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V");
0261:
0262: Label l21 = new Label();
0263: mv.visitLabel(l21);
0264: mv.visitLdcInsn(new Long(10L));
0265: mv.visitMethodInsn(INVOKESTATIC, "java/lang/Thread", "sleep", "(J)V");
0266: Label l22 = new Label();
0267: mv.visitLabel(l22);
0268: mv.visitFieldInsn(GETSTATIC, "java/lang/System", "err", "Ljava/io/PrintStream;");
0269: mv.visitTypeInsn(NEW, "java/lang/StringBuilder");
0270: mv.visitInsn(DUP);
0271: mv.visitLdcInsn("InnerRun state2: ");
0272: mv.visitMethodInsn(INVOKESPECIAL, "java/lang/StringBuilder", "<init>", "(Ljava/lang/String;)V");
0273: mv.visitVarInsn(ALOAD, 0);
0274: mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/concurrent/FutureTask$Sync", "getState", "()I");
0275: mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(I)Ljava/lang/StringBuilder;");
0276: mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;");
0277: mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V");
0278: */
0279: Label l23 = new Label();
0280: mv.visitLabel(l23);
0281: mv.visitVarInsn(ALOAD, 0);
0282: mv.visitMethodInsn(INVOKEVIRTUAL,
0283: "java/util/concurrent/FutureTask$Sync", "getState",
0284: "()I");
0285: mv.visitInsn(ICONST_1);
0286: Label l24 = new Label();
0287: mv.visitJumpInsn(IF_ICMPNE, l24);
0288: mv.visitInsn(ICONST_1);
0289: Label l25 = new Label();
0290: mv.visitJumpInsn(GOTO, l25);
0291: mv.visitLabel(l24);
0292: mv.visitInsn(ICONST_0);
0293: mv.visitLabel(l25);
0294: mv.visitVarInsn(ISTORE, 1);
0295: Label l26 = new Label();
0296: mv.visitLabel(l26);
0297: mv.visitVarInsn(ALOAD, 2);
0298: mv.visitInsn(MONITOREXIT);
0299: mv.visitLabel(l1);
0300: Label l27 = new Label();
0301: mv.visitJumpInsn(GOTO, l27);
0302: mv.visitLabel(l2);
0303: mv.visitVarInsn(ALOAD, 2);
0304: mv.visitInsn(MONITOREXIT);
0305: mv.visitLabel(l3);
0306: mv.visitInsn(ATHROW);
0307: mv.visitLabel(l27);
0308: mv.visitVarInsn(ILOAD, 1);
0309: Label l28 = new Label();
0310: mv.visitJumpInsn(IFEQ, l28);
0311: Label l29 = new Label();
0312: mv.visitLabel(l29);
0313: mv.visitVarInsn(ALOAD, 0);
0314: mv.visitFieldInsn(GETFIELD,
0315: "java/util/concurrent/FutureTask$Sync", "callable",
0316: "Ljava/util/concurrent/Callable;");
0317: mv.visitMethodInsn(INVOKEINTERFACE,
0318: "java/util/concurrent/Callable", "call",
0319: "()Ljava/lang/Object;");
0320: mv.visitVarInsn(ASTORE, 2);
0321: Label l30 = new Label();
0322: mv.visitLabel(l30);
0323: mv.visitVarInsn(ALOAD, 0);
0324: mv.visitFieldInsn(GETFIELD,
0325: "java/util/concurrent/FutureTask$Sync",
0326: "managedLock", "Ljava/lang/Object;");
0327: mv.visitInsn(DUP);
0328: mv.visitVarInsn(ASTORE, 3);
0329: mv.visitInsn(MONITORENTER);
0330: mv.visitLabel(l4);
0331: mv.visitVarInsn(ALOAD, 0);
0332: mv.visitVarInsn(ALOAD, 2);
0333: mv.visitMethodInsn(INVOKEVIRTUAL,
0334: "java/util/concurrent/FutureTask$Sync",
0335: "managedInnerSet", "(Ljava/lang/Object;)V");
0336: Label l31 = new Label();
0337: mv.visitLabel(l31);
0338: mv.visitVarInsn(ALOAD, 3);
0339: mv.visitInsn(MONITOREXIT);
0340: mv.visitLabel(l5);
0341: Label l32 = new Label();
0342: mv.visitJumpInsn(GOTO, l32);
0343: mv.visitLabel(l6);
0344: mv.visitVarInsn(ALOAD, 3);
0345: mv.visitInsn(MONITOREXIT);
0346: mv.visitLabel(l7);
0347: mv.visitInsn(ATHROW);
0348: mv.visitJumpInsn(GOTO, l32);
0349: mv.visitLabel(l28);
0350: mv.visitVarInsn(ALOAD, 0);
0351: mv.visitFieldInsn(GETFIELD,
0352: "java/util/concurrent/FutureTask$Sync",
0353: "managedLock", "Ljava/lang/Object;");
0354: mv.visitInsn(DUP);
0355: mv.visitVarInsn(ASTORE, 2);
0356: mv.visitInsn(MONITORENTER);
0357: mv.visitLabel(l8);
0358: mv.visitVarInsn(ALOAD, 0);
0359: mv.visitMethodInsn(INVOKESPECIAL,
0360: "java/util/concurrent/FutureTask$Sync",
0361: "managedTryReleaseShared", "()Z");
0362: mv.visitInsn(POP);
0363: Label l33 = new Label();
0364: mv.visitLabel(l33);
0365: mv.visitVarInsn(ALOAD, 2);
0366: mv.visitInsn(MONITOREXIT);
0367: mv.visitLabel(l9);
0368: mv.visitJumpInsn(GOTO, l32);
0369: mv.visitLabel(l10);
0370: mv.visitVarInsn(ALOAD, 2);
0371: mv.visitInsn(MONITOREXIT);
0372: mv.visitLabel(l11);
0373: mv.visitInsn(ATHROW);
0374: mv.visitJumpInsn(GOTO, l32);
0375: mv.visitLabel(l13);
0376: mv.visitVarInsn(ASTORE, 1);
0377: Label l34 = new Label();
0378: mv.visitLabel(l34);
0379: /*mv.visitFieldInsn(GETSTATIC, "java/lang/System", "err", "Ljava/io/PrintStream;");
0380: mv.visitLdcInsn("Catching Throwable in innerRun.");
0381: mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V");
0382: */
0383: Label l35 = new Label();
0384: mv.visitLabel(l35);
0385: mv.visitVarInsn(ALOAD, 0);
0386: mv.visitVarInsn(ALOAD, 1);
0387: mv.visitMethodInsn(INVOKEVIRTUAL,
0388: "java/util/concurrent/FutureTask$Sync",
0389: "innerSetException", "(Ljava/lang/Throwable;)V");
0390: Label l36 = new Label();
0391: mv.visitLabel(l36);
0392: mv.visitJumpInsn(GOTO, l32);
0393: mv.visitLabel(l14);
0394: mv.visitVarInsn(ALOAD, 0);
0395: mv.visitMethodInsn(INVOKESTATIC, "java/lang/Thread",
0396: "currentThread", "()Ljava/lang/Thread;");
0397: mv.visitFieldInsn(PUTFIELD,
0398: "java/util/concurrent/FutureTask$Sync", "runner",
0399: "Ljava/lang/Thread;");
0400: Label l37 = new Label();
0401: mv.visitLabel(l37);
0402: mv.visitVarInsn(ALOAD, 0);
0403: mv.visitVarInsn(ALOAD, 0);
0404: mv.visitFieldInsn(GETFIELD,
0405: "java/util/concurrent/FutureTask$Sync", "callable",
0406: "Ljava/util/concurrent/Callable;");
0407: mv.visitMethodInsn(INVOKEINTERFACE,
0408: "java/util/concurrent/Callable", "call",
0409: "()Ljava/lang/Object;");
0410: mv.visitMethodInsn(INVOKEVIRTUAL,
0411: "java/util/concurrent/FutureTask$Sync", "innerSet",
0412: "(Ljava/lang/Object;)V");
0413: mv.visitJumpInsn(GOTO, l32);
0414: mv.visitLabel(l15);
0415: mv.visitVarInsn(ASTORE, 1);
0416: Label l38 = new Label();
0417: mv.visitLabel(l38);
0418: mv.visitVarInsn(ALOAD, 0);
0419: mv.visitVarInsn(ALOAD, 1);
0420: mv.visitMethodInsn(INVOKEVIRTUAL,
0421: "java/util/concurrent/FutureTask$Sync",
0422: "innerSetException", "(Ljava/lang/Throwable;)V");
0423: mv.visitLabel(l32);
0424: mv.visitInsn(RETURN);
0425: Label l39 = new Label();
0426: mv.visitLabel(l39);
0427: mv.visitMaxs(0, 0);
0428: mv.visitEnd();
0429: return null;
0430: }
0431:
0432: private MethodVisitor rewriteInnerIsDoneMethod(MethodVisitor mv) {
0433: mv.visitCode();
0434: Label l0 = new Label();
0435: Label l1 = new Label();
0436: Label l2 = new Label();
0437: mv.visitTryCatchBlock(l0, l1, l2, null);
0438: Label l3 = new Label();
0439: mv.visitTryCatchBlock(l2, l3, l2, null);
0440: Label l4 = new Label();
0441: mv.visitLabel(l4);
0442: mv.visitVarInsn(ALOAD, 0);
0443: mv.visitFieldInsn(GETFIELD,
0444: "java/util/concurrent/FutureTask$Sync", "this$0",
0445: "Ljava/util/concurrent/FutureTask;");
0446: mv.visitMethodInsn(INVOKESTATIC,
0447: "com/tc/object/bytecode/ManagerUtil", "isManaged",
0448: "(Ljava/lang/Object;)Z");
0449: Label l5 = new Label();
0450: mv.visitJumpInsn(IFEQ, l5);
0451: Label l6 = new Label();
0452: mv.visitLabel(l6);
0453: mv.visitVarInsn(ALOAD, 0);
0454: mv.visitFieldInsn(GETFIELD,
0455: "java/util/concurrent/FutureTask$Sync",
0456: "managedLock", "Ljava/lang/Object;");
0457: mv.visitInsn(DUP);
0458: mv.visitVarInsn(ASTORE, 1);
0459: mv.visitInsn(MONITORENTER);
0460: mv.visitLabel(l0);
0461: mv.visitVarInsn(ALOAD, 0);
0462: mv.visitVarInsn(ALOAD, 0);
0463: mv.visitMethodInsn(INVOKEVIRTUAL,
0464: "java/util/concurrent/FutureTask$Sync", "getState",
0465: "()I");
0466: mv.visitMethodInsn(INVOKESPECIAL,
0467: "java/util/concurrent/FutureTask$Sync",
0468: "ranOrCancelled", "(I)Z");
0469: Label l7 = new Label();
0470: mv.visitJumpInsn(IFEQ, l7);
0471: mv.visitVarInsn(ALOAD, 0);
0472: mv.visitFieldInsn(GETFIELD,
0473: "java/util/concurrent/FutureTask$Sync",
0474: "proxyRunner", "Ljava/lang/Object;");
0475: mv.visitJumpInsn(IFNONNULL, l7);
0476: mv.visitInsn(ICONST_1);
0477: Label l8 = new Label();
0478: mv.visitJumpInsn(GOTO, l8);
0479: mv.visitLabel(l7);
0480: mv.visitInsn(ICONST_0);
0481: mv.visitLabel(l8);
0482: mv.visitVarInsn(ALOAD, 1);
0483: mv.visitInsn(MONITOREXIT);
0484: mv.visitLabel(l1);
0485: mv.visitInsn(IRETURN);
0486: mv.visitLabel(l2);
0487: mv.visitVarInsn(ALOAD, 1);
0488: mv.visitInsn(MONITOREXIT);
0489: mv.visitLabel(l3);
0490: mv.visitInsn(ATHROW);
0491: mv.visitLabel(l5);
0492: mv.visitVarInsn(ALOAD, 0);
0493: mv.visitVarInsn(ALOAD, 0);
0494: mv.visitMethodInsn(INVOKEVIRTUAL,
0495: "java/util/concurrent/FutureTask$Sync", "getState",
0496: "()I");
0497: mv.visitMethodInsn(INVOKESPECIAL,
0498: "java/util/concurrent/FutureTask$Sync",
0499: "ranOrCancelled", "(I)Z");
0500: Label l9 = new Label();
0501: mv.visitJumpInsn(IFEQ, l9);
0502: mv.visitVarInsn(ALOAD, 0);
0503: mv.visitFieldInsn(GETFIELD,
0504: "java/util/concurrent/FutureTask$Sync", "runner",
0505: "Ljava/lang/Thread;");
0506: mv.visitJumpInsn(IFNONNULL, l9);
0507: mv.visitInsn(ICONST_1);
0508: mv.visitInsn(IRETURN);
0509: mv.visitLabel(l9);
0510: mv.visitInsn(ICONST_0);
0511: mv.visitInsn(IRETURN);
0512: Label l10 = new Label();
0513: mv.visitLabel(l10);
0514: mv.visitMaxs(0, 0);
0515: mv.visitEnd();
0516: return null;
0517: }
0518:
0519: private MethodVisitor rewriteInnerSetExceptionMethod(
0520: MethodVisitor mv) {
0521: mv.visitCode();
0522: Label l0 = new Label();
0523: Label l1 = new Label();
0524: Label l2 = new Label();
0525: mv.visitTryCatchBlock(l0, l1, l2, null);
0526: Label l3 = new Label();
0527: Label l4 = new Label();
0528: mv.visitTryCatchBlock(l3, l4, l2, null);
0529: Label l5 = new Label();
0530: mv.visitTryCatchBlock(l2, l5, l2, null);
0531: Label l6 = new Label();
0532: Label l7 = new Label();
0533: Label l8 = new Label();
0534: mv.visitTryCatchBlock(l6, l7, l8, null);
0535: Label l9 = new Label();
0536: mv.visitTryCatchBlock(l8, l9, l8, null);
0537: Label l10 = new Label();
0538: mv.visitLabel(l10);
0539: mv.visitVarInsn(ALOAD, 0);
0540: mv.visitFieldInsn(GETFIELD,
0541: "java/util/concurrent/FutureTask$Sync", "this$0",
0542: "Ljava/util/concurrent/FutureTask;");
0543: mv.visitMethodInsn(INVOKESTATIC,
0544: "com/tc/object/bytecode/ManagerUtil", "isManaged",
0545: "(Ljava/lang/Object;)Z");
0546: Label l11 = new Label();
0547: mv.visitJumpInsn(IFEQ, l11);
0548: Label l12 = new Label();
0549: mv.visitLabel(l12);
0550: mv.visitVarInsn(ALOAD, 0);
0551: mv.visitFieldInsn(GETFIELD,
0552: "java/util/concurrent/FutureTask$Sync",
0553: "managedLock", "Ljava/lang/Object;");
0554: mv.visitInsn(DUP);
0555: mv.visitVarInsn(ASTORE, 2);
0556: mv.visitInsn(MONITORENTER);
0557: mv.visitLabel(l0);
0558: mv.visitVarInsn(ALOAD, 0);
0559: mv.visitMethodInsn(INVOKEVIRTUAL,
0560: "java/util/concurrent/FutureTask$Sync", "getState",
0561: "()I");
0562: mv.visitVarInsn(ISTORE, 3);
0563: Label l13 = new Label();
0564: mv.visitLabel(l13);
0565: mv.visitVarInsn(ALOAD, 0);
0566: mv.visitVarInsn(ILOAD, 3);
0567: mv.visitMethodInsn(INVOKESPECIAL,
0568: "java/util/concurrent/FutureTask$Sync",
0569: "ranOrCancelled", "(I)Z");
0570: mv.visitJumpInsn(IFEQ, l3);
0571: mv.visitVarInsn(ALOAD, 2);
0572: mv.visitInsn(MONITOREXIT);
0573: mv.visitLabel(l1);
0574: mv.visitInsn(RETURN);
0575: mv.visitLabel(l3);
0576: mv.visitVarInsn(ALOAD, 0);
0577: mv.visitInsn(ICONST_2);
0578: mv.visitMethodInsn(INVOKEVIRTUAL,
0579: "java/util/concurrent/FutureTask$Sync", "setState",
0580: "(I)V");
0581: Label l14 = new Label();
0582: mv.visitLabel(l14);
0583: mv.visitVarInsn(ALOAD, 0);
0584: mv.visitVarInsn(ALOAD, 1);
0585: mv.visitFieldInsn(PUTFIELD,
0586: "java/util/concurrent/FutureTask$Sync",
0587: "exception", "Ljava/lang/Throwable;");
0588: Label l15 = new Label();
0589: mv.visitLabel(l15);
0590: mv.visitVarInsn(ALOAD, 0);
0591: mv.visitInsn(ACONST_NULL);
0592: mv.visitFieldInsn(PUTFIELD,
0593: "java/util/concurrent/FutureTask$Sync", "result",
0594: "Ljava/lang/Object;");
0595: Label l16 = new Label();
0596: mv.visitLabel(l16);
0597: mv.visitVarInsn(ALOAD, 0);
0598: mv.visitMethodInsn(INVOKESPECIAL,
0599: "java/util/concurrent/FutureTask$Sync",
0600: "managedTryReleaseShared", "()Z");
0601: mv.visitInsn(POP);
0602: Label l17 = new Label();
0603: mv.visitLabel(l17);
0604: mv.visitVarInsn(ALOAD, 0);
0605: mv.visitFieldInsn(GETFIELD,
0606: "java/util/concurrent/FutureTask$Sync", "this$0",
0607: "Ljava/util/concurrent/FutureTask;");
0608: mv.visitMethodInsn(INVOKEVIRTUAL,
0609: "java/util/concurrent/FutureTask", "done", "()V");
0610: Label l18 = new Label();
0611: mv.visitLabel(l18);
0612: mv.visitVarInsn(ALOAD, 2);
0613: mv.visitInsn(MONITOREXIT);
0614: mv.visitLabel(l4);
0615: Label l19 = new Label();
0616: mv.visitJumpInsn(GOTO, l19);
0617: mv.visitLabel(l2);
0618: mv.visitVarInsn(ALOAD, 2);
0619: mv.visitInsn(MONITOREXIT);
0620: mv.visitLabel(l5);
0621: mv.visitInsn(ATHROW);
0622: Label l20 = new Label();
0623: mv.visitLabel(l20);
0624: mv.visitJumpInsn(GOTO, l19);
0625: mv.visitLabel(l11);
0626: mv.visitVarInsn(ALOAD, 0);
0627: mv.visitMethodInsn(INVOKEVIRTUAL,
0628: "java/util/concurrent/FutureTask$Sync", "getState",
0629: "()I");
0630: mv.visitVarInsn(ISTORE, 2);
0631: Label l21 = new Label();
0632: mv.visitLabel(l21);
0633: mv.visitVarInsn(ALOAD, 0);
0634: mv.visitVarInsn(ILOAD, 2);
0635: mv.visitMethodInsn(INVOKESPECIAL,
0636: "java/util/concurrent/FutureTask$Sync",
0637: "ranOrCancelled", "(I)Z");
0638: Label l22 = new Label();
0639: mv.visitJumpInsn(IFEQ, l22);
0640: mv.visitInsn(RETURN);
0641: mv.visitLabel(l22);
0642: mv.visitVarInsn(ALOAD, 0);
0643: mv.visitVarInsn(ILOAD, 2);
0644: mv.visitInsn(ICONST_2);
0645: mv.visitMethodInsn(INVOKEVIRTUAL,
0646: "java/util/concurrent/FutureTask$Sync",
0647: "compareAndSetState", "(II)Z");
0648: mv.visitJumpInsn(IFEQ, l11);
0649: Label l23 = new Label();
0650: mv.visitJumpInsn(GOTO, l23);
0651: Label l24 = new Label();
0652: mv.visitLabel(l24);
0653: mv.visitJumpInsn(GOTO, l11);
0654: mv.visitLabel(l23);
0655: mv.visitVarInsn(ALOAD, 0);
0656: mv.visitVarInsn(ALOAD, 1);
0657: mv.visitFieldInsn(PUTFIELD,
0658: "java/util/concurrent/FutureTask$Sync",
0659: "exception", "Ljava/lang/Throwable;");
0660: Label l25 = new Label();
0661: mv.visitLabel(l25);
0662: mv.visitVarInsn(ALOAD, 0);
0663: mv.visitInsn(ACONST_NULL);
0664: mv.visitFieldInsn(PUTFIELD,
0665: "java/util/concurrent/FutureTask$Sync", "result",
0666: "Ljava/lang/Object;");
0667: Label l26 = new Label();
0668: mv.visitLabel(l26);
0669: mv.visitVarInsn(ALOAD, 0);
0670: mv.visitFieldInsn(GETFIELD,
0671: "java/util/concurrent/FutureTask$Sync",
0672: "managedLock", "Ljava/lang/Object;");
0673: mv.visitInsn(DUP);
0674: mv.visitVarInsn(ASTORE, 2);
0675: mv.visitInsn(MONITORENTER);
0676: mv.visitLabel(l6);
0677: mv.visitVarInsn(ALOAD, 0);
0678: mv.visitInsn(ICONST_0);
0679: mv.visitMethodInsn(INVOKEVIRTUAL,
0680: "java/util/concurrent/FutureTask$Sync",
0681: "releaseShared", "(I)Z");
0682: mv.visitInsn(POP);
0683: Label l27 = new Label();
0684: mv.visitLabel(l27);
0685: mv.visitVarInsn(ALOAD, 2);
0686: mv.visitInsn(MONITOREXIT);
0687: mv.visitLabel(l7);
0688: Label l28 = new Label();
0689: mv.visitJumpInsn(GOTO, l28);
0690: mv.visitLabel(l8);
0691: mv.visitVarInsn(ALOAD, 2);
0692: mv.visitInsn(MONITOREXIT);
0693: mv.visitLabel(l9);
0694: mv.visitInsn(ATHROW);
0695: mv.visitLabel(l28);
0696: mv.visitVarInsn(ALOAD, 0);
0697: mv.visitFieldInsn(GETFIELD,
0698: "java/util/concurrent/FutureTask$Sync", "this$0",
0699: "Ljava/util/concurrent/FutureTask;");
0700: mv.visitMethodInsn(INVOKEVIRTUAL,
0701: "java/util/concurrent/FutureTask", "done", "()V");
0702: mv.visitLabel(l19);
0703: mv.visitInsn(RETURN);
0704: Label l29 = new Label();
0705: mv.visitLabel(l29);
0706: mv.visitMaxs(0, 0);
0707: mv.visitEnd();
0708: return null;
0709: }
0710:
0711: private MethodVisitor rewriteInnerSetMethod(MethodVisitor mv) {
0712: mv.visitCode();
0713: Label l0 = new Label();
0714: Label l1 = new Label();
0715: Label l2 = new Label();
0716: mv.visitTryCatchBlock(l0, l1, l2, null);
0717: Label l3 = new Label();
0718: mv.visitTryCatchBlock(l2, l3, l2, null);
0719: Label l4 = new Label();
0720: Label l5 = new Label();
0721: Label l6 = new Label();
0722: mv.visitTryCatchBlock(l4, l5, l6, null);
0723: Label l7 = new Label();
0724: mv.visitTryCatchBlock(l6, l7, l6, null);
0725: Label l8 = new Label();
0726: mv.visitLabel(l8);
0727: mv.visitVarInsn(ALOAD, 0);
0728: mv.visitFieldInsn(GETFIELD,
0729: "java/util/concurrent/FutureTask$Sync", "this$0",
0730: "Ljava/util/concurrent/FutureTask;");
0731: mv.visitMethodInsn(INVOKESTATIC,
0732: "com/tc/object/bytecode/ManagerUtil", "isManaged",
0733: "(Ljava/lang/Object;)Z");
0734: Label l9 = new Label();
0735: mv.visitJumpInsn(IFEQ, l9);
0736: Label l10 = new Label();
0737: mv.visitLabel(l10);
0738: mv.visitVarInsn(ALOAD, 0);
0739: mv.visitFieldInsn(GETFIELD,
0740: "java/util/concurrent/FutureTask$Sync",
0741: "managedLock", "Ljava/lang/Object;");
0742: mv.visitInsn(DUP);
0743: mv.visitVarInsn(ASTORE, 2);
0744: mv.visitInsn(MONITORENTER);
0745: mv.visitLabel(l0);
0746: mv.visitVarInsn(ALOAD, 0);
0747: mv.visitVarInsn(ALOAD, 1);
0748: mv.visitMethodInsn(INVOKEVIRTUAL,
0749: "java/util/concurrent/FutureTask$Sync",
0750: "managedInnerSet", "(Ljava/lang/Object;)V");
0751: Label l11 = new Label();
0752: mv.visitLabel(l11);
0753: mv.visitVarInsn(ALOAD, 2);
0754: mv.visitInsn(MONITOREXIT);
0755: mv.visitLabel(l1);
0756: Label l12 = new Label();
0757: mv.visitJumpInsn(GOTO, l12);
0758: mv.visitLabel(l2);
0759: mv.visitVarInsn(ALOAD, 2);
0760: mv.visitInsn(MONITOREXIT);
0761: mv.visitLabel(l3);
0762: mv.visitInsn(ATHROW);
0763: mv.visitJumpInsn(GOTO, l12);
0764: mv.visitLabel(l9);
0765: mv.visitVarInsn(ALOAD, 0);
0766: mv.visitMethodInsn(INVOKEVIRTUAL,
0767: "java/util/concurrent/FutureTask$Sync", "getState",
0768: "()I");
0769: mv.visitVarInsn(ISTORE, 2);
0770: Label l13 = new Label();
0771: mv.visitLabel(l13);
0772: mv.visitVarInsn(ALOAD, 0);
0773: mv.visitVarInsn(ILOAD, 2);
0774: mv.visitMethodInsn(INVOKESPECIAL,
0775: "java/util/concurrent/FutureTask$Sync",
0776: "ranOrCancelled", "(I)Z");
0777: Label l14 = new Label();
0778: mv.visitJumpInsn(IFEQ, l14);
0779: mv.visitInsn(RETURN);
0780: mv.visitLabel(l14);
0781: mv.visitVarInsn(ALOAD, 0);
0782: mv.visitVarInsn(ILOAD, 2);
0783: mv.visitInsn(ICONST_2);
0784: mv.visitMethodInsn(INVOKEVIRTUAL,
0785: "java/util/concurrent/FutureTask$Sync",
0786: "compareAndSetState", "(II)Z");
0787: mv.visitJumpInsn(IFEQ, l9);
0788: Label l15 = new Label();
0789: mv.visitJumpInsn(GOTO, l15);
0790: Label l16 = new Label();
0791: mv.visitLabel(l16);
0792: mv.visitJumpInsn(GOTO, l9);
0793: mv.visitLabel(l15);
0794: mv.visitVarInsn(ALOAD, 0);
0795: mv.visitVarInsn(ALOAD, 1);
0796: mv.visitFieldInsn(PUTFIELD,
0797: "java/util/concurrent/FutureTask$Sync", "result",
0798: "Ljava/lang/Object;");
0799: Label l17 = new Label();
0800: mv.visitLabel(l17);
0801: mv.visitVarInsn(ALOAD, 0);
0802: mv.visitFieldInsn(GETFIELD,
0803: "java/util/concurrent/FutureTask$Sync",
0804: "managedLock", "Ljava/lang/Object;");
0805: mv.visitInsn(DUP);
0806: mv.visitVarInsn(ASTORE, 2);
0807: mv.visitInsn(MONITORENTER);
0808: mv.visitLabel(l4);
0809: mv.visitVarInsn(ALOAD, 0);
0810: mv.visitInsn(ICONST_0);
0811: mv.visitMethodInsn(INVOKEVIRTUAL,
0812: "java/util/concurrent/FutureTask$Sync",
0813: "releaseShared", "(I)Z");
0814: mv.visitInsn(POP);
0815: Label l18 = new Label();
0816: mv.visitLabel(l18);
0817: mv.visitVarInsn(ALOAD, 2);
0818: mv.visitInsn(MONITOREXIT);
0819: mv.visitLabel(l5);
0820: Label l19 = new Label();
0821: mv.visitJumpInsn(GOTO, l19);
0822: mv.visitLabel(l6);
0823: mv.visitVarInsn(ALOAD, 2);
0824: mv.visitInsn(MONITOREXIT);
0825: mv.visitLabel(l7);
0826: mv.visitInsn(ATHROW);
0827: mv.visitLabel(l19);
0828: mv.visitVarInsn(ALOAD, 0);
0829: mv.visitFieldInsn(GETFIELD,
0830: "java/util/concurrent/FutureTask$Sync", "this$0",
0831: "Ljava/util/concurrent/FutureTask;");
0832: mv.visitMethodInsn(INVOKEVIRTUAL,
0833: "java/util/concurrent/FutureTask", "done", "()V");
0834: mv.visitLabel(l12);
0835: mv.visitInsn(RETURN);
0836: Label l20 = new Label();
0837: mv.visitLabel(l20);
0838: mv.visitMaxs(0, 0);
0839: mv.visitEnd();
0840: return null;
0841: }
0842:
0843: private MethodVisitor rewriteTimedInnerGetMethod(
0844: MethodVisitor mv) {
0845: mv.visitCode();
0846: Label l0 = new Label();
0847: Label l1 = new Label();
0848: Label l2 = new Label();
0849: mv.visitTryCatchBlock(l0, l1, l2, null);
0850: Label l3 = new Label();
0851: mv.visitTryCatchBlock(l2, l3, l2, null);
0852: Label l4 = new Label();
0853: mv.visitLabel(l4);
0854: mv.visitVarInsn(ALOAD, 0);
0855: mv.visitFieldInsn(GETFIELD,
0856: "java/util/concurrent/FutureTask$Sync", "this$0",
0857: "Ljava/util/concurrent/FutureTask;");
0858: mv.visitMethodInsn(INVOKESTATIC,
0859: "com/tc/object/bytecode/ManagerUtil", "isManaged",
0860: "(Ljava/lang/Object;)Z");
0861: Label l5 = new Label();
0862: mv.visitJumpInsn(IFEQ, l5);
0863: Label l6 = new Label();
0864: mv.visitLabel(l6);
0865: mv.visitVarInsn(ALOAD, 0);
0866: mv.visitFieldInsn(GETFIELD,
0867: "java/util/concurrent/FutureTask$Sync",
0868: "managedLock", "Ljava/lang/Object;");
0869: mv.visitInsn(DUP);
0870: mv.visitVarInsn(ASTORE, 3);
0871: mv.visitInsn(MONITORENTER);
0872: mv.visitLabel(l0);
0873: mv.visitMethodInsn(INVOKESTATIC, "java/lang/System",
0874: "nanoTime", "()J");
0875: mv.visitVarInsn(LSTORE, 4);
0876: Label l7 = new Label();
0877: mv.visitLabel(l7);
0878: Label l8 = new Label();
0879: mv.visitJumpInsn(GOTO, l8);
0880: Label l9 = new Label();
0881: mv.visitLabel(l9);
0882: mv.visitFieldInsn(GETSTATIC,
0883: "java/util/concurrent/TimeUnit", "NANOSECONDS",
0884: "Ljava/util/concurrent/TimeUnit;");
0885: mv.visitVarInsn(ALOAD, 0);
0886: mv.visitFieldInsn(GETFIELD,
0887: "java/util/concurrent/FutureTask$Sync",
0888: "managedLock", "Ljava/lang/Object;");
0889: mv.visitVarInsn(LLOAD, 1);
0890: mv.visitMethodInsn(INVOKEVIRTUAL,
0891: "java/util/concurrent/TimeUnit", "timedWait",
0892: "(Ljava/lang/Object;J)V");
0893: Label l10 = new Label();
0894: mv.visitLabel(l10);
0895: mv.visitMethodInsn(INVOKESTATIC, "java/lang/System",
0896: "nanoTime", "()J");
0897: mv.visitVarInsn(LSTORE, 6);
0898: Label l11 = new Label();
0899: mv.visitLabel(l11);
0900: mv.visitVarInsn(LLOAD, 1);
0901: mv.visitVarInsn(LLOAD, 6);
0902: mv.visitVarInsn(LLOAD, 4);
0903: mv.visitInsn(LSUB);
0904: mv.visitInsn(LSUB);
0905: mv.visitVarInsn(LSTORE, 1);
0906: mv.visitLabel(l8);
0907: mv.visitVarInsn(ALOAD, 0);
0908: mv.visitInsn(ICONST_0);
0909: mv.visitMethodInsn(INVOKEVIRTUAL,
0910: "java/util/concurrent/FutureTask$Sync",
0911: "tryAcquireShared", "(I)I");
0912: Label l12 = new Label();
0913: mv.visitJumpInsn(IFGE, l12);
0914: mv.visitVarInsn(LLOAD, 1);
0915: mv.visitInsn(LCONST_0);
0916: mv.visitInsn(LCMP);
0917: mv.visitJumpInsn(IFGT, l9);
0918: mv.visitLabel(l12);
0919: mv.visitVarInsn(ALOAD, 0);
0920: mv.visitInsn(ICONST_0);
0921: mv.visitMethodInsn(INVOKEVIRTUAL,
0922: "java/util/concurrent/FutureTask$Sync",
0923: "tryAcquireShared", "(I)I");
0924: Label l13 = new Label();
0925: mv.visitJumpInsn(IFGE, l13);
0926: mv.visitTypeInsn(NEW,
0927: "java/util/concurrent/TimeoutException");
0928: mv.visitInsn(DUP);
0929: mv.visitMethodInsn(INVOKESPECIAL,
0930: "java/util/concurrent/TimeoutException", "<init>",
0931: "()V");
0932: mv.visitInsn(ATHROW);
0933: mv.visitLabel(l13);
0934: mv.visitVarInsn(ALOAD, 3);
0935: mv.visitInsn(MONITOREXIT);
0936: mv.visitLabel(l1);
0937: Label l14 = new Label();
0938: mv.visitJumpInsn(GOTO, l14);
0939: mv.visitLabel(l2);
0940: mv.visitVarInsn(ALOAD, 3);
0941: mv.visitInsn(MONITOREXIT);
0942: mv.visitLabel(l3);
0943: mv.visitInsn(ATHROW);
0944: Label l15 = new Label();
0945: mv.visitLabel(l15);
0946: mv.visitJumpInsn(GOTO, l14);
0947: mv.visitLabel(l5);
0948: mv.visitVarInsn(ALOAD, 0);
0949: mv.visitInsn(ICONST_0);
0950: mv.visitVarInsn(LLOAD, 1);
0951: mv.visitMethodInsn(INVOKEVIRTUAL,
0952: "java/util/concurrent/FutureTask$Sync",
0953: "tryAcquireSharedNanos", "(IJ)Z");
0954: mv.visitJumpInsn(IFNE, l14);
0955: mv.visitTypeInsn(NEW,
0956: "java/util/concurrent/TimeoutException");
0957: mv.visitInsn(DUP);
0958: mv.visitMethodInsn(INVOKESPECIAL,
0959: "java/util/concurrent/TimeoutException", "<init>",
0960: "()V");
0961: mv.visitInsn(ATHROW);
0962: mv.visitLabel(l14);
0963: mv.visitVarInsn(ALOAD, 0);
0964: mv.visitMethodInsn(INVOKEVIRTUAL,
0965: "java/util/concurrent/FutureTask$Sync", "getState",
0966: "()I");
0967: mv.visitInsn(ICONST_4);
0968: Label l16 = new Label();
0969: mv.visitJumpInsn(IF_ICMPNE, l16);
0970: mv.visitTypeInsn(NEW,
0971: "java/util/concurrent/CancellationException");
0972: mv.visitInsn(DUP);
0973: mv.visitMethodInsn(INVOKESPECIAL,
0974: "java/util/concurrent/CancellationException",
0975: "<init>", "()V");
0976: mv.visitInsn(ATHROW);
0977: mv.visitLabel(l16);
0978: mv.visitVarInsn(ALOAD, 0);
0979: mv.visitFieldInsn(GETFIELD,
0980: "java/util/concurrent/FutureTask$Sync",
0981: "exception", "Ljava/lang/Throwable;");
0982: Label l17 = new Label();
0983: mv.visitJumpInsn(IFNULL, l17);
0984: mv.visitTypeInsn(NEW,
0985: "java/util/concurrent/ExecutionException");
0986: mv.visitInsn(DUP);
0987: mv.visitVarInsn(ALOAD, 0);
0988: mv.visitFieldInsn(GETFIELD,
0989: "java/util/concurrent/FutureTask$Sync",
0990: "exception", "Ljava/lang/Throwable;");
0991: mv.visitMethodInsn(INVOKESPECIAL,
0992: "java/util/concurrent/ExecutionException",
0993: "<init>", "(Ljava/lang/Throwable;)V");
0994: mv.visitInsn(ATHROW);
0995: mv.visitLabel(l17);
0996: mv.visitVarInsn(ALOAD, 0);
0997: mv.visitFieldInsn(GETFIELD,
0998: "java/util/concurrent/FutureTask$Sync", "result",
0999: "Ljava/lang/Object;");
1000: mv.visitInsn(ARETURN);
1001: Label l18 = new Label();
1002: mv.visitLabel(l18);
1003: mv.visitMaxs(0, 0);
1004: mv.visitEnd();
1005: return null;
1006: }
1007:
1008: private MethodVisitor rewriteInnerGetMethod(MethodVisitor mv) {
1009: mv.visitCode();
1010: Label l0 = new Label();
1011: Label l1 = new Label();
1012: Label l2 = new Label();
1013: mv.visitTryCatchBlock(l0, l1, l2, null);
1014: Label l3 = new Label();
1015: mv.visitTryCatchBlock(l2, l3, l2, null);
1016: Label l4 = new Label();
1017: mv.visitLabel(l4);
1018: mv.visitVarInsn(ALOAD, 0);
1019: mv.visitFieldInsn(GETFIELD,
1020: "java/util/concurrent/FutureTask$Sync", "this$0",
1021: "Ljava/util/concurrent/FutureTask;");
1022: mv.visitMethodInsn(INVOKESTATIC,
1023: "com/tc/object/bytecode/ManagerUtil", "isManaged",
1024: "(Ljava/lang/Object;)Z");
1025: Label l5 = new Label();
1026: mv.visitJumpInsn(IFEQ, l5);
1027: Label l6 = new Label();
1028: mv.visitLabel(l6);
1029: mv.visitVarInsn(ALOAD, 0);
1030: mv.visitFieldInsn(GETFIELD,
1031: "java/util/concurrent/FutureTask$Sync",
1032: MANAGED_OBJECT_LOCK_FIELD_NAME,
1033: "Ljava/lang/Object;");
1034: mv.visitInsn(DUP);
1035: mv.visitVarInsn(ASTORE, 1);
1036: mv.visitInsn(MONITORENTER);
1037: mv.visitLabel(l0);
1038: Label l7 = new Label();
1039: mv.visitJumpInsn(GOTO, l7);
1040: Label l8 = new Label();
1041: mv.visitLabel(l8);
1042: mv.visitVarInsn(ALOAD, 0);
1043: mv.visitFieldInsn(GETFIELD,
1044: "java/util/concurrent/FutureTask$Sync",
1045: MANAGED_OBJECT_LOCK_FIELD_NAME,
1046: "Ljava/lang/Object;");
1047: mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object",
1048: "wait", "()V");
1049: mv.visitLabel(l7);
1050: mv.visitVarInsn(ALOAD, 0);
1051: mv.visitInsn(ICONST_0);
1052: mv.visitMethodInsn(INVOKEVIRTUAL,
1053: "java/util/concurrent/FutureTask$Sync",
1054: "tryAcquireShared", "(I)I");
1055: mv.visitJumpInsn(IFLT, l8);
1056: Label l9 = new Label();
1057: mv.visitLabel(l9);
1058: mv.visitVarInsn(ALOAD, 1);
1059: mv.visitInsn(MONITOREXIT);
1060: mv.visitLabel(l1);
1061: Label l10 = new Label();
1062: mv.visitJumpInsn(GOTO, l10);
1063: mv.visitLabel(l2);
1064: mv.visitVarInsn(ALOAD, 1);
1065: mv.visitInsn(MONITOREXIT);
1066: mv.visitLabel(l3);
1067: mv.visitInsn(ATHROW);
1068: mv.visitJumpInsn(GOTO, l10);
1069: mv.visitLabel(l5);
1070: mv.visitVarInsn(ALOAD, 0);
1071: mv.visitInsn(ICONST_0);
1072: mv.visitMethodInsn(INVOKEVIRTUAL,
1073: "java/util/concurrent/FutureTask$Sync",
1074: "acquireSharedInterruptibly", "(I)V");
1075: mv.visitLabel(l10);
1076: mv.visitVarInsn(ALOAD, 0);
1077: mv.visitMethodInsn(INVOKEVIRTUAL,
1078: "java/util/concurrent/FutureTask$Sync", "getState",
1079: "()I");
1080: mv.visitInsn(ICONST_4);
1081: Label l11 = new Label();
1082: mv.visitJumpInsn(IF_ICMPNE, l11);
1083: mv.visitTypeInsn(NEW,
1084: "java/util/concurrent/CancellationException");
1085: mv.visitInsn(DUP);
1086: mv.visitMethodInsn(INVOKESPECIAL,
1087: "java/util/concurrent/CancellationException",
1088: "<init>", "()V");
1089: mv.visitInsn(ATHROW);
1090: mv.visitLabel(l11);
1091: mv.visitVarInsn(ALOAD, 0);
1092: mv.visitFieldInsn(GETFIELD,
1093: "java/util/concurrent/FutureTask$Sync",
1094: "exception", "Ljava/lang/Throwable;");
1095: Label l12 = new Label();
1096: mv.visitJumpInsn(IFNULL, l12);
1097: mv.visitTypeInsn(NEW,
1098: "java/util/concurrent/ExecutionException");
1099: mv.visitInsn(DUP);
1100: mv.visitVarInsn(ALOAD, 0);
1101: mv.visitFieldInsn(GETFIELD,
1102: "java/util/concurrent/FutureTask$Sync",
1103: "exception", "Ljava/lang/Throwable;");
1104: mv.visitMethodInsn(INVOKESPECIAL,
1105: "java/util/concurrent/ExecutionException",
1106: "<init>", "(Ljava/lang/Throwable;)V");
1107: mv.visitInsn(ATHROW);
1108: mv.visitLabel(l12);
1109: mv.visitVarInsn(ALOAD, 0);
1110: mv.visitFieldInsn(GETFIELD,
1111: "java/util/concurrent/FutureTask$Sync", "result",
1112: "Ljava/lang/Object;");
1113: mv.visitInsn(ARETURN);
1114: Label l13 = new Label();
1115: mv.visitLabel(l13);
1116: mv.visitMaxs(0, 0);
1117: mv.visitEnd();
1118: return null;
1119: }
1120:
1121: private MethodVisitor rewriteInnerCancelMethod(MethodVisitor mv) {
1122: mv.visitCode();
1123: Label l0 = new Label();
1124: Label l1 = new Label();
1125: Label l2 = new Label();
1126: mv.visitTryCatchBlock(l0, l1, l2, null);
1127: Label l3 = new Label();
1128: mv.visitTryCatchBlock(l2, l3, l2, null);
1129: Label l4 = new Label();
1130: Label l5 = new Label();
1131: Label l6 = new Label();
1132: mv.visitTryCatchBlock(l4, l5, l6, null);
1133: Label l7 = new Label();
1134: mv.visitTryCatchBlock(l6, l7, l6, null);
1135: Label l8 = new Label();
1136: mv.visitLabel(l8);
1137: mv.visitInsn(ICONST_M1);
1138: mv.visitVarInsn(ISTORE, 2);
1139: Label l9 = new Label();
1140: mv.visitLabel(l9);
1141: mv.visitVarInsn(ALOAD, 0);
1142: mv.visitFieldInsn(GETFIELD,
1143: "java/util/concurrent/FutureTask$Sync",
1144: "managedLock", "Ljava/lang/Object;");
1145: mv.visitInsn(DUP);
1146: mv.visitVarInsn(ASTORE, 3);
1147: mv.visitInsn(MONITORENTER);
1148: mv.visitLabel(l0);
1149: mv.visitVarInsn(ALOAD, 0);
1150: mv.visitMethodInsn(INVOKEVIRTUAL,
1151: "java/util/concurrent/FutureTask$Sync", "getState",
1152: "()I");
1153: mv.visitVarInsn(ISTORE, 2);
1154: Label l10 = new Label();
1155: mv.visitLabel(l10);
1156: mv.visitVarInsn(ALOAD, 3);
1157: mv.visitInsn(MONITOREXIT);
1158: mv.visitLabel(l1);
1159: Label l11 = new Label();
1160: mv.visitJumpInsn(GOTO, l11);
1161: mv.visitLabel(l2);
1162: mv.visitVarInsn(ALOAD, 3);
1163: mv.visitInsn(MONITOREXIT);
1164: mv.visitLabel(l3);
1165: mv.visitInsn(ATHROW);
1166: mv.visitLabel(l11);
1167: mv.visitVarInsn(ALOAD, 0);
1168: mv.visitVarInsn(ILOAD, 2);
1169: mv.visitMethodInsn(INVOKESPECIAL,
1170: "java/util/concurrent/FutureTask$Sync",
1171: "ranOrCancelled", "(I)Z");
1172: Label l12 = new Label();
1173: mv.visitJumpInsn(IFEQ, l12);
1174: mv.visitInsn(ICONST_0);
1175: mv.visitInsn(IRETURN);
1176: mv.visitLabel(l12);
1177: mv.visitVarInsn(ALOAD, 0);
1178: mv.visitVarInsn(ILOAD, 2);
1179: mv.visitInsn(ICONST_4);
1180: mv.visitMethodInsn(INVOKEVIRTUAL,
1181: "java/util/concurrent/FutureTask$Sync",
1182: "compareAndSetState", "(II)Z");
1183: mv.visitJumpInsn(IFEQ, l8);
1184: Label l13 = new Label();
1185: mv.visitJumpInsn(GOTO, l13);
1186: Label l14 = new Label();
1187: mv.visitLabel(l14);
1188: mv.visitJumpInsn(GOTO, l8);
1189: mv.visitLabel(l13);
1190: mv.visitVarInsn(ALOAD, 0);
1191: mv.visitFieldInsn(GETFIELD,
1192: "java/util/concurrent/FutureTask$Sync",
1193: "managedLock", "Ljava/lang/Object;");
1194: mv.visitInsn(DUP);
1195: mv.visitVarInsn(ASTORE, 2);
1196: mv.visitInsn(MONITORENTER);
1197: mv.visitLabel(l4);
1198: mv.visitVarInsn(ILOAD, 1);
1199: Label l15 = new Label();
1200: mv.visitJumpInsn(IFEQ, l15);
1201: Label l16 = new Label();
1202: mv.visitLabel(l16);
1203: mv.visitVarInsn(ALOAD, 0);
1204: mv.visitMethodInsn(INVOKESPECIAL,
1205: "java/util/concurrent/FutureTask$Sync",
1206: "managedInnerCancel", "()V");
1207: mv.visitLabel(l15);
1208: mv.visitVarInsn(ALOAD, 0);
1209: mv.visitInsn(ICONST_0);
1210: mv.visitMethodInsn(INVOKEVIRTUAL,
1211: "java/util/concurrent/FutureTask$Sync",
1212: "releaseShared", "(I)Z");
1213: mv.visitInsn(POP);
1214: Label l17 = new Label();
1215: mv.visitLabel(l17);
1216: mv.visitVarInsn(ALOAD, 2);
1217: mv.visitInsn(MONITOREXIT);
1218: mv.visitLabel(l5);
1219: Label l18 = new Label();
1220: mv.visitJumpInsn(GOTO, l18);
1221: mv.visitLabel(l6);
1222: mv.visitVarInsn(ALOAD, 2);
1223: mv.visitInsn(MONITOREXIT);
1224: mv.visitLabel(l7);
1225: mv.visitInsn(ATHROW);
1226: mv.visitLabel(l18);
1227: mv.visitVarInsn(ALOAD, 0);
1228: mv.visitFieldInsn(GETFIELD,
1229: "java/util/concurrent/FutureTask$Sync", "this$0",
1230: "Ljava/util/concurrent/FutureTask;");
1231: mv.visitMethodInsn(INVOKEVIRTUAL,
1232: "java/util/concurrent/FutureTask", "done", "()V");
1233: Label l19 = new Label();
1234: mv.visitLabel(l19);
1235: mv.visitInsn(ICONST_1);
1236: mv.visitInsn(IRETURN);
1237: Label l20 = new Label();
1238: mv.visitLabel(l20);
1239: mv.visitMaxs(0, 0);
1240: mv.visitEnd();
1241: return null;
1242: }
1243:
1244: private void addManagedTryReleaseSharedMethod() {
1245: MethodVisitor mv = cv.visitMethod(ACC_PRIVATE,
1246: MANAGED_TRY_RELEASE_SHARED_METHOD, "()Z", null,
1247: null);
1248: mv.visitCode();
1249: Label l0 = new Label();
1250: mv.visitLabel(l0);
1251: mv.visitVarInsn(ALOAD, 0);
1252: mv.visitInsn(ACONST_NULL);
1253: mv.visitFieldInsn(PUTFIELD,
1254: "java/util/concurrent/FutureTask$Sync", "runner",
1255: "Ljava/lang/Thread;");
1256: Label l1 = new Label();
1257: mv.visitLabel(l1);
1258: mv.visitVarInsn(ALOAD, 0);
1259: mv.visitInsn(ACONST_NULL);
1260: mv.visitFieldInsn(PUTFIELD,
1261: "java/util/concurrent/FutureTask$Sync",
1262: PROXY_RUNNER_FIELD_NAME, "Ljava/lang/Object;");
1263: Label l2 = new Label();
1264: mv.visitLabel(l2);
1265: mv.visitVarInsn(ALOAD, 0);
1266: mv.visitFieldInsn(GETFIELD,
1267: "java/util/concurrent/FutureTask$Sync",
1268: MANAGED_OBJECT_LOCK_FIELD_NAME,
1269: "Ljava/lang/Object;");
1270: mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object",
1271: "notifyAll", "()V");
1272: Label l3 = new Label();
1273: mv.visitLabel(l3);
1274: mv.visitInsn(ICONST_1);
1275: mv.visitInsn(IRETURN);
1276: Label l4 = new Label();
1277: mv.visitLabel(l4);
1278: mv.visitMaxs(0, 0);
1279: mv.visitEnd();
1280: }
1281:
1282: private void addManagedInnerCancelMethod() {
1283: MethodVisitor mv = cv.visitMethod(ACC_PRIVATE
1284: + ACC_SYNTHETIC, MAANGED_INNER_CANCEL_METHOD_NAME,
1285: "()V", null, null);
1286: mv.visitCode();
1287: Label l0 = new Label();
1288: mv.visitLabel(l0);
1289: /*mv.visitFieldInsn(GETSTATIC, "java/lang/System", "err", "Ljava/io/PrintStream;");
1290: mv.visitTypeInsn(NEW, "java/lang/StringBuilder");
1291: mv.visitInsn(DUP);
1292: mv.visitLdcInsn("Running managedInnerCancel: ");
1293: mv.visitMethodInsn(INVOKESPECIAL, "java/lang/StringBuilder", "<init>", "(Ljava/lang/String;)V");
1294: mv.visitVarInsn(ALOAD, 0);
1295: mv.visitFieldInsn(GETFIELD, "java/util/concurrent/FutureTask$Sync", "runner", "Ljava/lang/Thread;");
1296: mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/Object;)Ljava/lang/StringBuilder;");
1297: mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;");
1298: mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V");
1299:
1300: Label l1 = new Label();
1301: mv.visitLabel(l1);
1302: mv.visitTypeInsn(NEW, "java/lang/Exception");
1303: mv.visitInsn(DUP);
1304: mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Exception", "<init>", "()V");
1305: mv.visitFieldInsn(GETSTATIC, "java/lang/System", "err", "Ljava/io/PrintStream;");
1306: mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Exception", "printStackTrace", "(Ljava/io/PrintStream;)V");
1307: */
1308: Label l2 = new Label();
1309: mv.visitLabel(l2);
1310: mv.visitVarInsn(ALOAD, 0);
1311: mv.visitFieldInsn(GETFIELD,
1312: "java/util/concurrent/FutureTask$Sync", "runner",
1313: "Ljava/lang/Thread;");
1314: mv.visitVarInsn(ASTORE, 1);
1315: Label l3 = new Label();
1316: mv.visitLabel(l3);
1317: mv.visitVarInsn(ALOAD, 1);
1318: Label l4 = new Label();
1319: mv.visitJumpInsn(IFNULL, l4);
1320: Label l5 = new Label();
1321: mv.visitLabel(l5);
1322: mv.visitVarInsn(ALOAD, 1);
1323: mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Thread",
1324: "interrupt", "()V");
1325: mv.visitLabel(l4);
1326: mv.visitInsn(RETURN);
1327: Label l6 = new Label();
1328: mv.visitLabel(l6);
1329: mv.visitMaxs(0, 0);
1330: mv.visitEnd();
1331: }
1332:
1333: private static class Constructor extends MethodAdapter
1334: implements Opcodes {
1335: public Constructor(MethodVisitor mv) {
1336: super (mv);
1337: }
1338:
1339: public void visitFieldInsn(int opcode, String owner,
1340: String name, String desc) {
1341: super .visitFieldInsn(opcode, owner, name, desc);
1342: if (PUTFIELD == opcode
1343: && "java/util/concurrent/FutureTask$Sync"
1344: .equals(owner)
1345: && "callable".equals(name)
1346: && "Ljava/util/concurrent/Callable;"
1347: .equals(desc)) {
1348: mv.visitVarInsn(ALOAD, 0);
1349: mv.visitTypeInsn(NEW, "java/lang/Object");
1350: mv.visitInsn(DUP);
1351: mv.visitMethodInsn(INVOKESPECIAL,
1352: "java/lang/Object", "<init>", "()V");
1353: mv.visitFieldInsn(PUTFIELD,
1354: "java/util/concurrent/FutureTask$Sync",
1355: MANAGED_OBJECT_LOCK_FIELD_NAME,
1356: "Ljava/lang/Object;");
1357:
1358: }
1359: }
1360: }
1361: }
1362: }
|