asm
This commit is contained in:
@@ -12,6 +12,7 @@ import static org.redkale.asm.Opcodes.ICONST_0;
|
||||
import static org.redkale.asm.Opcodes.INVOKESTATIC;
|
||||
import static org.redkale.asm.Opcodes.INVOKEVIRTUAL;
|
||||
import static org.redkale.asm.Opcodes.SIPUSH;
|
||||
import org.redkale.util.RedkaleException;
|
||||
|
||||
/**
|
||||
* ASM简单的工具方法 <br>
|
||||
@@ -72,7 +73,7 @@ public final class Asms {
|
||||
}
|
||||
av.visitEnd();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new RedkaleException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,28 +9,16 @@ import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import org.redkale.asm.AnnotationVisitor;
|
||||
import org.redkale.asm.AsmMethodBean;
|
||||
import org.redkale.asm.AsmMethodBoost;
|
||||
import org.redkale.asm.Asms;
|
||||
import org.redkale.asm.ClassWriter;
|
||||
import org.redkale.asm.FieldVisitor;
|
||||
import org.redkale.asm.Label;
|
||||
import org.redkale.asm.MethodDebugVisitor;
|
||||
import static org.redkale.asm.Opcodes.ACC_PRIVATE;
|
||||
import static org.redkale.asm.Opcodes.ACC_PROTECTED;
|
||||
import static org.redkale.asm.Opcodes.ACC_PUBLIC;
|
||||
import static org.redkale.asm.Opcodes.ALOAD;
|
||||
import static org.redkale.asm.Opcodes.ARETURN;
|
||||
import static org.redkale.asm.Opcodes.DLOAD;
|
||||
import static org.redkale.asm.Opcodes.DRETURN;
|
||||
import static org.redkale.asm.Opcodes.FLOAD;
|
||||
import static org.redkale.asm.Opcodes.FRETURN;
|
||||
import static org.redkale.asm.Opcodes.ILOAD;
|
||||
import static org.redkale.asm.Opcodes.INVOKESPECIAL;
|
||||
import static org.redkale.asm.Opcodes.IRETURN;
|
||||
import static org.redkale.asm.Opcodes.LLOAD;
|
||||
import static org.redkale.asm.Opcodes.LRETURN;
|
||||
import static org.redkale.asm.Opcodes.RETURN;
|
||||
import static org.redkale.asm.Opcodes.*;
|
||||
import org.redkale.asm.Type;
|
||||
import org.redkale.cache.Cached;
|
||||
import org.redkale.util.RedkaleException;
|
||||
@@ -41,7 +29,9 @@ import org.redkale.util.RedkaleException;
|
||||
*/
|
||||
public class CacheAsmMethodBoost implements AsmMethodBoost {
|
||||
|
||||
private static final List<Class<? extends Annotation>> FILTER_ANN = List.of(Cached.class);
|
||||
private static final List<Class<? extends Annotation>> FILTER_ANN = List.of(Cached.class, DynForCache.class);
|
||||
|
||||
private final AtomicInteger fieldIndex = new AtomicInteger();
|
||||
|
||||
protected final Class serviceType;
|
||||
|
||||
@@ -75,8 +65,8 @@ public class CacheAsmMethodBoost implements AsmMethodBoost {
|
||||
acc = ACC_PRIVATE;
|
||||
nowMethodName = newMethodName;
|
||||
}
|
||||
|
||||
final String rsMethodName = method.getName() + "_afterCache";
|
||||
final String dynFieldName = fieldPrefix + "_" + method.getName() + "CacheAction" + fieldIndex.incrementAndGet();
|
||||
{
|
||||
Map<String, AsmMethodBean> methodBeans = AsmMethodBoost.getMethodBeans(serviceType);
|
||||
AsmMethodBean methodBean = AsmMethodBean.get(methodBeans, method);
|
||||
@@ -104,7 +94,8 @@ public class CacheAsmMethodBoost implements AsmMethodBoost {
|
||||
Label l0 = new Label();
|
||||
mv.visitLabel(l0);
|
||||
av = mv.visitAnnotation(cacheDynDesc, true);
|
||||
av.visitEnd();
|
||||
av.visit("dynField", dynFieldName);
|
||||
Asms.visitAnnotation(av, cached);
|
||||
if (newMethodName == null) {
|
||||
//给方法加上原有的Annotation
|
||||
final Annotation[] anns = method.getAnnotations();
|
||||
@@ -175,6 +166,10 @@ public class CacheAsmMethodBoost implements AsmMethodBoost {
|
||||
mv.visitMaxs(20, 20);
|
||||
mv.visitEnd();
|
||||
}
|
||||
{
|
||||
FieldVisitor fv = cw.visitField(ACC_PRIVATE, dynFieldName, Type.getDescriptor(CacheAction.class), null, null);
|
||||
fv.visitEnd();
|
||||
}
|
||||
return rsMethodName;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,14 +9,33 @@ import java.lang.annotation.Inherited;
|
||||
import java.lang.annotation.Retention;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
import java.lang.annotation.Target;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* {@link org.redkale.cache.Cached}注解的动态扩展版,会多一个字段信息
|
||||
* 用于识别方法是否已经动态处理过
|
||||
*
|
||||
* @author zhangjx
|
||||
*
|
||||
* @since 2.8.0
|
||||
*/
|
||||
@Inherited
|
||||
@Documented
|
||||
@Target({METHOD})
|
||||
@Retention(RUNTIME)
|
||||
public @interface DynForCache {
|
||||
|
||||
String dynField();
|
||||
|
||||
String key();
|
||||
|
||||
String map();
|
||||
|
||||
String localExpire();
|
||||
|
||||
String remoteExpire();
|
||||
|
||||
TimeUnit timeUnit();
|
||||
|
||||
boolean nullable();
|
||||
}
|
||||
|
||||
@@ -11,8 +11,12 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* {@link org.redkale.lock.Locked}注解的动态扩展版,会多一个字段信息
|
||||
* 用于识别方法是否已经动态处理过
|
||||
*
|
||||
* @author zhangjx
|
||||
*
|
||||
* @since 2.8.0
|
||||
*/
|
||||
@Inherited
|
||||
@Documented
|
||||
@@ -20,4 +24,5 @@ import java.lang.annotation.Target;
|
||||
@Retention(RUNTIME)
|
||||
public @interface DynForLock {
|
||||
|
||||
String dynField();
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import org.redkale.asm.AnnotationVisitor;
|
||||
import org.redkale.asm.AsmMethodBean;
|
||||
import org.redkale.asm.AsmMethodBoost;
|
||||
@@ -27,7 +28,9 @@ import org.redkale.util.RedkaleException;
|
||||
*/
|
||||
public class LockAsmMethodBoost implements AsmMethodBoost {
|
||||
|
||||
private static final List<Class<? extends Annotation>> FILTER_ANN = List.of(Locked.class);
|
||||
private static final List<Class<? extends Annotation>> FILTER_ANN = List.of(Locked.class, DynForLock.class);
|
||||
|
||||
private final AtomicInteger fieldIndex = new AtomicInteger();
|
||||
|
||||
protected final Class serviceType;
|
||||
|
||||
@@ -63,6 +66,7 @@ public class LockAsmMethodBoost implements AsmMethodBoost {
|
||||
}
|
||||
|
||||
final String rsMethodName = method.getName() + "_afterLock";
|
||||
final String dynFieldName = fieldPrefix + "_" + method.getName() + "LockAction" + fieldIndex.incrementAndGet();
|
||||
{
|
||||
Map<String, AsmMethodBean> methodBeans = AsmMethodBoost.getMethodBeans(serviceType);
|
||||
AsmMethodBean methodBean = AsmMethodBean.get(methodBeans, method);
|
||||
@@ -90,7 +94,8 @@ public class LockAsmMethodBoost implements AsmMethodBoost {
|
||||
Label l0 = new Label();
|
||||
mv.visitLabel(l0);
|
||||
av = mv.visitAnnotation(lockDynDesc, true);
|
||||
av.visitEnd();
|
||||
av.visit("dynField", dynFieldName);
|
||||
Asms.visitAnnotation(av, cached);
|
||||
if (newMethodName == null) {
|
||||
//给方法加上原有的Annotation
|
||||
final Annotation[] anns = method.getAnnotations();
|
||||
|
||||
Reference in New Issue
Block a user