OpenJDK / zgc / zgc
changeset 48547:7f57c5908c57
8157251: BeanLinker relinks array length operations for array types
Reviewed-by: hannesw, jlaskey, attila
Contributed-by: priya.lakshmi.muthuswamy@oracle.com
author | hannesw |
---|---|
date | Fri, 12 Jan 2018 10:33:06 +0100 |
parents | 7a700fd0ad50 |
children | a5f815d1060b |
files | src/jdk.dynalink/share/classes/jdk/dynalink/beans/BeanLinker.java test/nashorn/script/basic/JDK-8157251.js test/nashorn/script/basic/JDK-8157251.js.EXPECTED |
diffstat | 3 files changed, 41 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/jdk.dynalink/share/classes/jdk/dynalink/beans/BeanLinker.java Thu Jan 11 15:06:55 2018 -0800 +++ b/src/jdk.dynalink/share/classes/jdk/dynalink/beans/BeanLinker.java Fri Jan 12 10:33:06 2018 +0100 @@ -116,7 +116,7 @@ if(clazz.isArray()) { // Some languages won't have a notion of manipulating collections. Exposing "length" on arrays as an // explicit property is beneficial for them. - setPropertyGetter("length", MethodHandles.arrayLength(clazz), ValidationType.EXACT_CLASS); + setPropertyGetter("length", GET_ARRAY_LENGTH, ValidationType.IS_ARRAY); } else if(Collection.class.isAssignableFrom(clazz)) { setPropertyGetter("length", GET_COLLECTION_LENGTH, ValidationType.INSTANCE_OF); } else if(Map.class.isAssignableFrom(clazz)) { @@ -546,6 +546,9 @@ private static final MethodHandle GET_MAP_LENGTH = Lookup.PUBLIC.findVirtual(Map.class, "size", MethodType.methodType(int.class)); + private static final MethodHandle GET_ARRAY_LENGTH = Lookup.PUBLIC.findStatic(Array.class, "getLength", + MethodType.methodType(int.class, Object.class)); + private static void assertParameterCount(final CallSiteDescriptor descriptor, final int paramCount) { if(descriptor.getMethodType().parameterCount() != paramCount) { throw new BootstrapMethodError(descriptor.getOperation() + " must have exactly " + paramCount + " parameters.");
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/nashorn/script/basic/JDK-8157251.js Fri Jan 12 10:33:06 2018 +0100 @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2018, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * JDK-8157251: BeanLinker relinks array length operations for array types + * + * @test + * @run + */ + +var intArray = Java.type("int[]") +var doubleArray = Java.type("double[]") +var arrs = [new intArray(20), new doubleArray(0)] +for (var i in arrs) + print(arrs[i].length)