[foreign] RFR : Move array-like methods from Pointer to Array

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Tue Nov 20 01:42:50 UTC 2018


Looks good - can the code in BoundedArray be rewritten in terms of 
Stream::iterate too? E.g. if you produce a pointer to the last element - 
call it LAST - then it should be that

Array::elements()

~=

Array.elementPointer().iterate(LAST)

Right?

Also, don't we want to rename this to iterate() too?

Maurizio

On 19/11/2018 18:20, Jorn Vernee wrote:
> Update webrev: 
> http://cr.openjdk.java.net/~jvernee/panama/webrevs/arrays/webrev.04/
>
> Added 2 `iterate` methods to Pointer, one that takes a predicate, and 
> one that takes a pointer. Should I also add tests for these? 
> (elements() was not being tested previously it seems).
>
> Thanks,
> Jorn
>
> Maurizio Cimadamore schreef op 2018-11-19 16:27:
>> <snip>
>>>>
>>>> Stream<Pointer<T>> elements(Predicate<? super Predicate<T>> hasNext)
>>>
>>> Yes, this is a nice idea. Maybe we'd also want to have an overload 
>>> that just takes a `Pointer<T>` as an argument, and iterations will 
>>> be up until that pointer.
>> Sure, the pointer-end overload sounds like a nice idea!
>>>
>>>> And this would generally applicable to both arrays and pointers. No
>>>> guesswork involved, users iterating on pointers will have to provide
>>>> an explicit termination condition; if they get it wrong, they will get
>>>> some exception when dereferencing the wrong memory location.
>>>
>>> Well, for native-allocated pointers this will invoke undefined 
>>> behavior or possibly crash the VM (or enable access to VM internals? 
>>> I'm not sure what security is in place there currently).
>>
>> A possibility there would be to avoid using EVERYTHING as a backing
>> region. That is, the binder could, in principle, generate regions that
>> are small enough only to contain the region that we actually want to
>> access (e.g. starts at base address , ends at base address + pointee
>> layout size). If the client is not happy with that and knows that the
>> pointer is a pointer to some kind of a buffer, perhaps an (unsafe?)
>> operation could be provided to relax the memory region boundaries
>> beneath the pointer.
>>
>> But overall I think we should strive for the 'no VM crashes if you are
>> only using the safe API' (although we don't have to get there in one
>> step).
>>
>> <snip>
>>
>>>
>>>
>>>> As a final point, I think we should implement elements() using
>>>> Stream.iterate (and possibly document it in the API).
>>>
>>> Agreed. Maybe we should also rename Pointer::elements to 
>>> Pointer::iterate ?
>>
>> I like that.
>>
>> Cheers
>> Maurizio
>>
>>>
>>> Jorn


More information about the panama-dev mailing list