java.lang.Math.log replaced by intrinsic call, why not java.lang.Math.exp()?

时光毁灭记忆、已成空白 提交于 2019-11-28 10:04:31

问题


I'm reasking a question that had too little attention I think:

Why does this simple code (simply a call to Math.log()):

Double thisdouble = Math.log(10);

With a breakpoint on line 275 of Math.class of the jdk1.7.0_11:

274 public static double log(double a) {
275    return StrictMath.log(a); // default impl. delegates to StrictMath
276 }

Not stop execution in debug mode? Can somebody try this on his/her own machine (I'm using Eclipse)?

Calling Math.exp() and debugging the Math.exp(line 254) function does work...

EDIT: The answer to the above is that Math.log is replaced by an intrinsic call by the Hotspot VM so the code in the Math class is never reached. The question which remains now is why Math.exp is not replaced by an intrinsic... FWIW I'm on a Core i5 M520 (Arrandale), but I would seriously doubt that that processor has support for log and not for exp...


回答1:


I would assume that the code in the Math class is only a fallback code, used by those architectures where the method invocation isn't substituted by a call to some native floating point operation instead. So the method doesn't actually get called in your case. I must confess I don't have evidence tu support this assumption, though.



来源:https://stackoverflow.com/questions/15085294/java-lang-math-log-replaced-by-intrinsic-call-why-not-java-lang-math-exp

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