1 4 package com.tc.object.bytecode; 5 6 import com.tc.asm.ClassAdapter; 7 import com.tc.asm.ClassVisitor; 8 import com.tc.asm.MethodAdapter; 9 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, String [] includePatterns) { 17 super(cv); 18 this.includePatterns = includePatterns; 19 } 20 21 public MethodVisitor visitMethod(int access, String name, String desc, String signature, String [] exceptions) { 22 MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions); 23 24 for (int i = 0; i < includePatterns.length; i++) { 25 if (name.matches(includePatterns[i])) { return new RewriteStringGetChars(mv); } 26 } 27 28 return mv; 29 } 30 31 private static class RewriteStringGetChars extends MethodAdapter implements Opcodes { 32 33 public RewriteStringGetChars(MethodVisitor mv) { 34 super(mv); 35 } 36 37 public void visitMethodInsn(int opcode, String owner, String name, String desc) { 38 if ((INVOKEVIRTUAL == opcode) 39 && ("java/lang/String".equals(owner) && "getChars".equals(name) && ("(II[CI)V".equals(desc) || "([CI)V" 40 .equals(desc)))) { 41 super.visitMethodInsn(opcode, owner, "getCharsFast", desc); 42 } else { 43 super.visitMethodInsn(opcode, owner, name, desc); 44 } 45 } 46 } 47 48 } 49 | Popular Tags |