1 4 package com.tc.object.bytecode; 5 6 7 import com.tc.asm.ClassVisitor; 8 import com.tc.asm.Label; 9 import com.tc.asm.MethodAdapter; 10 import com.tc.asm.MethodVisitor; 11 import com.tc.asm.Opcodes; 12 13 public class THashMapAdapter { 14 15 public static class TransformValuesAdapter extends AbstractMethodAdapter { 16 private final static String STATIC_EXECUTE_DESC = "(Lgnu/trove/TObjectFunction;Ljava/lang/Object;Lgnu/trove/THashMap;Ljava/lang/Object;)Ljava/lang/Object;"; 17 18 public MethodVisitor adapt(ClassVisitor classVisitor) { 19 addStaticExecuteMethod(classVisitor); 20 MethodVisitor mv = visitOriginal(classVisitor); 21 return new Adapter(mv); 22 } 23 24 private void addStaticExecuteMethod(ClassVisitor cv) { 25 MethodVisitor mv = cv.visitMethod(ACC_PRIVATE + ACC_STATIC + ACC_SYNTHETIC, "execute", STATIC_EXECUTE_DESC, null, null); 26 mv.visitCode(); 27 Label l0 = new Label(); 28 mv.visitLabel(l0); 29 mv.visitLineNumber(468, l0); 30 mv.visitVarInsn(ALOAD, 0); 31 mv.visitVarInsn(ALOAD, 1); 32 mv.visitMethodInsn(INVOKEINTERFACE, "gnu/trove/TObjectFunction", "execute", "(Ljava/lang/Object;)Ljava/lang/Object;"); 33 mv.visitVarInsn(ASTORE, 4); 34 Label l1 = new Label(); 35 mv.visitLabel(l1); 36 mv.visitLineNumber(469, l1); 37 mv.visitVarInsn(ALOAD, 4); 38 mv.visitVarInsn(ALOAD, 1); 39 mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object", "equals", "(Ljava/lang/Object;)Z"); 40 Label l2 = new Label(); 41 mv.visitJumpInsn(IFNE, l2); 42 Label l3 = new Label(); 43 mv.visitLabel(l3); 44 mv.visitLineNumber(470, l3); 45 mv.visitVarInsn(ALOAD, 2); 46 mv.visitLdcInsn("put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); 47 mv.visitInsn(ICONST_2); 48 mv.visitTypeInsn(ANEWARRAY, "java/lang/Object"); 49 mv.visitInsn(DUP); 50 mv.visitInsn(ICONST_0); 51 mv.visitVarInsn(ALOAD, 3); 52 mv.visitInsn(AASTORE); 53 mv.visitInsn(DUP); 54 mv.visitInsn(ICONST_1); 55 mv.visitVarInsn(ALOAD, 4); 56 mv.visitInsn(AASTORE); 57 mv.visitMethodInsn(INVOKESTATIC, "com/tc/object/bytecode/ManagerUtil", "logicalInvoke", "(Ljava/lang/Object;Ljava/lang/String;[Ljava/lang/Object;)V"); 58 mv.visitLabel(l2); 59 mv.visitLineNumber(472, l2); 60 mv.visitVarInsn(ALOAD, 4); 61 mv.visitInsn(ARETURN); 62 Label l4 = new Label(); 63 mv.visitLabel(l4); 64 mv.visitMaxs(0, 0); 65 mv.visitEnd(); 66 } 67 68 public boolean doesOriginalNeedAdapting() { 69 return false; 70 } 71 72 private static class Adapter extends MethodAdapter implements Opcodes { 73 74 public Adapter(MethodVisitor mv) { 75 super(mv); 76 } 77 78 public void visitCode() { 79 super.visitCode(); 80 ByteCodeUtil.pushThis(mv); 81 mv.visitMethodInsn(INVOKEVIRTUAL, "gnu/trove/THashMap", "__tc_managed", "()Lcom/tc/object/TCObject;"); 82 Label l1 = new Label(); 83 mv.visitJumpInsn(IFNULL, l1); 84 ByteCodeUtil.pushThis(mv); 85 mv.visitMethodInsn(INVOKESTATIC, "com/tc/object/bytecode/ManagerUtil", "checkWriteAccess", "(Ljava/lang/Object;)V"); 86 mv.visitLabel(l1); 87 } 88 89 public void visitMethodInsn(int opcode, String owner, String name, String desc) { 90 if ((opcode == INVOKEINTERFACE) && "gnu/trove/TObjectFunction".equals(owner) && "execute".equals(name) && 91 "(Ljava/lang/Object;)Ljava/lang/Object;".equals(desc)) { 92 mv.visitVarInsn(ALOAD, 0); 93 mv.visitVarInsn(ALOAD, 3); 94 mv.visitVarInsn(ILOAD, 4); 95 mv.visitInsn(AALOAD); 96 opcode = INVOKESTATIC; 97 owner = "gnu/trove/THashMap"; 98 desc = STATIC_EXECUTE_DESC; 99 } 100 super.visitMethodInsn(opcode, owner, name, desc); 101 } 102 } 103 } 104 105 } 106 | Popular Tags |