01: /*
02: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tc.object.bytecode;
06:
07: import com.tc.asm.ClassVisitor;
08: import com.tc.asm.Label;
09: import com.tc.asm.MethodVisitor;
10: import com.tc.asm.Opcodes;
11: import com.tc.object.SerializationUtil;
12:
13: public class SetRemoveMethodAdapter extends AbstractMethodAdapter
14: implements Opcodes {
15:
16: private final String type;
17: private final String mapType;
18: private final String mapField;
19: private final String mapFieldType;
20:
21: public SetRemoveMethodAdapter(String type, String mapType,
22: String mapField, String mapFieldType) {
23: this .type = type;
24: this .mapType = mapType;
25: this .mapField = mapField;
26: this .mapFieldType = mapFieldType;
27: }
28:
29: public MethodVisitor adapt(ClassVisitor cv) {
30: String renamed = ByteCodeUtil.TC_METHOD_PREFIX
31: + this .methodName;
32:
33: addNewRemoveMethod(cv, renamed);
34:
35: return cv.visitMethod(ACC_PRIVATE | ACC_SYNTHETIC, renamed,
36: this .description, this .signature, this .exceptions);
37: }
38:
39: private void addNewRemoveMethod(ClassVisitor cv, String renamed) {
40: MethodVisitor mv = cv.visitMethod(this .access, this .methodName,
41: this .description, this .signature, this .exceptions);
42:
43: mv.visitCode();
44: mv.visitVarInsn(ALOAD, 0);
45: mv
46: .visitMethodInsn(INVOKEVIRTUAL, type, "__tc_isManaged",
47: "()Z");
48: Label notManaged = new Label();
49: mv.visitJumpInsn(IFEQ, notManaged);
50: mv.visitVarInsn(ALOAD, 0);
51: managerHelper.callManagerMethod("checkWriteAccess", mv);
52: mv.visitVarInsn(ALOAD, 0);
53: mv.visitFieldInsn(GETFIELD, type, mapField, "L" + mapFieldType
54: + ";");
55: mv.visitTypeInsn(CHECKCAST, mapType);
56: mv.visitVarInsn(ALOAD, 1);
57: mv.visitMethodInsn(INVOKEVIRTUAL, mapType, "removeEntryForKey",
58: "(Ljava/lang/Object;)L" + mapType + "$Entry;");
59: mv.visitVarInsn(ASTORE, 2);
60: mv.visitVarInsn(ALOAD, 2);
61: Label entryNotNull = new Label();
62: mv.visitJumpInsn(IFNONNULL, entryNotNull);
63: mv.visitInsn(ICONST_0);
64: mv.visitInsn(IRETURN);
65: mv.visitLabel(entryNotNull);
66: mv.visitVarInsn(ALOAD, 0);
67: mv.visitLdcInsn(SerializationUtil.REMOVE_SIGNATURE);
68: mv.visitInsn(ICONST_1);
69: mv.visitTypeInsn(ANEWARRAY, "java/lang/Object");
70: mv.visitInsn(DUP);
71: mv.visitInsn(ICONST_0);
72: mv.visitVarInsn(ALOAD, 2);
73: mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Map$Entry",
74: "getKey", "()Ljava/lang/Object;");
75: mv.visitInsn(AASTORE);
76: managerHelper.callManagerMethod("logicalInvoke", mv);
77: mv.visitInsn(ICONST_1);
78: mv.visitInsn(IRETURN);
79: mv.visitLabel(notManaged);
80: ByteCodeUtil.pushThis(mv);
81: ByteCodeUtil.pushMethodArguments(this .access, this .description,
82: mv);
83: mv.visitMethodInsn(INVOKESPECIAL, this .ownerDots.replace('.',
84: '/'), renamed, this .description);
85: mv.visitInsn(IRETURN);
86: mv.visitMaxs(0, 0);
87: mv.visitEnd();
88: }
89:
90: public boolean doesOriginalNeedAdapting() {
91: return false;
92: }
93:
94: }
|