01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.object.bytecode;
05:
06: import com.tc.asm.ClassAdapter;
07: import com.tc.asm.ClassVisitor;
08: import com.tc.asm.MethodAdapter;
09: import com.tc.asm.MethodVisitor;
10: import com.tc.asm.Opcodes;
11:
12: public class StringGetCharsAdapter extends ClassAdapter {
13:
14: private final String[] includePatterns;
15:
16: public StringGetCharsAdapter(ClassVisitor cv,
17: String[] includePatterns) {
18: super (cv);
19: this .includePatterns = includePatterns;
20: }
21:
22: public MethodVisitor visitMethod(int access, String name,
23: String desc, String signature, String[] exceptions) {
24: MethodVisitor mv = super .visitMethod(access, name, desc,
25: signature, exceptions);
26:
27: for (int i = 0; i < includePatterns.length; i++) {
28: if (name.matches(includePatterns[i])) {
29: return new RewriteStringGetChars(mv);
30: }
31: }
32:
33: return mv;
34: }
35:
36: private static class RewriteStringGetChars extends MethodAdapter
37: implements Opcodes {
38:
39: public RewriteStringGetChars(MethodVisitor mv) {
40: super (mv);
41: }
42:
43: public void visitMethodInsn(int opcode, String owner,
44: String name, String desc) {
45: if ((INVOKEVIRTUAL == opcode)
46: && ("java/lang/String".equals(owner)
47: && "getChars".equals(name) && ("(II[CI)V"
48: .equals(desc) || "([CI)V".equals(desc)))) {
49: super .visitMethodInsn(opcode, owner, "getCharsFast",
50: desc);
51: } else {
52: super.visitMethodInsn(opcode, owner, name, desc);
53: }
54: }
55: }
56:
57: }
|