[foreign] Handling pointers with special (negative) values

Jorn Vernee jbvernee at xs4all.nl
Thu Oct 25 17:15:41 UTC 2018


Maurizio Cimadamore schreef op 2018-10-25 18:03:
> All good points raised here.
> 
> I think I'm with Florian: the check is incorrect, or at least
> partially so. Let me explain what I mean by that; Unsafe uses two
> different kind of addressing mode, as documented here:
> 
> http://hg.openjdk.java.net/jdk/jdk/file/9c260a6b6471/src/java.base/share/classes/jdk/internal/misc/Unsafe.java#l129
> 
> If the 'base' object is set, then the long becomes a (positive)
> offset. But if there's no 'base' object, then the long argument is
> simply an absolute address, which can be anything.
> 
> So, I think it could be fine to enforce that the offset is positive,
> but only if the underlying memory region has a non-null base.
> 
> Thoughts?

I wonder if the check is needed for either. The current implementation 
seems to just add the resolved oop to the offset and cast it to an 
address [1]. But if those are the expected semantics for Unsafe I think 
we should go with your solution.

I worry about things like Pointer::addr reporting negative values in 
some cases, and maybe we will have to allow negative values for offset 
and length in the future, but I guess we can cross that bridge when we 
get to it.

Either way, I have filed a bug for this: 
https://bugs.openjdk.java.net/browse/JDK-8212987
I could submit an RFR later if there are no further comments.

Thanks,
Jorn

[1] : 
http://hg.openjdk.java.net/panama/dev/file/4b634b7d0cdb/src/hotspot/share/prims/unsafe.cpp#l122


More information about the panama-dev mailing list