changeset 1690:c187d75b77aa

8157225: adopt method handle for array length getter in BeanLinker Reviewed-by: hannesw, sundar
author mhaupt
date Wed, 18 May 2016 12:07:54 +0200
parents c24beef07d1b
children bb6cf30cf892
files src/jdk.dynalink/share/classes/jdk/dynalink/beans/BeanLinker.java
diffstat 1 files changed, 5 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.dynalink/share/classes/jdk/dynalink/beans/BeanLinker.java	Wed May 18 14:08:38 2016 +0530
+++ b/src/jdk.dynalink/share/classes/jdk/dynalink/beans/BeanLinker.java	Wed May 18 12:07:54 2016 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -113,7 +113,7 @@
             // Some languages won't have a notion of manipulating collections. Exposing "length" on arrays as an
             // explicit property is beneficial for them.
             // REVISIT: is it maybe a code smell that StandardOperation.GET_LENGTH is not needed?
-            setPropertyGetter("length", GET_ARRAY_LENGTH, ValidationType.IS_ARRAY);
+            setPropertyGetter("length", MethodHandles.arrayLength(clazz), ValidationType.IS_ARRAY);
         } else if(List.class.isAssignableFrom(clazz)) {
             setPropertyGetter("length", GET_COLLECTION_LENGTH, ValidationType.INSTANCE_OF);
         }
@@ -518,9 +518,6 @@
                 gic.getValidatorClass(), gic.getValidationType());
     }
 
-    private static final MethodHandle GET_ARRAY_LENGTH = Lookup.PUBLIC.findStatic(Array.class, "getLength",
-            MethodType.methodType(int.class, Object.class));
-
     private static final MethodHandle GET_COLLECTION_LENGTH = Lookup.PUBLIC.findVirtual(Collection.class, "size",
             MethodType.methodType(int.class));
 
@@ -537,7 +534,7 @@
         // Thing is, it'd be quite stupid of a call site creator to go though invokedynamic when it knows in advance
         // they're dealing with an array, collection, or map, but hey...
         if(declaredType.isArray()) {
-            return new GuardedInvocationComponent(GET_ARRAY_LENGTH.asType(callSiteType));
+            return new GuardedInvocationComponent(MethodHandles.arrayLength(declaredType).asType(callSiteType));
         } else if(Collection.class.isAssignableFrom(declaredType)) {
             return new GuardedInvocationComponent(GET_COLLECTION_LENGTH.asType(callSiteType));
         } else if(Map.class.isAssignableFrom(declaredType)) {
@@ -546,8 +543,8 @@
 
         // Otherwise, create a binding based on the actual type of the argument with an appropriate guard.
         if(clazz.isArray()) {
-            return new GuardedInvocationComponent(GET_ARRAY_LENGTH.asType(callSiteType), Guards.isArray(0,
-                    callSiteType), ValidationType.IS_ARRAY);
+            return new GuardedInvocationComponent(MethodHandles.arrayLength(clazz).asType(callSiteType),
+                    Guards.isArray(0, callSiteType), ValidationType.IS_ARRAY);
         } if(Collection.class.isAssignableFrom(clazz)) {
             return new GuardedInvocationComponent(GET_COLLECTION_LENGTH.asType(callSiteType), Guards.asType(
                     COLLECTION_GUARD, callSiteType), Collection.class, ValidationType.INSTANCE_OF);