java.lang.Math.log替换为内在调用,为什么不是java.lang.Math.exp()? [英] java.lang.Math.log replaced by intrinsic call, why not java.lang.Math.exp()?

查看:167
本文介绍了java.lang.Math.log替换为内在调用,为什么不是java.lang.Math.exp()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



为什么这个简单的代码(只需调用 Math。 log()):

  Double thisdouble = Math.log(10); 

在jdk1.7.0_11的Math.class第275行有一个断点:

  274 public static double log(double a){
275返回StrictMath.log(a); // default impl。代表StrictMath
276}

在调试模式下不停止执行?有人可以在自己的机器上尝试这个(我正在使用Eclipse)?



调用 Math.exp()并调试 Math.exp (第254行)功能正常工作...



编辑:上面的答案是, Math.log 被Hotspot VM的固有调用所替代,所以Math类中的代码从未达到。现在的问题是为什么 Math.exp 不会被内在的代替... FWIW我在Core i5 M520(Arrandale)上,但我会非常怀疑该处理器支持日志,而不是对...的支持。

解决方案

我假设Math类中的代码是只有一个后备代码,由那些架构使用,其中方法调用不被替换为一些本机浮点运算的调用所替代。所以这个方法在你的情况下并没有被实际调用。我必须承认,我没有证据支持这个假设,但是。


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...

解决方案

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.

这篇关于java.lang.Math.log替换为内在调用,为什么不是java.lang.Math.exp()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆