reverse_engineer
reverse_engineer

Reputation: 4269

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

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

Upvotes: 2

Views: 856

Answers (1)

MvG
MvG

Reputation: 60968

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.

Upvotes: 2

Related Questions