This commit is contained in:
Athijegannathan Sundararajan 2013-10-18 18:26:13 +05:30
commit a98e63edf4
18 changed files with 515 additions and 56 deletions

View File

@ -1665,9 +1665,9 @@ public final class Global extends ScriptObject implements GlobalObject, Scope {
final ScriptObject stringPrototype = getStringPrototype();
stringPrototype.addOwnProperty("length", Attribute.NON_ENUMERABLE_CONSTANT, 0.0);
// add Array.prototype.length
// set isArray flag on Array.prototype
final ScriptObject arrayPrototype = getArrayPrototype();
arrayPrototype.addOwnProperty("length", Attribute.NOT_ENUMERABLE|Attribute.NOT_CONFIGURABLE, 0.0);
arrayPrototype.setIsArray();
this.DEFAULT_DATE = new NativeDate(Double.NaN, this);

View File

@ -372,9 +372,7 @@ public final class NativeArray extends ScriptObject {
*/
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static Object isArray(final Object self, final Object arg) {
return isArray(arg) || (arg == Global.instance().getArrayPrototype())
|| (arg instanceof NativeRegExpExecResult)
|| (arg instanceof JSObject && ((JSObject)arg).isArray());
return isArray(arg) || (arg instanceof JSObject && ((JSObject)arg).isArray());
}
/**
@ -403,6 +401,26 @@ public final class NativeArray extends ScriptObject {
}
}
/**
* Prototype length getter
* @param self self reference
* @return the length of the object
*/
@Getter(name = "length", where = Where.PROTOTYPE, attributes = Attribute.NOT_ENUMERABLE | Attribute.NOT_CONFIGURABLE)
public static Object getProtoLength(final Object self) {
return length(self); // Same as instance getter but we can't make nasgen use the same method for prototype
}
/**
* Prototype length setter
* @param self self reference
* @param length new length property
*/
@Setter(name = "length", where = Where.PROTOTYPE, attributes = Attribute.NOT_ENUMERABLE | Attribute.NOT_CONFIGURABLE)
public static void setProtoLength(final Object self, final Object length) {
length(self, length); // Same as instance setter but we can't make nasgen use the same method for prototype
}
static long validLength(final Object length, final boolean reject) {
final double doubleLength = JSType.toNumber(length);
if (!Double.isNaN(doubleLength) && JSType.isRepresentableAsLong(doubleLength)) {
@ -1007,19 +1025,42 @@ public final class NativeArray extends ScriptObject {
final long actualStart = relativeStart < 0 ? Math.max(len + relativeStart, 0) : Math.min(relativeStart, len);
final long actualDeleteCount = Math.min(Math.max(JSType.toLong(deleteCount), 0), len - actualStart);
final NativeArray array = new NativeArray(actualDeleteCount);
NativeArray returnValue;
for (long k = 0; k < actualDeleteCount; k++) {
final long from = actualStart + k;
if (actualStart <= Integer.MAX_VALUE && actualDeleteCount <= Integer.MAX_VALUE && bulkable(sobj)) {
try {
returnValue = new NativeArray(sobj.getArray().fastSplice((int)actualStart, (int)actualDeleteCount, items.length));
// Since this is a dense bulkable array we can use faster defineOwnProperty to copy new elements
int k = (int) actualStart;
for (int i = 0; i < items.length; i++, k++) {
sobj.defineOwnProperty(k, items[i]);
}
} catch (UnsupportedOperationException uoe) {
returnValue = slowSplice(sobj, actualStart, actualDeleteCount, items, len);
}
} else {
returnValue = slowSplice(sobj, actualStart, actualDeleteCount, items, len);
}
return returnValue;
}
private static NativeArray slowSplice(final ScriptObject sobj, final long start, final long deleteCount, final Object[] items, final long len) {
final NativeArray array = new NativeArray(deleteCount);
for (long k = 0; k < deleteCount; k++) {
final long from = start + k;
if (sobj.has(from)) {
array.defineOwnProperty(ArrayIndex.getArrayIndex(k), sobj.get(from));
}
}
if (items.length < actualDeleteCount) {
for (long k = actualStart; k < (len - actualDeleteCount); k++) {
final long from = k + actualDeleteCount;
if (items.length < deleteCount) {
for (long k = start; k < (len - deleteCount); k++) {
final long from = k + deleteCount;
final long to = k + items.length;
if (sobj.has(from)) {
@ -1029,12 +1070,12 @@ public final class NativeArray extends ScriptObject {
}
}
for (long k = len; k > (len - actualDeleteCount + items.length); k--) {
for (long k = len; k > (len - deleteCount + items.length); k--) {
sobj.delete(k - 1, true);
}
} else if (items.length > actualDeleteCount) {
for (long k = len - actualDeleteCount; k > actualStart; k--) {
final long from = k + actualDeleteCount - 1;
} else if (items.length > deleteCount) {
for (long k = len - deleteCount; k > start; k--) {
final long from = k + deleteCount - 1;
final long to = k + items.length - 1;
if (sobj.has(from)) {
@ -1046,12 +1087,12 @@ public final class NativeArray extends ScriptObject {
}
}
long k = actualStart;
long k = start;
for (int i = 0; i < items.length; i++, k++) {
sobj.set(k, items[i], true);
}
final long newLength = len - actualDeleteCount + items.length;
final long newLength = len - deleteCount + items.length;
sobj.set("length", newLength, true);
return array;

View File

@ -629,7 +629,8 @@ public final class NativeJSAdapter extends ScriptObject {
// to name. Probably not a big deal, but if we can ever make it leaner, it'd be nice.
return new GuardedInvocation(MH.dropArguments(MH.constant(Object.class,
func.makeBoundFunction(this, new Object[] { name })), 0, Object.class),
adaptee.getMap().getProtoGetSwitchPoint(adaptee.getProto(), __call__), testJSAdaptor(adaptee, null, null, null));
adaptee.getMap().getProtoGetSwitchPoint(adaptee.getProto(), __call__),
testJSAdaptor(adaptee, null, null, null));
}
}
throw typeError("no.such.function", desc.getNameToken(2), ScriptRuntime.safeToString(this));

View File

@ -47,7 +47,6 @@ import static jdk.nashorn.internal.parser.TokenType.XML;
import jdk.nashorn.internal.runtime.ECMAErrors;
import jdk.nashorn.internal.runtime.ErrorManager;
import jdk.nashorn.internal.runtime.JSErrorType;
import jdk.nashorn.internal.runtime.JSType;
import jdk.nashorn.internal.runtime.ParserException;
import jdk.nashorn.internal.runtime.Source;
import jdk.nashorn.internal.runtime.options.Options;
@ -1053,16 +1052,6 @@ public class Lexer extends Scanner {
}
}
/**
* Convert string to number.
*
* @param valueString String to convert.
* @return Converted number.
*/
private static Number valueOf(final String valueString) throws NumberFormatException {
return JSType.narrowestIntegerRepresentation(Double.valueOf(valueString));
}
/**
* Scan a number.
*/
@ -1623,7 +1612,7 @@ public class Lexer extends Scanner {
case HEXADECIMAL:
return Lexer.valueOf(source.getString(start + 2, len - 2), 16); // number
case FLOATING:
return Lexer.valueOf(source.getString(start, len)); // number
return Double.valueOf(source.getString(start, len)); // number
case STRING:
return source.getString(start, len); // String
case ESCSTRING:

View File

@ -209,26 +209,6 @@ public enum JSType {
return (long)number == number;
}
/**
* Get the smallest integer representation of a number. Returns an Integer
* for something that is int representable, and Long for something that
* is long representable. If the number needs to be a double, this is an
* identity function
*
* @param number number to check
*
* @return Number instanceof the narrowest possible integer representation for number
*/
public static Number narrowestIntegerRepresentation(final double number) {
if (isRepresentableAsInt(number)) {
return (int)number;
} else if (isRepresentableAsLong(number)) {
return (long)number;
} else {
return number;
}
}
/**
* Check whether an object is primitive
*

View File

@ -594,7 +594,7 @@ public abstract class ScriptObject extends PropertyListenerManager implements Pr
* @param index key for property
* @param value value to define
*/
protected final void defineOwnProperty(final int index, final Object value) {
public final void defineOwnProperty(final int index, final Object value) {
assert isValidArrayIndex(index) : "invalid array index";
final long longIndex = ArrayIndex.toLongIndex(index);
if (longIndex >= getArray().length()) {

View File

@ -461,7 +461,23 @@ public abstract class ArrayData {
*/
public abstract ArrayData slice(long from, long to);
private static Class<?> widestType(final Object... items) {
/**
* Fast splice operation. This just modifies the array according to the number of
* elements added and deleted but does not insert the added elements. Throws
* {@code UnsupportedOperationException} if fast splice operation is not supported
* for this class or arguments.
*
* @param start start index of splice operation
* @param removed number of removed elements
* @param added number of added elements
* @throws UnsupportedOperationException if fast splice is not supported for the class or arguments.
*/
public ArrayData fastSplice(final int start, final int removed, final int added) throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
static Class<?> widestType(final Object... items) {
assert items.length > 0;
Class<?> widest = Integer.class;

View File

@ -269,4 +269,32 @@ final class IntArrayData extends ArrayData {
return new IntArrayData(Arrays.copyOfRange(array, (int)from, (int)to), (int)newLength);
}
@Override
public ArrayData fastSplice(final int start, final int removed, final int added) throws UnsupportedOperationException {
final long oldLength = length();
final long newLength = oldLength - removed + added;
if (newLength > SparseArrayData.MAX_DENSE_LENGTH && newLength > array.length) {
throw new UnsupportedOperationException();
}
final ArrayData returnValue = (removed == 0) ?
EMPTY_ARRAY : new IntArrayData(Arrays.copyOfRange(array, start, start + removed), removed);
if (newLength != oldLength) {
final int[] newArray;
if (newLength > array.length) {
newArray = new int[ArrayData.nextSize((int)newLength)];
System.arraycopy(array, 0, newArray, 0, start);
} else {
newArray = array;
}
System.arraycopy(array, start + removed, newArray, start + added, (int)(oldLength - start - removed));
array = newArray;
setLength(newLength);
}
return returnValue;
}
}

View File

@ -92,7 +92,7 @@ final class LongArrayData extends ArrayData {
@Override
public ArrayData convert(final Class<?> type) {
if (type == Long.class) {
if (type == Integer.class || type == Long.class) {
return this;
}
final int length = (int) length();
@ -238,4 +238,32 @@ final class LongArrayData extends ArrayData {
final long newLength = to - start;
return new LongArrayData(Arrays.copyOfRange(array, (int)from, (int)to), (int)newLength);
}
@Override
public ArrayData fastSplice(final int start, final int removed, final int added) throws UnsupportedOperationException {
final long oldLength = length();
final long newLength = oldLength - removed + added;
if (newLength > SparseArrayData.MAX_DENSE_LENGTH && newLength > array.length) {
throw new UnsupportedOperationException();
}
final ArrayData returnValue = (removed == 0) ?
EMPTY_ARRAY : new LongArrayData(Arrays.copyOfRange(array, start, start + removed), removed);
if (newLength != oldLength) {
final long[] newArray;
if (newLength > array.length) {
newArray = new long[ArrayData.nextSize((int)newLength)];
System.arraycopy(array, 0, newArray, 0, start);
} else {
newArray = array;
}
System.arraycopy(array, start + removed, newArray, start + added, (int)(oldLength - start - removed));
array = newArray;
setLength(newLength);
}
return returnValue;
}
}

View File

@ -218,4 +218,32 @@ final class NumberArrayData extends ArrayData {
final long newLength = to - start;
return new NumberArrayData(Arrays.copyOfRange(array, (int)from, (int)to), (int)newLength);
}
@Override
public ArrayData fastSplice(final int start, final int removed, final int added) throws UnsupportedOperationException {
final long oldLength = length();
final long newLength = oldLength - removed + added;
if (newLength > SparseArrayData.MAX_DENSE_LENGTH && newLength > array.length) {
throw new UnsupportedOperationException();
}
final ArrayData returnValue = (removed == 0) ?
EMPTY_ARRAY : new NumberArrayData(Arrays.copyOfRange(array, start, start + removed), removed);
if (newLength != oldLength) {
final double[] newArray;
if (newLength > array.length) {
newArray = new double[ArrayData.nextSize((int)newLength)];
System.arraycopy(array, 0, newArray, 0, start);
} else {
newArray = array;
}
System.arraycopy(array, start + removed, newArray, start + added, (int)(oldLength - start - removed));
array = newArray;
setLength(newLength);
}
return returnValue;
}
}

View File

@ -206,4 +206,32 @@ final class ObjectArrayData extends ArrayData {
final long newLength = to - start;
return new ObjectArrayData(Arrays.copyOfRange(array, (int)from, (int)to), (int)newLength);
}
@Override
public ArrayData fastSplice(final int start, final int removed, final int added) throws UnsupportedOperationException {
final long oldLength = length();
final long newLength = oldLength - removed + added;
if (newLength > SparseArrayData.MAX_DENSE_LENGTH && newLength > array.length) {
throw new UnsupportedOperationException();
}
final ArrayData returnValue = (removed == 0) ?
EMPTY_ARRAY : new ObjectArrayData(Arrays.copyOfRange(array, start, start + removed), removed);
if (newLength != oldLength) {
final Object[] newArray;
if (newLength > array.length) {
newArray = new Object[ArrayData.nextSize((int)newLength)];
System.arraycopy(array, 0, newArray, 0, start);
} else {
newArray = array;
}
System.arraycopy(array, start + removed, newArray, start + added, (int)(oldLength - start - removed));
array = newArray;
setLength(newLength);
}
return returnValue;
}
}

View File

@ -90,6 +90,24 @@ bench("set", function() {
array[6] = 6;
});
bench("push", function() {
var arr = [1, 2, 3];
arr.push(4);
arr.push(5);
arr.push(6);
});
bench("pop", function() {
var arr = [1, 2, 3];
arr.pop();
arr.pop();
arr.pop();
});
bench("splice", function() {
[1, 2, 3].splice(0, 2, 5, 6, 7);
});
var all = function(e) { return true; };
var none = function(e) { return false; };

View File

@ -0,0 +1,32 @@
/*
* Copyright (c) 2010, 2013, 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-8026161: Don't narrow floating-point literals in the lexer
*
* @test
* @run
*/
print(new java.awt.Color(1, 1, 1)) // creates Color[r=1,g=1,b=1]
print(new java.awt.Color(1.0, 1.0, 1.0)) // Color[r=255,g=255,b=255]

View File

@ -0,0 +1,2 @@
java.awt.Color[r=1,g=1,b=1]
java.awt.Color[r=255,g=255,b=255]

View File

@ -0,0 +1,72 @@
/*
* Copyright (c) 2010, 2013, 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-8026701: Array.prototype.splice is slow on dense arrays
*
* @test
* @run
*/
function testSplice(arr, e1, e2, e3) {
try {
print(arr);
print(arr.splice(3, 0, e1, e2, e3));
print(arr);
print(arr.splice(2, 3));
print(arr);
print(arr.splice(2, 3, arr[2], arr[3], arr[4]));
print(arr);
print(arr.splice(20, 10));
print(arr);
print(arr.splice(arr.length, 0, e1, e2, e3));
print(arr);
print(arr.splice(0, 2, arr[0], arr[1], arr[2], arr[3]));
print(arr);
} catch (error) {
print(error);
}
}
function convert(array, type) {
return (typeof Java === "undefined") ? array : Java.from(Java.to(array, type));
}
// run some splice tests on all dense array implementations
testSplice([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], -1, -2, -3);
testSplice(convert([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], "long[]"), -1, -2, -3);
testSplice(convert([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], "double[]"), -1, -2, -3);
testSplice(["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"], -1, -2, -3);
// test array conversion during splice
testSplice([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], -1, "-2", "-3");
testSplice([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], -1, -2.5, -3.5);
testSplice(convert([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], "long[]"), -1, "-2", "-3");
testSplice(convert([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], "long[]"), -1, -2.5, -3.5);
testSplice(convert([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], "double[]"), -1, "-2", "-3");
// test combination with defined elements
testSplice(Object.defineProperty([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 5, {value: 13}), -1, -2, -3);
testSplice(Object.defineProperty([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 5, {value: 13, writable: false}), -1, -2, -3);
testSplice(Object.defineProperty([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 5, {value: 13, configurable: false}), -1, -2, -3);
testSplice(Object.defineProperty([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 5, {value: 13, writable: false, configurable: false}), -1, -2, -3);

View File

@ -0,0 +1,147 @@
1,2,3,4,5,6,7,8,9,10
1,2,3,-1,-2,-3,4,5,6,7,8,9,10
3,-1,-2
1,2,-3,4,5,6,7,8,9,10
-3,4,5
1,2,-3,4,5,6,7,8,9,10
1,2,-3,4,5,6,7,8,9,10
1,2,-3,4,5,6,7,8,9,10,-1,-2,-3
1,2
1,2,-3,4,-3,4,5,6,7,8,9,10,-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7,8,9,10,-1,-2,-3
1,2,3,4,5,13,7,8,9,10
TypeError: "5" is not a writable property of [object Array]

View File

@ -0,0 +1,49 @@
/*
* Copyright (c) 2010, 2013, 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-8026805: Array.prototype.length doesn't work as expected
*
* @test
* @run
*/
if (Array.prototype.length !== 0) {
throw new Error("Initial length not 0");
}
Array.prototype[3] = 1;
if (Array.prototype.length !== 4) {
throw new Error("length not updated to 4");
}
Array.prototype.length = 0;
if (Array.prototype.length !== 0) {
throw new Error("length not reset to 0");
}
if (3 in Array.prototype) {
throw new Error("array element not deleted");
}

View File

@ -412,7 +412,7 @@ public class MethodAccessTest {
@Test
public void accessMethodMixedWithEllipsis() throws ScriptException {
assertArrayEquals(new Object[] { "Hello", 10, true, -100500, 80 }, (Object[])e.eval("o.methodMixedWithEllipsis('Hello', 10, true, -100500,80.0);"));
assertArrayEquals(new Object[] { "Hello", 10, true, -100500, 80d }, (Object[])e.eval("o.methodMixedWithEllipsis('Hello', 10, true, -100500,80.0);"));
assertArrayEquals(new Object[] { "Nashorn", 15 }, (Object[])e.eval("o.methodMixedWithEllipsis('Nashorn',15);"));
}
@ -431,8 +431,8 @@ public class MethodAccessTest {
@Test
public void accessMethodDoubleVSintOverloaded() throws ScriptException {
assertEquals("int", e.eval("o.overloadedMethodDoubleVSint(0.0);"));
assertEquals("int", e.eval("o.overloadedMethodDoubleVSint(1000.0);"));
assertEquals("double", e.eval("o.overloadedMethodDoubleVSint(0.0);"));
assertEquals("double", e.eval("o.overloadedMethodDoubleVSint(1000.0);"));
assertEquals("double", e.eval("o.overloadedMethodDoubleVSint(0.01);"));
assertEquals("double", e.eval("o.overloadedMethodDoubleVSint(100.02);"));
assertEquals("int", e.eval("o.overloadedMethodDoubleVSint(0);"));