Method breakpoints may dramatically slow down debugging

别等时光非礼了梦想. 提交于 2020-12-29 08:47:05

问题


Whenever adding a breakpoint to the line of a method declaration (in Intellij IDEA or Android Studio), a popup appears:

Method breakpoints may dramatically slow down debugging

Why would it dramatically slow down debugging, is my question? What is different about putting the breakpoint on the first line of the function?

Thanks!


回答1:


I looked around a little, and saw this post in the Intellij Documetation:

Method Breakpoint

Method breakpoints act in response to the program entering or exiting a particular method. They let you target your debugging sessions by method you wish to investigate, rather than by line number. Method breakpoints let you follow the program flow at the method level as well as check entry and exit conditions. Note that using method breakpoints can slow down the application you are debugging.

I guess it stops the program right before it enters the method, so that you can evaluate the parameters and such before entering the method.

The reason it dramatically slows down is (This is what I can gather, because that is all I could find on method breakpoints in Intellij's documentation) that it has to:

let you follow the program flow at the method level as well as check entry and exit conditions

and I suppose that would take a lot longer than just halting the program's execution




回答2:


There is a simple explanation from the IntelliJ Team: "Method breakpoints will slow down debugger a lot because of the JVM design, they are expensive to evaluate"

https://intellij-support.jetbrains.com/hc/en-us/articles/206544799-Java-slow-performance-or-hangups-when-starting-debugger-and-stepping




回答3:


My understanding is that the code must be run interpretively (instead of using JIT to pre-compile?) when the breakpoint is set on method entry.

If you set the breakpoint on the first line of the method instead, I suspect a line number index into the code can be used to simply swap a break opcode for the original opcode, so the app runs full speed. (which still seems pretty slow to me when debugging ;)



来源:https://stackoverflow.com/questions/31062069/method-breakpoints-may-dramatically-slow-down-debugging

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!