??????????д???????????

????(???????? depth ???????????????????????????????)

???????????????????????????????????????jdk????????????.* ?????????????java/util/regex/Pattern$CharProperty.match ???????? D ???????java/util/regex/Pattern$BmpCharProperty.match ????????????????????????????ASM

???????????????????????????????????????????£?

????package com.alibaba.taobao.tinyprofiler;

????import java.lang.instrument.ClassFileTransformer;

????import java.lang.instrument.IllegalClassFormatException;

????import java.security.ProtectionDomain;

????import org.objectweb.asm.ClassAdapter;

 ????import org.objectweb.asm.ClassReader;

????import org.objectweb.asm.ClassWriter;

????public class MethodCallCountTransformer implements ClassFileTransformer {

????@Override

????public byte[] transform(ClassLoader loader?? String className?? Class classBeingRedefined??

????ProtectionDomain protectionDomain?? byte[] classfileBuffer) throws IllegalClassFormatException {

????try {

????if (!“java/util/regex/Pattern$CharProperty”.equals(className)

????&& !“java/util/regex/Pattern$BmpCharProperty”.equals(className)) {

????return classfileBuffer;

????}

????ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);

????ClassAdapter adapter = new MethodCallClassAdapter(writer?? className);

????ClassReader reader = new ClassReader(classfileBuffer);

????reader.accept(adapter?? 0);

????// ?????????????

????return writer.toByteArray();

????} catch (Exception e) {

????e.printStackTrace();

????// ????????????

????return classfileBuffer;

????}

????}

????}

????package com.alibaba.taobao.tinyprofiler;

????import java.util.concurrent.atomic.AtomicInteger;

????public class Counter {

????private static AtomicInteger methodCallCount = new AtomicInteger(0);

????public static void printAndIncCount(String className?? String methodName) {

????System.out.println(className + “.” + methodName + “ called?? total times ” + methodCallCount.incrementAndGet());

????}

????}

????OK??????????????

????String regex = “.*.*.*D”;

????String target = “22asdvasdx”;

????Pattern.compile(regex).matcher(target).matches();

????System.out.println(“Xuanyin’s estimated count: ” + findTotalWays(4?? target.length()) + “; depth: ” + recursionDepth);

??????????(???????? depth ???????????????????????????????)??

??????????????????~OK???????????????????????????? .*.*.*.*.*.*D ???? com.taobao.binary.bogda.query.service.RulesInfoQueryService:1.0.0.daily

????????????? 5 ?? ??? ?????????? 2.5 ????

????????????????i7-2600K ??4.5G???????????5???????????????~

????????????????????600???????????????~???????????