01: /*
02: * All content copyright (c) 2003-2006 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.ClassAdapter;
08: import com.tc.asm.ClassVisitor;
09: import com.tc.asm.Label;
10: import com.tc.asm.MethodVisitor;
11: import com.tc.asm.Opcodes;
12:
13: public class JavaUtilConcurrentHashMapHashEntryAdapter extends
14: ClassAdapter implements Opcodes {
15: public JavaUtilConcurrentHashMapHashEntryAdapter(ClassVisitor cv) {
16: super (cv);
17: }
18:
19: public void visit(int version, int access, String name,
20: String signature, String super Name, String[] interfaces) {
21: String[] interfacesNew = new String[interfaces.length + 1];
22: System.arraycopy(interfaces, 0, interfacesNew, 0,
23: interfaces.length);
24: interfacesNew[interfacesNew.length - 1] = TCMapEntry.class
25: .getName().replace('.', '/');
26: super .visit(version, access, name, signature, super Name,
27: interfacesNew);
28: }
29:
30: public void visitEnd() {
31: createTCRawSetValueMethod();
32: createTCIsFaultedInMethod();
33:
34: super .visitEnd();
35: }
36:
37: private void createTCRawSetValueMethod() {
38: MethodVisitor mv = super .visitMethod(ACC_PUBLIC
39: | ACC_SYNCHRONIZED,
40: TCMapEntry.TC_RAWSETVALUE_METHOD_NAME,
41: TCMapEntry.TC_RAWSETVALUE_METHOD_DESC, null, null);
42: mv.visitCode();
43: mv.visitVarInsn(ALOAD, 0);
44: mv.visitVarInsn(ALOAD, 1);
45: mv.visitFieldInsn(PUTFIELD,
46: "java/util/concurrent/ConcurrentHashMap$HashEntry",
47: "value", "Ljava/lang/Object;");
48: mv.visitInsn(RETURN);
49: mv.visitMaxs(2, 2);
50: mv.visitEnd();
51: }
52:
53: private void createTCIsFaultedInMethod() {
54: MethodVisitor mv = super .visitMethod(ACC_PUBLIC
55: | ACC_SYNCHRONIZED,
56: TCMapEntry.TC_ISVALUEFAULTEDIN_METHOD_NAME,
57: TCMapEntry.TC_ISVALUEFAULTEDIN_METHOD_DESC, null, null);
58: mv.visitCode();
59: mv.visitVarInsn(ALOAD, 0);
60: mv.visitFieldInsn(GETFIELD,
61: "java/util/concurrent/ConcurrentHashMap$HashEntry",
62: "value", "Ljava/lang/Object;");
63: mv.visitTypeInsn(INSTANCEOF, "com/tc/object/ObjectID");
64:
65: Label labelTrue = new Label();
66: mv.visitJumpInsn(IFEQ, labelTrue);
67: mv.visitInsn(ICONST_0);
68: Label labelFalse = new Label();
69: mv.visitJumpInsn(GOTO, labelFalse);
70: mv.visitLabel(labelTrue);
71: mv.visitInsn(ICONST_1);
72: mv.visitLabel(labelFalse);
73:
74: mv.visitInsn(IRETURN);
75: mv.visitMaxs(1, 1);
76: mv.visitEnd();
77: }
78: }
|