JEP draft: Frozen Arrays (Preview)

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

JEP draft: Frozen Arrays (Preview)

Suminda Sirinath Salpitikorala Dharmasena
Since the type system (of both language and VM) gives no way to distinguish between variables which always refer to mutable arrays, always refer to frozen arrays, or may refer to a mix of arrays, there will in general be a dynamic check (for "frozen-ness") as part of any store to an array (as a[i]=x, or bytecodes like iastore or aastore). This check is similar to the existing checks for null references (potentially raising NullPointerException) or reference array subtypes (potentially raising ArrayStoreException).

I am wondering if the array can have a marker interface `UnFrozenArray` & `ForzenArray` which can be used to track if the array is frozen or not. Also perhaps this can be used to eliminate the dynamic check. The array API can use these maerker interfaces.

Also have a user facing method to create a frozen by birth array. Say `A[] a = {...}.frozen;`.

Also it would be great if an array related API can migrate away from using `Object` to a marker say `Array` so that arbitrary objects cannot be passed to these methods. This change will only break incorrect code where an non array is passed to an array specific method.

S
Reply | Threaded
Open this post in threaded view
|

Re: JEP draft: Frozen Arrays (Preview)

Suminda Sirinath Salpitikorala Dharmasena
Minor corrections below:

Since the type system (of both language and VM) gives no way to distinguish between variables which always refer to mutable arrays, always refer to frozen arrays, or may refer to a mix of arrays, there will in general be a dynamic check (for "frozen-ness") as part of any store to an array (as a[i]=x, or bytecodes like iastore or aastore). This check is similar to the existing checks for null references (potentially raising NullPointerException) or reference array subtypes (potentially raising ArrayStoreException).

I am wondering if the array can have a marker interface `UnFrozenArray` & `ForzenArray` which can be used to track if the array is frozen or not. Also perhaps this can be used to eliminate the dynamic check. The array API can use these maerker interfaces.

Also have a user facing method to create a frozen by birth array. Say `A[] a = {...}.frozen;`.

Also it would be great if an array related API can migrate away from using `Object` to a marker say `Array<T>` or `PrimitiveArray` so that arbitrary objects cannot be passed to these methods. This change will only break incorrect code where an non array is passed to an array specific method.

S