There’s a bit of an issue with this. Namely, the old GET_ARRAY_LENGTH being the 
unreflection of j.l.reflect.Array.getLength() worked for any array type, so it 
was always accompanied with ValidationType.IS_ARRAY. I believe this is wrong 
now and can cause ClassCastException at runtime (I say “believe” as I can’t 
currently build jdk 9 so can’t confirm). This could be caught by a test that 
handles two arrays of different types in the same call site, e.g. with Nashorn:

  var intArray = Java.type(“int[]”)
  var doubleArray = Java.type(“double[]”)
  var arrs = [new intArray(0), new doubleArray(0)]
  for (var i in arrs) arrs[i].length

Since the MethodHandles.arrayLength is typed to the concrete array class, it 
should be used with ValidationType.EXACT_CLASS. 

This will obviously cause call sites taking length of different kinds of arrays 
more polymorphic… FWIW, the IS_ARRAY validation type is probably obsolete now 
as it was only used for array length getters anyway.

The polymorphism could be somewhat alleviated by having stable validation for 
all arrays of reference types. Maybe have one 
MethodHandles.arrayLength(Object[].class) handle cached to use with all arrays 
of reference types, and use a Validator(Object[].class, 
ValidationType.INSTANCE_OF) with it. Then you’d have stable linkage that can 
take the length of any reference-typed array, but you’d still trigger relinking 
for primitive-typed arrays.

Attila.
 
> On 18 May 2016, at 11:25, Michael Haupt <michael.ha...@oracle.com> wrote:
> 
> Dear all,
> 
> please review this change.
> RFE: https://bugs.openjdk.java.net/browse/JDK-8157225
> Webrev: http://cr.openjdk.java.net/~mhaupt/8157225/webrev.00/
> 
> Thanks,
> 
> Michael
> 
> -- 
> 
> <http://www.oracle.com/>
> Dr. Michael Haupt | Principal Member of Technical Staff
> Phone: +49 331 200 7277 | Fax: +49 331 200 7561
> Oracle Java Platform Group | LangTools Team | Nashorn
> Oracle Deutschland B.V. & Co. KG | Schiffbauergasse 14 | 14467 Potsdam, 
> Germany
> 
> ORACLE Deutschland B.V. & Co. KG | Hauptverwaltung: Riesstraße 25, D-80992 
> München
> Registergericht: Amtsgericht München, HRA 95603
> 
> Komplementärin: ORACLE Deutschland Verwaltung B.V. | Hertogswetering 163/167, 
> 3543 AS Utrecht, Niederlande
> Handelsregister der Handelskammer Midden-Nederland, Nr. 30143697
> Geschäftsführer: Alexander van der Ven, Jan Schultheiss, Val Maher
> <http://www.oracle.com/commitment>    Oracle is committed to developing 
> practices and products that help protect the environment
> 

Reply via email to