Skip to content

Commit

Permalink
修复问题alibaba#108
Browse files Browse the repository at this point in the history
  • Loading branch information
oldmanpushcart committed Nov 7, 2018
1 parent df2960d commit 36943f9
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import static org.objectweb.asm.ClassReader.EXPAND_FRAMES;
import static org.objectweb.asm.ClassWriter.COMPUTE_FRAMES;
import static org.objectweb.asm.ClassWriter.COMPUTE_MAXS;
import static org.objectweb.asm.Opcodes.ASM7;

/**
* 事件代码增强器
Expand Down Expand Up @@ -90,7 +91,7 @@ private byte[] weavingEvent(final ClassLoader targetClassLoader,
final int targetClassLoaderObjectID = ObjectIDs.instance.identity(targetClassLoader);
cr.accept(
new EventWeaver(
Opcodes.ASM6, cw, namespace, listenerId,
ASM7, cw, namespace, listenerId,
targetClassLoaderObjectID,
cr.getClassName(),
signCodes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class ReWriteMethod extends AdviceAdapter implements Opcodes, AsmTypes, A
* Creates a new {@link AdviceAdapter}.
*
* @param api the ASM API version implemented by this visitor. Must be one
* of {@link Opcodes#ASM4} or {@link Opcodes#ASM6}.
* of {@link Opcodes#ASM4} or {@link Opcodes#ASM7}.
* @param mv the method visitor to which this adapter delegates calls.
* @param access the method's access flags (see {@link Opcodes}).
* @param name the method's name.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public boolean isBind() {
@Override
public void unbind() throws IOException {
try {

initializer.destroyProcess(new Initializer.Processor() {
@Override
public void process() throws Throwable {
Expand All @@ -86,6 +87,10 @@ public void process() throws Throwable {
httpServer.destroy();
logger.info("{} was destroyed.", this);

// 关闭对象池
EventListenerHandlers.getSingleton().getEventPool().close();
logger.info("{} was closed the Event-Pool!", this);

} catch (Throwable cause) {
logger.warn("{} unBind failed.", this, cause);
throw new IOException("unBind failed.", cause);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ public EventPool() {
this.isEnable = this.pool != null;
}

/**
* 关闭并清理对象池
* <p>
* 修复问题:#108
* </p>
*/
public void close() {
if (null != pool) {
pool.close();
}
}

private KeyedObjectPool<Event.Type, Event> createEventPool() {
final CoreConfigure cfg = CoreConfigure.getInstance();
if (cfg.isEventPoolEnable()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,14 @@ public class ClassStructureImplByAsm extends FamilyClassStructure {
private Access fixAccess() {
final AtomicInteger accessRef = new AtomicInteger(this.classReader.getAccess());
final String internalClassName = this.classReader.getClassName();
this.classReader.accept(new ClassVisitor(ASM6) {
this.classReader.accept(new ClassVisitor(ASM7) {
@Override
public void visitInnerClass(String name, String outerName, String innerName, int access) {
if (StringUtils.equals(name, internalClassName)) {
accessRef.set(access);
}
}
}, ASM6);
}, ASM7);
return new AccessImplByAsm(accessRef.get());
}

Expand Down Expand Up @@ -397,7 +397,7 @@ public List<ClassStructure> getInterfaceClassStructures() {
@Override
protected List<ClassStructure> initialValue() {
final List<ClassStructure> annotationTypeClassStructures = new ArrayList<ClassStructure>();
accept(new ClassVisitor(ASM6) {
accept(new ClassVisitor(ASM7) {

@Override
public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
Expand Down Expand Up @@ -426,7 +426,7 @@ public List<ClassStructure> getAnnotationTypeClassStructures() {
@Override
protected List<BehaviorStructure> initialValue() {
final List<BehaviorStructure> behaviorStructures = new ArrayList<BehaviorStructure>();
accept(new ClassVisitor(ASM6) {
accept(new ClassVisitor(ASM7) {

@Override
public MethodVisitor visitMethod(final int access,
Expand All @@ -441,7 +441,7 @@ public MethodVisitor visitMethod(final int access,
return super.visitMethod(access, name, desc, signature, exceptions);
}

return new MethodVisitor(ASM6, super.visitMethod(access, name, desc, signature, exceptions)) {
return new MethodVisitor(ASM7, super.visitMethod(access, name, desc, signature, exceptions)) {

private final Type methodType = Type.getMethodType(desc);
private final List<ClassStructure> annotationTypeClassStructures = new ArrayList<ClassStructure>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ public static void init(final String namespace,
*/
public static void clean(final String namespace) {
namespaceMethodHookMap.remove(namespace);

// 如果是最后的一个命名空间,则需要重新清理Node中所持有的Thread
if (namespaceMethodHookMap.isEmpty()) {
for (int index = 0; index < selfCallBarrier.nodeArray.length; index++) {
selfCallBarrier.nodeArray[index] = new SelfCallBarrier.Node();
}
}

}

private static final SelfCallBarrier selfCallBarrier = new SelfCallBarrier();
Expand Down Expand Up @@ -226,7 +234,7 @@ void delete(final Node node) {
node.next.pre = node.pre;
}
// help gc
node.pre = node.next = null;
node.pre = (node.next = null);
}

// 插入节点
Expand Down

0 comments on commit 36943f9

Please sign in to comment.