This commit is contained in:
Jesper Wilhelmsson 2016-12-18 15:37:51 +01:00
commit 725d3627e4
18 changed files with 232 additions and 3660 deletions

View File

@ -382,3 +382,4 @@ a7f21ee6ed30695a6de14e74035d2857a754f62b jdk-9+144
55f5a96988de8237f3ee65a69aa4a48aed9ca8d4 jdk-9+146
9e86d6383456a1eb0298c72bb9ca363939ad90cf jdk-9+147
0a4bc2f049132ddc20985565bb41b2be8a458dda jdk-9+148
c281306d33d83c92e0d870ace385d5f99678d7e7 jdk-9+149

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,31 @@
## Dynalink v.5
### Dynalink License
<pre>
Copyright (c) 2009-2013, Attila Szegedi
All rights reserved.Redistribution and use in source and binary forms, with or
without modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of Attila Szegedi nor the names of its contributors may be
used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THEPOSSIBILITY OF SUCH DAMAGE.
</pre>

View File

@ -39,7 +39,6 @@ import java.io.File;
import java.io.InputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UncheckedIOException;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
@ -49,6 +48,7 @@ import java.lang.ref.SoftReference;
import java.lang.module.Configuration;
import java.lang.module.ModuleDescriptor;
import java.lang.module.ModuleFinder;
import java.lang.module.ModuleReader;
import java.lang.module.ModuleReference;
import java.lang.reflect.Field;
import java.lang.reflect.Layer;
@ -1349,10 +1349,12 @@ public final class Context {
static Module createModuleTrusted(final Layer parent, final ModuleDescriptor descriptor, final ClassLoader loader) {
final String mn = descriptor.name();
final ModuleReference mref = new ModuleReference(descriptor, null, () -> {
IOException ioe = new IOException("<dynamic module>");
throw new UncheckedIOException(ioe);
});
final ModuleReference mref = new ModuleReference(descriptor, null) {
@Override
public ModuleReader open() {
throw new UnsupportedOperationException();
}
};
final ModuleFinder finder = new ModuleFinder() {
@Override

View File

@ -107,14 +107,13 @@ public abstract class ArrayData {
@Override
public ArrayData ensure(final long safeIndex) {
if (safeIndex > 0L) {
if (safeIndex >= SparseArrayData.MAX_DENSE_LENGTH) {
return new SparseArrayData(this, safeIndex + 1);
}
//known to fit in int
return toRealArrayData((int)safeIndex);
}
return this;
assert safeIndex >= 0L;
if (safeIndex >= SparseArrayData.MAX_DENSE_LENGTH) {
return new SparseArrayData(this, safeIndex + 1);
}
//known to fit in int
return toRealArrayData((int)safeIndex);
}
@Override
@ -133,8 +132,8 @@ public abstract class ArrayData {
}
@Override
public void shiftLeft(final int by) {
//nop, always empty or we wouldn't be of this class
public ArrayData shiftLeft(final int by) {
return this; //nop, always empty or we wouldn't be of this class
}
@Override
@ -451,13 +450,13 @@ public abstract class ArrayData {
/**
* Shift the array data left
*
* TODO: explore start at an index and not at zero, to make these operations
* even faster. Offset everything from the index. Costs memory but is probably
* worth it
* TODO: This is used for Array.prototype.shift() which only shifts by 1,
* so we might consider dropping the offset parameter.
*
* @param by offset to shift
* @return New arraydata (or same)
*/
public abstract void shiftLeft(final int by);
public abstract ArrayData shiftLeft(final int by);
/**
* Shift the array right

View File

@ -68,9 +68,10 @@ abstract class ArrayFilter extends ArrayData {
}
@Override
public void shiftLeft(final int by) {
public ArrayData shiftLeft(final int by) {
underlying.shiftLeft(by);
setLength(underlying.length());
return this;
}
@Override

View File

@ -82,7 +82,7 @@ final class ByteBufferArrayData extends ArrayData {
}
@Override
public void shiftLeft(final int by) {
public ArrayData shiftLeft(final int by) {
throw unsupported("shiftLeft");
}

View File

@ -76,9 +76,10 @@ final class DeletedArrayFilter extends ArrayFilter {
}
@Override
public void shiftLeft(final int by) {
public ArrayData shiftLeft(final int by) {
super.shiftLeft(by);
deleted.shiftLeft(by, length());
return this;
}
@Override

View File

@ -101,10 +101,12 @@ final class DeletedRangeArrayFilter extends ArrayFilter {
}
@Override
public void shiftLeft(final int by) {
public ArrayData shiftLeft(final int by) {
super.shiftLeft(by);
lo = Math.max(0, lo - by);
hi = Math.max(-1, hi - by);
return isEmpty() ? getUnderlying() : this;
}
@Override

View File

@ -176,8 +176,15 @@ final class IntArrayData extends ContinuousArrayData implements IntElements {
}
@Override
public void shiftLeft(final int by) {
System.arraycopy(array, by, array, 0, array.length - by);
public ArrayData shiftLeft(final int by) {
if (by >= length()) {
shrink(0);
} else {
System.arraycopy(array, by, array, 0, array.length - by);
}
setLength(Math.max(0, length() - by));
return this;
}
@Override

View File

@ -121,8 +121,14 @@ final class NumberArrayData extends ContinuousArrayData implements NumericElemen
}
@Override
public void shiftLeft(final int by) {
System.arraycopy(array, by, array, 0, array.length - by);
public ArrayData shiftLeft(final int by) {
if (by >= length()) {
shrink(0);
} else {
System.arraycopy(array, by, array, 0, array.length - by);
}
setLength(Math.max(0, length() - by));
return this;
}
@Override

View File

@ -98,8 +98,14 @@ final class ObjectArrayData extends ContinuousArrayData implements AnyElements {
}
@Override
public void shiftLeft(final int by) {
System.arraycopy(array, by, array, 0, array.length - by);
public ArrayData shiftLeft(final int by) {
if (by >= length()) {
shrink(0);
} else {
System.arraycopy(array, by, array, 0, array.length - by);
}
setLength(Math.max(0, length() - by));
return this;
}
@Override

View File

@ -36,6 +36,7 @@ import jdk.nashorn.internal.runtime.ScriptRuntime;
* Handle arrays where the index is very large.
*/
class SparseArrayData extends ArrayData {
/** Maximum size for dense arrays */
static final int MAX_DENSE_LENGTH = 1024 * 1024;
/** Underlying array. */
@ -51,7 +52,7 @@ class SparseArrayData extends ArrayData {
this(underlying, length, new TreeMap<>());
}
SparseArrayData(final ArrayData underlying, final long length, final TreeMap<Long, Object> sparseMap) {
private SparseArrayData(final ArrayData underlying, final long length, final TreeMap<Long, Object> sparseMap) {
super(length);
assert underlying.length() <= length;
this.underlying = underlying;
@ -89,38 +90,49 @@ class SparseArrayData extends ArrayData {
}
@Override
public void shiftLeft(final int by) {
underlying.shiftLeft(by);
public ArrayData shiftLeft(final int by) {
underlying = underlying.shiftLeft(by);
final TreeMap<Long, Object> newSparseMap = new TreeMap<>();
for (final Map.Entry<Long, Object> entry : sparseMap.entrySet()) {
final long newIndex = entry.getKey() - by;
if (newIndex < maxDenseLength) {
underlying = underlying.set((int) newIndex, entry.getValue(), false);
} else if (newIndex >= 0) {
newSparseMap.put(newIndex, entry.getValue());
if (newIndex >= 0) {
if (newIndex < maxDenseLength) {
final long oldLength = underlying.length();
underlying = underlying.ensure(newIndex)
.set((int) newIndex, entry.getValue(), false)
.safeDelete(oldLength, newIndex - 1, false);
} else {
newSparseMap.put(newIndex, entry.getValue());
}
}
}
sparseMap = newSparseMap;
setLength(Math.max(length() - by, 0));
return sparseMap.isEmpty() ? underlying : this;
}
@Override
public ArrayData shiftRight(final int by) {
final TreeMap<Long, Object> newSparseMap = new TreeMap<>();
// Move elements from underlying to sparse map if necessary
final long len = underlying.length();
if (len + by > maxDenseLength) {
for (long i = maxDenseLength - by; i < len; i++) {
// Length of underlying array after shrinking, before right-shifting
final long tempLength = Math.max(0, maxDenseLength - by);
for (long i = tempLength; i < len; i++) {
if (underlying.has((int) i)) {
newSparseMap.put(i + by, underlying.getObject((int) i));
}
}
underlying = underlying.shrink((int) (maxDenseLength - by));
underlying = underlying.shrink((int) tempLength);
underlying.setLength(tempLength);
}
underlying.shiftRight(by);
underlying = underlying.shiftRight(by);
for (final Map.Entry<Long, Object> entry : sparseMap.entrySet()) {
final long newIndex = entry.getKey() + by;
@ -135,14 +147,6 @@ class SparseArrayData extends ArrayData {
@Override
public ArrayData ensure(final long safeIndex) {
// Usually #ensure only needs to be called if safeIndex is greater or equal current length.
// SparseArrayData is an exception as an index smaller than our current length may still
// exceed the underlying ArrayData's capacity. Because of this, SparseArrayData invokes
// its ensure method internally in various places where other ArrayData subclasses don't,
// making it safe for outside uses to only call ensure(safeIndex) if safeIndex >= length.
if (safeIndex < maxDenseLength && underlying.length() <= safeIndex) {
underlying = underlying.ensure(safeIndex);
}
if (safeIndex >= length()) {
setLength(safeIndex + 1);
}
@ -167,8 +171,7 @@ class SparseArrayData extends ArrayData {
public ArrayData set(final int index, final Object value, final boolean strict) {
if (index >= 0 && index < maxDenseLength) {
final long oldLength = underlying.length();
ensure(index);
underlying = underlying.set(index, value, strict).safeDelete(oldLength, index - 1, strict);
underlying = underlying.ensure(index).set(index, value, strict).safeDelete(oldLength, index - 1, strict);
setLength(Math.max(underlying.length(), length()));
} else {
final Long longIndex = indexToKey(index);
@ -183,8 +186,7 @@ class SparseArrayData extends ArrayData {
public ArrayData set(final int index, final int value, final boolean strict) {
if (index >= 0 && index < maxDenseLength) {
final long oldLength = underlying.length();
ensure(index);
underlying = underlying.set(index, value, strict).safeDelete(oldLength, index - 1, strict);
underlying = underlying.ensure(index).set(index, value, strict).safeDelete(oldLength, index - 1, strict);
setLength(Math.max(underlying.length(), length()));
} else {
final Long longIndex = indexToKey(index);
@ -198,8 +200,7 @@ class SparseArrayData extends ArrayData {
public ArrayData set(final int index, final double value, final boolean strict) {
if (index >= 0 && index < maxDenseLength) {
final long oldLength = underlying.length();
ensure(index);
underlying = underlying.set(index, value, strict).safeDelete(oldLength, index - 1, strict);
underlying = underlying.ensure(index).set(index, value, strict).safeDelete(oldLength, index - 1, strict);
setLength(Math.max(underlying.length(), length()));
} else {
final Long longIndex = indexToKey(index);

View File

@ -98,7 +98,7 @@ public abstract class TypedArrayData<T extends Buffer> extends ContinuousArrayDa
}
@Override
public void shiftLeft(final int by) {
public ArrayData shiftLeft(final int by) {
throw new UnsupportedOperationException();
}

View File

@ -77,9 +77,10 @@ final class UndefinedArrayFilter extends ArrayFilter {
}
@Override
public void shiftLeft(final int by) {
public ArrayData shiftLeft(final int by) {
super.shiftLeft(by);
undefined.shiftLeft(by, length());
return this;
}
@Override

View File

@ -0,0 +1,36 @@
## Double-conversion v1.1.5
### Double-conversion License
https://raw.githubusercontent.com/google/double-conversion/master/LICENSE
<pre>
Copyright 2006-2011, the V8 project authors. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
</pre>

View File

@ -0,0 +1,26 @@
## JRuby Joni v1.1.9
### JRuby License
<pre>
Jruby 2012
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
</pre>

View File

@ -0,0 +1,57 @@
/*
* Copyright (c) 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
* 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-8171219: Missing checks in sparse array shift() implementation
*
* @test
* @run
*/
var a = [];
a[1048577] = 1;
a.shift();
a[1] = 2;
a.shift();
var ka = Object.keys(a);
Assert.assertTrue(ka.length === 2);
Assert.assertTrue(ka[0] === '0');
Assert.assertTrue(ka[1] === '1048575');
Assert.assertTrue(a.length === 1048576);
Assert.assertTrue(a[0] === 2);
Assert.assertTrue(a[1048575] = 1);
var b = [];
b[1048577] = 1;
b.unshift(2);
b.shift();
b[1] = 3;
b.shift();
var kb = Object.keys(b);
Assert.assertTrue(kb.length === 2);
Assert.assertTrue(kb[0] === '0');
Assert.assertTrue(kb[1] === '1048576');
Assert.assertTrue(b.length === 1048577);
Assert.assertTrue(b[0] === 3);
Assert.assertTrue(b[1048576] = 1);