Undefined behaviour in hotspot

Omair Majid omajid at redhat.com
Tue Apr 22 16:34:07 UTC 2014


* Volker Simonis <volker.simonis at gmail.com> [2014-04-22 04:41]:
> I think the simplest and safest fix would be to make encoding() (and
> all the corresponding functions) static functions which take a
> Register as argument like:
> 
> static int encoding(const RegisterImpl* r) { assert(is_valid(r),
> "invalid register"); return (intptr_t)r; }
> 
> This wouldn't waste any more memory and it would be fully C++
> compliant at the price of a slightly more verbose usage:
> 
> 2577    void Assembler::push(Register src) {
> 2578      int encode = prefix_and_encode(RegisterImpl::encoding(src));
> 2579
> 
> And of course this would work with any compiler.

Are you sure about this? 

It seems to me that a pointer created from an int does not satisfy the
conditions for a "safely-derived pointer". It has implementation defined
behaviour [1].

> What do you think?

That certainly works for me, but not sure for others.

For the sake of safety, I would rather use a typedef for registers and a
separate class with static methods to operate on the typedef.

Thanks,
Omair

[1] http://cpp0x.centaur.ath.cx/basic.stc.dynamic.safety.html

-- 
PGP Key: 66484681 (http://pgp.mit.edu/)
Fingerprint = F072 555B 0A17 3957 4E95  0056 F286 F14F 6648 4681


More information about the hotspot-dev mailing list