Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

对于throw指令被catch后再return,会导致pop多次,我comment了一个实现try-finally的链接 #54

Open
stevenys opened this issue Nov 26, 2017 · 1 comment

Comments

@stevenys
Copy link

对于throw后catch的路径,end代码被调用了多次,也就是pop了多次,虽然会比较start时存入的methodId(foo),对于不相等的,则不上报。但是已经pop出来的,却没有再push回去,会导致整个堆栈均无法正确end,导致错乱,只有等这一波堆栈全pop出来后重新来一次。

foo() {
(start_foo)
try {
(end_foo_1)
throw e;
} catch (e) {
}
(end_foo_2)
return ;
}

对于sql慢速日志,sql由于固定在一个特定的方法里,而且不会存在窃套,其实堆栈深度最大也就1,而且使用了独立的堆栈,问题倒不大。

相关代码:
ProfMethodAdapter. visitInsn(insn) :74
case Opcodes.RETURN:
case Opcodes.ATHROW:
this.visitLdcInsn(mMethodId);
this.visitMethodInsn(INVOKESTATIC, "com/taobao/profile/Profiler", "End", "(I)V");
break;

Profiler. End(methodId): 116
thrData.stackNum--;
long[] frameData = thrData.stackFrame.pop();
long id = frameData[0];
if (methodId != id) {
return;
}

@stevenys
Copy link
Author

我写了一个try-finally的实现,可以处理throw之后再次被catch的情况,可以参考下:https://github.com/stevenys/JavaProfiler

@stevenys stevenys changed the title 对于throw指令被catch后再return,会导致pop多次 对于throw指令被catch后再return,会导致pop多次,可以参考这个处理:https://github.com/stevenys/JavaProfiler Nov 27, 2017
@stevenys stevenys changed the title 对于throw指令被catch后再return,会导致pop多次,可以参考这个处理:https://github.com/stevenys/JavaProfiler 对于throw指令被catch后再return,会导致pop多次,我comment了一个实现try-finally的链接 Nov 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant